void fill(ImageProcessor ip, int foreground, int background) { int width = ip.getWidth(); int height = ip.getHeight(); FloodFiller ff = new FloodFiller(ip); ip.setColor(127); for (int y=0; y<height; y++) { if (ip.getPixel(0,y)==background) ff.fill(0, y); if (ip.getPixel(width-1,y)==background) ff.fill(width-1, y); } for (int x=0; x<width; x++){ if (ip.getPixel(x,0)==background) ff.fill(x, 0); if (ip.getPixel(x,height-1)==background) ff.fill(x, height-1); } byte[] pixels = (byte[])ip.getPixels(); int n = width*height; for (int i=0; i<n; i++) { if (pixels[i]==127) pixels[i] = (byte)background; else pixels[i] = (byte)foreground; } }
void floodFill() { int x = (int)getFirstArg(); int y = (int)getNextArg(); boolean fourConnected = true; if (interp.nextToken()==',') { String s = getLastString(); if (s.indexOf("8")!=-1) fourConnected = false; } else interp.getRightParen(); ImageProcessor ip = getProcessor(); if (!colorSet) setForegroundColor(ip); FloodFiller ff = new FloodFiller(ip); if (fourConnected) ff.fill(x, y); else ff.fill8(x, y); updateAndDraw(); if (Recorder.record && pgm.hasVars) Recorder.record("floodFill", x, y); }
mask.setColor(255); stackSize = 0; push(x, y); while(true) { x = popx(); if (x ==-1) return; y = popy(); if (!inParticle(x,y,level1,level2)) continue; int x1 = x; int x2 = x; while (inParticle(x1,y,level1,level2) && x1>=0) x1--; // find start of scan-line x1++; while (inParticle(x2,y,level1,level2) && x2<width) x2++; // find end of scan-line x2--; fillLine(mask, x1-bounds.x, x2-bounds.x, y-bounds.y); // fill scan-line i mask fillLine(ip,x1,x2,y); // fill scan-line in image boolean inScanLine = false; if (x1>0) x1--; if (x2<width-1) x2++; for (int i=x1; i<=x2; i++) { // find scan-lines above this one if (!inScanLine && y>0 && inParticle(i,y-1,level1,level2)) {push(i, y-1); inScanLine = true;} else if (inScanLine && y>0 && !inParticle(i,y-1,level1,level2)) inScanLine = false; if (!inScanLine && y<height-1 && inParticle(i,y+1,level1,level2)) {push(i, y+1); inScanLine = true;} else if (inScanLine && y<height-1 && !inParticle(i,y+1,level1,level2)) inScanLine = false;
ImageProcessor ipf = ip.duplicate(); ipf.setValue(fillColor); ff = new FloodFiller(ipf);
pf.setPolygon(proi.getXCoordinates(), proi.getYCoordinates(), proi.getNCoordinates()); ip2.setMask(pf.getMask(r.width, r.height)); if (floodFill) ff.particleAnalyzerFill(x, y, level1, level2, ip2.getMask(), r);
ImageProcessor ipf = ip.duplicate(); ipf.setValue(fillColor); ff = new FloodFiller(ipf);
pf.setPolygon(proi.getXCoordinates(), proi.getYCoordinates(), proi.getNCoordinates()); ip2.setMask(pf.getMask(r.width, r.height)); if (floodFill) ff.particleAnalyzerFill(x, y, level1, level2, ip2.getMask(), r);
mask.setColor(255); stackSize = 0; push(x, y); while(true) { x = popx(); if (x ==-1) return; y = popy(); if (!inParticle(x,y,level1,level2)) continue; int x1 = x; int x2 = x; while (inParticle(x1,y,level1,level2) && x1>=0) x1--; // find start of scan-line x1++; while (inParticle(x2,y,level1,level2) && x2<width) x2++; // find end of scan-line x2--; fillLine(mask, x1-bounds.x, x2-bounds.x, y-bounds.y); // fill scan-line i mask fillLine(ip,x1,x2,y); // fill scan-line in image boolean inScanLine = false; if (x1>0) x1--; if (x2<width-1) x2++; for (int i=x1; i<=x2; i++) { // find scan-lines above this one if (!inScanLine && y>0 && inParticle(i,y-1,level1,level2)) {push(i, y-1); inScanLine = true;} else if (inScanLine && y>0 && !inParticle(i,y-1,level1,level2)) inScanLine = false; if (!inScanLine && y<height-1 && inParticle(i,y+1,level1,level2)) {push(i, y+1); inScanLine = true;} else if (inScanLine && y<height-1 && !inParticle(i,y+1,level1,level2)) inScanLine = false;
void fill(ImageProcessor ip, int foreground, int background) { int width = ip.getWidth(); int height = ip.getHeight(); FloodFiller ff = new FloodFiller(ip); ip.setColor(127); for (int y=0; y<height; y++) { if (ip.getPixel(0,y)==background) ff.fill(0, y); if (ip.getPixel(width-1,y)==background) ff.fill(width-1, y); } for (int x=0; x<width; x++){ if (ip.getPixel(x,0)==background) ff.fill(x, 0); if (ip.getPixel(x,height-1)==background) ff.fill(x, height-1); } byte[] pixels = (byte[])ip.getPixels(); int n = width*height; for (int i=0; i<n; i++) { if (pixels[i]==127) pixels[i] = (byte)background; else pixels[i] = (byte)foreground; } }
void floodFill() { int x = (int)getFirstArg(); int y = (int)getNextArg(); boolean fourConnected = true; if (interp.nextToken()==',') { String s = getLastString(); if (s.indexOf("8")!=-1) fourConnected = false; } else interp.getRightParen(); ImageProcessor ip = getProcessor(); if (!colorSet) setForegroundColor(ip); FloodFiller ff = new FloodFiller(ip); if (fourConnected) ff.fill(x, y); else ff.fill8(x, y); updateAndDraw(); if (Recorder.record && pgm.hasVars) Recorder.record("floodFill", x, y); }
int height = ip.getHeight(); int color = ip.getPixel(x, y); fillLine(ip, x, x, y); int newColor = ip.getPixel(x, y); ip.putPixel(x, y, color); if (color==newColor) return false; stackSize = 0; push(x, y); while(true) { x = popx(); if (x ==-1) return true; y = popy(); if (ip.getPixel(x,y)!=color) continue; int x1 = x; int x2 = x; while (ip.getPixel(x2,y)==color && x2<width) x2++; // find end of scan-line x2--; fillLine(ip, x1,x2,y); // fill scan-line boolean inScanLine = false; for (int i=x1; i<=x2; i++) { // find scan-lines above this one if (!inScanLine && y>0 && ip.getPixel(i,y-1)==color) {push(i, y-1); inScanLine = true;} else if (inScanLine && y>0 && ip.getPixel(i,y-1)!=color) inScanLine = false; for (int i=x1; i<=x2; i++) { // find scan-lines below this one if (!inScanLine && y<height-1 && ip.getPixel(i,y+1)==color) {push(i, y+1); inScanLine = true;} else if (inScanLine && y<height-1 && ip.getPixel(i,y+1)!=color)
/** * Binary fill * @param ip input image * @param foreground foreground value * @param background background value */ public static void fill(ImageProcessor ip, int foreground, int background) { int width = ip.getWidth(); int height = ip.getHeight(); FloodFiller ff = new FloodFiller(ip); ip.setColor(127); for (int y=0; y<height; y++) { if (ip.getPixel(0,y)==background) ff.fill(0, y); if (ip.getPixel(width-1,y)==background) ff.fill(width-1, y); } for (int x=0; x<width; x++){ if (ip.getPixel(x,0)==background) ff.fill(x, 0); if (ip.getPixel(x,height-1)==background) ff.fill(x, height-1); } byte[] pixels = (byte[])ip.getPixels(); int n = width*height; for (int i=0; i<n; i++) { if (pixels[i]==127) pixels[i] = (byte)background; else pixels[i] = (byte)foreground; } }
int wm1=width-1; int hm1=height-1; fillLine(ip, x, x, y); int newColor = ip.getPixel(x, y); ip.putPixel(x, y, color); if (color==newColor) return false; stackSize = 0; push(x, y); while(true) { x = popx(); if (x==-1) return true; y = popy(); int x1 = x; int x2 = x; if(ip.getPixel(x1,y)==color){ while (ip.getPixel(x2,y)==color && x2<width) x2++; // find end of scan-line x2--; fillLine(ip, x1,x2,y); // fill scan-line push(x1-1,y-1); push(x2+1,y-1); if (x1>0){ if (ip.getPixel(x1-1,y+1)==color){ push(x1-1,y+1); push(x2+1,y+1);
/** * Binary fill * @param ip input image * @param foreground foreground value * @param background background value */ public static void fill(ImageProcessor ip, int foreground, int background) { int width = ip.getWidth(); int height = ip.getHeight(); FloodFiller ff = new FloodFiller(ip); ip.setColor(127); for (int y=0; y<height; y++) { if (ip.getPixel(0,y)==background) ff.fill(0, y); if (ip.getPixel(width-1,y)==background) ff.fill(width-1, y); } for (int x=0; x<width; x++){ if (ip.getPixel(x,0)==background) ff.fill(x, 0); if (ip.getPixel(x,height-1)==background) ff.fill(x, height-1); } byte[] pixels = (byte[])ip.getPixels(); int n = width*height; for (int i=0; i<n; i++) { if (pixels[i]==127) pixels[i] = (byte)background; else pixels[i] = (byte)foreground; } }
int wm1=width-1; int hm1=height-1; fillLine(ip, x, x, y); int newColor = ip.getPixel(x, y); ip.putPixel(x, y, color); if (color==newColor) return false; stackSize = 0; push(x, y); while(true) { x = popx(); if (x==-1) return true; y = popy(); int x1 = x; int x2 = x; if(ip.getPixel(x1,y)==color){ while (ip.getPixel(x2,y)==color && x2<width) x2++; // find end of scan-line x2--; fillLine(ip, x1,x2,y); // fill scan-line push(x1-1,y-1); push(x2+1,y-1); if (x1>0){ if (ip.getPixel(x1-1,y+1)==color){ push(x1-1,y+1); push(x2+1,y+1);
int height = ip.getHeight(); int color = ip.getPixel(x, y); fillLine(ip, x, x, y); int newColor = ip.getPixel(x, y); ip.putPixel(x, y, color); if (color==newColor) return false; stackSize = 0; push(x, y); while(true) { x = popx(); if (x ==-1) return true; y = popy(); if (ip.getPixel(x,y)!=color) continue; int x1 = x; int x2 = x; while (ip.getPixel(x2,y)==color && x2<width) x2++; // find end of scan-line x2--; fillLine(ip, x1,x2,y); // fill scan-line boolean inScanLine = false; for (int i=x1; i<=x2; i++) { // find scan-lines above this one if (!inScanLine && y>0 && ip.getPixel(i,y-1)==color) {push(i, y-1); inScanLine = true;} else if (inScanLine && y>0 && ip.getPixel(i,y-1)!=color) inScanLine = false; for (int i=x1; i<=x2; i++) { // find scan-lines below this one if (!inScanLine && y<height-1 && ip.getPixel(i,y+1)==color) {push(i, y+1); inScanLine = true;} else if (inScanLine && y<height-1 && ip.getPixel(i,y+1)!=color)