| 7 |
|
* Added white-balance adjustment 10/01 (GW). |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
– |
#include <stdio.h> |
| 10 |
|
#include <math.h> |
| 11 |
|
#include <ctype.h> |
| 12 |
+ |
#include "rtio.h" |
| 13 |
+ |
#include "platform.h" |
| 14 |
|
#include "tiffio.h" |
| 15 |
|
#include "color.h" |
| 16 |
|
#include "resolu.h" |
| 23 |
|
#define C_GAMMA 0x4 /* needs gamma correction */ |
| 24 |
|
#define C_GRY 0x8 /* TIFF is greyscale */ |
| 25 |
|
#define C_XYZE 0x10 /* Radiance is XYZE */ |
| 26 |
< |
#define C_RFLT 0x20 /* Radiance data is float */ |
| 27 |
< |
#define C_TFLT 0x40 /* TIFF data is float */ |
| 28 |
< |
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
| 29 |
< |
#define C_PRIM 0x100 /* has assigned primaries */ |
| 26 |
> |
#define C_SPEC 0x20 /* Radiance is spectral */ |
| 27 |
> |
#define C_RFLT 0x40 /* Radiance data is float */ |
| 28 |
> |
#define C_TFLT 0x80 /* TIFF data is float */ |
| 29 |
> |
#define C_TWRD 0x100 /* TIFF data is 16-bit */ |
| 30 |
> |
#define C_PRIM 0x200 /* has assigned primaries */ |
| 31 |
|
|
| 32 |
< |
struct { |
| 32 |
> |
typedef void colcvf_t(uint32 y); |
| 33 |
> |
|
| 34 |
> |
struct CONVST { |
| 35 |
|
uint16 flags; /* conversion flags (defined above) */ |
| 36 |
|
char capdate[20]; /* capture date/time */ |
| 37 |
|
char owner[256]; /* content owner */ |
| 43 |
|
uint16 orient; /* visual orientation (TIFF spec.) */ |
| 44 |
|
double stonits; /* input conversion to nits */ |
| 45 |
|
float pixrat; /* pixel aspect ratio */ |
| 46 |
+ |
int ncc; /* # color components for spectral */ |
| 47 |
+ |
float wpt[4]; /* wavelength partitions */ |
| 48 |
|
FILE *rfp; /* Radiance stream pointer */ |
| 49 |
|
TIFF *tif; /* TIFF pointer */ |
| 50 |
|
uint32 xmax, ymax; /* image dimensions */ |
| 53 |
|
union { |
| 54 |
|
COLR *colrs; /* 4-byte ???E pointer */ |
| 55 |
|
COLOR *colors; /* float array pointer */ |
| 56 |
< |
char *p; /* generic pointer */ |
| 56 |
> |
void *p; /* generic pointer */ |
| 57 |
|
} r; /* Radiance scanline */ |
| 58 |
|
union { |
| 59 |
|
uint8 *bp; /* byte pointer */ |
| 60 |
|
uint16 *wp; /* word pointer */ |
| 61 |
|
float *fp; /* float pointer */ |
| 62 |
< |
char *p; /* generic pointer */ |
| 62 |
> |
void *p; /* generic pointer */ |
| 63 |
|
} t; /* TIFF scanline */ |
| 64 |
< |
void (*tf)(); /* translation procedure */ |
| 64 |
> |
colcvf_t *tf; /* translation procedure */ |
| 65 |
|
} cvts = { /* conversion structure */ |
| 66 |
|
0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, |
| 67 |
< |
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., |
| 67 |
> |
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., 3, |
| 68 |
|
}; |
| 69 |
|
|
| 70 |
|
#define CHK(f) (cvts.flags & (f)) |
| 72 |
|
#define CLR(f) (cvts.flags &= ~(f)) |
| 73 |
|
#define TGL(f) (cvts.flags ^= (f)) |
| 74 |
|
|
| 75 |
< |
void Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
| 76 |
< |
void Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
| 77 |
< |
void RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry(); |
| 75 |
> |
static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr; |
| 76 |
> |
static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry; |
| 77 |
> |
static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry; |
| 78 |
|
|
| 79 |
+ |
static gethfunc headline; |
| 80 |
+ |
static void quiterr(char *err); |
| 81 |
+ |
static void allocbufs(void); |
| 82 |
+ |
static void initfromtif(void); |
| 83 |
+ |
static void tiff2ra(int ac, char *av[]); |
| 84 |
+ |
static void initfromrad(void); |
| 85 |
+ |
static void ra2tiff(int ac, char *av[]); |
| 86 |
+ |
static void ReadRadScan(struct CONVST *cvp); |
| 87 |
+ |
|
| 88 |
+ |
|
| 89 |
|
#define RfGfBf2Color Luv2Color |
| 90 |
|
#define Gryf2Color L2Color |
| 91 |
|
#define Color2Gryf Color2L |
| 107 |
|
extern char TMSTR[]; /* "CAPDATE=" from header.c */ |
| 108 |
|
char OWNSTR[] = "OWNER="; |
| 109 |
|
|
| 94 |
– |
char *progname; |
| 110 |
|
|
| 111 |
< |
|
| 112 |
< |
main(argc, argv) |
| 98 |
< |
int argc; |
| 99 |
< |
char *argv[]; |
| 111 |
> |
int |
| 112 |
> |
main(int argc, char *argv[]) |
| 113 |
|
{ |
| 114 |
|
int reverse = 0; |
| 115 |
|
int i; |
| 116 |
< |
|
| 117 |
< |
progname = argv[0]; |
| 116 |
> |
/* set global progname */ |
| 117 |
> |
fixargv0(argv[0]); |
| 118 |
|
|
| 119 |
|
for (i = 1; i < argc; i++) |
| 120 |
|
if (argv[i][0] == '-') |
| 173 |
|
if (i != argc-2) |
| 174 |
|
goto userr; |
| 175 |
|
/* consistency checks */ |
| 176 |
< |
if (CHK(C_GRY)) |
| 176 |
> |
if (CHK(C_GRY)) { |
| 177 |
|
if (cvts.phot == PHOTOMETRIC_RGB) |
| 178 |
|
cvts.phot = PHOTOMETRIC_MINISBLACK; |
| 179 |
|
else { |
| 180 |
|
cvts.phot = PHOTOMETRIC_LOGL; |
| 181 |
|
cvts.comp = COMPRESSION_SGILOG; |
| 182 |
|
} |
| 183 |
+ |
} |
| 184 |
|
if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT)) |
| 185 |
|
goto userr; |
| 186 |
|
|
| 190 |
|
exit(0); |
| 191 |
|
userr: |
| 192 |
|
fprintf(stderr, |
| 193 |
< |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n", |
| 193 |
> |
"Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n", |
| 194 |
|
progname); |
| 195 |
|
fprintf(stderr, |
| 196 |
< |
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n", |
| 196 |
> |
" Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n", |
| 197 |
|
progname); |
| 198 |
|
exit(1); |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
|
| 202 |
< |
quiterr(err) /* print message and exit */ |
| 203 |
< |
char *err; |
| 202 |
> |
static void |
| 203 |
> |
quiterr( /* print message and exit */ |
| 204 |
> |
char *err |
| 205 |
> |
) |
| 206 |
|
{ |
| 207 |
|
if (err != NULL) { |
| 208 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
|
| 215 |
< |
allocbufs() /* allocate scanline buffers */ |
| 215 |
> |
static void |
| 216 |
> |
allocbufs(void) /* allocate scanline buffers */ |
| 217 |
|
{ |
| 218 |
|
int rsiz, tsiz; |
| 219 |
|
|
| 221 |
|
tsiz = (CHK(C_TFLT) ? sizeof(float) : |
| 222 |
|
CHK(C_TWRD) ? sizeof(uint16) : sizeof(uint8)) * |
| 223 |
|
(CHK(C_GRY) ? 1 : 3); |
| 224 |
< |
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
| 225 |
< |
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
| 226 |
< |
if (cvts.r.p == NULL | cvts.t.p == NULL) |
| 224 |
> |
cvts.r.p = malloc(rsiz*cvts.xmax); |
| 225 |
> |
cvts.t.p = malloc(tsiz*cvts.xmax); |
| 226 |
> |
if ((cvts.r.p == NULL) | (cvts.t.p == NULL)) |
| 227 |
|
quiterr("no memory to allocate scanline buffers"); |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
|
| 231 |
< |
initfromtif() /* initialize conversion from TIFF input */ |
| 231 |
> |
static void |
| 232 |
> |
initfromtif(void) /* initialize conversion from TIFF input */ |
| 233 |
|
{ |
| 234 |
|
uint16 hi; |
| 235 |
|
char *cp; |
| 236 |
|
float *fa, f1, f2; |
| 237 |
|
|
| 220 |
– |
CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM); |
| 221 |
– |
|
| 238 |
|
TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_PLANARCONFIG, &cvts.pconf); |
| 239 |
|
|
| 240 |
|
if (TIFFGetField(cvts.tif, TIFFTAG_PRIMARYCHROMATICITIES, &fa)) { |
| 272 |
|
cpcolormat(cvts.cmat, xyz2rgbmat); |
| 273 |
|
SET(C_CXFM|C_GAMUT); |
| 274 |
|
} else if (cvts.comp == COMPRESSION_SGILOG) |
| 275 |
< |
SET(C_GAMUT); |
| 275 |
> |
SET(C_GAMUT); /* may be outside XYZ gamut */ |
| 276 |
|
if (cvts.pconf != PLANARCONFIG_CONTIG) |
| 277 |
|
quiterr("cannot handle separate Luv planes"); |
| 278 |
|
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
| 359 |
|
quiterr("unknown input image resolution"); |
| 360 |
|
|
| 361 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) |
| 362 |
< |
cvts.stonits = 1.; |
| 362 |
> |
cvts.stonits = -1.; |
| 363 |
|
|
| 364 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp)) |
| 365 |
|
cvts.capdate[0] = '\0'; |
| 374 |
|
cvts.owner[sizeof(cvts.owner)-1] = '\0'; |
| 375 |
|
} |
| 376 |
|
/* add to Radiance header */ |
| 377 |
< |
if (cvts.pixrat < .99 || cvts.pixrat > 1.01) |
| 377 |
> |
if (cvts.pixrat < .999 || cvts.pixrat > 1.001) |
| 378 |
|
fputaspect(cvts.pixrat, cvts.rfp); |
| 379 |
|
if (CHK(C_XYZE)) { |
| 380 |
< |
fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); |
| 380 |
> |
if (cvts.stonits > .0) |
| 381 |
> |
fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp); |
| 382 |
|
fputformat(CIEFMT, cvts.rfp); |
| 383 |
|
} else { |
| 384 |
|
if (CHK(C_PRIM)) |
| 385 |
|
fputprims(cvts.prims, cvts.rfp); |
| 386 |
< |
fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, |
| 387 |
< |
cvts.rfp); |
| 386 |
> |
if (cvts.stonits > .0) |
| 387 |
> |
fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits, |
| 388 |
> |
cvts.rfp); |
| 389 |
|
fputformat(COLRFMT, cvts.rfp); |
| 390 |
|
} |
| 391 |
|
if (cvts.capdate[0]) |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 400 |
< |
tiff2ra(ac, av) /* convert TIFF image to Radiance picture */ |
| 401 |
< |
int ac; |
| 402 |
< |
char *av[]; |
| 400 |
> |
static void |
| 401 |
> |
tiff2ra( /* convert TIFF image to Radiance picture */ |
| 402 |
> |
int ac, |
| 403 |
> |
char *av[] |
| 404 |
> |
) |
| 405 |
|
{ |
| 406 |
|
int32 y; |
| 407 |
|
/* open TIFF input */ |
| 412 |
|
cvts.rfp = stdout; |
| 413 |
|
else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL) |
| 414 |
|
quiterr("cannot open Radiance output picture"); |
| 415 |
+ |
SET_FILE_BINARY(cvts.rfp); |
| 416 |
|
/* start output header */ |
| 417 |
|
newheader("RADIANCE", cvts.rfp); |
| 418 |
|
printargs(ac, av, cvts.rfp); |
| 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]; |
| 441 |
> |
struct CONVST *cvp = (struct CONVST *)p; |
| 442 |
> |
char fmt[MAXFMTLEN]; |
| 443 |
|
|
| 444 |
< |
if (!tmstrlen) |
| 444 |
> |
if (!tmstrlen) { |
| 445 |
|
tmstrlen = strlen(TMSTR); |
| 422 |
– |
if (!ownstrlen) |
| 446 |
|
ownstrlen = strlen(OWNSTR); |
| 447 |
+ |
} |
| 448 |
|
if (formatval(fmt, s)) { |
| 449 |
< |
if (!strcmp(fmt, COLRFMT)) |
| 450 |
< |
CLR(C_XYZE); |
| 427 |
< |
else if (!strcmp(fmt, CIEFMT)) |
| 449 |
> |
CLR(C_XYZE|C_SPEC); |
| 450 |
> |
if (!strcmp(fmt, CIEFMT)) |
| 451 |
|
SET(C_XYZE); |
| 452 |
< |
else |
| 453 |
< |
quiterr("unrecognized input picture format"); |
| 452 |
> |
else if (!strcmp(fmt, SPECFMT)) |
| 453 |
> |
SET(C_SPEC); |
| 454 |
> |
else if (strcmp(fmt, COLRFMT)) |
| 455 |
> |
return(-1); |
| 456 |
|
return(1); |
| 457 |
|
} |
| 458 |
|
if (isexpos(s)) { |
| 459 |
< |
cvts.stonits /= exposval(s); |
| 459 |
> |
cvp->stonits /= exposval(s); |
| 460 |
|
return(1); |
| 461 |
|
} |
| 462 |
|
if (isaspect(s)) { |
| 463 |
< |
cvts.pixrat *= aspectval(s); |
| 463 |
> |
cvp->pixrat *= aspectval(s); |
| 464 |
|
return(1); |
| 465 |
|
} |
| 466 |
|
if (isprims(s)) { |
| 467 |
< |
primsval(cvts.prims, s); |
| 467 |
> |
primsval(cvp->prims, s); |
| 468 |
|
SET(C_PRIM); |
| 469 |
|
return(1); |
| 470 |
|
} |
| 471 |
|
if (isdate(s)) { |
| 472 |
|
if (s[tmstrlen] == ' ') |
| 473 |
< |
strncpy(cvts.capdate, s+tmstrlen+1, 19); |
| 473 |
> |
strncpy(cvp->capdate, s+tmstrlen+1, 19); |
| 474 |
|
else |
| 475 |
< |
strncpy(cvts.capdate, s+tmstrlen, 19); |
| 476 |
< |
cvts.capdate[19] = '\0'; |
| 475 |
> |
strncpy(cvp->capdate, s+tmstrlen, 19); |
| 476 |
> |
cvp->capdate[19] = '\0'; |
| 477 |
|
return(1); |
| 478 |
|
} |
| 479 |
|
if (!strncmp(s, OWNSTR, ownstrlen)) { |
| 480 |
< |
register char *cp = s + ownstrlen; |
| 480 |
> |
char *cp = s + ownstrlen; |
| 481 |
|
|
| 482 |
|
while (isspace(*cp)) |
| 483 |
|
++cp; |
| 484 |
< |
strncpy(cvts.owner, cp, sizeof(cvts.owner)); |
| 485 |
< |
cvts.owner[sizeof(cvts.owner)-1] = '\0'; |
| 486 |
< |
for (cp = cvts.owner; *cp; cp++) |
| 484 |
> |
strncpy(cvp->owner, cp, sizeof(cvp->owner)); |
| 485 |
> |
cvp->owner[sizeof(cvp->owner)-1] = '\0'; |
| 486 |
> |
for (cp = cvp->owner; *cp; cp++) |
| 487 |
|
; |
| 488 |
< |
while (cp > cvts.owner && isspace(cp[-1])) |
| 488 |
> |
while (cp > cvp->owner && isspace(cp[-1])) |
| 489 |
|
*--cp = '\0'; |
| 490 |
|
return(1); |
| 491 |
|
} |
| 492 |
+ |
if (isncomp(s)) { |
| 493 |
+ |
cvp->ncc = ncompval(s); |
| 494 |
+ |
return((3 <= cvp->ncc) & (cvp->ncc < MAXCSAMP) ? 1 : -1); |
| 495 |
+ |
} |
| 496 |
+ |
if (iswlsplit(s)) |
| 497 |
+ |
return(wlsplitval(cvp->wpt, s) ? 1 : -1); |
| 498 |
|
return(0); |
| 499 |
|
} |
| 500 |
|
|
| 501 |
|
|
| 502 |
< |
initfromrad() /* initialize input from a Radiance picture */ |
| 502 |
> |
static void |
| 503 |
> |
initfromrad(void) /* initialize input from a Radiance picture */ |
| 504 |
|
{ |
| 505 |
|
int i1, i2, po; |
| 506 |
|
/* read Radiance header */ |
| 507 |
< |
CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM); |
| 508 |
< |
cvts.capdate[0] = '\0'; |
| 509 |
< |
cvts.owner[0] = '\0'; |
| 478 |
< |
cvts.stonits = 1.; |
| 479 |
< |
cvts.pixrat = 1.; |
| 480 |
< |
cvts.pconf = PLANARCONFIG_CONTIG; |
| 481 |
< |
getheader(cvts.rfp, headline, NULL); |
| 482 |
< |
if ((po = fgetresolu(&i1, &i2, cvts.rfp)) < 0) |
| 507 |
> |
memcpy(cvts.wpt, WLPART, sizeof(cvts.wpt)); |
| 508 |
> |
if (getheader(cvts.rfp, headline, &cvts) < 0 || |
| 509 |
> |
(po = fgetresolu(&i1, &i2, cvts.rfp)) < 0) |
| 510 |
|
quiterr("bad Radiance picture"); |
| 511 |
|
cvts.xmax = i1; cvts.ymax = i2; |
| 512 |
|
for (i1 = 0; i1 < 8; i1++) /* interpret orientation */ |
| 528 |
|
case PHOTOMETRIC_LOGLUV: |
| 529 |
|
SET(C_RFLT|C_TFLT); |
| 530 |
|
CLR(C_GRY|C_TWRD); |
| 531 |
< |
if (!CHK(C_XYZE)) { |
| 531 |
> |
if (!CHK(C_XYZE|C_SPEC)) { |
| 532 |
|
comprgb2xyzWBmat(cvts.cmat, |
| 533 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
| 534 |
|
SET(C_CXFM); |
| 553 |
|
SET(C_GAMMA|C_GAMUT); |
| 554 |
|
CLR(C_GRY); |
| 555 |
|
setcolrgam(cvts.gamcor); |
| 556 |
< |
if (CHK(C_XYZE)) { |
| 556 |
> |
if (CHK(C_TWRD|C_TFLT) ? CHK(C_XYZE|C_SPEC) : CHK(C_XYZE)) { |
| 557 |
|
compxyz2rgbWBmat(cvts.cmat, |
| 558 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
| 559 |
|
SET(C_CXFM); |
| 568 |
|
cvts.tf = Color2RRGGBB; |
| 569 |
|
SET(C_RFLT); |
| 570 |
|
} else if (CHK(C_TFLT)) { |
| 571 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
| 572 |
+ |
SAMPLEFORMAT_IEEEFP); |
| 573 |
|
cvts.tf = Color2RfGfBf; |
| 574 |
|
SET(C_RFLT); |
| 575 |
+ |
CLR(C_GAMUT); |
| 576 |
|
} else |
| 577 |
|
cvts.tf = Colr2RGB; |
| 578 |
|
break; |
| 583 |
|
cvts.tf = Color2GGry; |
| 584 |
|
SET(C_RFLT); |
| 585 |
|
} else if (CHK(C_TFLT)) { |
| 586 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
| 587 |
+ |
SAMPLEFORMAT_IEEEFP); |
| 588 |
|
cvts.tf = Color2Gryf; |
| 589 |
|
SET(C_RFLT); |
| 590 |
|
} else |
| 623 |
|
} |
| 624 |
|
|
| 625 |
|
|
| 626 |
< |
ra2tiff(ac, av) /* convert Radiance picture to TIFF image */ |
| 627 |
< |
int ac; |
| 628 |
< |
char *av[]; |
| 626 |
> |
static void |
| 627 |
> |
ra2tiff( /* convert Radiance picture to TIFF image */ |
| 628 |
> |
int ac, |
| 629 |
> |
char *av[] |
| 630 |
> |
) |
| 631 |
|
{ |
| 632 |
|
uint32 y; |
| 633 |
|
/* open Radiance file */ |
| 635 |
|
cvts.rfp = stdin; |
| 636 |
|
else if ((cvts.rfp = fopen(av[ac], "r")) == NULL) |
| 637 |
|
quiterr("cannot open Radiance input picture"); |
| 638 |
+ |
SET_FILE_BINARY(cvts.rfp); |
| 639 |
|
/* open TIFF file */ |
| 640 |
|
if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL) |
| 641 |
|
quiterr("cannot open TIFF output"); |
| 650 |
|
} |
| 651 |
|
|
| 652 |
|
|
| 653 |
< |
void |
| 654 |
< |
Luv2Color(y) /* read/convert/write Luv->COLOR scanline */ |
| 620 |
< |
uint32 y; |
| 653 |
> |
static void |
| 654 |
> |
ReadRadScan(struct CONVST *cvp) |
| 655 |
|
{ |
| 656 |
< |
register int x; |
| 656 |
> |
static struct CONVST *lastcvp = NULL; |
| 657 |
> |
static COLOR scomp[MAXCSAMP]; |
| 658 |
|
|
| 659 |
+ |
if (cvp->ncc > 3) { /* convert spectral pixels */ |
| 660 |
+ |
SCOLR sclr; |
| 661 |
+ |
SCOLOR scol; |
| 662 |
+ |
COLOR xyz; |
| 663 |
+ |
int x, n; |
| 664 |
+ |
if (lastcvp != cvp) { |
| 665 |
+ |
for (n = cvp->ncc; n--; ) |
| 666 |
+ |
spec_cie(scomp[n], |
| 667 |
+ |
cvp->wpt[0] + (cvp->wpt[3] - cvp->wpt[0])*(n+1)/cvp->ncc, |
| 668 |
+ |
cvp->wpt[0] + (cvp->wpt[3] - cvp->wpt[0])*n/cvp->ncc); |
| 669 |
+ |
lastcvp = cvp; |
| 670 |
+ |
} |
| 671 |
+ |
for (x = 0; x < cvp->xmax; x++) { |
| 672 |
+ |
if (getbinary(sclr, cvp->ncc+1, 1, cvp->rfp) != 1) |
| 673 |
+ |
goto readerr; |
| 674 |
+ |
scolr2scolor(scol, sclr, cvp->ncc); |
| 675 |
+ |
setcolor(cvp->r.colors[x], 0, 0, 0); |
| 676 |
+ |
for (n = cvp->ncc; n--; ) { |
| 677 |
+ |
copycolor(xyz, scomp[n]); |
| 678 |
+ |
scalecolor(xyz, scol[n]); |
| 679 |
+ |
addcolor(cvp->r.colors[x], xyz); |
| 680 |
+ |
} |
| 681 |
+ |
} |
| 682 |
+ |
return; |
| 683 |
+ |
} |
| 684 |
+ |
if (freadscan(cvp->r.colors, cvp->xmax, cvp->rfp) >= 0) |
| 685 |
+ |
return; |
| 686 |
+ |
readerr: |
| 687 |
+ |
quiterr("error reading Radiance picture"); |
| 688 |
+ |
} |
| 689 |
+ |
|
| 690 |
+ |
|
| 691 |
+ |
static void |
| 692 |
+ |
Luv2Color( /* read/convert/write Luv->COLOR scanline */ |
| 693 |
+ |
uint32 y |
| 694 |
+ |
) |
| 695 |
+ |
{ |
| 696 |
+ |
int x; |
| 697 |
+ |
|
| 698 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
| 699 |
|
quiterr("internal error 1 in Luv2Color"); |
| 700 |
|
|
| 701 |
+ |
if (cvts.pconf != PLANARCONFIG_CONTIG) |
| 702 |
+ |
quiterr("cannot handle separate 32-bit color planes"); |
| 703 |
+ |
|
| 704 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
| 705 |
|
quiterr("error reading TIFF input"); |
| 706 |
|
/* also works for float RGB */ |
| 727 |
|
} |
| 728 |
|
|
| 729 |
|
|
| 730 |
< |
void |
| 731 |
< |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
| 732 |
< |
uint32 y; |
| 730 |
> |
static void |
| 731 |
> |
RRGGBB2Color( /* read/convert/write RGB16->COLOR scanline */ |
| 732 |
> |
uint32 y |
| 733 |
> |
) |
| 734 |
|
{ |
| 735 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
| 736 |
< |
register double d; |
| 737 |
< |
register int x; |
| 735 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
| 736 |
> |
double d; |
| 737 |
> |
int x; |
| 738 |
|
|
| 739 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) |
| 740 |
|
quiterr("internal error 1 in RRGGBB2Color"); |
| 741 |
|
|
| 742 |
+ |
if (cvts.pconf != PLANARCONFIG_CONTIG) |
| 743 |
+ |
quiterr("cannot handle separate 16-bit color planes"); |
| 744 |
+ |
|
| 745 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
| 746 |
|
quiterr("error reading TIFF input"); |
| 747 |
|
|
| 758 |
|
if (CHK(C_CXFM)) |
| 759 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
| 760 |
|
cvts.r.colors[x]); |
| 680 |
– |
if (CHK(C_GAMUT)) |
| 681 |
– |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
| 682 |
– |
CGAMUT_LOWER, cblack, cwhite); |
| 761 |
|
} |
| 762 |
|
if (cvts.bradj) { |
| 763 |
|
d = pow(2.,(double)cvts.bradj); |
| 770 |
|
} |
| 771 |
|
|
| 772 |
|
|
| 773 |
< |
void |
| 774 |
< |
L2Color(y) /* read/convert/write Lfloat->COLOR scanline */ |
| 775 |
< |
uint32 y; |
| 773 |
> |
static void |
| 774 |
> |
L2Color( /* read/convert/write Lfloat->COLOR scanline */ |
| 775 |
> |
uint32 y |
| 776 |
> |
) |
| 777 |
|
{ |
| 778 |
|
float m = pow(2., (double)cvts.bradj); |
| 779 |
< |
register int x; |
| 779 |
> |
int x; |
| 780 |
|
|
| 781 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
| 782 |
|
quiterr("internal error 1 in L2Color"); |
| 785 |
|
quiterr("error reading TIFF input"); |
| 786 |
|
/* also works for float greyscale */ |
| 787 |
|
for (x = cvts.xmax; x--; ) { |
| 788 |
< |
register float f = cvts.t.fp[x]; |
| 788 |
> |
float f = cvts.t.fp[x]; |
| 789 |
|
if (cvts.bradj) f *= m; |
| 790 |
|
setcolor(cvts.r.colors[x], f, f, f); |
| 791 |
|
} |
| 794 |
|
} |
| 795 |
|
|
| 796 |
|
|
| 797 |
< |
void |
| 798 |
< |
RGB2Colr(y) /* read/convert/write RGB->COLR scanline */ |
| 799 |
< |
uint32 y; |
| 797 |
> |
static void |
| 798 |
> |
RGB2Colr( /* read/convert/write RGB->COLR scanline */ |
| 799 |
> |
uint32 y |
| 800 |
> |
) |
| 801 |
|
{ |
| 802 |
|
COLOR ctmp; |
| 803 |
< |
register int x; |
| 803 |
> |
int x; |
| 804 |
|
|
| 805 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY)) |
| 806 |
|
quiterr("internal error 1 in RGB2Colr"); |
| 851 |
|
} |
| 852 |
|
|
| 853 |
|
|
| 854 |
< |
void |
| 855 |
< |
Gry2Colr(y) /* read/convert/write G8->COLR scanline */ |
| 856 |
< |
uint32 y; |
| 854 |
> |
static void |
| 855 |
> |
Gry2Colr( /* read/convert/write G8->COLR scanline */ |
| 856 |
> |
uint32 y |
| 857 |
> |
) |
| 858 |
|
{ |
| 859 |
< |
register int x; |
| 859 |
> |
int x; |
| 860 |
|
|
| 861 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
| 862 |
|
quiterr("internal error 1 in Gry2Colr"); |
| 878 |
|
} |
| 879 |
|
|
| 880 |
|
|
| 881 |
< |
void |
| 882 |
< |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
| 883 |
< |
uint32 y; |
| 881 |
> |
static void |
| 882 |
> |
GGry2Color( /* read/convert/write G16->COLOR scanline */ |
| 883 |
> |
uint32 y |
| 884 |
> |
) |
| 885 |
|
{ |
| 886 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
| 886 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
| 887 |
|
double m; |
| 888 |
< |
register double d; |
| 889 |
< |
register int x; |
| 888 |
> |
double d; |
| 889 |
> |
int x; |
| 890 |
|
|
| 891 |
|
if (CHK(C_TFLT|C_TWRD|C_GRY|C_RFLT) != (C_GRY|C_RFLT|C_TWRD)) |
| 892 |
|
quiterr("internal error 1 in GGry2Color"); |
| 909 |
|
} |
| 910 |
|
|
| 911 |
|
|
| 912 |
< |
void |
| 913 |
< |
Color2GGry(y) /* read/convert/write COLOR->G16 scanline */ |
| 914 |
< |
uint32 y; |
| 912 |
> |
static void |
| 913 |
> |
Color2GGry( /* read/convert/write COLOR->G16 scanline */ |
| 914 |
> |
uint32 y |
| 915 |
> |
) |
| 916 |
|
{ |
| 917 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
| 917 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
| 918 |
|
float m = pow(2.,(double)cvts.bradj); |
| 919 |
< |
register int x; |
| 919 |
> |
int x; |
| 920 |
|
|
| 921 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD|C_GRY)) |
| 922 |
|
quiterr("internal error 1 in Color2GGry"); |
| 923 |
|
|
| 924 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
| 842 |
< |
quiterr("error reading Radiance picture"); |
| 924 |
> |
ReadRadScan(&cvts); |
| 925 |
|
|
| 926 |
|
for (x = cvts.xmax; x--; ) { |
| 927 |
< |
register float f = m*( CHK(C_XYZE) ? |
| 927 |
> |
float f = m*( CHK(C_XYZE) ? |
| 928 |
|
colval(cvts.r.colors[x],CIEY) |
| 929 |
|
: bright(cvts.r.colors[x]) ); |
| 930 |
|
if (f <= 0) |
| 943 |
|
} |
| 944 |
|
|
| 945 |
|
|
| 946 |
< |
void |
| 947 |
< |
Color2L(y) /* read/convert/write COLOR->Lfloat scanline */ |
| 948 |
< |
uint32 y; |
| 946 |
> |
static void |
| 947 |
> |
Color2L( /* read/convert/write COLOR->Lfloat scanline */ |
| 948 |
> |
uint32 y |
| 949 |
> |
) |
| 950 |
|
{ |
| 951 |
|
float m = pow(2.,(double)cvts.bradj); |
| 952 |
< |
register int x; |
| 952 |
> |
int x; |
| 953 |
|
|
| 954 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
| 955 |
|
quiterr("internal error 1 in Color2L"); |
| 956 |
|
|
| 957 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
| 875 |
< |
quiterr("error reading Radiance picture"); |
| 957 |
> |
ReadRadScan(&cvts); |
| 958 |
|
|
| 959 |
|
for (x = cvts.xmax; x--; ) |
| 960 |
|
cvts.t.fp[x] = m*( CHK(C_XYZE) ? colval(cvts.r.colors[x],CIEY) |
| 965 |
|
} |
| 966 |
|
|
| 967 |
|
|
| 968 |
< |
void |
| 969 |
< |
Color2Luv(y) /* read/convert/write COLOR->Luv scanline */ |
| 970 |
< |
uint32 y; |
| 968 |
> |
static void |
| 969 |
> |
Color2Luv( /* read/convert/write COLOR->Luv scanline */ |
| 970 |
> |
uint32 y |
| 971 |
> |
) |
| 972 |
|
{ |
| 973 |
< |
register int x; |
| 973 |
> |
int x; |
| 974 |
|
|
| 975 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
| 976 |
|
quiterr("internal error 1 in Color2Luv"); |
| 977 |
|
|
| 978 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
| 896 |
< |
quiterr("error reading Radiance picture"); |
| 978 |
> |
ReadRadScan(&cvts); |
| 979 |
|
|
| 980 |
|
if (CHK(C_CXFM)) |
| 981 |
|
for (x = cvts.xmax; x--; ) |
| 998 |
|
} |
| 999 |
|
|
| 1000 |
|
|
| 1001 |
< |
void |
| 1002 |
< |
Color2RRGGBB(y) /* read/convert/write COLOR->RGB16 scanline */ |
| 1003 |
< |
uint32 y; |
| 1001 |
> |
static void |
| 1002 |
> |
Color2RRGGBB( /* read/convert/write COLOR->RGB16 scanline */ |
| 1003 |
> |
uint32 y |
| 1004 |
> |
) |
| 1005 |
|
{ |
| 1006 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
| 1006 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
| 1007 |
|
float m = pow(2.,(double)cvts.bradj); |
| 1008 |
< |
register int x, i; |
| 1008 |
> |
int x, i; |
| 1009 |
|
|
| 1010 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD)) |
| 1011 |
|
quiterr("internal error 1 in Color2RRGGBB"); |
| 1012 |
|
|
| 1013 |
< |
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
| 931 |
< |
quiterr("error reading Radiance picture"); |
| 1013 |
> |
ReadRadScan(&cvts); |
| 1014 |
|
|
| 1015 |
< |
for (x = cvts.xmax; x--; ) |
| 1015 |
> |
for (x = cvts.xmax; x--; ) { |
| 1016 |
> |
if (CHK(C_CXFM)) { |
| 1017 |
> |
colortrans(cvts.r.colors[x], cvts.cmat, |
| 1018 |
> |
cvts.r.colors[x]); |
| 1019 |
> |
if (CHK(C_GAMUT)) |
| 1020 |
> |
clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]), |
| 1021 |
> |
CGAMUT_LOWER, cblack, cwhite); |
| 1022 |
> |
} |
| 1023 |
|
for (i = 3; i--; ) { |
| 1024 |
< |
register float f = m*colval(cvts.r.colors[x],i); |
| 1024 |
> |
float f = m*colval(cvts.r.colors[x],i); |
| 1025 |
|
if (f <= 0) |
| 1026 |
|
cvts.t.wp[3*x + i] = 0; |
| 1027 |
|
else if (f >= 1) |
| 1032 |
|
else |
| 1033 |
|
cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f); |
| 1034 |
|
} |
| 1035 |
+ |
} |
| 1036 |
|
|
| 1037 |
|
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
| 1038 |
|
quiterr("error writing TIFF output"); |
| 1039 |
|
} |
| 1040 |
|
|
| 1041 |
|
|
| 1042 |
< |
void |
| 1043 |
< |
Colr2Gry(y) /* read/convert/write COLR->RGB scanline */ |
| 1044 |
< |
uint32 y; |
| 1042 |
> |
static void |
| 1043 |
> |
Colr2Gry( /* read/convert/write COLR->RGB scanline */ |
| 1044 |
> |
uint32 y |
| 1045 |
> |
) |
| 1046 |
|
{ |
| 1047 |
< |
register int x; |
| 1047 |
> |
int x; |
| 1048 |
|
|
| 1049 |
|
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
| 1050 |
|
quiterr("internal error 1 in Colr2Gry"); |
| 1051 |
|
|
| 1052 |
< |
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
| 1052 |
> |
if (fread2colrs(cvts.r.colrs, cvts.xmax, cvts.rfp, |
| 1053 |
> |
cvts.ncc, cvts.wpt) < 0) |
| 1054 |
|
quiterr("error reading Radiance picture"); |
| 1055 |
|
|
| 1056 |
|
if (cvts.bradj) |
| 1067 |
|
} |
| 1068 |
|
|
| 1069 |
|
|
| 1070 |
< |
void |
| 1071 |
< |
Colr2RGB(y) /* read/convert/write COLR->RGB scanline */ |
| 1072 |
< |
uint32 y; |
| 1070 |
> |
static void |
| 1071 |
> |
Colr2RGB( /* read/convert/write COLR->RGB scanline */ |
| 1072 |
> |
uint32 y |
| 1073 |
> |
) |
| 1074 |
|
{ |
| 1075 |
|
COLOR ctmp; |
| 1076 |
< |
register int x; |
| 1076 |
> |
int x; |
| 1077 |
|
|
| 1078 |
|
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY)) |
| 1079 |
|
quiterr("internal error 1 in Colr2RGB"); |
| 1080 |
|
|
| 1081 |
< |
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
| 1081 |
> |
if (fread2colrs(cvts.r.colrs, cvts.xmax, cvts.rfp, |
| 1082 |
> |
cvts.ncc, cvts.wpt) < 0) |
| 1083 |
|
quiterr("error reading Radiance picture"); |
| 1084 |
|
|
| 1085 |
|
if (cvts.bradj) |