Author: rmottola
Date: Tue Mar 28 17:35:38 2017
New Revision: 40427

URL: http://svn.gna.org/viewcvs/gnustep?rev=40427&view=rev
Log:
use double and better math to avoid rounding errors especially with cm->inch 
conversion

Modified:
    libs/gui/trunk/Source/NSBitmapImageRep+JPEG.m

Modified: libs/gui/trunk/Source/NSBitmapImageRep+JPEG.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSBitmapImageRep%2BJPEG.m?rev=40427&r1=40426&r2=40427&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSBitmapImageRep+JPEG.m       (original)
+++ libs/gui/trunk/Source/NSBitmapImageRep+JPEG.m       Tue Mar 28 17:35:38 2017
@@ -393,7 +393,7 @@
   JSAMPARRAY sclbuffer = NULL;
   unsigned char *imgbuffer = NULL;
   BOOL isProgressive;
-  unsigned x_density, y_density;
+  double x_density, y_density;
 
   if (!(self = [super init]))
     return nil;
@@ -507,8 +507,8 @@
   [self setProperty: NSImageProgressive
           withValue: [NSNumber numberWithBool: isProgressive]];
 
-  x_density = cinfo.X_density;
-  y_density = cinfo.Y_density;
+  x_density = (double) cinfo.X_density;
+  y_density = (double) cinfo.Y_density;
   if (x_density > 0 && y_density > 0)
     {
       unsigned short d_unit;
@@ -517,16 +517,16 @@
       /* we have dots/cm, convert to dots/inch*/
       if (d_unit == 2)
         {
-          x_density = (x_density * 254)/100;
-          y_density = (y_density * 254)/100;
+          x_density = x_density * 2.54;
+          y_density = y_density * 2.54;
         }
 
       if (!(x_density == 72 && y_density == 72))
         {
           NSSize pointSize;
 
-          pointSize = NSMakeSize((double)cinfo.output_width * (72.0 / 
(double)x_density),
-                                 (double)cinfo.output_height * (72.0 / 
(double)y_density));
+          pointSize = NSMakeSize((double)cinfo.output_width * 72.0 / x_density,
+                                 (double)cinfo.output_height * 72.0 / 
y_density);
           [self setSize: pointSize];
         }
     }


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to