Coverage Report

Created: 2026-08-14 09:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/gtiff/libtiff/tif_lzma.c
Line
Count
Source
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
24
#include "tiffiop.h"
25
#ifdef LZMA_SUPPORT
26
/*
27
 * TIFF Library.
28
 *
29
 * LZMA2 Compression Support
30
 *
31
 * You need an LZMA2 SDK to link with. See http://tukaani.org/xz/ for details.
32
 *
33
 * The codec is derived from ZLIB codec (tif_zip.c).
34
 */
35
36
#include "lzma.h"
37
#include "tif_predict.h"
38
39
#include <stdio.h>
40
41
/*
42
 * State block for each open TIFF file using LZMA2 compression/decompression.
43
 */
44
typedef struct
45
{
46
    TIFFPredictorState predict;
47
    int read_error; /* whether a read error has occurred, and which should cause
48
                       further reads in the same strip/tile to be aborted */
49
    lzma_stream stream;
50
    lzma_filter filters[LZMA_FILTERS_MAX + 1];
51
    lzma_options_delta opt_delta; /* delta filter options */
52
    lzma_options_lzma opt_lzma;   /* LZMA2 filter options */
53
    int preset;                   /* compression level */
54
    lzma_check check;             /* type of the integrity check */
55
    int state;                    /* state flags */
56
195
#define LSTATE_INIT_DECODE 0x01
57
68
#define LSTATE_INIT_ENCODE 0x02
58
59
    TIFFVGetMethod vgetparent; /* super-class method */
60
    TIFFVSetMethod vsetparent; /* super-class method */
61
} LZMAState;
62
63
19.6k
#define GetLZMAState(tif) ((LZMAState *)(tif)->tif_data)
64
322
#define LZMADecoderState(tif) GetLZMAState(tif)
65
0
#define LZMAEncoderState(tif) GetLZMAState(tif)
66
67
static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
68
static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
69
70
static const char *LZMAStrerror(lzma_ret ret)
71
80
{
72
80
    switch (ret)
73
80
    {
74
0
        case LZMA_OK:
75
0
            return "operation completed successfully";
76
0
        case LZMA_STREAM_END:
77
0
            return "end of stream was reached";
78
0
        case LZMA_NO_CHECK:
79
0
            return "input stream has no integrity check";
80
0
        case LZMA_UNSUPPORTED_CHECK:
81
0
            return "cannot calculate the integrity check";
82
0
        case LZMA_GET_CHECK:
83
0
            return "integrity check type is now available";
84
0
        case LZMA_MEM_ERROR:
85
0
            return "cannot allocate memory";
86
0
        case LZMA_MEMLIMIT_ERROR:
87
0
            return "memory usage limit was reached";
88
26
        case LZMA_FORMAT_ERROR:
89
26
            return "file format not recognized";
90
0
        case LZMA_OPTIONS_ERROR:
91
0
            return "invalid or unsupported options";
92
8
        case LZMA_DATA_ERROR:
93
8
            return "data is corrupt";
94
46
        case LZMA_BUF_ERROR:
95
46
            return "no progress is possible (stream is truncated or corrupt)";
96
0
        case LZMA_PROG_ERROR:
97
0
            return "programming error";
98
0
#if LZMA_VERSION >= 50040000 /* 5.4.0 */
99
0
        case LZMA_SEEK_NEEDED:
100
0
        case LZMA_RET_INTERNAL1:
101
0
        case LZMA_RET_INTERNAL2:
102
0
        case LZMA_RET_INTERNAL3:
103
0
        case LZMA_RET_INTERNAL4:
104
0
        case LZMA_RET_INTERNAL5:
105
0
        case LZMA_RET_INTERNAL6:
106
0
        case LZMA_RET_INTERNAL7:
107
0
        case LZMA_RET_INTERNAL8:
108
0
#endif
109
0
        default:
110
0
            return "unidentified liblzma error";
111
80
    }
112
80
}
113
114
static int LZMAFixupTags(TIFF *tif)
115
1.04k
{
116
1.04k
    (void)tif;
117
1.04k
    return 1;
118
1.04k
}
119
120
static int LZMASetupDecode(TIFF *tif)
121
68
{
122
68
    LZMAState *sp = LZMADecoderState(tif);
123
124
68
    assert(sp != NULL);
125
126
    /* if we were last encoding, terminate this mode */
127
68
    if (sp->state & LSTATE_INIT_ENCODE)
128
0
    {
129
0
        lzma_end(&sp->stream);
130
0
        sp->state = 0;
131
0
    }
132
133
68
    sp->state |= LSTATE_INIT_DECODE;
134
68
    return 1;
135
68
}
136
137
/*
138
 * Setup state for decoding a strip.
139
 */
