commit c164d3e36a6a50b8eb4fc0fa3999af0a9d0ac876 Author: Victor Giers Date: Thu Jan 7 11:01:12 2021 +0100 initial commit diff --git a/bounder.pde b/bounder.pde new file mode 100644 index 0000000..e494990 --- /dev/null +++ b/bounder.pde @@ -0,0 +1,118 @@ +class Bounder { + int state; + float h; + float angle, arcangle; + + float angle(PVector v1, PVector v2) { + float a = atan2(v2.y, v2.x) - atan2(v1.y, v1.x); + if (a < 0) a += TWO_PI; + return a; + } + PVector p1, p2, p3, p4; + void click() { + if (state < 4) state++; + if (state == 1) { + p1 = new PVector(mouseX, mouseY); + } + if (state == 2) { + p2 = new PVector(mouseX, mouseY); + } + if (state == 3) { + h = -p2.dist(new PVector(mouseX, mouseY)); + } + } + void update() { + if (state == 2) { + h = -p2.dist(new PVector(mouseX, mouseY)); + } + } + void display() { + if (state > 0) { + fill(0); + noStroke(); + circle(p1.x, p1.y, 5); + } + if (state == 1) { + stroke(1); + line(p1.x, p1.y, mouseX, mouseY); + } + if (state > 1) { + //stroke(1); + //line(p1.x, p1.y, p2.x, p2.y); + fill(0); + noStroke(); + circle(p2.x, p2.y, 5); + fill(255, 100); + stroke(1); + pushMatrix(); + translate(p1.x, p1.y); + rotate(angle(new PVector(0, width), PVector.sub(p2, p1))); + rect(0, 0, h, p1.dist(p2)); + p3 = new PVector(screenX(h, 0), screenY(h, 0)); + p4 = new PVector(screenX(h, p1.dist(p2)), screenY(h, p1.dist(p2))); + popMatrix(); + fill(0); + noStroke(); + circle(p3.x, p3.y, 5); + circle(p4.x, p4.y, 5); + } + } + + void compile() { + PVector ptopmid = new PVector((p1.x + p2.x)/2, (p1.y + p2.y)/2); + PVector pbotmid = new PVector((p3.x + p4.x)/2, (p3.y + p4.y)/2); + + /* + links: p1 -> ptopmid -> pbotmid -> p3 + rechts: ptopmid -> p2 -> p4 -> pbotmid + */ + int leftLeftTopX = (int)map(p1.x, 0, width, 0, images[imageNo].width); + int leftLeftTopY = (int)map(p1.y, 0, height, 0, images[imageNo].height); + int leftRightTopX = (int)map(ptopmid.x, 0, width, 0, images[imageNo].width); + int leftRightTopY = (int)map(ptopmid.y, 0, height, 0, images[imageNo].height); + int leftRightBotX = (int)map(pbotmid.x, 0, width, 0, images[imageNo].width); + int leftRightBotY = (int)map(pbotmid.y, 0, height, 0, images[imageNo].height); + int leftLeftBotX = (int)map(p3.x, 0, width, 0, images[imageNo].width); + int leftLeftBotY = (int)map(p3.y, 0, height, 0, images[imageNo].height); + + int rightLeftTopX = leftRightTopX; + int rightLeftTopY = leftRightTopY; + int rightRightTopX = (int)map(p2.x, 0, width, 0, images[imageNo].width); + int rightRightTopY = (int)map(p2.y, 0, height, 0, images[imageNo].height); + int rightRightBotX = (int)map(p4.x, 0, width, 0, images[imageNo].width); + int rightRightBotY = (int)map(p4.y, 0, height, 0, images[imageNo].height); + int rightLeftBotX = leftRightBotX; + int rightLeftBotY = leftRightBotY; + + + //beispielcommands: + //for f in ./*.jpg; do convert "$f" \( -clone 0 -fill black -colorize 100 -fill white -draw "polygon 3218,2414 4882,2414 4882,2621 3218,4771" \) -alpha off -compose copy_opacity -composite -trim +repage "$f"_left.jpg; done + //for f in ./*.jpg; do convert "$f" \( -clone 0 -fill black -colorize 100 -fill white -draw "polygon 3218,2414 4882,2414 4882,2621 3218,4771" \) -alpha off -compose copy_opacity -composite -trim +repage "$f"_right.jpg; done + + String folderName = String.valueOf((int)random(100000000)); + String cmdleft = "for f in ./*.jpg; do convert \"$f\" \\( -clone 0 -fill black -colorize 100 -fill white -draw \"polygon " + leftLeftTopX + "," + leftLeftTopY + " " + leftRightTopX + "," + leftRightTopY + " " + leftRightBotX + "," + leftRightBotY + " " + leftLeftBotX + "," + leftLeftBotY + "\" \\) -alpha off -compose copy_opacity -composite -trim +repage " + folderName + "/\"$f\"_left.jpg; done"; + String cmdright = "for f in ./*.jpg; do convert \"$f\" \\( -clone 0 -fill black -colorize 100 -fill white -draw \"polygon " + rightLeftTopX + "," + rightLeftTopY + " " + rightRightTopX + "," + rightRightTopY + " " + rightRightBotX + "," + rightRightBotY + " " + rightLeftBotX + "," + rightLeftBotY + "\" \\) -alpha off -compose copy_opacity -composite -trim +repage " + folderName + "/\"$f\"_right.jpg; done"; + String cmdpdf = "convert " + folderName + "/*.jpg notizheft.pdf"; + println(cmdleft); + println(cmdright); + //execl("/bin/sh", "-c", "cd", (const char *)0); + //exec("/bin/sh -c cd " + folderURI + " && " + cmdleft); + + //String[] runConvert = { "/bin/bash", "-c", "cd " + folderURI + " && mkdir " + folderName + " && " + cmdleft + " && " + cmdright + " && " + cmdpdf }; + String[] runConvert = { "/bin/bash", "-c", "cd " + folderURI + " && mkdir " + folderName + " && " + cmdleft + " && " + cmdright }; + exec(runConvert); + + //println(leftLeftTopX + "," + leftLeftTopY + " " + leftRightTopX + "," + leftRightTopY + " " + leftRightBotX + "," + leftRightBotY + " " + leftLeftBotX + "," + leftLeftBotY); + //println(rightLeftTopX + "," + rightLeftTopY + " " + rightRightTopX + "," + rightRightTopY + " " + rightRightBotX + "," + rightRightBotY + " " + rightLeftBotX + "," + rightLeftBotY); + + /* + println((int)map(p1.x, 0, width, 0, images[imageNo].width)); + println((int)map(p1.y, 0, height, 0, images[imageNo].height)); + println((int)map(p2.x, 0, width, 0, images[imageNo].width)); + println((int)map(p2.y, 0, height, 0, images[imageNo].height)); + println((int)map(p3.x, 0, width, 0, images[imageNo].width)); + println((int)map(p3.y, 0, height, 0, images[imageNo].height)); + println((int)map(p4.x, 0, width, 0, images[imageNo].width)); + println((int)map(p4.y, 0, height, 0, images[imageNo].height));*/ + } +} diff --git a/scancropper2.pde b/scancropper2.pde new file mode 100644 index 0000000..7807878 --- /dev/null +++ b/scancropper2.pde @@ -0,0 +1,96 @@ +import drop.*; + +SDrop drop; +Bounder bounder; +int imageNo = 0; +int imageAmount; +String[] imageList; +PImage[] images; +boolean imageLoaded; +String folderURI; + +void setup() { + size(240, 100); + frameRate(30); + drop = new SDrop(this); + surface.setResizable(true); + bounder = new Bounder(); +} + +void draw() { + background(255); + fill(0); + text("Drop image folder here", 52, 53, 20); + + if (imageLoaded) { + if (images[imageNo] != null) { + image(images[imageNo], 0, 0, width, height); + } + } + + bounder.update(); + bounder.display(); +} + +void keyPressed() { + if (key == ENTER) { + if (bounder.state >= 3) { + println("Compiling images"); + bounder.compile(); + println("Compiling finished, reset bounder"); + //bounder.state = 0; + } + } + if (key == ' ') { + bounder.state = 0; + println("Bounder reset"); + } + if (key == CODED) { + if (keyCode == RIGHT) { + imageNo++; + if (imageNo > imageAmount) imageNo = imageAmount; + else setImage(imageNo); + println(imageNo); + } else if (keyCode == LEFT) { + imageNo--; + if (imageNo < 0) imageNo = 0; + else setImage(imageNo); + + println(imageNo); + } + } +} + +void mousePressed() { + bounder.click(); +} + +void setImage(int i) { + imageLoaded = false; //seperate threat not present ladida + images[i] = loadImage(imageList[imageNo]); + imageLoaded = true; +} +void dropEvent(DropEvent theDropEvent) { + + if (theDropEvent.isFile()) { + File myFile = theDropEvent.file(); + if (myFile.isDirectory()) { + File[] droppedFiles = myFile.listFiles(); + println(droppedFiles); + folderURI = droppedFiles[0].getParent(); + println(folderURI); + imageAmount = droppedFiles.length-1; // assuming all files in folder are images + images = new PImage[imageAmount]; + imageList = new String[imageAmount]; + for (int i = 0; i < imageAmount; i++) { + imageList[i] = droppedFiles[i].toString(); + } + imageList = sort(imageList); + setImage(imageNo); + /*for (int i = 0; i < imageAmount; i++) { + images[i] = loadImage(droppedFiles[i].toString()); + println("hi"); + } // braucht zu lang die scheisse */ + } + } +}