32#ifdef PACKBITS_SUPPORT
40#ifndef PACKBITS_READ_ONLY
124 static const char module[] = "PackBitsEncode";
125 unsigned char *bp = (
unsigned char *)buf;
128 uint8_t *lastliteral;
157 for (; cc > 0 && b == *bp; cc--, bp++)
168 if (state == LITERAL || state == LITERAL_RUN)
170 slop = (long)(op - lastliteral);
176 *op++ = *lastliteral++;
196 (state == LITERAL && n == 1) ? 1 : (state == LITERAL_RUN ? 0 : 2);
203 " bytes is too small for PackBits encoding",
215 *op++ = (uint8_t)-127;
220 *op++ = (uint8_t)(-(n - 1));
237 *op++ = (uint8_t)-127;
242 *op++ = (uint8_t)(-(n - 1));
247 if (++(*lastliteral) == 127)
257 *op++ = (uint8_t)-127;
262 *op++ = (uint8_t)(-(n - 1));
280 if (n == 1 && op[-2] == (uint8_t)-1 && *lastliteral < 126)
283 (((*lastliteral) = (uint8_t)(*lastliteral + 2)) == 127
372 static const char module[] = "PackBitsDecode";
379 while (in.left > 0 && out.
left > 0)
392 " bytes to avoid buffer overrun",
400 "Terminating PackBitsDecode due to lack of data.");
412 " bytes to avoid buffer overrun",
414 n = (long)out.
left - 1;
420 "Terminating PackBitsDecode due to lack of data.");
431 memset(out.
p, 0, (
size_t)out.
left);
432 TIFFErrorExtR(tif, module,
"Not enough data for scanline %" PRIu32,
465#ifndef PACKBITS_READ_ONLY
int TIFFInitPackBits(TIFF *tif, int scheme)
Install PackBits transfer callbacks.
static int _TIFFByteCursorFill(TIFFByteCursor *dst, uint8_t value, tmsize_t n)
Write n copies of value to a cursor.
static int _TIFFByteCursorCopy(TIFFByteCursor *dst, TIFFByteCursor *src, tmsize_t n)
Move n bytes from src to dst.
static uint64_t PackBitsGetMaxCompressionRatio(TIFF *tif)
Report the PackBits expansion heuristic.
static int PackBitsPostEncode(TIFF *tif)
Release the PackBits cached row-size allocation.
static int PackBitsEncode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Encode one byte run region using PackBits packets.
static int PackBitsEncodeChunk(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Split PackBits input into row-bounded encoding requests.
static int PackBitsDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Expand PackBits packets into a bounded byte destination.
static int PackBitsPreEncode(TIFF *tif, uint16_t s)
Allocate and cache the PackBits row byte extent.
static int _TIFFByteCursorGetU8(TIFFByteCursor *c, uint8_t *out)
Read one byte from a cursor.
#define TIFF_SSIZE_FORMAT
Provide the printf conversion fragment for tmsize_t, without a percent sign.
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.
#define isTiled(tif)
Test whether a handle uses tiled storage.
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.
tmsize_t TIFFScanlineSize(TIFF *tif)
Compute the current scanline I/O byte estimate.
tmsize_t TIFFTileRowSize(TIFF *tif)
Compute the packed byte count of one tile row.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Track a borrowed byte range as a pointer and a remaining count.
tmsize_t left
Number of bytes remaining from p.
uint8_t * p
Next byte to read or write.
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
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.
TIFFPreMethod tif_preencode
Codec callback preparing a row, strip, or tile encode.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFGetMaxCompressionRatioMethod tif_getmaxcompressionratio
Codec callback returning its maximum compression ratio.
TIFFCodeMethod tif_decoderow
Codec callback decoding a scanline.
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.
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.
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.
Define small bounds-checked byte cursors for codec decoders.
Declare private library state, callbacks, and implementation helpers.