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 <ctype.h> |
13 |
+ |
#include <time.h> |
14 |
+ |
#include <string.h> |
15 |
+ |
|
16 |
|
#include "tiffio.h" |
17 |
|
#include "color.h" |
18 |
|
#include "resolu.h" |
19 |
|
|
20 |
|
#define GAMCOR 2.2 /* default gamma */ |
21 |
|
|
20 |
– |
#ifndef malloc |
21 |
– |
extern char *malloc(); |
22 |
– |
#endif |
22 |
|
/* conversion flags */ |
23 |
|
#define C_CXFM 0x1 /* needs color transformation */ |
24 |
|
#define C_GAMUT 0x2 /* needs gamut mapping */ |
30 |
|
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
31 |
|
#define C_PRIM 0x100 /* has assigned primaries */ |
32 |
|
|
33 |
+ |
typedef void colcvf_t(uint32 y); |
34 |
+ |
|
35 |
|
struct { |
36 |
|
uint16 flags; /* conversion flags (defined above) */ |
37 |
+ |
char capdate[20]; /* capture date/time */ |
38 |
+ |
char owner[256]; /* content owner */ |
39 |
|
uint16 comp; /* TIFF compression type */ |
40 |
|
uint16 phot; /* TIFF photometric type */ |
41 |
|
uint16 pconf; /* TIFF planar configuration */ |
60 |
|
float *fp; /* float pointer */ |
61 |
|
char *p; /* generic pointer */ |
62 |
|
} t; /* TIFF scanline */ |
63 |
< |
int (*tf)(); /* translation procedure */ |
63 |
> |
colcvf_t *tf; /* translation procedure */ |
64 |
|
} cvts = { /* conversion structure */ |
65 |
< |
0, COMPRESSION_NONE, PHOTOMETRIC_RGB, |
65 |
> |
0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, |
66 |
|
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., |
67 |
|
}; |
68 |
|
|
71 |
|
#define CLR(f) (cvts.flags &= ~(f)) |
72 |
|
#define TGL(f) (cvts.flags ^= (f)) |
73 |
|
|
74 |
< |
int Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
75 |
< |
int Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
76 |
< |
int RRGGBB2Color(), GGry2Color(); |
74 |
> |
static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr; |
75 |
> |
static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry; |
76 |
> |
static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry; |
77 |
|
|
78 |
+ |
static gethfunc headline; |
79 |
+ |
static void quiterr(char *err); |
80 |
+ |
static void allocbufs(void); |
81 |
+ |
static void initfromtif(void); |
82 |
+ |
static void tiff2ra(int ac, char *av[]); |
83 |
+ |
static void initfromrad(void); |
84 |
+ |
static void ra2tiff(int ac, char *av[]); |
85 |
+ |
|
86 |
+ |
|
87 |
+ |
|
88 |
+ |
#define RfGfBf2Color Luv2Color |
89 |
+ |
#define Gryf2Color L2Color |
90 |
+ |
#define Color2Gryf Color2L |
91 |
+ |
#define Color2RfGfBf Color2Luv |
92 |
+ |
|
93 |
|
short ortab[8] = { /* orientation conversion table */ |
94 |
|
YMAJOR|YDECR, |
95 |
|
YMAJOR|YDECR|XDECR, |
103 |
|
|
104 |
|
#define pixorder() ortab[cvts.orient-1] |
105 |
|
|
106 |
+ |
extern char TMSTR[]; /* "CAPDATE=" from header.c */ |
107 |
+ |
char OWNSTR[] = "OWNER="; |
108 |
+ |
|
109 |
|
char *progname; |
110 |
|
|
111 |
|
|
112 |
< |
main(argc, argv) |
113 |
< |
int argc; |
93 |
< |
char *argv[]; |
112 |
> |
int |
113 |
> |
main(int argc, char *argv[]) |
114 |
|
{ |
115 |
|
int reverse = 0; |
116 |
|
int i; |
137 |
|
cvts.comp = COMPRESSION_SGILOG24; |
138 |
|
cvts.phot = PHOTOMETRIC_LOGLUV; |
139 |
|
break; |
140 |
+ |
case 'w': /* 16-bit/primary output? */ |
141 |
+ |
TGL(C_TWRD); |
142 |
+ |
break; |
143 |
+ |
case 'f': /* IEEE float output? */ |
144 |
+ |
TGL(C_TFLT); |
145 |
+ |
break; |
146 |
|
case 'b': /* greyscale output? */ |
147 |
|
TGL(C_GRY); |
148 |
|
break; |
173 |
|
|
174 |
|
if (i != argc-2) |
175 |
|
goto userr; |
176 |
< |
|
177 |
< |
if (CHK(C_GRY)) /* consistency corrections */ |
176 |
> |
/* consistency checks */ |
177 |
> |
if (CHK(C_GRY)) { |
178 |
|
if (cvts.phot == PHOTOMETRIC_RGB) |
179 |
|
cvts.phot = PHOTOMETRIC_MINISBLACK; |
180 |
|
else { |
181 |
|
cvts.phot = PHOTOMETRIC_LOGL; |
182 |
|
cvts.comp = COMPRESSION_SGILOG; |
183 |
|
} |
184 |
+ |
} |
185 |
+ |
if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT)) |
186 |
+ |
goto userr; |
187 |
|
|
188 |
|
ra2tiff(i, argv); |
189 |
|
} |
191 |
|
exit(0); |
192 |
|
userr: |
193 |
|
fprintf(stderr, |
194 |
< |
"Usage: %s [-z|-L|-l][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n", |
194 |
> |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n", |
195 |
|
progname); |
196 |
|
fprintf(stderr, |
197 |
|
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n", |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
< |
quiterr(err) /* print message and exit */ |
204 |
< |
char *err; |
203 |
> |
static void |
204 |
> |
quiterr( /* print message and exit */ |
205 |
> |
char *err |
206 |
> |
) |
207 |
|
{ |
208 |
|
if (err != NULL) { |
209 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
< |
allocbufs() /* allocate scanline buffers */ |
216 |
> |
static void |
217 |
> |
allocbufs(void) /* allocate scanline buffers */ |
218 |
|
{ |
219 |
|
int rsiz, tsiz; |
220 |
|
|
224 |
|
(CHK(C_GRY) ? 1 : 3); |
225 |
|
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
226 |
|
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
227 |
< |
if (cvts.r.p == NULL | cvts.t.p == NULL) |
227 |
> |
if ((cvts.r.p == NULL) | (cvts.t.p == NULL)) |
228 |
|
quiterr("no memory to allocate scanline buffers"); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
< |
initfromtif() /* initialize conversion from TIFF input */ |
232 |
> |
static void |
233 |
> |
initfromtif(void) /* initialize conversion from TIFF input */ |
234 |
|
{ |
235 |
|
uint16 hi; |
236 |
+ |
char *cp; |
237 |
|
float *fa, f1, f2; |
238 |
|
|
239 |
< |
CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_CXFM); |
239 |
> |
CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM); |
240 |
|
|
241 |
|
TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_PLANARCONFIG, &cvts.pconf); |
242 |
|
|
275 |
|
cpcolormat(cvts.cmat, xyz2rgbmat); |
276 |
|
SET(C_CXFM|C_GAMUT); |
277 |
|
} else if (cvts.comp == COMPRESSION_SGILOG) |
278 |
< |
SET(C_GAMUT); |
278 |
> |
SET(C_GAMUT); /* may be outside XYZ gamut */ |
279 |
|
if (cvts.pconf != PLANARCONFIG_CONTIG) |
280 |
|
quiterr("cannot handle separate Luv planes"); |
281 |
|
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
302 |
|
SET(C_GAMMA); |
303 |
|
setcolrgam(cvts.gamcor); |
304 |
|
if (CHK(C_XYZE)) { |
305 |
< |
comprgb2xyzmat(cvts.cmat, |
305 |
> |
comprgb2xyzWBmat(cvts.cmat, |
306 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
307 |
|
SET(C_CXFM); |
308 |
|
} |
309 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || |
310 |
|
hi != 3) |
311 |
|
quiterr("unsupported samples per pixel for RGB"); |
312 |
< |
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
313 |
< |
hi != 8 & hi != 16) |
314 |
< |
quiterr("unsupported bits per sample for RGB"); |
315 |
< |
if (hi == 8) |
312 |
> |
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi)) |
313 |
> |
hi = -1; |
314 |
> |
switch (hi) { |
315 |
> |
case 8: |
316 |
|
cvts.tf = RGB2Colr; |
317 |
< |
else { |
317 |
> |
break; |
318 |
> |
case 16: |
319 |
|
cvts.tf = RRGGBB2Color; |
320 |
|
SET(C_RFLT|C_TWRD); |
321 |
+ |
break; |
322 |
+ |
case 32: |
323 |
+ |
cvts.tf = RfGfBf2Color; |
324 |
+ |
SET(C_RFLT|C_TFLT); |
325 |
+ |
break; |
326 |
+ |
default: |
327 |
+ |
quiterr("unsupported bits per sample for RGB"); |
328 |
|
} |
329 |
|
break; |
330 |
|
case PHOTOMETRIC_MINISBLACK: |
334 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || |
335 |
|
hi != 1) |
336 |
|
quiterr("unsupported samples per pixel for greyscale"); |
337 |
< |
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
338 |
< |
hi != 8 & hi != 16) |
339 |
< |
quiterr("unsupported bits per sample for greyscale"); |
340 |
< |
if (hi == 8) |
337 |
> |
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi)) |
338 |
> |
hi = -1; |
339 |
> |
switch (hi) { |
340 |
> |
case 8: |
341 |
|
cvts.tf = Gry2Colr; |
342 |
< |
else { |
342 |
> |
break; |
343 |
> |
case 16: |
344 |
|
cvts.tf = GGry2Color; |
345 |
|
SET(C_RFLT|C_TWRD); |
346 |
+ |
break; |
347 |
+ |
case 32: |
348 |
+ |
cvts.tf = Gryf2Color; |
349 |
+ |
SET(C_RFLT|C_TFLT); |
350 |
+ |
break; |
351 |
+ |
default: |
352 |
+ |
quiterr("unsupported bits per sample for Gray"); |
353 |
|
} |
354 |
|
break; |
355 |
|
default: |
363 |
|
|
364 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) |
365 |
|
cvts.stonits = 1.; |
366 |
+ |
|
367 |
+ |
if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp)) |
368 |
+ |
cvts.capdate[0] = '\0'; |
369 |
+ |
else { |
370 |
+ |
strncpy(cvts.capdate, cp, 19); |
371 |
+ |
cvts.capdate[19] = '\0'; |
372 |
+ |
} |
373 |
+ |
if (!TIFFGetField(cvts.tif, TIFFTAG_ARTIST, &cp)) |
374 |
+ |
cvts.owner[0] = '\0'; |
375 |
+ |
else { |
376 |
+ |
strncpy(cvts.owner, cp, sizeof(cvts.owner)); |
377 |
+ |
cvts.owner[sizeof(cvts.owner)-1] = '\0'; |
378 |
+ |
} |
379 |
|
/* add to Radiance header */ |
380 |
|
if (cvts.pixrat < .99 || cvts.pixrat > 1.01) |
381 |
|
fputaspect(cvts.pixrat, cvts.rfp); |
389 |
|
cvts.rfp); |
390 |
|
fputformat(COLRFMT, cvts.rfp); |
391 |
|
} |
392 |
+ |
if (cvts.capdate[0]) |
393 |
+ |
fprintf(cvts.rfp, "%s %s\n", TMSTR, cvts.capdate); |
394 |
+ |
if (cvts.owner[0]) |
395 |
+ |
fprintf(cvts.rfp, "%s %s\n", OWNSTR, cvts.owner); |
396 |
|
|
397 |
|
allocbufs(); /* allocate scanline buffers */ |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
< |
tiff2ra(ac, av) /* convert TIFF image to Radiance picture */ |
402 |
< |
int ac; |
403 |
< |
char *av[]; |
401 |
> |
static void |
402 |
> |
tiff2ra( /* convert TIFF image to Radiance picture */ |
403 |
> |
int ac, |
404 |
> |
char *av[] |
405 |
> |
) |
406 |
|
{ |
407 |
|
int32 y; |
408 |
|
/* open TIFF input */ |
430 |
|
} |
431 |
|
|
432 |
|
|
433 |
< |
int |
434 |
< |
headline(s) /* process Radiance input header line */ |
435 |
< |
char *s; |
433 |
> |
static int |
434 |
> |
headline( /* process Radiance input header line */ |
435 |
> |
char *s, |
436 |
> |
void *p |
437 |
> |
) |
438 |
|
{ |
439 |
+ |
static int tmstrlen = 0; |
440 |
+ |
static int ownstrlen = 0; |
441 |
|
char fmt[32]; |
442 |
|
|
443 |
+ |
if (!tmstrlen) |
444 |
+ |
tmstrlen = strlen(TMSTR); |
445 |
+ |
if (!ownstrlen) |
446 |
+ |
ownstrlen = strlen(OWNSTR); |
447 |
|
if (formatval(fmt, s)) { |
448 |
|
if (!strcmp(fmt, COLRFMT)) |
449 |
|
CLR(C_XYZE); |
466 |
|
SET(C_PRIM); |
467 |
|
return(1); |
468 |
|
} |
469 |
+ |
if (isdate(s)) { |
470 |
+ |
if (s[tmstrlen] == ' ') |
471 |
+ |
strncpy(cvts.capdate, s+tmstrlen+1, 19); |
472 |
+ |
else |
473 |
+ |
strncpy(cvts.capdate, s+tmstrlen, 19); |
474 |
+ |
cvts.capdate[19] = '\0'; |
475 |
+ |
return(1); |
476 |
+ |
} |
477 |
+ |
if (!strncmp(s, OWNSTR, ownstrlen)) { |
478 |
+ |
register char *cp = s + ownstrlen; |
479 |
+ |
|
480 |
+ |
while (isspace(*cp)) |
481 |
+ |
++cp; |
482 |
+ |
strncpy(cvts.owner, cp, sizeof(cvts.owner)); |
483 |
+ |
cvts.owner[sizeof(cvts.owner)-1] = '\0'; |
484 |
+ |
for (cp = cvts.owner; *cp; cp++) |
485 |
+ |
; |
486 |
+ |
while (cp > cvts.owner && isspace(cp[-1])) |
487 |
+ |
*--cp = '\0'; |
488 |
+ |
return(1); |
489 |
+ |
} |
490 |
|
return(0); |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
< |
initfromrad() /* initialize input from a Radiance picture */ |
494 |
> |
static void |
495 |
> |
initfromrad(void) /* initialize input from a Radiance picture */ |
496 |
|
{ |
497 |
|
int i1, i2, po; |
498 |
|
/* read Radiance header */ |
499 |
< |
CLR(C_RFLT|C_TFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM); |
499 |
> |
CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM); |
500 |
> |
cvts.capdate[0] = '\0'; |
501 |
> |
cvts.owner[0] = '\0'; |
502 |
|
cvts.stonits = 1.; |
503 |
|
cvts.pixrat = 1.; |
504 |
|
cvts.pconf = PLANARCONFIG_CONTIG; |
524 |
|
switch (cvts.phot) { |
525 |
|
case PHOTOMETRIC_LOGLUV: |
526 |
|
SET(C_RFLT|C_TFLT); |
527 |
< |
CLR(C_GRY); |
527 |
> |
CLR(C_GRY|C_TWRD); |
528 |
|
if (!CHK(C_XYZE)) { |
529 |
< |
cpcolormat(cvts.cmat, rgb2xyzmat); |
529 |
> |
comprgb2xyzWBmat(cvts.cmat, |
530 |
> |
CHK(C_PRIM) ? cvts.prims : stdprims); |
531 |
|
SET(C_CXFM); |
532 |
|
} |
533 |
|
if (cvts.comp != COMPRESSION_SGILOG && |
539 |
|
break; |
540 |
|
case PHOTOMETRIC_LOGL: |
541 |
|
SET(C_GRY|C_RFLT|C_TFLT); |
542 |
+ |
CLR(C_TWRD); |
543 |
|
if (cvts.comp != COMPRESSION_SGILOG) |
544 |
|
quiterr("internal error 3 in initfromrad"); |
545 |
|
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
551 |
|
CLR(C_GRY); |
552 |
|
setcolrgam(cvts.gamcor); |
553 |
|
if (CHK(C_XYZE)) { |
554 |
< |
compxyz2rgbmat(cvts.cmat, |
554 |
> |
compxyz2rgbWBmat(cvts.cmat, |
555 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
556 |
|
SET(C_CXFM); |
557 |
|
} |
561 |
|
TIFFSetField(cvts.tif, TIFFTAG_WHITEPOINT, |
562 |
|
(float *)cvts.prims[WHT]); |
563 |
|
} |
564 |
< |
cvts.tf = Colr2RGB; |
564 |
> |
if (CHK(C_TWRD)) { |
565 |
> |
cvts.tf = Color2RRGGBB; |
566 |
> |
SET(C_RFLT); |
567 |
> |
} else if (CHK(C_TFLT)) { |
568 |
> |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
569 |
> |
SAMPLEFORMAT_IEEEFP); |
570 |
> |
cvts.tf = Color2RfGfBf; |
571 |
> |
SET(C_RFLT); |
572 |
> |
CLR(C_GAMUT); |
573 |
> |
} else |
574 |
> |
cvts.tf = Colr2RGB; |
575 |
|
break; |
576 |
|
case PHOTOMETRIC_MINISBLACK: |
577 |
|
SET(C_GRY|C_GAMMA|C_GAMUT); |
578 |
|
setcolrgam(cvts.gamcor); |
579 |
< |
cvts.tf = Colr2Gry; |
579 |
> |
if (CHK(C_TWRD)) { |
580 |
> |
cvts.tf = Color2GGry; |
581 |
> |
SET(C_RFLT); |
582 |
> |
} else if (CHK(C_TFLT)) { |
583 |
> |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
584 |
> |
SAMPLEFORMAT_IEEEFP); |
585 |
> |
cvts.tf = Color2Gryf; |
586 |
> |
SET(C_RFLT); |
587 |
> |
} else |
588 |
> |
cvts.tf = Colr2Gry; |
589 |
|
break; |
590 |
|
default: |
591 |
|
quiterr("internal error 4 in initfromrad"); |
595 |
|
TIFFSetField(cvts.tif, TIFFTAG_IMAGEWIDTH, cvts.xmax); |
596 |
|
TIFFSetField(cvts.tif, TIFFTAG_IMAGELENGTH, cvts.ymax); |
597 |
|
TIFFSetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, CHK(C_GRY) ? 1 : 3); |
598 |
< |
TIFFSetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, CHK(C_TFLT) ? 32 : 8); |
598 |
> |
TIFFSetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, |
599 |
> |
CHK(C_TFLT) ? 32 : CHK(C_TWRD) ? 16 : 8); |
600 |
|
TIFFSetField(cvts.tif, TIFFTAG_XRESOLUTION, 72.); |
601 |
|
TIFFSetField(cvts.tif, TIFFTAG_YRESOLUTION, 72./cvts.pixrat); |
602 |
|
TIFFSetField(cvts.tif, TIFFTAG_ORIENTATION, cvts.orient); |
604 |
|
TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf); |
605 |
|
TIFFSetField(cvts.tif, TIFFTAG_STONITS, |
606 |
|
cvts.stonits/pow(2.,(double)cvts.bradj)); |
607 |
+ |
if (cvts.capdate[0]) |
608 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_DATETIME, cvts.capdate); |
609 |
+ |
if (cvts.owner[0]) |
610 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_ARTIST, cvts.owner); |
611 |
|
if (cvts.comp == COMPRESSION_NONE) |
612 |
|
i1 = TIFFScanlineSize(cvts.tif); |
613 |
|
else |
620 |
|
} |
621 |
|
|
622 |
|
|
623 |
< |
ra2tiff(ac, av) /* convert Radiance picture to TIFF image */ |
624 |
< |
int ac; |
625 |
< |
char *av[]; |
623 |
> |
static void |
624 |
> |
ra2tiff( /* convert Radiance picture to TIFF image */ |
625 |
> |
int ac, |
626 |
> |
char *av[] |
627 |
> |
) |
628 |
|
{ |
629 |
|
uint32 y; |
630 |
|
/* open Radiance file */ |
646 |
|
} |
647 |
|
|
648 |
|
|
649 |
< |
int |
650 |
< |
Luv2Color(y) /* read/convert/write Luv->COLOR scanline */ |
651 |
< |
uint32 y; |
649 |
> |
static void |
650 |
> |
Luv2Color( /* read/convert/write Luv->COLOR scanline */ |
651 |
> |
uint32 y |
652 |
> |
) |
653 |
|
{ |
654 |
|
register int x; |
655 |
|
|
658 |
|
|
659 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
660 |
|
quiterr("error reading TIFF input"); |
661 |
< |
|
661 |
> |
/* also works for float RGB */ |
662 |
|
for (x = cvts.xmax; x--; ) { |
663 |
< |
colval(cvts.r.colors[x],CIEX) = cvts.t.fp[3*x]; |
664 |
< |
colval(cvts.r.colors[x],CIEY) = cvts.t.fp[3*x + 1]; |
665 |
< |
colval(cvts.r.colors[x],CIEZ) = cvts.t.fp[3*x + 2]; |
663 |
> |
setcolor(cvts.r.colors[x], |
664 |
> |
cvts.t.fp[3*x], |
665 |
> |
cvts.t.fp[3*x + 1], |
666 |
> |
cvts.t.fp[3*x + 2]); |
667 |
|
if (CHK(C_CXFM)) |
668 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
669 |
|
cvts.r.colors[x]); |
682 |
|
} |
683 |
|
|
684 |
|
|
685 |
< |
int |
686 |
< |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
687 |
< |
uint32 y; |
685 |
> |
static void |
686 |
> |
RRGGBB2Color( /* read/convert/write RGB16->COLOR scanline */ |
687 |
> |
uint32 y |
688 |
> |
) |
689 |
|
{ |
690 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
690 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
691 |
|
register double d; |
692 |
|
register int x; |
693 |
|
|
710 |
|
if (CHK(C_CXFM)) |
711 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
712 |
|
cvts.r.colors[x]); |
581 |
– |
if (CHK(C_GAMUT)) |
582 |
– |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
583 |
– |
CGAMUT_LOWER, cblack, cwhite); |
713 |
|
} |
714 |
|
if (cvts.bradj) { |
715 |
|
d = pow(2.,(double)cvts.bradj); |
722 |
|
} |
723 |
|
|
724 |
|
|
725 |
< |
int |
726 |
< |
L2Color(y) /* read/convert/write L16->COLOR scanline */ |
727 |
< |
uint32 y; |
725 |
> |
static void |
726 |
> |
L2Color( /* read/convert/write Lfloat->COLOR scanline */ |
727 |
> |
uint32 y |
728 |
> |
) |
729 |
|
{ |
730 |
+ |
float m = pow(2., (double)cvts.bradj); |
731 |
|
register int x; |
732 |
|
|
733 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
735 |
|
|
736 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
737 |
|
quiterr("error reading TIFF input"); |
738 |
< |
|
739 |
< |
for (x = cvts.xmax; x--; ) |
740 |
< |
colval(cvts.r.colors[x],RED) = |
741 |
< |
colval(cvts.r.colors[x],GRN) = |
742 |
< |
colval(cvts.r.colors[x],BLU) = |
743 |
< |
cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
613 |
< |
|
738 |
> |
/* also works for float greyscale */ |
739 |
> |
for (x = cvts.xmax; x--; ) { |
740 |
> |
register float f = cvts.t.fp[x]; |
741 |
> |
if (cvts.bradj) f *= m; |
742 |
> |
setcolor(cvts.r.colors[x], f, f, f); |
743 |
> |
} |
744 |
|
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
745 |
|
quiterr("error writing Radiance picture"); |
746 |
|
} |
747 |
|
|
748 |
|
|
749 |
< |
int |
750 |
< |
RGB2Colr(y) /* read/convert/write RGB->COLR scanline */ |
751 |
< |
uint32 y; |
749 |
> |
static void |
750 |
> |
RGB2Colr( /* read/convert/write RGB->COLR scanline */ |
751 |
> |
uint32 y |
752 |
> |
) |
753 |
|
{ |
754 |
|
COLOR ctmp; |
755 |
|
register int x; |
803 |
|
} |
804 |
|
|
805 |
|
|
806 |
< |
int |
807 |
< |
Gry2Colr(y) /* read/convert/write G8->COLR scanline */ |
808 |
< |
uint32 y; |
806 |
> |
static void |
807 |
> |
Gry2Colr( /* read/convert/write G8->COLR scanline */ |
808 |
> |
uint32 y |
809 |
> |
) |
810 |
|
{ |
811 |
|
register int x; |
812 |
|
|
830 |
|
} |
831 |
|
|
832 |
|
|
833 |
< |
int |
834 |
< |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
835 |
< |
uint32 y; |
833 |
> |
static void |
834 |
> |
GGry2Color( /* read/convert/write G16->COLOR scanline */ |
835 |
> |
uint32 y |
836 |
> |
) |
837 |
|
{ |
838 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
838 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
839 |
|
double m; |
840 |
|
register double d; |
841 |
|
register int x; |
861 |
|
} |
862 |
|
|
863 |
|
|
864 |
< |
int |
865 |
< |
Color2L(y) /* read/convert/write COLOR->L16 scanline */ |
866 |
< |
uint32 y; |
864 |
> |
static void |
865 |
> |
Color2GGry( /* read/convert/write COLOR->G16 scanline */ |
866 |
> |
uint32 y |
867 |
> |
) |
868 |
|
{ |
869 |
< |
double m = pow(2.,(double)cvts.bradj); |
869 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
870 |
> |
float m = pow(2.,(double)cvts.bradj); |
871 |
|
register int x; |
872 |
|
|
873 |
+ |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD|C_GRY)) |
874 |
+ |
quiterr("internal error 1 in Color2GGry"); |
875 |
+ |
|
876 |
+ |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
877 |
+ |
quiterr("error reading Radiance picture"); |
878 |
+ |
|
879 |
+ |
for (x = cvts.xmax; x--; ) { |
880 |
+ |
register float f = m*( CHK(C_XYZE) ? |
881 |
+ |
colval(cvts.r.colors[x],CIEY) |
882 |
+ |
: bright(cvts.r.colors[x]) ); |
883 |
+ |
if (f <= 0) |
884 |
+ |
cvts.t.wp[x] = 0; |
885 |
+ |
else if (f >= 1) |
886 |
+ |
cvts.t.wp[x] = 0xffff; |
887 |
+ |
else if (dogamma) |
888 |
+ |
cvts.t.wp[x] = (int)((float)(1L<<16) * |
889 |
+ |
pow(f, 1./cvts.gamcor)); |
890 |
+ |
else |
891 |
+ |
cvts.t.wp[x] = (int)((float)(1L<<16) * f); |
892 |
+ |
} |
893 |
+ |
|
894 |
+ |
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
895 |
+ |
quiterr("error writing TIFF output"); |
896 |
+ |
} |
897 |
+ |
|
898 |
+ |
|
899 |
+ |
static void |
900 |
+ |
Color2L( /* read/convert/write COLOR->Lfloat scanline */ |
901 |
+ |
uint32 y |
902 |
+ |
) |
903 |
+ |
{ |
904 |
+ |
float m = pow(2.,(double)cvts.bradj); |
905 |
+ |
register int x; |
906 |
+ |
|
907 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
908 |
|
quiterr("internal error 1 in Color2L"); |
909 |
|
|
919 |
|
} |
920 |
|
|
921 |
|
|
922 |
< |
int |
923 |
< |
Color2Luv(y) /* read/convert/write COLOR->Luv scanline */ |
924 |
< |
uint32 y; |
922 |
> |
static void |
923 |
> |
Color2Luv( /* read/convert/write COLOR->Luv scanline */ |
924 |
> |
uint32 y |
925 |
> |
) |
926 |
|
{ |
927 |
|
register int x; |
928 |
|
|
941 |
|
for (x = cvts.xmax; x--; ) |
942 |
|
scalecolor(cvts.r.colors[x], m); |
943 |
|
} |
944 |
< |
|
944 |
> |
/* also works for float RGB */ |
945 |
|
for (x = cvts.xmax; x--; ) { |
946 |
|
cvts.t.fp[3*x] = colval(cvts.r.colors[x],CIEX); |
947 |
|
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],CIEY); |
953 |
|
} |
954 |
|
|
955 |
|
|
956 |
< |
int |
957 |
< |
Colr2Gry(y) /* read/convert/write COLR->RGB scanline */ |
958 |
< |
uint32 y; |
956 |
> |
static void |
957 |
> |
Color2RRGGBB( /* read/convert/write COLOR->RGB16 scanline */ |
958 |
> |
uint32 y |
959 |
> |
) |
960 |
|
{ |
961 |
+ |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
962 |
+ |
float m = pow(2.,(double)cvts.bradj); |
963 |
+ |
register int x, i; |
964 |
+ |
|
965 |
+ |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD)) |
966 |
+ |
quiterr("internal error 1 in Color2RRGGBB"); |
967 |
+ |
|
968 |
+ |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
969 |
+ |
quiterr("error reading Radiance picture"); |
970 |
+ |
|
971 |
+ |
for (x = cvts.xmax; x--; ) { |
972 |
+ |
if (CHK(C_CXFM)) { |
973 |
+ |
colortrans(cvts.r.colors[x], cvts.cmat, |
974 |
+ |
cvts.r.colors[x]); |
975 |
+ |
if (CHK(C_GAMUT)) |
976 |
+ |
clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]), |
977 |
+ |
CGAMUT_LOWER, cblack, cwhite); |
978 |
+ |
} |
979 |
+ |
for (i = 3; i--; ) { |
980 |
+ |
register float f = m*colval(cvts.r.colors[x],i); |
981 |
+ |
if (f <= 0) |
982 |
+ |
cvts.t.wp[3*x + i] = 0; |
983 |
+ |
else if (f >= 1) |
984 |
+ |
cvts.t.wp[3*x + i] = 0xffff; |
985 |
+ |
else if (dogamma) |
986 |
+ |
cvts.t.wp[3*x + i] = (int)((float)(1L<<16) * |
987 |
+ |
pow(f, 1./cvts.gamcor)); |
988 |
+ |
else |
989 |
+ |
cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f); |
990 |
+ |
} |
991 |
+ |
} |
992 |
+ |
|
993 |
+ |
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
994 |
+ |
quiterr("error writing TIFF output"); |
995 |
+ |
} |
996 |
+ |
|
997 |
+ |
|
998 |
+ |
static void |
999 |
+ |
Colr2Gry( /* read/convert/write COLR->RGB scanline */ |
1000 |
+ |
uint32 y |
1001 |
+ |
) |
1002 |
+ |
{ |
1003 |
|
register int x; |
1004 |
|
|
1005 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
1022 |
|
} |
1023 |
|
|
1024 |
|
|
1025 |
< |
int |
1026 |
< |
Colr2RGB(y) /* read/convert/write COLR->RGB scanline */ |
1027 |
< |
uint32 y; |
1025 |
> |
static void |
1026 |
> |
Colr2RGB( /* read/convert/write COLR->RGB scanline */ |
1027 |
> |
uint32 y |
1028 |
> |
) |
1029 |
|
{ |
1030 |
|
COLOR ctmp; |
1031 |
|
register int x; |