gimp r26524 - in trunk: . app/paint-funcs



Author: neo
Date: Tue Aug 12 20:01:19 2008
New Revision: 26524
URL: http://svn.gnome.org/viewvc/gimp?rev=26524&view=rev

Log:
2008-08-12  Sven Neumann  <sven gimp org>

	* app/paint-funcs/paint-funcs.c (replace_inten_pixels): applied 
a
	slightly modified version of the patch from Luidnel Maignan as
	attached to bug #105568. Fixes incorrect alpha treatment in
	plug-in selection masking.



Modified:
   trunk/ChangeLog
   trunk/app/paint-funcs/paint-funcs.c

Modified: trunk/app/paint-funcs/paint-funcs.c
==============================================================================
--- trunk/app/paint-funcs/paint-funcs.c	(original)
+++ trunk/app/paint-funcs/paint-funcs.c	Tue Aug 12 20:01:19 2008
@@ -1391,6 +1391,8 @@
  *  The operation is still bounded by mask/opacity constraints
  */
 
+#define INT_DIV(a, b) ((a)/(b) + (((a) % (b)) > ((b) / 2)))
+
 static inline void
 replace_inten_pixels (const guchar   *src1,
                       const guchar   *src2,
@@ -1402,54 +1404,57 @@
                       guint           bytes1,
                       guint           bytes2)
 {
-  const guint has_alpha1 = HAS_ALPHA (bytes1);
-  const guint has_alpha2 = HAS_ALPHA (bytes2);
-  const guint bytes      = MIN (bytes1, bytes2);
-  guint b;
-  gint  tmp;
+  const guint   has_alpha1 = HAS_ALPHA (bytes1);
+  const guint   has_alpha2 = HAS_ALPHA (bytes2);
+  const guint   alpha      = bytes1 - has_alpha1;
+  const guint   alpha2     = bytes2 - has_alpha2;
+  const guchar *m          = mask ? mask : &no_mask;
+  guint         b;
+  gint          tmp;
 
-  if (mask)
+  while (length --)
     {
-      const guchar *m = mask;
+      guchar src1_alpha  = has_alpha1 ? src1[alpha]  : 255;
+      guchar src2_alpha  = has_alpha2 ? src2[alpha2] : 255;
+      guchar new_alpha   = INT_BLEND (src2_alpha, src1_alpha,
+                                      INT_MULT (*m, opacity, tmp), tmp);
 
-      while (length --)
+      if (new_alpha && affect[b])
         {
-          guchar mask_alpha = INT_MULT (*m, opacity, tmp);
+          guint ratio = *m * opacity;
 
-          for (b = 0; b < bytes; b++)
-            dest[b] = (affect[b] ?
-                       INT_BLEND (src2[b], src1[b], mask_alpha, tmp) :
-                       src1[b]);
+          ratio = INT_DIV (ratio, new_alpha);
 
-          if (has_alpha1 && !has_alpha2)
+          for (b = 0; b < alpha; b++)
+            {
+              if (src2[b] > src1[b])
+                {
+                  guint t = (src2[b] - src1[b]) * ratio;
+                  dest[b] = src1[b] + INT_DIV (t, 255);
+                }
+              else
+                {
+                  guint t = (src1[b] - src2[b]) * ratio;
+                  dest[b] = src1[b] - INT_DIV (t, 255);
+                }
+            }
+        }
+      else
+        {
+          for (b = 0; b < alpha; b++)
             dest[b] = src1[b];
-
-          m++;
-
-          src1 += bytes1;
-          src2 += bytes2;
-          dest += bytes1;
         }
-    }
-  else
-    {
-      const guchar mask_alpha = opacity;
 
-      while (length --)
-        {
-          for (b = 0; b < bytes; b++)
-            dest[b] = (affect[b] ?
-                       INT_BLEND (src2[b], src1[b], mask_alpha, tmp) :
-                       src1[b]);
+      if (has_alpha1)
+        dest[alpha] = affect[alpha] ? new_alpha : src1[alpha];
 
-          if (has_alpha1 && !has_alpha2)
-            dest[b] = src1[b];
+      if (mask)
+        m++;
 
-          src1 += bytes1;
-          src2 += bytes2;
-          dest += bytes1;
-        }
-    }
+      src1 += bytes1;
+      src2 += bytes2;
+      dest += bytes1;
+   }
 }
 
 /*  replace the contents of one pixel row with the other



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