6 |
|
* Added white-balance adjustment 10/01 (GW). |
7 |
|
*/ |
8 |
|
|
9 |
– |
#include <stdio.h> |
10 |
– |
#include <string.h> |
9 |
|
#include <math.h> |
12 |
– |
#include <time.h> |
10 |
|
|
11 |
|
#include "platform.h" |
12 |
|
#include "color.h" |
13 |
|
#include "resolu.h" |
14 |
+ |
#include "rtio.h" |
15 |
|
|
16 |
|
int rgbinp = -1; /* input is RGBE? */ |
17 |
|
int rgbout = 0; /* output should be RGBE? */ |
19 |
|
RGBPRIMS outprims = STDPRIMS; /* output primaries */ |
20 |
|
double expcomp = 1.0; /* exposure compensation */ |
21 |
|
int doflat = -1; /* produce flat file? */ |
22 |
+ |
double origexp = -1.0; /* original exposure */ |
23 |
|
char *progname; |
24 |
|
|
25 |
|
static gethfunc headline; |
34 |
|
void *p |
35 |
|
) |
36 |
|
{ |
37 |
< |
char fmt[32]; |
37 |
> |
char fmt[MAXFMTLEN]; |
38 |
|
|
39 |
|
if (formatval(fmt, s)) { /* check if format string */ |
40 |
|
if (!strcmp(fmt,COLRFMT)) |
45 |
|
rgbinp = -2; |
46 |
|
return(0); /* don't echo */ |
47 |
|
} |
48 |
+ |
if (origexp > 0.0 && isexpos(s)) { |
49 |
+ |
origexp *= exposval(s); |
50 |
+ |
return(0); /* don't echo */ |
51 |
+ |
} |
52 |
|
if (isprims(s)) { /* get input primaries */ |
53 |
|
primsval(inprims, s); |
54 |
|
return(0); /* don't echo */ |
91 |
|
outprims[WHT][CIEX] = atof(argv[++i]); |
92 |
|
outprims[WHT][CIEY] = atof(argv[++i]); |
93 |
|
break; |
94 |
+ |
case 'o': /* original exposure */ |
95 |
+ |
origexp = 1.0; |
96 |
+ |
break; |
97 |
|
case 'e': /* exposure compensation */ |
98 |
|
expcomp = atof(argv[++i]); |
99 |
|
if (argv[i][0] == '+' || argv[i][0] == '-') |
128 |
|
convert(); /* convert picture */ |
129 |
|
exit(0); |
130 |
|
userr: |
131 |
< |
fprintf(stderr, "Usage: %s [-r][-e exp][-c|-u]", progname); |
131 |
> |
fprintf(stderr, "Usage: %s [-r][-o][-e exp][-c|-u]", progname); |
132 |
|
fprintf(stderr, "[-p rx ry gx gy bx by wx wy] [input [output]]\n"); |
133 |
|
exit(1); |
134 |
|
} |
155 |
|
COLORMAT xfm; |
156 |
|
register COLOR *scanin; |
157 |
|
register COLR *scanout; |
158 |
< |
double ourexp = expcomp; |
158 |
> |
double exp2do = expcomp; |
159 |
> |
double exp2report = expcomp; |
160 |
|
int y; |
161 |
|
register int x; |
162 |
+ |
/* recover original? */ |
163 |
+ |
if (origexp > 0.0) |
164 |
+ |
exp2do /= origexp; |
165 |
|
/* compute transform */ |
166 |
|
if (rgbout) { |
167 |
|
if (rgbinp) { /* RGBE -> RGBE */ |
168 |
|
comprgb2rgbWBmat(xfm, inprims, outprims); |
169 |
|
} else { /* XYZE -> RGBE */ |
170 |
|
compxyz2rgbWBmat(xfm, outprims); |
171 |
< |
ourexp *= WHTEFFICACY; |
171 |
> |
if (origexp > 0.0) |
172 |
> |
exp2do /= WHTEFFICACY; |
173 |
> |
else |
174 |
> |
exp2report *= WHTEFFICACY; |
175 |
|
} |
176 |
|
} else { |
177 |
|
if (rgbinp) { /* RGBE -> XYZE */ |
178 |
|
comprgb2xyzWBmat(xfm, inprims); |
179 |
< |
ourexp /= WHTEFFICACY; |
179 |
> |
if (origexp > 0.0) |
180 |
> |
exp2do *= WHTEFFICACY; |
181 |
> |
else |
182 |
> |
exp2report /= WHTEFFICACY; |
183 |
|
} else { /* XYZE -> XYZE */ |
184 |
|
for (y = 0; y < 3; y++) |
185 |
|
for (x = 0; x < 3; x++) |
188 |
|
} |
189 |
|
for (y = 0; y < 3; y++) |
190 |
|
for (x = 0; x < 3; x++) |
191 |
< |
xfm[y][x] *= expcomp; |
191 |
> |
xfm[y][x] *= exp2do; |
192 |
|
/* get input resolution */ |
193 |
|
if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0) |
194 |
|
quiterr("bad picture format"); |
195 |
|
/* complete output header */ |
196 |
< |
if (ourexp < 0.99 || ourexp > 1.01) |
197 |
< |
fputexpos(ourexp, stdout); |
196 |
> |
if ((exp2report < 0.99) | (exp2report > 1.01)) |
197 |
> |
fputexpos(exp2report, stdout); |
198 |
|
if (rgbout) { |
199 |
|
fputprims(outprims, stdout); |
200 |
|
fputformat(COLRFMT, stdout); |
222 |
|
setcolr(scanout[x], colval(scanin[x],RED), |
223 |
|
colval(scanin[x],GRN), |
224 |
|
colval(scanin[x],BLU)); |
225 |
< |
fwrite((char *)scanout, sizeof(COLR), xmax, stdout); |
225 |
> |
putbinary((char *)scanout, sizeof(COLR), xmax, stdout); |
226 |
|
} else |
227 |
|
fwritescan(scanin, xmax, stdout); |
228 |
|
if (ferror(stdout)) |