Opened 10 years ago

Closed 10 years ago

#4775 closed defect (fixed)

PDFDriver float->int conversion problem observed on RH6 / GCC4.4.5 / x32 / Release (only)

Reported by: mrosen Owned by: warmerdam
Priority: normal Milestone: 1.10.0
Component: default Version: unspecified
Severity: normal Keywords:


We build GDAL and this driver (1.9 but driver patched to trunk) on many different gcc versions in both debug and release. we observed a failure on gcc 4.4.5 / release / x32 only. The fix turns out to be more robust conversion between float and int.

The attached file should manifest the problem: gdalinfo reports the width as 1649 instead of 1650.

Here is our patch (you can ignore the earlier CPLDebug work around ... though it is ... curious):

diff -r 6ed53b9be6f9 xt_lib_gdal/src/gdal-1.9.0/frmts/pdf/pdfdataset.cpp
--- a/xt_lib_gdal/src/gdal-1.9.0/frmts/pdf/pdfdataset.cpp       Mon Aug 13 18:33:24 2012 +0100
+++ b/xt_lib_gdal/src/gdal-1.9.0/frmts/pdf/pdfdataset.cpp       Mon Aug 13 15:19:45 2012 -0700
@@ -2414,10 +2414,8 @@

     double dfUserUnit = poDS->dfDPI / 72.0;
-    poDS->nRasterXSize = (int) ((dfX2 - dfX1) * dfUserUnit);
-    CPLDebug("PDF", "Issue 14276.  We calculate raster width as %d ... now watch carefully:  uncommenting the line below makes the line above execute properly.  Whoa!", poDS->nRasterXSize );
-    CPLDebug("PDF", "This simple reference seems to fix an incorrect calulation above on gcc version 4.4.5:  dfX2 = %f", dfX2);
-    poDS->nRasterYSize = (int) ((dfY2 - dfY1) * dfUserUnit);
+    poDS->nRasterXSize = (int) floor((dfX2 - dfX1) * dfUserUnit+0.5);
+    poDS->nRasterYSize = (int) floor((dfY2 - dfY1) * dfUserUnit+0.5);

     double dfRotation = 0;

(one of the other engineers here just looked over my shoulder and mentioned that we've seen similar problems on similar compilers ... and that an even simpler fix was to force the cast into a function call: int myToInt(double v) { return static_cast<int>(v); }

I have not tried this one)

Attachments (1)

us_nw_default.pdf (208.2 KB ) - added by mrosen 10 years ago.

Download all attachments as: .zip

Change History (3)

by mrosen, 10 years ago

Attachment: us_nw_default.pdf added

comment:1 by Even Rouault, 10 years ago

Just curious, apart the size that is one pixel lower than what you would expect, did it cause other issues ? I tried to force the nRasterXSize to 1649, and IReadBlock() was still running OK

comment:2 by Even Rouault, 10 years ago

Milestone: 2.0.0
Resolution: fixed
Status: newclosed

r24778 /trunk/ (autotest/ogr/ gdal/frmts/pdf/pdfdataset.cpp): PDF: improve rounding of raster dimensions (#4775)

Note: See TracTickets for help on using tickets.