pixbuf scaling



Hi Owen, 

I think I found the reason for the recent problems with pixbuf scaling:
Your correction to force the weights to sum to 65536 can make the last
weight negative, which is not well received by the line functions which 
operate on unsigned variables.

I have appended an impressive demonstration of the problem (
gtk+/demos/testpixbuf-scale gtk+/gtk/stock-icons/dialog_warning.png
) and a possible fix.

Matthias 

Attachment: 2002_02_14_224730_shot.png
Description: current cvs

Attachment: 2002_02_14_224936_shot.png
Description: with the patch

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 21:52:33
@@ -1193,6 +1193,7 @@ bilinear_make_fast_weights (PixopsFilter
 	double y = (double)i_offset / SUBSAMPLE;
 	int i,j;
 	int total = 0;
+	int correction;
 	
 	if (x_scale > 1.0)	/* Bilinear */
 	  {
@@ -1266,7 +1267,13 @@ bilinear_make_fast_weights (PixopsFilter
 	      total += weight;
 	    }
 
-	*(pixel_weights + n_x * n_y - 1) += (int)(0.5 + 65536 * overall_alpha) - total;
+	correction = (int)(0.5 + 65536 * overall_alpha) - total;
+	for (i = n_x * n_y - 1; i >= 0; i--) {
+	  if (*(pixel_weights + i) + correction >= 0) {
+	    *(pixel_weights + i) += correction;
+	    break;
+	  }
+	}
       }
 
   g_free (x_weights);
@@ -1352,6 +1359,7 @@ bilinear_make_weights (PixopsFilter *fil
 	double y = (double)i_offset / SUBSAMPLE;
 	int i,j;
 	int total = 0;
+	int correction;
 	
 	for (i = 0; i < n_y; i++)
 	  for (j = 0; j < n_x; j++)
@@ -1368,7 +1376,13 @@ bilinear_make_weights (PixopsFilter *fil
 	      total += weight;
 	    }
 
-	*(pixel_weights + n_x * n_y - 1) += (int)(0.5 + 65536 * overall_alpha) - total;
+	correction = (int)(0.5 + 65536 * overall_alpha) - total;
+	for (i = n_x * n_y - 1; i >= 0; i--) {
+	  if (*(pixel_weights + i) + correction >= 0) {
+	    *(pixel_weights + i) += correction;
+	    break;
+	  }
+	}
       }
 }
 


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