7 |
|
* Added white-balance adjustment 10/01 (GW). |
8 |
|
*/ |
9 |
|
|
10 |
– |
#include <stdio.h> |
10 |
|
#include <math.h> |
11 |
< |
#include <time.h> |
11 |
> |
#include <ctype.h> |
12 |
> |
|
13 |
> |
#include "rtio.h" |
14 |
> |
#include "platform.h" |
15 |
|
#include "tiffio.h" |
16 |
|
#include "color.h" |
17 |
|
#include "resolu.h" |
24 |
|
#define C_GAMMA 0x4 /* needs gamma correction */ |
25 |
|
#define C_GRY 0x8 /* TIFF is greyscale */ |
26 |
|
#define C_XYZE 0x10 /* Radiance is XYZE */ |
27 |
< |
#define C_RFLT 0x20 /* Radiance data is float */ |
28 |
< |
#define C_TFLT 0x40 /* TIFF data is float */ |
29 |
< |
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
30 |
< |
#define C_PRIM 0x100 /* has assigned primaries */ |
27 |
> |
#define C_SPEC 0x20 /* Radiance is spectral */ |
28 |
> |
#define C_RFLT 0x40 /* Radiance data is float */ |
29 |
> |
#define C_TFLT 0x80 /* TIFF data is float */ |
30 |
> |
#define C_TWRD 0x100 /* TIFF data is 16-bit */ |
31 |
> |
#define C_PRIM 0x200 /* has assigned primaries */ |
32 |
|
|
33 |
< |
struct { |
33 |
> |
typedef void colcvf_t(uint32 y); |
34 |
> |
|
35 |
> |
struct CONVST { |
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 */ |
44 |
|
uint16 orient; /* visual orientation (TIFF spec.) */ |
45 |
|
double stonits; /* input conversion to nits */ |
46 |
|
float pixrat; /* pixel aspect ratio */ |
47 |
+ |
int ncc; /* # color components for spectral */ |
48 |
+ |
float wpt[4]; /* wavelength partitions */ |
49 |
|
FILE *rfp; /* Radiance stream pointer */ |
50 |
|
TIFF *tif; /* TIFF pointer */ |
51 |
|
uint32 xmax, ymax; /* image dimensions */ |
54 |
|
union { |
55 |
|
COLR *colrs; /* 4-byte ???E pointer */ |
56 |
|
COLOR *colors; /* float array pointer */ |
57 |
< |
char *p; /* generic pointer */ |
57 |
> |
void *p; /* generic pointer */ |
58 |
|
} r; /* Radiance scanline */ |
59 |
|
union { |
60 |
|
uint8 *bp; /* byte pointer */ |
61 |
|
uint16 *wp; /* word pointer */ |
62 |
|
float *fp; /* float pointer */ |
63 |
< |
char *p; /* generic pointer */ |
63 |
> |
void *p; /* generic pointer */ |
64 |
|
} t; /* TIFF scanline */ |
65 |
< |
void (*tf)(); /* translation procedure */ |
65 |
> |
colcvf_t *tf; /* translation procedure */ |
66 |
|
} cvts = { /* conversion structure */ |
67 |
< |
0, COMPRESSION_NONE, PHOTOMETRIC_RGB, |
68 |
< |
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., |
67 |
> |
0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, |
68 |
> |
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., 3, |
69 |
|
}; |
70 |
|
|
71 |
|
#define CHK(f) (cvts.flags & (f)) |
73 |
|
#define CLR(f) (cvts.flags &= ~(f)) |
74 |
|
#define TGL(f) (cvts.flags ^= (f)) |
75 |
|
|
76 |
< |
void Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
77 |
< |
void Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
78 |
< |
void RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry(); |
76 |
> |
static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr; |
77 |
> |
static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry; |
78 |
> |
static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry; |
79 |
|
|
80 |
+ |
static gethfunc headline; |
81 |
+ |
static void quiterr(char *err); |
82 |
+ |
static void allocbufs(void); |
83 |
+ |
static void initfromtif(void); |
84 |
+ |
static void tiff2ra(int ac, char *av[]); |
85 |
+ |
static void initfromrad(void); |
86 |
+ |
static void ra2tiff(int ac, char *av[]); |
87 |
+ |
static void ReadRadScan(struct CONVST *cvp); |
88 |
+ |
|
89 |
+ |
|
90 |
|
#define RfGfBf2Color Luv2Color |
91 |
|
#define Gryf2Color L2Color |
92 |
|
#define Color2Gryf Color2L |
105 |
|
|
106 |
|
#define pixorder() ortab[cvts.orient-1] |
107 |
|
|
108 |
+ |
extern char TMSTR[]; /* "CAPDATE=" from header.c */ |
109 |
+ |
char OWNSTR[] = "OWNER="; |
110 |
+ |
|
111 |
|
char *progname; |
112 |
|
|
113 |
|
|
114 |
< |
main(argc, argv) |
115 |
< |
int argc; |
94 |
< |
char *argv[]; |
114 |
> |
int |
115 |
> |
main(int argc, char *argv[]) |
116 |
|
{ |
117 |
|
int reverse = 0; |
118 |
|
int i; |
176 |
|
if (i != argc-2) |
177 |
|
goto userr; |
178 |
|
/* consistency checks */ |
179 |
< |
if (CHK(C_GRY)) |
179 |
> |
if (CHK(C_GRY)) { |
180 |
|
if (cvts.phot == PHOTOMETRIC_RGB) |
181 |
|
cvts.phot = PHOTOMETRIC_MINISBLACK; |
182 |
|
else { |
183 |
|
cvts.phot = PHOTOMETRIC_LOGL; |
184 |
|
cvts.comp = COMPRESSION_SGILOG; |
185 |
|
} |
186 |
+ |
} |
187 |
|
if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT)) |
188 |
|
goto userr; |
189 |
|
|
193 |
|
exit(0); |
194 |
|
userr: |
195 |
|
fprintf(stderr, |
196 |
< |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n", |
196 |
> |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n", |
197 |
|
progname); |
198 |
|
fprintf(stderr, |
199 |
< |
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n", |
199 |
> |
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n", |
200 |
|
progname); |
201 |
|
exit(1); |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
quiterr(err) /* print message and exit */ |
206 |
< |
char *err; |
205 |
> |
static void |
206 |
> |
quiterr( /* print message and exit */ |
207 |
> |
char *err |
208 |
> |
) |
209 |
|
{ |
210 |
|
if (err != NULL) { |
211 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
< |
allocbufs() /* allocate scanline buffers */ |
218 |
> |
static void |
219 |
> |
allocbufs(void) /* allocate scanline buffers */ |
220 |
|
{ |
221 |
|
int rsiz, tsiz; |
222 |
|
|
224 |
|
tsiz = (CHK(C_TFLT) ? sizeof(float) : |
225 |
|
CHK(C_TWRD) ? sizeof(uint16) : sizeof(uint8)) * |
226 |
|
(CHK(C_GRY) ? 1 : 3); |
227 |
< |
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
228 |
< |
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
229 |
< |
if (cvts.r.p == NULL | cvts.t.p == NULL) |
227 |
> |
cvts.r.p = malloc(rsiz*cvts.xmax); |
228 |
> |
cvts.t.p = malloc(tsiz*cvts.xmax); |
229 |
> |
if ((cvts.r.p == NULL) | (cvts.t.p == NULL)) |
230 |
|
quiterr("no memory to allocate scanline buffers"); |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
< |
initfromtif() /* initialize conversion from TIFF input */ |
234 |
> |
static void |
235 |
> |
initfromtif(void) /* initialize conversion from TIFF input */ |
236 |
|
{ |
237 |
|
uint16 hi; |
238 |
+ |
char *cp; |
239 |
|
float *fa, f1, f2; |
240 |
|
|
214 |
– |
CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM); |
215 |
– |
|
241 |
|
TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_PLANARCONFIG, &cvts.pconf); |
242 |
|
|
243 |
|
if (TIFFGetField(cvts.tif, TIFFTAG_PRIMARYCHROMATICITIES, &fa)) { |
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, |
362 |
|
quiterr("unknown input image resolution"); |
363 |
|
|
364 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) |
365 |
< |
cvts.stonits = 1.; |
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); |
382 |
|
if (CHK(C_XYZE)) { |
383 |
< |
fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); |
383 |
> |
if (cvts.stonits > .0) |
384 |
> |
fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); |
385 |
|
fputformat(CIEFMT, cvts.rfp); |
386 |
|
} else { |
387 |
|
if (CHK(C_PRIM)) |
388 |
|
fputprims(cvts.prims, cvts.rfp); |
389 |
< |
fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, |
390 |
< |
cvts.rfp); |
389 |
> |
if (cvts.stonits > .0) |
390 |
> |
fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, |
391 |
> |
cvts.rfp); |
392 |
|
fputformat(COLRFMT, cvts.rfp); |
393 |
|
} |
394 |
+ |
if (cvts.capdate[0]) |
395 |
+ |
fprintf(cvts.rfp, "%s %s\n", TMSTR, cvts.capdate); |
396 |
+ |
if (cvts.owner[0]) |
397 |
+ |
fprintf(cvts.rfp, "%s %s\n", OWNSTR, cvts.owner); |
398 |
|
|
399 |
|
allocbufs(); /* allocate scanline buffers */ |
400 |
|
} |
401 |
|
|
402 |
|
|
403 |
< |
tiff2ra(ac, av) /* convert TIFF image to Radiance picture */ |
404 |
< |
int ac; |
405 |
< |
char *av[]; |
403 |
> |
static void |
404 |
> |
tiff2ra( /* convert TIFF image to Radiance picture */ |
405 |
> |
int ac, |
406 |
> |
char *av[] |
407 |
> |
) |
408 |
|
{ |
409 |
|
int32 y; |
410 |
|
/* open TIFF input */ |
415 |
|
cvts.rfp = stdout; |
416 |
|
else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL) |
417 |
|
quiterr("cannot open Radiance output picture"); |
418 |
+ |
SET_FILE_BINARY(cvts.rfp); |
419 |
|
/* start output header */ |
420 |
|
newheader("RADIANCE", cvts.rfp); |
421 |
|
printargs(ac, av, cvts.rfp); |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
< |
int |
437 |
< |
headline(s) /* process Radiance input header line */ |
438 |
< |
char *s; |
436 |
> |
static int |
437 |
> |
headline( /* process Radiance input header line */ |
438 |
> |
char *s, |
439 |
> |
void *p |
440 |
> |
) |
441 |
|
{ |
442 |
< |
char fmt[32]; |
442 |
> |
static int tmstrlen = 0; |
443 |
> |
static int ownstrlen = 0; |
444 |
> |
struct CONVST *cvp = (struct CONVST *)p; |
445 |
> |
char fmt[MAXFMTLEN]; |
446 |
|
|
447 |
+ |
if (!tmstrlen) { |
448 |
+ |
tmstrlen = strlen(TMSTR); |
449 |
+ |
ownstrlen = strlen(OWNSTR); |
450 |
+ |
} |
451 |
|
if (formatval(fmt, s)) { |
452 |
< |
if (!strcmp(fmt, COLRFMT)) |
453 |
< |
CLR(C_XYZE); |
398 |
< |
else if (!strcmp(fmt, CIEFMT)) |
452 |
> |
CLR(C_XYZE|C_SPEC); |
453 |
> |
if (!strcmp(fmt, CIEFMT)) |
454 |
|
SET(C_XYZE); |
455 |
< |
else |
456 |
< |
quiterr("unrecognized input picture format"); |
455 |
> |
else if (!strcmp(fmt, SPECFMT)) |
456 |
> |
SET(C_SPEC); |
457 |
> |
else if (strcmp(fmt, COLRFMT)) |
458 |
> |
return(-1); |
459 |
|
return(1); |
460 |
|
} |
461 |
|
if (isexpos(s)) { |
462 |
< |
cvts.stonits /= exposval(s); |
462 |
> |
cvp->stonits /= exposval(s); |
463 |
|
return(1); |
464 |
|
} |
465 |
|
if (isaspect(s)) { |
466 |
< |
cvts.pixrat *= aspectval(s); |
466 |
> |
cvp->pixrat *= aspectval(s); |
467 |
|
return(1); |
468 |
|
} |
469 |
|
if (isprims(s)) { |
470 |
< |
primsval(cvts.prims, s); |
470 |
> |
primsval(cvp->prims, s); |
471 |
|
SET(C_PRIM); |
472 |
|
return(1); |
473 |
|
} |
474 |
+ |
if (isdate(s)) { |
475 |
+ |
if (s[tmstrlen] == ' ') |
476 |
+ |
strncpy(cvp->capdate, s+tmstrlen+1, 19); |
477 |
+ |
else |
478 |
+ |
strncpy(cvp->capdate, s+tmstrlen, 19); |
479 |
+ |
cvp->capdate[19] = '\0'; |
480 |
+ |
return(1); |
481 |
+ |
} |
482 |
+ |
if (!strncmp(s, OWNSTR, ownstrlen)) { |
483 |
+ |
char *cp = s + ownstrlen; |
484 |
+ |
|
485 |
+ |
while (isspace(*cp)) |
486 |
+ |
++cp; |
487 |
+ |
strncpy(cvp->owner, cp, sizeof(cvp->owner)); |
488 |
+ |
cvp->owner[sizeof(cvp->owner)-1] = '\0'; |
489 |
+ |
for (cp = cvp->owner; *cp; cp++) |
490 |
+ |
; |
491 |
+ |
while (cp > cvp->owner && isspace(cp[-1])) |
492 |
+ |
*--cp = '\0'; |
493 |
+ |
return(1); |
494 |
+ |
} |
495 |
+ |
if (isncomp(s)) { |
496 |
+ |
cvp->ncc = ncompval(s); |
497 |
+ |
return((3 <= cvp->ncc) & (cvp->ncc < MAXCSAMP) ? 1 : -1); |
498 |
+ |
} |
499 |
+ |
if (iswlsplit(s)) |
500 |
+ |
return(wlsplitval(cvp->wpt, s) ? 1 : -1); |
501 |
|
return(0); |
502 |
|
} |
503 |
|
|
504 |
|
|
505 |
< |
initfromrad() /* initialize input from a Radiance picture */ |
505 |
> |
static void |
506 |
> |
initfromrad(void) /* initialize input from a Radiance picture */ |
507 |
|
{ |
508 |
|
int i1, i2, po; |
509 |
|
/* read Radiance header */ |
510 |
< |
CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM); |
511 |
< |
cvts.stonits = 1.; |
512 |
< |
cvts.pixrat = 1.; |
428 |
< |
cvts.pconf = PLANARCONFIG_CONTIG; |
429 |
< |
getheader(cvts.rfp, headline, NULL); |
430 |
< |
if ((po = fgetresolu(&i1, &i2, cvts.rfp)) < 0) |
510 |
> |
memcpy(cvts.wpt, WLPART, sizeof(cvts.wpt)); |
511 |
> |
if (getheader(cvts.rfp, headline, &cvts) < 0 || |
512 |
> |
(po = fgetresolu(&i1, &i2, cvts.rfp)) < 0) |
513 |
|
quiterr("bad Radiance picture"); |
514 |
|
cvts.xmax = i1; cvts.ymax = i2; |
515 |
|
for (i1 = 0; i1 < 8; i1++) /* interpret orientation */ |
531 |
|
case PHOTOMETRIC_LOGLUV: |
532 |
|
SET(C_RFLT|C_TFLT); |
533 |
|
CLR(C_GRY|C_TWRD); |
534 |
< |
if (!CHK(C_XYZE)) { |
534 |
> |
if (!CHK(C_XYZE|C_SPEC)) { |
535 |
|
comprgb2xyzWBmat(cvts.cmat, |
536 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
537 |
|
SET(C_CXFM); |
556 |
|
SET(C_GAMMA|C_GAMUT); |
557 |
|
CLR(C_GRY); |
558 |
|
setcolrgam(cvts.gamcor); |
559 |
< |
if (CHK(C_XYZE)) { |
559 |
> |
if (CHK(C_XYZE|C_SPEC)) { |
560 |
|
compxyz2rgbWBmat(cvts.cmat, |
561 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
562 |
|
SET(C_CXFM); |
571 |
|
cvts.tf = Color2RRGGBB; |
572 |
|
SET(C_RFLT); |
573 |
|
} else if (CHK(C_TFLT)) { |
574 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
575 |
+ |
SAMPLEFORMAT_IEEEFP); |
576 |
|
cvts.tf = Color2RfGfBf; |
577 |
|
SET(C_RFLT); |
578 |
+ |
CLR(C_GAMUT); |
579 |
|
} else |
580 |
|
cvts.tf = Colr2RGB; |
581 |
|
break; |
586 |
|
cvts.tf = Color2GGry; |
587 |
|
SET(C_RFLT); |
588 |
|
} else if (CHK(C_TFLT)) { |
589 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
590 |
+ |
SAMPLEFORMAT_IEEEFP); |
591 |
|
cvts.tf = Color2Gryf; |
592 |
|
SET(C_RFLT); |
593 |
|
} else |
610 |
|
TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf); |
611 |
|
TIFFSetField(cvts.tif, TIFFTAG_STONITS, |
612 |
|
cvts.stonits/pow(2.,(double)cvts.bradj)); |
613 |
+ |
if (cvts.capdate[0]) |
614 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_DATETIME, cvts.capdate); |
615 |
+ |
if (cvts.owner[0]) |
616 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_ARTIST, cvts.owner); |
617 |
|
if (cvts.comp == COMPRESSION_NONE) |
618 |
|
i1 = TIFFScanlineSize(cvts.tif); |
619 |
|
else |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
< |
ra2tiff(ac, av) /* convert Radiance picture to TIFF image */ |
630 |
< |
int ac; |
631 |
< |
char *av[]; |
629 |
> |
static void |
630 |
> |
ra2tiff( /* convert Radiance picture to TIFF image */ |
631 |
> |
int ac, |
632 |
> |
char *av[] |
633 |
> |
) |
634 |
|
{ |
635 |
|
uint32 y; |
636 |
|
/* open Radiance file */ |
638 |
|
cvts.rfp = stdin; |
639 |
|
else if ((cvts.rfp = fopen(av[ac], "r")) == NULL) |
640 |
|
quiterr("cannot open Radiance input picture"); |
641 |
+ |
SET_FILE_BINARY(cvts.rfp); |
642 |
|
/* open TIFF file */ |
643 |
|
if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL) |
644 |
|
quiterr("cannot open TIFF output"); |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
< |
void |
657 |
< |
Luv2Color(y) /* read/convert/write Luv->COLOR scanline */ |
564 |
< |
uint32 y; |
656 |
> |
static void |
657 |
> |
ReadRadScan(struct CONVST *cvp) |
658 |
|
{ |
659 |
< |
register int x; |
659 |
> |
static struct CONVST *lastcvp = NULL; |
660 |
> |
static COLOR scomp[MAXCSAMP]; |
661 |
|
|
662 |
+ |
if (cvp->ncc > 3) { /* convert spectral pixels */ |
663 |
+ |
SCOLR sclr; |
664 |
+ |
SCOLOR scol; |
665 |
+ |
COLOR xyz; |
666 |
+ |
int x, n; |
667 |
+ |
if (lastcvp != cvp) { |
668 |
+ |
for (n = cvp->ncc; n--; ) |
669 |
+ |
spec_cie(scomp[n], |
670 |
+ |
cvp->wpt[0] + (cvp->wpt[3] - cvp->wpt[0])*(n+1)/cvp->ncc, |
671 |
+ |
cvp->wpt[0] + (cvp->wpt[3] - cvp->wpt[0])*n/cvp->ncc); |
672 |
+ |
lastcvp = cvp; |
673 |
+ |
} |
674 |
+ |
for (x = 0; x < cvp->xmax; x++) { |
675 |
+ |
if (getbinary(sclr, cvp->ncc+1, 1, cvp->rfp) != 1) |
676 |
+ |
goto readerr; |
677 |
+ |
scolr2scolor(scol, sclr, cvp->ncc); |
678 |
+ |
setcolor(cvp->r.colors[x], 0, 0, 0); |
679 |
+ |
for (n = cvp->ncc; n--; ) { |
680 |
+ |
copycolor(xyz, scomp[n]); |
681 |
+ |
scalecolor(xyz, scol[n]); |
682 |
+ |
addcolor(cvp->r.colors[x], xyz); |
683 |
+ |
} |
684 |
+ |
} |
685 |
+ |
return; |
686 |
+ |
} |
687 |
+ |
if (freadscan(cvp->r.colors, cvp->xmax, cvp->rfp) >= 0) |
688 |
+ |
return; |
689 |
+ |
readerr: |
690 |
+ |
quiterr("error reading Radiance picture"); |
691 |
+ |
} |
692 |
+ |
|
693 |
+ |
|
694 |
+ |
static void |
695 |
+ |
Luv2Color( /* read/convert/write Luv->COLOR scanline */ |
696 |
+ |
uint32 y |
697 |
+ |
) |
698 |
+ |
{ |
699 |
+ |
int x; |
700 |
+ |
|
701 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
702 |
|
quiterr("internal error 1 in Luv2Color"); |
703 |
|
|
704 |
+ |
if (cvts.pconf != PLANARCONFIG_CONTIG) |
705 |
+ |
quiterr("cannot handle separate 32-bit color planes"); |
706 |
+ |
|
707 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
708 |
|
quiterr("error reading TIFF input"); |
709 |
|
/* also works for float RGB */ |
730 |
|
} |
731 |
|
|
732 |
|
|
733 |
< |
void |
734 |
< |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
735 |
< |
uint32 y; |
733 |
> |
static void |
734 |
> |
RRGGBB2Color( /* read/convert/write RGB16->COLOR scanline */ |
735 |
> |
uint32 y |
736 |
> |
) |
737 |
|
{ |
738 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
739 |
< |
register double d; |
740 |
< |
register int x; |
738 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
739 |
> |
double d; |
740 |
> |
int x; |
741 |
|
|
742 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) |
743 |
|
quiterr("internal error 1 in RRGGBB2Color"); |
744 |
|
|
745 |
+ |
if (cvts.pconf != PLANARCONFIG_CONTIG) |
746 |
+ |
quiterr("cannot handle separate 16-bit color planes"); |
747 |
+ |
|
748 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
749 |
|
quiterr("error reading TIFF input"); |
750 |
|
|
761 |
|
if (CHK(C_CXFM)) |
762 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
763 |
|
cvts.r.colors[x]); |
624 |
– |
if (CHK(C_GAMUT)) |
625 |
– |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
626 |
– |
CGAMUT_LOWER, cblack, cwhite); |
764 |
|
} |
765 |
|
if (cvts.bradj) { |
766 |
|
d = pow(2.,(double)cvts.bradj); |
773 |
|
} |
774 |
|
|
775 |
|
|
776 |
< |
void |
777 |
< |
L2Color(y) /* read/convert/write Lfloat->COLOR scanline */ |
778 |
< |
uint32 y; |
776 |
> |
static void |
777 |
> |
L2Color( /* read/convert/write Lfloat->COLOR scanline */ |
778 |
> |
uint32 y |
779 |
> |
) |
780 |
|
{ |
781 |
|
float m = pow(2., (double)cvts.bradj); |
782 |
< |
register int x; |
782 |
> |
int x; |
783 |
|
|
784 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
785 |
|
quiterr("internal error 1 in L2Color"); |
788 |
|
quiterr("error reading TIFF input"); |
789 |
|
/* also works for float greyscale */ |
790 |
|
for (x = cvts.xmax; x--; ) { |
791 |
< |
register float f = cvts.t.fp[x]; |
791 |
> |
float f = cvts.t.fp[x]; |
792 |
|
if (cvts.bradj) f *= m; |
793 |
|
setcolor(cvts.r.colors[x], f, f, f); |
794 |
|
} |
797 |
|
} |
798 |
|
|
799 |
|
|
800 |
< |
void |
801 |
< |
RGB2Colr(y) /* read/convert/write RGB->COLR scanline */ |
802 |
< |
uint32 y; |
800 |
> |
static void |
801 |
> |
RGB2Colr( /* read/convert/write RGB->COLR scanline */ |
802 |
> |
uint32 y |
803 |
> |
) |
804 |
|
{ |
805 |
|
COLOR ctmp; |
806 |
< |
register int x; |
806 |
> |
int x; |
807 |
|
|
808 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY)) |
809 |
|
quiterr("internal error 1 in RGB2Colr"); |
854 |
|
} |
855 |
|
|
856 |
|
|
857 |
< |
void |
858 |
< |
Gry2Colr(y) /* read/convert/write G8->COLR scanline */ |
859 |
< |
uint32 y; |
857 |
> |
static void |
858 |
> |
Gry2Colr( /* read/convert/write G8->COLR scanline */ |
859 |
> |
uint32 y |
860 |
> |
) |
861 |
|
{ |
862 |
< |
register int x; |
862 |
> |
int x; |
863 |
|
|
864 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
865 |
|
quiterr("internal error 1 in Gry2Colr"); |
881 |
|
} |
882 |
|
|
883 |
|
|
884 |
< |
void |
885 |
< |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
886 |
< |
uint32 y; |
884 |
> |
static void |
885 |
> |
GGry2Color( /* read/convert/write G16->COLOR scanline */ |
886 |
> |
uint32 y |
887 |
> |
) |
888 |
|
{ |
889 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
889 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
890 |
|
double m; |
891 |
< |
register double d; |
892 |
< |
register int x; |
891 |
> |
double d; |
892 |
> |
int x; |
893 |
|
|
894 |
|
if (CHK(C_TFLT|C_TWRD|C_GRY|C_RFLT) != (C_GRY|C_RFLT|C_TWRD)) |
895 |
|
quiterr("internal error 1 in GGry2Color"); |
912 |
|
} |
913 |
|
|
914 |
|
|
915 |
< |
void |
916 |
< |
Color2GGry(y) /* read/convert/write COLOR->G16 scanline */ |
917 |
< |
uint32 y; |
915 |
> |
static void |
916 |
> |
Color2GGry( /* read/convert/write COLOR->G16 scanline */ |
917 |
> |
uint32 y |
918 |
> |
) |
919 |
|
{ |
920 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
920 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
921 |
|
float m = pow(2.,(double)cvts.bradj); |
922 |
< |
register int x; |
922 |
> |
int x; |
923 |
|
|
924 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD|C_GRY)) |
925 |
|
quiterr("internal error 1 in Color2GGry"); |
926 |
|
|
927 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
786 |
< |
quiterr("error reading Radiance picture"); |
927 |
> |
ReadRadScan(&cvts); |
928 |
|
|
929 |
|
for (x = cvts.xmax; x--; ) { |
930 |
< |
register float f = m*( CHK(C_XYZE) ? |
930 |
> |
float f = m*( CHK(C_XYZE) ? |
931 |
|
colval(cvts.r.colors[x],CIEY) |
932 |
|
: bright(cvts.r.colors[x]) ); |
933 |
|
if (f <= 0) |
946 |
|
} |
947 |
|
|
948 |
|
|
949 |
< |
void |
950 |
< |
Color2L(y) /* read/convert/write COLOR->Lfloat scanline */ |
951 |
< |
uint32 y; |
949 |
> |
static void |
950 |
> |
Color2L( /* read/convert/write COLOR->Lfloat scanline */ |
951 |
> |
uint32 y |
952 |
> |
) |
953 |
|
{ |
954 |
|
float m = pow(2.,(double)cvts.bradj); |
955 |
< |
register int x; |
955 |
> |
int x; |
956 |
|
|
957 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
958 |
|
quiterr("internal error 1 in Color2L"); |
959 |
|
|
960 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
819 |
< |
quiterr("error reading Radiance picture"); |
960 |
> |
ReadRadScan(&cvts); |
961 |
|
|
962 |
|
for (x = cvts.xmax; x--; ) |
963 |
|
cvts.t.fp[x] = m*( CHK(C_XYZE) ? colval(cvts.r.colors[x],CIEY) |
968 |
|
} |
969 |
|
|
970 |
|
|
971 |
< |
void |
972 |
< |
Color2Luv(y) /* read/convert/write COLOR->Luv scanline */ |
973 |
< |
uint32 y; |
971 |
> |
static void |
972 |
> |
Color2Luv( /* read/convert/write COLOR->Luv scanline */ |
973 |
> |
uint32 y |
974 |
> |
) |
975 |
|
{ |
976 |
< |
register int x; |
976 |
> |
int x; |
977 |
|
|
978 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
979 |
|
quiterr("internal error 1 in Color2Luv"); |
980 |
|
|
981 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
840 |
< |
quiterr("error reading Radiance picture"); |
981 |
> |
ReadRadScan(&cvts); |
982 |
|
|
983 |
|
if (CHK(C_CXFM)) |
984 |
|
for (x = cvts.xmax; x--; ) |
1001 |
|
} |
1002 |
|
|
1003 |
|
|
1004 |
< |
void |
1005 |
< |
Color2RRGGBB(y) /* read/convert/write COLOR->RGB16 scanline */ |
1006 |
< |
uint32 y; |
1004 |
> |
static void |
1005 |
> |
Color2RRGGBB( /* read/convert/write COLOR->RGB16 scanline */ |
1006 |
> |
uint32 y |
1007 |
> |
) |
1008 |
|
{ |
1009 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
1009 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
1010 |
|
float m = pow(2.,(double)cvts.bradj); |
1011 |
< |
register int x, i; |
1011 |
> |
int x, i; |
1012 |
|
|
1013 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD)) |
1014 |
|
quiterr("internal error 1 in Color2RRGGBB"); |
1015 |
|
|
1016 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
875 |
< |
quiterr("error reading Radiance picture"); |
1016 |
> |
ReadRadScan(&cvts); |
1017 |
|
|
1018 |
< |
for (x = cvts.xmax; x--; ) |
1018 |
> |
for (x = cvts.xmax; x--; ) { |
1019 |
> |
if (CHK(C_CXFM)) { |
1020 |
> |
colortrans(cvts.r.colors[x], cvts.cmat, |
1021 |
> |
cvts.r.colors[x]); |
1022 |
> |
if (CHK(C_GAMUT)) |
1023 |
> |
clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]), |
1024 |
> |
CGAMUT_LOWER, cblack, cwhite); |
1025 |
> |
} |
1026 |
|
for (i = 3; i--; ) { |
1027 |
< |
register float f = m*colval(cvts.r.colors[x],i); |
1027 |
> |
float f = m*colval(cvts.r.colors[x],i); |
1028 |
|
if (f <= 0) |
1029 |
|
cvts.t.wp[3*x + i] = 0; |
1030 |
|
else if (f >= 1) |
1035 |
|
else |
1036 |
|
cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f); |
1037 |
|
} |
1038 |
+ |
} |
1039 |
|
|
1040 |
|
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
1041 |
|
quiterr("error writing TIFF output"); |
1042 |
|
} |
1043 |
|
|
1044 |
|
|
1045 |
< |
void |
1046 |
< |
Colr2Gry(y) /* read/convert/write COLR->RGB scanline */ |
1047 |
< |
uint32 y; |
1045 |
> |
static void |
1046 |
> |
Colr2Gry( /* read/convert/write COLR->RGB scanline */ |
1047 |
> |
uint32 y |
1048 |
> |
) |
1049 |
|
{ |
1050 |
< |
register int x; |
1050 |
> |
int x; |
1051 |
|
|
1052 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
1053 |
|
quiterr("internal error 1 in Colr2Gry"); |
1054 |
|
|
1055 |
< |
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
1055 |
> |
if (fread2colrs(cvts.r.colrs, cvts.xmax, cvts.rfp, |
1056 |
> |
cvts.ncc, cvts.wpt) < 0) |
1057 |
|
quiterr("error reading Radiance picture"); |
1058 |
|
|
1059 |
|
if (cvts.bradj) |
1070 |
|
} |
1071 |
|
|
1072 |
|
|
1073 |
< |
void |
1074 |
< |
Colr2RGB(y) /* read/convert/write COLR->RGB scanline */ |
1075 |
< |
uint32 y; |
1073 |
> |
static void |
1074 |
> |
Colr2RGB( /* read/convert/write COLR->RGB scanline */ |
1075 |
> |
uint32 y |
1076 |
> |
) |
1077 |
|
{ |
1078 |
|
COLOR ctmp; |
1079 |
< |
register int x; |
1079 |
> |
int x; |
1080 |
|
|
1081 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY)) |
1082 |
|
quiterr("internal error 1 in Colr2RGB"); |
1083 |
|
|
1084 |
< |
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
1084 |
> |
if (fread2colrs(cvts.r.colrs, cvts.xmax, cvts.rfp, |
1085 |
> |
cvts.ncc, cvts.wpt) < 0) |
1086 |
|
quiterr("error reading Radiance picture"); |
1087 |
|
|
1088 |
|
if (cvts.bradj) |