experiment with app14 decode

This commit is contained in:
John Cupitt 2019-04-15 10:50:42 +01:00
parent c351c665a1
commit e081ae2d99

View File

@ -394,11 +394,10 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out )
case JCS_CMYK: case JCS_CMYK:
interpretation = VIPS_INTERPRETATION_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; break;
case JCS_RGB: case JCS_RGB:
@ -561,6 +560,28 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out )
} }
break; 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: default:
#ifdef DEBUG #ifdef DEBUG
printf( "read_jpeg_header: " printf( "read_jpeg_header: "
@ -787,11 +808,12 @@ static int
vips__jpeg_read( ReadJpeg *jpeg, VipsImage *out, gboolean header_only ) vips__jpeg_read( ReadJpeg *jpeg, VipsImage *out, gboolean header_only )
{ {
/* Need to read in APP1 (EXIF metadata), APP2 (ICC profile), APP13 /* 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 + 1, 0xffff );
jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 2, 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 + 13, 0xffff );
jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 14, 0xffff );
#ifdef DEBUG #ifdef DEBUG
{ {