53#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
67#define TIFFCvtNativeToIEEEDouble(tif, n, dp)
107 uint16_t tag, uint32_t count,
112 uint32_t count,
char *value);
115 uint32_t count, uint8_t *value);
118 uint32_t count, uint8_t *value);
121 uint32_t count, int8_t *value);
127 uint32_t count, uint16_t *value);
133 uint32_t count, int16_t *value);
139 uint32_t count, uint32_t *value);
142 uint32_t count, int32_t *value);
145 uint32_t count, uint64_t *value);
148 uint32_t count, int64_t *value);
154 uint32_t count,
float *value);
157 uint32_t count,
float *value);
160 uint32_t count,
float *value);
163 uint32_t count,
double *value);
166 uint32_t count, uint32_t *value);
172 uint32_t count, uint64_t *value);
175 uint32_t count, uint64_t *value);
185 uint32_t count,
char *value);
193 uint16_t tag, uint32_t count,
197 uint16_t tag, uint32_t count,
204 uint16_t tag, uint32_t count,
208 uint16_t tag, uint32_t count,
215 uint16_t tag, uint32_t count,
219 uint16_t tag, uint32_t count,
223 uint16_t tag, uint32_t count,
227 uint16_t tag, uint32_t count,
258 uint32_t count,
double *value);
267 uint16_t tag, uint32_t count,
271 uint16_t tag, uint32_t count,
279 uint16_t tag, uint32_t count,
284 uint16_t datatype, uint32_t count,
285 uint32_t datalength,
void *data);
327 static const char module[] = "TIFFDeferStrileArrayWriting";
335 TIFFErrorExtR(tif, module,
"Directory has already been written");
402 static const char module[] = "TIFFRewriteDirectory";
431 "tif->tif_diroff exceeds 32 bit range allowed for "
443 uint32_t nextnextdir;
451 if (!
SeekOK(tif, nextdir) || !
ReadOK(tif, &dircount, 2))
454 "Error fetching directory count");
459 (void)
TIFFSeekFile(tif, nextdir + 2 + dircount * 12U, SEEK_SET);
460 if (!
ReadOK(tif, &nextnextdir, 4))
476 "Error writing directory link");
484 nextdir = nextnextdir;
513 uint64_t nextnextdir;
521 if (!
SeekOK(tif, nextdir) || !
ReadOK(tif, &dircount64, 8))
524 "Error fetching directory count");
529 if (dircount64 > 0xFFFF)
532 "Sanity check on tag count failed, likely "
538 if (!
ReadOK(tif, &nextnextdir, 8))
554 "Error writing directory link");
562 nextdir = nextnextdir;
623 static const char module[] = "TIFFWriteDirectorySec";
647 "Error post-encoding before directory write");
664 "Error flushing data before directory write");
685 "Creating TIFF with legacy Deflate codec identifier, "
686 "COMPRESSION_ADOBE_DEFLATE is more widely supported");
852 "StripByteCount array is not set, pointer is NULL");
879 "StripByteOffset array is not set, pointer is NULL");
1047 pa = (uint32_t)(strlen(pb) + 1);
1049 tif, &ndir, dir, (uint16_t)o->
field_tag,
1063 tif, &ndir, dir, (uint16_t)o->
field_tag,
1077 tif, &ndir, dir, (uint16_t)o->
field_tag,
1092 tif, &ndir, dir, (uint16_t)o->
field_tag,
1148 "Cannot write tag %" PRIu32
" (%s)",
1168 tif, &ndir, dir, tag, count,
1174 tif, &ndir, dir, tag, count,
1180 tif, &ndir, dir, tag, count,
1186 tif, &ndir, dir, tag, count,
1192 tif, &ndir, dir, tag, count,
1198 tif, &ndir, dir, tag, count,
1204 tif, &ndir, dir, tag, count,
1210 tif, &ndir, dir, tag, count,
1216 tif, &ndir, dir, tag, count,
1222 tif, &ndir, dir, tag, count,
1237 tif, &ndir, dir, tag, count,
1246 tif, &ndir, dir, tag, count,
1254 tif,
"TIFFLib: _TIFFWriteDirectorySec()",
1255 "Rational2Double: .set_get_field_type is "
1273 tif, &ndir, dir, tag, count,
1282 tif, &ndir, dir, tag, count,
1290 tif,
"TIFFLib: _TIFFWriteDirectorySec()",
1291 "Rational2Double: .set_get_field_type is "
1300 tif, &ndir, dir, tag, count,
1306 tif, &ndir, dir, tag, count,
1312 tif, &ndir, dir, tag, count,
1318 tif, &ndir, dir, tag, count,
1325 "Cannot write custom field with tag %" PRIu32
1326 ": unhandled field type %u",
1393 if (end_offset == (
toff_t)-1)
1396 "Error seeking to end of file before "
1397 "writing custom directory");
1404 if (pdiroff != NULL)
1407 dirsize = 2 + ndir * 12 + 4;
1409 dirsize = 8 + ndir * 20 + 8;
1420 TIFFErrorExtR(tif, module,
"Maximum TIFF file size exceeded");
1435 for (na = 0, nb = dir;; na++, nb++)
1464 n = (uint8_t *)dirmem;
1465 *(uint16_t *)n = (uint16_t)ndir;
1470 for (m = 0; m < ndir; m++)
1500 n = (uint8_t *)dirmem;
1501 *(uint64_t *)n = ndir;
1506 for (m = 0; m < ndir; m++)
1533 "IO error writing directory at seek to offset");
1566 "tif_curdircount is TIFF_NON_EXISTENT_DIR_NUMBER, "
1567 "not expected !! Line %d",
1600 "Starting directory %u at offset 0x%" PRIx64
" (%" PRIu64
1601 ") might cause an IFD loop",
1643 if (val < -128 || isnan(val))
1663 if (val < -32768 || isnan(val))
1665 return (int16_t)val;
1681 if (val > 0x7FFFFFFF)
1683 if (val < -0x7FFFFFFF - 1 || isnan(val))
1684 return -0x7FFFFFFF - 1;
1685 return (int32_t)val;
1703 if (val > 255 || isnan(val))
1705 return (uint8_t)val;
1723 if (val > 65535 || isnan(val))
1725 return (uint16_t)val;
1743 if (val > 0xFFFFFFFFU || isnan(val))
1745 return (uint32_t)val;
1779 uint16_t tag, uint32_t count,
1782 static const char module[] = "TIFFWriteDirectoryTagSampleformatArray";
1798 for (i = 0; i < count; ++i)
1812 for (i = 0; i < count; ++i)
1819 for (i = 0; i < count; ++i)
1822 count, (int16_t *)conv);
1826 for (i = 0; i < count; ++i)
1835 for (i = 0; i < count; ++i)
1842 for (i = 0; i < count; ++i)
1849 for (i = 0; i < count; ++i)
1887 uint32_t count,
char *value)
1917 uint32_t count, uint8_t *value)
1947 uint32_t count, uint8_t *value)
1977 uint32_t count, int8_t *value)
2034 uint32_t count, uint16_t *value)
2067 static const char module[] = "TIFFWriteDirectoryTagShortPerSample";
2079 sizeof(uint16_t), module);
2120 uint32_t count, int16_t *value)
2177 uint32_t count, uint32_t *value)
2210 uint32_t count, int32_t *value)
2250 uint32_t count, uint64_t *value)
2252 static const char module[] = "TIFFWriteDirectoryTagLong8Array";
2275 for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
2277 if (*ma > 0xFFFFFFFF)
2280 "Attempt to write unsigned long value %" PRIu64
2281 " larger than 0xFFFFFFFF for tag %d in Classic TIFF "
2282 "file. TIFF file writing aborted",
2287 *q = (uint32_t)(*ma);
2330 uint32_t count, int64_t *value)
2332 static const char module[] = "TIFFWriteDirectoryTagSlong8Array";
2355 for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
2357 if (*ma > (2147483647))
2360 "Attempt to write signed long value %" PRIi64
2361 " larger than 0x7FFFFFFF (2147483647) for tag %d in "
2362 "Classic TIFF file. TIFF writing to file aborted",
2367 else if (*ma < (-2147483647 - 1))
2370 "Attempt to write signed long value %" PRIi64
2371 " smaller than 0x80000000 (-2147483648) for tag %d "
2372 "in Classic TIFF file. TIFF writing to file aborted",
2377 *q = (int32_t)(*ma);
2442 uint32_t count,
float *value)
2476 uint32_t count,
float *value)
2552 tif, ndir, dir, tag, count, value));
2583 uint32_t count,
float *value)
2617 uint32_t count,
double *value)
2650 uint32_t count, uint32_t *value)
2677 if (value <= 0xFFFF)
2701 uint64_t uncompressed_threshold)
2706 return strile_size > uncompressed_threshold;
2720 return strile_size >= uncompressed_threshold / 10;
2807 uint32_t count, uint64_t *value)
2809 static const char module[] = "TIFFWriteDirectoryTagLongLong8Array";
2829 int write_aslong8 = 1;
2877 for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
2879 if (*ma > 0xFFFFFFFF)
2882 "Attempt to write value larger than 0xFFFFFFFF "
2887 *q = (uint32_t)(*ma);
2908 for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
2914 "Attempt to write value larger than 0xFFFF in "
2919 *q = (uint16_t)(*ma);
2965 uint32_t count, uint64_t *value)
2967 static const char module[] = "TIFFWriteDirectoryTagIfdIfd8Array";
2991 for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
2993 if (*ma > 0xFFFFFFFF)
2996 "Attempt to write value larger than 0xFFFFFFFF in "
2997 "Classic TIFF file.");
3001 *q = (uint32_t)(*ma);
3031 uint32_t typesize, uint32_t *ndir)
3033 uint64_t datalength = (uint64_t)count * typesize;
3074 static const char module[] = "TIFFWriteDirectoryTagColormap";
3086 "No ColorMap entries stored. Tag not written to file");
3096 if (count == 0 || total_values == 0 || plane_bytes == 0)
3149 static const char module[] = "TIFFWriteDirectoryTagTransferfunction";
3167 "No TransferFunction entries stored. Tag not written to file");
3172 if (plane_bytes == 0)
3179 for (
int i = 0; i < n; i++)
3184 "Too few TransferFunctions provided. Tag "
3185 "not written to file");
3208 if (count == 0 || total_values == 0)
3266 static const char module[] = "TIFFWriteDirectoryTagSubifd";
3279 sizeof(uint32_t), module);
3293 if (*pa > 0xFFFFFFFFUL)
3299 *pb++ = (uint32_t)(*pa++);
3358 uint32_t count,
char *value)
3360 assert(
sizeof(
char) == 1);
3398 assert(
sizeof(uint8_t) == 1);
3405 count, count, value));
3432 uint16_t tag, uint32_t count,
3435 assert(
sizeof(uint8_t) == 1);
3469 uint16_t tag, uint32_t count,
3472 assert(
sizeof(int8_t) == 1);
3504 assert(
sizeof(uint16_t) == 2);
3545 uint16_t tag, uint32_t count,
3548 static const char module[] = "TIFFWriteDirectoryTagCheckedShortArray";
3549 if (count > UINT32_MAX / 2)
3552 "Tag %" PRIu16
": count %" PRIu32
3553 " exceeds maximum of %" PRIu32
" entries",
3554 tag, count, UINT32_MAX / 2);
3594 uint16_t tag, uint32_t count,
3597 static const char module[] = "TIFFWriteDirectoryTagCheckedSshortArray";
3598 if (count > UINT32_MAX / 2)
3601 "Tag %" PRIu16
": count %" PRIu32
3602 " exceeds maximum of %" PRIu32
" entries",
3603 tag, count, UINT32_MAX / 2);
3639 assert(
sizeof(uint32_t) == 4);
3679 uint16_t tag, uint32_t count,
3682 if (count > UINT32_MAX / 4)
3721 uint16_t tag, uint32_t count,
3724 if (count > UINT32_MAX / 4)
3766 uint16_t tag, uint32_t count,
3771 TIFFErrorExtR(tif,
"TIFFWriteDirectoryTagCheckedLong8Array",
3772 "LONG8 not allowed for ClassicTIFF");
3775 if (count > UINT32_MAX / 8)
3817 uint16_t tag, uint32_t count,
3822 TIFFErrorExtR(tif,
"TIFFWriteDirectoryTagCheckedSlong8Array",
3823 "SLONG8 not allowed for ClassicTIFF");
3826 if (count > UINT32_MAX / 8)
3863 static const char module[] = "TIFFWriteDirectoryTagCheckedRational";
3865 assert(
sizeof(uint32_t) == 4);
3871 else if (isnan(value))
3873 TIFFErrorExtR(tif, module,
"Not-a-number value is illegal");
3928 static const char module[] = "TIFFWriteDirectoryTagCheckedRationalArray";
3934 if (count > UINT32_MAX / 8)
3937 "Tag %" PRIu16
": count %" PRIu32
3938 " exceeds maximum of %" PRIu32
" entries",
3939 tag, count, UINT32_MAX / 8);
3948 "for rational array");
3954 for (na = value, nb = m, nc = 0; nc < count; na++, nb += 2, nc++)
3998 static const char module[] = "TIFFWriteDirectoryTagCheckedSrationalArray";
4004 if (count > UINT32_MAX / 8)
4007 "Tag %" PRIu16
": count %" PRIu32
4008 " exceeds maximum of %" PRIu32
" entries",
4009 tag, count, UINT32_MAX / 8);
4018 "for srational array");
4024 for (na = value, nb = m, nc = 0; nc < count; na++, nb += 2, nc++)
4066 uint32_t count,
double *value)
4068 static const char module[] =
4069 "TIFFWriteDirectoryTagCheckedRationalDoubleArray";
4075 if (count > UINT32_MAX / 8)
4078 "Tag %" PRIu16
": count %" PRIu32
4079 " exceeds maximum of %" PRIu32
" entries",
4080 tag, count, UINT32_MAX / 8);
4089 "for rational double array");
4095 for (na = value, nb = m, nc = 0; nc < count; na++, nb += 2, nc++)
4134 TIFF *tif, uint32_t *ndir,
TIFFDirEntry *dir, uint16_t tag, uint32_t count,
4137 static const char module[] =
4138 "TIFFWriteDirectoryTagCheckedSrationalDoubleArray";
4144 if (count > UINT32_MAX / 8)
4147 "Tag %" PRIu16
": count %" PRIu32
4148 " exceeds maximum of %" PRIu32
" entries",
4149 tag, count, UINT32_MAX / 8);
4158 "for srational double array");
4164 for (na = value, nb = m, nc = 0; nc < count; na++, nb += 2, nc++)
4228 int blnUseSmallRange, uint64_t *ullNum,
4234 uint64_t numSum[3] = {0, 1, 0}, denomSum[3] = {1, 0, 0};
4235 uint64_t aux, bigNum, bigDenom;
4236 uint64_t returnLimit;
4240 unsigned long maxDenom;
4249 if (blnUseSmallRange)
4251 nMax = (uint64_t)((2147483647 - 1) / 2);
4255 nMax = ((9223372036854775807 - 1) / 2);
4257 fMax = (double)nMax;
4265 if (blnUseSignedRange)
4267 maxDenom = 2147483647UL;
4268 returnLimit = maxDenom;
4272 maxDenom = 0xFFFFFFFFUL;
4273 returnLimit = maxDenom;
4287 while ((!
TIFF_DOUBLE_EQ(value, floor(value))) && (value < fMax) &&
4293 bigNum = (uint64_t)value;
4297#define MAX_ITERATIONS 64
4306 val = bigNum / bigDenom;
4312 bigDenom = aux % bigDenom;
4316 if (denomSum[1] * val + denomSum[0] >= maxDenom)
4318 aux = (maxDenom - denomSum[0]) / denomSum[1];
4319 if (aux * 2 >= val || denomSum[1] >= maxDenom)
4327 numSum[2] = aux * numSum[1] + numSum[0];
4328 numSum[0] = numSum[1];
4329 numSum[1] = numSum[2];
4332 denomSum[2] = aux * denomSum[1] + denomSum[0];
4333 denomSum[0] = denomSum[1];
4334 denomSum[1] = denomSum[2];
4339 while (numSum[1] > returnLimit || denomSum[1] > returnLimit)
4341 numSum[1] = numSum[1] / 2;
4342 denomSum[1] = denomSum[1] / 2;
4346 *ullNum = numSum[1];
4347 *ullDenom = denomSum[1];
4377 double dblDiff, dblDiff2;
4378 uint64_t ullNum, ullDenom, ullNum2, ullDenom2;
4386 " Negative Value for Unsigned Rational given.");
4391 if (value > 0xFFFFFFFFUL)
4400 *num = (uint32_t)value;
4405 if (value < 1.0 / (
double)0xFFFFFFFFUL)
4408 *denom = 0xFFFFFFFFU;
4419 if (ullNum > 0xFFFFFFFFUL || ullDenom > 0xFFFFFFFFUL ||
4420 ullNum2 > 0xFFFFFFFFUL || ullDenom2 > 0xFFFFFFFFUL)
4423 " Num or Denom exceeds ULONG: val=%14.6f, num=%12" PRIu64
4424 ", denom=%12" PRIu64
" | num2=%12" PRIu64
4425 ", denom2=%12" PRIu64
"",
4426 value, ullNum, ullDenom, ullNum2, ullDenom2);
4433 dblDiff = fabs(value - ((
double)ullNum / (
double)ullDenom));
4434 dblDiff2 = fabs(value - ((
double)ullNum2 / (
double)ullDenom2));
4435 if (dblDiff < dblDiff2)
4437 *num = (uint32_t)ullNum;
4438 *denom = (uint32_t)ullDenom;
4442 *num = (uint32_t)ullNum2;
4443 *denom = (uint32_t)ullDenom2;
4476 double dblDiff, dblDiff2;
4477 uint64_t ullNum, ullDenom, ullNum2, ullDenom2;
4488 if (value > 0x7FFFFFFFL)
4497 *num = (int32_t)(neg * value);
4502 if (value < 1.0 / (
double)0x7FFFFFFFL)
4505 *denom = 0x7FFFFFFFL;
4517 if (ullNum > 0x7FFFFFFFL || ullDenom > 0x7FFFFFFFL ||
4518 ullNum2 > 0x7FFFFFFFL || ullDenom2 > 0x7FFFFFFFL)
4521 " Num or Denom exceeds LONG: val=%14.6f, num=%12" PRIu64
4522 ", denom=%12" PRIu64
" | num2=%12" PRIu64
4523 ", denom2=%12" PRIu64
"",
4524 neg * value, ullNum, ullDenom, ullNum2, ullDenom2);
4525 *num = (int32_t)(neg * 0x7FFFFFFFL);
4531 dblDiff = fabs(value - ((
double)ullNum / (
double)ullDenom));
4532 dblDiff2 = fabs(value - ((
double)ullNum2 / (
double)ullDenom2));
4533 if (dblDiff < dblDiff2)
4535 *num = (int32_t)(neg * (
long)ullNum);
4536 *denom = (int32_t)ullDenom;
4540 *num = (int32_t)(neg * (
long)ullNum2);
4541 *denom = (int32_t)ullDenom2;
4572 uint16_t tag, uint32_t count,
4575 assert(
sizeof(
float) == 4);
4576 if (count > UINT32_MAX / 4)
4617 uint16_t tag, uint32_t count,
4620 assert(
sizeof(
double) == 8);
4621 if (count > UINT32_MAX / 8)
4661 uint32_t count, uint32_t *value)
4663 if (count > UINT32_MAX / 4)
4703 uint16_t tag, uint32_t count,
4707 if (count > UINT32_MAX / 8)
4752 uint16_t datatype, uint32_t count,
4753 uint32_t datalength,
void *data)
4755 static const char module[] = "TIFFWriteDirectoryTagData";
4760 assert(dir[m].tdir_tag != tag);
4761 if (dir[m].tdir_tag > tag)
4768 for (n = *ndir; n > m; n--)
4769 dir[n] = dir[n - 1];
4777 if (data && datalength)
4779 _TIFFmemcpy(&dir[m].tdir_offset, data, datalength);
4786 nb = na + datalength;
4789 if ((nb < na) || (nb < datalength))
4791 TIFFErrorExtR(tif, module,
"Maximum TIFF file size exceeded");
4799 if (datalength >= 0x80000000UL)
4802 "libtiff does not allow writing more than 2147483647 "
4859 static const char module[] = "TIFFLinkDirectory";
4862 if (end_offset == (
toff_t)-1)
4865 "Error seeking to end of file before linking directory");
4885 "Error writing SubIFD directory link");
4909 "Error writing SubIFD directory link");
4974 uint32_t nextnextdir;
4984 if (!
SeekOK(tif, nextdir) || !
ReadOK(tif, &dircount, 2))
4986 TIFFErrorExtR(tif, module,
"Error fetching directory count");
4991 (void)
TIFFSeekFile(tif, nextdir + 2 + dircount * 12U, SEEK_SET);
4992 if (!
ReadOK(tif, &nextnextdir, 4))
4994 TIFFErrorExtR(tif, module,
"Error fetching directory link");
4999 if (nextnextdir == 0)
5001 (void)
TIFFSeekFile(tif, nextdir + 2 + dircount * 12U, SEEK_SET);
5010 nextdir = nextnextdir;
5058 uint64_t dircount64;
5059 uint64_t nextnextdir;
5068 if (!
SeekOK(tif, nextdir) || !
ReadOK(tif, &dircount64, 8))
5070 TIFFErrorExtR(tif, module,
"Error fetching directory count");
5075 if (dircount64 > 0xFFFF)
5078 "Sanity check on tag count failed, "
5079 "likely corrupt TIFF");
5082 (void)
TIFFSeekFile(tif, nextdir + 8 + dircount64 * 20, SEEK_SET);
5083 if (!
ReadOK(tif, &nextnextdir, 8))
5085 TIFFErrorExtR(tif, module,
"Error fetching directory link");
5090 if (nextnextdir == 0)
5102 nextdir = nextnextdir;
5136 static const char module[] = "TIFFResetField";
5140 uint8_t direntry_raw[20];
5141 uint16_t entry_tag = 0;
5142 uint16_t entry_type = 0;
5143 uint64_t entry_count = 0;
5144 uint64_t entry_offset = 0;
5145 int value_in_entry = 0;
5146 uint64_t read_offset;
5147 uint8_t *buf_to_write = NULL;
5161 "Memory mapped files not currently supported for "
5170 "Attempt to reset field on directory not already on disk.");
5179 TIFFErrorExtR(tif, module,
"%s: Seek error accessing TIFF directory",
5188 if (!
ReadOK(tif, &dircount,
sizeof(uint16_t)))
5190 TIFFErrorExtR(tif, module,
"%s: Can not read TIFF directory count",
5201 uint64_t dircount64;
5202 if (!
ReadOK(tif, &dircount64,
sizeof(uint64_t)))
5204 TIFFErrorExtR(tif, module,
"%s: Can not read TIFF directory count",
5210 dircount = (uint16_t)dircount64;
5218 while (dircount > 0)
5220 if (!
ReadOK(tif, direntry_raw, dirsize))
5222 TIFFErrorExtR(tif, module,
"%s: Can not read TIFF directory entry.",
5227 memcpy(&entry_tag, direntry_raw + 0,
sizeof(uint16_t));
5231 if (entry_tag == tag)
5234 read_offset += (uint64_t)dirsize;
5237 if (entry_tag != tag)
5239 TIFFErrorExtR(tif, module,
"%s: Could not find tag %" PRIu16
".",
5247 memcpy(&entry_type, direntry_raw + 2,
sizeof(uint16_t));
5255 memcpy(&value, direntry_raw + 4,
sizeof(uint32_t));
5258 entry_count = value;
5260 memcpy(&value, direntry_raw + 8,
sizeof(uint32_t));
5263 entry_offset = value;
5267 memcpy(&entry_count, direntry_raw + 4,
sizeof(uint64_t));
5271 memcpy(&entry_offset, direntry_raw + 12,
sizeof(uint64_t));
5279 if (entry_offset == 0 && entry_count == 0 && entry_type == 0)
5288 int write_aslong8 = 1;
5303 int write_aslong4 = 1;
5336 datatype = in_datatype;
5351 datatype = in_datatype;
5363 if (datatype == in_datatype)
5364 memcpy(buf_to_write, data,
5370 for (i = 0; i < count; i++)
5372 ((int32_t *)buf_to_write)[i] = (int32_t)((int64_t *)data)[i];
5373 if ((int64_t)((int32_t *)buf_to_write)[i] != ((int64_t *)data)[i])
5377 "Value exceeds 32bit range of output type.");
5387 for (i = 0; i < count; i++)
5389 ((uint32_t *)buf_to_write)[i] = (uint32_t)((uint64_t *)data)[i];
5390 if ((uint64_t)((uint32_t *)buf_to_write)[i] !=
5391 ((uint64_t *)data)[i])
5395 "Value exceeds 32bit range of output type.");
5404 for (i = 0; i < count; i++)
5406 ((uint16_t *)buf_to_write)[i] = (uint16_t)((uint64_t *)data)[i];
5407 if ((uint64_t)((uint16_t *)buf_to_write)[i] !=
5408 ((uint64_t *)data)[i])
5412 "Value exceeds 16bit range of output type.");
5440 entry_offset = read_offset + 8;
5448 entry_offset = read_offset + 12;
5476 if (entry_count == (uint64_t)count && entry_type == (uint16_t)datatype)
5478 if (!
SeekOK(tif, entry_offset))
5482 "%s: Seek error accessing TIFF directory",
5500 if (!value_in_entry)
5516 memcpy(&value, buf_to_write,
5518 entry_offset = value;
5522 memcpy(&entry_offset, buf_to_write,
5533 entry_type = (uint16_t)datatype;
5534 entry_count = (uint64_t)count;
5535 memcpy(direntry_raw + 2, &entry_type,
sizeof(uint16_t));
5543 value = (uint32_t)entry_count;
5544 memcpy(direntry_raw + 4, &value,
sizeof(uint32_t));
5548 value = (uint32_t)entry_offset;
5549 memcpy(direntry_raw + 8, &value,
sizeof(uint32_t));
5555 memcpy(direntry_raw + 4, &entry_count,
sizeof(uint64_t));
5559 memcpy(direntry_raw + 12, &entry_offset,
sizeof(uint64_t));
5567 if (!
SeekOK(tif, read_offset))
5569 TIFFErrorExtR(tif, module,
"%s: Seek error accessing TIFF directory",
5574 if (!
WriteOK(tif, direntry_raw, dirsize))
5576 TIFFErrorExtR(tif, module,
"%s: Can not write TIFF directory entry.",
uint32_t _TIFFCastUInt64ToUInt32(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
float _TIFFClampDoubleToFloat(double val)
Clamp a double to the finite float range before conversion.
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Multiply two unsigned values with an overflow check.
int _TIFFRemoveEntryFromDirectoryListByOffset(TIFF *tif, uint64_t diroff)
Attempt to remove a shared directory-map entry by offset.
int _TIFFCheckDirNumberAndOffset(TIFF *tif, tdir_t dirn, uint64_t diroff)
Register or validate a chain index/offset pair for loop detection.
int _TIFFGetDirNumberFromOffset(TIFF *tif, uint64_t diroff, tdir_t *dirn)
Resolve a directory offset using the chain maps.
#define FIELD_RESOLUTION
Index the resolution presence bit; not an on-disk tag number.
#define FIELD_CODEC
Start the range reserved for codec-private presence bits.
#define FIELD_SUBFILETYPE
Index the subfile type presence bit; not an on-disk tag number.
#define FIELD_STRIPOFFSETS
Index the strile offsets presence bit; not an on-disk tag number.
#define FIELD_TRANSFERFUNCTION
Index the transfer function presence bit; not an on-disk tag number.
#define FIELD_HALFTONEHINTS
Index the halftone hints presence bit; not an on-disk tag number.
#define FIELD_ORIENTATION
Index the orientation presence bit; not an on-disk tag number.
#define FIELD_MINSAMPLEVALUE
Index the minimum sample value presence bit; not an on-disk tag number.
#define FIELD_FILLORDER
Index the fill order 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_IMAGEDIMENSIONS
Index the image dimensions 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.
#define FIELD_SUBIFD
Index the child IFD presence bit; not an on-disk tag number.
#define FIELD_EXTRASAMPLES
Index the extra samples presence bit; not an on-disk tag number.
#define FIELD_IMAGEDEPTH
Index the image depth presence bit; not an on-disk tag number.
#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.
#define FIELD_MAXSAMPLEVALUE
Index the maximum sample value presence bit; not an on-disk tag number.
#define FIELD_NUMBEROFINKS
Index the number of inks presence bit; not an on-disk tag number.
#define FIELD_TILEDEPTH
Index the tile depth presence bit; not an on-disk tag number.
#define FIELD_TILEDIMENSIONS
Index the tile dimensions presence bit; not an on-disk tag number.
#define FIELD_POSITION
Index the position presence bit; not an on-disk tag number.
#define FIELD_ROWSPERSTRIP
Index the rows per strip presence bit; not an on-disk tag number.
#define FIELD_COMPRESSION
Index the compression presence bit; not an on-disk tag number.
#define FIELD_STRIPBYTECOUNTS
Index the strile byte counts presence bit; not an on-disk tag number.
#define FIELD_YCBCRPOSITIONING
Index the YCbCr positioning presence bit; not an on-disk tag number.
#define FIELD_REFBLACKWHITE
Index the reference black/white presence bit; not an on-disk tag number.
#define FIELD_SAMPLEFORMAT
Index the sample format presence bit; not an on-disk tag number.
#define FIELD_PAGENUMBER
Index the page number presence bit; not an on-disk tag number.
#define FIELD_BITSPERSAMPLE
Index the bits per sample presence bit; not an on-disk tag number.
#define FIELD_INKNAMES
Index the ink names presence bit; not an on-disk tag number.
#define FIELD_RESOLUTIONUNIT
Index the resolution unit presence bit; not an on-disk tag number.
#define FIELD_PLANARCONFIG
Index the planar configuration presence bit; not an on-disk tag number.
#define FIELD_SAMPLESPERPIXEL
Index the samples per pixel presence bit; not an on-disk tag number.
#define FIELD_PHOTOMETRIC
Index the photometric presence bit; not an on-disk tag number.
#define FIELD_THRESHHOLDING
Index the thresholding presence bit; not an on-disk tag number.
@ TIFF_SETGET_C16_UINT8
Unsigned 8-bit array with 16-bit explicit count.
@ TIFF_SETGET_C0_SINT64
Signed 64-bit array with implicit count.
@ TIFF_SETGET_DOUBLE
Double scalar storage.
@ TIFF_SETGET_SINT64
Signed 64-bit scalar storage.
@ TIFF_SETGET_C32_SINT32
Signed 32-bit array with 32-bit explicit count.
@ TIFF_SETGET_C16_FLOAT
Float array with 16-bit explicit count.
@ TIFF_SETGET_UNDEFINED
Unsupported or unspecified argument representation.
@ TIFF_SETGET_SINT8
Signed 8-bit scalar storage.
@ TIFF_SETGET_C32_ASCII
Character array with 32-bit explicit count.
@ TIFF_SETGET_INT
Promoted int scalar representation.
@ TIFF_SETGET_C32_UINT8
Unsigned 8-bit array with 32-bit explicit count.
@ TIFF_SETGET_IFD8
64-bit directory-offset scalar storage.
@ TIFF_SETGET_C32_UINT16
Unsigned 16-bit array with 32-bit explicit count.
@ TIFF_SETGET_C16_DOUBLE
Double array with 16-bit explicit count.
@ TIFF_SETGET_UINT64
Unsigned 64-bit scalar storage.
@ TIFF_SETGET_C0_UINT32
Unsigned 32-bit array with implicit count.
@ TIFF_SETGET_C16_UINT32
Unsigned 32-bit array with 16-bit explicit count.
@ TIFF_SETGET_UINT16_PAIR
Two separate promoted uint16_t values / uint16_t output slots.
@ TIFF_SETGET_C32_SINT16
Signed 16-bit array with 32-bit explicit count.
@ TIFF_SETGET_C16_UINT16
Unsigned 16-bit array with 16-bit explicit count.
@ TIFF_SETGET_C16_SINT64
Signed 64-bit array with 16-bit explicit count.
@ TIFF_SETGET_C0_FLOAT
Float array with implicit count.
@ TIFF_SETGET_C0_SINT32
Signed 32-bit array with implicit count.
@ TIFF_SETGET_C16_UINT64
Unsigned 64-bit array with 16-bit explicit count.
@ TIFF_SETGET_C32_UINT32
Unsigned 32-bit array with 32-bit explicit count.
@ TIFF_SETGET_C0_ASCII
Character array with implicit count.
@ TIFF_SETGET_C32_SINT8
Signed 8-bit array with 32-bit explicit count.
@ TIFF_SETGET_UINT16
Unsigned 16-bit scalar storage.
@ TIFF_SETGET_C16_SINT16
Signed 16-bit array with 16-bit explicit count.
@ TIFF_SETGET_C0_UINT8
Unsigned 8-bit array with implicit count.
@ TIFF_SETGET_ASCII
Null-terminated string representation.
@ TIFF_SETGET_C0_SINT8
Signed 8-bit array with implicit count.
@ TIFF_SETGET_C16_SINT8
Signed 8-bit array with 16-bit explicit count.
@ TIFF_SETGET_OTHER
Tag-specific calling convention outside the regular encodings.
@ TIFF_SETGET_C0_UINT64
Unsigned 64-bit array with implicit count.
@ TIFF_SETGET_FLOAT
Float scalar storage.
@ TIFF_SETGET_C16_SINT32
Signed 32-bit array with 16-bit explicit count.
@ TIFF_SETGET_SINT16
Signed 16-bit scalar storage.
@ TIFF_SETGET_C0_SINT16
Signed 16-bit array with implicit count.
@ TIFF_SETGET_C32_IFD8
64-bit directory-offset array with 32-bit explicit count.
@ TIFF_SETGET_UINT32
Unsigned 32-bit scalar storage.
@ TIFF_SETGET_C32_SINT64
Signed 64-bit array with 32-bit explicit count.
@ TIFF_SETGET_C16_ASCII
Character array with 16-bit explicit count.
@ TIFF_SETGET_C32_DOUBLE
Double array with 32-bit explicit count.
@ TIFF_SETGET_UINT8
Unsigned 8-bit scalar storage.
@ TIFF_SETGET_C0_UINT16
Unsigned 16-bit array with implicit count.
@ TIFF_SETGET_C32_UINT64
Unsigned 64-bit array with 32-bit explicit count.
@ TIFF_SETGET_C0_IFD8
64-bit directory-offset array with implicit count.
@ TIFF_SETGET_C16_IFD8
64-bit directory-offset array with 16-bit explicit count.
@ TIFF_SETGET_SINT32
Signed 32-bit scalar storage.
@ TIFF_SETGET_C32_FLOAT
Float array with 32-bit explicit count.
@ TIFF_SETGET_C0_DOUBLE
Double array with implicit count.
static int TIFFWriteDirectoryTagShortLong(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t value)
Account for or emit ShortLong tag data.
static int TIFFWriteDirectoryTagCheckedSlongArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int32_t *value)
Account for or emit Slong array tag data.
#define MAX_ITERATIONS
Bound the rational approximation loop to 64 iterations.
static int TIFFWriteDirectoryTagSlongArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int32_t *value)
Account for or emit Slong array tag data.
static int TIFFWriteDirectoryTagLong(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t value)
Account for or emit Long tag data.
static uint16_t TIFFClampDoubleToUInt16(double val)
Clamp and convert a double to uint16.
static int TIFFWriteDirectoryTagSbyteArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int8_t *value)
Account for or emit Sbyte array tag data.
static int TIFFWriteDirectoryTagRationalDoubleArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit RationalDouble array tag data.
static int TIFFWriteDirectoryTagAscii(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, char *value)
Account for or emit Ascii tag data.
static int _WriteAsType(TIFF *tif, uint64_t strile_size, uint64_t uncompressed_threshold)
Choose whether a strile count needs a wider integer type.
static int TIFFWriteDirectoryTagIfdArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint32_t *value)
Account for or emit Ifd array tag data.
static int TIFFWriteDirectoryTagCheckedDoubleArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit Double array tag data.
static int TIFFWriteDirectoryTagCheckedLong(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t value)
Account for or emit Long tag data.
static int TIFFRewriteDirectorySec(TIFF *tif, int isimage, int imagedone, uint64_t *pdiroff)
Detach and relocate an IFD using the requested writer mode.
static int TIFFWriteDirectoryTagCheckedRationalArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, float *value)
Account for or emit Rational array tag data.
static void EvaluateIFDdatasizeWrite(TIFF *tif, uint32_t count, uint32_t typesize, uint32_t *ndir)
Accumulate external payload size and one IFD entry.
static void DoubleToSrational(double value, int32_t *num, int32_t *denom)
Convert a non-NaN double into signed rational components.
#define TIFFCvtNativeToIEEEDouble(tif, n, dp)
Recognise already compatible double storage without conversion.
static int TIFFWriteDirectoryTagCheckedAscii(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, char *value)
Account for or emit Ascii tag data.
static int TIFFLinkDirectory(TIFF *)
Link a new IFD at an even end-of-file offset.
static int TIFFWriteDirectoryTagSrationalDoubleArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit SrationalDouble array tag data.
static int TIFFWriteDirectoryTagCheckedSbyteArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int8_t *value)
Account for or emit Sbyte array tag data.
static int TIFFWriteDirectoryTagCheckedUndefinedArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint8_t *value)
Account for or emit Undefined array tag data.
static int TIFFWriteDirectoryTagCheckedShort(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint16_t value)
Account for or emit Short tag data.
static int TIFFWriteDirectoryTagDoubleArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit Double array tag data.
static int TIFFWriteDirectoryTagLongArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint32_t *value)
Account for or emit Long array tag data.
static int TIFFWriteDirectoryTagSlong8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int64_t *value)
Account for or emit Slong8 array tag data.
static int TIFFWriteDirectoryTagCheckedByteArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint8_t *value)
Account for or emit Byte array tag data.
static int TIFFWriteDirectoryTagColormap(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir)
Account for or emit Colormap tag data.
static int TIFFWriteDirectoryTagTransferfunction(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir)
Account for or emit Transferfunction tag data.
static int TIFFWriteDirectoryTagCheckedIfdArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint32_t *value)
Account for or emit Ifd array tag data.
static int TIFFWriteDirectoryTagSrationalArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, float *value)
Account for or emit Srational array tag data.
static int TIFFWriteDirectoryTagCheckedSlong8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int64_t *value)
Account for or emit Slong8 array tag data.
static int32_t TIFFClampDoubleToInt32(double val)
Clamp and convert a double to int32.
static int TIFFWriteDirectoryTagCheckedSrationalArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, float *value)
Account for or emit Srational array tag data.
static int TIFFWriteDirectoryTagByteArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint8_t *value)
Account for or emit Byte array tag data.
static int8_t TIFFClampDoubleToInt8(double val)
Clamp and convert a double to int8.
static int TIFFWriteDirectoryTagCheckedShortArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint16_t *value)
Account for or emit Short array tag data.
static int TIFFWriteDirectoryTagData(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint16_t datatype, uint32_t count, uint32_t datalength, void *data)
Insert one sorted IFD entry and emit its raw payload.
static int WriteAsLong4(TIFF *tif, uint64_t strile_size)
Choose whether a strile count needs a wider integer type.
static int TIFFWriteDirectoryTagCheckedRational(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, double value)
Account for or emit Rational tag data.
static int TIFFWriteDirectoryTagRationalArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, float *value)
Account for or emit Rational array tag data.
static int TIFFWriteDirectoryTagSampleformatArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit Sampleformat array tag data.
static int TIFFWriteDirectoryTagCheckedLong8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint64_t *value)
Account for or emit Long8 array tag data.
static void DoubleToRational(double value, uint32_t *num, uint32_t *denom)
Convert a double into unsigned 32-bit rational components.
int _TIFFRewriteField(TIFF *tif, uint16_t tag, TIFFDataType in_datatype, tmsize_t count, void *data)
Patch an existing field in the current on-file IFD.
static int TIFFWriteDirectoryTagIfdIfd8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint64_t *value)
Account for or emit IfdIfd8 array tag data.
static int TIFFWriteDirectoryTagFloatArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, float *value)
Account for or emit Float array tag data.
static int TIFFWriteDirectoryTagLongLong8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint64_t *value)
Account for or emit LongLong8 array tag data.
static uint32_t TIFFClampDoubleToUInt32(double val)
Clamp and convert a double to uint32.
static int TIFFWriteDirectoryTagSshortArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int16_t *value)
Account for or emit Sshort array tag data.
static void ToRationalEuclideanGCD(double value, int blnUseSignedRange, int blnUseSmallRange, uint64_t *ullNum, uint64_t *ullDenom)
Approximate a nonnegative scalar by bounded rational components.
static int WriteAsLong8(TIFF *tif, uint64_t strile_size)
Choose whether a strile count needs a wider integer type.
static int TIFFWriteDirectorySec(TIFF *tif, int isimage, int imagedone, uint64_t *pdiroff)
Serialise the current IFD using image/custom and completion modes.
static int TIFFWriteDirectoryTagShortArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint16_t *value)
Account for or emit Short array tag data.
static int TIFFWriteDirectoryTagCheckedFloatArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, float *value)
Account for or emit Float array tag data.
static int TIFFWriteDirectoryTagShortPerSample(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint16_t value)
Account for or emit Short per sample tag data.
static int TIFFWriteDirectoryTagCheckedSshortArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, int16_t *value)
Account for or emit Sshort array tag data.
static int TIFFWriteDirectoryTagUndefinedArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint8_t *value)
Account for or emit Undefined array tag data.
static int TIFFWriteDirectoryTagCheckedIfd8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint64_t *value)
Account for or emit Ifd8 array tag data.
static int TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit RationalDouble array tag data.
static int TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, double *value)
Account for or emit SrationalDouble array tag data.
static int TIFFWriteDirectoryTagShort(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint16_t value)
Account for or emit Short tag data.
static int TIFFWriteDirectoryTagLong8Array(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint64_t *value)
Account for or emit Long8 array tag data.
static int TIFFWriteDirectoryTagCheckedLongArray(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, uint32_t count, uint32_t *value)
Account for or emit Long array tag data.
static int16_t TIFFClampDoubleToInt16(double val)
Clamp and convert a double to int16.
static int TIFFWriteDirectoryTagRational(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir, uint16_t tag, double value)
Account for or emit Rational tag data.
static int TIFFWriteDirectoryTagSubifd(TIFF *tif, uint32_t *ndir, TIFFDirEntry *dir)
Account for or emit Subifd tag data.
#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
Recognise already compatible float storage without conversion.
static uint8_t TIFFClampDoubleToUInt8(double val)
Clamp and convert a double to uint8.
int TIFFFlushData1(TIFF *tif)
Append buffered encoded bytes without invoking postencode recursively.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Allocate a checked array with an allocation-failure diagnostic.
#define TIFF_NON_EXISTENT_DIR_NUMBER
Mark an unknown or nonexistent directory index.
#define TIFF_DOUBLE_EQ(x, y)
Test whether a double difference is not greater than zero in magnitude.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#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 SeekOK(tif, off)
Test whether an absolute seek reaches the requested file position.
#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_BIGTIFF
Mark the BigTIFF file format.
#define TIFF_SWAB
Request swapping multibyte file values to or from host order.
void TIFFSwabArrayOfLong8(uint64_t *lp, tmsize_t n)
Reverse the byte order of each array element.
void TIFFSwabArrayOfDouble(double *dp, tmsize_t n)
Reverse the byte order of each array element.
void TIFFSwabArrayOfShort(uint16_t *wp, tmsize_t n)
Reverse the byte order of each array element.
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 TIFFSwabArrayOfLong(uint32_t *lp, tmsize_t n)
Reverse the byte order of each array element.
void TIFFSwabLong(uint32_t *lp)
Reverse the byte order of one value.
void TIFFSwabArrayOfFloat(float *fp, tmsize_t n)
Reverse the byte order of each array element.
#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 TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
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.
void TIFFFreeDirectory(TIFF *tif)
Release the current directory's owned values and codec state.
int TIFFCreateDirectory(TIFF *tif)
Replace current values with a fresh in-memory image directory.
int TIFFDataWidth(TIFFDataType type)
Report the on-disk byte width of a TIFF data type.
uint32_t TIFFFieldTag(const TIFFField *fip)
Read a field descriptor's tag number.
const TIFFField * TIFFFindField(TIFF *tif, uint32_t tag, TIFFDataType dt)
Find a registered field by tag number and file data type.
int TIFFFieldSetGetSize(const TIFFField *fip)
Report the internal element storage width of a field.
int TIFFCheckpointDirectory(TIFF *tif)
Write the current image directory while retaining its values.
int TIFFRewriteDirectory(TIFF *tif)
Relocate the current image IFD and repair its main-chain link.
int TIFFDeferStrileArrayWriting(TIFF *tif)
Reserve strile-array entries for deferred payload writing.
int TIFFWriteDirectory(TIFF *tif)
Finish the current image directory and prepare a fresh one.
int TIFFWriteCustomDirectory(TIFF *tif, uint64_t *pdiroff)
Write current custom values and return their IFD offset.
int TIFFSetupStrips(TIFF *tif)
Replace strile offset/count arrays from current geometry.
uint64_t TIFFTileSize64(TIFF *tif)
Compute the decoded-size estimate for the configured tile height.
uint64_t TIFFStripSize64(TIFF *tif)
Compute the decoded-size estimate for a nominal strip.
void TIFFSetWriteOffset(TIFF *tif, toff_t off)
Change the cached next payload write offset.
int _TIFFmemcmp(const void *p1, const void *p2, tmsize_t c)
Compare two byte ranges lexicographically.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Query a present tag or a supported default.
int TIFFGetField(TIFF *tif, uint32_t tag,...)
Query a present tag in the current directory.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
TIFFDataType
Identify the on-disk representation of a TIFF directory field.
uint64_t toff_t
Represent an unsigned file byte offset independently of off_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.
uint64_t tdir_count
Number of file-type elements, normalised to host order.
uint16_t tdir_type
On-disk TIFFDataType code.
uint64_t toff_long8
Raw 64-bit view of inline bytes or offset storage.
uint16_t tdir_tag
Directory tag identifier.
union TIFFDirEntry::@0 tdir_offset
Overlay raw directory inline bytes and offset-width views.
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.
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...
int td_inknameslen
Byte length of the concatenated ink-name strings, including terminators.
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.
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.
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.
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.
unsigned char td_deferstrilearraywriting
Nonzero to reserve strile entries for later explicit array writing.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_subfiletype
NewSubfileType flag mask.
uint32_t td_nstrips
Total strile count across all planes; logical array length.
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_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.
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 field's file type and internal argument contract.
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.
TIFFSetGetFieldType set_get_field_type
Internal storage/count representation for tag access and conversion.
Hold private state for one open TIFF library instance.
uint64_t tif_subifdoff
File byte offset at which the next SubIFD link is patched.
tdir_t tif_curdircount
Cache the number of main IFDs in the file.
uint16_t tif_nsubifd
Number of remaining SubIFD links to write.
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.
size_t tif_nfields
Number of entries in tif_fields.
uint64_t tif_nextdiroff
Next directory byte offset from the current chain link.
TIFFField ** tif_fields
Owned sorted array of field pointers; descriptors have mixed ownership.
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.
TIFFBoolMethod tif_postencode
Codec callback completing buffered encoding.
TIFFVoidMethod tif_close
Codec close callback; distinct from the client I/O close callback.
uint64_t tif_dataoff
Byte offset used when placing directory data in the file.
tdir_t tif_curdir
Track the current or last-written directory index.
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.
uint64_t tif_lastdiroff
Byte offset of the last directory written so far.
int tif_mode
Current access mode using the O_* constants.
Declare private library state, callbacks, and implementation helpers.