• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OSGeo / gdal / 15899162844

26 Jun 2025 10:14AM UTC coverage: 71.088% (+0.004%) from 71.084%
15899162844

Pull #12623

github

web-flow
Merge c704a8392 into f5cb024d4
Pull Request #12623: gdal raster overview add: add a --overview-src option

209 of 244 new or added lines in 5 files covered. (85.66%)

96 existing lines in 44 files now uncovered.

574014 of 807474 relevant lines covered (71.09%)

250815.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.83
/frmts/gtiff/libtiff/tif_predict.c
1
/*
2
 * Copyright (c) 1988-1997 Sam Leffler
3
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software and
6
 * its documentation for any purpose is hereby granted without fee, provided
7
 * that (i) the above copyright notices and this permission notice appear in
8
 * all copies of the software and related documentation, and (ii) the names of
9
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10
 * publicity relating to the software without the specific, prior written
11
 * permission of Sam Leffler and Silicon Graphics.
12
 *
13
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16
 *
17
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22
 * OF THIS SOFTWARE.
23
 */
24

25
/*
26
 * TIFF Library.
27
 *
28
 * Predictor Tag Support (used by multiple codecs).
29
 */
30
#include "tif_predict.h"
31
#include "tiffiop.h"
32

33
#if defined(__x86_64__) || defined(_M_X64)
34
#include <emmintrin.h>
35
#endif
36

37
#define PredictorState(tif) ((TIFFPredictorState *)(tif)->tif_data)
38

39
static int horAcc8(TIFF *tif, uint8_t *cp0, tmsize_t cc);
40
static int horAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
41
static int horAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
42
static int horAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
43
static int swabHorAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
44
static int swabHorAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
45
static int swabHorAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
46
static int horDiff8(TIFF *tif, uint8_t *cp0, tmsize_t cc);
47
static int horDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
48
static int horDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
49
static int horDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
50
static int swabHorDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
51
static int swabHorDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
52
static int swabHorDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
53
static int fpAcc(TIFF *tif, uint8_t *cp0, tmsize_t cc);
54
static int fpDiff(TIFF *tif, uint8_t *cp0, tmsize_t cc);
55
static int PredictorDecodeRow(TIFF *tif, uint8_t *op0, tmsize_t occ0,
56
                              uint16_t s);
57
static int PredictorDecodeTile(TIFF *tif, uint8_t *op0, tmsize_t occ0,
58
                               uint16_t s);
59
static int PredictorEncodeRow(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
60
static int PredictorEncodeTile(TIFF *tif, uint8_t *bp0, tmsize_t cc0,
61
                               uint16_t s);
62

63
static int PredictorSetup(TIFF *tif)
20,960✔
64
{
65
    static const char module[] = "PredictorSetup";
66

67
    TIFFPredictorState *sp = PredictorState(tif);
20,960✔
68
    TIFFDirectory *td = &tif->tif_dir;
20,960✔
69

70
    switch (sp->predictor) /* no differencing */
20,960✔
71
    {
72
        case PREDICTOR_NONE:
20,561✔
73
            return 1;
20,561✔
74
        case PREDICTOR_HORIZONTAL:
387✔
75
            if (td->td_bitspersample != 8 && td->td_bitspersample != 16 &&
387✔
76
                td->td_bitspersample != 32 && td->td_bitspersample != 64)
6✔
77
            {
78
                TIFFErrorExtR(tif, module,
×
79
                              "Horizontal differencing \"Predictor\" not "
80
                              "supported with %" PRIu16 "-bit samples",
81
                              td->td_bitspersample);
×
82
                return 0;
×
83
            }
84
            break;
387✔
85
        case PREDICTOR_FLOATINGPOINT:
11✔
86
            if (td->td_sampleformat != SAMPLEFORMAT_IEEEFP)
11✔
87
            {
88
                TIFFErrorExtR(
×
89
                    tif, module,
90
                    "Floating point \"Predictor\" not supported with %" PRIu16
91
                    " data format",
92
                    td->td_sampleformat);
×
93
                return 0;
×
94
            }
95
            if (td->td_bitspersample != 16 && td->td_bitspersample != 24 &&
11✔
96
                td->td_bitspersample != 32 && td->td_bitspersample != 64)
11✔
97
            { /* Should 64 be allowed? */
98
                TIFFErrorExtR(
×
99
                    tif, module,
100
                    "Floating point \"Predictor\" not supported with %" PRIu16
101
                    "-bit samples",
102
                    td->td_bitspersample);
×
103
                return 0;
×
104
            }
105
            break;
11✔
106
        default:
1✔
107
            TIFFErrorExtR(tif, module, "\"Predictor\" value %d not supported",
1✔
108
                          sp->predictor);
109
            return 0;
1✔
110
    }
111
    sp->stride =
398✔
112
        (td->td_planarconfig == PLANARCONFIG_CONTIG ? td->td_samplesperpixel
796✔
113
                                                    : 1);
398✔
114
    /*
115
     * Calculate the scanline/tile-width size in bytes.
116
     */
117
    if (isTiled(tif))
398✔
118
        sp->rowsize = TIFFTileRowSize(tif);
22✔
119
    else
120
        sp->rowsize = TIFFScanlineSize(tif);
376✔
121
    if (sp->rowsize == 0)
398✔
122
        return 0;
×
123

124
    return 1;
398✔
125
}
126

127
static int PredictorSetupDecode(TIFF *tif)
3,313✔
128
{
129
    TIFFPredictorState *sp = PredictorState(tif);
3,313✔
130
    TIFFDirectory *td = &tif->tif_dir;
3,313✔
131

132
    /* Note: when PredictorSetup() fails, the effets of setupdecode() */
133
    /* will not be "canceled" so setupdecode() might be robust to */
134
    /* be called several times. */
135
    if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif))
3,313✔
136
        return 0;
1✔
137

138
    if (sp->predictor == 2)
