Using Magick++ 6.9.2 and libtiff 4.0.4 in Linux environment.
I have some TIFF images that are missing some of the required tags, such as photometric interpretation, resolution unit.
When I attempt to read or ping the image, an exception is thrown that reads "Magick: improper image header" and severity CorruptImageError (425).
However, I can use convert to create a new image and convert processes the input file without issue, creating a new file with the missing tags filled in.
How can I mimick this same behavior with Magick++?
Here is some additional information I've gathered:
The previous version of my program did not have this issue, but it was built with Magick++ 6.8.8-7.
Between 6.8.8-7 and 6.9.2, coders/tiff.c was changed to add these tests in ReadTIFFImage:
if ((TIFFGetField(tiff,TIFFTAG_IMAGEWIDTH,&width) != 1) ||
(TIFFGetField(tiff,TIFFTAG_IMAGELENGTH,&height) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_COMPRESSION,&compress_tag) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_FILLORDER,&endian) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_PLANARCONFIG,&interlace) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL,&samples_per_pixel) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,&bits_per_sample) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLEFORMAT,&sample_format) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_MINSAMPLEVALUE,&min_sample_value) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_MAXSAMPLEVALUE,&max_sample_value) != 1) ||
(TIFFGetFieldDefaulted(tiff,TIFFTAG_PHOTOMETRIC,&photometric) != 1))
The default values are provided in libtiff by tif_aux.c, which does not provide a default for photometric interpretation, and that is cause the ping/read exception.
As a work-around, I've altered libtiff tif_aux.c to provide a default for TIFFTAG_PHOTOMETRIC.
This still does not answer the question as to why convert can process the image that is missing the photometric tag but both Magick++ ping and read fail with the corrupt image exception.
TIFF ping/read returning improper image header
-
- Posts: 12
- Joined: 2013-12-03T15:56:51-07:00
- Authentication code: 6789
-
- Posts: 12
- Joined: 2013-12-03T15:56:51-07:00
- Authentication code: 6789
Re: TIFF ping/read returning improper image header
Oops - it turns out that convert 6.9.2 does fail for the same reason that my program does. My mistake was not giving a full path to convert so my command line picked up version 6.7.7-10 which predates the change to test the tags shown above.