LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_predict.c
Go to the documentation of this file.
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 */
35#include "tif_predict.h"
36#include "tiffiop.h"
37
38#if defined(__x86_64__) || (defined(_M_X64) && !defined(_M_ARM64EC))
39#include <emmintrin.h>
40#endif
41
42#define PredictorState(tif) ((TIFFPredictorState *)(tif)->tif_data)
43
44static int horAcc8(TIFF *tif, uint8_t *cp0, tmsize_t cc);
45static int horAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
46static int horAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
47static int horAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
48static int swabHorAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
49static int swabHorAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
50static int swabHorAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
51static int horDiff8(TIFF *tif, uint8_t *cp0, tmsize_t cc);
52static int horDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
53static int horDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
54static int horDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
55static int swabHorDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc);
56static int swabHorDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc);
57static int swabHorDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc);
58static int fpAcc(TIFF *tif, uint8_t *cp0, tmsize_t cc);
59static int fpDiff(TIFF *tif, uint8_t *cp0, tmsize_t cc);
60static int PredictorDecodeRow(TIFF *tif, uint8_t *op0, tmsize_t occ0,
61 uint16_t s);
62static int PredictorDecodeTile(TIFF *tif, uint8_t *op0, tmsize_t occ0,
63 uint16_t s);
64static int PredictorEncodeRow(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
65static int PredictorEncodeTile(TIFF *tif, uint8_t *bp0, tmsize_t cc0,
66 uint16_t s);
67
83static int PredictorSetup(TIFF *tif)
84{
85 static const char module[] = "PredictorSetup";
86
88 TIFFDirectory *td = &tif->tif_dir;
89
90 switch (sp->predictor) /* no differencing */
91 {
92 case PREDICTOR_NONE:
93 return 1;
95 if (td->td_bitspersample != 8 && td->td_bitspersample != 16 &&
96 td->td_bitspersample != 32 && td->td_bitspersample != 64)
97 {
98 TIFFErrorExtR(tif, module,
99 "Horizontal differencing \"Predictor\" not "
100 "supported with %" PRIu16 "-bit samples",
101 td->td_bitspersample);
102 return 0;
103 }
104 break;
107 {
109 tif, module,
110 "Floating point \"Predictor\" not supported with %" PRIu16
111 " data format",
112 td->td_sampleformat);
113 return 0;
114 }
115 if (td->td_bitspersample != 16 && td->td_bitspersample != 24 &&
116 td->td_bitspersample != 32 && td->td_bitspersample != 64)
117 { /* Should 64 be allowed? */
119 tif, module,
120 "Floating point \"Predictor\" not supported with %" PRIu16
121 "-bit samples",
122 td->td_bitspersample);
123 return 0;
124 }
125 break;
126 default:
127 TIFFErrorExtR(tif, module, "\"Predictor\" value %d not supported",
128 sp->predictor);
129 return 0;
130 }
131 sp->stride =
133 : 1);
134 /*
135 * Calculate the scanline/tile-width size in bytes.
136 */
137 if (isTiled(tif))
138 {
139 /* The differencing row of a tile has always been the full
140 * interleaved tile width, including for downsampled YCbCr data,
141 * where TIFFTileRowSize() now reports the subsample-aware
142 * TIFFTileSize() / TileLength quotient instead. Keep the
143 * historical length here, computed locally, so that existing
144 * Predictor files keep decoding bit-for-bit and the layouts whose
145 * tile size is not a whole number of differencing rows keep being
146 * rejected at encode time. */
147 uint64_t rowsize64 = _TIFFMultiply64(tif, td->td_bitspersample,
148 td->td_tilewidth, module);
150 rowsize64 =
151 _TIFFMultiply64(tif, rowsize64, td->td_samplesperpixel, module);
152 sp->rowsize =
153 _TIFFCastUInt64ToSSize(tif, TIFFhowmany8_64(rowsize64), module);
154 }
155 else
156 sp->rowsize = TIFFScanlineSize(tif);
157 if (sp->rowsize == 0)
158 return 0;
159
160 return 1;
161}
162
178{
180 TIFFDirectory *td = &tif->tif_dir;
181
182 /* Note: when PredictorSetup() fails, the effets of setupdecode() */
183 /* will not be "canceled" so setupdecode() might be robust to */
184 /* be called several times. */
185 if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif))
186 return 0;
187
188 if (sp->predictor == 2)
189 {
190 switch (td->td_bitspersample)
191 {
192 case 8:
193 sp->decodepfunc = horAcc8;
194 break;
195 case 16:
196 sp->decodepfunc = horAcc16;
197 break;
198 case 32:
199 sp->decodepfunc = horAcc32;
200 break;
201 case 64:
202 sp->decodepfunc = horAcc64;
203 break;
204 default:
205 break;
206 }
207 /*
208 * Override default decoding method with one that does the
209 * predictor stuff.
210 */
212 {
213 sp->decoderow = tif->tif_decoderow;
215 sp->decodestrip = tif->tif_decodestrip;
217 sp->decodetile = tif->tif_decodetile;
219 }
220
221 /*
222 * If the data is horizontally differenced 16-bit data that
223 * requires byte-swapping, then it must be byte swapped before
224 * the accumulation step. We do this with a special-purpose
225 * routine and override the normal post decoding logic that
226 * the library setup when the directory was read.
227 */
228 if (tif->tif_flags & TIFF_SWAB)
229 {
230 if (sp->decodepfunc == horAcc16)
231 {
234 }
235 else if (sp->decodepfunc == horAcc32)
236 {
239 }
240 else if (sp->decodepfunc == horAcc64)
241 {
244 }
245 }
246 }
247
248 else if (sp->predictor == 3)
249 {
250 sp->decodepfunc = fpAcc;
251 /*
252 * Override default decoding method with one that does the
253 * predictor stuff.
254 */
256 {
257 sp->decoderow = tif->tif_decoderow;
259 sp->decodestrip = tif->tif_decodestrip;
261 sp->decodetile = tif->tif_decodetile;
263 }
264 /*
265 * The data should not be swapped outside of the floating
266 * point predictor, the accumulation routine should return
267 * bytes in the native order.
268 */
269 if (tif->tif_flags & TIFF_SWAB)
270 {
272 }
273 }
274
275 return 1;
276}
277
292{
294 TIFFDirectory *td = &tif->tif_dir;
295
296 if (!(*sp->setupencode)(tif) || !PredictorSetup(tif))
297 return 0;
298
299 if (sp->predictor == 2)
300 {
301 switch (td->td_bitspersample)
302 {
303 case 8:
304 sp->encodepfunc = horDiff8;
305 break;
306 case 16:
308 break;
309 case 32:
311 break;
312 case 64:
314 break;
315 default:
316 break;
317 }
318 /*
319 * Override default encoding method with one that does the
320 * predictor stuff.
321 */
323 {
324 sp->encoderow = tif->tif_encoderow;
326 sp->encodestrip = tif->tif_encodestrip;
328 sp->encodetile = tif->tif_encodetile;
330 }
331
332 /*
333 * If the data is horizontally differenced 16-bit data that
334 * requires byte-swapping, then it must be byte swapped after
335 * the differentiation step. We do this with a special-purpose
336 * routine and override the normal post decoding logic that
337 * the library setup when the directory was read.
338 */
339 if (tif->tif_flags & TIFF_SWAB)
340 {
341 if (sp->encodepfunc == horDiff16)
342 {
345 }
346 else if (sp->encodepfunc == horDiff32)
347 {
350 }
351 else if (sp->encodepfunc == horDiff64)
352 {
355 }
356 }
357 }
358
359 else if (sp->predictor == 3)
360 {
361 sp->encodepfunc = fpDiff;
362 /*
363 * Override default encoding method with one that does the
364 * predictor stuff.
365 */
367 {
368 sp->encoderow = tif->tif_encoderow;
370 sp->encodestrip = tif->tif_encodestrip;
372 sp->encodetile = tif->tif_encodetile;
374 }
375 /*
376 * The data should not be swapped outside of the floating
377 * point predictor, the differentiation routine should return
378 * bytes in the native order.
379 */
380 if (tif->tif_flags & TIFF_SWAB)
381 {
383 }
384 }
385
386 return 1;
387}
388
389#define REPEAT4(n, op) \
390 switch (n) \
391 { \
392 default: \
393 { \
394 tmsize_t i; \
395 for (i = n - 4; i > 0; i--) \
396 { \
397 op; \
398 } \
399 } /*-fallthrough*/ \
400 case 4: \
401 op; /*-fallthrough*/ \
402 case 3: \
403 op; /*-fallthrough*/ \
404 case 2: \
405 op; /*-fallthrough*/ \
406 case 1: \
407 op; /*-fallthrough*/ \
408 case 0:; \
409 }
410
411/* Remarks related to C standard compliance in all below functions : */
412/* - to avoid any undefined behavior, we only operate on unsigned types */
413/* since the behavior of "overflows" is defined (wrap over) */
414/* - when storing into the byte stream, we explicitly mask with 0xff so */
415/* as to make icc -check=conversions happy (not necessary by the standard) */
416
417/*
418 * Predictor accumulation works on native-order samples. If the TIFF byte
419 * order differs from host byte order, the swab wrapper first swaps the byte
420 * stream explicitly. These helpers only avoid unaligned typed dereferences.
421 * Use fixed-size memcpy() calls directly so optimizing compilers can expand
422 * them in this per-sample hot path. _TIFFmemcpy() is an out-of-line wrapper
423 * in non-LTO builds.
424 */
440static void PredictorAccumulate16NativeUnaligned(uint8_t *current,
441 const uint8_t *previous)
442{
443 uint16_t thisval;
444 uint16_t prevval;
445 memcpy(&thisval, current, sizeof(thisval));
446 memcpy(&prevval, previous, sizeof(prevval));
447 thisval =
448 (uint16_t)(((unsigned int)thisval + (unsigned int)prevval) & 0xffff);
449 memcpy(current, &thisval, sizeof(thisval));
450}
451
467static void PredictorAccumulate32NativeUnaligned(uint8_t *current,
468 const uint8_t *previous)
469{
470 uint32_t thisval;
471 uint32_t prevval;
472 memcpy(&thisval, current, sizeof(thisval));
473 memcpy(&prevval, previous, sizeof(prevval));
474 thisval += prevval;
475 memcpy(current, &thisval, sizeof(thisval));
476}
477
493static void PredictorAccumulate64NativeUnaligned(uint8_t *current,
494 const uint8_t *previous)
495{
496 uint64_t thisval;
497 uint64_t prevval;
498 memcpy(&thisval, current, sizeof(thisval));
499 memcpy(&prevval, previous, sizeof(prevval));
500 thisval += prevval;
501 memcpy(current, &thisval, sizeof(thisval));
502}
503
514static void PredictorSwabByteStream16(uint8_t *cp, tmsize_t n)
515{
516 while (n-- > 0)
517 {
518 uint8_t tmp = cp[0];
519 cp[0] = cp[1];
520 cp[1] = tmp;
521 cp += 2;
522 }
523}
524
535static void PredictorSwabByteStream32(uint8_t *cp, tmsize_t n)
536{
537 while (n-- > 0)
538 {
539 uint8_t tmp = cp[0];
540 cp[0] = cp[3];
541 cp[3] = tmp;
542 tmp = cp[1];
543 cp[1] = cp[2];
544 cp[2] = tmp;
545 cp += 4;
546 }
547}
548
559static void PredictorSwabByteStream64(uint8_t *cp, tmsize_t n)
560{
561 while (n-- > 0)
562 {
563 uint8_t tmp = cp[0];
564 cp[0] = cp[7];
565 cp[7] = tmp;
566 tmp = cp[1];
567 cp[1] = cp[6];
568 cp[6] = tmp;
569 tmp = cp[2];
570 cp[2] = cp[5];
571 cp[5] = tmp;
572 tmp = cp[3];
573 cp[3] = cp[4];
574 cp[4] = tmp;
575 cp += 8;
576 }
577}
578
596static int horAcc8(TIFF *tif, uint8_t *cp0, tmsize_t cc)
597{
598 tmsize_t stride = PredictorState(tif)->stride;
599
600 uint8_t *cp = cp0;
601 if ((cc % stride) != 0)
602 {
603 TIFFErrorExtR(tif, "horAcc8", "%s", "(cc%stride)!=0");
604 return 0;
605 }
606
607 if (cc > stride)
608 {
609 /*
610 * Pipeline the most common cases.
611 */
612 if (stride == 1)
613 {
614 uint32_t acc = cp[0];
615 tmsize_t i = stride;
616 for (; i < cc - 3; i += 4)
617 {
618 cp[i + 0] = (uint8_t)((acc += cp[i + 0]) & 0xff);
619 cp[i + 1] = (uint8_t)((acc += cp[i + 1]) & 0xff);
620 cp[i + 2] = (uint8_t)((acc += cp[i + 2]) & 0xff);
621 cp[i + 3] = (uint8_t)((acc += cp[i + 3]) & 0xff);
622 }
623 for (; i < cc; i++)
624 {
625 cp[i + 0] = (uint8_t)((acc += cp[i + 0]) & 0xff);
626 }
627 }
628 else if (stride == 3)
629 {
630 uint32_t cr = cp[0];
631 uint32_t cg = cp[1];
632 uint32_t cb = cp[2];
633 tmsize_t i = stride;
634 for (; i < cc; i += stride)
635 {
636 cp[i + 0] = (uint8_t)((cr += cp[i + 0]) & 0xff);
637 cp[i + 1] = (uint8_t)((cg += cp[i + 1]) & 0xff);
638 cp[i + 2] = (uint8_t)((cb += cp[i + 2]) & 0xff);
639 }
640 }
641 else if (stride == 4)
642 {
643 uint32_t cr = cp[0];
644 uint32_t cg = cp[1];
645 uint32_t cb = cp[2];
646 uint32_t ca = cp[3];
647 tmsize_t i = stride;
648 for (; i < cc; i += stride)
649 {
650 cp[i + 0] = (uint8_t)((cr += cp[i + 0]) & 0xff);
651 cp[i + 1] = (uint8_t)((cg += cp[i + 1]) & 0xff);
652 cp[i + 2] = (uint8_t)((cb += cp[i + 2]) & 0xff);
653 cp[i + 3] = (uint8_t)((ca += cp[i + 3]) & 0xff);
654 }
655 }
656 else
657 {
658 cc -= stride;
659 do
660 {
661 REPEAT4(stride,
662 cp[stride] = (uint8_t)((cp[stride] + *cp) & 0xff);
663 cp++)
664 cc -= stride;
665 } while (cc > 0);
666 }
667 }
668 return 1;
669}
670
689static int swabHorAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
690{
691 tmsize_t wc = cc / 2;
692
694 return horAcc16(tif, cp0, cc);
695}
696
715static int horAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
716{
717 tmsize_t stride = PredictorState(tif)->stride;
718 uint8_t *cp = cp0;
719 tmsize_t wc = cc / 2;
720
721 if ((cc % (2 * stride)) != 0)
722 {
723 TIFFErrorExtR(tif, "horAcc16", "%s", "cc%(2*stride))!=0");
724 return 0;
725 }
726
727 if (wc > stride)
728 {
729 wc -= stride;
730 do
731 {
732 REPEAT4(stride,
733 PredictorAccumulate16NativeUnaligned(cp + 2 * stride, cp);
734 cp += 2)
735 wc -= stride;
736 } while (wc > 0);
737 }
738 return 1;
739}
740
759static int swabHorAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
760{
761 tmsize_t wc = cc / 4;
762
764 return horAcc32(tif, cp0, cc);
765}
766
785static int horAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
786{
787 tmsize_t stride = PredictorState(tif)->stride;
788 uint8_t *cp = cp0;
789 tmsize_t wc = cc / 4;
790
791 if ((cc % (4 * stride)) != 0)
792 {
793 TIFFErrorExtR(tif, "horAcc32", "%s", "cc%(4*stride))!=0");
794 return 0;
795 }
796
797 if (wc > stride)
798 {
799 wc -= stride;
800 do
801 {
802 REPEAT4(stride,
803 PredictorAccumulate32NativeUnaligned(cp + 4 * stride, cp);
804 cp += 4)
805 wc -= stride;
806 } while (wc > 0);
807 }
808 return 1;
809}
810
829static int swabHorAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
830{
831 tmsize_t wc = cc / 8;
832
834 return horAcc64(tif, cp0, cc);
835}
836
855static int horAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
856{
857 tmsize_t stride = PredictorState(tif)->stride;
858 uint8_t *cp = cp0;
859 tmsize_t wc = cc / 8;
860
861 if ((cc % (8 * stride)) != 0)
862 {
863 TIFFErrorExtR(tif, "horAcc64", "%s", "cc%(8*stride))!=0");
864 return 0;
865 }
866
867 if (wc > stride)
868 {
869 wc -= stride;
870 do
871 {
872 REPEAT4(stride,
873 PredictorAccumulate64NativeUnaligned(cp + 8 * stride, cp);
874 cp += 8)
875 wc -= stride;
876 } while (wc > 0);
877 }
878 return 1;
879}
880
881/*
882 * Floating point predictor accumulation routine.
883 */
903static int fpAcc(TIFF *tif, uint8_t *cp0, tmsize_t cc)
904{
905 tmsize_t stride = PredictorState(tif)->stride;
906 uint32_t bps = tif->tif_dir.td_bitspersample / 8;
907 tmsize_t wc = cc / bps;
908 tmsize_t count = cc;
909 uint8_t *cp = cp0;
910 uint8_t *tmp;
911
912 if (cc % (bps * stride) != 0)
913 {
914 TIFFErrorExtR(tif, "fpAcc", "%s", "cc%(bps*stride))!=0");
915 return 0;
916 }
917
918 tmp = (uint8_t *)_TIFFmallocExt(tif, cc);
919 if (!tmp)
920 return 0;
921
922 if (stride == 1)
923 {
924 /* Optimization of general case */
925#define OP \
926 do \
927 { \
928 cp[1] = (uint8_t)((cp[1] + cp[0]) & 0xff); \
929 ++cp; \
930 } while (0)
931 for (; count > 8; count -= 8)
932 {
933 OP;
934 OP;
935 OP;
936 OP;
937 OP;
938 OP;
939 OP;
940 OP;
941 }
942 for (; count > 1; count -= 1)
943 {
944 OP;
945 }
946#undef OP
947 }
948 else
949 {
950 while (count > stride)
951 {
952 REPEAT4(stride, cp[stride] = (uint8_t)((cp[stride] + cp[0]) & 0xff);
953 cp++)
954 count -= stride;
955 }
956 }
957
958 _TIFFmemcpy(tmp, cp0, cc);
959 cp = (uint8_t *)cp0;
960 count = 0;
961
962#if defined(__x86_64__) || (defined(_M_X64) && !defined(_M_ARM64EC))
963 if (bps == 4)
964 {
965 /* Optimization of general case */
966 for (; count + 15 < wc; count += 16)
967 {
968 /* Interlace 4*16 byte values */
969
970 __m128i xmm0 =
971 _mm_loadu_si128((const __m128i *)(tmp + count + 3 * wc));
972 __m128i xmm1 =
973 _mm_loadu_si128((const __m128i *)(tmp + count + 2 * wc));
974 __m128i xmm2 =
975 _mm_loadu_si128((const __m128i *)(tmp + count + 1 * wc));
976 __m128i xmm3 =
977 _mm_loadu_si128((const __m128i *)(tmp + count + 0 * wc));
978 /* (xmm0_0, xmm1_0, xmm0_1, xmm1_1, xmm0_2, xmm1_2, ...) */
979 __m128i tmp0 = _mm_unpacklo_epi8(xmm0, xmm1);
980 /* (xmm0_8, xmm1_8, xmm0_9, xmm1_9, xmm0_10, xmm1_10, ...) */
981 __m128i tmp1 = _mm_unpackhi_epi8(xmm0, xmm1);
982 /* (xmm2_0, xmm3_0, xmm2_1, xmm3_1, xmm2_2, xmm3_2, ...) */
983 __m128i tmp2 = _mm_unpacklo_epi8(xmm2, xmm3);
984 /* (xmm2_8, xmm3_8, xmm2_9, xmm3_9, xmm2_10, xmm3_10, ...) */
985 __m128i tmp3 = _mm_unpackhi_epi8(xmm2, xmm3);
986 /* (xmm0_0, xmm1_0, xmm2_0, xmm3_0, xmm0_1, xmm1_1, xmm2_1, xmm3_1,
987 * ...) */
988 __m128i tmp2_0 = _mm_unpacklo_epi16(tmp0, tmp2);
989 __m128i tmp2_1 = _mm_unpackhi_epi16(tmp0, tmp2);
990 __m128i tmp2_2 = _mm_unpacklo_epi16(tmp1, tmp3);
991 __m128i tmp2_3 = _mm_unpackhi_epi16(tmp1, tmp3);
992 _mm_storeu_si128((__m128i *)(cp + 4 * count + 0 * 16), tmp2_0);
993 _mm_storeu_si128((__m128i *)(cp + 4 * count + 1 * 16), tmp2_1);
994 _mm_storeu_si128((__m128i *)(cp + 4 * count + 2 * 16), tmp2_2);
995 _mm_storeu_si128((__m128i *)(cp + 4 * count + 3 * 16), tmp2_3);
996 }
997 }
998#endif
999
1000 for (; count < wc; count++)
1001 {
1002 uint32_t byte;
1003 for (byte = 0; byte < bps; byte++)
1004 {
1005#if WORDS_BIGENDIAN
1006 cp[bps * count + byte] = tmp[byte * wc + count];
1007#else
1008 cp[bps * count + byte] = tmp[(bps - byte - 1) * wc + count];
1009#endif
1010 }
1011 }
1012 _TIFFfreeExt(tif, tmp);
1013 return 1;
1014}
1015
1016/*
1017 * Decode a scanline and apply the predictor routine.
1018 */
1036static int PredictorDecodeRow(TIFF *tif, uint8_t *op0, tmsize_t occ0,
1037 uint16_t s)
1038{
1040
1041 assert(sp != NULL);
1042 assert(sp->decoderow != NULL);
1043 assert(sp->decodepfunc != NULL);
1044
1045 if ((*sp->decoderow)(tif, op0, occ0, s))
1046 {
1047 return (*sp->decodepfunc)(tif, op0, occ0);
1048 }
1049 else
1050 return 0;
1051}
1052
1053/*
1054 * Decode a tile/strip and apply the predictor routine.
1055 * Note that horizontal differencing must be done on a
1056 * row-by-row basis. The width of a "row" has already
1057 * been calculated at pre-decode time according to the
1058 * strip/tile dimensions.
1059 */
1078static int PredictorDecodeTile(TIFF *tif, uint8_t *op0, tmsize_t occ0,
1079 uint16_t s)
1080{
1082
1083 assert(sp != NULL);
1084 assert(sp->decodetile != NULL);
1085
1086 if ((*sp->decodetile)(tif, op0, occ0, s))
1087 {
1088 tmsize_t rowsize = sp->rowsize;
1089 assert(rowsize > 0);
1090 if ((occ0 % rowsize) != 0)
1091 {
1092 TIFFErrorExtR(tif, "PredictorDecodeTile", "%s",
1093 "occ0%rowsize != 0");
1094 return 0;
1095 }
1096 assert(sp->decodepfunc != NULL);
1097 while (occ0 > 0)
1098 {
1099 if (!(*sp->decodepfunc)(tif, op0, rowsize))
1100 return 0;
1101 occ0 -= rowsize;
1102 op0 += rowsize;
1103 }
1104 return 1;
1105 }
1106 else
1107 return 0;
1108}
1109
1127static int horDiff8(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1128{
1130 tmsize_t stride = sp->stride;
1131 unsigned char *cp = (unsigned char *)cp0;
1132
1133 if ((cc % stride) != 0)
1134 {
1135 TIFFErrorExtR(tif, "horDiff8", "%s", "(cc%stride)!=0");
1136 return 0;
1137 }
1138
1139 if (cc > stride)
1140 {
1141 cc -= stride;
1142 /*
1143 * Pipeline the most common cases.
1144 */
1145 if (stride == 3)
1146 {
1147 unsigned int r1, g1, b1;
1148 unsigned int r2 = cp[0];
1149 unsigned int g2 = cp[1];
1150 unsigned int b2 = cp[2];
1151 do
1152 {
1153 r1 = cp[3];
1154 cp[3] = (unsigned char)((r1 - r2) & 0xff);
1155 r2 = r1;
1156 g1 = cp[4];
1157 cp[4] = (unsigned char)((g1 - g2) & 0xff);
1158 g2 = g1;
1159 b1 = cp[5];
1160 cp[5] = (unsigned char)((b1 - b2) & 0xff);
1161 b2 = b1;
1162 cp += 3;
1163 } while ((cc -= 3) > 0);
1164 }
1165 else if (stride == 4)
1166 {
1167 unsigned int r1, g1, b1, a1;
1168 unsigned int r2 = cp[0];
1169 unsigned int g2 = cp[1];
1170 unsigned int b2 = cp[2];
1171 unsigned int a2 = cp[3];
1172 do
1173 {
1174 r1 = cp[4];
1175 cp[4] = (unsigned char)((r1 - r2) & 0xff);
1176 r2 = r1;
1177 g1 = cp[5];
1178 cp[5] = (unsigned char)((g1 - g2) & 0xff);
1179 g2 = g1;
1180 b1 = cp[6];
1181 cp[6] = (unsigned char)((b1 - b2) & 0xff);
1182 b2 = b1;
1183 a1 = cp[7];
1184 cp[7] = (unsigned char)((a1 - a2) & 0xff);
1185 a2 = a1;
1186 cp += 4;
1187 } while ((cc -= 4) > 0);
1188 }
1189 else
1190 {
1191 cp += cc - 1;
1192 do
1193 {
1194 REPEAT4(stride,
1195 cp[stride] =
1196 (unsigned char)((cp[stride] - cp[0]) & 0xff);
1197 cp--)
1198 } while ((cc -= stride) > 0);
1199 }
1200 }
1201 return 1;
1202}
1203
1222static int horDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1223{
1225 tmsize_t stride = sp->stride;
1226 uint16_t *wp = (uint16_t *)cp0;
1227 tmsize_t wc = cc / 2;
1228
1229 if ((cc % (2 * stride)) != 0)
1230 {
1231 TIFFErrorExtR(tif, "horDiff8", "%s", "(cc%(2*stride))!=0");
1232 return 0;
1233 }
1234
1235 if (wc > stride)
1236 {
1237 wc -= stride;
1238 wp += wc - 1;
1239 do
1240 {
1241 REPEAT4(stride, wp[stride] = (uint16_t)(((unsigned int)wp[stride] -
1242 (unsigned int)wp[0]) &
1243 0xffff);
1244 wp--)
1245 wc -= stride;
1246 } while (wc > 0);
1247 }
1248 return 1;
1249}
1250
1268static int swabHorDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1269{
1270 uint16_t *wp = (uint16_t *)cp0;
1271 tmsize_t wc = cc / 2;
1272
1273 if (!horDiff16(tif, cp0, cc))
1274 return 0;
1275
1276 TIFFSwabArrayOfShort(wp, wc);
1277 return 1;
1278}
1279
1298static int horDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1299{
1301 tmsize_t stride = sp->stride;
1302 uint32_t *wp = (uint32_t *)cp0;
1303 tmsize_t wc = cc / 4;
1304
1305 if ((cc % (4 * stride)) != 0)
1306 {
1307 TIFFErrorExtR(tif, "horDiff32", "%s", "(cc%(4*stride))!=0");
1308 return 0;
1309 }
1310
1311 if (wc > stride)
1312 {
1313 wc -= stride;
1314 wp += wc - 1;
1315 do
1316 {
1317 REPEAT4(stride, wp[stride] -= wp[0]; wp--)
1318 wc -= stride;
1319 } while (wc > 0);
1320 }
1321 return 1;
1322}
1323
1341static int swabHorDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1342{
1343 uint32_t *wp = (uint32_t *)cp0;
1344 tmsize_t wc = cc / 4;
1345
1346 if (!horDiff32(tif, cp0, cc))
1347 return 0;
1348
1349 TIFFSwabArrayOfLong(wp, wc);
1350 return 1;
1351}
1352
1371static int horDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1372{
1374 tmsize_t stride = sp->stride;
1375 uint64_t *wp = (uint64_t *)cp0;
1376 tmsize_t wc = cc / 8;
1377
1378 if ((cc % (8 * stride)) != 0)
1379 {
1380 TIFFErrorExtR(tif, "horDiff64", "%s", "(cc%(8*stride))!=0");
1381 return 0;
1382 }
1383
1384 if (wc > stride)
1385 {
1386 wc -= stride;
1387 wp += wc - 1;
1388 do
1389 {
1390 REPEAT4(stride, wp[stride] -= wp[0]; wp--)
1391 wc -= stride;
1392 } while (wc > 0);
1393 }
1394 return 1;
1395}
1396
1414static int swabHorDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1415{
1416 uint64_t *wp = (uint64_t *)cp0;
1417 tmsize_t wc = cc / 8;
1418
1419 if (!horDiff64(tif, cp0, cc))
1420 return 0;
1421
1422 TIFFSwabArrayOfLong8(wp, wc);
1423 return 1;
1424}
1425
1426/*
1427 * Floating point predictor differencing routine.
1428 */
1449static int fpDiff(TIFF *tif, uint8_t *cp0, tmsize_t cc)
1450{
1451 tmsize_t stride = PredictorState(tif)->stride;
1452 uint32_t bps = tif->tif_dir.td_bitspersample / 8;
1453 tmsize_t wc = cc / bps;
1454 tmsize_t count;
1455 uint8_t *cp = (uint8_t *)cp0;
1456 uint8_t *tmp;
1457
1458 if ((cc % (bps * stride)) != 0)
1459 {
1460 TIFFErrorExtR(tif, "fpDiff", "%s", "(cc%(bps*stride))!=0");
1461 return 0;
1462 }
1463
1464 tmp = (uint8_t *)_TIFFmallocExt(tif, cc);
1465 if (!tmp)
1466 return 0;
1467
1468 _TIFFmemcpy(tmp, cp0, cc);
1469 for (count = 0; count < wc; count++)
1470 {
1471 uint32_t byte;
1472 for (byte = 0; byte < bps; byte++)
1473 {
1474#if WORDS_BIGENDIAN
1475 cp[byte * wc + count] = tmp[bps * count + byte];
1476#else
1477 cp[(bps - byte - 1) * wc + count] = tmp[bps * count + byte];
1478#endif
1479 }
1480 }
1481 _TIFFfreeExt(tif, tmp);
1482
1483 cp = (uint8_t *)cp0;
1484 cp += cc - stride - 1;
1485 for (count = cc; count > stride; count -= stride)
1486 REPEAT4(stride,
1487 cp[stride] = (unsigned char)((cp[stride] - cp[0]) & 0xff);
1488 cp--)
1489 return 1;
1490}
1491
1510static int PredictorEncodeRow(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
1511{
1512 static const char module[] = "PredictorEncodeRow";
1514 uint8_t *working_copy;
1515 int result_code;
1516
1517 assert(sp != NULL);
1518 assert(sp->encodepfunc != NULL);
1519 assert(sp->encoderow != NULL);
1520
1521 /*
1522 * Do predictor manipulation in a working buffer to avoid altering
1523 * the callers buffer, like for PredictorEncodeTile().
1524 * https://gitlab.com/libtiff/libtiff/-/issues/5
1525 */
1526 working_copy = (uint8_t *)_TIFFmallocExt(tif, cc);
1527 if (working_copy == NULL)
1528 {
1529 TIFFErrorExtR(tif, module,
1530 "Out of memory allocating %" PRId64 " byte temp buffer.",
1531 (int64_t)cc);
1532 return 0;
1533 }
1534 memcpy(working_copy, bp, (size_t)cc);
1535
1536 if (!(*sp->encodepfunc)(tif, working_copy, cc))
1537 {
1538 _TIFFfreeExt(tif, working_copy);
1539 return 0;
1540 }
1541 result_code = (*sp->encoderow)(tif, working_copy, cc, s);
1542 _TIFFfreeExt(tif, working_copy);
1543 return result_code;
1544}
1545
1566static int PredictorEncodeTile(TIFF *tif, uint8_t *bp0, tmsize_t cc0,
1567 uint16_t s)
1568{
1569 static const char module[] = "PredictorEncodeTile";
1571 uint8_t *working_copy;
1572 tmsize_t cc = cc0, rowsize;
1573 unsigned char *bp;
1574 int result_code;
1575
1576 assert(sp != NULL);
1577 assert(sp->encodepfunc != NULL);
1578 assert(sp->encodetile != NULL);
1579
1580 /*
1581 * Do predictor manipulation in a working buffer to avoid altering
1582 * the callers buffer. http://trac.osgeo.org/gdal/ticket/1965
1583 */
1584 working_copy = (uint8_t *)_TIFFmallocExt(tif, cc0);
1585 if (working_copy == NULL)
1586 {
1587 TIFFErrorExtR(tif, module,
1588 "Out of memory allocating %" PRId64 " byte temp buffer.",
1589 (int64_t)cc0);
1590 return 0;
1591 }
1592 memcpy(working_copy, bp0, (size_t)cc0);
1593 bp = working_copy;
1594
1595 rowsize = sp->rowsize;
1596 assert(rowsize > 0);
1597 if ((cc0 % rowsize) != 0)
1598 {
1599 TIFFErrorExtR(tif, "PredictorEncodeTile", "%s", "(cc0%rowsize)!=0");
1600 _TIFFfreeExt(tif, working_copy);
1601 return 0;
1602 }
1603 while (cc > 0)
1604 {
1605 if (!(*sp->encodepfunc)(tif, bp, rowsize))
1606 {
1607 _TIFFfreeExt(tif, working_copy);
1608 return 0;
1609 }
1610 cc -= rowsize;
1611 bp += rowsize;
1612 }
1613 result_code = (*sp->encodetile)(tif, working_copy, cc0, s);
1614
1615 _TIFFfreeExt(tif, working_copy);
1616
1617 return result_code;
1618}
1619
1620#define FIELD_PREDICTOR (FIELD_CODEC + 0) /* XXX */
1621
1629static const TIFFField predictFields[] = {
1631 FIELD_PREDICTOR, FALSE, FALSE, "Predictor", NULL},
1632};
1633
1652static int PredictorVSetField(TIFF *tif, uint32_t tag, va_list ap)
1653{
1655
1656 assert(sp != NULL);
1657 assert(sp->vsetparent != NULL);
1658
1659 switch (tag)
1660 {
1661 case TIFFTAG_PREDICTOR:
1662 sp->predictor = (uint16_t)va_arg(ap, uint16_vap);
1664 break;
1665 default:
1666 return (*sp->vsetparent)(tif, tag, ap);
1667 }
1669 return 1;
1670}
1671
1689static int PredictorVGetField(TIFF *tif, uint32_t tag, va_list ap)
1690{
1692
1693 assert(sp != NULL);
1694 assert(sp->vgetparent != NULL);
1695
1696 switch (tag)
1697 {
1698 case TIFFTAG_PREDICTOR:
1699 *va_arg(ap, uint16_t *) = (uint16_t)sp->predictor;
1700 break;
1701 default:
1702 return (*sp->vgetparent)(tif, tag, ap);
1703 }
1704 return 1;
1705}
1706
1721static void PredictorPrintDir(TIFF *tif, FILE *fd, long flags)
1722{
1724
1725 (void)flags;
1726 if (TIFFFieldSet(tif, FIELD_PREDICTOR))
1727 {
1728 fprintf(fd, " Predictor: ");
1729 switch (sp->predictor)
1730 {
1731 case 1:
1732 fprintf(fd, "none ");
1733 break;
1734 case 2:
1735 fprintf(fd, "horizontal differencing ");
1736 break;
1737 case 3:
1738 fprintf(fd, "floating point predictor ");
1739 break;
1740 default:
1741 break;
1742 }
1743 fprintf(fd, "%d (0x%x)\n", sp->predictor, (unsigned)sp->predictor);
1744 }
1745 if (sp->printdir)
1746 (*sp->printdir)(tif, fd, flags);
1747}
1748
1750{
1752
1753 assert(sp != 0);
1754
1755 /*
1756 * Merge codec-specific tag information.
1757 */
1759 {
1760 TIFFErrorExtR(tif, "TIFFPredictorInit",
1761 "Merging Predictor codec-specific tags failed");
1762 return 0;
1763 }
1764
1765 /*
1766 * Override parent get/set field methods.
1767 */
1770 PredictorVGetField; /* hook for predictor tag */
1773 PredictorVSetField; /* hook for predictor tag */
1774 sp->printdir = tif->tif_tagmethods.printdir;
1776 PredictorPrintDir; /* hook for predictor tag */
1777
1778 sp->setupdecode = tif->tif_setupdecode;
1780 sp->setupencode = tif->tif_setupencode;
1782
1783 sp->predictor = 1; /* default value */
1784 sp->encodepfunc = NULL; /* no predictor routine */
1785 sp->decodepfunc = NULL; /* no predictor routine */
1786 return 1;
1787}
1788
1790{
1792
1793 assert(sp != 0);
1794
1797 tif->tif_tagmethods.printdir = sp->printdir;
1798 tif->tif_setupdecode = sp->setupdecode;
1799 tif->tif_setupencode = sp->setupencode;
1800
1801 return 1;
1802}
1803
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
Definition tif_aux.c:140
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Multiply two unsigned values with an overflow check.
Definition tif_aux.c:46
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
Merge borrowed field definitions into the lookup table.
#define TIFFFieldSet(tif, field)
Test a directory presence bit.
Definition tif_dir.h:662
#define TIFFSetFieldBit(tif, field)
Set a directory presence bit.
Definition tif_dir.h:675
@ TIFF_SETGET_UINT16
Unsigned 16-bit scalar storage.
Definition tif_dir.h:744
void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
Leave decoded bytes unchanged.
Definition tif_read.c:2209
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
static int horAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Accumulate 16-bit horizontal predictor samples in place.
static void PredictorSwabByteStream64(uint8_t *cp, tmsize_t n)
Reverse each 64-bit sample in an unaligned byte stream.
static int swabHorDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Swap and difference 16-bit horizontal predictor samples in place.
static int horDiff16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Difference 16-bit horizontal predictor samples in place.
static int PredictorDecodeRow(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
Decode one row then undo prediction in place.
#define PredictorState(tif)
Borrow the predictor prefix of codec-owned tif_data.
Definition tif_predict.c:42
static int horDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Difference 32-bit horizontal predictor samples in place.
static int fpDiff(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Apply floating-point byte-plane prediction on one row.
int TIFFPredictorCleanup(TIFF *tif)
Restore saved Predictor tag print and setup hooks.
static int horDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Difference 64-bit horizontal predictor samples in place.
#define REPEAT4(n, op)
Repeat a statement using an unrolled small-count switch.
static void PredictorPrintDir(TIFF *tif, FILE *fd, long flags)
Print predictor information then chain the parent printer.
static int PredictorSetupDecode(TIFF *tif)
Chain parent decoder setup and install predictor decoding.
static int swabHorAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Swap and accumulate 64-bit horizontal predictor samples in place.
static int horAcc64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Accumulate 64-bit horizontal predictor samples in place.
static int swabHorAcc16(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Swap and accumulate 16-bit horizontal predictor samples in place.
static int horDiff8(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Difference 8-bit horizontal predictor samples in place.
static int swabHorDiff64(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Swap and difference 64-bit horizontal predictor samples in place.
static int PredictorEncodeRow(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Transform a temporary row copy then call the parent encoder.
static int fpAcc(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Undo floating-point byte-plane prediction on one row.
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate32NativeUnaligned(uint8_t *current, const uint8_t *previous)
Add two unaligned native-order 32-bit samples modulo their width.
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate16NativeUnaligned(uint8_t *current, const uint8_t *previous)
Add two unaligned native-order 16-bit samples modulo their width.
static int horAcc8(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Accumulate 8-bit horizontal predictor samples in place.
static int swabHorAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Swap and accumulate 32-bit horizontal predictor samples in place.
#define FIELD_PREDICTOR
Reserve the codec field bit for Predictor.
static void PredictorSwabByteStream32(uint8_t *cp, tmsize_t n)
Reverse each 32-bit sample in an unaligned byte stream.
#define OP
Accumulate the next byte in the floating-point fast path.
static int PredictorSetupEncode(TIFF *tif)
Chain parent encoder setup and install predictor encoding.
static int PredictorSetup(TIFF *tif)
Validate predictor format and cache stride and row extent.
Definition tif_predict.c:83
int TIFFPredictorInit(TIFF *tif)
Install Predictor tag and setup hooks around a codec.
static int swabHorDiff32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Swap and difference 32-bit horizontal predictor samples in place.
static const TIFFField predictFields[]
Define the codec-owned Predictor field metadata.
static int horAcc32(TIFF *tif, uint8_t *cp0, tmsize_t cc)
Accumulate 32-bit horizontal predictor samples in place.
static int PredictorVGetField(TIFF *tif, uint32_t tag, va_list ap)
Fetch Predictor or delegate another variadic tag query.
static void PredictorSwabByteStream16(uint8_t *cp, tmsize_t n)
Reverse each 16-bit sample in an unaligned byte stream.
static int PredictorDecodeTile(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
Decode a strile then undo prediction row by row.
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate64NativeUnaligned(uint8_t *current, const uint8_t *previous)
Add two unaligned native-order 64-bit samples modulo their width.
static int PredictorVSetField(TIFF *tif, uint32_t tag, va_list ap)
Store Predictor or delegate another variadic tag assignment.
static int PredictorEncodeTile(TIFF *tif, uint8_t *bp0, tmsize_t cc0, uint16_t s)
Transform a temporary strile copy then call the parent encoder.
#define isTiled(tif)
Test whether a handle uses tiled storage.
Definition tiffiop.h:833
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
Suppress unsigned-overflow instrumentation on supported Clang functions.
Definition tiffiop.h:1484
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
#define TIFF_DIRTYDIRECT
Mark a current directory that needs writing.
Definition tiffiop.h:421
#define TIFF_SWAB
Request swapping multibyte file values to or from host order.
Definition tiffiop.h:441
#define TIFFhowmany8_64(x)
Compute the byte count needed to hold a 64-bit bit count.
Definition tiffiop.h:1127
#define TIFFArrayCount(a)
Compute the element count of an actual array.
Definition tiffiop.h:1239
void TIFFSwabArrayOfLong8(uint64_t *lp, tmsize_t n)
Reverse the byte order of each array element.
Definition tif_swab.c:144
void TIFFSwabArrayOfShort(uint16_t *wp, tmsize_t n)
Reverse the byte order of each array element.
Definition tif_swab.c:87
void TIFFSwabArrayOfLong(uint32_t *lp, tmsize_t n)
Reverse the byte order of each array element.
Definition tif_swab.c:123
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
tmsize_t TIFFScanlineSize(TIFF *tif)
Compute the current scanline I/O byte estimate.
Definition tif_strip.c:383
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
Definition tif_unix.c:497
#define PREDICTOR_NONE
No prediction scheme used.
Definition tiff.h:550
#define PREDICTOR_FLOATINGPOINT
Floating point predictor.
Definition tiff.h:554
#define SAMPLEFORMAT_IEEEFP
IEEE floating point data (introduced in TIFF 6.0).
Definition tiff.h:614
#define TIFFTAG_PREDICTOR
TIFF tag: Prediction scheme applied before compression.
Definition tiff.h:548
#define PREDICTOR_HORIZONTAL
Horizontal differencing.
Definition tiff.h:552
#define PLANARCONFIG_CONTIG
Single image plane.
Definition tiff.h:472
int uint16_vap
Represent a uint16_t value after default variadic argument promotion.
Definition tiff.h:159
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89
@ TIFF_SHORT
Unsigned 16-bit integer.
Definition tiff.h:237
Store the current directory values and image traversal state.
Definition tif_dir.h:143
uint32_t td_tilewidth
Tile width in pixels.
Definition tif_dir.h:160
uint16_t td_bitspersample
Bits in each sample.
Definition tif_dir.h:168
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
Definition tif_dir.h:200
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
Definition tif_dir.h:170
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
Definition tif_dir.h:182
Prefix codec state with Predictor method chains and row geometry.
Definition tif_predict.h:76
tmsize_t stride
Positive channel stride in samples, not bytes, for active transforms.
Definition tif_predict.h:83
TIFFEncodeDecodeMethod decodepfunc
Selected in-place row accumulator, NULL before setup.
TIFFVSetMethod vsetparent
Saved borrowed tag setter.
TIFFCodeMethod encoderow
Saved parent row encoder.
Definition tif_predict.h:88
TIFFVGetMethod vgetparent
Saved borrowed tag getter.
TIFFCodeMethod encodetile
Saved parent strile encoder invoked by the shared wrapper.
Definition tif_predict.h:95
TIFFCodeMethod encodestrip
Saved parent strip encoder; shared strile wrapper dispatch currently uses encodetile.
Definition tif_predict.h:93
TIFFCodeMethod decodestrip
Saved parent strip decoder; shared strile wrapper dispatch currently uses decodetile.
tmsize_t rowsize
Positive decoded row byte extent for active strile transforms.
Definition tif_predict.h:85
int predictor
Predictor tag value; validated at setup.
Definition tif_predict.h:78
TIFFCodeMethod decodetile
Saved parent strile decoder invoked by the shared wrapper.
TIFFCodeMethod decoderow
Saved parent row decoder.
TIFFPrintMethod printdir
Saved optional borrowed directory printer.
TIFFBoolMethod setupdecode
Saved borrowed decoder setup method.
TIFFBoolMethod setupencode
Saved borrowed encoder setup method.
TIFFEncodeDecodeMethod encodepfunc
Selected in-place row differencer, NULL before setup.
Definition tif_predict.h:97
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
TIFFPrintMethod printdir
Optional codec/extension directory-print callback.
Definition tiffio.h:1579
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
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
Definition tiffiop.h:647
TIFFPostMethod tif_postdecode
Callback transforming decoded data, for example by byte swapping.
Definition tiffiop.h:727
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
TIFFCodeMethod tif_encoderow
Codec callback encoding a scanline.
Definition tiffiop.h:645
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
Definition tiffiop.h:628
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
Definition tiffiop.h:404
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.