[gs-cvs] rev 8539 - trunk/gs/src

leonardo at ghostscript.com leonardo at ghostscript.com
Fri Feb 22 12:18:09 PST 2008


Author: leonardo
Date: 2008-02-22 12:18:08 -0800 (Fri, 22 Feb 2008)
New Revision: 8539

Modified:
   trunk/gs/src/gdevm24.c
   trunk/gs/src/gsimage.c
   trunk/gs/src/gxiscale.c
   trunk/gs/src/lib.mak
   trunk/gs/src/siscale.c
Log:
Fix (images) : Improve coordinate precision when scaling an image (continued 6).

DETAILS :

Ghostscript Bug 687345 "Image interpolation problem at a band boundary"
Ghostscript Bug 689718 "Regression: differences in FIG3.eps".

1. siscale.c : The revision 8529 patch part 4 tried to represent 'ceil' with rational 
arithmetics. But when downsampling the argument still uses a floating
number WidthIn, so we still need 'ceil'. 
This patch converts the formula back to floats, 
assuming that double precision is enough for precise result 
because source image size usually is smaller than 2^24.

The wrong rational representation of 'ceil' caused an array element index 
to fall outside the array. Debugged with FIG3.eps.

2. Improved debug printing and visual trace.

EXPECTED DIFFERENCES :

The patch fixes regression with FIG3.eps .

Also it causes minor raster differences with following files :

"148-11.ps" 
"A-12-3480-0109-5.pdf" 
"B-12-3077-1831-7-001.pdf"
"C-12-2706-0239-9-001.pdf" 
"john_clippedimage.pdf"
"mspro.pdf" 


Modified: trunk/gs/src/gdevm24.c
===================================================================
--- trunk/gs/src/gdevm24.c	2008-02-22 10:29:49 UTC (rev 8538)
+++ trunk/gs/src/gdevm24.c	2008-02-22 20:18:08 UTC (rev 8539)
@@ -108,7 +108,7 @@
     declare_unpack_color(r, g, b, color);
     declare_scan_ptr(dest);
 
-    if_debug2('b', "[b]device y=%d h=%d\n", y + mdev->band_y, h);
+    if_debug4('b', "[b]device y=%d h=%d x=%d w=%d\n", y + mdev->band_y, h, x, w);
     /*
      * In order to avoid testing w > 0 and h > 0 twice, we defer
      * executing setup_rect, and use fit_fill_xywh instead of

Modified: trunk/gs/src/gsimage.c
===================================================================
--- trunk/gs/src/gsimage.c	2008-02-22 10:29:49 UTC (rev 8538)
+++ trunk/gs/src/gsimage.c	2008-02-22 20:18:08 UTC (rev 8539)
@@ -28,6 +28,7 @@
 #include "gximask.h"
 #include "gzstate.h"
 #include "gsutil.h"
+#include "vdtrace.h"
 
 /*
   The main internal invariant for the gs_image machinery is
@@ -477,6 +478,10 @@
     int code = 0;
 
 #ifdef DEBUG
+    vd_get_dc('i');
+    vd_set_shift(0, 0);
+    vd_set_scale(0.01);
+    vd_set_origin(0, 0);
     if (gs_debug_c('b')) {
 	int pi;
 
@@ -607,6 +612,7 @@
     /* Return the retained data pointers. */
     for (i = 0; i < num_planes; ++i)
 	plane_data[i] = penum->planes[i].source;
+    vd_release_dc;
     return code;
 }
 

Modified: trunk/gs/src/gxiscale.c
===================================================================
--- trunk/gs/src/gxiscale.c	2008-02-22 10:29:49 UTC (rev 8538)
+++ trunk/gs/src/gxiscale.c	2008-02-22 20:18:08 UTC (rev 8539)
@@ -348,6 +348,7 @@
 			    case 3:
 				do {
 				    LINE_ACCUM(color, bpp);
+				    vd_pixel(int2fixed(x), int2fixed(ry), color);
 				    x++, psrc += 3;
 				} while (x < xe && psrc[-4] == psrc[0] &&
 				     psrc[-3] == psrc[1] && psrc[-2] == psrc[2] &&

Modified: trunk/gs/src/lib.mak
===================================================================
--- trunk/gs/src/lib.mak	2008-02-22 10:29:49 UTC (rev 8538)
+++ trunk/gs/src/lib.mak	2008-02-22 20:18:08 UTC (rev 8539)
@@ -842,7 +842,8 @@
 
 $(GLOBJ)gsimage.$(OBJ) : $(GLSRC)gsimage.c $(GXERR) $(memory__h) $(math__h)\
  $(gscspace_h) $(gsimage_h) $(gsmatrix_h) $(gsstruct_h) $(gsptype2_h)\
- $(gxarith_h) $(gxdevice_h) $(gxiparam_h) $(gxpath_h) $(gximask_h) $(gzstate_h)
+ $(gxarith_h) $(gxdevice_h) $(gxiparam_h) $(gxpath_h) $(gximask_h) $(gzstate_h)\
+ $(vdtrace_h)
 	$(GLCC) $(GLO_)gsimage.$(OBJ) $(C_) $(GLSRC)gsimage.c
 
 $(GLOBJ)gsimpath.$(OBJ) : $(GLSRC)gsimpath.c $(GXERR)\

Modified: trunk/gs/src/siscale.c
===================================================================
--- trunk/gs/src/siscale.c	2008-02-22 10:29:49 UTC (rev 8538)
+++ trunk/gs/src/siscale.c	2008-02-22 20:18:08 UTC (rev 8539)
@@ -219,8 +219,8 @@
 	int center_denom = dst_size; 
 	int64_t center_num = /* center * center_denom = */ 
 	    (starting_output_index  + i) * src_size + dst_y_offset_fraction_num - (center_denom / 2);
-	int left = (int)((center_num - WidthIn * center_denom + (center_denom - 1)) / center_denom);
-	int right = (int)((center_num + WidthIn * center_denom) / center_denom);
+	int left = (int)ceil((center_num - WidthIn * center_denom) / center_denom);
+	int right = (int)floor((center_num + WidthIn * center_denom) / center_denom);
 	double center = (double)center_num / center_denom;
 #define clamp_pixel(j) (j < 0 ? 0 : j >= limit ? limit - 1 : j)
 	int first_pixel = clamp_pixel(left);
@@ -374,7 +374,21 @@
     if (sizeofPixelOut == 1) {
 	zoom_y_loop(byte)
     } else {			/* sizeofPixelOut == 2 */
-	zoom_y_loop(bits16)
+	//zoom_y_loop(bits16)
+	for ( kc = 0; kc < kn; ++kc ) {
+		AccumTmp weight = 0;
+		{ const PixelTmp *pp = &tmp[kc + first_pixel];
+		  int j = cn;
+		  const CONTRIB *cp = cbp;
+		  for ( ; j > 0; pp += kn, ++cp, --j )
+		    weight += *pp * cp->weight;
+		}
+		{ PixelTmp2 pixel = unscale_AccumTmp(weight, fraction_bits);
+		  if_debug1('W', " %lx", (long)pixel);
+		  ((bits16 *)dst)[kc] =
+		    (bits16)CLAMP(pixel, 0, max_weight);
+		}
+	}
     }
     if_debug0('W', "\n");
 }



More information about the gs-cvs mailing list