48#define DATATYPE_VOID 0
58#define DATATYPE_UINT 2
63#define DATATYPE_IEEEFP 3
133 setByteArray(NULL, (
void **)wpp, wp, n,
sizeof(uint16_t));
138 setByteArray(tif, (
void **)wpp, wp, n,
sizeof(uint16_t));
143 setByteArray(NULL, (
void **)lpp, lp, n,
sizeof(uint32_t));
148 setByteArray(tif, (
void **)lpp, lp, n,
sizeof(uint32_t));
168 setByteArray(tif, (
void **)lpp, lp, n,
sizeof(uint64_t));
182 setByteArray(NULL, (
void **)dpp, dp, n,
sizeof(
double));
222 ((
double *)*vpp)[nmemb] = value;
242 const uint16_t *wp, uint32_t n)
269 for (i = 0; i < 3; i++)
297 for (i = 0; i < 3; i++)
328 static const char module[] = "setColorMap";
332 for (i = 0; i < 3; i++)
334 cm[i] = va_arg(ap, uint16_t *);
338 "%s: ColorMap requires three arrays of %" PRIu32
344 for (i = 0; i < 3; i++)
375 static const char module[] = "setTransferFunction";
381 for (i = 0; i < v; i++)
383 tf[i] = va_arg(ap, uint16_t *);
387 "%s: TransferFunction requires %" PRIu32
388 " curves of %" PRIu32
" values each",
393 for (i = 0; i < v; i++)
444#define EXTRASAMPLE_COREL_UNASSALPHA 999
449 static const char module[] = "setExtraSamples";
454 va = va_arg(ap, uint16_t *);
455 if (*v > 0 && va == NULL)
457 for (i = 0; i < *v; i++)
479 "ExtraSamples tag value is changing, "
480 "but TransferFunction was read with a different value. "
489#undef EXTRASAMPLE_COREL_UNASSALPHA
518 const char *ep = s + slen;
522 for (; cp < ep && *cp !=
'\0'; cp++)
534 "%s: Invalid InkNames value; no null at given buffer end "
535 "location %" PRIu32
", after %" PRIu16
" ink",
601 static const char module[] = "_TIFFVSetField";
608 void *old_custom_value = NULL;
610 uint32_t standard_tag = tag;
624 switch (standard_tag)
627 td->td_subfiletype = (uint32_t)va_arg(ap, uint32_t);
630 td->td_imagewidth = (uint32_t)va_arg(ap, uint32_t);
633 td->td_imagelength = (uint32_t)va_arg(ap, uint32_t);
655 if (v != td->td_bitspersample)
668 uint64_t newcount = v < 32 ? (uint64_t)1 << v : 0;
670 if (newcount != 0 && newcount <= td->td_colormap_alloc)
671 td->td_colormap_count = (uint32_t)newcount;
675 "BitsPerSample tag value is changing, "
676 "but ColorMap was read with a "
677 "different value. Canceling it");
684 "BitsPerSample tag value is changing, "
685 "but TransferFunction was read with a "
686 "different value. Canceling it");
690 td->td_bitspersample = (uint16_t)v;
700 if (td->td_bitspersample == 8)
702 else if (td->td_bitspersample == 16)
704 else if (td->td_bitspersample == 24)
706 else if (td->td_bitspersample == 32)
708 else if (td->td_bitspersample == 64)
710 else if (td->td_bitspersample == 128)
723 if ((uint32_t)td->td_compression == v)
732 td->td_compression = (uint16_t)v;
737 td->td_photometric = (uint16_t)va_arg(ap,
uint16_vap);
740 td->td_threshholding = (uint16_t)va_arg(ap,
uint16_vap);
746 td->td_fillorder = (uint16_t)v;
753 td->td_orientation = (uint16_t)v;
759 if (v != td->td_samplesperpixel)
762 if (td->td_sminsamplevalue != NULL)
765 "SamplesPerPixel tag value is changing, "
766 "but SMinSampleValue tag was read with a "
767 "different value. Canceling it");
770 td->td_sminsamplevalue = NULL;
772 if (td->td_smaxsamplevalue != NULL)
775 "SamplesPerPixel tag value is changing, "
776 "but SMaxSampleValue tag was read with a "
777 "different value. Canceling it");
780 td->td_smaxsamplevalue = NULL;
785 if (td->td_transferfunction[0] != NULL &&
786 (v - td->td_extrasamples > 1) &&
787 !(td->td_samplesperpixel - td->td_extrasamples > 1))
790 "SamplesPerPixel tag value is changing, "
791 "but TransferFunction was read with a "
792 "different value. Canceling it");
796 td->td_samplesperpixel = (uint16_t)v;
799 v32 = (uint32_t)va_arg(ap, uint32_t);
802 td->td_rowsperstrip = v32;
805 td->td_tilelength = v32;
806 td->td_tilewidth = td->td_imagewidth;
810 td->td_minsamplevalue = (uint16_t)va_arg(ap,
uint16_vap);
813 td->td_maxsamplevalue = (uint16_t)va_arg(ap,
uint16_vap);
818 va_arg(ap,
double *),
819 td->td_samplesperpixel);
823 td->td_samplesperpixel);
828 va_arg(ap,
double *),
829 td->td_samplesperpixel);
833 td->td_samplesperpixel);
836 dblval = va_arg(ap,
double);
837 if (isnan(dblval) || dblval < 0)
842 dblval = va_arg(ap,
double);
843 if (isnan(dblval) || dblval < 0)
851 td->td_planarconfig = (uint16_t)v;
863 td->td_resolutionunit = (uint16_t)v;
866 td->td_pagenumber[0] = (uint16_t)va_arg(ap,
uint16_vap);
867 td->td_pagenumber[1] = (uint16_t)va_arg(ap,
uint16_vap);
870 td->td_halftonehints[0] = (uint16_t)va_arg(ap,
uint16_vap);
871 td->td_halftonehints[1] = (uint16_t)va_arg(ap,
uint16_vap);
874 if (td->td_bitspersample >= 32)
876 v = td->td_bitspersample;
879 v32 = 1U << td->td_bitspersample;
888 td->td_extrasamples = (((uint16_t)va_arg(ap,
uint16_vap)) != 0);
889 if (td->td_extrasamples)
896 v32 = (uint32_t)va_arg(ap, uint32_t);
903 "Nonstandard tile width %" PRIu32
", convert file", v32);
905 td->td_tilewidth = v32;
909 v32 = (uint32_t)va_arg(ap, uint32_t);
916 "Nonstandard tile length %" PRIu32
", convert file", v32);
918 td->td_tilelength = v32;
922 v32 = (uint32_t)va_arg(ap, uint32_t);
925 td->td_tiledepth = v32;
946 td->td_sampleformat = (uint16_t)v;
952 td->td_sampleformat = (uint16_t)v;
956 td->td_bitspersample == 32 &&
961 td->td_bitspersample == 64 &&
966 td->td_imagedepth = (uint32_t)va_arg(ap, uint32_t);
971 td->td_nsubifd = (uint16_t)va_arg(ap,
uint16_vap);
973 (uint64_t *)va_arg(ap, uint64_t *),
974 (uint32_t)td->td_nsubifd);
984 td->td_ycbcrpositioning = (uint16_t)va_arg(ap,
uint16_vap);
987 td->td_ycbcrsubsampling[0] = (uint16_t)va_arg(ap,
uint16_vap);
988 td->td_ycbcrsubsampling[1] = (uint16_t)va_arg(ap,
uint16_vap);
991 if (td->td_bitspersample >= 32)
993 v = td->td_bitspersample;
1002 va_arg(ap,
float *), 6);
1007 s = va_arg(ap,
char *);
1008 uint16_t ninksinstring;
1010 status = ninksinstring > 0;
1011 if (ninksinstring > 0)
1014 td->td_inknameslen = (int)v;
1018 if (td->td_numberofinks != ninksinstring)
1022 "Warning %s; Tag %s:\n Value %" PRIu16
1023 " of NumberOfInks is different from the number of "
1025 ".\n -> NumberOfInks value adapted to %" PRIu16
"",
1027 ninksinstring, ninksinstring);
1028 td->td_numberofinks = ninksinstring;
1033 td->td_numberofinks = ninksinstring;
1038 if (td->td_numberofinks != td->td_samplesperpixel)
1041 "Warning %s; Tag %s:\n Value %" PRIu16
1042 " of NumberOfInks is different from the "
1043 "SamplesPerPixel value %" PRIu16
"",
1045 td->td_numberofinks,
1046 td->td_samplesperpixel);
1058 if (v != td->td_numberofinks)
1062 "Error %s; Tag %s:\n It is not possible to set the "
1064 " for NumberOfInks\n which is different from the "
1065 "number of inks in the InkNames tag (%" PRIu16
")",
1074 td->td_numberofinks = (uint16_t)v;
1077 if (td->td_numberofinks != td->td_samplesperpixel)
1080 "Warning %s; Tag %s:\n Value %" PRIu32
1081 " of NumberOfInks is different from the "
1082 "SamplesPerPixel value %" PRIu16
"",
1084 td->td_samplesperpixel);
1099 int tv_size, iCustom;
1116 "%s: Ignored %stag \"%s\" (not supported by libtiff)",
1126 "%s: Invalid %stag \"%s\" (not supported by codec)",
1137 for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++)
1139 if (td->td_customValues[iCustom].info->field_tag == tag)
1141 tv = td->td_customValues + iCustom;
1142 old_custom_value = tv->
value;
1156 (
tmsize_t)td->td_customValueCount + 1;
1157 const tmsize_t custom_values_size =
1159 new_custom_count, module);
1160 if (custom_values_size == 0)
1166 tif, td->td_customValues, custom_values_size);
1167 if (!new_customValues)
1170 "%s: Failed to allocate space for list of "
1177 td->td_customValueCount++;
1178 td->td_customValues = new_customValues;
1180 tv = td->td_customValues + (td->td_customValueCount - 1);
1195 TIFFErrorExtR(tif, module,
"%s: Bad field type %u for \"%s\"",
1208 ma = (uint32_t)va_arg(ap, uint32_t);
1209 mb = (
const char *)va_arg(ap,
const char *);
1213 mb = (
const char *)va_arg(ap,
const char *);
1214 size_t len = strlen(mb) + 1;
1215 if (len >= 0x80000000U)
1219 "%s: Too long string value for \"%s\". "
1220 "Maximum supported is 2147483647 bytes",
1227 tv->
count = (int)ma;
1229 if (!tv->
value && ma != 0)
1241 tv->
count = (int)va_arg(ap, uint32_t);
1243 tv->
count = va_arg(ap,
int);
1249 tv->
count = td->td_samplesperpixel;
1256 "%s: Null count for \"%s\" (type "
1257 "%u, writecount %d, passcount %d)",
1265 "custom tag binary object");
1281 v2[0] = (uint16_t)va_arg(ap,
int);
1282 v2[1] = (uint16_t)va_arg(ap,
int);
1307 uint64_t *pui64 = (uint64_t *)tv->
value;
1308 for (
int i = 0; i < tv->
count; i++)
1310 if (pui64[i] > 0xffffffffu)
1314 "%s: Bad %s value %" PRIu64
1315 " at %d. array position for \"%s\" tag "
1316 "%u in ClassicTIFF. Tag won't be "
1323 goto badvalueifd8long8;
1329 int64_t *pi64 = (int64_t *)tv->
value;
1330 for (
int i = 0; i < tv->
count; i++)
1332 if (pi64[i] > 2147483647 ||
1333 pi64[i] < (-2147483647 - 1))
1337 "%s: Bad SLONG8 value %" PRIi64
1338 " at %d. array position for \"%s\" tag "
1339 "%u in ClassicTIFF. Tag won't be "
1343 goto badvalueifd8long8;
1351 char *val = (
char *)tv->
value;
1352 assert(tv->
count == 1);
1359 uint8_t v2 = (uint8_t)va_arg(ap,
int);
1365 int8_t v2 = (int8_t)va_arg(ap,
int);
1371 uint16_t v2 = (uint16_t)va_arg(ap,
int);
1377 int16_t v2 = (int16_t)va_arg(ap,
int);
1384 uint32_t v2 = va_arg(ap, uint32_t);
1390 int32_t v2 = va_arg(ap, int32_t);
1397 uint64_t v2 = va_arg(ap, uint64_t);
1406 "%s: Bad LONG8 or IFD8 value %" PRIu64
1407 " for \"%s\" tag %u in ClassicTIFF. Tag "
1408 "won't be written to file",
1410 goto badvalueifd8long8;
1416 int64_t v2 = va_arg(ap, int64_t);
1421 ((v2 > 2147483647) || (v2 < (-2147483647 - 1))))
1425 "%s: Bad SLONG8 value %" PRIi64
1426 " for \"%s\" tag %u in ClassicTIFF. Tag "
1427 "won't be written to file",
1429 goto badvalueifd8long8;
1442 double v2 = va_arg(ap,
double);
1448 float v3 = (float)va_arg(ap,
double);
1457 ".set_get_field_type "
1473 double v2 = va_arg(ap,
double);
1486 if (old_custom_value)
1489 old_custom_value = NULL;
1502 if (old_custom_value)
1509 TIFFErrorExtR(tif, module,
"%s: Bad value %" PRIu32
" for \"%s\" tag",
1517 TIFFErrorExtR(tif, module,
"%s: Bad value %" PRIu32
" for \"%s\" tag",
1526 dblval, fip2 ? fip2->
field_name :
"Unknown");
1536 for (iCustom2 = 0; iCustom2 < td->td_customValueCount; iCustom2++)
1538 if (td->td_customValues[iCustom2].info->field_tag == tag)
1540 tv2 = td->td_customValues + (iCustom2);
1547 if (tv2->
value != NULL)
1554 td->td_customValueCount--;
1555 for (iC2 = iCustom2; iC2 < td->td_customValueCount; iC2++)
1557 td->td_customValues[iC2] = td->td_customValues[iC2 + 1];
1564 if (old_custom_value)
1599 TIFFErrorExtR(tif,
"TIFFSetField",
"%s: Unknown %stag %" PRIu32,
1613 "%s: Cannot modify tag \"%s\" while writing",
1664 if (i < td->td_customValueCount)
1724 uint32_t standard_tag = tag;
1740 switch (standard_tag)
1792 *va_arg(ap,
double *) = v;
1806 *va_arg(ap,
double *) = v;
1836 *va_arg(ap,
const uint16_t **) = td->
td_colormap[0];
1837 *va_arg(ap,
const uint16_t **) = td->
td_colormap[1];
1838 *va_arg(ap,
const uint16_t **) = td->
td_colormap[2];
1855 *va_arg(ap, uint16_t *) =
1899 *va_arg(ap,
const uint64_t **) = td->
td_subifd;
1917 *va_arg(ap,
const uint16_t **) = NULL;
1918 *va_arg(ap,
const uint16_t **) = NULL;
1946 "%s: Invalid %stag \"%s\" "
1947 "(not supported by codec)",
1973 *va_arg(ap, uint32_t *) = (uint32_t)tv->
count;
1975 *va_arg(ap, uint16_t *) = (uint16_t)tv->
count;
1976 *va_arg(ap,
const void **) = tv->
value;
1986 *va_arg(ap, uint16_t *) = ((uint16_t *)tv->
value)[0];
1987 *va_arg(ap, uint16_t *) = ((uint16_t *)tv->
value)[1];
1997 *va_arg(ap,
void **) = tv->
value;
2002 char *val = (
char *)tv->
value;
2003 assert(tv->
count == 1);
2008 *va_arg(ap, uint8_t *) = *(uint8_t *)val;
2012 *va_arg(ap, int8_t *) = *(int8_t *)val;
2016 *va_arg(ap, uint16_t *) = *(uint16_t *)val;
2020 *va_arg(ap, int16_t *) = *(int16_t *)val;
2025 *va_arg(ap, uint32_t *) = *(uint32_t *)val;
2029 *va_arg(ap, int32_t *) = *(int32_t *)val;
2034 *va_arg(ap, uint64_t *) = *(uint64_t *)val;
2038 *va_arg(ap, int64_t *) = *(int64_t *)val;
2050 *va_arg(ap,
double *) = *(
double *)val;
2056 *va_arg(ap,
float *) = *(
float *)val;
2065 ".set_get_field_type "
2073 *va_arg(ap,
float *) = *(
float *)val;
2077 *va_arg(ap,
double *) = *(
double *)val;
2138#define CleanupField(member) \
2142 _TIFFfreeExt(tif, td->member); \
2155 td->
td_row = (uint32_t)-1;
2156 td->
td_col = (uint32_t)-1;
2280 "Invalid TIFFFieldArray provided (NULL pointer)");
2335#ifdef STRIPBYTECOUNTSORTED_UNUSED
2336 td->td_stripbytecountsorted = 1;
2381 (*_TIFFextender)(tif);
2431 static const char module[] = "TIFFAdvanceDirectory";
2437 "Starting directory %u at offset 0x%" PRIx64
" (%" PRIu64
2438 ") might cause an IFD loop",
2439 *nextdirnum, *nextdiroff, *nextdiroff);
2447 uint64_t poff = *nextdiroff;
2450 tmsize_t poffa, poffb, poffc, poffd;
2454 poff > (uint64_t)tif->
tif_size -
sizeof(uint16_t))
2457 "%s:%d: %s: Error fetching directory count",
2458 __FILE__, __LINE__, tif->
tif_name);
2463 poffb = poffa + (
tmsize_t)
sizeof(uint16_t);
2470 TIFFErrorExtR(tif, module,
"Error fetching directory link");
2473 poffc = poffb + dircount * 12;
2474 poffd = poffc + (
tmsize_t)
sizeof(uint32_t);
2477 TIFFErrorExtR(tif, module,
"Error fetching directory link");
2481 *off = (uint64_t)poffc;
2485 *nextdiroff = nextdir32;
2489 tmsize_t poffa, poffb, poffc, poffd;
2490 uint64_t dircount64;
2494 "%s:%d: %s: Error fetching directory count",
2495 __FILE__, __LINE__, tif->
tif_name);
2499 poffb = poffa + (
tmsize_t)
sizeof(uint64_t);
2503 "%s:%d: %s: Error fetching directory count",
2504 __FILE__, __LINE__, tif->
tif_name);
2510 if (dircount64 > 0xFFFF)
2513 "Sanity check on directory count failed");
2519 TIFFErrorExtR(tif, module,
"Error fetching directory link");
2522 poffc = poffb + (
tmsize_t)(dircount64 * 20);
2523 poffd = poffc + (
tmsize_t)
sizeof(uint64_t);
2526 TIFFErrorExtR(tif, module,
"Error fetching directory link");
2530 *off = (uint64_t)poffc;
2542 if (!
SeekOK(tif, *nextdiroff) ||
2543 !
ReadOK(tif, &dircount,
sizeof(uint16_t)))
2546 "%s:%d: %s: Error fetching directory count",
2547 __FILE__, __LINE__, tif->
tif_name);
2556 if (!
ReadOK(tif, &nextdir32,
sizeof(uint32_t)))
2558 TIFFErrorExtR(tif, module,
"%s: Error fetching directory link",
2564 *nextdiroff = nextdir32;
2568 uint64_t dircount64;
2569 if (!
SeekOK(tif, *nextdiroff) ||
2570 !
ReadOK(tif, &dircount64,
sizeof(uint64_t)))
2573 "%s:%d: %s: Error fetching directory count",
2574 __FILE__, __LINE__, tif->
tif_name);
2579 if (dircount64 > 0xFFFF)
2582 "%s:%d: %s: Error fetching directory count",
2583 __FILE__, __LINE__, tif->
tif_name);
2590 if (!
ReadOK(tif, nextdiroff,
sizeof(uint64_t)))
2592 TIFFErrorExtR(tif, module,
"%s: Error fetching directory link",
2600 if (*nextdiroff != 0)
2609 "the next directory %u at offset 0x%" PRIx64
" (%" PRIu64
2610 ") might be an IFD loop. Treating directory %d as "
2612 *nextdirnum, *nextdiroff, *nextdiroff, (
int)(*nextdirnum) - 1);
2625 uint64_t nextdiroff;
2634 while (nextdiroff != 0 &&
2650 uint64_t nextdiroff;
2682 const int relative = (dirn >= tif->
tif_curdir) &&
2700 for (n = dirn; n > 0 && nextdiroff != 0; n--)
2705 if (nextdiroff == 0 || n > 0)
2756 uint32_t curdir = 0;
2757 int8_t probablySubIFD = 0;
2787 if (!retval && diroff != 0 && tif->
tif_curdir == curdir)
2830 static const char module[] = "TIFFUnlinkDirectory";
2839 "Can not unlink directory in read-only file");
2845 "For TIFFUnlinkDirectory() first directory starts with "
2846 "number 1 and not 0");
2866 for (n = dirn - 1; n > 0; n--)
2870 TIFFErrorExtR(tif, module,
"Directory %u does not exist", dirn);
2891 nextdir32 = (uint32_t)nextdir;
2892 assert((uint64_t)nextdir32 == nextdir);
2895 if (!
WriteOK(tif, &nextdir32,
sizeof(uint32_t)))
2904 uint64_t nextdir64 = nextdir;
2907 if (!
WriteOK(tif, &nextdir64,
sizeof(uint64_t)))
float _TIFFClampDoubleToFloat(double val)
Clamp a double to the finite float range before conversion.
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and multiply two signed-size operands.
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Reset methods and install the selected compression implementation.
int _TIFFCheckDirNumberAndOffset(TIFF *tif, tdir_t dirn, uint64_t diroff)
Register or validate a chain index/offset pair for loop detection.
int _TIFFGetOffsetFromDirNumber(TIFF *tif, tdir_t dirn, uint64_t *diroff)
Resolve an index from the existing number-to-offset map.
int _TIFFGetDirNumberFromOffset(TIFF *tif, uint64_t diroff, tdir_t *dirn)
Resolve a directory offset using the chain maps.
#define CleanupField(member)
Release and clear one directory-owned allocation.
int TIFFDefaultDirectory(TIFF *tif)
Install the image schema, default values, and core tag methods.
void _TIFFResetTifDirAndInitStrileCounters(TIFFDirectory *td)
Zero directory storage and initialise traversal sentinels.
static int TIFFAdvanceDirectory(TIFF *tif, uint64_t *nextdiroff, uint64_t *off, tdir_t *nextdirnum)
Read one chain link and update traversal/map bookkeeping.
#define FIELD_TRANSFERFUNCTION
Index the transfer function presence bit; not an on-disk tag number.
#define FIELD_SMAXSAMPLEVALUE
Index the per-sample maximum presence bit; not an on-disk tag number.
#define FIELD_YCBCRSUBSAMPLING
Index the YCbCr subsampling presence bit; not an on-disk tag number.
#define FIELD_COLORMAP
Index the colormap presence bit; not an on-disk tag number.
static const TIFFFieldArray exifFieldArray
Wrap the static EXIF field schema.
#define NOSTRIP
Represent the absence of a current strip with UINT32_MAX.
#define FIELD_IGNORE
Mark a processed-but-discarded tag; bit zero is reserved.
const TIFFFieldArray * _TIFFGetFields(void)
Return the built-in image field schema.
#define FIELD_SMINSAMPLEVALUE
Index the per-sample minimum presence bit; not an on-disk tag number.
#define TIFFFieldSet(tif, field)
Test a directory presence bit.
static const TIFFFieldArray tiffFieldArray
Wrap the static image field schema.
#define FIELD_NUMBEROFINKS
Index the number of inks presence bit; not an on-disk tag number.
#define FIELD_TILEDIMENSIONS
Index the tile dimensions presence bit; not an on-disk tag number.
static const TIFFFieldArray gpsFieldArray
Wrap the static GPS field schema.
#define FIELD_COMPRESSION
Index the compression presence bit; not an on-disk tag number.
void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
Replace the registered field-pointer table with a schema.
#define FIELD_YCBCRPOSITIONING
Index the YCbCr positioning presence bit; not an on-disk tag number.
const TIFFFieldArray * _TIFFGetGpsFields(void)
Return the built-in GPS field schema.
#define NOTILE
Represent the absence of a current tile with UINT32_MAX.
#define TIFFClrFieldBit(tif, field)
Clear a directory presence bit.
static TIFFExtendProc _TIFFextender
Store the process-wide borrowed directory-extension callback.
#define FIELD_INKNAMES
Index the ink names presence bit; not an on-disk tag number.
#define TIFFSetFieldBit(tif, field)
Set a directory presence bit.
#define FIELD_SAMPLESPERPIXEL
Index the samples per pixel presence bit; not an on-disk tag number.
const TIFFFieldArray * _TIFFGetExifFields(void)
Return the built-in EXIF field schema.
void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
Leave decoded bytes unchanged.
void _TIFFSwab24BitData(TIFF *tif, uint8_t *buf, tmsize_t cc)
Swap each 3-byte sample in place.
void _TIFFSwab16BitData(TIFF *tif, uint8_t *buf, tmsize_t cc)
Swap each 2-byte sample in place.
void _TIFFSwab32BitData(TIFF *tif, uint8_t *buf, tmsize_t cc)
Swap each 4-byte sample in place.
void _TIFFSwab64BitData(TIFF *tif, uint8_t *buf, tmsize_t cc)
Swap each 8-byte sample in place.
void _TIFFCleanupIFDOffsetAndNumberMaps(TIFF *tif)
Release a handle's directory-offset/index lookup maps.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
void _TIFFsetLongArray(uint32_t **lpp, const uint32_t *lp, uint32_t n)
Replace an owned long array with a copied array.
static void setByteArray(TIFF *tif, void **vpp, const void *vp, size_t nmemb, size_t elem_size)
Discard an old allocation and copy a replacement byte product.
void _TIFFsetLongArrayExt(TIFF *tif, uint32_t **lpp, const uint32_t *lp, uint32_t n)
Replace an owned long array with a copied array.
void _TIFFsetByteArray(void **vpp, const void *vp, uint32_t n)
Replace an owned byte array with a copied array.
void _TIFFsetFloatArrayExt(TIFF *tif, float **fpp, const float *fp, uint32_t n)
Replace an owned float array with a copied array.
static void _TIFFsetNString(TIFF *tif, char **cpp, const char *cp, uint32_t n)
Replace an owned string byte sequence with a copy.
static void _TIFFsetLong8Array(TIFF *tif, uint64_t **lpp, const uint64_t *lp, uint32_t n)
Replace an owned 64-bit integer array with a copy.
void _TIFFsetByteArrayExt(TIFF *tif, void **vpp, const void *vp, uint32_t n)
Replace an owned byte array with a copied array.
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Resize a handle-aware block or release it for a nonpositive size.
static void setDoubleArrayOneValue(TIFF *tif, double **vpp, double value, size_t nmemb)
Replace an owned double array with one repeated value.
void _TIFFsetDoubleArray(double **dpp, const double *dp, uint32_t n)
Replace an owned double array with a copied array.
void _TIFFsetDoubleArrayExt(TIFF *tif, double **dpp, const double *dp, uint32_t n)
Replace an owned double array with a copied array.
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
void _TIFFsetShortArray(uint16_t **wpp, const uint16_t *wp, uint32_t n)
Replace an owned short array with a copied array.
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Allocate a checked array with an allocation-failure diagnostic.
static int setShortArrayWithCount(TIFF *tif, uint16_t **wpp, uint32_t *countp, const uint16_t *wp, uint32_t n)
Install a short array together with the number of elements it holds.
void _TIFFsetShortArrayExt(TIFF *tif, uint16_t **wpp, const uint16_t *wp, uint32_t n)
Replace an owned short array with a copied array.
void _TIFFsetFloatArray(float **fpp, const float *fp, uint32_t n)
Replace an owned float array with a copied array.
#define TIFF_NON_EXISTENT_DIR_NUMBER
Mark an unknown or nonexistent directory index.
#define WriteOK(tif, buf, size)
Test whether one client write transfers the entire requested byte count.
#define TIFF_MYBUFFER
Mark a raw buffer owned and released by the handle.
#define TIFF_BUFFERSETUP
Mark completed data-buffer setup.
#define ReadOK(tif, buf, size)
Test whether one client read transfers the entire requested byte count.
#define TIFF_POSTENCODE
Request a pending codec postencode call.
#define TIFF_PERSAMPLE
Select per-sample arrays for supported sample-valued fields.
#define TIFF_BUF4WRITE
Interpret the raw buffer and its byte count as pending output.
#define SeekOK(tif, off)
Test whether an absolute seek reaches the requested file position.
#define isPseudoTag(t)
Test whether a tag identifier is outside the on-disk 16-bit range.
#define TIFF_INSUBIFD
Mark writing within a SubIFD sequence.
#define isMapped(tif)
Test whether TIFF_MAPPED is set on a handle.
#define TRUE
Represent the legacy internal true value.
#define FALSE
Represent the legacy internal false value.
#define TIFF_BEENWRITING
Record that scanline or image-data writing has begun.
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
#define TIFF_DIRTYDIRECT
Mark a current directory that needs writing.
#define TIFF_BIGTIFF
Mark the BigTIFF file format.
#define TIFF_SWAB
Request swapping multibyte file values to or from host order.
#define TIFF_ISTILED
Mark tile-based rather than strip-based image storage.
static void cancelTransferFunction(TIFF *tif)
Drop a TransferFunction that no longer describes the directory it belongs to.
#define DATATYPE_INT
Identify legacy DataType signed integer samples.
static void cancelColorMap(TIFF *tif)
Drop a ColorMap that no longer describes the directory it belongs to.
static int setTransferFunction(TIFF *tif, va_list ap, uint32_t count)
Install the TransferFunction curves.
#define DATATYPE_UINT
Identify legacy DataType unsigned integer samples.
#define DATATYPE_IEEEFP
Identify legacy DataType IEEE floating-point samples.
static int _TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap)
Implement core and generic custom-tag queries.
static int OkToChangeTag(TIFF *tif, uint32_t tag)
Check registration and tag mutability during writing.
#define DATATYPE_VOID
Identify legacy DataType untyped samples.
static int _TIFFVSetField(TIFF *tif, uint32_t tag, va_list ap)
Implement core and generic custom-tag storage.
#define EXTRASAMPLE_COREL_UNASSALPHA
Recognise Corel's nonstandard unassociated-alpha code.
static int setColorMap(TIFF *tif, va_list ap, uint32_t count)
Install the ColorMap arrays.
static uint16_t countInkNamesString(TIFF *tif, uint32_t slen, const char *s)
Count terminated ink names within a byte extent.
static int setExtraSamples(TIFF *tif, va_list ap, uint32_t *v)
Validate and install extra-sample interpretations.
static void removeCustomValue(TIFFDirectory *td, int i)
Remove a custom tag entry whose value could not be set.
void TIFFSwabLong8(uint64_t *lp)
Reverse the byte order of one value.
void TIFFSwabShort(uint16_t *wp)
Reverse the byte order of one value.
void TIFFSwabLong(uint32_t *lp)
Reverse the byte order of one value.
#define FIELD_CUSTOM
Identify a field stored through the custom-metadata mechanism.
#define TIFF_SPP
Mark a field whose count follows SamplesPerPixel.
#define TIFF_VARIABLE
Mark a variable-length field with a 16-bit count convention.
#define TIFF_ANY
Match any data type when searching for a field descriptor.
#define TIFF_VARIABLE2
Mark a variable-length field with a 32-bit count convention.
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a warning diagnostic to the configured handlers.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
tdir_t TIFFNumberOfDirectories(TIFF *tif)
Count reachable main-chain directories from the cached file header.
int TIFFSetSubDirectory(TIFF *tif, uint64_t diroff)
Select and read an image directory at a file offset.
void TIFFFreeDirectory(TIFF *tif)
Release the current directory's owned values and codec state.
int TIFFLastDirectory(TIFF *tif)
Test whether the cached next-directory link is zero.
int TIFFCreateGPSDirectory(TIFF *tif)
Create a fresh in-memory EXIF GPS metadata directory.
int TIFFSetDirectory(TIFF *tif, tdir_t dirn)
Select and read an image directory by its main-chain index.
int TIFFUnlinkDirectory(TIFF *tif, tdir_t dirn)
Remove an image directory from the on-file main chain.
int TIFFCreateDirectory(TIFF *tif)
Replace current values with a fresh in-memory image directory.
int TIFFCreateCustomDirectory(TIFF *tif, const TIFFFieldArray *infoarray)
Replace current values with a fresh custom metadata directory.
int TIFFCreateEXIFDirectory(TIFF *tif)
Create a fresh in-memory EXIF metadata directory.
uint64_t TIFFCurrentDirOffset(TIFF *tif)
Read the cached file offset of the current directory.
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32_t tag)
Find a registered field by tag number.
void(* TIFFExtendProc)(TIFF *tif)
Extend the image-directory field table during default initialisation.
const TIFFField * TIFFFindField(TIFF *tif, uint32_t tag, TIFFDataType dt)
Find a registered field by tag number and file data type.
TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc extender)
Replace the process-wide image-directory extension callback.
int TIFFFieldSetGetSize(const TIFFField *fip)
Report the internal element storage width of a field.
int TIFFReadDirectory(TIFF *tif)
Read and install the next image directory.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
int TIFFUnsetField(TIFF *tif, uint32_t tag)
Clear tag presence or remove a stored custom value.
int TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap)
Query a present tag in the current directory.
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Set a tag value in the current in-memory directory.
int TIFFGetField(TIFF *tif, uint32_t tag,...)
Query a present tag in the current directory.
int TIFFVSetField(TIFF *tif, uint32_t tag, va_list ap)
Set a tag value in the current in-memory directory.
int uint16_vap
Represent a uint16_t value after default variadic argument promotion.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
uint32_t tdir_t
Represent a zero-based directory index, rather than a file offset.
@ TIFF_SSHORT
Signed 16-bit integer.
@ TIFF_SLONG
Signed 32-bit integer.
@ TIFF_BYTE
Unsigned 8-bit integer.
@ TIFF_SBYTE
Signed 8-bit integer.
@ TIFF_IFD
Unsigned 32-bit IFD byte offset.
@ TIFF_SHORT
Unsigned 16-bit integer.
@ TIFF_UNDEFINED
Untyped 8-bit data.
@ TIFF_LONG
Unsigned 32-bit integer.
@ TIFF_SLONG8
BigTIFF signed 64-bit integer.
@ TIFF_LONG8
BigTIFF unsigned 64-bit integer.
@ TIFF_ASCII
Sequence of 8-bit bytes ending in a null byte.
@ TIFF_NOTYPE
Placeholder for an unspecified field type.
@ TIFF_FLOAT
32-bit IEEE floating-point value.
@ TIFF_DOUBLE
64-bit IEEE floating-point value.
@ TIFF_IFD8
BigTIFF unsigned 64-bit IFD byte offset.
@ TIFF_SRATIONAL
Signed 32-bit numerator and denominator.
@ TIFF_RATIONAL
Unsigned 32-bit numerator and denominator.
Represent a parsed directory entry before value conversion.
Store the current directory values and image traversal state.
uint32_t td_colormap_alloc
Number of entries allocated in each ColorMap plane, zero when none is installed.
int td_customValueCount
Number of live records in td_customValues, including partial setter entries.
uint16_t td_pagenumber[2]
Page index and total-page count as two uint16_t values.
float td_xposition
Horizontal image position in resolution units.
uint32_t td_tiledepth
Tile depth in slices.
uint16_t td_fillorder
FILLORDER_* bit order within file bytes.
uint32_t td_dirdatasize_Noffsets
Number of ranges collected in td_dirdatasize_offsets.
float td_xresolution
Horizontal pixels per resolution unit.
uint64_t td_dirdatasize_read
Reusable IFD span including entry space and contiguous external data; UINT64_MAX permits extension at...
uint16_t * td_sampleinfo
Owned ExtraSamples interpretation array of td_extrasamples entries, or NULL.
tmsize_t td_tilesize
Cached decoded tile size in bytes; minus one when invalidated.
float * td_refblackwhite
Owned six-float reference black/white array, or NULL.
uint32_t td_rowsperstrip
Rows per strip; UINT32_MAX represents one whole-image strip.
uint32_t td_imagewidth
Image width in pixels.
uint16_t td_compression
COMPRESSION_* codec identifier.
uint16_t td_photometric
PHOTOMETRIC_* interpretation.
uint32_t td_tilewidth
Tile width in pixels.
tmsize_t td_scanlinesize
Cached decoded scanline size in bytes; zero when not computed.
float td_yresolution
Vertical pixels per resolution unit.
uint16_t td_extrasamples
Number of extra samples described by td_sampleinfo.
uint16_t td_threshholding
THRESHHOLD_* bilevel rendering convention.
uint16_t td_minsamplevalue
Legacy unsigned minimum sample value.
double * td_sminsamplevalue
Owned SamplesPerPixel-length array of minimum values, or NULL.
uint16_t td_bitspersample
Bits in each sample.
char * td_inknames
Owned concatenated null-terminated ink names, or NULL.
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
TIFFDirEntry td_stripoffset_entry
Deferred offset entry; tag/type/count are swapped but offset storage is raw.
uint16_t * td_transferfunction[3]
Up to three owned gamma curves of td_transferfunction_count entries each.
uint16_t td_maxsamplevalue
Legacy unsigned maximum sample value.
uint32_t td_imagedepth
Image depth in slices.
uint16_t td_orientation
ORIENTATION_* storage orientation.
uint32_t td_fieldsset[FIELDSET_ITEMS]
Presence bitmap indexed by FIELD_* bit numbers.
uint16_t td_resolutionunit
RESUNIT_* unit for resolution and position values.
uint32_t td_colormap_count
Number of entries in each ColorMap plane that the directory uses, zero when none is installed.
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
TIFFTagValue * td_customValues
Owned array of custom-value records, each owning its value.
double * td_smaxsamplevalue
Owned SamplesPerPixel-length array of maximum values, or NULL.
uint64_t * td_stripbytecount_p
Owned byte-count array/cache, possibly NULL or partial; use TIFFGetStrileByteCount().
unsigned char td_iswrittentofile
Nonzero when the current directory has an on-file representation.
uint64_t * td_stripoffset_p
Owned offset array/cache, possibly NULL or partial; use TIFFGetStrileOffset().
uint16_t * td_colormap[3]
Three owned palette planes of td_colormap_alloc entries each, or NULL slots; presence is FIELD_COLORM...
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
uint16_t td_ycbcrsubsampling[2]
Horizontal and vertical YCbCr subsampling factors.
uint64_t td_dirdatasize_write
Accumulated IFD write size in bytes, including entry space after counting.
uint32_t td_col
Current pixel column; UINT32_MAX before traversal starts.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_subfiletype
NewSubfileType flag mask.
uint16_t td_numberofinks
Number of inks, kept consistent with accepted InkNames where possible.
TIFFDirEntry td_stripbytecount_entry
Deferred byte-count entry; offset storage still requires swapping.
uint32_t td_imagelength
Image length in rows.
uint32_t td_stripoffsetbyteallocsize
Allocated element capacity of lazy strile offset/count caches, not byte size.
TIFFEntryOffsetAndLength * td_dirdatasize_offsets
Owned auxiliary array of external IFD-value ranges, or NULL.
uint32_t td_curtile
Current tile index, or NOTILE.
uint32_t td_tilelength
Tile length in rows.
uint16_t td_nsubifd
Number of child-directory offsets in td_subifd.
uint64_t * td_subifd
Owned array of td_nsubifd child-directory offsets, or NULL.
float td_yposition
Vertical image position in resolution units.
uint32_t td_transferfunction_count
Number of entries in each installed TransferFunction curve, zero when none is installed; the only rec...
uint16_t td_ycbcrpositioning
YCBCRPOSITION_* placement convention.
uint16_t td_halftonehints[2]
Highlight and shadow grayscale breakpoints.
uint32_t td_curstrip
Current strip index, or NOSTRIP.
TIFFVGetMethod vgetfield
Variadic tag-query implementation for the handle.
TIFFVSetMethod vsetfield
Variadic tag-setting implementation for the handle.
TIFFPrintMethod printdir
Optional codec/extension directory-print callback.
Store one custom field value and its descriptor.
void * value
Owned custom-value allocation, or NULL after clearing/failure.
int count
Number of internally stored elements; after a partial setter failure it may be zero or a nonzero coun...
const TIFFField * info
Borrowed live descriptor; must outlive this custom value.
Describe a borrowed schema or owned compatibility batch.
uint32_t allocated_size
Descriptor capacity when owned; zero identifies a static schema.
TIFFField * fields
Descriptor array; static/borrowed or owned according to allocated_size and creator.
Describe a field's file type and internal argument contract.
unsigned char field_oktochange
Nonzero to permit changes after writing starts; ImageLength is separately exempt.
TIFFDataType field_type
On-disk TIFFDataType, distinct from the argument representation.
unsigned char field_passcount
Nonzero for an explicit count argument; tag-specific exceptions still apply.
const char * field_name
Borrowed or anonymous-owned null-terminated name; must remain live while used.
unsigned short field_bit
FIELD_* presence index; FIELD_CUSTOM shares storage through the custom list.
uint32_t field_tag
Tag identifier in this schema namespace.
short field_readcount
Fixed getter count or TIFF_VARIABLE/TIFF_VARIABLE2/TIFF_SPP rule.
short field_writecount
Fixed setter count or variable/sample-count sentinel.
Hold private state for one open TIFF library instance.
const TIFFField * tif_foundfield
Borrowed cached field descriptor; valid only while that descriptor lives.
tdir_t tif_curdircount
Cache the number of main IFDs in the file.
TIFFTagMethods tif_tagmethods
Inline table of directory field and print callbacks.
int tif_setdirectory_force_absolute
Nonzero to force absolute rather than relative directory stepping.
tmsize_t tif_rawdataloaded
Number of bytes loaded into the raw-buffer window.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
uint64_t tif_curoff
Tracked current file byte offset for read/write operations.
uint64_t tif_nextdiroff
Next directory byte offset from the current chain link.
TIFFPostMethod tif_postdecode
Callback transforming decoded data, for example by byte swapping.
uint64_t tif_diroff
Current directory byte offset, or zero for an unlinked in-memory IFD.
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
TIFFDirectory tif_dir
Inline representation of the current image directory.
tmsize_t tif_size
Mapped-file region length in bytes.
tdir_t tif_curdir
Track the current or last-written directory index.
TIFFVoidMethod tif_cleanup
Codec callback releasing codec-private state.
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
uint8_t * tif_rawdata
Raw buffer; ownership/mapping follow TIFF_MYBUFFER and TIFF_BUFFERMMAP.
TIFFHeaderUnion tif_header
Inline decoded classic TIFF or BigTIFF file header.
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
tmsize_t tif_rawdataoff
Byte offset of the raw-buffer window within the strip.
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
size_t tif_nfieldscompat
Number of entries in tif_fieldscompat.
uint64_t tif_lastdiroff
Byte offset of the last directory written so far.
int tif_mode
Current access mode using the O_* constants.
TIFFFieldArray * tif_fieldscompat
Owned array of legacy field-registration batches.
uint8_t * tif_base
Mapped-file base provided by tif_mapproc; released through tif_unmapproc by TIFFCleanup() only while ...
Declare private library state, callbacks, and implementation helpers.