]> granicus.if.org Git - libjpeg-turbo/commitdiff
djpeg: Fix PPM output regression w/ color quant.
authorDRC <information@libjpeg-turbo.org>
Mon, 21 Jan 2019 22:25:02 +0000 (16:25 -0600)
committerDRC <information@libjpeg-turbo.org>
Mon, 21 Jan 2019 22:33:49 +0000 (16:33 -0600)
Regression caused by aa7459050d7a50e1d8a99488902d41fbc118a50f

Fix based on:
https://github.com/sinic/libjpeg-turbo/commit/03fbacb8ebf1fffc3f2d2db26ddf4db8b1f6aa7b

Closes #310

ChangeLog.md
wrppm.c

index 461931bc461254dec8e094303267e52bc4c6d1b8..0ed0b9a39bf8364edb816239cfdcf281d93ca758 100644 (file)
@@ -28,6 +28,9 @@ of specifying 1x subsampling (normally 4:4:4 JPEGs have 1x1 luminance and
 chrominance sampling factors), but the JPEG format and the libjpeg API both
 allow it.
 
+6. Fixed a regression introduced by 2.0 beta1[7] that caused djpeg to generate
+incorrect PPM images when used with the `-colors` option.
+
 
 2.0.1
 =====
diff --git a/wrppm.c b/wrppm.c
index 819a0a7e3898b25f86a38aeccee13acd630de458..69f91e816aecfec98d9a97cec60d7b9061fbd3d0 100644 (file)
--- a/wrppm.c
+++ b/wrppm.c
@@ -5,7 +5,7 @@
  * Copyright (C) 1991-1996, Thomas G. Lane.
  * Modified 2009 by Guido Vollbeding.
  * libjpeg-turbo Modifications:
- * Copyright (C) 2017, D. R. Commander.
+ * Copyright (C) 2017, 2019, D. R. Commander.
  * For conditions of distribution and use, see the accompanying README.ijg
  * file.
  *
@@ -256,6 +256,8 @@ start_output_ppm(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
   case JCS_EXT_ABGR:
   case JCS_EXT_ARGB:
   case JCS_CMYK:
+    if (!IsExtRGB(cinfo->out_color_space) && cinfo->quantize_colors)
+      ERREXIT(cinfo, JERR_PPM_COLORSPACE);
     /* emit header for raw PPM format */
     fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n",
             (long)cinfo->output_width, (long)cinfo->output_height, PPM_MAXVAL);
@@ -337,13 +339,14 @@ jinit_write_ppm(j_decompress_ptr cinfo)
       ((j_common_ptr)cinfo, JPOOL_IMAGE,
        cinfo->output_width * cinfo->output_components, (JDIMENSION)1);
     dest->pub.buffer_height = 1;
-    if (IsExtRGB(cinfo->out_color_space))
-      dest->pub.put_pixel_rows = put_rgb;
-    else if (cinfo->out_color_space == JCS_CMYK)
-      dest->pub.put_pixel_rows = put_cmyk;
-    else if (!cinfo->quantize_colors)
-      dest->pub.put_pixel_rows = copy_pixel_rows;
-    else if (cinfo->out_color_space == JCS_GRAYSCALE)
+    if (!cinfo->quantize_colors) {
+      if (IsExtRGB(cinfo->out_color_space))
+        dest->pub.put_pixel_rows = put_rgb;
+      else if (cinfo->out_color_space == JCS_CMYK)
+        dest->pub.put_pixel_rows = put_cmyk;
+      else
+        dest->pub.put_pixel_rows = copy_pixel_rows;
+    } else if (cinfo->out_color_space == JCS_GRAYSCALE)
       dest->pub.put_pixel_rows = put_demapped_gray;
     else
       dest->pub.put_pixel_rows = put_demapped_rgb;