Re: pixbuf scaling



Here is a corrected version of the patch. Unfortunately, I'm not
very good at making up names for helper functions...

Matthias


Index: pixops.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk-pixbuf/pixops/pixops.c,v
retrieving revision 1.25
diff -u -b -B -p -r1.25 pixops.c
--- pixops.c	2002/02/11 19:36:12	1.25
+++ pixops.c	2002/02/14 22:54:06
@@ -1077,6 +1077,20 @@ pixops_process (guchar         *dest_buf
   g_free (line_bufs);
 }
 
+static void correct_total (int *weights, int n, int total, double overall_alpha)
+{
+  int correction = (int)(0.5 + 65536 * overall_alpha) - total;
+  int i;
+  for (i = n - 1; i >= 0; i--) 
+    {
+      if (*(weights + i) + correction >= 0) 
+	{
+	  *(weights + i) += correction;
+	  break;
+	}
+    }
+}  
+
 static void
 tile_make_weights (PixopsFilter *filter, double x_scale, double y_scale, double overall_alpha)
 {
@@ -1144,7 +1158,7 @@ tile_make_weights (PixopsFilter *filter,
 		*(pixel_weights + n_x * i + j) = weight;
 	      }
 
-	    *(pixel_weights + n_x * n_y - 1) += (int)(0.5 + 65536 * overall_alpha) - total;
+	    correct_total (pixel_weights, n_x * n_y, total, overall_alpha);
 	  }
       }
 }
@@ -1266,7 +1280,7 @@ bilinear_make_fast_weights (PixopsFilter
 	      total += weight;
 	    }
 
-	*(pixel_weights + n_x * n_y - 1) += (int)(0.5 + 65536 * overall_alpha) - total;
+	correct_total (pixel_weights, n_x * n_y, total, overall_alpha);
       }
 
   g_free (x_weights);
@@ -1368,7 +1382,7 @@ bilinear_make_weights (PixopsFilter *fil
 	      total += weight;
 	    }
 
-	*(pixel_weights + n_x * n_y - 1) += (int)(0.5 + 65536 * overall_alpha) - total;
+	correct_total (pixel_weights, n_x * n_y, total, overall_alpha);
       }
 }
 


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