140
static int LZMAPreDecode(TIFF *tif, uint16_t s)
141
127
{
142
127
    static const char module[] = "LZMAPreDecode";
143
127
    LZMAState *sp = LZMADecoderState(tif);
144
127
    lzma_ret ret;
145
146
127
    (void)s;
147
127
    assert(sp != NULL);
148
149
127
    if ((sp->state & LSTATE_INIT_DECODE) == 0)
150
0
        tif->tif_setupdecode(tif);
151
152
127
    sp->stream.next_in = tif->tif_rawdata;
153
127
    sp->stream.avail_in = (size_t)tif->tif_rawcc;
154
127
    if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc)
155
0
    {
156
0
        TIFFErrorExtR(tif, module,
157
0
                      "Liblzma cannot deal with buffers this size");
158
0
        return 0;
159
0
    }
160
161
    /*
162
     * Disable memory limit when decoding. UINT64_MAX is a flag to disable
163
     * the limit, we are passing (uint64_t)-1 which should be the same.
164
     */
165
127
    ret = lzma_stream_decoder(&sp->stream, (uint64_t)-1, 0);
166
127
    if (ret != LZMA_OK)
167
0
    {
168
0
        TIFFErrorExtR(tif, module, "Error initializing the stream decoder, %s",
169
0
                      LZMAStrerror(ret));
170
0
        return 0;
171
0
    }
172
173
127
    sp->read_error = 0;
174
175
127
    return 1;
176
127
}
177
178
static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
179
127
{
180
127
    static const char module[] = "LZMADecode";
181
127
    LZMAState *sp = LZMADecoderState(tif);
182
183
127
    (void)s;
184
127
    assert(sp != NULL);
185
127
    assert(sp->state == LSTATE_INIT_DECODE);
186
187
127
    if (sp->read_error)
188
0
    {
189
0
        memset(op, 0, (size_t)occ);
190
0
        TIFFErrorExtR(tif, module,
191
0
                      "LZMADecode: Scanline %" PRIu32 " cannot be read due to "
192
0
                      "previous error",
193
0
                      tif->tif_dir.td_row);
194
0
        return 0;
195
0
    }
196
197
127
    sp->stream.next_in = tif->tif_rawcp;
198
127
    sp->stream.avail_in = (size_t)tif->tif_rawcc;
199
200
127
    sp->stream.next_out = op;
201
127
    sp->stream.avail_out = (size_t)occ;
202
127
    if ((tmsize_t)sp->stream.avail_out != occ)
203
0
    {
204
        // read_error not set here as this is a usage issue that can be
205
        // recovered in a following call.
206
0
        memset(op, 0, (size_t)occ);
207
0
        TIFFErrorExtR(tif, module,
208
0
                      "Liblzma cannot deal with buffers this size");
209
0
        return 0;
210
0
    }
211
212
127
    do
213
219
    {
214
        /*
215
         * Save the current stream state to properly recover from the
216
         * decoding errors later.
217
         */
218
219
        const uint8_t *next_in = sp->stream.next_in;
219
219
        size_t avail_in = sp->stream.avail_in;
220
221
219
        lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN);
222
219
        if (ret == LZMA_STREAM_END)
223
27
            break;
224
192
        if (ret == LZMA_MEMLIMIT_ERROR)
225
0
        {
226
0
            lzma_ret r =
227
0
                lzma_stream_decoder(&sp->stream, lzma_memusage(&sp->stream), 0);
228
0
            if (r != LZMA_OK)
229
0
            {
230
0
                sp->read_error = 1;
231
0
                memset(op, 0, (size_t)occ);
232
0
                TIFFErrorExtR(tif, module,
233
0
                              "Error initializing the stream decoder, %s",
234
0
                              LZMAStrerror(r));
235
0
                break;
236
0
            }
237
0
            sp->stream.next_in = next_in;
238
0
            sp->stream.avail_in = avail_in;
239
0
            continue;
240
0
        }
241
192
        if (ret != LZMA_OK)
242
80
        {
243
80
            TIFFErrorExtR(tif, module,
244
80
                          "Decoding error at scanline %" PRIu32 ", %s",
245
80
                          tif->tif_dir.td_row, LZMAStrerror(ret));
246
80
            break;
247
80
        }
248
192
    } while (sp->stream.avail_out > 0);
