LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_lzma.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, Andrey Kiselev <dron@ak4719.spb.edu>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the names of
8 * Sam Leffler and Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Sam Leffler and Silicon Graphics.
11 *
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
17 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
18 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
20 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
29#include "tiffiop.h"
30#ifdef LZMA_SUPPORT
31/*
32 * TIFF Library.
33 *
34 * LZMA2 Compression Support
35 *
36 * You need an LZMA2 SDK to link with. See http://tukaani.org/xz/ for details.
37 *
38 * The codec is derived from ZLIB codec (tif_zip.c).
39 */
40
41#include "lzma.h"
42#include "tif_predict.h"
43
44#include <stdio.h>
45
46/*
47 * State block for each open TIFF file using LZMA2 compression/decompression.
48 */
57typedef struct
58{
66 lzma_stream stream;
71 lzma_filter filters[LZMA_FILTERS_MAX + 1];
73 lzma_options_delta opt_delta;
75 lzma_options_lzma opt_lzma;
80 int preset;
82 lzma_check check;
84 int state;
85#define LSTATE_INIT_DECODE 0x01
86#define LSTATE_INIT_ENCODE 0x02
87
92} LZMAState;
93
94#define GetLZMAState(tif) ((LZMAState *)(tif)->tif_data)
95#define LZMADecoderState(tif) GetLZMAState(tif)
96#define LZMAEncoderState(tif) GetLZMAState(tif)
97
98static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
99static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
100
112static const char *LZMAStrerror(lzma_ret ret)
113{
114 switch (ret)
115 {
116 case LZMA_OK:
117 return "operation completed successfully";
118 case LZMA_STREAM_END:
119 return "end of stream was reached";
120 case LZMA_NO_CHECK:
121 return "input stream has no integrity check";
122 case LZMA_UNSUPPORTED_CHECK:
123 return "cannot calculate the integrity check";
124 case LZMA_GET_CHECK:
125 return "integrity check type is now available";
126 case LZMA_MEM_ERROR:
127 return "cannot allocate memory";
128 case LZMA_MEMLIMIT_ERROR:
129 return "memory usage limit was reached";
130 case LZMA_FORMAT_ERROR:
131 return "file format not recognized";
132 case LZMA_OPTIONS_ERROR:
133 return "invalid or unsupported options";
134 case LZMA_DATA_ERROR:
135 return "data is corrupt";
136 case LZMA_BUF_ERROR:
137 return "no progress is possible (stream is truncated or corrupt)";
138 case LZMA_PROG_ERROR:
139 return "programming error";
140#if LZMA_VERSION >= 50040000 /* 5.4.0 */
141 case LZMA_SEEK_NEEDED:
142 case LZMA_RET_INTERNAL1:
143 case LZMA_RET_INTERNAL2:
144 case LZMA_RET_INTERNAL3:
145 case LZMA_RET_INTERNAL4:
146 case LZMA_RET_INTERNAL5:
147 case LZMA_RET_INTERNAL6:
148 case LZMA_RET_INTERNAL7:
149 case LZMA_RET_INTERNAL8:
150#endif
151 default:
152 return "unidentified liblzma error";
153 }
154}
155
165static int LZMAFixupTags(TIFF *tif)
166{
167 (void)tif;
168 return 1;
169}
170
183static int LZMASetupDecode(TIFF *tif)
184{
185 LZMAState *sp = LZMADecoderState(tif);
186
187 assert(sp != NULL);
188
189 /* if we were last encoding, terminate this mode */
190 if (sp->state & LSTATE_INIT_ENCODE)
191 {
192 lzma_end(&sp->stream);
193 sp->state = 0;
194 }
195
197 return 1;
198}
199
200/*
201 * Setup state for decoding a strip.
202 */
219static int LZMAPreDecode(TIFF *tif, uint16_t s)
220{
221 static const char module[] = "LZMAPreDecode";
222 LZMAState *sp = LZMADecoderState(tif);
223 lzma_ret ret;
224
225 (void)s;
226 assert(sp != NULL);
227
228 if ((sp->state & LSTATE_INIT_DECODE) == 0)
229 tif->tif_setupdecode(tif);
230
231 sp->stream.next_in = tif->tif_rawdata;
232 sp->stream.avail_in = (size_t)tif->tif_rawcc;
233 if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc)
234 {
235 TIFFErrorExtR(tif, module,
236 "Liblzma cannot deal with buffers this size");
237 return 0;
238 }
239
240 /*
241 * Disable memory limit when decoding. UINT64_MAX is a flag to disable
242 * the limit, we are passing (uint64_t)-1 which should be the same.
243 */
244 ret = lzma_stream_decoder(&sp->stream, (uint64_t)-1, 0);
245 if (ret != LZMA_OK)
246 {
247 TIFFErrorExtR(tif, module, "Error initializing the stream decoder, %s",
248 LZMAStrerror(ret));
249 return 0;
250 }
251
252 sp->read_error = 0;
253
254 return 1;
255}
256
279static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
280{
281 static const char module[] = "LZMADecode";
282 LZMAState *sp = LZMADecoderState(tif);
283
284 (void)s;
285 assert(sp != NULL);
286 assert(sp->state == LSTATE_INIT_DECODE);
287
288 if (sp->read_error)
289 {
290 memset(op, 0, (size_t)occ);
291 TIFFErrorExtR(tif, module,
292 "LZMADecode: Scanline %" PRIu32 " cannot be read due to "
293 "previous error",
294 tif->tif_dir.td_row);
295 return 0;
296 }
297
298 sp->stream.next_in = tif->tif_rawcp;
299 sp->stream.avail_in = (size_t)tif->tif_rawcc;
300
301 sp->stream.next_out = op;
302 sp->stream.avail_out = (size_t)occ;
303 if ((tmsize_t)sp->stream.avail_out != occ)
304 {
305 // read_error not set here as this is a usage issue that can be
306 // recovered in a following call.
307 memset(op, 0, (size_t)occ);
308 TIFFErrorExtR(tif, module,
309 "Liblzma cannot deal with buffers this size");
310 return 0;
311 }
312
313 do
314 {
315 /*
316 * Save the current stream state to properly recover from the
317 * decoding errors later.
318 */
319 const uint8_t *next_in = sp->stream.next_in;
320 size_t avail_in = sp->stream.avail_in;
321
322 lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN);
323 if (ret == LZMA_STREAM_END)
324 break;
325 if (ret == LZMA_MEMLIMIT_ERROR)
326 {
327 lzma_ret r =
328 lzma_stream_decoder(&sp->stream, lzma_memusage(&sp->stream), 0);
329 if (r != LZMA_OK)
330 {
331 sp->read_error = 1;
332 memset(op, 0, (size_t)occ);
333 TIFFErrorExtR(tif, module,
334 "Error initializing the stream decoder, %s",
335 LZMAStrerror(r));
336 break;
337 }
338 sp->stream.next_in = next_in;
339 sp->stream.avail_in = avail_in;
340 continue;
341 }
342 if (ret != LZMA_OK)
343 {
344 TIFFErrorExtR(tif, module,
345 "Decoding error at scanline %" PRIu32 ", %s",
346 tif->tif_dir.td_row, LZMAStrerror(ret));
347 break;
348 }
349 } while (sp->stream.avail_out > 0);
350 if (sp->stream.avail_out != 0)
351 {
352 sp->read_error = 1;
353 memset(sp->stream.next_out, 0, sp->stream.avail_out);
354 TIFFErrorExtR(tif, module,
355 "Not enough data at scanline %" PRIu32
356 " (short %" TIFF_SIZE_FORMAT " bytes)",
357 tif->tif_dir.td_row, sp->stream.avail_out);
358 return 0;
359 }
360
361 tif->tif_rawcp = (uint8_t *)sp->stream.next_in; /* cast away const */
362 tif->tif_rawcc = (tmsize_t)sp->stream.avail_in;
363
364 return 1;
365}
366
379static int LZMASetupEncode(TIFF *tif)
380{
381 LZMAState *sp = LZMAEncoderState(tif);
382
383 assert(sp != NULL);
384 if (sp->state & LSTATE_INIT_DECODE)
385 {
386 lzma_end(&sp->stream);
387 sp->state = 0;
388 }
389
391 return 1;
392}
393
394/*
395 * Reset encoding state at the start of a strip.
396 */
412static int LZMAPreEncode(TIFF *tif, uint16_t s)
413{
414 static const char module[] = "LZMAPreEncode";
415 LZMAState *sp = LZMAEncoderState(tif);
416 lzma_ret ret;
417
418 (void)s;
419 assert(sp != NULL);
420 if (sp->state != LSTATE_INIT_ENCODE)
421 tif->tif_setupencode(tif);
422
423 sp->stream.next_out = tif->tif_rawdata;
424 sp->stream.avail_out = (size_t)tif->tif_rawdatasize;
425 if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
426 {
427 TIFFErrorExtR(tif, module,
428 "Liblzma cannot deal with buffers this size");
429 return 0;
430 }
431 ret = lzma_stream_encoder(&sp->stream, sp->filters, sp->check);
432 if (ret != LZMA_OK)
433 {
434 TIFFErrorExtR(tif, module, "Error in lzma_stream_encoder(): %s",
435 LZMAStrerror(ret));
436 return 0;
437 }
438 return 1;
439}
440
441/*
442 * Encode a chunk of pixels.
443 */
464static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
465{
466 static const char module[] = "LZMAEncode";
467 LZMAState *sp = LZMAEncoderState(tif);
468
469 assert(sp != NULL);
470 if (sp->state != LSTATE_INIT_ENCODE)
471 {
472 TIFFErrorExtR(tif, module,
473 "LZMA codec state is not initialized for encoding");
474 return 0;
475 }
476
477 (void)s;
478 sp->stream.next_in = bp;
479 sp->stream.avail_in = (size_t)cc;
480 if ((tmsize_t)sp->stream.avail_in != cc)
481 {
482 TIFFErrorExtR(tif, module,
483 "Liblzma cannot deal with buffers this size");
484 return 0;
485 }
486 do
487 {
488 lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN);
489 if (ret != LZMA_OK)
490 {
491 TIFFErrorExtR(tif, module,
492 "Encoding error at scanline %" PRIu32 ", %s",
493 tif->tif_dir.td_row, LZMAStrerror(ret));
494 return 0;
495 }
496 if (sp->stream.avail_out == 0)
497 {
498 tif->tif_rawcc = tif->tif_rawdatasize;
499 if (!TIFFFlushData1(tif))
500 return 0;
501 sp->stream.next_out = tif->tif_rawdata;
502 sp->stream.avail_out =
503 (size_t)
504 tif->tif_rawdatasize; /* this is a safe typecast, as check
505 is made already in LZMAPreEncode */
506 }
507 } while (sp->stream.avail_in > 0);
508 return 1;
509}
510
511/*
512 * Finish off an encoded strip by flushing the last
513 * string and tacking on an End Of Information code.
514 */
530static int LZMAPostEncode(TIFF *tif)
531{
532 static const char module[] = "LZMAPostEncode";
533 LZMAState *sp = LZMAEncoderState(tif);
534 lzma_ret ret;
535
536 if (sp->state != LSTATE_INIT_ENCODE)
537 {
538 TIFFErrorExtR(tif, module,
539 "LZMA codec state is not initialized for encoding");
540 return 0;
541 }
542
543 sp->stream.avail_in = 0;
544 do
545 {
546 ret = lzma_code(&sp->stream, LZMA_FINISH);
547 switch (ret)
548 {
549 case LZMA_STREAM_END:
550 case LZMA_OK:
551 if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
552 {
553 tif->tif_rawcc =
554 tif->tif_rawdatasize - (tmsize_t)sp->stream.avail_out;
555 if (!TIFFFlushData1(tif))
556 return 0;
557 sp->stream.next_out = tif->tif_rawdata;
558 sp->stream.avail_out =
559 (size_t)
560 tif->tif_rawdatasize; /* this is a safe typecast, as
561 check is made already in
562 ZIPPreEncode */
563 }
564 break;
565 case LZMA_NO_CHECK:
566 case LZMA_UNSUPPORTED_CHECK:
567 case LZMA_GET_CHECK:
568 case LZMA_MEM_ERROR:
569 case LZMA_MEMLIMIT_ERROR:
570 case LZMA_FORMAT_ERROR:
571 case LZMA_OPTIONS_ERROR:
572 case LZMA_DATA_ERROR:
573 case LZMA_BUF_ERROR:
574 case LZMA_PROG_ERROR:
575#if LZMA_VERSION >= 50040000 /* 5.4.0 */
576 case LZMA_SEEK_NEEDED:
577 case LZMA_RET_INTERNAL1:
578 case LZMA_RET_INTERNAL2:
579 case LZMA_RET_INTERNAL3:
580 case LZMA_RET_INTERNAL4:
581 case LZMA_RET_INTERNAL5:
582 case LZMA_RET_INTERNAL6:
583 case LZMA_RET_INTERNAL7:
584 case LZMA_RET_INTERNAL8:
585#endif
586 default:
587 TIFFErrorExtR(tif, module, "Liblzma error: %s",
588 LZMAStrerror(ret));
589 return 0;
590 }
591 } while (ret != LZMA_STREAM_END);
592 return 1;
593}
594
607static void LZMACleanup(TIFF *tif)
608{
609 LZMAState *sp = GetLZMAState(tif);
610
611 assert(sp != 0);
612
613 (void)TIFFPredictorCleanup(tif);
614
617
618 if (sp->state)
619 {
620 lzma_end(&sp->stream);
621 sp->state = 0;
622 }
623 _TIFFfreeExt(tif, sp);
624 tif->tif_data = NULL;
625
627}
628
647static int LZMAVSetField(TIFF *tif, uint32_t tag, va_list ap)
648{
649 static const char module[] = "LZMAVSetField";
650 LZMAState *sp = GetLZMAState(tif);
651
652 switch (tag)
653 {
655 sp->preset = (int)va_arg(ap, int);
656 lzma_lzma_preset(&sp->opt_lzma, (uint32_t)sp->preset);
657 if (sp->state & LSTATE_INIT_ENCODE)
658 {
659 lzma_ret ret =
660 lzma_stream_encoder(&sp->stream, sp->filters, sp->check);
661 if (ret != LZMA_OK)
662 {
663 TIFFErrorExtR(tif, module, "Liblzma error: %s",
664 LZMAStrerror(ret));
665 }
666 }
667 return 1;
668 default:
669 return (*sp->vsetparent)(tif, tag, ap);
670 }
671 /*NOTREACHED*/
672}
673
689static int LZMAVGetField(TIFF *tif, uint32_t tag, va_list ap)
690{
691 LZMAState *sp = GetLZMAState(tif);
692
693 switch (tag)
694 {
696 *va_arg(ap, int *) = sp->preset;
697 break;
698 default:
699 return (*sp->vgetparent)(tif, tag, ap);
700 }
701 return 1;
702}
703
711static const TIFFField lzmaFields[] = {
713 FALSE, "LZMA2 Compression Preset", NULL},
714};
715
726static uint64_t LZMAGetMaxCompressionRatio(TIFF *tif)
727{
728 (void)tif;
729
730 /* See README_for_libtiff_developpers.md for raw data used to estimate
731 * the maximum compression rate. */
732
733 /* 1024x1024: 3800 */
734 /* 4096x4096: 6534 */
735 /* 16383x16383: 6846 */
736 /* 65536x65536: 6874 */
737
738 return 7000;
739}
740
741int TIFFInitLZMA(TIFF *tif, int scheme)
742{
743 static const char module[] = "TIFFInitLZMA";
744 LZMAState *sp;
745 lzma_stream tmp_stream = LZMA_STREAM_INIT;
746
747 (void)scheme;
748 assert(scheme == COMPRESSION_LZMA);
749
750 /*
751 * Merge codec-specific tag information.
752 */
754 {
755 TIFFErrorExtR(tif, module, "Merging LZMA2 codec-specific tags failed");
756 return 0;
757 }
758
759 /*
760 * Allocate state block so tag methods have storage to record values.
761 */
762 tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(LZMAState));
763 if (tif->tif_data == NULL)
764 goto bad;
765 sp = GetLZMAState(tif);
766 memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream));
767
768 /*
769 * Override parent get/set field methods.
770 */
771 sp->vgetparent = tif->tif_tagmethods.vgetfield;
772 tif->tif_tagmethods.vgetfield = LZMAVGetField; /* hook for codec tags */
773 sp->vsetparent = tif->tif_tagmethods.vsetfield;
774 tif->tif_tagmethods.vsetfield = LZMAVSetField; /* hook for codec tags */
775
776 /* Default values for codec-specific fields */
777 sp->preset = LZMA_PRESET_DEFAULT; /* default comp. level */
778 sp->check = LZMA_CHECK_NONE;
779 sp->state = 0;
780
781 /* Data filters. So far we are using delta and LZMA2 filters only. */
782 sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE;
783 /*
784 * The sample size in bytes seems to be reasonable distance for delta
785 * filter.
786 */
787 sp->opt_delta.dist = (tif->tif_dir.td_bitspersample % 8)
788 ? 1
789 : tif->tif_dir.td_bitspersample / 8;
790 sp->filters[0].id = LZMA_FILTER_DELTA;
791 sp->filters[0].options = &sp->opt_delta;
792
793 lzma_lzma_preset(&sp->opt_lzma, (uint32_t)sp->preset);
794 sp->filters[1].id = LZMA_FILTER_LZMA2;
795 sp->filters[1].options = &sp->opt_lzma;
796
797 sp->filters[2].id = LZMA_VLI_UNKNOWN;
798 sp->filters[2].options = NULL;
799
800 /*
801 * Install codec methods.
802 */
817
818 /*
819 * Setup predictor setup.
820 */
821 (void)TIFFPredictorInit(tif);
822 return 1;
823bad:
824 TIFFErrorExtR(tif, module, "No space for LZMA2 state block");
825 return 0;
826}
827#endif /* LZMA_SUPPORT */
828
void _TIFFSetDefaultCompressionState(TIFF *tif)
Install fallback codec callbacks and reset raw-access flags.
#define TIFF_SIZE_FORMAT
Provide the printf conversion fragment for size_t, without a percent sign.
Definition tif_config.h:287
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
Merge borrowed field definitions into the lookup table.
#define FIELD_PSEUDO
Share bit zero with FIELD_IGNORE for pseudo-tags.
Definition tif_dir.h:620
@ TIFF_SETGET_INT
Promoted int scalar representation.
Definition tif_dir.h:762
int TIFFFlushData1(TIFF *tif)
Append buffered encoded bytes without invoking postencode recursively.
Definition tif_write.c:1213
#define LZMAEncoderState(tif)
Alias of GetLZMAState(), returning the LZMAState for encoding.
Definition tif_lzma.c:96
#define GetLZMAState(tif)
Cast tif->tif_data to the LZMAState.
Definition tif_lzma.c:94
static int LZMAVGetField(TIFF *tif, uint32_t tag, va_list ap)
Retrieve LZMA preset or delegate a tag query.
Definition tif_lzma.c:689
static void LZMACleanup(TIFF *tif)
End the dependency stream and release LZMA codec state.
Definition tif_lzma.c:607
static int LZMAPostEncode(TIFF *tif)
Finish the LZMA2 stream and flush produced output.
Definition tif_lzma.c:530
static int LZMAPreEncode(TIFF *tif, uint16_t s)
Initialise a filtered LZMA2 stream for one output strile.
Definition tif_lzma.c:412
#define LSTATE_INIT_ENCODE
Bit 0x02 of the codec state field: encoding has been set up.
Definition tif_lzma.c:86
static int LZMAPreDecode(TIFF *tif, uint16_t s)
Initialise the liblzma decoder for one strile.
Definition tif_lzma.c:219
static int LZMASetupDecode(TIFF *tif)
Switch the liblzma stream to decode mode.
Definition tif_lzma.c:183
#define LSTATE_INIT_DECODE
Bit 0x01 of the codec state field: decoding has been set up.
Definition tif_lzma.c:85
static int LZMAFixupTags(TIFF *tif)
Accept LZMA tag fixup without changes.
Definition tif_lzma.c:165
#define LZMADecoderState(tif)
Alias of GetLZMAState(), returning the LZMAState for decoding.
Definition tif_lzma.c:95
static uint64_t LZMAGetMaxCompressionRatio(TIFF *tif)
Report the empirical LZMA expansion heuristic.
Definition tif_lzma.c:726
static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Consume input through the active liblzma encoder.
Definition tif_lzma.c:464
static const TIFFField lzmaFields[]
Define the LZMA compression-preset pseudo-tag.
Definition tif_lzma.c:711
static int LZMASetupEncode(TIFF *tif)
Switch the liblzma stream to encode mode.
Definition tif_lzma.c:379
static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Expand cached liblzma input into caller output.
Definition tif_lzma.c:279
int TIFFInitLZMA(TIFF *tif, int scheme)
Allocate predictor-aware LZMA2 codec state and install callbacks.
Definition tif_lzma.c:741
static const char * LZMAStrerror(lzma_ret ret)
Describe a liblzma status using immutable text.
Definition tif_lzma.c:112
static int LZMAVSetField(TIFF *tif, uint32_t tag, va_list ap)
Store LZMA preset or delegate a tag assignment.
Definition tif_lzma.c:647
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
Definition tif_open.c:301
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
Definition tif_open.c:195
int TIFFPredictorCleanup(TIFF *tif)
Restore saved Predictor tag print and setup hooks.
int TIFFPredictorInit(TIFF *tif)
Install Predictor tag and setup hooks around a codec.
#define TRUE
Represent the legacy internal true value.
Definition tiffiop.h:131
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
#define TIFFArrayCount(a)
Compute the element count of an actual array.
Definition tiffiop.h:1239
#define TIFF_ANY
Match any data type when searching for a field descriptor.
Definition tiffio.h:1289
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
#define TIFFTAG_LZMAPRESET
Pseudo-tag: LZMA2 preset (compression level).
Definition tiff.h:1633
int(* TIFFVGetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag getter.
Definition tiffio.h:1540
int(* TIFFVSetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag setter.
Definition tiffio.h:1521
#define COMPRESSION_LZMA
LZMA2.
Definition tiff.h:367
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89
Own a filtered liblzma stream and predictor-prefixed methods.
Definition tif_lzma.c:58
TIFFPredictorState predict
Predictor prefix, first in codec state.
Definition tif_lzma.c:60
TIFFVSetMethod vsetparent
Borrowed parent tag setter restored during cleanup.
Definition tif_lzma.c:91
lzma_check check
Dependency integrity check, default LZMA_CHECK_NONE.
Definition tif_lzma.c:82
int read_error
Same-strile decode failure latch reset after successful predecode.
Definition tif_lzma.c:64
int preset
Cached compression preset; setter stores even when option conversion fails.
Definition tif_lzma.c:80
lzma_options_delta opt_delta
Embedded byte-delta options referenced by filters.
Definition tif_lzma.c:73
TIFFVGetMethod vgetparent
Borrowed parent tag getter restored during cleanup.
Definition tif_lzma.c:89
int state
Initialised decode/encode mode bits.
Definition tif_lzma.c:84
lzma_options_lzma opt_lzma
Embedded LZMA2 options referenced by filters.
Definition tif_lzma.c:75
lzma_stream stream
Dependency stream owning internal allocations until lzma_end.
Definition tif_lzma.c:66
uint16_t td_bitspersample
Bits in each sample.
Definition tif_dir.h:168
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
Definition tif_dir.h:240
Prefix codec state with Predictor method chains and row geometry.
Definition tif_predict.h:76
TIFFVGetMethod vgetfield
Variadic tag-query implementation for the handle.
Definition tiffio.h:1577
TIFFVSetMethod vsetfield
Variadic tag-setting implementation for the handle.
Definition tiffio.h:1575
Describe a field's file type and internal argument contract.
Definition tif_dir.h:993
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
TIFFCodeMethod tif_encodestrip
Codec callback encoding strip data.
Definition tiffiop.h:649
TIFFCodeMethod tif_encodetile
Codec callback encoding tile data.
Definition tiffiop.h:653
TIFFTagMethods tif_tagmethods
Inline table of directory field and print callbacks.
Definition tiffiop.h:742
TIFFPreMethod tif_preencode
Codec callback preparing a row, strip, or tile encode.
Definition tiffiop.h:639
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
Definition tiffiop.h:626
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
Definition tiffiop.h:696
TIFFPreMethod tif_predecode
Codec callback preparing a row, strip, or tile decode.
Definition tiffiop.h:630
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
Definition tiffiop.h:647
TIFFGetMaxCompressionRatioMethod tif_getmaxcompressionratio
Codec callback returning its maximum compression ratio.
Definition tiffiop.h:670
TIFFCodeMethod tif_decoderow
Codec callback decoding a scanline.
Definition tiffiop.h:643
TIFFBoolMethod tif_setupencode
Codec setup callback run before preencode.
Definition tiffiop.h:632
TIFFDirectory tif_dir
Inline representation of the current image directory.
Definition tiffiop.h:572
TIFFBoolMethod tif_postencode
Codec callback completing buffered encoding.
Definition tiffiop.h:641
TIFFCodeMethod tif_encoderow
Codec callback encoding a scanline.
Definition tiffiop.h:645
TIFFVoidMethod tif_cleanup
Codec callback releasing codec-private state.
Definition tiffiop.h:661
uint8_t * tif_data
Codec-private storage; allocation and cleanup follow the selected codec.
Definition tiffiop.h:675
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
Definition tiffiop.h:692
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
Definition tiffiop.h:628
uint8_t * tif_rawdata
Raw buffer; ownership/mapping follow TIFF_MYBUFFER and TIFF_BUFFERMMAP.
Definition tiffiop.h:681
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
Definition tiffiop.h:686
TIFFCodeMethod tif_decodetile
Codec callback decoding tile data.
Definition tiffiop.h:651
Define the predictor prefix and method-chain contracts.
Declare private library state, callbacks, and implementation helpers.