66 "Multistrip images not supported in decoder");
100 struct jbg_dec_state decoder;
101 int decodeStatus = 0;
102 unsigned char *pImage = NULL;
103 unsigned long decodedSizeUL;
104 uint64_t decodedSize64;
113 jbg_dec_init(&decoder);
115#if defined(HAVE_JBG_NEWLEN)
129 decodeStatus = jbg_dec_in(&decoder, (
unsigned char *)tif->
tif_rawcp,
131 if (JBG_EOK != decodeStatus)
138 TIFFErrorExtR(tif,
"JBIG",
"Error (%d) decoding: %s", decodeStatus,
140 jbg_strerror(decodeStatus, JBG_EN)
142 jbg_strerror(decodeStatus)
146 memset(buffer, 0, (
size_t)size);
147 jbg_dec_free(&decoder);
159 decodedSizeUL = jbg_dec_getsize(&decoder);
160 decodedSize64 = decodedSizeUL;
164 "Decoded %lu bytes, which exceeds the maximum supported "
168 memset(buffer, 0, (
size_t)size);
169 jbg_dec_free(&decoder);
172 decodedSize = (
tmsize_t)decodedSizeUL;
173 if (decodedSize > size)
178 decodedSizeUL, size);
180 memset(buffer, 0, (
size_t)size);
181 jbg_dec_free(&decoder);
184 if (decodedSize < size)
186 memset(buffer + decodedSize, 0, (
size_t)(size - decodedSize));
190 decodedSizeUL, size);
194 pImage = jbg_dec_getimage(&decoder, 0);
197 TIFFErrorExtR(tif,
"JBIG",
"JBIG decoder returned no image data");
199 memset(buffer, 0, (
size_t)size);
200 jbg_dec_free(&decoder);
205 jbg_dec_free(&decoder);
228 "Multistrip images not supported in encoder");
336 static const char module[] = "JBIG";
338 struct jbg_enc_state encoder;
345 if (dir->td_bitspersample != 1 || dir->td_samplesperpixel != 1)
348 "JBIG encoder supports only single-sample 1-bit image "
356 "Multistrip images not supported in encoder");
361 required64 =
_TIFFMultiply64(tif, rowbytes64, dir->td_imagelength, module);
368 "Application buffer too small for JBIG source image "
375 jbg_enc_init(&encoder, dir->td_imagewidth, dir->td_imagelength, 1, &buffer,
381 jbg_enc_out(&encoder);
382 jbg_enc_free(&encoder);
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Multiply two unsigned values with an overflow check.
#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.
static int JBIGSetupDecode(TIFF *tif)
Require one strip for JBIG decoding.
static void JBIGOutputBie(unsigned char *buffer, size_t len, void *userData)
Reverse and forward a dependency-produced JBIG output fragment.
int TIFFInitJBIG(TIFF *tif, int scheme)
Install single-strip JBIG callbacks and mutable raw-input policy.
static int JBIGDecode(TIFF *tif, uint8_t *buffer, tmsize_t size, uint16_t s)
Decode one complete JBIG plane into caller storage.
static int JBIGCopyEncodedData(TIFF *tif, unsigned char *pp, size_t cc, uint16_t s)
Copy JBIG output fragments into the buffered raw stream.
static int JBIGSetupEncode(TIFF *tif)
Require one strip for JBIG encoding.
static int JBIGEncode(TIFF *tif, uint8_t *buffer, tmsize_t size, uint16_t s)
Encode a complete single-sample one-bit JBIG image plane.
#define TIFF_MYBUFFER
Mark a raw buffer owned and released by the handle.
#define isFillOrder(tif, o)
Test whether selected bit-fill-order bits are present in a handle.
#define TIFF_NOBITREV
Suppress automatic bit reversal.
#define TIFF_BUFFERMMAP
Mark raw data that borrows mapped-file storage.
#define TIFFhowmany8_64(x)
Compute the byte count needed to hold a 64-bit bit count.
void TIFFReverseBits(uint8_t *cp, tmsize_t n)
Reverse the bit order within each byte of a buffer.
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.
uint32_t TIFFNumberOfStrips(TIFF *tif)
Compute the strip count from current image geometry.
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.
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
Store the current directory values and image traversal state.
uint16_t td_fillorder
FILLORDER_* bit order within file bytes.
Hold private state for one open TIFF library instance.
TIFFCodeMethod tif_encodestrip
Codec callback encoding strip data.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFBoolMethod tif_setupencode
Codec setup callback run before preencode.
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.
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...
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
Declare private library state, callbacks, and implementation helpers.