diff --git a/pipi/dither.c b/pipi/dither.c index d6c179d..4496c0e 100644 --- a/pipi/dither.c +++ b/pipi/dither.c @@ -25,32 +25,34 @@ #include "pipi.h" #include "pipi_internals.h" +/* FIXME: this is not the right place for this... see pixels.c instead */ void pipi_dither_24to16(pipi_image_t *img) { -/* XXX: disabled because this is not the right place... see pixels.c instead */ -#if 0 int *error, *nexterror; + pipi_pixels_t *p; uint32_t *p32; int x, y; - error = malloc(sizeof(int) * 3 * (img->width + 2)); - nexterror = malloc(sizeof(int) * 3 * (img->width + 2)); - p32 = (uint32_t *)img->pixels; + error = malloc(sizeof(int) * 3 * (img->w + 2)); + nexterror = malloc(sizeof(int) * 3 * (img->w + 2)); + p = pipi_get_pixels(img, PIPI_PIXELS_RGBA_U8); + p32 = (uint32_t *)p->pixels; - memset(error, 0, sizeof(int) * 3 * (img->width + 2)); + memset(error, 0, sizeof(int) * 3 * (img->w + 2)); - for(y = 0; y < img->height; y++) + for(y = 0; y < img->h; y++) { int er = 0, eg = 0, eb = 0; - memset(nexterror, 0, sizeof(int) * 3 * (img->width + 2)); + memset(nexterror, 0, sizeof(int) * 3 * (img->w + 2)); - for(x = 0; x < img->width; x++) + for(x = 0; x < img->w; x++) { - int r, g, b, r2, g2, b2; - r = p32[y * img->width + x] & 0xff; - g = (p32[y * img->width + x] >> 8) & 0xff; - b = (p32[y * img->width + x] >> 16) & 0xff; + int r, g, b, a, r2, g2, b2; + r = p32[y * img->w + x] & 0xff; + g = (p32[y * img->w + x] >> 8) & 0xff; + b = (p32[y * img->w + x] >> 16) & 0xff; + a = (p32[y * img->w + x] >> 24) & 0xff; r += er + error[x * 3 + 3]; g += eg + error[x * 3 + 4]; b += eb + error[x * 3 + 5]; @@ -61,7 +63,7 @@ void pipi_dither_24to16(pipi_image_t *img) /* hack */ if(r2 == 0x88 && g2 == 0x88 && b2 == 0x88) g2 = 0x84; /* hack */ - p32[y * img->width + x] = (b2 << 16) | (g2 << 8) | r2; + p32[y * img->w + x] = (a << 24) | (b2 << 16) | (g2 << 8) | r2; er = r - (r2 / 8 * 255 / 31); eg = g - (g2 / 4 * 255 / 63); @@ -80,11 +82,12 @@ void pipi_dither_24to16(pipi_image_t *img) eb -= eb * 3 / 8 + eb * 7 / 8 + eb * 1 / 8; } - memcpy(error, nexterror, sizeof(int) * 3 * (img->width + 2)); + memcpy(error, nexterror, sizeof(int) * 3 * (img->w + 2)); } + pipi_release_pixels(img, p); + free(error); free(nexterror); -#endif }