Attempting to modify Kim Asendorf's ASDFPixelSort
in
Programming Questions
•
1 month ago
Hey all,
I've been looking at modifying another sketch to read and manipulate a folder full of images in sequence but I'm not having much luck.
The modifications I've made to Kim Asendorf's ASDFPixelSort sketch have allowed it to read all the image files in a folder, but not only can I not get it to load the whole list, it doesn't even sort the first image anymore (which is the only file it does load).
Here's my alternation:
- int mode = 1;
- //MODE:
- //0 -> black
- //1 -> bright
- //2 -> white
- //b(16777216)
- java.io.FilenameFilter jpgFilter = new java.io.FilenameFilter() {
- boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".jpg");
- }
- };
- PImage img;
- //String FileName = "Tri.jpg";
- File dir;
- String[] list;
- int loops = 1;
- int blackValue = -16000000;
- int brigthnessValue = 50;
- int whiteValue = -13000000;
- int row = 0;
- int column = 0;
- boolean saved = false;
- void setup() {
- size(1920, 1080);
- dir = new File(dataPath("images"));
- list = dir.list(jpgFilter);
- }
- void draw() {
- for (int i = 0; i < list.length; i=i+1) {
- println(list[i]);
- img = loadImage(dataPath("images/" + list[i]));
- background(loadImage(dataPath("images/" + list[i])));
- loadPixels();
- while(column < width-1) {
- img.loadPixels();
- sortColumn();
- column++;
- img.updatePixels();
- }
- while(row < height-1) {
- img.loadPixels();
- sortRow();
- row++;
- img.updatePixels();
- }
- image(img,0,0);
- if(!saved && frameCount >= loops) {
- saveFrame(list[i]);
- saved = true;
- println("DONE "+list[i]);
- }
- }
- }
- void sortRow() {
- int x = 0;
- int y = row;
- int xend = 0;
- while(xend < width-1) {
- switch(mode) {
- case 0:
- x = getFirstNotBlackX(x, y);
- xend = getNextBlackX(x, y);
- break;
- case 1:
- x = getFirstBrightX(x, y);
- xend = getNextDarkX(x, y);
- break;
- case 2:
- x = getFirstNotWhiteX(x, y);
- xend = getNextWhiteX(x, y);
- break;
- default:
- break;
- }
- if(x < 0) break;
- int sortLength = xend-x;
- color[] unsorted = new color[sortLength];
- color[] sorted = new color[sortLength];
- for(int i=0; i<sortLength; i++) {
- unsorted[i] = img.pixels[x + i + y * img.width];
- }
- sorted = sort(unsorted);
- for(int i=0; i<sortLength; i++) {
- img.pixels[x + i + y * img.width] = sorted[i];
- }
- x = xend+1;
- }
- }
- void sortColumn() {
- int x = column;
- int y = 0;
- int yend = 0;
- while(yend < height-1) {
- switch(mode) {
- case 0:
- y = getFirstNotBlackY(x, y);
- yend = getNextBlackY(x, y);
- break;
- case 1:
- y = getFirstBrightY(x, y);
- yend = getNextDarkY(x, y);
- break;
- case 2:
- y = getFirstNotWhiteY(x, y);
- yend = getNextWhiteY(x, y);
- break;
- default:
- break;
- }
- if(y < 0) break;
- int sortLength = yend-y;
- color[] unsorted = new color[sortLength];
- color[] sorted = new color[sortLength];
- for(int i=0; i<sortLength; i++) {
- unsorted[i] = img.pixels[x + (y+i) * img.width];
- }
- sorted = sort(unsorted);
- for(int i=0; i<sortLength; i++) {
- img.pixels[x + (y+i) * img.width] = sorted[i];
- }
- y = yend+1;
- }
- }
- //BLACK
- int getFirstNotBlackX(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- while((c = img.pixels[x + y * img.width]) < blackValue) {
- x++;
- if(x >= width) return -1;
- }
- return x;
- }
- int getNextBlackX(int _x, int _y) {
- int x = _x+1;
- int y = _y;
- color c;
- while((c = img.pixels[x + y * img.width]) > blackValue) {
- x++;
- if(x >= width) return width-1;
- }
- return x-1;
- }
- //BRIGHTNESS
- int getFirstBrightX(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- while(brightness(c = img.pixels[x + y * img.width]) < brigthnessValue) {
- x++;
- if(x >= width) return -1;
- }
- return x;
- }
- int getNextDarkX(int _x, int _y) {
- int x = _x+1;
- int y = _y;
- color c;
- while(brightness(c = img.pixels[x + y * img.width]) > brigthnessValue) {
- x++;
- if(x >= width) return width-1;
- }
- return x-1;
- }
- //WHITE
- int getFirstNotWhiteX(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- while((c = img.pixels[x + y * img.width]) > whiteValue) {
- x++;
- if(x >= width) return -1;
- }
- return x;
- }
- int getNextWhiteX(int _x, int _y) {
- int x = _x+1;
- int y = _y;
- color c;
- while((c = img.pixels[x + y * img.width]) < whiteValue) {
- x++;
- if(x >= width) return width-1;
- }
- return x-1;
- }
- //BLACK
- int getFirstNotBlackY(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- if(y < height) {
- while((c = img.pixels[x + y * img.width]) < blackValue) {
- y++;
- if(y >= height) return -1;
- }
- }
- return y;
- }
- int getNextBlackY(int _x, int _y) {
- int x = _x;
- int y = _y+1;
- color c;
- if(y < height) {
- while((c = img.pixels[x + y * img.width]) > blackValue) {
- y++;
- if(y >= height) return height-1;
- }
- }
- return y-1;
- }
- //BRIGHTNESS
- int getFirstBrightY(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- if(y < height) {
- while(brightness(c = img.pixels[x + y * img.width]) < brigthnessValue) {
- y++;
- if(y >= height) return -1;
- }
- }
- return y;
- }
- int getNextDarkY(int _x, int _y) {
- int x = _x;
- int y = _y+1;
- color c;
- if(y < height) {
- while(brightness(c = img.pixels[x + y * img.width]) > brigthnessValue) {
- y++;
- if(y >= height) return height-1;
- }
- }
- return y-1;
- }
- //WHITE
- int getFirstNotWhiteY(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- if(y < height) {
- while((c = img.pixels[x + y * img.width]) > whiteValue) {
- y++;
- if(y >= height) return -1;
- }
- }
- return y;
- }
- int getNextWhiteY(int _x, int _y) {
- int x = _x;
- int y = _y+1;
- color c;
- if(y < height) {
- while((c = img.pixels[x + y * img.width]) < whiteValue) {
- y++;
- if(y >= height) return height-1;
- }
- }
- return y-1;
- }
Would love some help if you have any ideas,
cheers,
Steve
1