3,312✔
139
    {
140
        switch (td->td_bitspersample)
96✔
141
        {
142
            case 8:
76✔
143
                sp->decodepfunc = horAcc8;
76✔
144
                break;
76✔
145
            case 16:
17✔
146
                sp->decodepfunc = horAcc16;
17✔
147
                break;
17✔
148
            case 32:
2✔
149
                sp->decodepfunc = horAcc32;
2✔
150
                break;
2✔
151
            case 64:
1✔
152
                sp->decodepfunc = horAcc64;
1✔
153
                break;
1✔
154
        }
155
        /*
156
         * Override default decoding method with one that does the
157
         * predictor stuff.
158
         */
159
        if (tif->tif_decoderow != PredictorDecodeRow)
96✔
160
        {
161
            sp->decoderow = tif->tif_decoderow;
96✔
162
            tif->tif_decoderow = PredictorDecodeRow;
96✔
163
            sp->decodestrip = tif->tif_decodestrip;
96✔
164
            tif->tif_decodestrip = PredictorDecodeTile;
96✔
165
            sp->decodetile = tif->tif_decodetile;
96✔
166
            tif->tif_decodetile = PredictorDecodeTile;
96✔
167
        }
168

169
        /*
170
         * If the data is horizontally differenced 16-bit data that
171
         * requires byte-swapping, then it must be byte swapped before
172
         * the accumulation step.  We do this with a special-purpose
173
         * routine and override the normal post decoding logic that
174
         * the library setup when the directory was read.
175
         */
176
        if (tif->tif_flags & TIFF_SWAB)
96✔
177
        {
178
            if (sp->decodepfunc == horAcc16)
5✔
179
            {
180
                sp->decodepfunc = swabHorAcc16;
4✔
181
                tif->tif_postdecode = _TIFFNoPostDecode;
4✔
182
            }
183
            else if (sp->decodepfunc == horAcc32)
1✔
184
            {
185
                sp->decodepfunc = swabHorAcc32;
1✔
186
                tif->tif_postdecode = _TIFFNoPostDecode;
1✔
187
            }
188
            else if (sp->decodepfunc == horAcc64)
×
189
            {
190
                sp->decodepfunc = swabHorAcc64;
×
191
                tif->tif_postdecode = _TIFFNoPostDecode;
×
192
            }
193
        }
194
    }
195

196
    else if (sp->predictor == 3)
3,216✔
197
    {
198
        sp->decodepfunc = fpAcc;
8✔
199
        /*
200
         * Override default decoding method with one that does the
201
         * predictor stuff.
202
         */
203
        if (tif->tif_decoderow != PredictorDecodeRow)
8✔
204
        {
205
            sp->decoderow = tif->tif_decoderow;
8✔
206
            tif->tif_decoderow = PredictorDecodeRow;
8✔
207
            sp->decodestrip = tif->tif_decodestrip;
8✔
208
            tif->tif_decodestrip = PredictorDecodeTile;
8✔
209
            sp->decodetile = tif->tif_decodetile;
8✔
210
            tif->tif_decodetile = PredictorDecodeTile;
8✔
211
        }
212
        /*
213
         * The data should not be swapped outside of the floating
214
         * point predictor, the accumulation routine should return
215
         * bytes in the native order.
216
         */
217
        if (tif->tif_flags & TIFF_SWAB)
8✔
218
        {
219
            tif->tif_postdecode = _TIFFNoPostDecode;
2✔
220
        }
221
    }
222

223
    return 1;
3,312✔
224
}
225

226
static int PredictorSetupEncode(TIFF *tif)
17,647✔
227
{
228
    TIFFPredictorState *sp = PredictorState(tif);
17,647✔
229
    TIFFDirectory *td = &tif->tif_dir;
17,647✔
230

231
    if (!(*sp->setupencode)(tif) || !PredictorSetup(tif))
17,647✔
232
        return 0;
×
233

234
    if (sp->predictor == 2)
17,646✔
235
    {
236
        switch (td->td_bitspersample)
291✔
237
        {
238
            case 8:
276✔
239
                sp->encodepfunc = horDiff8;
276✔
240
                break;
276✔
241
            case 16:
12✔
242
                sp->encodepfunc = horDiff16;
12✔
243
                break;
12✔
244
            case 32:
2✔
245
                sp->encodepfunc = horDiff32;
2✔
246
                break;
2✔
247
            case 64:
1✔
248
                sp->encodepfunc = horDiff64;
1✔
249
                break;
1✔
250
        }
251
        /*
252
         * Override default encoding method with one that does the
253
         * predictor stuff.
254
         */
255
        if (tif->tif_encoderow != PredictorEncodeRow)
291✔
256
        {
257
            sp->encoderow = tif->tif_encoderow;
290✔
258
            tif->tif_encoderow = PredictorEncodeRow;
290✔
259
            sp->encodestrip = tif->tif_encodestrip;
290✔
260
            tif->tif_encodestrip = PredictorEncodeTile;
290✔
261
            sp->encodetile = tif->tif_encodetile;
290✔
262
            tif->tif_encodetile = PredictorEncodeTile;
290✔
263
        }
264

265
        /*
266
         * If the data is horizontally differenced 16-bit data that
267
         * requires byte-swapping, then it must be byte swapped after
268
         * the differentiation step.  We do this with a special-purpose
269
         * routine and override the normal post decoding logic that
270
         * the library setup when the directory was read.
271
         */
272
        if (tif->tif_flags & TIFF_SWAB)
291✔
273
        {
274
            if (sp->encodepfunc == horDiff16)
6✔
275
            {
276
                sp->encodepfunc = swabHorDiff16;
5✔
277
                tif->tif_postdecode = _TIFFNoPostDecode;
5✔
278
            }
279
            else if (sp->encodepfunc == horDiff32)
1✔
280
            {
281
                sp->encodepfunc = swabHorDiff32;
1✔
282
                tif->tif_postdecode = _TIFFNoPostDecode;
1✔
283
            }
284
            else if (sp->encodepfunc == horDiff64)
×
285
            {
286
                sp->encodepfunc = swabHorDiff64;
×
287
                tif->tif_postdecode = _TIFFNoPostDecode;
×
288
            }
289
        }
290
    }
291

292
    else if (sp->predictor == 3)
17,355✔
293
    {
294
        sp->encodepfunc = fpDiff;
3✔
295
        /*
296
         * Override default encoding method with one that does the
297
         * predictor stuff.
298
         */
299
        if (tif->tif_encoderow != PredictorEncodeRow)
3✔
300
        {
301
            sp->encoderow = tif->tif_encoderow;
3✔
302
            tif->tif_encoderow = PredictorEncodeRow;
3✔
303
            sp->encodestrip = tif->tif_encodestrip;
3✔
304
            tif->tif_encodestrip = PredictorEncodeTile;
3✔
305
            sp->encodetile = tif->tif_encodetile;
3✔
306
            tif->tif_encodetile = PredictorEncodeTile;
3✔
307
        }
308
        /*
309
         * The data should not be swapped outside of the floating
310
         * point predictor, the differentiation routine should return
311
         * bytes in the native order.
312
         */
313
        if (tif->tif_flags & TIFF_SWAB)
3✔
314
        {
315
            tif->tif_postdecode = _TIFFNoPostDecode;
1✔
316
        }
317
    }
318

319
    return 1;
17,646✔
320
}
321

