JPEG coder ignores undefined resolution

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mehcode
Posts: 1
Joined: 2013-09-25T14:00:51-07:00
Authentication code: 6789

JPEG coder ignores undefined resolution

Post by mehcode »

When running the following command:

Code: Select all

convert image.jpg -density 1 -units undefined converted.jpg
The resolution units are saved in the converted.jpg as PixelsPerInch instead of None.

Attached are two patches to fix this in the JPEG coder; one for 6.8.7 and one for svn develop.

Code: Select all

Index: coders/jpeg.c
===================================================================
--- coders/jpeg.c	(revision 13281)
+++ coders/jpeg.c	(working copy)
@@ -2173,10 +2173,16 @@
       jpeg_info.write_JFIF_header=MagickTrue;
       jpeg_info.X_density=(UINT16) floor(image->resolution.x+0.5);
       jpeg_info.Y_density=(UINT16) floor(image->resolution.y+0.5);
+
+      /*
+        Set image resolution units.
+       */
       if (image->units == PixelsPerInchResolution)
         jpeg_info.density_unit=(UINT8) 1;
-      if (image->units == PixelsPerCentimeterResolution)
+      else if (image->units == PixelsPerCentimeterResolution)
         jpeg_info.density_unit=(UINT8) 2;
+      else
+        jpeg_info.density_unit=(UINT8) 0;
     }
   jpeg_info.dct_method=JDCT_FLOAT;
   option=GetImageOption(image_info,"jpeg:dct-method");
And in 6.8.7.

Code: Select all

Index: coders/jpeg.c
===================================================================
--- coders/jpeg.c	(revision 13281)
+++ coders/jpeg.c	(working copy)
@@ -2139,10 +2139,16 @@
       jpeg_info.write_JFIF_header=MagickTrue;
       jpeg_info.X_density=(UINT16) floor(image->x_resolution+0.5);
       jpeg_info.Y_density=(UINT16) floor(image->y_resolution+0.5);
+
+      /*
+        Set image resolution units.
+      */
       if (image->units == PixelsPerInchResolution)
         jpeg_info.density_unit=(UINT8) 1;
-      if (image->units == PixelsPerCentimeterResolution)
+      else if (image->units == PixelsPerCentimeterResolution)
         jpeg_info.density_unit=(UINT8) 2;
+      else
+        jpeg_info.density_unit=(UINT8) 0;
     }
   jpeg_info.dct_method=JDCT_FLOAT;
   option=GetImageOption(image_info,"jpeg:dct-method");
If I need to do something else to get this applied let me know.
Thank you.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: JPEG coder ignores undefined resolution

Post by magick »

We will apply your patch by sometime tomorrow. Thanks.
Post Reply