diff --git a/ChangeLog b/ChangeLog index d7cbda80..f52b3304 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,8 @@ - set "interlaced=1" for interlaced JPG and PNG images - add PDFium PDF loader - add @format option to magickload +- jpegload adds a jpeg-chroma-subsample field with eg. 4:4:4 for no + chrominance subsampling. 12/3/18 started 8.6.4 - better fitting of fonts with overhanging edges [AdriĆ ] diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 04c59f36..d67239e9 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -279,6 +279,25 @@ readjpeg_file( ReadJpeg *jpeg, const char *filename ) return( 0 ); } +static const char * +find_chroma_subsample( struct jpeg_decompress_struct *cinfo ) +{ + gboolean has_subsample; + + /* libjpeg only uses 4:4:4 and 4:2:0, confusingly. + * + * http://poynton.ca/PDFs/Chroma_subsampling_notation.pdf + */ + has_subsample = cinfo->max_h_samp_factor > 1 || + cinfo->max_v_samp_factor > 1; + if( cinfo->num_components > 3 ) + /* A cmyk image. + */ + return( has_subsample ? "4:2:0:4" : "4:4:4:4" ); + else + return( has_subsample ? "4:2:0" : "4:4:4" ); +} + static int attach_blob( VipsImage *im, const char *field, void *data, int data_length ) { @@ -439,6 +458,9 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) if( jpeg_has_multiple_scans( cinfo ) ) vips_image_set_int( out, "interlaced", 1 ); + (void) vips_image_set_string( out, "jpeg-chroma-subsample", + find_chroma_subsample( cinfo ) ); + /* Look for EXIF and ICC profile. */ for( p = cinfo->marker_list; p; p = p->next ) { diff --git a/libvips/foreign/jpegload.c b/libvips/foreign/jpegload.c index 06ec6c81..607e54f8 100644 --- a/libvips/foreign/jpegload.c +++ b/libvips/foreign/jpegload.c @@ -374,6 +374,11 @@ vips_foreign_load_jpeg_buffer_init( VipsForeignLoadJpegBuffer *buffer ) * memory to load, so this field gives callers a chance to handle these * images differently. * + * The string-valued field "jpeg-chroma-subsample" gives the chroma subsample + * in standard notation. 4:4:4 means no subsample, 4:2:0 means YCbCr with + * Cb and Cr subsampled horizontally and vertically, 4:4:4:4 means a CMYK + * image with no subsampling. + * * The EXIF thumbnail, if present, is attached to the image as * "jpeg-thumbnail-data". See vips_image_get_blob(). *