[gegl] lowbit-dither: fix to vanish when converting back to 8bpc



commit 48803a24305b6155fb32f84bfa5972ee0d1df599
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Dec 21 00:36:00 2016 +0100

    lowbit-dither: fix to vanish when converting back to 8bpc
    
    scaling the -0.5 - 0.5 mask range by 1/256.0 instead of 1/255.0 now, makes the
    result a no-op when applied to an "R'G'B' u8" layer in GIMP - which means the
    op acts as intended.

 operations/workshop/lowbit-dither.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/operations/workshop/lowbit-dither.c b/operations/workshop/lowbit-dither.c
index ac9cb7a..1c32aef 100644
--- a/operations/workshop/lowbit-dither.c
+++ b/operations/workshop/lowbit-dither.c
@@ -58,22 +58,29 @@ process (GeglOperation       *operation,
     {
       int ch;
       for (ch = 0; ch < 4; ch++)
-      {
-       if (in_pixel [ch] > 0.0000001f && in_pixel [ch] < 1.0000000f)
-         out_pixel [ch] = in_pixel [ch] + ((((((x+ch * 67) + y * 236) * 119) & 255)/255.0f)-0.5f )/255.0f;
-         /* this computes an 8bit http://pippin.gimp.org/a_dither/ mask */
-       else
-         out_pixel [ch] = in_pixel [ch];
-      }
-      out_pixel += 4;
-      in_pixel  += 4;
-
-      /* update x and y coordinates */
-      if (++x>=roi->x + roi->width)
         {
-          x=roi->x;
-          y++;
+          if (in_pixel [ch] > 0.0000001f && in_pixel [ch] < 1.0000000f)
+            {
+              /* this computes an 8bit http://pippin.gimp.org/a_dither/ mask */
+              float a_dither = 
+                ((((((x+ch * 67) + y * 236) * 119) & 255)/255.0f)-0.5f) *
+                   (1.0f/256.0f);
+              out_pixel [ch] = in_pixel [ch] + a_dither;
+            }
+          else
+            {
+              out_pixel [ch] = in_pixel [ch];
+            }
         }
+        out_pixel += 4;
+        in_pixel  += 4;
+
+        /* update x and y coordinates */
+        if (++x>=roi->x + roi->width)
+          {
+            x=roi->x;
+            y++;
+          }
     }
 
   return  TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]