| 1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Program to convert between RADIANCE RGBE and XYZE formats |
| 6 |
+ |
* Added white-balance adjustment 10/01 (GW). |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
#include <stdio.h> |
| 10 |
+ |
#include <string.h> |
| 11 |
|
#include <math.h> |
| 12 |
+ |
#include <time.h> |
| 13 |
|
#include "color.h" |
| 14 |
|
#include "resolu.h" |
| 15 |
|
|
| 17 |
|
#include <fcntl.h> |
| 18 |
|
#endif |
| 19 |
|
|
| 20 |
– |
extern char *malloc(), *strcpy(); |
| 21 |
– |
|
| 20 |
|
int rgbinp = -1; /* input is RGBE? */ |
| 21 |
|
|
| 22 |
|
int rgbout = 0; /* output should be RGBE? */ |
| 32 |
|
char *progname; |
| 33 |
|
|
| 34 |
|
|
| 35 |
+ |
int |
| 36 |
|
headline(s) /* process header line */ |
| 37 |
|
char *s; |
| 38 |
|
{ |
| 45 |
|
rgbinp = 0; |
| 46 |
|
else |
| 47 |
|
rgbinp = -2; |
| 48 |
< |
return; /* don't echo */ |
| 48 |
> |
return(0); /* don't echo */ |
| 49 |
|
} |
| 50 |
|
if (isprims(s)) { /* get input primaries */ |
| 51 |
|
primsval(inprims, s); |
| 52 |
< |
return; /* don't echo */ |
| 52 |
> |
return(0); /* don't echo */ |
| 53 |
|
} |
| 54 |
|
/* should I grok colcorr also? */ |
| 55 |
< |
fputs(s, stdout); |
| 55 |
> |
return(fputs(s, stdout)); |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 124 |
|
if (rgbinp == -1) |
| 125 |
|
rgbinp = !rgbout; |
| 126 |
|
printargs(argc, argv, stdout); /* add to header */ |
| 128 |
– |
if (expcomp < 0.99 || expcomp > 1.01) |
| 129 |
– |
fputexpos(expcomp, stdout); |
| 127 |
|
convert(); /* convert picture */ |
| 128 |
|
exit(0); |
| 129 |
|
userr: |
| 151 |
|
COLORMAT xfm; |
| 152 |
|
register COLOR *scanin; |
| 153 |
|
register COLR *scanout; |
| 154 |
+ |
double ourexp = expcomp; |
| 155 |
|
int y; |
| 156 |
|
register int x; |
| 157 |
|
/* compute transform */ |
| 158 |
|
if (rgbout) { |
| 161 |
– |
double mult; |
| 159 |
|
if (rgbinp) { /* RGBE -> RGBE */ |
| 160 |
< |
comprgb2rgbmat(xfm, inprims, outprims); |
| 164 |
< |
mult = expcomp; |
| 160 |
> |
comprgb2rgbWBmat(xfm, inprims, outprims); |
| 161 |
|
} else { /* XYZE -> RGBE */ |
| 162 |
< |
compxyz2rgbmat(xfm, outprims); |
| 163 |
< |
mult = expcomp/WHTEFFICACY; |
| 162 |
> |
compxyz2rgbWBmat(xfm, outprims); |
| 163 |
> |
ourexp *= WHTEFFICACY; |
| 164 |
|
} |
| 169 |
– |
for (y = 0; y < 3; y++) |
| 170 |
– |
for (x = 0; x < 3; x++) |
| 171 |
– |
xfm[y][x] *= mult; |
| 165 |
|
} else { |
| 166 |
|
if (rgbinp) { /* RGBE -> XYZE */ |
| 167 |
< |
comprgb2xyzmat(xfm, inprims); |
| 168 |
< |
for (y = 0; y < 3; y++) |
| 176 |
< |
for (x = 0; x < 3; x++) |
| 177 |
< |
xfm[y][x] *= WHTEFFICACY*expcomp; |
| 167 |
> |
comprgb2xyzWBmat(xfm, inprims); |
| 168 |
> |
ourexp /= WHTEFFICACY; |
| 169 |
|
} else { /* XYZE -> XYZE */ |
| 170 |
|
for (y = 0; y < 3; y++) |
| 171 |
|
for (x = 0; x < 3; x++) |
| 172 |
< |
xfm[y][x] = x==y ? expcomp : 0.; |
| 172 |
> |
xfm[y][x] = x==y ? 1. : 0.; |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
+ |
for (y = 0; y < 3; y++) |
| 176 |
+ |
for (x = 0; x < 3; x++) |
| 177 |
+ |
xfm[y][x] *= expcomp; |
| 178 |
|
/* get input resolution */ |
| 179 |
|
if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0) |
| 180 |
|
quiterr("bad picture format"); |
| 181 |
|
/* complete output header */ |
| 182 |
+ |
if (ourexp < 0.99 || ourexp > 1.01) |
| 183 |
+ |
fputexpos(ourexp, stdout); |
| 184 |
|
if (rgbout) { |
| 185 |
|
fputprims(outprims, stdout); |
| 186 |
|
fputformat(COLRFMT, stdout); |
| 197 |
|
for (y = 0; y < ymax; y++) { |
| 198 |
|
if (freadscan(scanin, xmax, stdin) < 0) |
| 199 |
|
quiterr("error reading input picture"); |
| 200 |
< |
for (x = 0; x < xmax; x++) |
| 200 |
> |
for (x = 0; x < xmax; x++) { |
| 201 |
|
colortrans(scanin[x], xfm, scanin[x]); |
| 202 |
+ |
if (rgbout) |
| 203 |
+ |
clipgamut(scanin[x], bright(scanin[x]), |
| 204 |
+ |
CGAMUT_LOWER, cblack, cwhite); |
| 205 |
+ |
} |
| 206 |
|
if (scanout != NULL) { |
| 207 |
|
for (x = 0; x < xmax; x++) |
| 208 |
|
setcolr(scanout[x], colval(scanin[x],RED), |
| 215 |
|
quiterr("error writing output picture"); |
| 216 |
|
} |
| 217 |
|
/* free scanline */ |
| 218 |
< |
free((char *)scanin); |
| 218 |
> |
free((void *)scanin); |
| 219 |
|
if (scanout != NULL) |
| 220 |
< |
free((char *)scanout); |
| 220 |
> |
free((void *)scanout); |
| 221 |
|
} |