diff --git a/libvips/arithmetic/unaryconst.c b/libvips/arithmetic/unaryconst.c index f098f169..f3aa4732 100644 --- a/libvips/arithmetic/unaryconst.c +++ b/libvips/arithmetic/unaryconst.c @@ -44,6 +44,7 @@ #include #include +#include #include diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 45e9d39b..d30064d7 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -255,6 +255,7 @@ typedef struct _RtiffHeader { int samples_per_pixel; int bits_per_sample; int photometric_interpretation; + int inkset; int sample_format; gboolean separate; int orientation; @@ -1329,6 +1330,7 @@ rtiff_parse_copy( Rtiff *rtiff, VipsImage *out ) int samples_per_pixel = rtiff->header.samples_per_pixel; int photometric_interpretation = rtiff->header.photometric_interpretation; + int inkset = rtiff->header.inkset; if( rtiff_non_fractional( rtiff ) ) return( -1 ); @@ -1358,9 +1360,15 @@ rtiff_parse_copy( Rtiff *rtiff, VipsImage *out ) out->Type = VIPS_INTERPRETATION_LAB; if( samples_per_pixel >= 4 && - photometric_interpretation == PHOTOMETRIC_SEPARATED ) + photometric_interpretation == PHOTOMETRIC_SEPARATED && + inkset == INKSET_CMYK) out->Type = VIPS_INTERPRETATION_CMYK; + if (samples_per_pixel >= 1 && + photometric_interpretation == PHOTOMETRIC_SEPARATED && + inkset == INKSET_MULTIINK) + out->Type = VIPS_INTERPRETATION_MULTIBAND; + rtiff->sfn = rtiff_memcpy_line; rtiff->client = out; @@ -2176,7 +2184,10 @@ rtiff_header_read( Rtiff *rtiff, RtiffHeader *header ) TIFFTAG_BITSPERSAMPLE, &header->bits_per_sample ) || !tfget16( rtiff->tiff, TIFFTAG_PHOTOMETRIC, - &header->photometric_interpretation ) ) + &header->photometric_interpretation ) || + !tfget16(rtiff->tiff, + TIFFTAG_INKSET, + &header->inkset ) ) return( -1 ); TIFFGetFieldDefaulted( rtiff->tiff, diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index c713140f..419337c1 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -654,50 +654,52 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer ) TIFFSetField( tif, TIFFTAG_BITSPERSAMPLE, vips_format_sizeof( wtiff->im->BandFmt ) << 3 ); - if( wtiff->im->Bands < 3 ) { - /* Mono or mono + alpha. - */ - photometric = wtiff->miniswhite ? - PHOTOMETRIC_MINISWHITE : + if (wtiff->im->Type == VIPS_INTERPRETATION_B_W || + wtiff->im->Type == VIPS_INTERPRETATION_GREY16) { + // Mono or mono + alpha. + photometric = wtiff->miniswhite ? + PHOTOMETRIC_MINISWHITE : PHOTOMETRIC_MINISBLACK; colour_bands = 1; } + else if( wtiff->im->Type == VIPS_INTERPRETATION_LAB || + wtiff->im->Type == VIPS_INTERPRETATION_LABS ) { + photometric = PHOTOMETRIC_CIELAB; + colour_bands = 3; + } + else if( wtiff->im->Type == VIPS_INTERPRETATION_CMYK && + wtiff->im->Bands >= 4 ) { + photometric = PHOTOMETRIC_SEPARATED; + TIFFSetField( tif, + TIFFTAG_INKSET, INKSET_CMYK ); + colour_bands = 4; + } + else if (wtiff->im->Type == VIPS_INTERPRETATION_MULTIBAND ) { + photometric = PHOTOMETRIC_SEPARATED; + TIFFSetField(tif, + TIFFTAG_INKSET, INKSET_MULTIINK); + colour_bands = 4; + } + else if( wtiff->compression == COMPRESSION_JPEG && + wtiff->im->Bands == 3 && + wtiff->im->BandFmt == VIPS_FORMAT_UCHAR && + (!wtiff->rgbjpeg && wtiff->Q < 90) ) { + /* This signals to libjpeg that it can do + * YCbCr chrominance subsampling from RGB, not + * that we will supply the image as YCbCr. + */ + photometric = PHOTOMETRIC_YCBCR; + TIFFSetField( tif, TIFFTAG_JPEGCOLORMODE, + JPEGCOLORMODE_RGB ); + colour_bands = 3; + } else { - /* Could be: RGB, CMYK, LAB, perhaps with extra alpha. - */ - if( wtiff->im->Type == VIPS_INTERPRETATION_LAB || - wtiff->im->Type == VIPS_INTERPRETATION_LABS ) { - photometric = PHOTOMETRIC_CIELAB; - colour_bands = 3; - } - else if( wtiff->im->Type == VIPS_INTERPRETATION_CMYK && - wtiff->im->Bands >= 4 ) { - photometric = PHOTOMETRIC_SEPARATED; - TIFFSetField( tif, - TIFFTAG_INKSET, INKSET_CMYK ); - colour_bands = 4; - } - else if( wtiff->compression == COMPRESSION_JPEG && - wtiff->im->Bands == 3 && - wtiff->im->BandFmt == VIPS_FORMAT_UCHAR && - (!wtiff->rgbjpeg && wtiff->Q < 90) ) { - /* This signals to libjpeg that it can do - * YCbCr chrominance subsampling from RGB, not - * that we will supply the image as YCbCr. - */ - photometric = PHOTOMETRIC_YCBCR; - TIFFSetField( tif, TIFFTAG_JPEGCOLORMODE, - JPEGCOLORMODE_RGB ); - colour_bands = 3; - } - else { - /* Some kind of generic multi-band image .. - * save the first three bands as RGB, the rest - * as alpha. - */ - photometric = PHOTOMETRIC_RGB; - colour_bands = 3; - } + /* Some kind of generic multi-band image .. + * save the first three bands as RGB, the rest + * as alpha. + */ + photometric = PHOTOMETRIC_RGB; + colour_bands = 3; } alpha_bands = VIPS_CLIP( 0,