]> granicus.if.org Git - libjpeg-turbo/commitdiff
TurboJPEG: Handle CMYK JPEGs w/ subsampled M, Y
authorDRC <information@libjpeg-turbo.org>
Thu, 26 Apr 2018 23:01:52 +0000 (18:01 -0500)
committerDRC <information@libjpeg-turbo.org>
Thu, 26 Apr 2018 23:15:27 +0000 (18:15 -0500)
Arguably it doesn't make much sense for non-chroma components to be
subsampled (which is why this type of image was overlooked in
cd7c3e6672cce3779450c6dd10d0d70b0c2278b2-- I didn't realize it was a
thing), but certain Adobe applications apparently generate these images.

Fixes #236

ChangeLog.md
tjbench.c
turbojpeg.c

index 650199f858dde1820d844e6369146bcc788c7096..57bcf1d263d166cbbf5e8950c0e68a8b0ef68576 100644 (file)
@@ -1,3 +1,17 @@
+2.0.0
+=====
+
+### Significant changes relative to 2.0 beta1:
+
+1. The TurboJPEG API can now decompress CMYK JPEG images that have subsampled M
+and Y components (not to be confused with YCCK JPEG images, in which the C/M/Y
+components have been transformed into luma and chroma.)   Previously, an error
+was generated ("Could not determine subsampling type for JPEG image") when such
+an image was passed to `tjDecompressHeader3()`, `tjTransform()`,
+`tjDecompressToYUVPlanes()`, `tjDecompressToYUV2()`, or the equivalent Java
+methods.
+
+
 1.5.90 (2.0 beta1)
 ==================
 
index 1e286dc75a23008a2ed29e0e163e6608f321a954..ec70b7c06732b21baf85e7228a9ecbce728a3efb 100644 (file)
--- a/tjbench.c
+++ b/tjbench.c
@@ -99,7 +99,7 @@ char *formatName(int subsamp, int cs, char *buf)
 {
   if (cs == TJCS_YCbCr)
     return (char *)subNameLong[subsamp];
-  else if (cs == TJCS_YCCK) {
+  else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
     snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
     return buf;
   } else
index 2ecd9e7b0bd0843105969a3db697da157ae96cbd..a41e8dfd9f7c6880245500477253c51ef4628872 100644 (file)
@@ -319,7 +319,8 @@ static int getSubsamp(j_decompress_ptr dinfo)
         for (k = 1; k < dinfo->num_components; k++) {
           int href = 1, vref = 1;
 
-          if (dinfo->jpeg_color_space == JCS_YCCK && k == 3) {
+          if ((dinfo->jpeg_color_space == JCS_YCCK ||
+               dinfo->jpeg_color_space == JCS_CMYK) && k == 3) {
             href = tjMCUWidth[i] / 8;  vref = tjMCUHeight[i] / 8;
           }
           if (dinfo->comp_info[k].h_samp_factor == href &&
@@ -340,7 +341,8 @@ static int getSubsamp(j_decompress_ptr dinfo)
         for (k = 1; k < dinfo->num_components; k++) {
           int href = tjMCUHeight[i] / 8, vref = tjMCUWidth[i] / 8;
 
-          if (dinfo->jpeg_color_space == JCS_YCCK && k == 3) {
+          if ((dinfo->jpeg_color_space == JCS_YCCK ||
+               dinfo->jpeg_color_space == JCS_CMYK) && k == 3) {
             href = vref = 2;
           }
           if (dinfo->comp_info[k].h_samp_factor == href &&