57#define THUNDER_CODE 0xc0
65#define THUNDER_RUN 0x00
72#define THUNDER_2BITDELTAS 0x40
84#define THUNDER_3BITDELTAS 0x80
96#define THUNDER_RAW 0xc0
131#define SETPIXEL(op, v) \
133 lastpixel = (v) & 0xf; \
134 if (npixels < maxpixels) \
137 *op++ |= (uint8_t)lastpixel; \
139 op[0] = (uint8_t)(lastpixel << 4); \
157 static const char module[] = "ThunderSetupDecode";
162 "Wrong bitspersample value (%d), Thunder decoder only "
163 "supports 4bits per sample.",
171 "Samples/pixel shall be 1 for ThunderScan decoding, "
172 "or PlanarConfiguration must be set to Separate.");
200 static const char module[] = "ThunderDecode";
203 unsigned int lastpixel;
211 while (cc > 0 && npixels < maxpixels)
228 op[0] |= (uint8_t)lastpixel;
234 lastpixel |= lastpixel << 4;
236 if (npixels > maxpixels)
238 for (; n > 0; n -= 2)
239 *op++ = (uint8_t)lastpixel;
272 if (npixels != maxpixels)
274 uint8_t *op_end = op0 + (maxpixels + 1) / 2;
275 memset(op, 0, (
size_t)(op_end - op));
277 "%s data at scanline %lu (%" PRIu64
" != %" PRIu64
")",
278 npixels < maxpixels ?
"Not enough" :
"Too much",
280 (uint64_t)maxpixels);
307 static const char module[] = "ThunderDecodeRow";
313 TIFFErrorExtR(tif, module,
"Fractional scanlines cannot be read");
326 memset(row, 0, (
size_t)occ);
int TIFFInitThunderScan(TIFF *tif, int scheme)
Install ThunderScan transfer callbacks.
static int ThunderDecodeRow(TIFF *tif, uint8_t *buf, tmsize_t occ, uint16_t s)
Decode complete ThunderScan scanlines into caller storage.
#define THUNDER_2BITDELTAS
ThunderScan code word for three packed 2-bit pixel deltas.
static int ThunderSetupDecode(TIFF *tif)
Validate four-bit single-plane ThunderScan decoding.
#define THUNDER_CODE
Mask selecting the 2-bit code word in the top bits of a ThunderScan byte.
static int ThunderDecode(TIFF *tif, uint8_t *op0, tmsize_t maxpixels)
Expand one ThunderScan row into packed four-bit samples.
#define DELTA3_SKIP
3-bit delta value meaning "no pixel" in a THUNDER_3BITDELTAS byte.
#define THUNDER_3BITDELTAS
ThunderScan code word for two packed 3-bit pixel deltas.
#define THUNDER_RAW
ThunderScan code word for a literal 4-bit pixel.
#define DELTA2_SKIP
2-bit delta value meaning "no pixel" in a THUNDER_2BITDELTAS byte.
#define SETPIXEL(op, v)
Store a 4-bit pixel into the packed output if maxpixels has not been reached.
#define THUNDER_RUN
ThunderScan code word for a run of the previous pixel.
static const int twobitdeltas[4]
Map two-bit delta codes to signed pixel increments.
static const int threebitdeltas[8]
Map three-bit delta codes to signed pixel increments.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
uint32_t td_imagewidth
Image width in pixels.
tmsize_t td_scanlinesize
Cached decoded scanline size in bytes; zero when not computed.
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_samplesperpixel
Samples per pixel, including extra samples.
Hold private state for one open TIFF library instance.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
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.
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
Declare private library state, callbacks, and implementation helpers.