249
127
    if (sp->stream.avail_out != 0)
250
80
    {
251
80
        sp->read_error = 1;
252
80
        memset(sp->stream.next_out, 0, sp->stream.avail_out);
253
80
        TIFFErrorExtR(tif, module,
254
80
                      "Not enough data at scanline %" PRIu32
255
80
                      " (short %" TIFF_SIZE_FORMAT " bytes)",
256
80
                      tif->tif_dir.td_row, sp->stream.avail_out);
257
80
        return 0;
258
80
    }
259
260
47
    tif->tif_rawcp = (uint8_t *)sp->stream.next_in; /* cast away const */
261
47
    tif->tif_rawcc = (tmsize_t)sp->stream.avail_in;
262
263
47
    return 1;
264
127
}
265
266
static int LZMASetupEncode(TIFF *tif)
267
0
{
268
0
    LZMAState *sp = LZMAEncoderState(tif);
269
270
0
    assert(sp != NULL);
271
0
    if (sp->state & LSTATE_INIT_DECODE)
272
0
    {
273
0
        lzma_end(&sp->stream);
274
0
        sp->state = 0;
275
0
    }
276
277
0
    sp->state |= LSTATE_INIT_ENCODE;
278
0
    return 1;
279
0
}
280
281
/*
282
 * Reset encoding state at the start of a strip.
283
 */
284
static int LZMAPreEncode(TIFF *tif, uint16_t s)
285
0
{
286
0
    static const char module[] = "LZMAPreEncode";
287
0
    LZMAState *sp = LZMAEncoderState(tif);
288
0
    lzma_ret ret;
289
290
0
    (void)s;
291
0
    assert(sp != NULL);
292
0
    if (sp->state != LSTATE_INIT_ENCODE)
293
0
        tif->tif_setupencode(tif);
294
295
0
    sp->stream.next_out = tif->tif_rawdata;
296
0
    sp->stream.avail_out = (size_t)tif->tif_rawdatasize;
297
0
    if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
298
0
    {
299
0
        TIFFErrorExtR(tif, module,
300
0
                      "Liblzma cannot deal with buffers this size");
301
0
        return 0;
302
0
    }
303
0
    ret = lzma_stream_encoder(&sp->stream, sp->filters, sp->check);
304
0
    if (ret != LZMA_OK)
305
0
    {
306
0
        TIFFErrorExtR(tif, module, "Error in lzma_stream_encoder(): %s",
307
0
                      LZMAStrerror(ret));
308
0
        return 0;
309
0
    }
310
0
    return 1;
311
0
}
312
313
/*
314
 * Encode a chunk of pixels.
315
 */