322
#define REPEAT4(n, op)                                                         \
323
    switch (n)                                                                 \
324
    {                                                                          \
325
        default:                                                               \
326
        {                                                                      \
327
            tmsize_t i;                                                        \
328
            for (i = n - 4; i > 0; i--)                                        \
329
            {                                                                  \
330
                op;                                                            \
331
            }                                                                  \
332
        } /*-fallthrough*/                                                     \
333
        case 4:                                                                \
334
            op; /*-fallthrough*/                                               \
335
        case 3:                                                                \
336
            op; /*-fallthrough*/                                               \
337
        case 2:                                                                \
338
            op; /*-fallthrough*/                                               \
339
        case 1:                                                                \
340
            op; /*-fallthrough*/                                               \
341
        case 0:;                                                               \
342
    }
343

344
/* Remarks related to C standard compliance in all below functions : */
345
/* - to avoid any undefined behavior, we only operate on unsigned types */
346
/*   since the behavior of "overflows" is defined (wrap over) */
347
/* - when storing into the byte stream, we explicitly mask with 0xff so */
348
/*   as to make icc -check=conversions happy (not necessary by the standard) */
349

350
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
351
static int horAcc8(TIFF *tif, uint8_t *cp0, tmsize_t cc)
67,006✔
352
{
353
    tmsize_t stride = PredictorState(tif)->stride;
67,006✔
354

355
    uint8_t *cp = cp0;
67,006✔
356
    if ((cc % stride) != 0)
67,006✔
357
    {
358
        TIFFErrorExtR(tif, "horAcc8", "%s", "(cc%stride)!=0");
×
359
        return 0;
×
360
    }
361

362
    if (cc > stride)
67,006✔
363
    {
364
        /*
365
         * Pipeline the most common cases.
366
         */
367
        if (stride == 1)
67,006✔
368
        {
369
            uint32_t acc = cp[0];
64,635✔
370
            tmsize_t i = stride;
64,635✔
371
            for (; i < cc - 3; i += 4)
4,126,060✔
372
            {
373
                cp[i + 0] = (uint8_t)((acc += cp[i + 0]) & 0xff);
4,061,420✔
374
                cp[i + 1] = (uint8_t)((acc += cp[i + 1]) & 0xff);
4,061,420✔
375
                cp[i + 2] = (uint8_t)((acc += cp[i + 2]) & 0xff);
4,061,420✔
376
                cp[i + 3] = (uint8_t)((acc += cp[i + 3]) & 0xff);
4,061,420✔
377
            }
378
            for (; i < cc; i++)
258,536✔
379
            {
380
                cp[i + 0] = (uint8_t)((acc += cp[i + 0]) & 0xff);
193,901✔
381
            }
382
        }
383
        else if (stride == 3)
2,371✔
384
        {
385
            uint32_t cr = cp[0];
2,305✔
386
            uint32_t cg = cp[1];
2,305✔
387
            uint32_t cb = cp[2];
2,305✔
388
            tmsize_t i = stride;
2,305✔
389
            for (; i < cc; i += stride)
36,868✔
390
            {
391
                cp[i + 0] = (uint8_t)((cr += cp[i + 0]) & 0xff);
34,563✔
392
                cp[i + 1] = (uint8_t)((cg += cp[i + 1]) & 0xff);
34,563✔
393
                cp[i + 2] = (uint8_t)((cb += cp[i + 2]) & 0xff);
34,563✔
394
            }
395
        }
396
        else if (stride == 4)
66✔
397
        {
398
            uint32_t cr = cp[0];
65✔
399
            uint32_t cg = cp[1];
65✔
400
            uint32_t cb = cp[2];
65✔
401
            uint32_t ca = cp[3];
65✔
402
            tmsize_t i = stride;
65✔
403
            for (; i < cc; i += stride)
2,052✔
404
            {
405
                cp[i + 0] = (uint8_t)((cr += cp[i + 0]) & 0xff);
1,987✔
406
                cp[i + 1] = (uint8_t)((cg += cp[i + 1]) & 0xff);
1,987✔
407
                cp[i + 2] = (uint8_t)((cb += cp[i + 2]) & 0xff);
1,987✔
408
                cp[i + 3] = (uint8_t)((ca += cp[i + 3]) & 0xff);
1,987✔
409
            }
410
        }
411
        else
412
        {
413
            cc -= stride;
1✔
414
            do
415
            {
416
                REPEAT4(stride,
2✔
417
                        cp[stride] = (uint8_t)((cp[stride] + *cp) & 0xff);
418
                        cp++)
419
                cc -= stride;
1✔
420
            } while (cc > 0);
1✔
421
        }
422
    }
423
    return 1;
67,006✔
424
}
425

426
static int swabHorAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
245✔
427
{
428
    uint16_t *wp = (uint16_t *)cp0;
245✔
429
    tmsize_t wc = cc / 2;
245✔
430

431
    TIFFSwabArrayOfShort(wp, wc);
245✔
432
    return horAcc16(tif, cp0, cc);
245✔
433
}
434

