49 if (second && first > UINT64_MAX / second)
55 return first * second;
65 while (*str ==
' ' || *str ==
'\t' || *str ==
'\n' || *str ==
'\v' ||
66 *str ==
'\f' || *str ==
'\r')
70 if (*str <
'0' || *str >
'9')
74 const uint32_t digit = (uint32_t)(*str -
'0');
75 if (digit > max_value || val > (max_value - digit) / 10)
77 val = val * 10 + digit;
79 }
while (*str >=
'0' && *str <=
'9');
94 if (first <= 0 || second <= 0)
96 if (tif != NULL && where != NULL)
99 "Invalid argument to _TIFFMultiplySSize() in %s",
107 if (tif != NULL && where != NULL)
113 return first * second;
119 if (first < 0 || second < 0)
121 if (tif != NULL && where != NULL)
124 "Invalid argument to _TIFFAddSSize() in %s", where);
131 if (tif != NULL && where != NULL)
137 return first + second;
144 if (tif != NULL && module != NULL)
167 const char *where,
bool *pOverflowed)
169 if (second && first > UINT32_MAX / second)
172 if (pOverflowed != NULL)
177 return first * second;
181 const char *where,
bool *pOverflowed)
183 if (first > UINT64_MAX - second)
185 if (tif != NULL && where != NULL)
189 if (pOverflowed != NULL)
194 return first + second;
200 if (val > UINT32_MAX)
202 if (tif != NULL && module != NULL)
206 if (pOverflowed != NULL)
210 return (uint32_t)val;
222 uint16_t bps,
const char *where)
225 if (samples == 0 && col != 0)
235 uint16_t bps,
const char *where)
250 tmsize_t elem_size,
const char *what)
265 "Failed to allocate memory for %s "
268 what, nmemb, elem_size);
306 tf[0] = tf[1] = tf[2] = 0;
324 nbytes = (
tmsize_t)((uint64_t)n *
sizeof(uint16_t));
329 for (i = 1; i < n; i++)
331 double t = (double)i / ((
double)n - 1.);
332 tf[0][i] = (uint16_t)floor(65535. * pow(t, 2.2) + .5);
356 tf[0] = tf[1] = tf[2] = 0;
401 for (i = 0; i < 3; i++)
456 uint16_t maxsamplevalue;
471 maxsamplevalue = 65535;
478 *va_arg(ap, uint16_t *) = maxsamplevalue;
494 "Cannot get \"Predictor\" tag as plugin is not configured");
495 *va_arg(ap, uint16_t *) = 0;
498 *va_arg(ap, uint16_t *) = (uint16_t)sp->
predictor;
502 *va_arg(ap, uint16_t *) = 0;
504 *va_arg(ap, uint16_t *) =
507 *va_arg(ap, uint16_t *) = 65535;
513 *va_arg(ap, uint16_t *) = 4;
520 *va_arg(ap, uint16_t *) =
539 static const float ycbcrcoeffs[] = {0.299f, 0.587f, 0.114f};
540 *va_arg(ap,
const float **) = ycbcrcoeffs;
555 static const float whitepoint[] = {
558 *va_arg(ap,
const float **) = whitepoint;
566 "No space for \"TransferFunction\" tag");
604 if (val > (
double)FLT_MAX)
606 if (val < -(
double)FLT_MAX)
615 if (val > 0xFFFFFFFFU || isnan(val))
617 return (uint32_t)val;
624 return off <= (~(uint64_t)0) / 2 &&
TIFFSeekFile(tif, off, SEEK_SET) == off;
tmsize_t _TIFFAddSSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and add two signed-size operands.
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...
uint32_t _TIFFClampDoubleToUInt32(double val)
Clamp and truncate a double to an unsigned 32-bit value.
uint32_t _TIFFParseUInt32(const char *str, uint32_t default_value, uint32_t max_value)
Parse a decimal unsigned integer with a fallback value.
int _TIFFSeekOK(TIFF *tif, toff_t off)
Test whether an allowed absolute client seek reaches its target.
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.
uint32_t _TIFFCastUInt64ToUInt32(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
uint64_t _TIFFAdd64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Check and add two unsigned operands.
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.
uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second, const char *where)
Multiply two unsigned values with an overflow check.
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...
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.
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
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.
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.
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and multiply two signed-size operands.
#define TIFF_SSIZE_FORMAT
Provide the printf conversion fragment for tmsize_t, without a percent sign.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Resize a handle-aware block or release it for a nonpositive size.
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
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.
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Allocate a checked array with an allocation-failure diagnostic.
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
#define TIFFhowmany8_64(x)
Compute the byte count needed to hold a 64-bit bit count.
static int TIFFDefaultTransferFunction(TIFF *tif, TIFFDirectory *td)
Allocate and cache default gamma transfer tables.
static int TIFFDefaultRefBlackWhite(TIFF *tif, TIFFDirectory *td)
Allocate and cache six default reference levels.
#define D50_X0
Define the D50 reference-white X coordinate, scaled to Y = 100.
#define D50_Y0
Define the D50 reference-white Y coordinate (100).
#define D50_Z0
Define the D50 reference-white Z coordinate, scaled to Y = 100.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
int TIFFVGetFieldDefaulted(TIFF *tif, uint32_t tag, va_list ap)
Query a present tag or a supported default.
int TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap)
Query a present tag in the current directory.
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Query a present tag or a supported default.
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.
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
Store the current directory values and image traversal state.
uint32_t td_tiledepth
Tile depth in slices.
uint16_t td_fillorder
FILLORDER_* bit order within file bytes.
uint16_t * td_sampleinfo
Owned ExtraSamples interpretation array of td_extrasamples entries, or NULL.
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.
uint16_t td_photometric
PHOTOMETRIC_* interpretation.
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.
uint16_t td_bitspersample
Bits in each sample.
uint16_t * td_transferfunction[3]
Up to three owned gamma curves of td_transferfunction_count entries each.
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.
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
uint16_t td_ycbcrsubsampling[2]
Horizontal and vertical YCbCr subsampling factors.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_subfiletype
NewSubfileType flag mask.
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.
Prefix codec state with Predictor method chains and row geometry.
int predictor
Predictor tag value; validated at setup.
Hold private state for one open TIFF library instance.
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
TIFFDirectory tif_dir
Inline representation of the current image directory.
uint8_t * tif_data
Codec-private storage; allocation and cleanup follow the selected codec.
Define the predictor prefix and method-chain contracts.
Declare private library state, callbacks, and implementation helpers.