316
static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
317
0
{
318
0
    static const char module[] = "LZMAEncode";
319
0
    LZMAState *sp = LZMAEncoderState(tif);
320
321
0
    assert(sp != NULL);
322
0
    assert(sp->state == LSTATE_INIT_ENCODE);
323
324
0
    (void)s;
325
0
    sp->stream.next_in = bp;
326
0
    sp->stream.avail_in = (size_t)cc;
327
0
    if ((tmsize_t)sp->stream.avail_in != cc)
328
0
    {
329
0
        TIFFErrorExtR(tif, module,
330
0
                      "Liblzma cannot deal with buffers this size");
331
0
        return 0;
332
0
    }
333
0
    do
334
0
    {
335
0
        lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN);
336
0
        if (ret != LZMA_OK)
337
0
        {
338
0
            TIFFErrorExtR(tif, module,
339
0
                          "Encoding error at scanline %" PRIu32 ", %s",
340
0
                          tif->tif_dir.td_row, LZMAStrerror(ret));
341
0
            return 0;
342
0
        }
343
0
        if (sp->stream.avail_out == 0)
344
0
        {
345
0
            tif->tif_rawcc = tif->tif_rawdatasize;
346
0
            if (!TIFFFlushData1(tif))
347
0
                return 0;
348
0
            sp->stream.next_out = tif->tif_rawdata;
349
0
            sp->stream.avail_out =
350
0
                (size_t)
351
0
                    tif->tif_rawdatasize; /* this is a safe typecast, as check
352
                                             is made already in LZMAPreEncode */
353
0
        }
354
0
    } while (sp->stream.avail_in > 0);
355
0
    return 1;
356
0
}
357
358
/*
359
 * Finish off an encoded strip by flushing the last
360
 * string and tacking on an End Of Information code.
361
 */
