54#define SETPIXEL(op, v) \
56 switch (npixels++ & 3) \
59 op[0] = (unsigned char)((v) << 6); \
62 op[0] |= (unsigned char)((v) << 4); \
65 op[0] |= (unsigned char)((v) << 2); \
68 *op++ |= (unsigned char)(v); \
81#define LITERALROW 0x00
89#define LITERALSPAN 0x40
115 static const char module[] = "NeXTDecode";
116 unsigned char *bp, *op;
127 for (op = (
unsigned char *)buf, cc = occ; cc-- > 0;)
135 TIFFErrorExtR(tif, module,
"Fractional scanlines cannot be read");
138 for (row = buf; cc > 0 && occ > 0; occ -= scanline, row += scanline)
163 off = (bp[0] * 256) + bp[1];
164 n = (bp[2] * 256) + bp[3];
165 if (cc < 4 + n || off + n > scanline)
174 uint32_t npixels = 0, grey;
189 grey = (uint32_t)((n >> 6) & 0x3);
196 while (n-- > 0 && npixels < imagewidth &&
197 op_offset < scanline)
199 if (npixels >= imagewidth)
201 if (op_offset >= scanline)
204 "Invalid data for scanline %" PRIu32,
221 TIFFErrorExtR(tif, module,
"Not enough data for scanline %" PRIu32,
241 static const char module[] = "NeXTPreDecode";
245 if (td->td_bitspersample != 2)
247 TIFFErrorExtR(tif, module,
"Unsupported BitsPerSample = %" PRIu16,
248 td->td_bitspersample);
251 if (td->td_samplesperpixel != 1 &&
255 "Samples/pixel shall be 1 for NeXT decoding, "
256 "or PlanarConfiguration must be set to Separate.");
static int NeXTDecode(TIFF *tif, uint8_t *buf, tmsize_t occ, uint16_t s)
Expand NeXT literal rows spans and grayscale runs.
#define LITERALROW
NeXT row opcode: the scanline follows as td_scanlinesize literal bytes.
int TIFFInitNeXT(TIFF *tif, int scheme)
Install NeXT transfer callbacks.
#define LITERALSPAN
NeXT row opcode: a 16-bit big-endian offset and length precede a literal byte span within the white s...
#define SETPIXEL(op, v)
Store a 2-bit pixel into the packed output byte at op.
static int NeXTPreDecode(TIFF *tif, uint16_t s)
Validate two-bit single-plane NeXT decoding.
#define isTiled(tif)
Test whether a handle uses tiled storage.
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.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Store the current directory values and image traversal state.
uint32_t td_imagewidth
Image width in pixels.
uint32_t td_tilewidth
Tile width in pixels.
tmsize_t td_scanlinesize
Cached decoded scanline size in bytes; zero when not computed.
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
Hold private state for one open TIFF library instance.
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.
TIFFDirectory tif_dir
Inline representation of the current image directory.
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
TIFFCodeMethod tif_decodetile
Codec callback decoding tile data.
Declare private library state, callbacks, and implementation helpers.