OLD | NEW |
1 /* $Id: tif_luv.c,v 1.35 2011-04-02 20:54:09 bfriesen Exp $ */ | 1 /* $Id: tif_luv.c,v 1.40 2015-06-21 01:09:09 bfriesen Exp $ */ |
2 | 2 |
3 /* | 3 /* |
4 * Copyright (c) 1997 Greg Ward Larson | 4 * Copyright (c) 1997 Greg Ward Larson |
5 * Copyright (c) 1997 Silicon Graphics, Inc. | 5 * Copyright (c) 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, Greg Larson and Silicon Graphics may not be used in any | 11 * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any |
12 * advertising or publicity relating to the software without the specific, | 12 * advertising or publicity relating to the software without the specific, |
13 * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics. | 13 * prior written permission of Sam Leffler, Greg Larson 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, GREG LARSON OR SILICON GRAPHICS BE LIABLE | 19 * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE |
20 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, | 20 * FOR 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 LOGLUV_SUPPORT | 28 #ifdef LOGLUV_SUPPORT |
28 | 29 |
29 /* | 30 /* |
30 * TIFF Library. | 31 * TIFF Library. |
31 * LogLuv compression support for high dynamic range images. | 32 * LogLuv compression support for high dynamic range images. |
32 * | 33 * |
33 * Contributed by Greg Larson. | 34 * Contributed by Greg Larson. |
34 * | 35 * |
35 * LogLuv image support uses the TIFF library to store 16 or 10-bit | 36 * LogLuv image support uses the TIFF library to store 16 or 10-bit |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 /* | 372 /* |
372 * Decode a strip of pixels. We break it into rows to | 373 * Decode a strip of pixels. We break it into rows to |
373 * maintain synchrony with the encode algorithm, which | 374 * maintain synchrony with the encode algorithm, which |
374 * is row by row. | 375 * is row by row. |
375 */ | 376 */ |
376 static int | 377 static int |
377 LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) | 378 LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) |
378 { | 379 { |
379 tmsize_t rowlen = TIFFScanlineSize(tif); | 380 tmsize_t rowlen = TIFFScanlineSize(tif); |
380 | 381 |
| 382 if (rowlen == 0) |
| 383 return 0; |
| 384 |
381 assert(cc%rowlen == 0); | 385 assert(cc%rowlen == 0); |
382 while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) | 386 while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) |
383 bp += rowlen, cc -= rowlen; | 387 bp += rowlen, cc -= rowlen; |
384 return (cc == 0); | 388 return (cc == 0); |
385 } | 389 } |
386 | 390 |
387 /* | 391 /* |
388 * Decode a tile of pixels. We break it into rows to | 392 * Decode a tile of pixels. We break it into rows to |
389 * maintain synchrony with the encode algorithm, which | 393 * maintain synchrony with the encode algorithm, which |
390 * is row by row. | 394 * is row by row. |
391 */ | 395 */ |
392 static int | 396 static int |
393 LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) | 397 LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) |
394 { | 398 { |
395 tmsize_t rowlen = TIFFTileRowSize(tif); | 399 tmsize_t rowlen = TIFFTileRowSize(tif); |
396 | 400 |
| 401 if (rowlen == 0) |
| 402 return 0; |
| 403 |
397 assert(cc%rowlen == 0); | 404 assert(cc%rowlen == 0); |
398 while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) | 405 while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) |
399 bp += rowlen, cc -= rowlen; | 406 bp += rowlen, cc -= rowlen; |
400 return (cc == 0); | 407 return (cc == 0); |
401 } | 408 } |
402 | 409 |
403 /* | 410 /* |
404 * Encode a row of 16-bit pixels. | 411 * Encode a row of 16-bit pixels. |
405 */ | 412 */ |
406 static int | 413 static int |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 643 |
637 /* | 644 /* |
638 * Encode a strip of pixels. We break it into rows to | 645 * Encode a strip of pixels. We break it into rows to |
639 * avoid encoding runs across row boundaries. | 646 * avoid encoding runs across row boundaries. |
640 */ | 647 */ |
641 static int | 648 static int |
642 LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) | 649 LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) |
643 { | 650 { |
644 tmsize_t rowlen = TIFFScanlineSize(tif); | 651 tmsize_t rowlen = TIFFScanlineSize(tif); |
645 | 652 |
| 653 if (rowlen == 0) |
| 654 return 0; |
| 655 |
646 assert(cc%rowlen == 0); | 656 assert(cc%rowlen == 0); |
647 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) | 657 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) |
648 bp += rowlen, cc -= rowlen; | 658 bp += rowlen, cc -= rowlen; |
649 return (cc == 0); | 659 return (cc == 0); |
650 } | 660 } |
651 | 661 |
652 /* | 662 /* |
653 * Encode a tile of pixels. We break it into rows to | 663 * Encode a tile of pixels. We break it into rows to |
654 * avoid encoding runs across row boundaries. | 664 * avoid encoding runs across row boundaries. |
655 */ | 665 */ |
656 static int | 666 static int |
657 LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) | 667 LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) |
658 { | 668 { |
659 tmsize_t rowlen = TIFFTileRowSize(tif); | 669 tmsize_t rowlen = TIFFTileRowSize(tif); |
660 | 670 |
| 671 if (rowlen == 0) |
| 672 return 0; |
| 673 |
661 assert(cc%rowlen == 0); | 674 assert(cc%rowlen == 0); |
662 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) | 675 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) |
663 bp += rowlen, cc -= rowlen; | 676 bp += rowlen, cc -= rowlen; |
664 return (cc == 0); | 677 return (cc == 0); |
665 } | 678 } |
666 | 679 |
667 /* | 680 /* |
668 * Encode/Decode functions for converting to and from user formats. | 681 * Encode/Decode functions for converting to and from user formats. |
669 */ | 682 */ |
670 | 683 |
671 #include "uvcode.h" | 684 #include "uvcode.h" |
672 | 685 |
673 #ifndef UVSCALE | 686 #ifndef UVSCALE |
674 #define U_NEU 0.210526316 | 687 #define U_NEU 0.210526316 |
675 #define V_NEU 0.473684211 | 688 #define V_NEU 0.473684211 |
676 #define UVSCALE 410. | 689 #define UVSCALE 410. |
677 #endif | 690 #endif |
678 | 691 |
679 #ifndef M_LN2 | 692 #ifndef M_LN2 |
680 #define M_LN2 0.69314718055994530942 | 693 #define M_LN2 0.69314718055994530942 |
681 #endif | 694 #endif |
682 #ifndef M_PI | 695 #ifndef M_PI |
683 #define M_PI 3.14159265358979323846 | 696 #define M_PI 3.14159265358979323846 |
684 #endif | 697 #endif |
685 #ifndef log2 | 698 #undef log2 /* Conflict with C'99 function */ |
686 #define log2(x) ((1./M_LN2)*log(x)) | 699 #define log2(x) ((1./M_LN2)*log(x)) |
687 #endif | 700 #undef exp2 /* Conflict with C'99 function */ |
688 #define exp2(x) exp(M_LN2*(x)) | 701 #define exp2(x) exp(M_LN2*(x)) |
689 | 702 |
690 #define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \ | 703 #define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \ |
691 (int)(x) : \ | 704 (int)(x) : \ |
692 (int)((x) + rand()*(1./RAND_MAX) - .5)) | 705 (int)((x) + rand()*(1./RAND_MAX) - .5)) |
693 | 706 |
694 #if !LOGLUV_PUBLIC | 707 #if !LOGLUV_PUBLIC |
695 static | 708 static |
696 #endif | 709 #endif |
697 double | 710 double |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 #endif /* LOGLUV_SUPPORT */ | 1688 #endif /* LOGLUV_SUPPORT */ |
1676 | 1689 |
1677 /* vim: set ts=8 sts=8 sw=8 noet: */ | 1690 /* vim: set ts=8 sts=8 sw=8 noet: */ |
1678 /* | 1691 /* |
1679 * Local Variables: | 1692 * Local Variables: |
1680 * mode: c | 1693 * mode: c |
1681 * c-basic-offset: 8 | 1694 * c-basic-offset: 8 |
1682 * fill-column: 78 | 1695 * fill-column: 78 |
1683 * End: | 1696 * End: |
1684 */ | 1697 */ |
1685 | |
OLD | NEW |