362
static int LZMAPostEncode(TIFF *tif)
363
0
{
364
0
    static const char module[] = "LZMAPostEncode";
365
0
    LZMAState *sp = LZMAEncoderState(tif);
366
0
    lzma_ret ret;
367
368
0
    sp->stream.avail_in = 0;
369
0
    do
370
0
    {
371
0
        ret = lzma_code(&sp->stream, LZMA_FINISH);
372
0
        switch (ret)
373
0
        {
374
0
            case LZMA_STREAM_END:
375
0
            case LZMA_OK:
376
0
                if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
377
0
                {
378
0
                    tif->tif_rawcc =
379
0
                        tif->tif_rawdatasize - (tmsize_t)sp->stream.avail_out;
380
0
                    if (!TIFFFlushData1(tif))
381
0
                        return 0;
382
0
                    sp->stream.next_out = tif->tif_rawdata;
383
0
                    sp->stream.avail_out =
384
0
                        (size_t)
385
0
                            tif->tif_rawdatasize; /* this is a safe typecast, as
386
                                                     check is made already in
387
                                                     ZIPPreEncode */
388
0
                }
389
0
                break;
390
0
            case LZMA_NO_CHECK:
391
0
            case LZMA_UNSUPPORTED_CHECK:
392
0
            case LZMA_GET_CHECK:
393
0
            case LZMA_MEM_ERROR:
394
0
            case LZMA_MEMLIMIT_ERROR:
395
0
            case LZMA_FORMAT_ERROR:
396
0
            case LZMA_OPTIONS_ERROR:
397
0
            case LZMA_DATA_ERROR:
398
0
            case LZMA_BUF_ERROR:
399
0
            case LZMA_PROG_ERROR:
400
0
#if LZMA_VERSION >= 50040000 /* 5.4.0 */
401
0
            case LZMA_SEEK_NEEDED:
402
0
            case LZMA_RET_INTERNAL1:
403
0
            case LZMA_RET_INTERNAL2:
404
0
            case LZMA_RET_INTERNAL3:
405
0
            case LZMA_RET_INTERNAL4:
406
0
            case LZMA_RET_INTERNAL5:
407
0
            case LZMA_RET_INTERNAL6:
408
0
            case LZMA_RET_INTERNAL7:
409
0
            case LZMA_RET_INTERNAL8:
410
0
#endif
411
0
            default:
412
0
                TIFFErrorExtR(tif, module, "Liblzma error: %s",
413
0
                              LZMAStrerror(ret));
414
0
                return 0;
415
0
        }
416
0
    } while (ret != LZMA_STREAM_END);
417
0
    return 1;
418
0
}
419
420
static void LZMACleanup(TIFF *tif)
421
1.10k
{
422
1.10k
    LZMAState *sp = GetLZMAState(tif);
423
424
1.10k
    assert(sp != 0);
425
426
1.10k
    (void)TIFFPredictorCleanup(tif);
427
428
1.10k
    tif->tif_tagmethods.vgetfield = sp->vgetparent;
429
1.10k
    tif->tif_tagmethods.vsetfield = sp->vsetparent;
430
431
1.10k
    if (sp->state)
432
42
    {
433
42
        lzma_end(&sp->stream);
434
42
        sp->state = 0;
435
42
    }
436
1.10k
    _TIFFfreeExt(tif, sp);
437
1.10k
    tif->tif_data = NULL;
438
439
1.10k
    _TIFFSetDefaultCompressionState(tif);
440
1.10k
}
441
442
static int LZMAVSetField(TIFF *tif, uint32_t tag, va_list ap)
443
7.51k
{
444
7.51k
    static const char module[] = "LZMAVSetField";
445
7.51k
    LZMAState *sp = GetLZMAState(tif);
446
447
7.51k
    switch (tag)
448
7.51k
    {
449
0
        case TIFFTAG_LZMAPRESET:
450
0
            sp->preset = (int)va_arg(ap, int);
451
0
            lzma_lzma_preset(&sp->opt_lzma, (uint32_t)sp->preset);
452
0
            if (sp->state & LSTATE_INIT_ENCODE)
453
0
            {
454
0
                lzma_ret ret =
455
0
                    lzma_stream_encoder(&sp->stream, sp->filters, sp->check);
456
0
                if (ret != LZMA_OK)
457
0
                {
458
0
                    TIFFErrorExtR(tif, module, "Liblzma error: %s",
459
0
                                  LZMAStrerror(ret));
460
0
                }
461
0
            }
462
0
            return 1;
463
7.51k
        default:
464
7.51k
            return (*sp->vsetparent)(tif, tag, ap);
465
7.51k
    }
466
    /*NOTREACHED*/
467
7.51k
}
468
469
static int LZMAVGetField(TIFF *tif, uint32_t tag, va_list ap)
470
9.55k
{
471
9.55k
    LZMAState *sp = GetLZMAState(tif);
472
473
9.55k
    switch (tag)
474
9.55k
    {
475
0
        case TIFFTAG_LZMAPRESET:
476
0
            *va_arg(ap, int *) = sp->preset;
477
0
            break;
478
9.55k
        default:
479
9.55k
            return (*sp->vgetparent)(tif, tag, ap);
480
9.55k
    }
481
0
    return 1;
482
9.55k
}
483
484
static const TIFFField lzmaFields[] = {
485
    {TIFFTAG_LZMAPRESET, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, FIELD_PSEUDO, TRUE,
486
     FALSE, "LZMA2 Compression Preset", NULL},
487
};
488
489
static uint64_t LZMAGetMaxCompressionRatio(TIFF *tif)
490
20
{
491
20
    (void)tif;
492
493
    /* See README_for_libtiff_developpers.md for raw data used to estimate
494
     * the maximum compression rate. */
495
496
    /* 1024x1024: 3800 */
497
    /* 4096x4096: 6534 */
498
    /* 16383x16383: 6846 */
499
    /* 65536x65536: 6874 */
500
501
20
    return 7000;
502
20
}
503
504
int TIFFInitLZMA(TIFF *tif, int scheme)
505
1.10k
{
506
1.10k
    static const char module[] = "TIFFInitLZMA";
507
1.10k
    LZMAState *sp;
508
1.10k
    lzma_stream tmp_stream = LZMA_STREAM_INIT;
509
510
1.10k
    (void)scheme;
511
1.10k
    assert(scheme == COMPRESSION_LZMA);
512
513
    /*
514
     * Merge codec-specific tag information.
515
     */
516
1.10k
    if (!_TIFFMergeFields(tif, lzmaFields, TIFFArrayCount(lzmaFields)))
517
0
    {
518
0
        TIFFErrorExtR(tif, module, "Merging LZMA2 codec-specific tags failed");
519
0
        return 0;
520
0
    }
521
522
    /*
523
     * Allocate state block so tag methods have storage to record values.
524
     */
525
1.10k
    tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(LZMAState));