435
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
436
static int horAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1,736✔
437
{
438
    tmsize_t stride = PredictorState(tif)->stride;
1,736✔
439
    uint16_t *wp = (uint16_t *)cp0;
1,736✔
440
    tmsize_t wc = cc / 2;
1,736✔
441

442
    if ((cc % (2 * stride)) != 0)
1,736✔
443
    {
444
        TIFFErrorExtR(tif, "horAcc16", "%s", "cc%(2*stride))!=0");
×
445
        return 0;
×
446
    }
447

448
    if (wc > stride)
1,736✔
449
    {
450
        wc -= stride;
1,736✔
451
        do
452
        {
453
            REPEAT4(stride, wp[stride] = (uint16_t)(((unsigned int)wp[stride] +
514,708✔
454
                                                     (unsigned int)wp[0]) &
455
                                                    0xffff);
456
                    wp++)
457
            wc -= stride;
514,708✔
458
        } while (wc > 0);
514,708✔
459
    }
460
    return 1;
1,736✔
461
}
462

463
static int swabHorAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1✔
464
{
465
    uint32_t *wp = (uint32_t *)cp0;
1✔
466
    tmsize_t wc = cc / 4;
1✔
467

468
    TIFFSwabArrayOfLong(wp, wc);
1✔
469
    return horAcc32(tif, cp0, cc);
1✔
470
}
471

472
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
473
static int horAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
2✔
474
{
475
    tmsize_t stride = PredictorState(tif)->stride;
2✔
476
    uint32_t *wp = (uint32_t *)cp0;
2✔
477
    tmsize_t wc = cc / 4;
2✔
478

479
    if ((cc % (4 * stride)) != 0)
2✔
480
    {
481
        TIFFErrorExtR(tif, "horAcc32", "%s", "cc%(4*stride))!=0");
×
482
        return 0;
×
483
    }
484

485
    if (wc > stride)
2✔
486
    {
487
        wc -= stride;
2✔
488
        do
489
        {
490
            REPEAT4(stride, wp[stride] += wp[0]; wp++)
10✔
491
            wc -= stride;
10✔
492
        } while (wc > 0);
10✔
493
    }
494
    return 1;
2✔
495
}
496

497
static int swabHorAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
×
498
{
499
    uint64_t *wp = (uint64_t *)cp0;
×
500
    tmsize_t wc = cc / 8;
×
501

502
    TIFFSwabArrayOfLong8(wp, wc);
×
503
    return horAcc64(tif, cp0, cc);
×
504
}
505

506
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
507
static int horAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1✔
508
{
509
    tmsize_t stride = PredictorState(tif)->stride;
1✔
510
    uint64_t *wp = (uint64_t *)cp0;
1✔
511
    tmsize_t wc = cc / 8;
1✔
512

513
    if ((cc % (8 * stride)) != 0)
1✔
514
    {
515
        TIFFErrorExtR(tif, "horAcc64", "%s", "cc%(8*stride))!=0");
×
516
        return 0;
×
517
    }
518

519
    if (wc > stride)
1✔
520
    {
521
        wc -= stride;
1✔
522
        do
523
        {
524
            REPEAT4(stride, wp[stride] += wp[0]; wp++)
1✔
525
            wc -= stride;
1✔
526
        } while (wc > 0);
1✔
527
    }
528
    return 1;
1✔
529
}
530

531
/*
532
 * Floating point predictor accumulation routine.
533
 */
