Only ask for YCbCr->RGB libtiff conversion for jpeg-compressed tiffs

JPEG-related tiff pseudo-tags are registered only when tiff image has jpeg compression. Trying to set TIFFTAG_JPEGCOLORMODE on non jpeg-compressed file prints error "Unknown pseudo-tag 65538".
This commit is contained in:
Konstantin Kopachev 2018-10-18 21:23:06 -07:00
parent f4ce428a4f
commit 2bf3ceee85
No known key found for this signature in database
GPG Key ID: CECF757E656F4F62

View File

@ -169,10 +169,11 @@ int ImagingLibTiffInit(ImagingCodecState state, int fp, int offset) {
}
int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) {
TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
char *filename = "tempfile.tif";
char *mode = "r";
TIFF *tiff;
TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
char *filename = "tempfile.tif";
char *mode = "r";
TIFF *tiff;
uint16 photometric = 0, compression;
/* buffer is the encoded file, bytes is the length of the encoded file */
@ -234,7 +235,12 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int
}
}
TIFFSetField(tiff, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
TIFFGetFieldDefaulted(tiff, TIFFTAG_COMPRESSION, &compression);
TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric);
if (compression == COMPRESSION_JPEG && photometric == PHOTOMETRIC_YCBCR) {
/* Set pseudo-tag to force automatic YCbCr->RGB conversion */
TIFFSetField(tiff, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
}
if (TIFFIsTiled(tiff)) {
uint32 x, y, tile_y;