| 189 | // Binary fill by Gabriel Landini, G.Landini at bham.ac.uk |
| 190 | // 21/May/2008 |
| 191 | void fill(ImageProcessor ip, int foreground, int background) { |
| 192 | int width = ip.getWidth(); |
| 193 | int height = ip.getHeight(); |
| 194 | FloodFiller ff = new FloodFiller(ip); |
| 195 | ip.setColor(127); |
| 196 | for (int y=0; y<height; y++) { |
| 197 | if (ip.getPixel(0,y)==background) ff.fill(0, y); |
| 198 | if (ip.getPixel(width-1,y)==background) ff.fill(width-1, y); |
| 199 | } |
| 200 | for (int x=0; x<width; x++){ |
| 201 | if (ip.getPixel(x,0)==background) ff.fill(x, 0); |
| 202 | if (ip.getPixel(x,height-1)==background) ff.fill(x, height-1); |
| 203 | } |
| 204 | byte[] pixels = (byte[])ip.getPixels(); |
| 205 | int n = width*height; |
| 206 | for (int i=0; i<n; i++) { |
| 207 | if (pixels[i]==127) |
| 208 | pixels[i] = (byte)background; |
| 209 | else |
| 210 | pixels[i] = (byte)foreground; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | } |