1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Program to convert between RADIANCE and TIFF files. |
6 |
< |
* Added experimental LogLuv encodings 7/97 (GWL). |
6 |
> |
* Added LogLuv encodings 7/97 (GWL). |
7 |
> |
* Added white-balance adjustment 10/01 (GW). |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
#include <math.h> |
12 |
+ |
#include <time.h> |
13 |
|
#include "tiffio.h" |
14 |
|
#include "color.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
17 |
|
#define GAMCOR 2.2 /* default gamma */ |
18 |
|
|
20 |
– |
#ifndef malloc |
21 |
– |
extern char *malloc(); |
22 |
– |
#endif |
19 |
|
/* conversion flags */ |
20 |
|
#define C_CXFM 0x1 /* needs color transformation */ |
21 |
|
#define C_GAMUT 0x2 /* needs gamut mapping */ |
24 |
|
#define C_XYZE 0x10 /* Radiance is XYZE */ |
25 |
|
#define C_RFLT 0x20 /* Radiance data is float */ |
26 |
|
#define C_TFLT 0x40 /* TIFF data is float */ |
27 |
< |
#define C_PRIM 0x80 /* has assigned primaries */ |
27 |
> |
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
28 |
> |
#define C_PRIM 0x100 /* has assigned primaries */ |
29 |
|
|
30 |
|
struct { |
31 |
|
uint16 flags; /* conversion flags (defined above) */ |
183 |
|
int rsiz, tsiz; |
184 |
|
|
185 |
|
rsiz = CHK(C_RFLT) ? sizeof(COLOR) : sizeof(COLR); |
186 |
< |
tsiz = (CHK(C_TFLT) ? sizeof(float) : sizeof(uint8)) * |
186 |
> |
tsiz = (CHK(C_TFLT) ? sizeof(float) : |
187 |
> |
CHK(C_TWRD) ? sizeof(uint16) : sizeof(uint8)) * |
188 |
|
(CHK(C_GRY) ? 1 : 3); |
189 |
|
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
190 |
|
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
264 |
|
SET(C_GAMMA); |
265 |
|
setcolrgam(cvts.gamcor); |
266 |
|
if (CHK(C_XYZE)) { |
267 |
< |
comprgb2xyzmat(cvts.cmat, |
267 |
> |
comprgb2xyzWBmat(cvts.cmat, |
268 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
269 |
|
SET(C_CXFM); |
270 |
|
} |
278 |
|
cvts.tf = RGB2Colr; |
279 |
|
else { |
280 |
|
cvts.tf = RRGGBB2Color; |
281 |
< |
SET(C_RFLT); |
281 |
> |
SET(C_RFLT|C_TWRD); |
282 |
|
} |
283 |
|
break; |
284 |
|
case PHOTOMETRIC_MINISBLACK: |
295 |
|
cvts.tf = Gry2Colr; |
296 |
|
else { |
297 |
|
cvts.tf = GGry2Color; |
298 |
< |
SET(C_RFLT); |
298 |
> |
SET(C_RFLT|C_TWRD); |
299 |
|
} |
300 |
|
break; |
301 |
|
default: |
421 |
|
SET(C_RFLT|C_TFLT); |
422 |
|
CLR(C_GRY); |
423 |
|
if (!CHK(C_XYZE)) { |
424 |
< |
cpcolormat(cvts.cmat, rgb2xyzmat); |
424 |
> |
comprgb2xyzWBmat(cvts.cmat, |
425 |
> |
CHK(C_PRIM) ? cvts.prims : stdprims); |
426 |
|
SET(C_CXFM); |
427 |
|
} |
428 |
|
if (cvts.comp != COMPRESSION_SGILOG && |
445 |
|
CLR(C_GRY); |
446 |
|
setcolrgam(cvts.gamcor); |
447 |
|
if (CHK(C_XYZE)) { |
448 |
< |
compxyz2rgbmat(cvts.cmat, |
448 |
> |
compxyz2rgbWBmat(cvts.cmat, |
449 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
450 |
|
SET(C_CXFM); |
451 |
|
} |
520 |
|
{ |
521 |
|
register int x; |
522 |
|
|
523 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
523 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
524 |
|
quiterr("internal error 1 in Luv2Color"); |
525 |
|
|
526 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
556 |
|
register double d; |
557 |
|
register int x; |
558 |
|
|
559 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != C_RFLT) |
559 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) |
560 |
|
quiterr("internal error 1 in RRGGBB2Color"); |
561 |
|
|
562 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
596 |
|
{ |
597 |
|
register int x; |
598 |
|
|
599 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
599 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
600 |
|
quiterr("internal error 1 in L2Color"); |
601 |
|
|
602 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
620 |
|
COLOR ctmp; |
621 |
|
register int x; |
622 |
|
|
623 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY)) |
623 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY)) |
624 |
|
quiterr("internal error 1 in RGB2Colr"); |
625 |
|
|
626 |
|
if (cvts.pconf == PLANARCONFIG_CONTIG) { |
675 |
|
{ |
676 |
|
register int x; |
677 |
|
|
678 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != C_GRY) |
678 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
679 |
|
quiterr("internal error 1 in Gry2Colr"); |
680 |
|
|
681 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
704 |
|
register double d; |
705 |
|
register int x; |
706 |
|
|
707 |
< |
if (CHK(C_TFLT|C_GRY|C_RFLT) != (C_GRY|C_RFLT)) |
707 |
> |
if (CHK(C_TFLT|C_TWRD|C_GRY|C_RFLT) != (C_GRY|C_RFLT|C_TWRD)) |
708 |
|
quiterr("internal error 1 in GGry2Color"); |
709 |
|
|
710 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
732 |
|
double m = pow(2.,(double)cvts.bradj); |
733 |
|
register int x; |
734 |
|
|
735 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
735 |
> |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
736 |
|
quiterr("internal error 1 in Color2L"); |
737 |
|
|
738 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
753 |
|
{ |
754 |
|
register int x; |
755 |
|
|
756 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
756 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
757 |
|
quiterr("internal error 1 in Color2Luv"); |
758 |
|
|
759 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
786 |
|
{ |
787 |
|
register int x; |
788 |
|
|
789 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != C_GRY) |
789 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
790 |
|
quiterr("internal error 1 in Colr2Gry"); |
791 |
|
|
792 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
813 |
|
COLOR ctmp; |
814 |
|
register int x; |
815 |
|
|
816 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY)) |
816 |
> |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY)) |
817 |
|
quiterr("internal error 1 in Colr2RGB"); |
818 |
|
|
819 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |