48 lzma_filter filters[LZMA_FILTERS_MAX + 1];
49 lzma_options_delta opt_delta;
50 lzma_options_lzma opt_lzma;
54#define LSTATE_INIT_DECODE 0x01
55#define LSTATE_INIT_ENCODE 0x02
61#define LState(tif) ((LZMAState*) (tif)->tif_data)
62#define DecoderState(tif) LState(tif)
63#define EncoderState(tif) LState(tif)
69LZMAStrerror(lzma_ret
ret)
73 return "operation completed successfully";
75 return "end of stream was reached";
77 return "input stream has no integrity check";
78 case LZMA_UNSUPPORTED_CHECK:
79 return "cannot calculate the integrity check";
81 return "integrity check type is now available";
83 return "cannot allocate memory";
84 case LZMA_MEMLIMIT_ERROR:
85 return "memory usage limit was reached";
86 case LZMA_FORMAT_ERROR:
87 return "file format not recognized";
88 case LZMA_OPTIONS_ERROR:
89 return "invalid or unsupported options";
91 return "data is corrupt";
93 return "no progress is possible (stream is truncated or corrupt)";
95 return "programming error";
97 return "unidentified liblzma error";
102LZMAFixupTags(
TIFF* tif)
109LZMASetupDecode(
TIFF* tif)
111 LZMAState*
sp = DecoderState(tif);
116 if (
sp->state & LSTATE_INIT_ENCODE) {
117 lzma_end(&
sp->stream);
121 sp->state |= LSTATE_INIT_DECODE;
131 static const char module[] =
"LZMAPreDecode";
132 LZMAState*
sp = DecoderState(tif);
138 if( (
sp->state & LSTATE_INIT_DECODE) == 0 )
145 "Liblzma cannot deal with buffers this size");
154 if (
ret != LZMA_OK) {
156 "Error initializing the stream decoder, %s",
166 static const char module[] =
"LZMADecode";
167 LZMAState*
sp = DecoderState(tif);
171 assert(
sp->state == LSTATE_INIT_DECODE);
176 sp->stream.next_out =
op;
177 sp->stream.avail_out = (
size_t) occ;
180 "Liblzma cannot deal with buffers this size");
189 const uint8_t *next_in =
sp->stream.next_in;
190 size_t avail_in =
sp->stream.avail_in;
192 lzma_ret
ret = lzma_code(&
sp->stream, LZMA_RUN);
193 if (
ret == LZMA_STREAM_END)
195 if (
ret == LZMA_MEMLIMIT_ERROR) {
196 lzma_ret
r = lzma_stream_decoder(&
sp->stream,
197 lzma_memusage(&
sp->stream), 0);
200 "Error initializing the stream decoder, %s",
204 sp->stream.next_in = next_in;
205 sp->stream.avail_in = avail_in;
208 if (
ret != LZMA_OK) {
210 "Decoding error at scanline %lu, %s",
211 (
unsigned long) tif->
tif_row, LZMAStrerror(
ret));
214 }
while (
sp->stream.avail_out > 0);
215 if (
sp->stream.avail_out != 0) {
217 "Not enough data at scanline %lu (short %lu bytes)",
218 (
unsigned long) tif->
tif_row, (
unsigned long)
sp->stream.avail_out);
229LZMASetupEncode(
TIFF* tif)
231 LZMAState*
sp = EncoderState(tif);
234 if (
sp->state & LSTATE_INIT_DECODE) {
235 lzma_end(&
sp->stream);
239 sp->state |= LSTATE_INIT_ENCODE;
249 static const char module[] =
"LZMAPreEncode";
250 LZMAState *
sp = EncoderState(tif);
255 if(
sp->state != LSTATE_INIT_ENCODE )
262 "Liblzma cannot deal with buffers this size");
265 ret = lzma_stream_encoder(&
sp->stream,
sp->filters,
sp->check);
266 if (
ret != LZMA_OK) {
268 "Error in lzma_stream_encoder(): %s", LZMAStrerror(
ret));
280 static const char module[] =
"LZMAEncode";
281 LZMAState *
sp = EncoderState(tif);
284 assert(
sp->state == LSTATE_INIT_ENCODE);
287 sp->stream.next_in = bp;
291 "Liblzma cannot deal with buffers this size");
295 lzma_ret
ret = lzma_code(&
sp->stream, LZMA_RUN);
296 if (
ret != LZMA_OK) {
298 "Encoding error at scanline %lu, %s",
299 (
unsigned long) tif->
tif_row, LZMAStrerror(
ret));
302 if (
sp->stream.avail_out == 0) {
308 }
while (
sp->stream.avail_in > 0);
317LZMAPostEncode(
TIFF* tif)
319 static const char module[] =
"LZMAPostEncode";
320 LZMAState *
sp = EncoderState(tif);
323 sp->stream.avail_in = 0;
325 ret = lzma_code(&
sp->stream, LZMA_FINISH);
327 case LZMA_STREAM_END:
342 }
while (
ret != LZMA_STREAM_END);
347LZMACleanup(
TIFF* tif)
349 LZMAState*
sp = LState(tif);
359 lzma_end(&
sp->stream);
371 static const char module[] =
"LZMAVSetField";
372 LZMAState*
sp = LState(tif);
377 lzma_lzma_preset(&
sp->opt_lzma,
sp->preset);
378 if (
sp->state & LSTATE_INIT_ENCODE) {
379 lzma_ret
ret = lzma_stream_encoder(&
sp->stream,
382 if (
ret != LZMA_OK) {
390 return (*
sp->vsetparent)(tif,
tag,
ap);
398 LZMAState*
sp = LState(tif);
405 return (*
sp->vgetparent)(tif,
tag,
ap);
418 static const char module[] =
"TIFFInitLZMA";
420 lzma_stream tmp_stream = LZMA_STREAM_INIT;
429 "Merging LZMA2 codec-specific tags failed");
440 memcpy(&
sp->stream, &tmp_stream,
sizeof(lzma_stream));
451 sp->preset = LZMA_PRESET_DEFAULT;
452 sp->check = LZMA_CHECK_NONE;
456 sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE;
463 sp->filters[0].id = LZMA_FILTER_DELTA;
464 sp->filters[0].options = &
sp->opt_delta;
466 lzma_lzma_preset(&
sp->opt_lzma,
sp->preset);
467 sp->filters[1].id = LZMA_FILTER_LZMA2;
468 sp->filters[1].options = &
sp->opt_lzma;
470 sp->filters[2].id = LZMA_VLI_UNKNOWN;
471 sp->filters[2].options =
NULL;
496 "No space for LZMA2 state block");
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
#define check(expected, result)
GLdouble GLdouble GLdouble r
#define memcpy(s1, s2, n)
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 n)
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
int TIFFPredictorCleanup(TIFF *tif)
int TIFFPredictorInit(TIFF *tif)
void * _TIFFmalloc(tmsize_t s)
int TIFFFlushData1(TIFF *tif)
#define TIFFTAG_LZMAPRESET
int(* TIFFVGetMethod)(TIFF *, uint32, va_list)
int(* TIFFVSetMethod)(TIFF *, uint32, va_list)
#define TIFFArrayCount(a)
void int int ULONGLONG int va_list * ap