37
37
static void horAcc8(TIFF*, tidata_t, tsize_t);
38
38
static void horAcc16(TIFF*, tidata_t, tsize_t);
39
static void horAcc32(TIFF*, tidata_t, tsize_t);
39
40
static void swabHorAcc16(TIFF*, tidata_t, tsize_t);
41
static void swabHorAcc32(TIFF*, tidata_t, tsize_t);
40
42
static void horDiff8(TIFF*, tidata_t, tsize_t);
41
43
static void horDiff16(TIFF*, tidata_t, tsize_t);
44
static void horDiff32(TIFF*, tidata_t, tsize_t);
42
45
static void fpAcc(TIFF*, tidata_t, tsize_t);
43
46
static void fpDiff(TIFF*, tidata_t, tsize_t);
44
47
static int PredictorDecodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
61
64
case PREDICTOR_HORIZONTAL:
62
65
if (td->td_bitspersample != 8
63
&& td->td_bitspersample != 16) {
66
&& td->td_bitspersample != 16
67
&& td->td_bitspersample != 32) {
64
68
TIFFErrorExt(tif->tif_clientdata, module,
65
69
"Horizontal differencing \"Predictor\" not supported with %d-bit samples",
66
70
td->td_bitspersample);
106
110
if (sp->predictor == 2) {
107
111
switch (td->td_bitspersample) {
108
case 8: sp->pfunc = horAcc8; break;
109
case 16: sp->pfunc = horAcc16; break;
112
case 8: sp->decodepfunc = horAcc8; break;
113
case 16: sp->decodepfunc = horAcc16; break;
114
case 32: sp->decodepfunc = horAcc32; break;
112
117
* Override default decoding method with one that does the
113
118
* predictor stuff.
115
sp->coderow = tif->tif_decoderow;
116
tif->tif_decoderow = PredictorDecodeRow;
117
sp->codestrip = tif->tif_decodestrip;
118
tif->tif_decodestrip = PredictorDecodeTile;
119
sp->codetile = tif->tif_decodetile;
120
tif->tif_decodetile = PredictorDecodeTile;
120
if( tif->tif_decoderow != PredictorDecodeRow )
122
sp->decoderow = tif->tif_decoderow;
123
tif->tif_decoderow = PredictorDecodeRow;
124
sp->decodestrip = tif->tif_decodestrip;
125
tif->tif_decodestrip = PredictorDecodeTile;
126
sp->decodetile = tif->tif_decodetile;
127
tif->tif_decodetile = PredictorDecodeTile;
122
130
* If the data is horizontally differenced 16-bit data that
123
131
* requires byte-swapping, then it must be byte swapped before
126
134
* the library setup when the directory was read.
128
136
if (tif->tif_flags & TIFF_SWAB) {
129
if (sp->pfunc == horAcc16) {
130
sp->pfunc = swabHorAcc16;
131
tif->tif_postdecode = _TIFFNoPostDecode;
132
} /* else handle 32-bit case... */
137
if (sp->decodepfunc == horAcc16) {
138
sp->decodepfunc = swabHorAcc16;
139
tif->tif_postdecode = _TIFFNoPostDecode;
140
} else if (sp->decodepfunc == horAcc32) {
141
sp->decodepfunc = swabHorAcc32;
142
tif->tif_postdecode = _TIFFNoPostDecode;
136
147
else if (sp->predictor == 3) {
148
sp->decodepfunc = fpAcc;
139
150
* Override default decoding method with one that does the
140
151
* predictor stuff.
142
sp->coderow = tif->tif_decoderow;
143
tif->tif_decoderow = PredictorDecodeRow;
144
sp->codestrip = tif->tif_decodestrip;
145
tif->tif_decodestrip = PredictorDecodeTile;
146
sp->codetile = tif->tif_decodetile;
147
tif->tif_decodetile = PredictorDecodeTile;
153
if( tif->tif_decoderow != PredictorDecodeRow )
155
sp->decoderow = tif->tif_decoderow;
156
tif->tif_decoderow = PredictorDecodeRow;
157
sp->decodestrip = tif->tif_decodestrip;
158
tif->tif_decodestrip = PredictorDecodeTile;
159
sp->decodetile = tif->tif_decodetile;
160
tif->tif_decodetile = PredictorDecodeTile;
149
163
* The data should not be swapped outside of the floating
150
164
* point predictor, the accumulation routine should return
174
188
if (sp->predictor == 2) {
175
189
switch (td->td_bitspersample) {
176
case 8: sp->pfunc = horDiff8; break;
177
case 16: sp->pfunc = horDiff16; break;
190
case 8: sp->encodepfunc = horDiff8; break;
191
case 16: sp->encodepfunc = horDiff16; break;
192
case 32: sp->encodepfunc = horDiff32; break;
180
195
* Override default encoding method with one that does the
181
196
* predictor stuff.
183
sp->coderow = tif->tif_encoderow;
184
tif->tif_encoderow = PredictorEncodeRow;
185
sp->codestrip = tif->tif_encodestrip;
186
tif->tif_encodestrip = PredictorEncodeTile;
187
sp->codetile = tif->tif_encodetile;
188
tif->tif_encodetile = PredictorEncodeTile;
198
if( tif->tif_encoderow != PredictorEncodeRow )
200
sp->encoderow = tif->tif_encoderow;
201
tif->tif_encoderow = PredictorEncodeRow;
202
sp->encodestrip = tif->tif_encodestrip;
203
tif->tif_encodestrip = PredictorEncodeTile;
204
sp->encodetile = tif->tif_encodetile;
205
tif->tif_encodetile = PredictorEncodeTile;
191
209
else if (sp->predictor == 3) {
210
sp->encodepfunc = fpDiff;
194
212
* Override default encoding method with one that does the
195
213
* predictor stuff.
197
sp->coderow = tif->tif_encoderow;
198
tif->tif_encoderow = PredictorEncodeRow;
199
sp->codestrip = tif->tif_encodestrip;
200
tif->tif_encodestrip = PredictorEncodeTile;
201
sp->codetile = tif->tif_encodetile;
202
tif->tif_encodetile = PredictorEncodeTile;
215
if( tif->tif_encoderow != PredictorEncodeRow )
217
sp->encoderow = tif->tif_encoderow;
218
tif->tif_encoderow = PredictorEncodeRow;
219
sp->encodestrip = tif->tif_encodestrip;
220
tif->tif_encodestrip = PredictorEncodeTile;
221
sp->encodetile = tif->tif_encodetile;
222
tif->tif_encodetile = PredictorEncodeTile;
316
swabHorAcc32(TIFF* tif, tidata_t cp0, tsize_t cc)
318
tsize_t stride = PredictorState(tif)->stride;
319
uint32* wp = (uint32*) cp0;
323
TIFFSwabArrayOfLong(wp, wc);
326
REPEAT4(stride, wp[stride] += wp[0]; wp++)
328
} while ((int32) wc > 0);
333
horAcc32(TIFF* tif, tidata_t cp0, tsize_t cc)
335
tsize_t stride = PredictorState(tif)->stride;
336
uint32* wp = (uint32*) cp0;
342
REPEAT4(stride, wp[stride] += wp[0]; wp++)
344
} while ((int32) wc > 0);
295
349
* Floating point predictor accumulation routine.
337
391
TIFFPredictorState *sp = PredictorState(tif);
339
393
assert(sp != NULL);
340
assert(sp->coderow != NULL);
341
assert(sp->pfunc != NULL);
394
assert(sp->decoderow != NULL);
395
assert(sp->decodepfunc != NULL);
343
if ((*sp->coderow)(tif, op0, occ0, s)) {
344
(*sp->pfunc)(tif, op0, occ0);
397
if ((*sp->decoderow)(tif, op0, occ0, s)) {
398
(*sp->decodepfunc)(tif, op0, occ0);
360
414
TIFFPredictorState *sp = PredictorState(tif);
362
416
assert(sp != NULL);
363
assert(sp->codetile != NULL);
417
assert(sp->decodetile != NULL);
365
if ((*sp->codetile)(tif, op0, occ0, s)) {
419
if ((*sp->decodetile)(tif, op0, occ0, s)) {
366
420
tsize_t rowsize = sp->rowsize;
367
421
assert(rowsize > 0);
368
assert(sp->pfunc != NULL);
422
assert(sp->decodepfunc != NULL);
369
423
while ((long)occ0 > 0) {
370
(*sp->pfunc)(tif, op0, (tsize_t) rowsize);
424
(*sp->decodepfunc)(tif, op0, (tsize_t) rowsize);
497
horDiff32(TIFF* tif, tidata_t cp0, tsize_t cc)
499
TIFFPredictorState* sp = PredictorState(tif);
500
tsize_t stride = sp->stride;
501
int32 *wp = (int32*) cp0;
508
REPEAT4(stride, wp[stride] -= wp[0]; wp--)
510
} while ((int32) wc > 0);
443
515
* Floating point predictor differencing routine.
481
553
TIFFPredictorState *sp = PredictorState(tif);
483
555
assert(sp != NULL);
484
assert(sp->pfunc != NULL);
485
assert(sp->coderow != NULL);
556
assert(sp->encodepfunc != NULL);
557
assert(sp->encoderow != NULL);
487
559
/* XXX horizontal differencing alters user's data XXX */
488
(*sp->pfunc)(tif, bp, cc);
489
return (*sp->coderow)(tif, bp, cc, s);
560
(*sp->encodepfunc)(tif, bp, cc);
561
return (*sp->encoderow)(tif, bp, cc, s);
493
565
PredictorEncodeTile(TIFF* tif, tidata_t bp0, tsize_t cc0, tsample_t s)
567
static const char module[] = "PredictorEncodeTile";
495
568
TIFFPredictorState *sp = PredictorState(tif);
496
570
tsize_t cc = cc0, rowsize;
497
unsigned char* bp = bp0;
499
574
assert(sp != NULL);
500
assert(sp->pfunc != NULL);
501
assert(sp->codetile != NULL);
575
assert(sp->encodepfunc != NULL);
576
assert(sp->encodetile != NULL);
579
* Do predictor manipulation in a working buffer to avoid altering
580
* the callers buffer. http://trac.osgeo.org/gdal/ticket/1965
582
working_copy = (uint8*) _TIFFmalloc(cc0);
583
if( working_copy == NULL )
585
TIFFErrorExt(tif->tif_clientdata, module,
586
"Out of memory allocating %d byte temp buffer.",
590
memcpy( working_copy, bp0, cc0 );
503
593
rowsize = sp->rowsize;
504
594
assert(rowsize > 0);
505
while ((long)cc > 0) {
506
(*sp->pfunc)(tif, bp, (tsize_t) rowsize);
595
assert((cc0%rowsize)==0);
597
(*sp->encodepfunc)(tif, bp, rowsize);
510
return (*sp->codetile)(tif, bp0, cc0, s);
601
result_code = (*sp->encodetile)(tif, working_copy, cc0, s);
603
_TIFFfree( working_copy );
513
608
#define FIELD_PREDICTOR (FIELD_CODEC+0) /* XXX */