From f3a19b6ce5ff52cc3a83b63e4285fcd537cfb04d Mon Sep 17 00:00:00 2001
From: sam <sam@92316355-f0b4-4df1-b90c-862c8a59935f>
Date: Mon, 25 Aug 2008 23:39:20 +0000
Subject: [PATCH]   * pixels.c: allow to call pipi_getpixels with
 PIPI_PIXELS_MASK_C.   * pixels.c: simplify Floyd-Steinberg coefficients.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2773 92316355-f0b4-4df1-b90c-862c8a59935f
---
 pipi/pixels.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/pipi/pixels.c b/pipi/pixels.c
index 3f11837..da3e371 100644
--- a/pipi/pixels.c
+++ b/pipi/pixels.c
@@ -48,6 +48,10 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
     if(img->last_modified == type)
         return &img->p[type];
 
+    /* Handle special cases */
+    if(type == PIPI_PIXELS_MASK_C)
+        return &img->p[type];
+
     /* Preliminary conversions */
     if(img->last_modified == PIPI_PIXELS_RGBA_C
                   && type == PIPI_PIXELS_Y_F)
@@ -152,16 +156,16 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
 
                     dest[4 * (y * img->w + x) + i] = d;
 
-                    e = p - u8tof32(d);
+                    e = (p - u8tof32(d)) / 8;
                     if(x < img->w - 1)
-                        src[4 * (y * img->w + x + 1) + i] += e * .4375;
+                        src[4 * (y * img->w + x + 1) + i] += e * 7;
                     if(y < img->h - 1)
                     {
                         if(x > 0)
-                            src[4 * ((y + 1) * img->w + x - 1) + i] += e * .1875;
-                        src[4 * ((y + 1) * img->w + x) + i] += e * .3125;
+                            src[4 * ((y + 1) * img->w + x - 1) + i] += e * 3;
+                        src[4 * ((y + 1) * img->w + x) + i] += e * 5;
                         if(x < img->w - 1)
-                            src[4 * ((y + 1) * img->w + x + 1) + i] += e * .0625;
+                            src[4 * ((y + 1) * img->w + x + 1) + i] += e;
                     }
                 }
     }
@@ -188,16 +192,16 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
 
                     dest[3 * (y * img->w + x) + i] = d;
 
-                    e = p - u8tof32(d);
+                    e = (p - u8tof32(d));
                     if(x < img->w - 1)
-                        src[4 * (y * img->w + x + 1) + i] += e * .4375;
+                        src[4 * (y * img->w + x + 1) + i] += e * 7;
                     if(y < img->h - 1)
                     {
                         if(x > 0)
-                            src[4 * ((y + 1) * img->w + x - 1) + i] += e * .1875;
-                        src[4 * ((y + 1) * img->w + x) + i] += e * .3125;
+                            src[4 * ((y + 1) * img->w + x - 1) + i] += e * 3;
+                        src[4 * ((y + 1) * img->w + x) + i] += e * 5;
                         if(x < img->w - 1)
-                            src[4 * ((y + 1) * img->w + x + 1) + i] += e * .0625;
+                            src[4 * ((y + 1) * img->w + x + 1) + i] += e;
                     }
                 }
     }