From e081ae2d99724755871c11d4237d78e830df01f6 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 15 Apr 2019 10:50:42 +0100 Subject: [PATCH] experiment with app14 decode --- libvips/foreign/jpeg2vips.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 980f1635..7bdaac34 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -394,11 +394,10 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) case JCS_CMYK: interpretation = VIPS_INTERPRETATION_CMYK; - /* Photoshop writes CMYK JPEG inverted :-( Maybe this is a - * way to spot photoshop CMYK JPGs. + + /* CMYKs are almost always returned inverted, but see below. */ - if( cinfo->saw_Adobe_marker ) - jpeg->invert_pels = TRUE; + jpeg->invert_pels = TRUE; break; case JCS_RGB: @@ -561,6 +560,28 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) } break; + case JPEG_APP0 + 14: + /* Adobe block. We need to check the transform flag to + * see if we must invert CMYK. + * + * See: https://sno.phy.queensu.ca/~phil/exiftool/\ + * TagNames/JPEG.html#Adobe + * + * CMYK JPGs are almost always returned inverted. The + * exception is non-YCCK Adobe jpg. + */ + if( p->data_length > 5 && + vips_isprefix( "Adobe", (char *) p->data ) ) { + if( p->data_length >= 12 && + p->data[11] == 0 ) { +#ifdef DEBUG + printf( "not YCCK image\n" ); +#endif /*DEBUG*/ + jpeg->invert_pels = FALSE; + } + } + break; + default: #ifdef DEBUG printf( "read_jpeg_header: " @@ -787,11 +808,12 @@ static int vips__jpeg_read( ReadJpeg *jpeg, VipsImage *out, gboolean header_only ) { /* Need to read in APP1 (EXIF metadata), APP2 (ICC profile), APP13 - * (photoshop IPTC). + * (photoshop IPTC) and APP14 (Adobe flags). */ jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 1, 0xffff ); jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 2, 0xffff ); jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 13, 0xffff ); + jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 14, 0xffff ); #ifdef DEBUG {