[gimp] Bug 735902 - Drawing a gradient should never produce negative RGB channel values



commit 1db5c06f54c4bd1dfe196a57be839dbdf97c77f1
Author: Michael Natterer <mitch gimp org>
Date:   Mon Sep 8 22:49:51 2014 +0200

    Bug 735902 - Drawing a gradient should never produce negative RGB channel values
    
    Use MAX(value, 0.0) on the result of dithering.

 app/operations/gimpoperationblend.c |   38 +++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/app/operations/gimpoperationblend.c b/app/operations/gimpoperationblend.c
index 1d9d084..36aa5f6 100644
--- a/app/operations/gimpoperationblend.c
+++ b/app/operations/gimpoperationblend.c
@@ -939,12 +939,18 @@ gradient_put_pixel (gint      x,
 
   if (ppd->dither_rand)
     {
-      gint i = g_rand_int (ppd->dither_rand);
-
-      *dest++ = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
-      *dest++ = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
-      *dest++ = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
-      *dest++ = color->a + (gdouble) (i & 0xff) / 256.0 / 256.0;
+      gfloat r, g, b, a;
+      gint   i = g_rand_int (ppd->dither_rand);
+
+      r = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
+      g = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
+      b = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
+      a = color->a + (gdouble) (i & 0xff) / 256.0 / 256.0;
+
+      *dest++ = MAX (r, 0.0);
+      *dest++ = MAX (g, 0.0);
+      *dest++ = MAX (b, 0.0);
+      *dest++ = MAX (a, 0.0);
     }
   else
     {
@@ -1058,7 +1064,7 @@ gimp_operation_blend_process (GeglOperation       *operation,
 
   if (self->supersample)
     {
-      PutPixelData  ppd = {0, };
+      PutPixelData  ppd = { 0, };
 
       ppd.buffer      = output;
       ppd.row_data    = g_malloc (sizeof (float) * 4 * result->width);
@@ -1097,8 +1103,8 @@ gimp_operation_blend_process (GeglOperation       *operation,
       while (gegl_buffer_iterator_next (iter))
         {
           gfloat *dest = iter->data[0];
-          gint    endx  = roi->x + roi->width;
-          gint    endy  = roi->y + roi->height;
+          gint    endx = roi->x + roi->width;
+          gint    endy = roi->y + roi->height;
           gint    x, y;
 
           if (rbd.seed)
@@ -1109,14 +1115,20 @@ gimp_operation_blend_process (GeglOperation       *operation,
                 for (x = roi->x; x < endx; x++)
                   {
                     GimpRGB  color = { 0.0, 0.0, 0.0, 1.0 };
+                    gfloat   r, g, b, a;
                     gint     i = g_rand_int (dither_rand);
 
                     gradient_render_pixel (x, y, &color, &rbd);
 
-                    *dest++ = color.r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
-                    *dest++ = color.g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
-                    *dest++ = color.b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
-                    *dest++ = color.a + (gdouble) (i & 0xff) / 256.0 / 256.0;
+                    r = color.r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
+                    g = color.g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
+                    b = color.b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
+                    a = color.a + (gdouble) (i & 0xff) / 256.0 / 256.0;
+
+                    *dest++ = MAX (r, 0.0);
+                    *dest++ = MAX (g, 0.0);
+                    *dest++ = MAX (b, 0.0);
+                    *dest++ = MAX (a, 0.0);
                   }
 
               g_rand_free (dither_rand);


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