[gimp/gimp-2-6] plug-ins: Fix preview in Difference of Gaussians



commit b0868e3eef076e8aadbf6726ee9cd9938c2ff524
Author: Seth Burgess <sjburges gimp org>
Date:   Mon Sep 13 02:08:05 2010 +0200

    plug-ins: Fix preview in Difference of Gaussians
    
    Implement invert as part of normalize routine - See Bug 557380
    (cherry picked from commit 0382fdb45de2d9f05157327295c873a84b5b8f8d)

 plug-ins/common/edge-dog.c |   41 +++++++++++++++++++++++++++--------------
 1 files changed, 27 insertions(+), 14 deletions(-)
---
diff --git a/plug-ins/common/edge-dog.c b/plug-ins/common/edge-dog.c
index c3f8120..9af60ba 100644
--- a/plug-ins/common/edge-dog.c
+++ b/plug-ins/common/edge-dog.c
@@ -70,8 +70,10 @@ static void      compute_difference   (GimpDrawable *drawable,
                                        GimpDrawable *drawable2,
                                        guchar       *maxval);
 
-static void      normalize            (GimpDrawable *drawable,
-                                       guint         maxval);
+static void      normalize_invert     (GimpDrawable *drawable,
+                                       gboolean      normalize,
+                                       guint         maxval,
+                                       gboolean      invert);
 
 static void      dog                  (gint32        image_ID,
                                        GimpDrawable *drawable,
@@ -493,16 +495,16 @@ dog (gint32        image_ID,
   gimp_drawable_merge_shadow (drawable_id, TRUE);
   gimp_drawable_update (drawable_id, x1, y1, width, height);
 
-  if (dogvals.normalize)
+  if (dogvals.normalize || dogvals.invert)
+    /* gimp_invert doesn't work properly with previews due to shadow handling
+     * so reimplement it here - see Bug 557380
+     */
     {
-      normalize (drawable, maxval);
+      normalize_invert (drawable, dogvals.normalize, maxval, dogvals.invert);
       gimp_drawable_flush (drawable);
       gimp_drawable_merge_shadow (drawable_id, TRUE);
       gimp_drawable_update (drawable_id, x1, y1, width, height);
     }
-
-  if (dogvals.invert)
-    gimp_invert (drawable_id);
 }
 
 
@@ -593,8 +595,10 @@ compute_difference (GimpDrawable *drawable,
 
 
 static void
-normalize (GimpDrawable *drawable,
-           guint         maxval)
+normalize_invert (GimpDrawable *drawable,
+                  gboolean      normalize,
+                  guint         maxval,
+                  gboolean      invert)
 {
   GimpPixelRgn src_rgn, dest_rgn;
   gint         bpp;
@@ -604,10 +608,11 @@ normalize (GimpDrawable *drawable,
   gboolean     has_alpha;
   gdouble      factor;
 
-  if (maxval == 0)
-    return;
+  if (normalize && maxval != 0) {
+      factor = 255.0 / maxval;
+    }
   else
-    factor = 255.0 / maxval;
+    factor = 1.0;
 
   gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
   bpp = drawable->bpp;
@@ -640,12 +645,20 @@ normalize (GimpDrawable *drawable,
               if (has_alpha)
                 {
                   for (k = 0; k < bpp-1; k++)
-                    d[k] = factor * s[k];
+                    {
+                      d[k] = factor * s[k];
+                      if (invert)
+                        d[k] = 255 - d[k];
+                    }
                 }
               else
                 {
                   for (k = 0; k < bpp; k++)
-                    d[k] = factor * s[k];
+                    {
+                      d[k] = factor * s[k];
+                      if (invert)
+                        d[k] = 255 - d[k];
+                    }
                 }
 
               s += bpp;



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