Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: third_party/libtiff/tif_fax3.c

Issue 1563103002: XFA: Upgrade to libtiff 4.0.6. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rename to libtiff Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libtiff/tif_fax3.h ('k') | third_party/libtiff/tif_fax3sm.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* $Id: tif_fax3.c,v 1.74 2012-06-21 02:01:31 fwarmerdam Exp $ */ 1 /* $Id: tif_fax3.c,v 1.75 2015-08-30 20:49:55 erouault Exp $ */
2 2
3 /* 3 /*
4 * Copyright (c) 1990-1997 Sam Leffler 4 * Copyright (c) 1990-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
12 * publicity relating to the software without the specific, prior written 12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics. 13 * permission of Sam Leffler and Silicon Graphics.
14 * 14 *
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 * 18 *
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE. 24 * OF THIS SOFTWARE.
25 */ 25 */
26
26 #include "tiffiop.h" 27 #include "tiffiop.h"
27 #ifdef CCITT_SUPPORT 28 #ifdef CCITT_SUPPORT
28 /* 29 /*
29 * TIFF Library. 30 * TIFF Library.
30 * 31 *
31 * CCITT Group 3 (T.4) and Group 4 (T.6) Compression Support. 32 * CCITT Group 3 (T.4) and Group 4 (T.6) Compression Support.
32 * 33 *
33 * This file contains support for decoding and encoding TIFF 34 * This file contains support for decoding and encoding TIFF
34 * compression algorithms 2, 3, 4, and 32771. 35 * compression algorithms 2, 3, 4, and 32771.
35 * 36 *
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 /* 363 /*
363 * Bit-fill a row according to the white/black 364 * Bit-fill a row according to the white/black
364 * runs generated during G3/G4 decoding. 365 * runs generated during G3/G4 decoding.
365 */ 366 */
366 void 367 void
367 _TIFFFax3fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) 368 _TIFFFax3fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx)
368 { 369 {
369 static const unsigned char _fillmasks[] = 370 static const unsigned char _fillmasks[] =
370 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; 371 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
371 unsigned char* cp; 372 unsigned char* cp;
372 » uint32 x, bx, run,bx_;/* add bx_ = 8-bx for avoid ms evc compiler bug*/ 373 » uint32 x, bx, run;
373 int32 n, nw; 374 int32 n, nw;
374 long* lp; 375 long* lp;
375 376
376 if ((erun-runs)&1) 377 if ((erun-runs)&1)
377 *erun++ = 0; 378 *erun++ = 0;
378 x = 0; 379 x = 0;
379 for (; runs < erun; runs += 2) { 380 for (; runs < erun; runs += 2) {
380 run = runs[0]; 381 run = runs[0];
381 if (x+run > lastx || run > lastx ) 382 if (x+run > lastx || run > lastx )
382 run = runs[0] = (uint32) (lastx - x); 383 run = runs[0] = (uint32) (lastx - x);
383 if (run) { 384 if (run) {
384 cp = buf + (x>>3); 385 cp = buf + (x>>3);
385 bx = x&7; 386 bx = x&7;
386 // » » if (run > 8-bx) { 387 » » if (run > 8-bx) {
387 // » » » if (bx) {» » » /* align to byte boundar y */
388 // » » » » *cp++ &= 0xff << (8-bx);
389 // » » » » run -= 8-bx;
390 // » » }
391 //Modify by Sunliang.Liu 20090804
392 //Detail: For avoid ms evc compiler bug in WCE ARMV4(I) Release
393 » » bx_ = 8-bx;
394 » » if (run > bx_) {
395 if (bx) { /* align to byte boundary */ 388 if (bx) { /* align to byte boundary */
396 » » » *cp++ &= 0xff << bx_; 389 » » » *cp++ &= 0xff << (8-bx);
397 » » » run -= bx_; 390 » » » run -= 8-bx;
398 } 391 }
399 if( (n = run >> 3) != 0 ) { /* multiple bytes to fill */ 392 if( (n = run >> 3) != 0 ) { /* multiple bytes to fill */
400 if ((n/sizeof (long)) > 1) { 393 if ((n/sizeof (long)) > 1) {
401 /* 394 /*
402 * Align to longword boundary and fill. 395 * Align to longword boundary and fill.
403 */ 396 */
404 for (; n && !isAligned(cp, long); n--) 397 for (; n && !isAligned(cp, long); n--)
405 *cp++ = 0x00; 398 *cp++ = 0x00;
406 lp = (long*) cp; 399 lp = (long*) cp;
407 nw = (int32)(n / sizeof (long)); 400 nw = (int32)(n / sizeof (long));
408 n -= nw * sizeof (long); 401 n -= nw * sizeof (long);
409 do { 402 do {
410 *lp++ = 0L; 403 *lp++ = 0L;
411 } while (--nw); 404 } while (--nw);
412 cp = (unsigned char*) lp; 405 cp = (unsigned char*) lp;
413 } 406 }
414 #ifdef FAX3_DEBUG
415 printf("_TIFFFax3fillruns ZERO: %d\n",n);
416 #endif
417 ZERO(n, cp); 407 ZERO(n, cp);
418 run &= 7; 408 run &= 7;
419 } 409 }
420 if (run) 410 if (run)
421 cp[0] &= 0xff >> run; 411 cp[0] &= 0xff >> run;
422 } else 412 } else
423 cp[0] &= ~(_fillmasks[run]>>bx); 413 cp[0] &= ~(_fillmasks[run]>>bx);
424 x += runs[0]; 414 x += runs[0];
425 } 415 }
426 run = runs[1]; 416 run = runs[1];
(...skipping 15 matching lines...) Expand all
442 for (; n && !isAligned(cp, long); n--) 432 for (; n && !isAligned(cp, long); n--)
443 *cp++ = 0xff; 433 *cp++ = 0xff;
444 lp = (long*) cp; 434 lp = (long*) cp;
445 nw = (int32)(n / sizeof (long)); 435 nw = (int32)(n / sizeof (long));
446 n -= nw * sizeof (long); 436 n -= nw * sizeof (long);
447 do { 437 do {
448 *lp++ = -1L; 438 *lp++ = -1L;
449 } while (--nw); 439 } while (--nw);
450 cp = (unsigned char*) lp; 440 cp = (unsigned char*) lp;
451 } 441 }
452 #ifdef FAX3_DEBUG
453 printf("_TIFFFax3fillruns FILL: %d\n",n);
454 #endif
455 FILL(n, cp); 442 FILL(n, cp);
456 run &= 7; 443 run &= 7;
457 } 444 }
445 /* Explicit 0xff masking to make icc -check=conversions happ y */
458 if (run) 446 if (run)
459 » » » cp[0] |= 0xff00 >> run; 447 » » » cp[0] = (unsigned char)((cp[0] | (0xff00 >> run))&0xff);
460 } else 448 } else
461 cp[0] |= _fillmasks[run]>>bx; 449 cp[0] |= _fillmasks[run]>>bx;
462 x += runs[1]; 450 x += runs[1];
463 } 451 }
464 } 452 }
465 assert(x == lastx); 453 assert(x == lastx);
466 } 454 }
467 #undef ZERO 455 #undef ZERO
468 #undef FILL 456 #undef FILL
469 457
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 * Compression Scheme Support. 1374 * Compression Scheme Support.
1387 */ 1375 */
1388 1376
1389 #define SWAP(t,a,b) { t x; x = (a); (a) = (b); (b) = x; } 1377 #define SWAP(t,a,b) { t x; x = (a); (a) = (b); (b) = x; }
1390 /* 1378 /*
1391 * Decode the requested amount of G4-encoded data. 1379 * Decode the requested amount of G4-encoded data.
1392 */ 1380 */
1393 static int 1381 static int
1394 Fax4Decode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) 1382 Fax4Decode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
1395 { 1383 {
1396 #ifdef FAX3_DEBUG
1397 FILE* file;
1398 #endif
1399 DECLARE_STATE_2D(tif, sp, "Fax4Decode"); 1384 DECLARE_STATE_2D(tif, sp, "Fax4Decode");
1400
1401 (void) s; 1385 (void) s;
1402 if (occ % sp->b.rowbytes) 1386 if (occ % sp->b.rowbytes)
1403 { 1387 {
1404 TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); 1388 TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read");
1405 return (-1); 1389 return (-1);
1406 } 1390 }
1407 CACHE_STATE(tif, sp); 1391 CACHE_STATE(tif, sp);
1408 while (occ > 0) { 1392 while (occ > 0) {
1409 a0 = 0; 1393 a0 = 0;
1410 RunLength = 0; 1394 RunLength = 0;
1411 pa = thisrun = sp->curruns; 1395 pa = thisrun = sp->curruns;
1412 pb = sp->refruns; 1396 pb = sp->refruns;
1413 b1 = *pb++; 1397 b1 = *pb++;
1414 #ifdef FAX3_DEBUG 1398 #ifdef FAX3_DEBUG
1415 printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); 1399 printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail);
1416 printf("-------------------- %d\n", tif->tif_row); 1400 printf("-------------------- %d\n", tif->tif_row);
1417 fflush(stdout); 1401 fflush(stdout);
1418 #endif 1402 #endif
1419 EXPAND2D(EOFG4); 1403 EXPAND2D(EOFG4);
1420 if (EOLcnt) 1404 if (EOLcnt)
1421 goto EOFG4; 1405 goto EOFG4;
1422 (*sp->fill)(buf, thisrun, pa, lastx); 1406 (*sp->fill)(buf, thisrun, pa, lastx);
1423 #ifdef FAX3_DEBUG
1424 file = fopen("fillbuf.txt", "a");
1425 fwrite(buf, sp->b.rowbytes, 1, file);
1426 fclose(file);
1427 #endif
1428 SETVALUE(0); /* imaginary change for reference */ 1407 SETVALUE(0); /* imaginary change for reference */
1429 SWAP(uint32*, sp->curruns, sp->refruns); 1408 SWAP(uint32*, sp->curruns, sp->refruns);
1430 buf += sp->b.rowbytes; 1409 buf += sp->b.rowbytes;
1431 occ -= sp->b.rowbytes; 1410 occ -= sp->b.rowbytes;
1432 sp->line++; 1411 sp->line++;
1433 continue; 1412 continue;
1434 EOFG4: 1413 EOFG4:
1435 NeedBits16( 13, BADG4 ); 1414 NeedBits16( 13, BADG4 );
1436 BADG4: 1415 BADG4:
1437 #ifdef FAX3_DEBUG 1416 #ifdef FAX3_DEBUG
1438 if( GetBits(13) != 0x1001 ) 1417 if( GetBits(13) != 0x1001 )
1439 fputs( "Bad EOFB\n", stderr ); 1418 fputs( "Bad EOFB\n", stderr );
1440 #endif 1419 #endif
1441 ClrBits( 13 ); 1420 ClrBits( 13 );
1442 (*sp->fill)(buf, thisrun, pa, lastx); 1421 (*sp->fill)(buf, thisrun, pa, lastx);
1443 #ifdef FAX3_DEBUG
1444 file = fopen("fillbuf.txt", "a");
1445 fwrite(buf, sp->b.rowbytes, 1, file);
1446 fclose(file);
1447 #endif
1448 UNCACHE_STATE(tif, sp); 1422 UNCACHE_STATE(tif, sp);
1449 return ( sp->line ? 1 : -1); /* don't error on badly-terminat ed strips */ 1423 return ( sp->line ? 1 : -1); /* don't error on badly-terminat ed strips */
1450 } 1424 }
1451 UNCACHE_STATE(tif, sp); 1425 UNCACHE_STATE(tif, sp);
1452 return (1); 1426 return (1);
1453 } 1427 }
1454 #undef SWAP 1428 #undef SWAP
1455 1429
1456 /* 1430 /*
1457 * Encode the requested amount of data. 1431 * Encode the requested amount of data.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 #endif /* CCITT_SUPPORT */ 1587 #endif /* CCITT_SUPPORT */
1614 1588
1615 /* vim: set ts=8 sts=8 sw=8 noet: */ 1589 /* vim: set ts=8 sts=8 sw=8 noet: */
1616 /* 1590 /*
1617 * Local Variables: 1591 * Local Variables:
1618 * mode: c 1592 * mode: c
1619 * c-basic-offset: 8 1593 * c-basic-offset: 8
1620 * fill-column: 78 1594 * fill-column: 78
1621 * End: 1595 * End:
1622 */ 1596 */
1623
OLDNEW
« no previous file with comments | « third_party/libtiff/tif_fax3.h ('k') | third_party/libtiff/tif_fax3sm.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698