526
1.10k
    if (tif->tif_data == NULL)
527
0
        goto bad;
528
1.10k
    sp = GetLZMAState(tif);
529
1.10k
    memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream));
530
531
    /*
532
     * Override parent get/set field methods.
533
     */
534
1.10k
    sp->vgetparent = tif->tif_tagmethods.vgetfield;
535
1.10k
    tif->tif_tagmethods.vgetfield = LZMAVGetField; /* hook for codec tags */
536
1.10k
    sp->vsetparent = tif->tif_tagmethods.vsetfield;
537
1.10k
    tif->tif_tagmethods.vsetfield = LZMAVSetField; /* hook for codec tags */
538
539
    /* Default values for codec-specific fields */
540
1.10k
    sp->preset = LZMA_PRESET_DEFAULT; /* default comp. level */
541
1.10k
    sp->check = LZMA_CHECK_NONE;
542
1.10k
    sp->state = 0;
543
544
    /* Data filters. So far we are using delta and LZMA2 filters only. */
545
1.10k
    sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE;
546
    /*
547
     * The sample size in bytes seems to be reasonable distance for delta
548
     * filter.
549
     */
550
1.10k
    sp->opt_delta.dist = (tif->tif_dir.td_bitspersample % 8)
551
1.10k
                             ? 1
552
1.10k
                             : tif->tif_dir.td_bitspersample / 8;
553
1.10k
    sp->filters[0].id = LZMA_FILTER_DELTA;
554
1.10k
    sp->filters[0].options = &sp->opt_delta;
555
556
1.10k
    lzma_lzma_preset(&sp->opt_lzma, (uint32_t)sp->preset);
557
1.10k
    sp->filters[1].id = LZMA_FILTER_LZMA2;
558
1.10k
    sp->filters[1].options = &sp->opt_lzma;
559
560
1.10k
    sp->filters[2].id = LZMA_VLI_UNKNOWN;
561
1.10k
    sp->filters[2].options = NULL;
562
563
    /*
564
     * Install codec methods.
565
     */
566
1.10k
    tif->tif_fixuptags = LZMAFixupTags;
567
1.10k
    tif->tif_setupdecode = LZMASetupDecode;
568
1.10k
    tif->tif_predecode = LZMAPreDecode;
569
1.10k
    tif->tif_decoderow = LZMADecode;
570
1.10k
    tif->tif_decodestrip = LZMADecode;
571
1.10k
    tif->tif_decodetile = LZMADecode;
572
1.10k
    tif->tif_setupencode = LZMASetupEncode;
573
1.10k
    tif->tif_preencode = LZMAPreEncode;
574
1.10k
    tif->tif_postencode = LZMAPostEncode;
575
1.10k
    tif->tif_encoderow = LZMAEncode;
576
1.10k
    tif->tif_encodestrip = LZMAEncode;
577
1.10k
    tif->tif_encodetile = LZMAEncode;
578
1.10k
    tif->tif_cleanup = LZMACleanup;
579
1.10k
    tif->tif_getmaxcompressionratio = LZMAGetMaxCompressionRatio;
580
581
    /*
582
     * Setup predictor setup.
583
     */
584
1.10k
    (void)TIFFPredictorInit(tif);
585
1.10k
    return 1;
586
0
bad:
587
0
    TIFFErrorExtR(tif, module, "No space for LZMA2 state block");
588
0
    return 0;
589
1.10k
}
590
#endif /* LZMA_SUPPORT */