mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-25 08:10:33 +03:00
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:
parent
f4ce428a4f
commit
2bf3ceee85
|
@ -169,10 +169,11 @@ int ImagingLibTiffInit(ImagingCodecState state, int fp, int offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) {
|
int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) {
|
||||||
TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
|
TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
|
||||||
char *filename = "tempfile.tif";
|
char *filename = "tempfile.tif";
|
||||||
char *mode = "r";
|
char *mode = "r";
|
||||||
TIFF *tiff;
|
TIFF *tiff;
|
||||||
|
uint16 photometric = 0, compression;
|
||||||
|
|
||||||
|
|
||||||
/* buffer is the encoded file, bytes is the length of the encoded file */
|
/* 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)) {
|
if (TIFFIsTiled(tiff)) {
|
||||||
uint32 x, y, tile_y;
|
uint32 x, y, tile_y;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user