[PATCH] A lost patch for bug 306029



Hello gtk'ers,

I was looking through my old bookmarks
and found this one:

http://bugzilla.gnome.org/show_bug.cgi?id=306029

I filed that one. Seems like it was not noticed yet,
after one year.

gtk-2.8.13's  pixops/pixops.c::process_pixel is still
the same and can still be optimized.

Please apply attached.
--
vda
diff -urpN gtk+-2.8.13/gdk-pixbuf/pixops/pixops.c gtk+-2.8.13.new/gdk-pixbuf/pixops/pixops.c
--- gtk+-2.8.13/gdk-pixbuf/pixops/pixops.c	Tue Jul 12 18:58:57 2005
+++ gtk+-2.8.13.new/gdk-pixbuf/pixops/pixops.c	Fri May  5 10:28:04 2006
@@ -939,34 +939,63 @@ process_pixel (int *weights, int n_x, in
 	       PixopsPixelFunc pixel_func)
 {
   unsigned int r = 0, g = 0, b = 0, a = 0;
+  unsigned int ta;
+  guchar *q;
   int i, j;
   
-  for (i=0; i<n_y; i++)
+  if (src_has_alpha)
     {
-      int *line_weights  = weights + n_x * i;
-
-      for (j=0; j<n_x; j++)
+      for (i=0; i<n_y; i++)
 	{
-	  unsigned int ta;
-	  guchar *q;
-
-	  if (x_start + j < 0)
-	    q = src[i];
-	  else if (x_start + j < src_width)
-	    q = src[i] + (x_start + j) * src_channels;
-	  else
-	    q = src[i] + (src_width - 1) * src_channels;
+	  int *line_weights = weights + n_x * i;
+	  int x_end = x_start + n_x;
 
-	  if (src_has_alpha)
-	    ta = q[3] * line_weights[j];
-	  else
-	    ta = 0xff * line_weights[j];
+	  if (x_start<=0) q = src[i];
+	  else if (x_start<src_width) q = src[i] + x_start * src_channels;
+	  else q = src[i] + (src_width-1) * src_channels;
+    
+	  j = x_start;
+	  while(j < x_end)
+	    {
+	      ta = q[3] * (*line_weights++);
+	      r += ta * q[0];
+	      g += ta * q[1];
+	      b += ta * q[2];
+	      a += ta;
+	      j++;
+	      if (j>0 && j<src_width)
+	        q += src_channels;
+	    }
+	}
+    }
+  else
+    {
+      for (i=0; i<n_y; i++)
+	{
+	  int *line_weights = weights + n_x * i;
+	  int x_end = x_start + n_x;
 
-	  r += ta * q[0];
-	  g += ta * q[1];
-	  b += ta * q[2];
-	  a += ta;
+	  if (x_start<=0) q = src[i];
+	  else if (x_start<src_width) q = src[i] + x_start * src_channels;
+	  else q = src[i] + (src_width-1) * src_channels;
+    
+	  j = x_start;
+	  while(j < x_end)
+	    {
+	      ta = *line_weights++; /* x 255 alpha value: done later */
+	      r += ta * q[0];
+	      g += ta * q[1];
+	      b += ta * q[2];
+	      a += ta;
+	      j++;
+	      if (j>0 && j<src_width)
+	        q += src_channels;
+	    }
 	}
+      r *= 0xff; /* alpha: completely opaque */
+      g *= 0xff;
+      b *= 0xff;
+      a *= 0xff;
     }
 
   (*pixel_func) (dest, dest_x, dest_channels, dest_has_alpha, src_has_alpha, check_size, color1, color2, r, g, b, a);


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