OLD | NEW |
1 /* $Id: tif_predict.c,v 1.32 2010-03-10 18:56:49 bfriesen Exp $ */ | 1 /* $Id: tif_predict.c,v 1.35 2015-08-31 15:05:57 erouault Exp $ */ |
2 | 2 |
3 /* | 3 /* |
4 * Copyright (c) 1988-1997 Sam Leffler | 4 * Copyright (c) 1988-1997 Sam Leffler |
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc. | 5 * Copyright (c) 1991-1997 Silicon Graphics, Inc. |
6 * | 6 * |
7 * Permission to use, copy, modify, distribute, and sell this software and | 7 * Permission to use, copy, modify, distribute, and sell this software and |
8 * its documentation for any purpose is hereby granted without fee, provided | 8 * its documentation for any purpose is hereby granted without fee, provided |
9 * that (i) the above copyright notices and this permission notice appear in | 9 * that (i) the above copyright notices and this permission notice appear in |
10 * all copies of the software and related documentation, and (ii) the names of | 10 * all copies of the software and related documentation, and (ii) the names of |
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or | 11 * Sam Leffler and Silicon Graphics may not be used in any advertising or |
(...skipping 23 matching lines...) Expand all Loading... |
35 #define PredictorState(tif) ((TIFFPredictorState*) (tif)->tif_data) | 35 #define PredictorState(tif) ((TIFFPredictorState*) (tif)->tif_data) |
36 | 36 |
37 static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc); | 37 static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc); |
38 static void horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); | 38 static void horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); |
39 static void horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); | 39 static void horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); |
40 static void swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); | 40 static void swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); |
41 static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); | 41 static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); |
42 static void horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); | 42 static void horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); |
43 static void horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); | 43 static void horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); |
44 static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); | 44 static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); |
| 45 static void swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); |
| 46 static void swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); |
45 static void fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); | 47 static void fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); |
46 static void fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); | 48 static void fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); |
47 static int PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); | 49 static int PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); |
48 static int PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); | 50 static int PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); |
49 static int PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); | 51 static int PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); |
50 static int PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s); | 52 static int PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s); |
51 | 53 |
52 static int | 54 static int |
53 PredictorSetup(TIFF* tif) | 55 PredictorSetup(TIFF* tif) |
54 { | 56 { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 */ | 202 */ |
201 if( tif->tif_encoderow != PredictorEncodeRow ) | 203 if( tif->tif_encoderow != PredictorEncodeRow ) |
202 { | 204 { |
203 sp->encoderow = tif->tif_encoderow; | 205 sp->encoderow = tif->tif_encoderow; |
204 tif->tif_encoderow = PredictorEncodeRow; | 206 tif->tif_encoderow = PredictorEncodeRow; |
205 sp->encodestrip = tif->tif_encodestrip; | 207 sp->encodestrip = tif->tif_encodestrip; |
206 tif->tif_encodestrip = PredictorEncodeTile; | 208 tif->tif_encodestrip = PredictorEncodeTile; |
207 sp->encodetile = tif->tif_encodetile; | 209 sp->encodetile = tif->tif_encodetile; |
208 tif->tif_encodetile = PredictorEncodeTile; | 210 tif->tif_encodetile = PredictorEncodeTile; |
209 } | 211 } |
210 » } | 212 |
| 213 /* |
| 214 * If the data is horizontally differenced 16-bit data that |
| 215 * requires byte-swapping, then it must be byte swapped after |
| 216 * the differenciation step. We do this with a special-purpose |
| 217 * routine and override the normal post decoding logic that |
| 218 * the library setup when the directory was read. |
| 219 */ |
| 220 if (tif->tif_flags & TIFF_SWAB) { |
| 221 if (sp->encodepfunc == horDiff16) { |
| 222 sp->encodepfunc = swabHorDiff16; |
| 223 tif->tif_postdecode = _TIFFNoPostDecode; |
| 224 } else if (sp->encodepfunc == horDiff32) { |
| 225 sp->encodepfunc = swabHorDiff32; |
| 226 tif->tif_postdecode = _TIFFNoPostDecode; |
| 227 } |
| 228 } |
| 229 } |
211 | 230 |
212 else if (sp->predictor == 3) { | 231 else if (sp->predictor == 3) { |
213 sp->encodepfunc = fpDiff; | 232 sp->encodepfunc = fpDiff; |
214 /* | 233 /* |
215 * Override default encoding method with one that does the | 234 * Override default encoding method with one that does the |
216 * predictor stuff. | 235 * predictor stuff. |
217 */ | 236 */ |
218 if( tif->tif_encoderow != PredictorEncodeRow ) | 237 if( tif->tif_encoderow != PredictorEncodeRow ) |
219 { | 238 { |
220 sp->encoderow = tif->tif_encoderow; | 239 sp->encoderow = tif->tif_encoderow; |
(...skipping 11 matching lines...) Expand all Loading... |
232 #define REPEAT4(n, op) \ | 251 #define REPEAT4(n, op) \ |
233 switch (n) { \ | 252 switch (n) { \ |
234 default: { tmsize_t i; for (i = n-4; i > 0; i--) { op; } } \ | 253 default: { tmsize_t i; for (i = n-4; i > 0; i--) { op; } } \ |
235 case 4: op; \ | 254 case 4: op; \ |
236 case 3: op; \ | 255 case 3: op; \ |
237 case 2: op; \ | 256 case 2: op; \ |
238 case 1: op; \ | 257 case 1: op; \ |
239 case 0: ; \ | 258 case 0: ; \ |
240 } | 259 } |
241 | 260 |
| 261 /* Remarks related to C standard compliance in all below functions : */ |
| 262 /* - to avoid any undefined behaviour, we only operate on unsigned types */ |
| 263 /* since the behaviour of "overflows" is defined (wrap over) */ |
| 264 /* - when storing into the byte stream, we explicitly mask with 0xff so */ |
| 265 /* as to make icc -check=conversions happy (not necessary by the standard) */ |
| 266 |
242 static void | 267 static void |
243 horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) | 268 horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) |
244 { | 269 { |
245 /* | |
246 * compare v4.0.3 with v3.9.5, | |
247 * we find that horAcc8 uses while loop in the v4.0.3 and uses do while
loop in the v3.9.5. | |
248 * times of do while loop are less than while loop, so we use v3.9.5 ins
tead of v4.0.3. | |
249 */ | |
250 #if 0 | |
251 tmsize_t stride = PredictorState(tif)->stride; | 270 tmsize_t stride = PredictorState(tif)->stride; |
252 | 271 |
253 » char* cp = (char*) cp0; | 272 » unsigned char* cp = (unsigned char*) cp0; |
254 assert((cc%stride)==0); | 273 assert((cc%stride)==0); |
255 if (cc > stride) { | 274 if (cc > stride) { |
256 /* | 275 /* |
257 * Pipeline the most common cases. | 276 * Pipeline the most common cases. |
258 */ | 277 */ |
259 if (stride == 3) { | 278 if (stride == 3) { |
260 unsigned int cr = cp[0]; | 279 unsigned int cr = cp[0]; |
261 unsigned int cg = cp[1]; | 280 unsigned int cg = cp[1]; |
262 unsigned int cb = cp[2]; | 281 unsigned int cb = cp[2]; |
263 cc -= 3; | 282 cc -= 3; |
264 cp += 3; | 283 cp += 3; |
265 while (cc>0) { | 284 while (cc>0) { |
266 » » » » cp[0] = (char) (cr += cp[0]); | 285 » » » » cp[0] = (unsigned char) ((cr += cp[0]) & 0xff); |
267 » » » » cp[1] = (char) (cg += cp[1]); | 286 » » » » cp[1] = (unsigned char) ((cg += cp[1]) & 0xff); |
268 » » » » cp[2] = (char) (cb += cp[2]); | 287 » » » » cp[2] = (unsigned char) ((cb += cp[2]) & 0xff); |
269 cc -= 3; | 288 cc -= 3; |
270 cp += 3; | 289 cp += 3; |
271 } | 290 } |
272 } else if (stride == 4) { | 291 } else if (stride == 4) { |
273 unsigned int cr = cp[0]; | 292 unsigned int cr = cp[0]; |
274 unsigned int cg = cp[1]; | 293 unsigned int cg = cp[1]; |
275 unsigned int cb = cp[2]; | 294 unsigned int cb = cp[2]; |
276 unsigned int ca = cp[3]; | 295 unsigned int ca = cp[3]; |
277 cc -= 4; | 296 cc -= 4; |
278 cp += 4; | 297 cp += 4; |
279 while (cc>0) { | 298 while (cc>0) { |
280 » » » » cp[0] = (char) (cr += cp[0]); | 299 » » » » cp[0] = (unsigned char) ((cr += cp[0]) & 0xff); |
281 » » » » cp[1] = (char) (cg += cp[1]); | 300 » » » » cp[1] = (unsigned char) ((cg += cp[1]) & 0xff); |
282 » » » » cp[2] = (char) (cb += cp[2]); | 301 » » » » cp[2] = (unsigned char) ((cb += cp[2]) & 0xff); |
283 » » » » cp[3] = (char) (ca += cp[3]); | 302 » » » » cp[3] = (unsigned char) ((ca += cp[3]) & 0xff); |
284 cc -= 4; | 303 cc -= 4; |
285 cp += 4; | 304 cp += 4; |
286 } | 305 } |
287 } else { | 306 } else { |
288 cc -= stride; | 307 cc -= stride; |
289 do { | 308 do { |
290 REPEAT4(stride, cp[stride] = | 309 REPEAT4(stride, cp[stride] = |
291 » » » » » (char) (cp[stride] + *cp); cp++) | 310 » » » » » (unsigned char) ((cp[stride] + *cp) & 0x
ff); cp++) |
292 cc -= stride; | 311 cc -= stride; |
293 } while (cc>0); | 312 } while (cc>0); |
294 } | 313 } |
295 } | 314 } |
296 #else | |
297 tsize_t stride = PredictorState(tif)->stride; | |
298 | |
299 char* cp = (char*) cp0; | |
300 if (cc > stride) { | |
301 cc -= stride; | |
302 /* | |
303 * Pipeline the most common cases. | |
304 */ | |
305 if (stride == 3) { | |
306 unsigned int cr = cp[0]; | |
307 unsigned int cg = cp[1]; | |
308 unsigned int cb = cp[2]; | |
309 do { | |
310 cc -= 3, cp += 3; | |
311 cp[0] = (char) (cr += cp[0]); | |
312 cp[1] = (char) (cg += cp[1]); | |
313 cp[2] = (char) (cb += cp[2]); | |
314 } while ((int32) cc > 0); | |
315 } else if (stride == 4) { | |
316 unsigned int cr = cp[0]; | |
317 unsigned int cg = cp[1]; | |
318 unsigned int cb = cp[2]; | |
319 unsigned int ca = cp[3]; | |
320 do { | |
321 cc -= 4, cp += 4; | |
322 cp[0] = (char) (cr += cp[0]); | |
323 cp[1] = (char) (cg += cp[1]); | |
324 cp[2] = (char) (cb += cp[2]); | |
325 cp[3] = (char) (ca += cp[3]); | |
326 } while ((int32) cc > 0); | |
327 } else { | |
328 do { | |
329 REPEAT4(stride, cp[stride] = | |
330 (char) (cp[stride] + *cp); cp++) | |
331 cc -= stride; | |
332 } while ((int32) cc > 0); | |
333 } | |
334 } | |
335 #endif | |
336 } | 315 } |
337 | 316 |
338 static void | 317 static void |
339 swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) | 318 swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) |
340 { | 319 { |
341 tmsize_t stride = PredictorState(tif)->stride; | |
342 uint16* wp = (uint16*) cp0; | 320 uint16* wp = (uint16*) cp0; |
343 tmsize_t wc = cc / 2; | 321 tmsize_t wc = cc / 2; |
344 | 322 |
345 » assert((cc%(2*stride))==0); | 323 TIFFSwabArrayOfShort(wp, wc); |
346 | 324 horAcc16(tif, cp0, cc); |
347 » if (wc > stride) { | |
348 » » TIFFSwabArrayOfShort(wp, wc); | |
349 » » wc -= stride; | |
350 » » do { | |
351 » » » REPEAT4(stride, wp[stride] += wp[0]; wp++) | |
352 » » » wc -= stride; | |
353 » » } while (wc > 0); | |
354 » } | |
355 } | 325 } |
356 | 326 |
357 static void | 327 static void |
358 horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) | 328 horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) |
359 { | 329 { |
360 tmsize_t stride = PredictorState(tif)->stride; | 330 tmsize_t stride = PredictorState(tif)->stride; |
361 uint16* wp = (uint16*) cp0; | 331 uint16* wp = (uint16*) cp0; |
362 tmsize_t wc = cc / 2; | 332 tmsize_t wc = cc / 2; |
363 | 333 |
364 assert((cc%(2*stride))==0); | 334 assert((cc%(2*stride))==0); |
365 | 335 |
366 if (wc > stride) { | 336 if (wc > stride) { |
367 wc -= stride; | 337 wc -= stride; |
368 do { | 338 do { |
369 » » » REPEAT4(stride, wp[stride] += wp[0]; wp++) | 339 » » » REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[
stride] + (unsigned int)wp[0]) & 0xffff); wp++) |
370 wc -= stride; | 340 wc -= stride; |
371 } while (wc > 0); | 341 } while (wc > 0); |
372 } | 342 } |
373 } | 343 } |
374 | 344 |
375 static void | 345 static void |
376 swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) | 346 swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) |
377 { | 347 { |
378 tmsize_t stride = PredictorState(tif)->stride; | |
379 uint32* wp = (uint32*) cp0; | 348 uint32* wp = (uint32*) cp0; |
380 tmsize_t wc = cc / 4; | 349 tmsize_t wc = cc / 4; |
381 | 350 |
382 » assert((cc%(4*stride))==0); | 351 TIFFSwabArrayOfLong(wp, wc); |
383 | 352 » horAcc32(tif, cp0, cc); |
384 » if (wc > stride) { | |
385 » » TIFFSwabArrayOfLong(wp, wc); | |
386 » » wc -= stride; | |
387 » » do { | |
388 » » » REPEAT4(stride, wp[stride] += wp[0]; wp++) | |
389 » » » wc -= stride; | |
390 » » } while (wc > 0); | |
391 » } | |
392 } | 353 } |
393 | 354 |
394 static void | 355 static void |
395 horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) | 356 horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) |
396 { | 357 { |
397 tmsize_t stride = PredictorState(tif)->stride; | 358 tmsize_t stride = PredictorState(tif)->stride; |
398 uint32* wp = (uint32*) cp0; | 359 uint32* wp = (uint32*) cp0; |
399 tmsize_t wc = cc / 4; | 360 tmsize_t wc = cc / 4; |
400 | 361 |
401 assert((cc%(4*stride))==0); | 362 assert((cc%(4*stride))==0); |
(...skipping 19 matching lines...) Expand all Loading... |
421 tmsize_t count = cc; | 382 tmsize_t count = cc; |
422 uint8 *cp = (uint8 *) cp0; | 383 uint8 *cp = (uint8 *) cp0; |
423 uint8 *tmp = (uint8 *)_TIFFmalloc(cc); | 384 uint8 *tmp = (uint8 *)_TIFFmalloc(cc); |
424 | 385 |
425 assert((cc%(bps*stride))==0); | 386 assert((cc%(bps*stride))==0); |
426 | 387 |
427 if (!tmp) | 388 if (!tmp) |
428 return; | 389 return; |
429 | 390 |
430 while (count > stride) { | 391 while (count > stride) { |
431 » » REPEAT4(stride, cp[stride] += cp[0]; cp++) | 392 » » REPEAT4(stride, cp[stride] = |
| 393 (unsigned char) ((cp[stride] + cp[0]) & 0xff); cp++) |
432 count -= stride; | 394 count -= stride; |
433 } | 395 } |
434 | 396 |
435 _TIFFmemcpy(tmp, cp0, cc); | 397 _TIFFmemcpy(tmp, cp0, cc); |
436 cp = (uint8 *) cp0; | 398 cp = (uint8 *) cp0; |
437 for (count = 0; count < wc; count++) { | 399 for (count = 0; count < wc; count++) { |
438 uint32 byte; | 400 uint32 byte; |
439 for (byte = 0; byte < bps; byte++) { | 401 for (byte = 0; byte < bps; byte++) { |
440 #if WORDS_BIGENDIAN | 402 #if WORDS_BIGENDIAN |
441 cp[bps * count + byte] = tmp[byte * wc + count]; | 403 cp[bps * count + byte] = tmp[byte * wc + count]; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 return 1; | 457 return 1; |
496 } else | 458 } else |
497 return 0; | 459 return 0; |
498 } | 460 } |
499 | 461 |
500 static void | 462 static void |
501 horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) | 463 horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) |
502 { | 464 { |
503 TIFFPredictorState* sp = PredictorState(tif); | 465 TIFFPredictorState* sp = PredictorState(tif); |
504 tmsize_t stride = sp->stride; | 466 tmsize_t stride = sp->stride; |
505 » char* cp = (char*) cp0; | 467 » unsigned char* cp = (unsigned char*) cp0; |
506 | 468 |
507 assert((cc%stride)==0); | 469 assert((cc%stride)==0); |
508 | 470 |
509 if (cc > stride) { | 471 if (cc > stride) { |
510 cc -= stride; | 472 cc -= stride; |
511 /* | 473 /* |
512 * Pipeline the most common cases. | 474 * Pipeline the most common cases. |
513 */ | 475 */ |
514 if (stride == 3) { | 476 if (stride == 3) { |
515 » » » int r1, g1, b1; | 477 » » » unsigned int r1, g1, b1; |
516 » » » int r2 = cp[0]; | 478 » » » unsigned int r2 = cp[0]; |
517 » » » int g2 = cp[1]; | 479 » » » unsigned int g2 = cp[1]; |
518 » » » int b2 = cp[2]; | 480 » » » unsigned int b2 = cp[2]; |
519 do { | 481 do { |
520 » » » » r1 = cp[3]; cp[3] = r1-r2; r2 = r1; | 482 » » » » r1 = cp[3]; cp[3] = (unsigned char)((r1-r2)&0xff
); r2 = r1; |
521 » » » » g1 = cp[4]; cp[4] = g1-g2; g2 = g1; | 483 » » » » g1 = cp[4]; cp[4] = (unsigned char)((g1-g2)&0xff
); g2 = g1; |
522 » » » » b1 = cp[5]; cp[5] = b1-b2; b2 = b1; | 484 » » » » b1 = cp[5]; cp[5] = (unsigned char)((b1-b2)&0xff
); b2 = b1; |
523 cp += 3; | 485 cp += 3; |
524 } while ((cc -= 3) > 0); | 486 } while ((cc -= 3) > 0); |
525 } else if (stride == 4) { | 487 } else if (stride == 4) { |
526 » » » int r1, g1, b1, a1; | 488 » » » unsigned int r1, g1, b1, a1; |
527 » » » int r2 = cp[0]; | 489 » » » unsigned int r2 = cp[0]; |
528 » » » int g2 = cp[1]; | 490 » » » unsigned int g2 = cp[1]; |
529 » » » int b2 = cp[2]; | 491 » » » unsigned int b2 = cp[2]; |
530 » » » int a2 = cp[3]; | 492 » » » unsigned int a2 = cp[3]; |
531 do { | 493 do { |
532 » » » » r1 = cp[4]; cp[4] = r1-r2; r2 = r1; | 494 » » » » r1 = cp[4]; cp[4] = (unsigned char)((r1-r2)&0xff
); r2 = r1; |
533 » » » » g1 = cp[5]; cp[5] = g1-g2; g2 = g1; | 495 » » » » g1 = cp[5]; cp[5] = (unsigned char)((g1-g2)&0xff
); g2 = g1; |
534 » » » » b1 = cp[6]; cp[6] = b1-b2; b2 = b1; | 496 » » » » b1 = cp[6]; cp[6] = (unsigned char)((b1-b2)&0xff
); b2 = b1; |
535 » » » » a1 = cp[7]; cp[7] = a1-a2; a2 = a1; | 497 » » » » a1 = cp[7]; cp[7] = (unsigned char)((a1-a2)&0xff
); a2 = a1; |
536 cp += 4; | 498 cp += 4; |
537 } while ((cc -= 4) > 0); | 499 } while ((cc -= 4) > 0); |
538 } else { | 500 } else { |
539 cp += cc - 1; | 501 cp += cc - 1; |
540 do { | 502 do { |
541 » » » » REPEAT4(stride, cp[stride] -= cp[0]; cp--) | 503 » » » » REPEAT4(stride, cp[stride] = (unsigned char)((cp
[stride] - cp[0])&0xff); cp--) |
542 } while ((cc -= stride) > 0); | 504 } while ((cc -= stride) > 0); |
543 } | 505 } |
544 } | 506 } |
545 } | 507 } |
546 | 508 |
547 static void | 509 static void |
548 horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) | 510 horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) |
549 { | 511 { |
550 TIFFPredictorState* sp = PredictorState(tif); | 512 TIFFPredictorState* sp = PredictorState(tif); |
551 tmsize_t stride = sp->stride; | 513 tmsize_t stride = sp->stride; |
552 » int16 *wp = (int16*) cp0; | 514 » uint16 *wp = (uint16*) cp0; |
553 tmsize_t wc = cc/2; | 515 tmsize_t wc = cc/2; |
554 | 516 |
555 assert((cc%(2*stride))==0); | 517 assert((cc%(2*stride))==0); |
556 | 518 |
557 if (wc > stride) { | 519 if (wc > stride) { |
558 wc -= stride; | 520 wc -= stride; |
559 wp += wc - 1; | 521 wp += wc - 1; |
560 do { | 522 do { |
561 » » » REPEAT4(stride, wp[stride] -= wp[0]; wp--) | 523 » » » REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[
stride] - (unsigned int)wp[0]) & 0xffff); wp--) |
562 wc -= stride; | 524 wc -= stride; |
563 } while (wc > 0); | 525 } while (wc > 0); |
564 } | 526 } |
565 } | 527 } |
566 | 528 |
567 static void | 529 static void |
| 530 swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) |
| 531 { |
| 532 uint16* wp = (uint16*) cp0; |
| 533 tmsize_t wc = cc / 2; |
| 534 |
| 535 horDiff16(tif, cp0, cc); |
| 536 |
| 537 TIFFSwabArrayOfShort(wp, wc); |
| 538 } |
| 539 |
| 540 static void |
568 horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) | 541 horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) |
569 { | 542 { |
570 TIFFPredictorState* sp = PredictorState(tif); | 543 TIFFPredictorState* sp = PredictorState(tif); |
571 tmsize_t stride = sp->stride; | 544 tmsize_t stride = sp->stride; |
572 » int32 *wp = (int32*) cp0; | 545 » uint32 *wp = (uint32*) cp0; |
573 tmsize_t wc = cc/4; | 546 tmsize_t wc = cc/4; |
574 | 547 |
575 assert((cc%(4*stride))==0); | 548 assert((cc%(4*stride))==0); |
576 | 549 |
577 if (wc > stride) { | 550 if (wc > stride) { |
578 wc -= stride; | 551 wc -= stride; |
579 wp += wc - 1; | 552 wp += wc - 1; |
580 do { | 553 do { |
581 REPEAT4(stride, wp[stride] -= wp[0]; wp--) | 554 REPEAT4(stride, wp[stride] -= wp[0]; wp--) |
582 wc -= stride; | 555 wc -= stride; |
583 } while (wc > 0); | 556 } while (wc > 0); |
584 } | 557 } |
585 } | 558 } |
586 | 559 |
| 560 static void |
| 561 swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) |
| 562 { |
| 563 uint32* wp = (uint32*) cp0; |
| 564 tmsize_t wc = cc / 4; |
| 565 |
| 566 horDiff32(tif, cp0, cc); |
| 567 |
| 568 TIFFSwabArrayOfLong(wp, wc); |
| 569 } |
| 570 |
587 /* | 571 /* |
588 * Floating point predictor differencing routine. | 572 * Floating point predictor differencing routine. |
589 */ | 573 */ |
590 static void | 574 static void |
591 fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) | 575 fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) |
592 { | 576 { |
593 tmsize_t stride = PredictorState(tif)->stride; | 577 tmsize_t stride = PredictorState(tif)->stride; |
594 uint32 bps = tif->tif_dir.td_bitspersample / 8; | 578 uint32 bps = tif->tif_dir.td_bitspersample / 8; |
595 tmsize_t wc = cc / bps; | 579 tmsize_t wc = cc / bps; |
596 tmsize_t count; | 580 tmsize_t count; |
(...skipping 15 matching lines...) Expand all Loading... |
612 cp[(bps - byte - 1) * wc + count] = | 596 cp[(bps - byte - 1) * wc + count] = |
613 tmp[bps * count + byte]; | 597 tmp[bps * count + byte]; |
614 #endif | 598 #endif |
615 } | 599 } |
616 } | 600 } |
617 _TIFFfree(tmp); | 601 _TIFFfree(tmp); |
618 | 602 |
619 cp = (uint8 *) cp0; | 603 cp = (uint8 *) cp0; |
620 cp += cc - stride - 1; | 604 cp += cc - stride - 1; |
621 for (count = cc; count > stride; count -= stride) | 605 for (count = cc; count > stride; count -= stride) |
622 » » REPEAT4(stride, cp[stride] -= cp[0]; cp--) | 606 » » REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0]
)&0xff); cp--) |
623 } | 607 } |
624 | 608 |
625 static int | 609 static int |
626 PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) | 610 PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) |
627 { | 611 { |
628 TIFFPredictorState *sp = PredictorState(tif); | 612 TIFFPredictorState *sp = PredictorState(tif); |
629 | 613 |
630 assert(sp != NULL); | 614 assert(sp != NULL); |
631 assert(sp->encodepfunc != NULL); | 615 assert(sp->encodepfunc != NULL); |
632 assert(sp->encoderow != NULL); | 616 assert(sp->encoderow != NULL); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 } | 785 } |
802 | 786 |
803 /* vim: set ts=8 sts=8 sw=8 noet: */ | 787 /* vim: set ts=8 sts=8 sw=8 noet: */ |
804 /* | 788 /* |
805 * Local Variables: | 789 * Local Variables: |
806 * mode: c | 790 * mode: c |
807 * c-basic-offset: 8 | 791 * c-basic-offset: 8 |
808 * fill-column: 78 | 792 * fill-column: 78 |
809 * End: | 793 * End: |
810 */ | 794 */ |
811 | |
OLD | NEW |