| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "tiffiop.h" |
| 31 |
|
| 32 |
static int DumpFixupTags(TIFF *tif) |
| 33 |
{ |
| 34 |
(void)tif; |
| 35 |
return (1); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
static int DumpModeEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s) |
| 42 |
{ |
| 43 |
(void)s; |
| 44 |
while (cc > 0) |
| 45 |
{ |
| 46 |
tmsize_t n; |
| 47 |
|
| 48 |
n = cc; |
| 49 |
if (tif->tif_rawcc + n > tif->tif_rawdatasize) |
| 50 |
n = tif->tif_rawdatasize - tif->tif_rawcc; |
| 51 |
|
| 52 |
assert(n > 0); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
if (tif->tif_rawcp != pp) |
| 59 |
_TIFFmemcpy(tif->tif_rawcp, pp, n); |
| 60 |
tif->tif_rawcp += n; |
| 61 |
tif->tif_rawcc += n; |
| 62 |
pp += n; |
| 63 |
cc -= n; |
| 64 |
if (tif->tif_rawcc >= tif->tif_rawdatasize && !TIFFFlushData1(tif)) |
| 65 |
return (0); |
| 66 |
} |
| 67 |
return (1); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
static int DumpModeDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s) |
| 74 |
{ |
| 75 |
static const char module[] = "DumpModeDecode"; |
| 76 |
(void)s; |
| 77 |
if (tif->tif_rawcc < cc) |
| 78 |
{ |
| 79 |
TIFFErrorExtR(tif, module, |
| 80 |
"Not enough data for scanline %" PRIu32 |
| 81 |
", expected a request for at most %" TIFF_SSIZE_FORMAT |
| 82 |
" bytes, got a request for %" TIFF_SSIZE_FORMAT " bytes", |
| 83 |
tif->tif_dir.td_row, tif->tif_rawcc, cc); |
| 84 |
return (0); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
if (tif->tif_rawcp != buf) |
| 91 |
_TIFFmemcpy(buf, tif->tif_rawcp, cc); |
| 92 |
tif->tif_rawcp += cc; |
| 93 |
tif->tif_rawcc -= cc; |
| 94 |
return (1); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
static int DumpModeSeek(TIFF *tif, uint32_t nrows) |
| 101 |
{ |
| 102 |
tmsize_t seek_size; |
| 103 |
if (nrows > 0 && |
| 104 |
tif->tif_dir.td_scanlinesize > (tmsize_t)(TIFF_TMSIZE_T_MAX / nrows)) |
| 105 |
{ |
| 106 |
TIFFErrorExtR(tif, "DumpModeSeek", |
| 107 |
"Integer overflow computing seek size"); |
| 108 |
return (0); |
| 109 |
} |
| 110 |
seek_size = (tmsize_t)nrows * tif->tif_dir.td_scanlinesize; |
| 111 |
if (seek_size > tif->tif_rawcc) |
| 112 |
{ |
| 113 |
TIFFErrorExtR(tif, "DumpModeSeek", |
| 114 |
"Seek beyond end of raw data buffer"); |
| 115 |
return (0); |
| 116 |
} |
| 117 |
tif->tif_rawcp += seek_size; |
| 118 |
tif->tif_rawcc -= seek_size; |
| 119 |
return (1); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
int TIFFInitDumpMode(TIFF *tif, int scheme) |
| 126 |
{ |
| 127 |
(void)scheme; |
| 128 |
tif->tif_fixuptags = DumpFixupTags; |
| 129 |
tif->tif_decoderow = DumpModeDecode; |
| 130 |
tif->tif_decodestrip = DumpModeDecode; |
| 131 |
tif->tif_decodetile = DumpModeDecode; |
| 132 |
tif->tif_encoderow = DumpModeEncode; |
| 133 |
tif->tif_encodestrip = DumpModeEncode; |
| 134 |
tif->tif_encodetile = DumpModeEncode; |
| 135 |
tif->tif_seek = DumpModeSeek; |
| 136 |
return (1); |
| 137 |
} |