39#include "Lerc_c_api.h"
47#include "libdeflate.h"
49#define LIBDEFLATE_MAX_COMPRESSION_LEVEL 12
53#define LSTATE_INIT_DECODE 0x01
54#define LSTATE_INIT_ENCODE 0x02
56#ifndef LERC_AT_LEAST_VERSION
57#define LERC_AT_LEAST_VERSION(maj, min, patch) 0
126#if LIBDEFLATE_SUPPORT
131 struct libdeflate_decompressor *libdeflate_dec;
136 struct libdeflate_compressor *libdeflate_enc;
145#define GetLERCState(tif) ((LERCState *)(tif)->tif_data)
146#define LERCDecoderState(tif) GetLERCState(tif)
147#define LERCEncoderState(tif) GetLERCState(tif)
210 static const char module[] = "GetLercDataType";
256 "Unsupported combination of SampleFormat and td_bitspersample");
286 uint64_t new_size_64;
287 uint64_t new_alloc_64;
288 unsigned int new_size;
289 unsigned int new_alloc;
315 if (new_size_64 > UINT_MAX)
317 TIFFErrorExtR(tif, module,
"Too large uncompressed strip/tile");
321 new_size = (
unsigned int)new_size_64;
327 new_alloc_64 = 256 + new_size_64 + new_size_64 / 3;
330 size_t zstd_max = ZSTD_compressBound((
size_t)new_size_64);
331 if (new_alloc_64 < zstd_max)
333 new_alloc_64 = zstd_max;
337 new_alloc = (
unsigned int)new_alloc_64;
338 if (new_alloc != new_alloc_64)
340 TIFFErrorExtR(tif, module,
"Too large uncompressed strip/tile");
369 unsigned int mask_size =
373#if LERC_AT_LEAST_VERSION(3, 0, 0)
388 if (mask_buffer == NULL)
435 static const char module[] = "LERCPreDecode";
436 lerc_status lerc_ret;
440 unsigned int infoArray[9];
445 unsigned int lerc_data_size = (
unsigned int)tif->
tif_rawcc;
453 if (lerc_data_type < 0)
476#if LIBDEFLATE_SUPPORT
477 enum libdeflate_result res;
478 size_t lerc_data_sizet = 0;
479 if (sp->libdeflate_dec == NULL)
481 sp->libdeflate_dec = libdeflate_alloc_decompressor();
482 if (sp->libdeflate_dec == NULL)
489 res = libdeflate_zlib_decompress(
492 if (res != LIBDEFLATE_SUCCESS)
498 assert(lerc_data_sizet == (
unsigned int)lerc_data_sizet);
500 lerc_data_size = (
unsigned int)lerc_data_sizet;
505 memset(&strm, 0,
sizeof(strm));
509 zlib_ret = inflateInit(&strm);
510 if (zlib_ret != Z_OK)
521 zlib_ret = inflate(&strm, Z_FINISH);
522 if (zlib_ret != Z_STREAM_END && zlib_ret != Z_OK)
540 if (ZSTD_isError(zstd_ret))
543 ZSTD_getErrorName(zstd_ret));
548 lerc_data_size = (
unsigned int)zstd_ret;
556 TIFFErrorExtR(tif, module,
"Unhandled additional compression");
561 lerc_getBlobInfo(lerc_data, lerc_data_size, infoArray, NULL, 9, 0);
594 "Unexpected version number: %u. Expected: %d",
597 if (infoArray[1] != (
unsigned)lerc_data_type)
599 TIFFErrorExtR(tif, module,
"Unexpected dataType: %u. Expected: %d",
600 infoArray[1], lerc_data_type);
604 const unsigned nFoundDims = infoArray[2];
605#if LERC_AT_LEAST_VERSION(3, 0, 0)
610 if (nFoundDims != 1 && nFoundDims != (
unsigned)ndims)
612 TIFFErrorExtR(tif, module,
"Unexpected nDim: %u. Expected: 1 or %d",
619 if (nFoundDims != (
unsigned)ndims)
621 TIFFErrorExtR(tif, module,
"Unexpected nDim: %u. Expected: %d",
628 TIFFErrorExtR(tif, module,
"Unexpected nCols: %u. Expected: %u",
634 TIFFErrorExtR(tif, module,
"Unexpected nRows: %u. Expected: %u",
639 const unsigned nFoundBands = infoArray[5];
644#if !LERC_AT_LEAST_VERSION(3, 0, 0)
649 "Unexpected nBands: %d. This file may have been generated with "
650 "a liblerc version >= 3.0, with one mask per band, and is not "
651 "supported by this older version of liblerc",
658 TIFFErrorExtR(tif, module,
"Unexpected nBands: %u. Expected: %d",
663 else if (nFoundBands != 1)
665 TIFFErrorExtR(tif, module,
"Unexpected nBands: %u. Expected: %d",
670 if (infoArray[7] != lerc_data_size)
672 TIFFErrorExtR(tif, module,
"Unexpected blobSize: %u. Expected: %u",
673 infoArray[7], lerc_data_size);
677 int nRequestedMasks = use_mask ? 1 : 0;
678#if LERC_AT_LEAST_VERSION(3, 0, 0)
679 const int nFoundMasks = (int)infoArray[8];
687 "Unexpected nFoundMasks: %d. Expected: 0 or %d",
691 nRequestedMasks = nFoundMasks;
695 if (nFoundMasks != 0 && nFoundMasks != 1)
698 "Unexpected nFoundMasks: %d. Expected: 0 or 1",
710 const unsigned nb_pixels =
715#if LERC_AT_LEAST_VERSION(3, 0, 0)
716 if (nRequestedMasks > 1)
718 unsigned int num_bytes_needed =
720 if (num_bytes_needed == 0)
725 if (num_bytes_needed == 0)
739 lerc_ret = lerc_decode(lerc_data, lerc_data_size, nRequestedMasks,
742 (
int)nFoundBands, (
unsigned int)lerc_data_type,
748 lerc_ret = lerc_decode(
749 lerc_data, lerc_data_size,
753 use_mask ? sp->
mask_buffer : NULL, (int)nFoundDims,
768 unsigned dst_stride =
770 unsigned i = nb_pixels;
772 while (i > 0 && i > nomask_bands)
794 const unsigned char nan_bytes[] = {0x7f, 0xc0, 0, 0};
796 const unsigned char nan_bytes[] = {0, 0, 0xc0, 0x7f};
799 memcpy(&nan_float32, nan_bytes, 4);
806 for (i = 0; i < nb_pixels; i++)
814 const double nan_float64 = (double)nan_float32;
815 for (i = 0; i < nb_pixels; i++)
822 else if (nRequestedMasks == 1)
825 assert(nFoundBands == 1);
830 for (i = 0; i < nb_pixels; i++)
842 const double nan_float64 = (double)nan_float32;
843 for (i = 0; i < nb_pixels; i++)
855#if LERC_AT_LEAST_VERSION(3, 0, 0)
859 assert(nFoundDims == 1);
865 for (i = 0; i < nb_pixels; i++)
869 if (sp->
mask_buffer[i + (
unsigned int)j * nb_pixels] ==
875 [i + (
unsigned int)j * nb_pixels];
882 const double nan_float64 = (double)nan_float32;
883 for (i = 0; i < nb_pixels; i++)
887 if (sp->
mask_buffer[i + (
unsigned int)j * nb_pixels] ==
894 [i + (
unsigned int)j * nb_pixels];
930 static const char module[] = "LERCDecode";
937 if (sp->uncompressed_buffer == NULL)
939 memset(op, 0, (
size_t)occ);
940 TIFFErrorExtR(tif, module,
"Uncompressed buffer not allocated");
944 if ((uint64_t)sp->uncompressed_offset + (uint64_t)occ >
945 sp->uncompressed_size)
947 memset(op, 0, (
size_t)occ);
952 memcpy(op, sp->uncompressed_buffer + sp->uncompressed_offset, (
size_t)occ);
953 sp->uncompressed_offset += (
unsigned int)occ;
958#ifndef LERC_READ_ONLY
1007 static const char module[] = "LERCPreEncode";
1017 if (lerc_data_type < 0)
1051 static const char module[] = "LERCEncode";
1059 "LERC codec state is not initialized for encoding");
1063 if ((uint64_t)sp->uncompressed_offset + (uint64_t)cc >
1064 sp->uncompressed_size)
1070 memcpy(sp->uncompressed_buffer + sp->uncompressed_offset, bp, (
size_t)cc);
1071 sp->uncompressed_offset += (
unsigned int)cc;
1108 lerc_status lerc_ret;
1109 static const char module[] = "LERCPostEncode";
1111 unsigned int numBytesWritten = 0;
1119 "LERC codec state is not initialized for encoding");
1123 if (sp->uncompressed_offset != sp->uncompressed_size)
1125 TIFFErrorExtR(tif, module,
"Unexpected number of bytes in the buffer");
1130 const unsigned nb_pixels =
1142 const unsigned dst_stride =
1145 const unsigned src_stride =
1150 for (i = 0; i < nb_pixels; i++)
1152 int v = sp->uncompressed_buffer[i * src_stride +
1154 if (v != 0 && v != 255)
1165 for (i = 0; i < dst_nbands && i < nb_pixels; i++)
1167 memmove(sp->uncompressed_buffer + i * dst_stride,
1168 sp->uncompressed_buffer + i * src_stride, dst_stride);
1169 sp->mask_buffer[i] =
1170 sp->uncompressed_buffer[i * src_stride +
1173 for (; i < nb_pixels; i++)
1175 memcpy(sp->uncompressed_buffer + i * dst_stride,
1176 sp->uncompressed_buffer + i * src_stride, dst_stride);
1177 sp->mask_buffer[i] =
1178 sp->uncompressed_buffer[i * src_stride +
1193 for (i = 0; i < nb_pixels; i++)
1198 const float val = ((
float *)sp->uncompressed_buffer)[k];
1208 if (count_nan < td->td_samplesperpixel)
1218 for (i = 0; i < nb_pixels; i++)
1220 const float val = ((
float *)sp->uncompressed_buffer)[i];
1234 for (i = 0; i < nb_pixels; i++)
1240 ((
double *)sp->uncompressed_buffer)[k];
1250 if (count_nan < td->td_samplesperpixel)
1260 for (i = 0; i < nb_pixels; i++)
1262 const double val = ((
double *)sp->uncompressed_buffer)[i];
1276#if LERC_AT_LEAST_VERSION(3, 0, 0)
1277 unsigned int num_bytes_needed =
1279 if (num_bytes_needed == 0)
1284 if (num_bytes_needed == 0)
1286 if (sp->uncompressed_buffer_multiband_alloc < num_bytes_needed)
1289 sp->uncompressed_buffer_multiband =
1291 if (!sp->uncompressed_buffer_multiband)
1293 sp->uncompressed_buffer_multiband_alloc = 0;
1296 sp->uncompressed_buffer_multiband_alloc = num_bytes_needed;
1302 for (i = 0; i < nb_pixels; i++)
1307 ((
float *)sp->uncompressed_buffer)[k];
1308 ((
float *)sp->uncompressed_buffer_multiband)
1309 [i + (
unsigned int)j * nb_pixels] = val;
1311 sp->mask_buffer[i + (
unsigned int)j * nb_pixels] =
1312 !isnan(val) ? 255 : 0;
1318 for (i = 0; i < nb_pixels; i++)
1323 ((
double *)sp->uncompressed_buffer)[k];
1324 ((
double *)sp->uncompressed_buffer_multiband)
1325 [i + (
unsigned int)j * nb_pixels] = val;
1327 sp->mask_buffer[i + (
unsigned int)j * nb_pixels] =
1328 !isnan(val) ? 255 : 0;
1334 "lerc_encode() would need to create one mask per "
1335 "sample, but this requires liblerc >= 3.0");
1344 for (i = 0; i < nb_pixels; i++)
1347 ((
float *)sp->uncompressed_buffer)[i * dst_nbands];
1348 sp->mask_buffer[i] = !isnan(val) ? 255 : 0;
1353 for (i = 0; i < nb_pixels; i++)
1356 ((
double *)sp->uncompressed_buffer)[i * dst_nbands];
1357 sp->mask_buffer[i] = !isnan(val) ? 255 : 0;
1365 for (i = 0; i < nb_pixels; i++)
1367 const float val = ((
float *)sp->uncompressed_buffer)[i];
1368 sp->mask_buffer[i] = !isnan(val) ? 255 : 0;
1373 for (i = 0; i < nb_pixels; i++)
1376 ((
double *)sp->uncompressed_buffer)[i];
1377 sp->mask_buffer[i] = !isnan(val) ? 255 : 0;
1384 unsigned int estimated_compressed_size = sp->uncompressed_alloc;
1385#if LERC_AT_LEAST_VERSION(3, 0, 0)
1388 uint64_t mask_overhead =
1389 ((uint64_t)sp->segment_width * sp->segment_height *
1390 (
unsigned)mask_count +
1393 if (mask_overhead > UINT_MAX - estimated_compressed_size)
1396 "Integer overflow in estimated compressed size");
1399 estimated_compressed_size += (
unsigned int)mask_overhead;
1403 if (sp->compressed_size < estimated_compressed_size)
1406 sp->compressed_buffer =
_TIFFmallocExt(tif, estimated_compressed_size);
1407 if (!sp->compressed_buffer)
1409 sp->compressed_size = 0;
1412 sp->compressed_size = estimated_compressed_size;
1415#if LERC_AT_LEAST_VERSION(3, 0, 0)
1418 lerc_ret = lerc_encodeForVersion(
1419 sp->uncompressed_buffer_multiband, sp->lerc_version,
1421 (
int)sp->segment_height, (
int)dst_nbands, (
int)dst_nbands,
1422 sp->mask_buffer, sp->maxzerror,
1423 (
unsigned char *)sp->compressed_buffer, sp->compressed_size,
1429 lerc_ret = lerc_encodeForVersion(
1430 sp->uncompressed_buffer, sp->lerc_version,
1433 (
int)sp->segment_width, (int)sp->segment_height, 1,
1437 use_mask ? sp->mask_buffer : NULL, sp->maxzerror,
1438 (
unsigned char *)sp->compressed_buffer, sp->compressed_size,
1446 assert(numBytesWritten < estimated_compressed_size);
1450#if LIBDEFLATE_SUPPORT
1451 if (sp->libdeflate_enc == NULL)
1455 sp->libdeflate_enc = libdeflate_alloc_compressor(
1456 sp->zipquality == Z_DEFAULT_COMPRESSION ? 7
1457 : sp->zipquality >= 6 && sp->zipquality <= 9
1458 ? sp->zipquality + 1
1460 if (sp->libdeflate_enc == NULL)
1468 if (libdeflate_zlib_compress_bound(
1469 sp->libdeflate_enc, numBytesWritten) > sp->uncompressed_alloc)
1472 "Output buffer for libdeflate too small");
1477 sp->libdeflate_enc, sp->compressed_buffer, numBytesWritten,
1478 sp->uncompressed_buffer, sp->uncompressed_alloc);
1489 int cappedQuality = sp->zipquality;
1490 if (cappedQuality > Z_BEST_COMPRESSION)
1491 cappedQuality = Z_BEST_COMPRESSION;
1493 memset(&strm, 0,
sizeof(strm));
1497 zlib_ret = deflateInit(&strm, cappedQuality);
1498 if (zlib_ret != Z_OK)
1504 strm.avail_in = numBytesWritten;
1505 strm.next_in = sp->compressed_buffer;
1506 strm.avail_out = sp->uncompressed_alloc;
1507 strm.next_out = sp->uncompressed_buffer;
1508 zlib_ret = deflate(&strm, Z_FINISH);
1509 if (zlib_ret == Z_STREAM_END)
1511 tif->
tif_rawcc = sp->uncompressed_alloc - strm.avail_out;
1514 if (zlib_ret != Z_STREAM_END)
1538 size_t zstd_ret = ZSTD_compress(
1539 sp->uncompressed_buffer, sp->uncompressed_alloc,
1540 sp->compressed_buffer, numBytesWritten, sp->zstd_compress_level);
1541 if (ZSTD_isError(zstd_ret))
1544 ZSTD_getErrorName(zstd_ret));
1570 TIFFErrorExtR(tif, module,
"Unhandled additional compression");
1579 tif->
tif_rawdata = (uint8_t *)sp->compressed_buffer;
1620#if LIBDEFLATE_SUPPORT
1621 if (sp->libdeflate_dec)
1622 libdeflate_free_decompressor(sp->libdeflate_dec);
1623 if (sp->libdeflate_enc)
1624 libdeflate_free_compressor(sp->libdeflate_enc);
1644 (
char *)
"LercParameters", NULL},
1652 FALSE, (
char *)
"ZSTD zstd_compress_level", NULL},
1654 FALSE, (
char *)
"", NULL},
1711 static const char module[] = "LERCVSetField";
1718 uint32_t count = (uint32_t)va_arg(ap,
int);
1719 int *params = va_arg(ap,
int *);
1723 "Invalid count for LercParameters: %u", count);
1726 sp->lerc_version = params[0];
1727 sp->additional_compression = params[1];
1732 sp->maxzerror = va_arg(ap,
double);
1736 int params[2] = {0, 0};
1737 int version = va_arg(ap,
int);
1740 TIFFErrorExtR(tif, module,
"Invalid value for LercVersion: %d",
1744 sp->lerc_version = version;
1745 params[0] = sp->lerc_version;
1746 params[1] = sp->additional_compression;
1751 int params[2] = {0, 0};
1752 int additional_compression = va_arg(ap,
int);
1757 "LERC_ZSTD requested, but ZSTD not available");
1766 "Invalid value for LercAdditionalCompression: %d",
1767 additional_compression);
1770 sp->additional_compression = additional_compression;
1771 params[0] = sp->lerc_version;
1772 params[1] = sp->additional_compression;
1778 sp->zstd_compress_level = (int)va_arg(ap,
int);
1779 if (sp->zstd_compress_level <= 0 ||
1780 sp->zstd_compress_level > ZSTD_maxCLevel())
1783 "ZSTD_LEVEL should be between 1 and %d",
1791 sp->zipquality = (int)va_arg(ap,
int);
1792 if (sp->zipquality < Z_DEFAULT_COMPRESSION ||
1797 "Invalid ZipQuality value. Should be in [-1,%d] range",
1802#if LIBDEFLATE_SUPPORT
1803 if (sp->libdeflate_enc)
1805 libdeflate_free_compressor(sp->libdeflate_enc);
1806 sp->libdeflate_enc = NULL;
1813 return (*sp->vsetparent)(tif, tag, ap);
1865 static const char module[] = "TIFFInitLERC";
1876 TIFFErrorExtR(tif, module,
"Merging LERC codec-specific tags failed");
1905#ifndef LERC_READ_ONLY
1925 sp->maxzerror = 0.0;
1926 sp->zstd_compress_level = 9;
1927 sp->zipquality = Z_DEFAULT_COMPRESSION;
1932 TIFFErrorExtR(tif, module,
"No space for LERC state block");
uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second, const char *where)
Multiply two unsigned values with an overflow check.
void _TIFFSetDefaultCompressionState(TIFF *tif)
Install fallback codec callbacks and reset raw-access flags.
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
Merge borrowed field definitions into the lookup table.
#define FIELD_PSEUDO
Share bit zero with FIELD_IGNORE for pseudo-tags.
@ TIFF_SETGET_DOUBLE
Double scalar storage.
@ TIFF_SETGET_INT
Promoted int scalar representation.
@ TIFF_SETGET_C32_UINT32
Unsigned 32-bit array with 32-bit explicit count.
@ TIFF_SETGET_UINT32
Unsigned 32-bit scalar storage.
int TIFFFlushData1(TIFF *tif)
Append buffered encoded bytes without invoking postencode recursively.
static int LERCSetupEncode(TIFF *tif)
Select LERC encode mode.
int TIFFInitLERC(TIFF *tif, int scheme)
Allocate LERC staging state and install frame callbacks and pseudo-tags.
static int SetupBuffers(TIFF *tif, LERCState *sp, const char *module)
Size and reserve full-strile sample and validity-mask storage.
static int GetLercDataType(TIFF *tif)
Map TIFF sample format and depth to a LERC scalar code.
static int LERCPostEncode(TIFF *tif)
Encode a fully staged LERC strile and flush optional secondary compression.
static int LERCPreDecode(TIFF *tif, uint16_t s)
Decode and validate an entire LERC strile into owned staging.
#define LERCDecoderState(tif)
Alias of GetLERCState(), returning the LERCState for decoding.
static int LERCSetupDecode(TIFF *tif)
Select LERC decode mode.
#define GetLERCState(tif)
Cast tif->tif_data to the LERCState.
#define LERC_AT_LEAST_VERSION(maj, min, patch)
Fallback used when the LERC header lacks LERC_AT_LEAST_VERSION.
#define LERCEncoderState(tif)
Alias of GetLERCState(), returning the LERCState for encoding.
static int LERCEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Stage the next LERC input bytes for later frame encoding.
static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Copy the next decoded byte extent from LERC staging.
static const TIFFField LERCFields[]
Define LERC parameters error tolerance version and secondary-compression tags.
#define LSTATE_INIT_ENCODE
Bit 0x02 of the codec state field: encoding has been set up.
static int LERCVSetField(TIFF *tif, uint32_t tag, va_list ap)
Set LERC version error tolerance or secondary-compression controls.
#define LSTATE_INIT_DECODE
Bit 0x01 of the codec state field: decoding has been set up.
static int LERCPreEncode(TIFF *tif, uint16_t s)
Validate LERC sample type and prepare full-strile input storage.
static void LERCCleanup(TIFF *tif)
Release LERC staging masks secondary compressors and outer state.
static int LERCVSetFieldBase(TIFF *tif, uint32_t tag,...)
Forward a variadic assignment directly to the saved parent setter.
static int LERCFixupTags(TIFF *tif)
Accept LERC tag fixup without changes.
static int LERCVGetField(TIFF *tif, uint32_t tag, va_list ap)
Retrieve cached LERC controls or delegate another tag query.
#define LIBDEFLATE_MAX_COMPRESSION_LEVEL
Highest accepted TIFFTAG_ZIPQUALITY value: 12.
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 * _TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz)
Allocate a zero-filled array under a handle's allocation policy.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define TRUE
Represent the legacy internal true value.
#define FALSE
Represent the legacy internal false value.
#define TIFFArrayCount(a)
Compute the element count of an actual array.
#define FIELD_CUSTOM
Identify a field stored through the custom-metadata mechanism.
#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.
int(* TIFFVGetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag getter.
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Set a tag value in the current in-memory directory.
int(* TIFFVSetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag setter.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
@ TIFF_LONG
Unsigned 32-bit integer.
Own LERC full-strile staging masks and secondary-compression state.
TIFFVSetMethod vsetparent
Borrowed parent tag setter restored during cleanup.
void * compressed_buffer
Owned Ext LERC blob or secondary-decompressed staging.
uint32_t segment_width
Current strile width in pixels.
int state
Encode/decode mode flags.
unsigned int uncompressed_buffer_multiband_alloc
Multiband staging capacity in bytes.
unsigned int mask_size
Validity-mask allocation capacity in bytes.
uint8_t * uncompressed_buffer
Owned Ext row-interleaved staging reused as secondary-compression output.
unsigned int uncompressed_offset
Next staged input/output byte offset.
int zstd_compress_level
Cached ZSTD level, including warned values.
int additional_compression
Secondary none/Deflate/ZSTD selection.
int zipquality
Cached Deflate quality, including rejected attempted assignments.
uint8_t * mask_buffer
Owned Ext pixel or per-band validity masks.
uint32_t segment_height
Current tile or truncated-strip height in rows.
int lerc_version
Cached encoded LERC version.
TIFFVGetMethod vgetparent
Borrowed parent tag getter restored during cleanup.
unsigned int compressed_size
Compressed/intermediate allocation capacity in bytes.
unsigned int uncompressed_size
Logical current-strile decoded extent in bytes.
double maxzerror
Cached maximum encoding error, zero for default lossless operation.
uint8_t * uncompressed_buffer_multiband
Owned Ext planar multiband staging for per-band masks.
unsigned int uncompressed_alloc
Allocated main staging capacity in bytes, including compression margin.
Store the current directory values and image traversal state.
uint16_t * td_sampleinfo
Owned ExtraSamples interpretation array of td_extrasamples entries, or NULL.
uint32_t td_rowsperstrip
Rows per strip; UINT32_MAX represents one whole-image strip.
uint32_t td_imagewidth
Image width in pixels.
uint32_t td_tilewidth
Tile width in pixels.
uint16_t td_extrasamples
Number of extra samples described by td_sampleinfo.
uint16_t td_bitspersample
Bits in each sample.
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_imagelength
Image length in rows.
uint32_t td_tilelength
Tile length in rows.
TIFFVGetMethod vgetfield
Variadic tag-query implementation for the handle.
TIFFVSetMethod vsetfield
Variadic tag-setting implementation for the handle.
Describe a field's file type and internal argument contract.
Hold private state for one open TIFF library instance.
TIFFCodeMethod tif_encodestrip
Codec callback encoding strip data.
TIFFCodeMethod tif_encodetile
Codec callback encoding tile data.
TIFFTagMethods tif_tagmethods
Inline table of directory field and print callbacks.
TIFFPreMethod tif_preencode
Codec callback preparing a row, strip, or tile encode.
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
TIFFPreMethod tif_predecode
Codec callback preparing a row, strip, or tile decode.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFCodeMethod tif_decoderow
Codec callback decoding a scanline.
TIFFBoolMethod tif_setupencode
Codec setup callback run before preencode.
TIFFDirectory tif_dir
Inline representation of the current image directory.
TIFFBoolMethod tif_postencode
Codec callback completing buffered encoding.
TIFFCodeMethod tif_encoderow
Codec callback encoding a scanline.
TIFFVoidMethod tif_cleanup
Codec callback releasing codec-private state.
uint8_t * tif_data
Codec-private storage; allocation and cleanup follow the selected codec.
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
uint8_t * tif_rawdata
Raw buffer; ownership/mapping follow TIFF_MYBUFFER and TIFF_BUFFERMMAP.
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
TIFFCodeMethod tif_decodetile
Codec callback decoding tile data.
Declare private library state, callbacks, and implementation helpers.