50 lzma_filter filters[LZMA_FILTERS_MAX + 1];
51 lzma_options_delta opt_delta;
52 lzma_options_lzma opt_lzma;
56#define LSTATE_INIT_DECODE 0x01
57#define LSTATE_INIT_ENCODE 0x02
63#define GetLZMAState(tif) ((LZMAState *)(tif)->tif_data)
64#define LZMADecoderState(tif) GetLZMAState(tif)
65#define LZMAEncoderState(tif) GetLZMAState(tif)
70static const char *LZMAStrerror(lzma_ret
ret)
75 return "operation completed successfully";
77 return "end of stream was reached";
79 return "input stream has no integrity check";
80 case LZMA_UNSUPPORTED_CHECK:
81 return "cannot calculate the integrity check";
83 return "integrity check type is now available";
85 return "cannot allocate memory";
86 case LZMA_MEMLIMIT_ERROR:
87 return "memory usage limit was reached";
88 case LZMA_FORMAT_ERROR:
89 return "file format not recognized";
90 case LZMA_OPTIONS_ERROR:
91 return "invalid or unsupported options";
93 return "data is corrupt";
95 return "no progress is possible (stream is truncated or corrupt)";
97 return "programming error";
99 return "unidentified liblzma error";
103static int LZMAFixupTags(
TIFF *tif)
109static int LZMASetupDecode(
TIFF *tif)
111 LZMAState *
sp = LZMADecoderState(tif);
116 if (
sp->state & LSTATE_INIT_ENCODE)
118 lzma_end(&
sp->stream);
122 sp->state |= LSTATE_INIT_DECODE;
131 static const char module[] =
"LZMAPreDecode";
132 LZMAState *
sp = LZMADecoderState(tif);
138 if ((
sp->state & LSTATE_INIT_DECODE) == 0)
146 "Liblzma cannot deal with buffers this size");
169 static const char module[] =
"LZMADecode";
170 LZMAState *
sp = LZMADecoderState(tif);
174 assert(
sp->state == LSTATE_INIT_DECODE);
180 "LZMADecode: Scanline %" PRIu32 " cannot be read due to "
189 sp->stream.next_out =
op;
190 sp->stream.avail_out = (
size_t)occ;
197 "Liblzma cannot deal with buffers this size");
207 const uint8_t *next_in =
sp->stream.next_in;
208 size_t avail_in =
sp->stream.avail_in;
210 lzma_ret
ret = lzma_code(&
sp->stream, LZMA_RUN);
211 if (
ret == LZMA_STREAM_END)
213 if (
ret == LZMA_MEMLIMIT_ERROR)
216 lzma_stream_decoder(&
sp->stream, lzma_memusage(&
sp->stream), 0);
222 "Error initializing the stream decoder, %s",
226 sp->stream.next_in = next_in;
227 sp->stream.avail_in = avail_in;
233 "Decoding error at scanline %" PRIu32 ", %s",
237 }
while (
sp->stream.avail_out > 0);
238 if (
sp->stream.avail_out != 0)
241 memset(
sp->stream.next_out, 0,
sp->stream.avail_out);
243 "Not enough data at scanline %" PRIu32
255static int LZMASetupEncode(
TIFF *tif)
257 LZMAState *
sp = LZMAEncoderState(tif);
260 if (
sp->state & LSTATE_INIT_DECODE)
262 lzma_end(&
sp->stream);
266 sp->state |= LSTATE_INIT_ENCODE;
275 static const char module[] =
"LZMAPreEncode";
276 LZMAState *
sp = LZMAEncoderState(tif);
281 if (
sp->state != LSTATE_INIT_ENCODE)
289 "Liblzma cannot deal with buffers this size");
292 ret = lzma_stream_encoder(&
sp->stream,
sp->filters,
sp->check);
307 static const char module[] =
"LZMAEncode";
308 LZMAState *
sp = LZMAEncoderState(tif);
311 assert(
sp->state == LSTATE_INIT_ENCODE);
314 sp->stream.next_in = bp;
319 "Liblzma cannot deal with buffers this size");
324 lzma_ret
ret = lzma_code(&
sp->stream, LZMA_RUN);
328 "Encoding error at scanline %" PRIu32 ", %s",
332 if (
sp->stream.avail_out == 0)
338 sp->stream.avail_out =
343 }
while (
sp->stream.avail_in > 0);
351static int LZMAPostEncode(
TIFF *tif)
353 static const char module[] =
"LZMAPostEncode";
354 LZMAState *
sp = LZMAEncoderState(tif);
357 sp->stream.avail_in = 0;
360 ret = lzma_code(&
sp->stream, LZMA_FINISH);
363 case LZMA_STREAM_END:
372 sp->stream.avail_out =
384 }
while (
ret != LZMA_STREAM_END);
388static void LZMACleanup(
TIFF *tif)
390 LZMAState *
sp = GetLZMAState(tif);
401 lzma_end(&
sp->stream);
412 static const char module[] =
"LZMAVSetField";
413 LZMAState *
sp = GetLZMAState(tif);
419 lzma_lzma_preset(&
sp->opt_lzma,
sp->preset);
420 if (
sp->state & LSTATE_INIT_ENCODE)
423 lzma_stream_encoder(&
sp->stream,
sp->filters,
sp->check);
432 return (*
sp->vsetparent)(tif,
tag,
ap);
439 LZMAState *
sp = GetLZMAState(tif);
447 return (*
sp->vgetparent)(tif,
tag,
ap);
454 FALSE,
"LZMA2 Compression Preset",
NULL},
459 static const char module[] =
"TIFFInitLZMA";
461 lzma_stream tmp_stream = LZMA_STREAM_INIT;
481 sp = GetLZMAState(tif);
482 memcpy(&
sp->stream, &tmp_stream,
sizeof(lzma_stream));
493 sp->preset = LZMA_PRESET_DEFAULT;
494 sp->check = LZMA_CHECK_NONE;
498 sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE;
506 sp->filters[0].id = LZMA_FILTER_DELTA;
507 sp->filters[0].options = &
sp->opt_delta;
509 lzma_lzma_preset(&
sp->opt_lzma,
sp->preset);
510 sp->filters[1].id = LZMA_FILTER_LZMA2;
511 sp->filters[1].options = &
sp->opt_lzma;
513 sp->filters[2].id = LZMA_VLI_UNKNOWN;
514 sp->filters[2].options =
NULL;
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
#define check(expected, result)
GLdouble GLdouble GLdouble r
#define memcpy(s1, s2, n)
uint16_t td_bitspersample
TIFFCodeMethod tif_encodestrip
TIFFCodeMethod tif_encodetile
TIFFTagMethods tif_tagmethods
TIFFPreMethod tif_preencode
TIFFBoolMethod tif_fixuptags
TIFFPreMethod tif_predecode
TIFFCodeMethod tif_decodestrip
TIFFCodeMethod tif_decoderow
TIFFBoolMethod tif_setupencode
TIFFBoolMethod tif_postencode
TIFFCodeMethod tif_encoderow
TIFFVoidMethod tif_cleanup
TIFFBoolMethod tif_setupdecode
TIFFCodeMethod tif_decodetile
void _TIFFSetDefaultCompressionState(TIFF *tif)
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
void _TIFFfreeExt(TIFF *tif, void *p)
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
int TIFFPredictorCleanup(TIFF *tif)
int TIFFPredictorInit(TIFF *tif)
int TIFFFlushData1(TIFF *tif)
#define TIFFTAG_LZMAPRESET
int(* TIFFVSetMethod)(TIFF *, uint32_t, va_list)
int(* TIFFVGetMethod)(TIFF *, uint32_t, va_list)
#define TIFFArrayCount(a)
void int int ULONGLONG int va_list * ap