From: DRC Date: Thu, 26 Apr 2018 23:01:52 +0000 (-0500) Subject: TurboJPEG: Handle CMYK JPEGs w/ subsampled M, Y X-Git-Tag: 2.0.0~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2401e4d10c2749c5c260a711c3bde52163829505;p=libjpeg-turbo TurboJPEG: Handle CMYK JPEGs w/ subsampled M, Y 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 --- diff --git a/ChangeLog.md b/ChangeLog.md index 650199f..57bcf1d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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) ================== diff --git a/tjbench.c b/tjbench.c index 1e286dc..ec70b7c 100644 --- 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 diff --git a/turbojpeg.c b/turbojpeg.c index 2ecd9e7..a41e8df 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -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 &&