37 # define TIFFCvtIEEEFloatToNative(tif, n, fp) 38 # define TIFFCvtIEEEDoubleToNative(tif, n, dp) 47 static void MissingRequired(
TIFF*,
const char*);
67 static void ChopUpSingleUncompressedStrip(
TIFF*);
76 static const char module[] =
"TIFFReadDirectory";
86 int diroutoforderwarning = 0, compressionknown = 0;
87 int haveunknowntags = 0;
104 "%s: Failed to read directory at offset %u",
147 for (dp = dir, n = dircount; n > 0; n--, dp++) {
153 if (!TIFFFetchNormalTag(tif, dp))
162 for (dp = dir, n = dircount; n > 0; n--, dp++) {
175 if (!diroutoforderwarning) {
177 "%s: invalid TIFF directory; tags are not sorted in ascending order",
179 diroutoforderwarning = 1;
183 while (fix < tif->tif_nfields &&
205 && fix < tif->tif_nfields) {
212 "%s: wrong data type %d for \"%s\"; tag ignored",
226 if (!CheckDirCount(tif, dp, expected))
244 compressionknown = 1;
248 if (!TIFFFetchPerSampleLongs(tif, dp, &v) ||
252 if (!TIFFFetchPerSampleShorts(tif, dp, &iv)
273 if (!TIFFFetchNormalTag(tif, dp))
288 if (haveunknowntags) {
290 for (dp = dir, n = dircount; n > 0; n--, dp++) {
296 while (fix < tif->tif_nfields &&
304 "%s: unknown field with tag %d (0x%x) encountered",
317 "Registering anonymous field with tag %d (0x%x) failed",
324 while (fix < tif->tif_nfields &&
333 && fix < tif->tif_nfields) {
340 "%s: wrong data type %d for \"%s\"; tag ignored",
362 dp = TIFFReadDirectoryFind(dir, dircount,
368 "Planarconfig tag value assumed incorrect, " 369 "assuming data is contig instead of chunky");
378 MissingRequired(tif,
"ImageLength");
396 "%s: cannot handle zero number of %s",
418 isTiled(tif) ?
"TileOffsets" :
"StripOffsets");
426 for (dp = dir, n = dircount; n > 0; n--, dp++) {
458 if (!TIFFFetchPerSampleLongs(tif, dp, &v) ||
462 if (!TIFFFetchPerSampleShorts(tif, dp, &iv) ||
471 if (!TIFFFetchPerSampleAnys(tif, dp, &dv) ||
478 if (!TIFFFetchStripThing(tif, dp,
484 if (!TIFFFetchStripThing(tif, dp,
500 if (!CheckDirCount(tif, dp, 3 * v))
507 "to read \"TransferFunction\" tag");
509 if (TIFFFetchData(tif, dp, cp)) {
529 (void) TIFFFetchShortPair(tif, dp);
532 (void) TIFFFetchRefBlackWhite(tif, dp);
551 (void) TIFFFetchNormalTag(tif, dp);
576 "Photometric tag is missing, assuming data is YCbCr");
584 "Photometric tag value assumed incorrect, " 585 "assuming data is YCbCr instead of RGB");
590 "BitsPerSample tag is missing, assuming 8 bits per sample");
601 "SamplesPerPixel tag is missing, " 602 "assuming correct SamplesPerPixel value is 3");
611 "SamplesPerPixel tag is missing, " 612 "assuming correct SamplesPerPixel value is 1");
623 MissingRequired(tif,
"Colormap");
646 MissingRequired(tif,
"StripByteCounts");
650 "%s: TIFF directory is missing required " 651 "\"%s\" field, calculating from imagelength",
654 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
669 #define BYTECOUNTLOOKSBAD \ 670 ( (td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \ 671 (td->td_compression == COMPRESSION_NONE && \ 672 td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]) || \ 673 (tif->tif_mode == O_RDONLY && \ 674 td->td_compression == COMPRESSION_NONE && \ 675 td->td_stripbytecount[0] < TIFFScanlineSize(tif) * td->td_imagelength) ) 687 "%s: Bogus \"%s\" field, ignoring and calculating from imagelength",
690 if(EstimateStripByteCounts(tif, dir, dircount) < 0)
705 "%s: Wrong \"%s\" field, ignoring and calculating from imagelength",
708 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
731 for (strip = 1; strip < td->
td_nstrips; strip++) {
753 ChopUpSingleUncompressedStrip(tif);
767 "%s: cannot handle zero scanline size",
776 "%s: cannot handle zero tile size",
783 "%s: cannot handle zero strip size",
800 for (m=dir, n=0; n<dircount; m++, n++)
816 static const char module[] =
"TIFFReadCustomDirectory";
826 dircount = TIFFFetchDirectory(tif, diroff, &dir, NULL);
829 "%s: Failed to read custom directory at offset %u",
838 for (dp = dir, i = dircount; i > 0; i--, dp++) {
847 while (fix < tif->tif_nfields &&
855 "%s: unknown field with tag %d (0x%x) encountered",
864 "Registering anonymous field with tag %d (0x%x) failed",
870 while (fix < tif->tif_nfields &&
887 && fix < tif->tif_nfields) {
894 "%s: wrong data type %d for \"%s\"; tag ignored",
908 if (!CheckDirCount(tif, dp, expected))
917 (void) TIFFFetchSubjectDistance(tif, dp);
920 (void) TIFFFetchNormalTag(tif, dp);
937 size_t exifFieldInfoCount;
947 static const char module[] =
"EstimateStripByteCounts";
957 "for \"StripByteCounts\" array");
970 for (dp = dir, n = dircount; n > 0; n--, dp++)
975 "%s: Cannot determine size of unknown tag type %d",
980 if (cc >
sizeof (uint32))
983 space = filesize - space;
986 for (strip = 0; strip < td->
td_nstrips; strip++)
1003 for (strip = 0; strip < td->
td_nstrips; strip++)
1008 for (strip = 0; strip < td->
td_nstrips; strip++)
1018 MissingRequired(
TIFF* tif,
const char* tagname)
1020 static const char module[] =
"MissingRequired";
1023 "%s: TIFF directory is missing required \"%s\" field",
1080 "incorrect count for field \"%s\" (%u, expecting %u); tag ignored",
1084 }
else if (count < dir->tdir_count) {
1086 "incorrect count for field \"%s\" (%u, expecting %u); tag trimmed",
1103 static const char module[] =
"TIFFFetchDirectory";
1116 "%s: Seek error accessing TIFF directory",
1122 "%s: Can not read TIFF directory count",
1130 "to read TIFF directory");
1135 "%.100s: Can not read TIFF directory",
1145 (void)
ReadOK(tif, nextdiroff,
sizeof(uint32));
1161 "%s: Can not read TIFF directory count",
1173 "to read TIFF directory");
1178 "%s: Can not read TIFF directory",
1188 if (off +
sizeof (uint32) <= tif->
tif_size) {
1222 if (!
ReadOK(tif, cp, cc))
1255 "Error fetching data for field \"%s\"",
1273 return (TIFFFetchData(tif, dir, cp));
1280 cvtRational(
TIFF* tif,
TIFFDirEntry* dir, uint32 num, uint32 denom,
float* rv)
1284 "%s: Rational with zero denominator (num = %u)",
1289 *rv = ((float)num / (
float)denom);
1291 *rv = ((float)(int32)num / (float)(int32)denom);
1306 return (!TIFFFetchData(tif, dir, (
char *)l) ||
1307 !cvtRational(tif, dir, l[0], l[1], &v) ? 1.0f : v);
1367 return (TIFFFetchData(tif, dir, (
char*) v) != 0);
1390 return (TIFFFetchData(tif, dir, (
char *)v) != 0);
1406 "unexpected count for field \"%s\", %u, expected 2; ignored",
1417 return TIFFFetchByteArray(tif, dir, v)
1424 return TIFFFetchShortArray(tif, dir, v)
1442 return (TIFFFetchData(tif, dir, (
char*) v) != 0);
1456 "to fetch array of rationals");
1458 if (TIFFFetchData(tif, dir, (
char *)l)) {
1461 ok = cvtRational(tif, dir,
1462 l[2*i+0], l[2*i+1], &v[i]);
1490 }
else if (TIFFFetchData(tif, dir, (
char*) v)) {
1503 if (TIFFFetchData(tif, dir, (
char*) v)) {
1527 if (!TIFFFetchByteArray(tif, dir, (
uint8*) v))
1541 if (!TIFFFetchShortArray(tif, dir, (
uint16*) v))
1555 if (!TIFFFetchLongArray(tif, dir, (uint32*) v))
1558 uint32* vp = (uint32*) v;
1562 int32* vp = (int32*) v;
1569 if (!TIFFFetchRationalArray(tif, dir, (
float*) v))
1571 {
float* vp = (
float*) v;
1577 if (!TIFFFetchFloatArray(tif, dir, (
float*) v))
1579 {
float* vp = (
float*) v;
1585 return (TIFFFetchDoubleArray(tif, dir, (
double*) v));
1591 "cannot read TIFF_ANY type %d for field \"%s\"",
1605 static const char mesg[] =
"to fetch tag value";
1617 ok = cp && TIFFFetchByteArray(tif, dp, (
uint8*) cp);
1623 ok = cp && TIFFFetchShortArray(tif, dp, (
uint16*) cp);
1629 ok = cp && TIFFFetchLongArray(tif, dp, (uint32*) cp);
1635 ok = cp && TIFFFetchRationalArray(tif, dp, (
float*) cp);
1640 ok = cp && TIFFFetchFloatArray(tif, dp, (
float*) cp);
1645 ok = cp && TIFFFetchDoubleArray(tif, dp, (
double*) cp);
1655 if( (ok = (cp && TIFFFetchString(tif, dp, cp))) != 0 )
1666 }
else if (CheckDirCount(tif, dp, 1)) {
1709 TIFFFetchFloat(tif, dp)
1710 : TIFFFetchRational(tif, dp));
1718 ok = (TIFFFetchDoubleArray(tif, dp, &v) &&
1728 if( (ok = (TIFFFetchString(tif, dp, c) != 0)) != 0 ) {
1741 #define NITEMS(x) (sizeof (x) / sizeof (x[0])) 1753 if (CheckDirCount(tif, dir, (uint32) samples)) {
1759 "to fetch per-sample values");
1760 if (v && TIFFFetchShortArray(tif, dir, v)) {
1763 if( samples < check_count )
1764 check_count = samples;
1766 for (i = 1; i < check_count; i++)
1769 "Cannot handle different per-sample values for field \"%s\"",
1794 if (CheckDirCount(tif, dir, (uint32) samples)) {
1800 "to fetch per-sample values");
1801 if (v && TIFFFetchLongArray(tif, dir, v)) {
1805 if( samples < check_count )
1806 check_count = samples;
1807 for (i = 1; i < check_count; i++)
1810 "Cannot handle different per-sample values for field \"%s\"",
1834 if (CheckDirCount(tif, dir, (uint32) samples)) {
1840 "to fetch per-sample values");
1841 if (v && TIFFFetchAnyArray(tif, dir, v)) {
1844 if( samples < check_count )
1845 check_count = samples;
1847 for (i = 1; i < check_count; i++)
1850 "Cannot handle different per-sample values for field \"%s\"",
1870 TIFFFetchStripThing(
TIFF* tif,
TIFFDirEntry* dir,
long nstrips, uint32** lpp)
1872 register uint32* lp;
1875 CheckDirCount(tif, dir, (uint32) nstrips);
1882 nstrips,
sizeof (uint32),
"for strip array")) == NULL)
1895 if( (status = TIFFFetchShortArray(tif, dir, dp)) != 0 ) {
1898 for( i = 0; i < nstrips && i < (int) dir->
tdir_count; i++ )
1905 }
else if( nstrips != (
int) dir->
tdir_count ) {
1909 dir->
tdir_count, sizeof (uint32),
"to fetch strip tag");
1913 status = TIFFFetchLongArray(tif, dir, dp);
1917 for( i = 0; i < nstrips && i < (int) dir->
tdir_count; i++ )
1925 status = TIFFFetchLongArray(tif, dir, lp);
1936 static const char mesg[] =
"for \"ReferenceBlackWhite\" array";
1941 return (TIFFFetchNormalTag(tif, dir));
1946 sizeof (uint32), mesg);
1947 if( (ok = (cp && TIFFFetchLongArray(tif, dir, (uint32*) cp))) != 0) {
1948 float* fp = (
float*)
1950 if( (ok = (fp != NULL)) != 0 ) {
1953 fp[i] = (
float)((uint32*) cp)[i];
1976 "incorrect count or type for SubjectDistance, tag ignored" );
1980 if (TIFFFetchData(tif, dir, (
char *)l)
1981 && cvtRational(tif, dir, l[0], l[1], &v)) {
1988 (l[0] != 0xFFFFFFFF) ? v : -v);
2001 ChopUpSingleUncompressedStrip(
TIFF* tif)
2007 tstrip_t strip, nstrips, rowsperstrip;
2016 stripbytes = rowbytes;
2018 }
else if (rowbytes > 0 ) {
2020 stripbytes = rowbytes * rowsperstrip;
2035 "for chopped \"StripByteCounts\" array");
2037 "for chopped \"StripOffsets\" array");
2038 if (newcounts == NULL || newoffsets == NULL) {
2043 if (newcounts != NULL)
2045 if (newoffsets != NULL)
2053 for (strip = 0; strip < nstrips; strip++) {
2054 if ((uint32)stripbytes > bytecount)
2055 stripbytes = bytecount;
2056 newcounts[strip] = stripbytes;
2057 newoffsets[strip] = offset;
2058 offset += stripbytes;
2059 bytecount -= stripbytes;
#define TIFFTAG_SUBFILETYPE
tstrile_t td_stripsperimage
#define PHOTOMETRIC_YCBCR
int TIFFReadDirectory(TIFF *tif)
const TIFFFieldInfo * _TIFFGetExifFieldInfo(size_t *)
#define TIFFTAG_BITSPERSAMPLE
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
#define TIFFTAG_ROWSPERSTRIP
#define FIELD_STRIPOFFSETS
#define TIFFTAG_STRIPBYTECOUNTS
#define TIFFCvtIEEEFloatToNative(tif, n, fp)
#define TIFFTAG_EXTRASAMPLES
#define FIELD_IMAGEDIMENSIONS
#define TIFFhowmany(x, y)
#define TIFFTAG_IMAGEWIDTH
#define TIFFTAG_MINSAMPLEVALUE
tsize_t TIFFScanlineSize(TIFF *tif)
#define TIFFTAG_STRIPOFFSETS
#define COMPRESSION_OJPEG
#define TIFFTAG_YCBCRSUBSAMPLING
void TIFFSwabArrayOfShort(uint16 *wp, register unsigned long n)
#define TIFFTAG_SMINSAMPLEVALUE
#define TIFFTAG_REFERENCEBLACKWHITE
#define TIFFTAG_PLANARCONFIG
#define TIFFTAG_TILEBYTECOUNTS
void _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
#define FIELD_MAXSAMPLEVALUE
#define FIELD_BITSPERSAMPLE
#define TIFFSetFieldBit(tif, field)
#define TIFFTAG_TILEWIDTH
#define FIELD_STRIPBYTECOUNTS
#define TIFFTAG_TILELENGTH
unsigned char field_passcount
tsize_t TIFFVTileSize(TIFF *tif, uint32 nrows)
#define PHOTOMETRIC_MINISWHITE
#define TIFFTAG_IMAGELENGTH
#define TIFFTAG_TILEOFFSETS
#define TIFFTAG_SAMPLESPERPIXEL
#define PHOTOMETRIC_PALETTE
int TIFFReadCustomDirectory(TIFF *tif, toff_t diroff, const TIFFFieldInfo info[], size_t n)
void TIFFFreeDirectory(TIFF *tif)
int td_stripbytecountsorted
#define PHOTOMETRIC_MINISBLACK
int TIFFReadEXIFDirectory(TIFF *tif, toff_t diroff)
void TIFFSwabShort(uint16 *wp)
ttile_t TIFFNumberOfTiles(TIFF *tif)
int _TIFFMergeFieldInfo(TIFF *, const TIFFFieldInfo[], int)
#define STRIP_SIZE_DEFAULT
#define TIFFTAG_HALFTONEHINTS
#define FIELD_PHOTOMETRIC
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
#define TIFFTAG_PHOTOMETRIC
void TIFFSwabArrayOfLong(register uint32 *lp, register unsigned long n)
#define TIFFFieldSet(tif, field)
#define TIFFTAG_PAGENUMBER
#define FIELD_COMPRESSION
#define FIELD_ROWSPERSTRIP
#define EXIFTAG_SUBJECTDISTANCE
#define TIFFTAG_TRANSFERFUNCTION
TIFFFieldInfo ** tif_fieldinfo
#define TIFFTAG_COMPRESSION
#define PLANARCONFIG_SEPARATE
#define FILETYPE_REDUCEDIMAGE
TIFFVoidMethod tif_cleanup
#define TIFFExtractData(tif, type, v)
#define TIFFGetFileSize(tif)
void _TIFFmemset(tdata_t p, int v, tsize_t c)
tstrip_t TIFFNumberOfStrips(TIFF *tif)
#define TIFFTAG_SMAXSAMPLEVALUE
uint16 td_samplesperpixel
int TIFFDataWidth(TIFFDataType type)
void TIFFSwabArrayOfDouble(double *dp, register unsigned long n)
#define OFILETYPE_REDUCEDIMAGE
const TIFFFieldInfo * _TIFFFieldWithTag(TIFF *tif, ttag_t tag)
#define TIFFTAG_TILEDEPTH
#define TIFFTAG_IMAGEDEPTH
#define BYTECOUNTLOOKSBAD
void TIFFSwabLong(uint32 *lp)
tsize_t TIFFTileSize(TIFF *tif)
#define FIELD_TILEDIMENSIONS
int TIFFSetField(TIFF *tif, ttag_t tag,...)
int TIFFDefaultDirectory(TIFF *tif)
tsize_t TIFFStripSize(TIFF *tif)
#define FIELD_SAMPLESPERPIXEL
#define ReadOK(tif, buf, size)
tdata_t _TIFFCheckMalloc(TIFF *tif, size_t nmemb, size_t elem_size, const char *what)
toff_t * td_stripbytecount
void _TIFFfree(tdata_t p)
tdata_t _TIFFCheckRealloc(TIFF *tif, tdata_t buffer, size_t nmemb, size_t elem_size, const char *what)
#define TIFFTAG_SAMPLEFORMAT
#define TIFFCvtIEEEDoubleToNative(tif, n, dp)
#define TIFFTAG_OSUBFILETYPE
#define TIFFTAG_MAXSAMPLEVALUE
#define PLANARCONFIG_CONTIG
TIFFFieldInfo * _TIFFCreateAnonFieldInfo(TIFF *tif, ttag_t tag, TIFFDataType dt)
void _TIFFSetupFieldInfo(TIFF *, const TIFFFieldInfo[], size_t)