Subject: bug#17519: [PATCH] take into account QuantumScale when reading imagemagick images

From: Paul Eggert <[email-masked]>
Date: Mon, 19 May 2014 13:04:12 -0700

Thanks for reporting this. Does the attached simpler patch fix the 
problem for you?  Dividing by QuantumRange instead of multiplying by 
QuantumScale avoids potential double-rounding problems in future 
versions of ImageMagick.
=== modified file 'src/image.c'
--- src/image.c	2014-05-04 18:51:32 +0000
+++ src/image.c	2014-05-19 19:47:21 +0000
@@ -8388,6 +8388,7 @@
 #endif /* HAVE_MAGICKEXPORTIMAGEPIXELS */
     {
       size_t image_height;
+      double color_scale = 65535.0 / QuantumRange;
 
       /* Try to create a x pixmap to hold the imagemagick pixmap.  */
       if (!image_create_x_image_and_pixmap (f, img, width, height, 0,
@@ -8428,9 +8429,9 @@
               PixelGetMagickColor (pixels[x], &pixel);
               XPutPixel (ximg, x, y,
                          lookup_rgb_color (f,
-                                           pixel.red,
-                                           pixel.green,
-                                           pixel.blue));
+					   color_scale * pixel.red,
+					   color_scale * pixel.green,
+					   color_scale * pixel.blue));
             }
         }
       DestroyPixelIterator (iterator);