LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_aux.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 1991-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25/*
26 * TIFF Library.
27 *
28 * Auxiliary Support Routines.
29 */
35#include "tif_predict.h"
36#include "tiffiop.h"
37#include <float.h>
38#include <math.h>
39
40uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second,
41 const char *where)
42{
43 return _TIFFMultiply32Ext(tif, first, second, where, NULL);
44}
45
46uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second,
47 const char *where)
48{
49 if (second && first > UINT64_MAX / second)
50 {
51 TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
52 return 0;
53 }
54
55 return first * second;
56}
57
58uint32_t _TIFFParseUInt32(const char *str, uint32_t default_value,
59 uint32_t max_value)
60{
61 uint32_t val = 0;
62
63 if (str == NULL)
64 return default_value;
65 while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\v' ||
66 *str == '\f' || *str == '\r')
67 str++;
68 if (*str == '+')
69 str++;
70 if (*str < '0' || *str > '9')
71 return default_value;
72 do
73 {
74 const uint32_t digit = (uint32_t)(*str - '0');
75 if (digit > max_value || val > (max_value - digit) / 10)
76 return default_value;
77 val = val * 10 + digit;
78 str++;
79 } while (*str >= '0' && *str <= '9');
80 if (*str != '\0')
81 return default_value;
82 return val;
83}
84
85uint64_t _TIFFAdd64(TIFF *tif, uint64_t first, uint64_t second,
86 const char *where)
87{
88 return _TIFFAdd64Ext(tif, first, second, where, NULL);
89}
90
92 const char *where)
93{
94 if (first <= 0 || second <= 0)
95 {
96 if (tif != NULL && where != NULL)
97 {
98 TIFFErrorExtR(tif, where,
99 "Invalid argument to _TIFFMultiplySSize() in %s",
100 where);
101 }
102 return 0;
103 }
104
105 if (first > TIFF_TMSIZE_T_MAX / second)
106 {
107 if (tif != NULL && where != NULL)
108 {
109 TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
110 }
111 return 0;
112 }
113 return first * second;
114}
115
117 const char *where)
118{
119 if (first < 0 || second < 0)
120 {
121 if (tif != NULL && where != NULL)
122 {
123 TIFFErrorExtR(tif, where,
124 "Invalid argument to _TIFFAddSSize() in %s", where);
125 }
126 return 0;
127 }
128
129 if (first > TIFF_TMSIZE_T_MAX - second)
130 {
131 if (tif != NULL && where != NULL)
132 {
133 TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
134 }
135 return 0;
136 }
137 return first + second;
138}
139
140tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
141{
142 if (val > (uint64_t)TIFF_TMSIZE_T_MAX)
143 {
144 if (tif != NULL && module != NULL)
145 {
146 TIFFErrorExtR(tif, module, "Integer overflow");
147 }
148 return 0;
149 }
150 return (tmsize_t)val;
151}
152
153uint32_t _TIFFCastUInt64ToUInt32(TIFF *tif, uint64_t val, const char *module)
154{
155 return _TIFFCastUInt64ToUInt32Ext(tif, val, module, NULL);
156}
157
158/*
159 * The *Ext() variants of the checked arithmetic functions behave like the
160 * functions they extend, and additionally set *pOverflowed to true on overflow
161 * when pOverflowed is not NULL. *pOverflowed is never reset to false, so
162 * several operations can share one flag that is tested once. This tells an
163 * overflow apart from a genuine 0 result without re-testing the operands.
164 */
165
166uint32_t _TIFFMultiply32Ext(TIFF *tif, uint32_t first, uint32_t second,
167 const char *where, bool *pOverflowed)
168{
169 if (second && first > UINT32_MAX / second)
170 {
171 TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
172 if (pOverflowed != NULL)
173 *pOverflowed = true;
174 return 0;
175 }
176
177 return first * second;
178}
179
180uint64_t _TIFFAdd64Ext(TIFF *tif, uint64_t first, uint64_t second,
181 const char *where, bool *pOverflowed)
182{
183 if (first > UINT64_MAX - second)
184 {
185 if (tif != NULL && where != NULL)
186 {
187 TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
188 }
189 if (pOverflowed != NULL)
190 *pOverflowed = true;
191 return 0;
192 }
193
194 return first + second;
195}
196
197uint32_t _TIFFCastUInt64ToUInt32Ext(TIFF *tif, uint64_t val, const char *module,
198 bool *pOverflowed)
199{
200 if (val > UINT32_MAX)
201 {
202 if (tif != NULL && module != NULL)
203 {
204 TIFFErrorExtR(tif, module, "Integer overflow");
205 }
206 if (pOverflowed != NULL)
207 *pOverflowed = true;
208 return 0;
209 }
210 return (uint32_t)val;
211}
212
213tmsize_t _TIFFComputeRowOffset(TIFF *tif, tmsize_t rowstride, uint32_t row,
214 const char *where)
215{
216 if (row == 0)
217 return 0;
218 return _TIFFMultiplySSize(tif, rowstride, (tmsize_t)row, where);
219}
220
221uint64_t _TIFFComputeBitOffset(TIFF *tif, uint32_t col, uint16_t spp,
222 uint16_t bps, const char *where)
223{
224 uint64_t samples = _TIFFMultiply64(tif, col, spp, where);
225 if (samples == 0 && col != 0)
226 return 0;
227 return _TIFFMultiply64(tif, samples, bps, where);
228}
229
230/*
231 * Returns 0 on overflow or invalid zero-sized row inputs. Callers that
232 * intentionally allow empty rows should not use this helper directly.
233 */
234uint64_t _TIFFComputeRowSize64(TIFF *tif, uint32_t width, uint16_t spp,
235 uint16_t bps, const char *where)
236{
237 uint64_t samples = _TIFFMultiply64(tif, width, spp, where);
238 uint64_t bits;
239 if (samples == 0)
240 return 0;
241
242 bits = _TIFFMultiply64(tif, samples, bps, where);
243 if (bits == 0)
244 return 0;
245
246 return TIFFhowmany8_64(bits);
247}
248
249void *_TIFFCheckRealloc(TIFF *tif, void *buffer, tmsize_t nmemb,
250 tmsize_t elem_size, const char *what)
251{
252 void *cp = NULL;
253 tmsize_t count = _TIFFMultiplySSize(tif, nmemb, elem_size, NULL);
254 /*
255 * Check for integer overflow.
256 */
257 if (count != 0)
258 {
259 cp = _TIFFreallocExt(tif, buffer, count);
260 }
261
262 if (cp == NULL)
263 {
264 TIFFErrorExtR(tif, tif->tif_name,
265 "Failed to allocate memory for %s "
266 "(%" TIFF_SSIZE_FORMAT " elements of %" TIFF_SSIZE_FORMAT
267 " bytes each)",
268 what, nmemb, elem_size);
269 }
270
271 return cp;
272}
273
274void *_TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size,
275 const char *what)
276{
277 return _TIFFCheckRealloc(tif, NULL, nmemb, elem_size, what);
278}
279
302{
303 uint16_t **tf = td->td_transferfunction;
304 tmsize_t i, n, nbytes;
305
306 tf[0] = tf[1] = tf[2] = 0;
307 /*
308 * The curves below are computed in place rather than copied from a
309 * caller array, so this is the one place outside setTransferFunction()
310 * in tif_dir.c that writes td_transferfunction_count. It is kept in
311 * step with the allocation here: cleared before anything is allocated,
312 * and set only once every curve is in place. FIELD_TRANSFERFUNCTION is
313 * deliberately not set - this is a default value, not a tag the caller
314 * supplied.
315 */
317 // Do not try to generate a default TransferFunction beyond 24 bits.
318 // This otherwise leads to insane amounts, resulting in denial of service
319 // See https://github.com/OSGeo/gdal/issues/10875
320 if (td->td_bitspersample > 24)
321 return 0;
322
323 n = (tmsize_t)(1ULL << td->td_bitspersample);
324 nbytes = (tmsize_t)((uint64_t)n * sizeof(uint16_t));
325 tf[0] = (uint16_t *)_TIFFmallocExt(tif, nbytes);
326 if (tf[0] == NULL)
327 return 0;
328 tf[0][0] = 0;
329 for (i = 1; i < n; i++)
330 {
331 double t = (double)i / ((double)n - 1.);
332 tf[0][i] = (uint16_t)floor(65535. * pow(t, 2.2) + .5);
333 }
334
335 if (td->td_samplesperpixel - td->td_extrasamples > 1)
336 {
337 tf[1] = (uint16_t *)_TIFFmallocExt(tif, nbytes);
338 if (tf[1] == NULL)
339 goto bad;
340 _TIFFmemcpy(tf[1], tf[0], nbytes);
341 tf[2] = (uint16_t *)_TIFFmallocExt(tif, nbytes);
342 if (tf[2] == NULL)
343 goto bad;
344 _TIFFmemcpy(tf[2], tf[0], nbytes);
345 }
346 td->td_transferfunction_count = (uint32_t)n;
347 return 1;
348
349bad:
350 if (tf[0])
351 _TIFFfreeExt(tif, tf[0]);
352 if (tf[1])
353 _TIFFfreeExt(tif, tf[1]);
354 if (tf[2])
355 _TIFFfreeExt(tif, tf[2]);
356 tf[0] = tf[1] = tf[2] = 0;
357 return 0;
358}
359
379{
380 int i;
381
382 td->td_refblackwhite = (float *)_TIFFmallocExt(tif, 6 * sizeof(float));
383 if (td->td_refblackwhite == NULL)
384 return 0;
386 {
387 /*
388 * YCbCr (Class Y) images must have the ReferenceBlackWhite
389 * tag set. Fix the broken images, which lacks that tag.
390 */
391 td->td_refblackwhite[0] = 0.0f;
392 td->td_refblackwhite[1] = td->td_refblackwhite[3] =
393 td->td_refblackwhite[5] = 255.0f;
394 td->td_refblackwhite[2] = td->td_refblackwhite[4] = 128.0f;
395 }
396 else
397 {
398 /*
399 * Assume RGB (Class R)
400 */
401 for (i = 0; i < 3; i++)
402 {
403 td->td_refblackwhite[2 * i + 0] = 0;
404 if (td->td_bitspersample < 64)
405 td->td_refblackwhite[2 * i + 1] =
406 (float)((1ULL << td->td_bitspersample) - 1ULL);
407 else
408 td->td_refblackwhite[2 * i + 1] = (float)UINT64_MAX;
409 }
410 }
411 return 1;
412}
413
414/*
415 * Like TIFFGetField, but return any default
416 * value if the tag is not present in the directory.
417 *
418 * NB: We use the value in the directory, rather than
419 * explicit values so that defaults exist only one
420 * place in the library -- in TIFFDefaultDirectory.
421 */
422int TIFFVGetFieldDefaulted(TIFF *tif, uint32_t tag, va_list ap)
423{
424 TIFFDirectory *td = &tif->tif_dir;
425
426 if (TIFFVGetField(tif, tag, ap))
427 return (1);
428 switch (tag)
429 {
431 *va_arg(ap, uint32_t *) = td->td_subfiletype;
432 return (1);
434 *va_arg(ap, uint16_t *) = td->td_bitspersample;
435 return (1);
437 *va_arg(ap, uint16_t *) = td->td_threshholding;
438 return (1);
440 *va_arg(ap, uint16_t *) = td->td_fillorder;
441 return (1);
443 *va_arg(ap, uint16_t *) = td->td_orientation;
444 return (1);
446 *va_arg(ap, uint16_t *) = td->td_samplesperpixel;
447 return (1);
449 *va_arg(ap, uint32_t *) = td->td_rowsperstrip;
450 return (1);
452 *va_arg(ap, uint16_t *) = td->td_minsamplevalue;
453 return (1);
455 {
456 uint16_t maxsamplevalue;
457 /* td_bitspersample=1 is always set in TIFFDefaultDirectory().
458 * Therefore, td_maxsamplevalue has to be re-calculated in
459 * TIFFGetFieldDefaulted(). */
460 if (td->td_bitspersample > 0)
461 {
462 /* This shift operation into a uint16_t limits the value to
463 * 65535 even if td_bitspersamle is > 16 */
464 if (td->td_bitspersample <= 16)
465 {
466 maxsamplevalue = (uint16_t)((1U << td->td_bitspersample) -
467 1); /* 2**(BitsPerSample) - 1 */
468 }
469 else
470 {
471 maxsamplevalue = 65535;
472 }
473 }
474 else
475 {
476 maxsamplevalue = 0;
477 }
478 *va_arg(ap, uint16_t *) = maxsamplevalue;
479 return (1);
480 }
482 *va_arg(ap, uint16_t *) = td->td_planarconfig;
483 return (1);
485 *va_arg(ap, uint16_t *) = td->td_resolutionunit;
486 return (1);
488 {
490 if (sp == NULL)
491 {
493 tif, tif->tif_name,
494 "Cannot get \"Predictor\" tag as plugin is not configured");
495 *va_arg(ap, uint16_t *) = 0;
496 return 0;
497 }
498 *va_arg(ap, uint16_t *) = (uint16_t)sp->predictor;
499 return 1;
500 }
501 case TIFFTAG_DOTRANGE:
502 *va_arg(ap, uint16_t *) = 0;
503 if (td->td_bitspersample <= 16)
504 *va_arg(ap, uint16_t *) =
505 (uint16_t)((1U << td->td_bitspersample) - 1);
506 else
507 *va_arg(ap, uint16_t *) = 65535;
508 return (1);
509 case TIFFTAG_INKSET:
510 *va_arg(ap, uint16_t *) = INKSET_CMYK;
511 return 1;
513 *va_arg(ap, uint16_t *) = 4;
514 return (1);
516 *va_arg(ap, uint16_t *) = td->td_extrasamples;
517 *va_arg(ap, const uint16_t **) = td->td_sampleinfo;
518 return (1);
519 case TIFFTAG_MATTEING:
520 *va_arg(ap, uint16_t *) =
521 (td->td_extrasamples == 1 && td->td_sampleinfo &&
523 return (1);
525 *va_arg(ap, uint32_t *) = td->td_tiledepth;
526 return (1);
527 case TIFFTAG_DATATYPE:
528 *va_arg(ap, uint16_t *) = (uint16_t)(td->td_sampleformat - 1);
529 return (1);
531 *va_arg(ap, uint16_t *) = td->td_sampleformat;
532 return (1);
534 *va_arg(ap, uint32_t *) = td->td_imagedepth;
535 return (1);
537 {
538 /* defaults are from CCIR Recommendation 601-1 */
539 static const float ycbcrcoeffs[] = {0.299f, 0.587f, 0.114f};
540 *va_arg(ap, const float **) = ycbcrcoeffs;
541 return 1;
542 }
544 *va_arg(ap, uint16_t *) = td->td_ycbcrsubsampling[0];
545 *va_arg(ap, uint16_t *) = td->td_ycbcrsubsampling[1];
546 return (1);
548 *va_arg(ap, uint16_t *) = td->td_ycbcrpositioning;
549 return (1);
551 {
552 /* TIFF 6.0 specification tells that it is no default
553 value for the WhitePoint, but AdobePhotoshop TIFF
554 Technical Note tells that it should be CIE D50. */
555 static const float whitepoint[] = {
556 D50_X0 / (D50_X0 + D50_Y0 + D50_Z0),
557 D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0)};
558 *va_arg(ap, const float **) = whitepoint;
559 return 1;
560 }
562 if (!td->td_transferfunction[0] &&
564 {
565 TIFFErrorExtR(tif, tif->tif_name,
566 "No space for \"TransferFunction\" tag");
567 return (0);
568 }
569 *va_arg(ap, const uint16_t **) = td->td_transferfunction[0];
570 if (td->td_samplesperpixel - td->td_extrasamples > 1)
571 {
572 *va_arg(ap, const uint16_t **) = td->td_transferfunction[1];
573 *va_arg(ap, const uint16_t **) = td->td_transferfunction[2];
574 }
575 return (1);
577 if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(tif, td))
578 return (0);
579 *va_arg(ap, const float **) = td->td_refblackwhite;
580 return (1);
581 default:
582 break;
583 }
584 return 0;
585}
586
587/*
588 * Like TIFFGetField, but return any default
589 * value if the tag is not present in the directory.
590 */
591int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag, ...)
592{
593 int ok;
594 va_list ap;
595
596 va_start(ap, tag);
597 ok = TIFFVGetFieldDefaulted(tif, tag, ap);
598 va_end(ap);
599 return (ok);
600}
601
602float _TIFFClampDoubleToFloat(double val)
603{
604 if (val > (double)FLT_MAX)
605 return FLT_MAX;
606 if (val < -(double)FLT_MAX)
607 return -FLT_MAX;
608 return (float)val;
609}
610
611uint32_t _TIFFClampDoubleToUInt32(double val)
612{
613 if (val < 0)
614 return 0;
615 if (val > 0xFFFFFFFFU || isnan(val))
616 return 0xFFFFFFFFU;
617 return (uint32_t)val;
618}
619
620int _TIFFSeekOK(TIFF *tif, toff_t off)
621{
622 /* Huge offsets, especially -1 / UINT64_MAX, can cause issues */
623 /* See http://bugzilla.maptools.org/show_bug.cgi?id=2726 */
624 return off <= (~(uint64_t)0) / 2 && TIFFSeekFile(tif, off, SEEK_SET) == off;
625}
tmsize_t _TIFFAddSSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and add two signed-size operands.
Definition tif_aux.c:116
uint32_t _TIFFMultiply32Ext(TIFF *tif, uint32_t first, uint32_t second, const char *where, bool *pOverflowed)
Multiply two unsigned values with an overflow check, and record an overflow in a caller-provided flag...
Definition tif_aux.c:166
uint32_t _TIFFClampDoubleToUInt32(double val)
Clamp and truncate a double to an unsigned 32-bit value.
Definition tif_aux.c:611
uint32_t _TIFFParseUInt32(const char *str, uint32_t default_value, uint32_t max_value)
Parse a decimal unsigned integer with a fallback value.
Definition tif_aux.c:58
int _TIFFSeekOK(TIFF *tif, toff_t off)
Test whether an allowed absolute client seek reaches its target.
Definition tif_aux.c:620
uint64_t _TIFFComputeRowSize64(TIFF *tif, uint32_t width, uint16_t spp, uint16_t bps, const char *where)
Compute a byte-rounded row size from width and sample geometry.
Definition tif_aux.c:234
uint32_t _TIFFCastUInt64ToUInt32(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
Definition tif_aux.c:153
uint64_t _TIFFAdd64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Check and add two unsigned operands.
Definition tif_aux.c:85
tmsize_t _TIFFComputeRowOffset(TIFF *tif, tmsize_t rowstride, uint32_t row, const char *where)
Compute a checked byte offset for a row in a memory raster.
Definition tif_aux.c:213
uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second, const char *where)
Multiply two unsigned values with an overflow check.
Definition tif_aux.c:40
uint32_t _TIFFCastUInt64ToUInt32Ext(TIFF *tif, uint64_t val, const char *module, bool *pOverflowed)
Convert an unsigned 64-bit value after checking the destination range, and record a rejection in a ca...
Definition tif_aux.c:197
uint64_t _TIFFComputeBitOffset(TIFF *tif, uint32_t col, uint16_t spp, uint16_t bps, const char *where)
Compute a checked packed-sample column offset in bits.
Definition tif_aux.c:221
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
Definition tif_aux.c:140
uint64_t _TIFFAdd64Ext(TIFF *tif, uint64_t first, uint64_t second, const char *where, bool *pOverflowed)
Check and add two unsigned operands, and record an overflow in a caller-provided flag.
Definition tif_aux.c:180
float _TIFFClampDoubleToFloat(double val)
Clamp a double to the finite float range before conversion.
Definition tif_aux.c:602
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Multiply two unsigned values with an overflow check.
Definition tif_aux.c:46
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and multiply two signed-size operands.
Definition tif_aux.c:91
#define TIFF_SSIZE_FORMAT
Provide the printf conversion fragment for tmsize_t, without a percent sign.
Definition tif_config.h:294
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
Definition tif_open.c:301
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Resize a handle-aware block or release it for a nonpositive size.
Definition tif_open.c:257
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
Definition tif_open.c:195
void * _TIFFCheckRealloc(TIFF *tif, void *buffer, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Resize a checked array with an allocation-failure diagnostic.
Definition tif_aux.c:249
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Allocate a checked array with an allocation-failure diagnostic.
Definition tif_aux.c:274
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
Definition tiffiop.h:920
#define TIFFhowmany8_64(x)
Compute the byte count needed to hold a 64-bit bit count.
Definition tiffiop.h:1127
static int TIFFDefaultTransferFunction(TIFF *tif, TIFFDirectory *td)
Allocate and cache default gamma transfer tables.
Definition tif_aux.c:301
static int TIFFDefaultRefBlackWhite(TIFF *tif, TIFFDirectory *td)
Allocate and cache six default reference levels.
Definition tif_aux.c:378
#define D50_X0
Define the D50 reference-white X coordinate, scaled to Y = 100.
Definition tiffio.h:259
#define D50_Y0
Define the D50 reference-white Y coordinate (100).
Definition tiffio.h:264
#define D50_Z0
Define the D50 reference-white Z coordinate, scaled to Y = 100.
Definition tiffio.h:269
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
Definition tif_unix.c:497
int TIFFVGetFieldDefaulted(TIFF *tif, uint32_t tag, va_list ap)
Query a present tag or a supported default.
Definition tif_aux.c:422
int TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap)
Query a present tag in the current directory.
Definition tif_dir.c:2116
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Query a present tag or a supported default.
Definition tif_aux.c:591
#define TIFFTAG_BITSPERSAMPLE
TIFF tag: Bits per channel (sample).
Definition tiff.h:298
#define TIFFTAG_RESOLUTIONUNIT
TIFF tag: Units of resolutions.
Definition tiff.h:516
#define TIFFTAG_WHITEPOINT
TIFF tag: Image white point.
Definition tiff.h:556
#define TIFFTAG_DOTRANGE
TIFF tag: 0% and 100% dot codes (introduced in TIFF 6.0).
Definition tiff.h:596
#define EXTRASAMPLE_ASSOCALPHA
Associated alpha data (introduced in TIFF 6.0).
Definition tiff.h:604
#define TIFFTAG_FILLORDER
TIFF tag: Data order within a byte.
Definition tiff.h:422
#define TIFFTAG_SAMPLESPERPIXEL
TIFF tag: Samples per pixel.
Definition tiff.h:456
#define TIFFTAG_INKSET
TIFF tag: Inks in separated image (introduced in TIFF 6.0).
Definition tiff.h:586
#define TIFFTAG_DATATYPE
TIFF tag: Legacy sample-type indicator; superseded by TIFFTAG_SAMPLEFORMAT (obsoleted by TIFF 6....
Definition tiff.h:770
#define TIFFTAG_IMAGEDEPTH
TIFF tag: Z depth of image.
Definition tiff.h:772
#define TIFFTAG_MAXSAMPLEVALUE
TIFF tag: Maximum sample value (obsoleted by TIFF 5.0).
Definition tiff.h:464
#define TIFFTAG_TILEDEPTH
TIFF tag: Z depth/data tile.
Definition tiff.h:774
#define TIFFTAG_EXTRASAMPLES
TIFF tag: Info about extra samples (introduced in TIFF 6.0).
Definition tiff.h:600
#define TIFFTAG_YCBCRCOEFFICIENTS
TIFF tag: RGB -> YCbCr transform (introduced in TIFF 6.0).
Definition tiff.h:727
#define TIFFTAG_ORIENTATION
TIFF tag: Image orientation (obsoleted by TIFF 5.0).
Definition tiff.h:438
#define TIFFTAG_MATTEING
TIFF tag: Legacy alpha indicator; superseded by TIFFTAG_EXTRASAMPLES (obsoleted by TIFF 6....
Definition tiff.h:765
#define TIFFTAG_MINSAMPLEVALUE
TIFF tag: Minimum sample value (obsoleted by TIFF 5.0).
Definition tiff.h:462
#define TIFFTAG_NUMBEROFINKS
TIFF tag: Number of inks (introduced in TIFF 6.0).
Definition tiff.h:594
#define PHOTOMETRIC_YCBCR
CCIR 601 (introduced in TIFF 6.0).
Definition tiff.h:396
#define TIFFTAG_TRANSFERFUNCTION
TIFF tag: Colorimetry info (introduced in TIFF 6.0).
Definition tiff.h:538
#define INKSET_CMYK
Cyan-magenta-yellow-black color (introduced in TIFF 6.0).
Definition tiff.h:588
#define TIFFTAG_YCBCRSUBSAMPLING
TIFF tag: YCbCr subsampling factors (introduced in TIFF 6.0).
Definition tiff.h:729
#define TIFFTAG_ROWSPERSTRIP
TIFF tag: Rows per strip of data.
Definition tiff.h:458
#define TIFFTAG_SAMPLEFORMAT
TIFF tag: Data sample format (introduced in TIFF 6.0).
Definition tiff.h:608
#define TIFFTAG_REFERENCEBLACKWHITE
TIFF tag: Colorimetry info (introduced in TIFF 6.0).
Definition tiff.h:737
#define TIFFTAG_PLANARCONFIG
TIFF tag: Storage organization.
Definition tiff.h:470
#define TIFFTAG_SUBFILETYPE
TIFF tag: Subfile data descriptor.
Definition tiff.h:275
#define TIFFTAG_PREDICTOR
TIFF tag: Prediction scheme applied before compression.
Definition tiff.h:548
#define TIFFTAG_YCBCRPOSITIONING
TIFF tag: Subsample positioning (introduced in TIFF 6.0).
Definition tiff.h:731
#define TIFFTAG_THRESHHOLDING
TIFF tag: Thresholding used on data (obsoleted by TIFF 5.0).
Definition tiff.h:410
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
Definition tiffio.h:91
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
Definition tiffio.h:94
Store the current directory values and image traversal state.
Definition tif_dir.h:143
uint32_t td_tiledepth
Tile depth in slices.
Definition tif_dir.h:164
uint16_t td_fillorder
FILLORDER_* bit order within file bytes.
Definition tif_dir.h:178
uint16_t * td_sampleinfo
Owned ExtraSamples interpretation array of td_extrasamples entries, or NULL.
Definition tif_dir.h:237
float * td_refblackwhite
Owned six-float reference black/white array, or NULL.
Definition tif_dir.h:327
uint32_t td_rowsperstrip
Rows per strip; UINT32_MAX represents one whole-image strip.
Definition tif_dir.h:184
uint16_t td_photometric
PHOTOMETRIC_* interpretation.
Definition tif_dir.h:174
uint16_t td_extrasamples
Number of extra samples described by td_sampleinfo.
Definition tif_dir.h:232
uint16_t td_threshholding
THRESHHOLD_* bilevel rendering convention.
Definition tif_dir.h:176
uint16_t td_minsamplevalue
Legacy unsigned minimum sample value.
Definition tif_dir.h:186
uint16_t td_bitspersample
Bits in each sample.
Definition tif_dir.h:168
uint16_t * td_transferfunction[3]
Up to three owned gamma curves of td_transferfunction_count entries each.
Definition tif_dir.h:320
uint32_t td_imagedepth
Image depth in slices.
Definition tif_dir.h:158
uint16_t td_orientation
ORIENTATION_* storage orientation.
Definition tif_dir.h:180
uint16_t td_resolutionunit
RESUNIT_* unit for resolution and position values.
Definition tif_dir.h:198
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
Definition tif_dir.h:200
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
Definition tif_dir.h:170
uint16_t td_ycbcrsubsampling[2]
Horizontal and vertical YCbCr subsampling factors.
Definition tif_dir.h:312
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
Definition tif_dir.h:182
uint32_t td_subfiletype
NewSubfileType flag mask.
Definition tif_dir.h:166
uint32_t td_transferfunction_count
Number of entries in each installed TransferFunction curve, zero when none is installed; the only rec...
Definition tif_dir.h:325
uint16_t td_ycbcrpositioning
YCBCRPOSITION_* placement convention.
Definition tif_dir.h:314
Prefix codec state with Predictor method chains and row geometry.
Definition tif_predict.h:76
int predictor
Predictor tag value; validated at setup.
Definition tif_predict.h:78
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
Definition tiffiop.h:394
TIFFDirectory tif_dir
Inline representation of the current image directory.
Definition tiffiop.h:572
uint8_t * tif_data
Codec-private storage; allocation and cleanup follow the selected codec.
Definition tiffiop.h:675
Define the predictor prefix and method-chain contracts.
Declare private library state, callbacks, and implementation helpers.