root/trunk/processing/sketches/modest_maps_lib/atkinson.pde

Revision 499, 0.8 kB (checked in by tom, 9 months ago)

working Processing sketches and library-ready src folder

Line 
1
2 PImage atkinsonDither(PImage toDither) {
3
4   PImage img = createImage(toDither.width, toDither.height, ARGB);
5   img.copy(toDither, 0, 0, toDither.width, toDither.height, 0, 0, toDither.width, toDither.height);
6  
7   img.loadPixels();
8  
9   for (int y = 0; y < img.height; y++) {
10     for (int x = 0; x < img.width; x++) {
11
12       int old = (int)brightness(img.get(x, y));
13       int nu = old < 128 ? 0 : 255;
14       int err = (old - nu) >> 3; // divide by 8
15
16       img.set(x, y, color(nu));
17
18       int neighbors = 6;
19       int nx[] = { x+1, x+2, x-1, x, x+1, x };
20       int ny[] = { y, y, y+1, y+1, y+1, y+2 };
21
22       for (int n = 0; n < neighbors; n++) {
23         img.set(nx[n], ny[n], color( brightness(img.get(nx[n], ny[n])) + err));
24       }
25     }
26   }
27
28   img.updatePixels();
29
30   return img; 
31 }
Note: See TracBrowser for help on using the browser.