--- ray/src/px/ra_xyze.c 1995/10/25 15:13:38 2.2 +++ ray/src/px/ra_xyze.c 2003/02/22 02:07:28 2.6 @@ -1,15 +1,15 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_xyze.c,v 2.6 2003/02/22 02:07:28 greg Exp $"; #endif - /* * Program to convert between RADIANCE RGBE and XYZE formats + * Added white-balance adjustment 10/01 (GW). */ #include +#include #include +#include #include "color.h" #include "resolu.h" @@ -17,8 +17,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include #endif -extern char *malloc(), *strcpy(); - int rgbinp = -1; /* input is RGBE? */ int rgbout = 0; /* output should be RGBE? */ @@ -34,6 +32,7 @@ int doflat = -1; /* produce flat file? */ char *progname; +int headline(s) /* process header line */ char *s; { @@ -46,14 +45,14 @@ char *s; rgbinp = 0; else rgbinp = -2; - return; /* don't echo */ + return(0); /* don't echo */ } if (isprims(s)) { /* get input primaries */ primsval(inprims, s); - return; /* don't echo */ + return(0); /* don't echo */ } /* should I grok colcorr also? */ - fputs(s, stdout); + return(fputs(s, stdout)); } @@ -125,8 +124,6 @@ char *argv[]; if (rgbinp == -1) rgbinp = !rgbout; printargs(argc, argv, stdout); /* add to header */ - if (expcomp < 0.99 || expcomp > 1.01) - fputexpos(expcomp, stdout); convert(); /* convert picture */ exit(0); userr: @@ -154,37 +151,36 @@ convert() /* convert to XYZE or RGBE picture */ COLORMAT xfm; register COLOR *scanin; register COLR *scanout; + double ourexp = expcomp; int y; register int x; /* compute transform */ if (rgbout) { - double mult; if (rgbinp) { /* RGBE -> RGBE */ - comprgb2rgbmat(xfm, inprims, outprims); - mult = expcomp; + comprgb2rgbWBmat(xfm, inprims, outprims); } else { /* XYZE -> RGBE */ - compxyz2rgbmat(xfm, outprims); - mult = expcomp/WHTEFFICACY; + compxyz2rgbWBmat(xfm, outprims); + ourexp *= WHTEFFICACY; } - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - xfm[y][x] *= mult; } else { if (rgbinp) { /* RGBE -> XYZE */ - comprgb2xyzmat(xfm, inprims); - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - xfm[y][x] *= WHTEFFICACY*expcomp; + comprgb2xyzWBmat(xfm, inprims); + ourexp /= WHTEFFICACY; } else { /* XYZE -> XYZE */ for (y = 0; y < 3; y++) for (x = 0; x < 3; x++) - xfm[y][x] = x==y ? expcomp : 0.; + xfm[y][x] = x==y ? 1. : 0.; } } + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) + xfm[y][x] *= expcomp; /* get input resolution */ if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0) quiterr("bad picture format"); /* complete output header */ + if (ourexp < 0.99 || ourexp > 1.01) + fputexpos(ourexp, stdout); if (rgbout) { fputprims(outprims, stdout); fputformat(COLRFMT, stdout); @@ -201,8 +197,12 @@ convert() /* convert to XYZE or RGBE picture */ for (y = 0; y < ymax; y++) { if (freadscan(scanin, xmax, stdin) < 0) quiterr("error reading input picture"); - for (x = 0; x < xmax; x++) + for (x = 0; x < xmax; x++) { colortrans(scanin[x], xfm, scanin[x]); + if (rgbout) + clipgamut(scanin[x], bright(scanin[x]), + CGAMUT_LOWER, cblack, cwhite); + } if (scanout != NULL) { for (x = 0; x < xmax; x++) setcolr(scanout[x], colval(scanin[x],RED), @@ -215,7 +215,7 @@ convert() /* convert to XYZE or RGBE picture */ quiterr("error writing output picture"); } /* free scanline */ - free((char *)scanin); + free((void *)scanin); if (scanout != NULL) - free((char *)scanout); + free((void *)scanout); }