534
static int fpAcc(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1,530✔
535
{
536
    tmsize_t stride = PredictorState(tif)->stride;
1,530✔
537
    uint32_t bps = tif->tif_dir.td_bitspersample / 8;
1,530✔
538
    tmsize_t wc = cc / bps;
1,530✔
539
    tmsize_t count = cc;
1,530✔
540
    uint8_t *cp = cp0;
1,530✔
541
    uint8_t *tmp;
542

543
    if (cc % (bps * stride) != 0)
1,530✔
544
    {
545
        TIFFErrorExtR(tif, "fpAcc", "%s", "cc%(bps*stride))!=0");
×
546
        return 0;
×
547
    }
548

549
    tmp = (uint8_t *)_TIFFmallocExt(tif, cc);
1,530✔
550
    if (!tmp)
1,530✔
551
        return 0;
×
552

553
    if (stride == 1)
1,530✔
554
    {
555
        /* Optimization of general case */
556
#define OP                                                                     \
557
    do                                                                         \
558
    {                                                                          \
559
        cp[1] = (uint8_t)((cp[1] + cp[0]) & 0xff);                             \
560
        ++cp;                                                                  \
561
    } while (0)
562
        for (; count > 8; count -= 8)
149,204✔
563
        {
564
            OP;
147,675✔
565
            OP;
147,675✔
566
            OP;
147,675✔
567
            OP;
147,675✔
568
            OP;
147,675✔
569
            OP;
147,675✔
570
            OP;
147,675✔
571
            OP;
147,675✔
572
        }
573
        for (; count > 1; count -= 1)
12,232✔
574
        {
575
            OP;
10,703✔
576
        }
577
#undef OP
578
    }
579
    else
580
    {
581
        while (count > stride)
16✔
582
        {
583
            REPEAT4(stride, cp[stride] = (uint8_t)((cp[stride] + cp[0]) & 0xff);
15✔
584
                    cp++)
585
            count -= stride;
15✔
586
        }
587
    }
588

589
    _TIFFmemcpy(tmp, cp0, cc);
1,530✔
590
    cp = (uint8_t *)cp0;
1,530✔
591
    count = 0;
1,530✔
592

593
#if defined(__x86_64__) || defined(_M_X64)
594
    if (bps == 4)
1,530✔
595
    {
596
        /* Optimization of general case */
597
        for (; count + 15 < wc; count += 16)
19,425✔
598
        {
599
            /* Interlace 4*16 byte values */
600

601
            __m128i xmm0 =
602
                _mm_loadu_si128((const __m128i *)(tmp + count + 3 * wc));
17,896✔
603
            __m128i xmm1 =
604
                _mm_loadu_si128((const __m128i *)(tmp + count + 2 * wc));
17,896✔
605
            __m128i xmm2 =
606
                _mm_loadu_si128((const __m128i *)(tmp + count + 1 * wc));
17,896✔
607
            __m128i xmm3 =
608
                _mm_loadu_si128((const __m128i *)(tmp + count + 0 * wc));
35,792✔
609
            /* (xmm0_0, xmm1_0, xmm0_1, xmm1_1, xmm0_2, xmm1_2, ...) */
610
            __m128i tmp0 = _mm_unpacklo_epi8(xmm0, xmm1);
17,896✔
611
            /* (xmm0_8, xmm1_8, xmm0_9, xmm1_9, xmm0_10, xmm1_10, ...) */
612
            __m128i tmp1 = _mm_unpackhi_epi8(xmm0, xmm1);
17,896✔
613
            /* (xmm2_0, xmm3_0, xmm2_1, xmm3_1, xmm2_2, xmm3_2, ...) */
614
            __m128i tmp2 = _mm_unpacklo_epi8(xmm2, xmm3);
17,896✔
615
            /* (xmm2_8, xmm3_8, xmm2_9, xmm3_9, xmm2_10, xmm3_10, ...) */
616
            __m128i tmp3 = _mm_unpackhi_epi8(xmm2, xmm3);
17,896✔
617
            /* (xmm0_0, xmm1_0, xmm2_0, xmm3_0, xmm0_1, xmm1_1, xmm2_1, xmm3_1,
618
             * ...) */
619
            __m128i tmp2_0 = _mm_unpacklo_epi16(tmp0, tmp2);
17,896✔
620
            __m128i tmp2_1 = _mm_unpackhi_epi16(tmp0, tmp2);
17,896✔
621
            __m128i tmp2_2 = _mm_unpacklo_epi16(tmp1, tmp3);
17,896✔
622
            __m128i tmp2_3 = _mm_unpackhi_epi16(tmp1, tmp3);
17,896✔
623
            _mm_storeu_si128((__m128i *)(cp + 4 * count + 0 * 16), tmp2_0);
17,896✔
624
            _mm_storeu_si128((__m128i *)(cp + 4 * count + 1 * 16), tmp2_1);
17,896✔
625
            _mm_storeu_si128((__m128i *)(cp + 4 * count + 2 * 16), tmp2_2);
17,896✔
626
            _mm_storeu_si128((__m128i *)(cp + 4 * count + 3 * 16), tmp2_3);
17,896✔
627
        }
628
    }
629
#endif
630

631
    for (; count < wc; count++)
13,606✔
632
    {
633
        uint32_t byte;
634
        for (byte = 0; byte < bps; byte++)
60,396✔
635
        {
636
#if WORDS_BIGENDIAN
637
            cp[bps * count + byte] = tmp[byte * wc + count];
638
#else
639
            cp[bps * count + byte] = tmp[(bps - byte - 1) * wc + count];
48,320✔
640
#endif
641
        }
642
    }
643
    _TIFFfreeExt(tif, tmp);
1,530✔
644
    return 1;
1,530✔
645
}
646

647
/*
648
 * Decode a scanline and apply the predictor routine.
649
 */
650
static int PredictorDecodeRow(TIFF *tif, uint8_t *op0, tmsize_t occ0,
×
651
                              uint16_t s)
652
{
653
    TIFFPredictorState *sp = PredictorState(tif);
×
654

655
    assert(sp != NULL);
×
656
    assert(sp->decoderow != NULL);
×
657
    assert(sp->decodepfunc != NULL);
×
658

659
    if ((*sp->decoderow)(tif, op0, occ0, s))
×
660
    {
661
        return (*sp->decodepfunc)(tif, op0, occ0);
×
662
    }
663
    else
664
        return 0;
×
665
}
666

667
/*
668
 * Decode a tile/strip and apply the predictor routine.
669
 * Note that horizontal differencing must be done on a
670
 * row-by-row basis.  The width of a "row" has already
671
 * been calculated at pre-decode time according to the
672
 * strip/tile dimensions.
673
 */
674
static int PredictorDecodeTile(TIFF *tif, uint8_t *op0, tmsize_t occ0,
486✔
675
                               uint16_t s)
676
{
677
    TIFFPredictorState *sp = PredictorState(tif);
486✔
678

679
    assert(sp != NULL);
486✔
680
    assert(sp->decodetile != NULL);
486✔
681

682
    if ((*sp->decodetile)(tif, op0, occ0, s))
486✔
683
    {
684
        tmsize_t rowsize = sp->rowsize;
486✔
685
        assert(rowsize > 0);
486✔
686
        if ((occ0 % rowsize) != 0)
486✔
687
        {
688
            TIFFErrorExtR(tif, "PredictorDecodeTile", "%s",
×
689
                          "occ0%rowsize != 0");
690
            return 0;
×
691
        }
692
        assert(sp->decodepfunc != NULL);
486✔
693
        while (occ0 > 0)
70,761✔
694
        {
695
            if (!(*sp->decodepfunc)(tif, op0, rowsize))
70,275✔
696
                return 0;
×
697
            occ0 -= rowsize;
70,275✔
698
            op0 += rowsize;
70,275✔
699
        }
700
        return 1;
486✔
701
    }
702
    else
703
        return 0;
×
704
}
705

706
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
707
static int horDiff8(TIFF *tif, uint8_t *cp0, tmsize_t cc)
67,478✔
708
{
709
    TIFFPredictorState *sp = PredictorState(tif);
67,478✔
710
    tmsize_t stride = sp->stride;
67,478✔
711
    unsigned char *cp = (unsigned char *)cp0;
67,478✔
712

713
    if ((cc % stride) != 0)
67,478✔
714
    {
715
        TIFFErrorExtR(tif, "horDiff8", "%s", "(cc%stride)!=0");
×
716
        return 0;
×
717
    }
718

719
    if (cc > stride)
67,478✔
720
    {
721
        cc -= stride;
67,468✔
722
        /*
723
         * Pipeline the most common cases.
724
         */
725
        if (stride == 3)
67,468✔
726
        {
727
            unsigned int r1, g1, b1;
728
            unsigned int r2 = cp[0];
897✔
729
            unsigned int g2 = cp[1];
897✔
730
            unsigned int b2 = cp[2];
897✔
731
            do
732
            {
733
                r1 = cp[3];
267,395✔
734
                cp[3] = (unsigned char)((r1 - r2) & 0xff);
267,395✔
735
                r2 = r1;
267,395✔
736
                g1 = cp[4];
267,395✔
737
                cp[4] = (unsigned char)((g1 - g2) & 0xff);
267,395✔
738
                g2 = g1;
267,395✔
739
                b1 = cp[5];
267,395✔
740
                cp[5] = (unsigned char)((b1 - b2) & 0xff);
267,395✔
741
                b2 = b1;
267,395✔
742
                cp += 3;
267,395✔
743
            } while ((cc -= 3) > 0);
267,395✔
744
        }
745
        else if (stride == 4)
66,571✔
746
        {
747
            unsigned int r1, g1, b1, a1;
748
            unsigned int r2 = cp[0];
33✔
749
            unsigned int g2 = cp[1];
33✔
750
            unsigned int b2 = cp[2];
33✔
751
            unsigned int a2 = cp[3];
33✔
752
            do
753
            {
754
                r1 = cp[4];
995✔
755
                cp[4] = (unsigned char)((r1 - r2) & 0xff);
995✔
756
                r2 = r1;
995✔
757
                g1 = cp[5];
995✔
758
                cp[5] = (unsigned char)((g1 - g2) & 0xff);
995✔
759
                g2 = g1;
995✔
760
                b1 = cp[6];
995✔
761
                cp[6] = (unsigned char)((b1 - b2) & 0xff);
995✔
762
                b2 = b1;
995✔
763
                a1 = cp[7];
995✔
764
                cp[7] = (unsigned char)((a1 - a2) & 0xff);
995✔
765
                a2 = a1;
995✔
766
                cp += 4;
995✔
767
            } while ((cc -= 4) > 0);
995✔
768
        }
769
        else
770
        {
771
            cp += cc - 1;
66,538✔
772
            do
773
            {
774
                REPEAT4(stride,
13,280,400✔
775
                        cp[stride] =
776
                            (unsigned char)((cp[stride] - cp[0]) & 0xff);
777
                        cp--)
778
            } while ((cc -= stride) > 0);
13,280,400✔
779
        }
780
    }
781
    return 1;
67,478✔
782
}
783

784
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
785
static int horDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1,014✔
786
{
787
    TIFFPredictorState *sp = PredictorState(tif);
1,014✔
788
    tmsize_t stride = sp->stride;
1,014✔
789
    uint16_t *wp = (uint16_t *)cp0;
1,014✔
790
    tmsize_t wc = cc / 2;
1,014✔
791

792
    if ((cc % (2 * stride)) != 0)
1,014✔
793
    {
794
        TIFFErrorExtR(tif, "horDiff8", "%s", "(cc%(2*stride))!=0");
×
795
        return 0;
×
796
    }
797

798
    if (wc > stride)
1,014✔
799
    {
800
        wc -= stride;
1,014✔
801
        wp += wc - 1;
1,014✔
802
        do
803
        {
804
            REPEAT4(stride, wp[stride] = (uint16_t)(((unsigned int)wp[stride] -
126,596✔
805
                                                     (unsigned int)wp[0]) &
806
                                                    0xffff);
807
                    wp--)
808
            wc -= stride;
126,596✔
809
        } while (wc > 0);
126,596✔
810
    }
811
    return 1;
1,014✔
812
}
813

814
static int swabHorDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
379✔
815
{
816
    uint16_t *wp = (uint16_t *)cp0;
379✔
817
    tmsize_t wc = cc / 2;
379✔
818

819
    if (!horDiff16(tif, cp0, cc))
379✔
820
        return 0;
×
821

822
    TIFFSwabArrayOfShort(wp, wc);
379✔
823
    return 1;
379✔
824
}
825

826
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
827
static int horDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
2✔
828
{
829
    TIFFPredictorState *sp = PredictorState(tif);
2✔
830
    tmsize_t stride = sp->stride;
2✔
831
    uint32_t *wp = (uint32_t *)cp0;
2✔
832
    tmsize_t wc = cc / 4;
2✔
833

834
    if ((cc % (4 * stride)) != 0)
2✔
835
    {
836
        TIFFErrorExtR(tif, "horDiff32", "%s", "(cc%(4*stride))!=0");
×
837
        return 0;
×
838
    }
839

840
    if (wc > stride)
2✔
841
    {
842
        wc -= stride;
2✔
843
        wp += wc - 1;
2✔
844
        do
845
        {
846
            REPEAT4(stride, wp[stride] -= wp[0]; wp--)
10✔
847
            wc -= stride;
10✔
848
        } while (wc > 0);
10✔
849
    }
850
    return 1;
2✔
851
}
852

853
static int swabHorDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1✔
854
{
855
    uint32_t *wp = (uint32_t *)cp0;
1✔
856
    tmsize_t wc = cc / 4;
1✔
857

858
    if (!horDiff32(tif, cp0, cc))
1✔
859
        return 0;
×
860

861
    TIFFSwabArrayOfLong(wp, wc);
1✔
862
    return 1;
1✔
863
}
864

865
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
866
static int horDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1✔
867
{
868
    TIFFPredictorState *sp = PredictorState(tif);
1✔
869
    tmsize_t stride = sp->stride;
1✔
870
    uint64_t *wp = (uint64_t *)cp0;
1✔
871
    tmsize_t wc = cc / 8;
1✔
872

873
    if ((cc % (8 * stride)) != 0)
1✔
874
    {
875
        TIFFErrorExtR(tif, "horDiff64", "%s", "(cc%(8*stride))!=0");
×
876
        return 0;
×
877
    }
878

879
    if (wc > stride)
1✔
880
    {
881
        wc -= stride;
1✔
882
        wp += wc - 1;
1✔
883
        do
884
        {
885
            REPEAT4(stride, wp[stride] -= wp[0]; wp--)
1✔
886
            wc -= stride;
1✔
887
        } while (wc > 0);
1✔
888
    }
889
    return 1;
1✔
890
}
891

892
static int swabHorDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
×
893
{
894
    uint64_t *wp = (uint64_t *)cp0;
×
895
    tmsize_t wc = cc / 8;
×
896

897
    if (!horDiff64(tif, cp0, cc))
×
898
        return 0;
×
899

900
    TIFFSwabArrayOfLong8(wp, wc);
×
901
    return 1;
×
902
}
903

904
/*
905
 * Floating point predictor differencing routine.
906
 */
907
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
908
static int fpDiff(TIFF *tif, uint8_t *cp0, tmsize_t cc)
22✔
909
{
910
    tmsize_t stride = PredictorState(tif)->stride;
22✔
911
    uint32_t bps = tif->tif_dir.td_bitspersample / 8;
22✔
912
    tmsize_t wc = cc / bps;
22✔
913
    tmsize_t count;
914
    uint8_t *cp = (uint8_t *)cp0;
22✔
915
    uint8_t *tmp;
916

917
    if ((cc % (bps * stride)) != 0)
22✔
918
    {
919
        TIFFErrorExtR(tif, "fpDiff", "%s", "(cc%(bps*stride))!=0");
×
920
        return 0;
×
921
    }
922

923
    tmp = (uint8_t *)_TIFFmallocExt(tif, cc);
22✔
924
    if (!tmp)
22✔
925
        return 0;
×
926

927
    _TIFFmemcpy(tmp, cp0, cc);
22✔
928
    for (count = 0; count < wc; count++)
434✔
929
    {
930
        uint32_t byte;
931
        for (byte = 0; byte < bps; byte++)
2,076✔
932
        {
933
#if WORDS_BIGENDIAN
934
            cp[byte * wc + count] = tmp[bps * count + byte];
935
#else
936
            cp[(bps - byte - 1) * wc + count] = tmp[bps * count + byte];
1,664✔
937
#endif
938
        }
939
    }
940
    _TIFFfreeExt(tif, tmp);
22✔
941

942
    cp = (uint8_t *)cp0;
22✔
943
    cp += cc - stride - 1;
22✔
944
    for (count = cc; count > stride; count -= stride)
1,648✔
945
        REPEAT4(stride,
1,626✔
946
                cp[stride] = (unsigned char)((cp[stride] - cp[0]) & 0xff);
947
                cp--)
948
    return 1;
22✔
949
}
950

951
static int PredictorEncodeRow(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
×
952
{
953
    static const char module[] = "PredictorEncodeRow";
954
    TIFFPredictorState *sp = PredictorState(tif);
×
955
    uint8_t *working_copy;
956
    int result_code;
957

958
    assert(sp != NULL);
×
959
    assert(sp->encodepfunc != NULL);
×
960
    assert(sp->encoderow != NULL);
×
961

962
    /*
963
     * Do predictor manipulation in a working buffer to avoid altering
964
     * the callers buffer, like for PredictorEncodeTile().
965
     * https://gitlab.com/libtiff/libtiff/-/issues/5
966
     */
967
    working_copy = (uint8_t *)_TIFFmallocExt(tif, cc);
×
968
    if (working_copy == NULL)
×
969
    {
970
        TIFFErrorExtR(tif, module,
×
971
                      "Out of memory allocating %" PRId64 " byte temp buffer.",
972
                      (int64_t)cc);
973
        return 0;
×
974
    }
975
    memcpy(working_copy, bp, cc);
×
976

977
    if (!(*sp->encodepfunc)(tif, working_copy, cc))
×
978
    {
979
        _TIFFfreeExt(tif, working_copy);
×
980
        return 0;
×
981
    }
982
    result_code = (*sp->encoderow)(tif, working_copy, cc, s);
×
983
    _TIFFfreeExt(tif, working_copy);
×
984
    return result_code;
×
985
}
986

987
static int PredictorEncodeTile(TIFF *tif, uint8_t *bp0, tmsize_t cc0,
313✔
988
                               uint16_t s)
989
{
990
    static const char module[] = "PredictorEncodeTile";
991
    TIFFPredictorState *sp = PredictorState(tif);
313✔
992
    uint8_t *working_copy;
993
    tmsize_t cc = cc0, rowsize;
313✔
994
    unsigned char *bp;
995
    int result_code;
996

997
    assert(sp != NULL);
313✔
998
    assert(sp->encodepfunc != NULL);
313✔
999
    assert(sp->encodetile != NULL);
313✔
1000

1001
    /*
1002
     * Do predictor manipulation in a working buffer to avoid altering
1003
     * the callers buffer. http://trac.osgeo.org/gdal/ticket/1965
1004
     */
1005
    working_copy = (uint8_t *)_TIFFmallocExt(tif, cc0);
313✔
1006
    if (working_copy == NULL)
313✔
1007
    {
1008
        TIFFErrorExtR(tif, module,
×
1009
                      "Out of memory allocating %" PRId64 " byte temp buffer.",
1010
                      (int64_t)cc0);
1011
        return 0;
×
1012
    }
1013
    memcpy(working_copy, bp0, cc0);
313✔
1014
    bp = working_copy;
313✔
1015

1016
    rowsize = sp->rowsize;
313✔
1017
    assert(rowsize > 0);
313✔
1018
    if ((cc0 % rowsize) != 0)
313✔
1019
    {
1020
        TIFFErrorExtR(tif, "PredictorEncodeTile", "%s", "(cc0%rowsize)!=0");
×
1021
        _TIFFfreeExt(tif, working_copy);
×
1022
        return 0;
×
1023
    }
1024
    while (cc > 0)
68,835✔
1025
    {
1026
        (*sp->encodepfunc)(tif, bp, rowsize);
68,513✔
1027
        cc -= rowsize;
68,522✔
1028
        bp += rowsize;
68,522✔
1029
    }
1030
    result_code = (*sp->encodetile)(tif, working_copy, cc0, s);
322✔
1031

1032
    _TIFFfreeExt(tif, working_copy);
313✔
1033

1034
    return result_code;
313✔
1035
}
1036

1037
#define FIELD_PREDICTOR (FIELD_CODEC + 0) /* XXX */
1038

1039
static const TIFFField predictFields[] = {
1040
    {TIFFTAG_PREDICTOR, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
1041
     FIELD_PREDICTOR, FALSE, FALSE, "Predictor", NULL},
1042
};
1043

1044
static int PredictorVSetField(TIFF *tif, uint32_t tag, va_list ap)
185,166✔
1045
{
1046
    TIFFPredictorState *sp = PredictorState(tif);
185,166✔
1047

1048
    assert(sp != NULL);
185,166✔
1049
    assert(sp->vsetparent != NULL);
185,166✔
1050

1051
    switch (tag)
185,166✔
1052
    {
1053
        case TIFFTAG_PREDICTOR:
6,877✔
1054
            sp->predictor = (uint16_t)va_arg(ap, uint16_vap);
6,877✔
1055
            TIFFSetFieldBit(tif, FIELD_PREDICTOR);
6,877✔
1056
            break;
6,877✔
1057
        default:
178,289✔
1058
            return (*sp->vsetparent)(tif, tag, ap);
178,289✔
1059
    }
1060
    tif->tif_flags |= TIFF_DIRTYDIRECT;
6,877✔
1061
    return 1;
6,877✔
1062
}
1063

1064
static int PredictorVGetField(TIFF *tif, uint32_t tag, va_list ap)
492,081✔
1065
{
1066
    TIFFPredictorState *sp = PredictorState(tif);
492,081✔
1067

1068
    assert(sp != NULL);
492,081✔
1069
    assert(sp->vgetparent != NULL);
492,081✔
1070

1071
    switch (tag)
492,081✔
1072
    {
1073
        case TIFFTAG_PREDICTOR:
22,122✔
1074
            *va_arg(ap, uint16_t *) = (uint16_t)sp->predictor;
22,122✔
1075
            break;
22,122✔
1076
        default:
469,959✔
1077
            return (*sp->vgetparent)(tif, tag, ap);
469,959✔
1078
    }
1079
    return 1;
22,122✔
1080
}
1081

1082
static void PredictorPrintDir(TIFF *tif, FILE *fd, long flags)
×
1083
{
1084
    TIFFPredictorState *sp = PredictorState(tif);
×
1085

1086
    (void)flags;
1087
    if (TIFFFieldSet(tif, FIELD_PREDICTOR))
×
1088
    {
1089
        fprintf(fd, "  Predictor: ");
×
1090
        switch (sp->predictor)
×
1091
        {
1092
            case 1:
×
1093
                fprintf(fd, "none ");
×
1094
                break;
×
1095
            case 2:
×
1096
                fprintf(fd, "horizontal differencing ");
×
1097
                break;
×
1098
            case 3:
×
1099
                fprintf(fd, "floating point predictor ");
×
1100
                break;
×
1101
        }
1102
        fprintf(fd, "%d (0x%x)\n", sp->predictor, sp->predictor);
×
1103
    }
1104
    if (sp->printdir)
×
1105
        (*sp->printdir)(tif, fd, flags);
×
1106
}
×
1107

1108
int TIFFPredictorInit(TIFF *tif)
28,250✔
1109
{
1110
    TIFFPredictorState *sp = PredictorState(tif);
28,250✔
1111

1112
    assert(sp != 0);
28,250✔
1113

1114
    /*
1115
     * Merge codec-specific tag information.
1116
     */
1117
    if (!_TIFFMergeFields(tif, predictFields, TIFFArrayCount(predictFields)))
28,250✔
1118
    {
UNCOV
1119
        TIFFErrorExtR(tif, "TIFFPredictorInit",
×
1120
                      "Merging Predictor codec-specific tags failed");
1121
        return 0;
×
1122
    }
1123

1124
    /*
1125
     * Override parent get/set field methods.
1126
     */
1127
    sp->vgetparent = tif->tif_tagmethods.vgetfield;
28,251✔
1128
    tif->tif_tagmethods.vgetfield =
28,251✔
1129
        PredictorVGetField; /* hook for predictor tag */
1130
    sp->vsetparent = tif->tif_tagmethods.vsetfield;
28,251✔
1131
    tif->tif_tagmethods.vsetfield =
28,251✔
1132
        PredictorVSetField; /* hook for predictor tag */
1133
    sp->printdir = tif->tif_tagmethods.printdir;
28,251✔
1134
    tif->tif_tagmethods.printdir =
28,251✔
1135
        PredictorPrintDir; /* hook for predictor tag */
1136

1137
    sp->setupdecode = tif->tif_setupdecode;
28,251✔
1138
    tif->tif_setupdecode = PredictorSetupDecode;
28,251✔
1139
    sp->setupencode = tif->tif_setupencode;
28,251✔
1140
    tif->tif_setupencode = PredictorSetupEncode;
28,251✔
1141

1142
    sp->predictor = 1;      /* default value */
28,251✔
1143
    sp->encodepfunc = NULL; /* no predictor routine */
28,251✔
1144
    sp->decodepfunc = NULL; /* no predictor routine */
28,251✔
1145
    return 1;
28,251✔
1146
}
1147

1148
int TIFFPredictorCleanup(TIFF *tif)
28,247✔
1149
{
1150
    TIFFPredictorState *sp = PredictorState(tif);
28,247✔
1151

1152
    assert(sp != 0);
28,247✔
1153

1154
    tif->tif_tagmethods.vgetfield = sp->vgetparent;
28,247✔
1155
    tif->tif_tagmethods.vsetfield = sp->vsetparent;
28,247✔
1156
    tif->tif_tagmethods.printdir = sp->printdir;
28,247✔
1157
    tif->tif_setupdecode = sp->setupdecode;
28,247✔
1158
    tif->tif_setupencode = sp->setupencode;
28,247✔
1159

1160
    return 1;
28,247✔
1161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc