Browse Source

* floydsteinberg.c: perform Floyd-Steinberg dithering on a serpentine path.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2653 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 years ago
parent
commit
2182fdfdbf
1 changed files with 10 additions and 6 deletions
  1. +10
    -6
      pipi/dither/floydsteinberg.c

+ 10
- 6
pipi/dither/floydsteinberg.c View File

@@ -44,21 +44,25 @@ pipi_image_t *pipi_floydsteinberg(pipi_image_t *src)
for(x = 0; x < w; x++) for(x = 0; x < w; x++)
{ {
float p, q, e; float p, q, e;
int x2 = (y & 1) ? x : w - 1 - x;
int s = (y & 1) ? 1 : -1;


p = srcdata[y * w + x];
p = srcdata[y * w + x2];
q = p < 0.5 ? 0. : 1.; q = p < 0.5 ? 0. : 1.;
dstdata[y * w + x] = q;
dstdata[y * w + x2] = q;


/* FIXME: according to our 2008 paper, [7 4 5 0] is a better
* error diffusion kernel for serpentine scan. */
e = p - q; e = p - q;
if(x < w - 1) if(x < w - 1)
srcdata[y * w + x + 1] += e * .4375;
srcdata[y * w + x2 + s] += e * .4375;
if(y < h - 1) if(y < h - 1)
{ {
if(x > 0) if(x > 0)
srcdata[(y + 1) * w + x - 1] += e * .1875;
srcdata[(y + 1) * w + x] += e * .3125;
srcdata[(y + 1) * w + x2 - s] += e * .1875;
srcdata[(y + 1) * w + x2] += e * .3125;
if(x < w - 1) if(x < w - 1)
srcdata[(y + 1) * w + x + 1] += e * .0625;
srcdata[(y + 1) * w + x2 + s] += e * .0625;
} }
} }
} }


Loading…
Cancel
Save