16 |
|
#include "resolu.h" |
17 |
|
|
18 |
|
int rgbinp = -1; /* input is RGBE? */ |
19 |
– |
|
19 |
|
int rgbout = 0; /* output should be RGBE? */ |
21 |
– |
|
20 |
|
RGBPRIMS inprims = STDPRIMS; /* input primaries */ |
23 |
– |
|
21 |
|
RGBPRIMS outprims = STDPRIMS; /* output primaries */ |
25 |
– |
|
22 |
|
double expcomp = 1.0; /* exposure compensation */ |
27 |
– |
|
23 |
|
int doflat = -1; /* produce flat file? */ |
24 |
< |
|
24 |
> |
double origexp = -1.0; /* original exposure */ |
25 |
|
char *progname; |
26 |
|
|
27 |
+ |
static gethfunc headline; |
28 |
+ |
static void quiterr(char *err); |
29 |
+ |
static void convert(void); |
30 |
|
|
31 |
< |
int |
32 |
< |
headline(s) /* process header line */ |
33 |
< |
char *s; |
31 |
> |
|
32 |
> |
|
33 |
> |
static int |
34 |
> |
headline( /* process header line */ |
35 |
> |
char *s, |
36 |
> |
void *p |
37 |
> |
) |
38 |
|
{ |
39 |
|
char fmt[32]; |
40 |
|
|
47 |
|
rgbinp = -2; |
48 |
|
return(0); /* don't echo */ |
49 |
|
} |
50 |
+ |
if (origexp > 0.0 && isexpos(s)) { |
51 |
+ |
origexp *= exposval(s); |
52 |
+ |
return(0); /* don't echo */ |
53 |
+ |
} |
54 |
|
if (isprims(s)) { /* get input primaries */ |
55 |
|
primsval(inprims, s); |
56 |
|
return(0); /* don't echo */ |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
< |
main(argc, argv) |
64 |
< |
int argc; |
59 |
< |
char *argv[]; |
63 |
> |
int |
64 |
> |
main(int argc, char *argv[]) |
65 |
|
{ |
66 |
|
int i; |
67 |
|
SET_DEFAULT_BINARY(); |
93 |
|
outprims[WHT][CIEX] = atof(argv[++i]); |
94 |
|
outprims[WHT][CIEY] = atof(argv[++i]); |
95 |
|
break; |
96 |
+ |
case 'o': /* original exposure */ |
97 |
+ |
origexp = 1.0; |
98 |
+ |
break; |
99 |
|
case 'e': /* exposure compensation */ |
100 |
|
expcomp = atof(argv[++i]); |
101 |
|
if (argv[i][0] == '+' || argv[i][0] == '-') |
130 |
|
convert(); /* convert picture */ |
131 |
|
exit(0); |
132 |
|
userr: |
133 |
< |
fprintf(stderr, "Usage: %s [-r][-e exp][-c|-u]", progname); |
133 |
> |
fprintf(stderr, "Usage: %s [-r][-o][-e exp][-c|-u]", progname); |
134 |
|
fprintf(stderr, "[-p rx ry gx gy bx by wx wy] [input [output]]\n"); |
135 |
|
exit(1); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
< |
quiterr(err) /* print message and exit */ |
140 |
< |
char *err; |
139 |
> |
static void |
140 |
> |
quiterr( /* print message and exit */ |
141 |
> |
char *err |
142 |
> |
) |
143 |
|
{ |
144 |
|
if (err != NULL) { |
145 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
< |
convert() /* convert to XYZE or RGBE picture */ |
152 |
> |
static void |
153 |
> |
convert(void) /* convert to XYZE or RGBE picture */ |
154 |
|
{ |
155 |
|
int order; |
156 |
|
int xmax, ymax; |
157 |
|
COLORMAT xfm; |
158 |
|
register COLOR *scanin; |
159 |
|
register COLR *scanout; |
160 |
< |
double ourexp = expcomp; |
160 |
> |
double exp2do = expcomp; |
161 |
> |
double exp2report = expcomp; |
162 |
|
int y; |
163 |
|
register int x; |
164 |
+ |
/* recover original? */ |
165 |
+ |
if (origexp > 0.0) |
166 |
+ |
exp2do /= origexp; |
167 |
|
/* compute transform */ |
168 |
|
if (rgbout) { |
169 |
|
if (rgbinp) { /* RGBE -> RGBE */ |
170 |
|
comprgb2rgbWBmat(xfm, inprims, outprims); |
171 |
|
} else { /* XYZE -> RGBE */ |
172 |
|
compxyz2rgbWBmat(xfm, outprims); |
173 |
< |
ourexp *= WHTEFFICACY; |
173 |
> |
if (origexp > 0.0) |
174 |
> |
exp2do /= WHTEFFICACY; |
175 |
> |
else |
176 |
> |
exp2report *= WHTEFFICACY; |
177 |
|
} |
178 |
|
} else { |
179 |
|
if (rgbinp) { /* RGBE -> XYZE */ |
180 |
|
comprgb2xyzWBmat(xfm, inprims); |
181 |
< |
ourexp /= WHTEFFICACY; |
181 |
> |
if (origexp > 0.0) |
182 |
> |
exp2do *= WHTEFFICACY; |
183 |
> |
else |
184 |
> |
exp2report /= WHTEFFICACY; |
185 |
|
} else { /* XYZE -> XYZE */ |
186 |
|
for (y = 0; y < 3; y++) |
187 |
|
for (x = 0; x < 3; x++) |
190 |
|
} |
191 |
|
for (y = 0; y < 3; y++) |
192 |
|
for (x = 0; x < 3; x++) |
193 |
< |
xfm[y][x] *= expcomp; |
193 |
> |
xfm[y][x] *= exp2do; |
194 |
|
/* get input resolution */ |
195 |
|
if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0) |
196 |
|
quiterr("bad picture format"); |
197 |
|
/* complete output header */ |
198 |
< |
if (ourexp < 0.99 || ourexp > 1.01) |
199 |
< |
fputexpos(ourexp, stdout); |
198 |
> |
if ((exp2report < 0.99) | (exp2report > 1.01)) |
199 |
> |
fputexpos(exp2report, stdout); |
200 |
|
if (rgbout) { |
201 |
|
fputprims(outprims, stdout); |
202 |
|
fputformat(COLRFMT, stdout); |