1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
|
#endif |
6 |
|
|
7 |
|
/* |
34 |
|
char *progname; |
35 |
|
|
36 |
|
|
37 |
+ |
int |
38 |
|
headline(s) /* process header line */ |
39 |
|
char *s; |
40 |
|
{ |
47 |
|
rgbinp = 0; |
48 |
|
else |
49 |
|
rgbinp = -2; |
50 |
< |
return; /* don't echo */ |
50 |
> |
return(0); /* don't echo */ |
51 |
|
} |
52 |
|
if (isprims(s)) { /* get input primaries */ |
53 |
|
primsval(inprims, s); |
54 |
< |
return; /* don't echo */ |
54 |
> |
return(0); /* don't echo */ |
55 |
|
} |
56 |
|
/* should I grok colcorr also? */ |
57 |
< |
fputs(s, stdout); |
57 |
> |
return(fputs(s, stdout)); |
58 |
|
} |
59 |
|
|
60 |
|
|
84 |
|
rgbout = 1; |
85 |
|
break; |
86 |
|
case 'p': /* RGB primaries */ |
87 |
< |
if (i+9 >= argc) |
87 |
> |
if (i+8 >= argc) |
88 |
|
goto userr; |
89 |
|
outprims[RED][CIEX] = atof(argv[++i]); |
90 |
|
outprims[RED][CIEY] = atof(argv[++i]); |
126 |
|
if (rgbinp == -1) |
127 |
|
rgbinp = !rgbout; |
128 |
|
printargs(argc, argv, stdout); /* add to header */ |
128 |
– |
if (expcomp < 0.99 || expcomp > 1.01) |
129 |
– |
fputexpos(expcomp, stdout); |
129 |
|
convert(); /* convert picture */ |
130 |
|
exit(0); |
131 |
|
userr: |
153 |
|
COLORMAT xfm; |
154 |
|
register COLOR *scanin; |
155 |
|
register COLR *scanout; |
156 |
+ |
double ourexp = expcomp; |
157 |
|
int y; |
158 |
|
register int x; |
159 |
|
/* compute transform */ |
160 |
|
if (rgbout) { |
161 |
– |
double mult; |
161 |
|
if (rgbinp) { /* RGBE -> RGBE */ |
162 |
|
comprgb2rgbmat(xfm, inprims, outprims); |
164 |
– |
mult = expcomp; |
163 |
|
} else { /* XYZE -> RGBE */ |
164 |
|
compxyz2rgbmat(xfm, outprims); |
165 |
< |
mult = expcomp/WHTEFFICACY; |
165 |
> |
ourexp *= WHTEFFICACY; |
166 |
|
} |
169 |
– |
for (y = 0; y < 3; y++) |
170 |
– |
for (x = 0; x < 3; x++) |
171 |
– |
xfm[y][x] *= mult; |
167 |
|
} else { |
168 |
|
if (rgbinp) { /* RGBE -> XYZE */ |
169 |
|
comprgb2xyzmat(xfm, inprims); |
170 |
< |
for (y = 0; y < 3; y++) |
176 |
< |
for (x = 0; x < 3; x++) |
177 |
< |
xfm[y][x] *= WHTEFFICACY*expcomp; |
170 |
> |
ourexp /= WHTEFFICACY; |
171 |
|
} else { /* XYZE -> XYZE */ |
172 |
|
for (y = 0; y < 3; y++) |
173 |
|
for (x = 0; x < 3; x++) |
174 |
< |
xfm[y][x] = x==y ? expcomp : 0.; |
174 |
> |
xfm[y][x] = x==y ? 1. : 0.; |
175 |
|
} |
176 |
|
} |
177 |
+ |
for (y = 0; y < 3; y++) |
178 |
+ |
for (x = 0; x < 3; x++) |
179 |
+ |
xfm[y][x] *= expcomp; |
180 |
|
/* get input resolution */ |
181 |
|
if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0) |
182 |
|
quiterr("bad picture format"); |
183 |
|
/* complete output header */ |
184 |
+ |
if (ourexp < 0.99 || ourexp > 1.01) |
185 |
+ |
fputexpos(ourexp, stdout); |
186 |
|
if (rgbout) { |
187 |
|
fputprims(outprims, stdout); |
188 |
|
fputformat(COLRFMT, stdout); |
199 |
|
for (y = 0; y < ymax; y++) { |
200 |
|
if (freadscan(scanin, xmax, stdin) < 0) |
201 |
|
quiterr("error reading input picture"); |
202 |
< |
for (x = 0; x < xmax; x++) |
202 |
> |
for (x = 0; x < xmax; x++) { |
203 |
|
colortrans(scanin[x], xfm, scanin[x]); |
204 |
+ |
if (rgbout) |
205 |
+ |
clipgamut(scanin[x], bright(scanin[x]), |
206 |
+ |
CGAMUT_LOWER, cblack, cwhite); |
207 |
+ |
} |
208 |
|
if (scanout != NULL) { |
209 |
|
for (x = 0; x < xmax; x++) |
210 |
|
setcolr(scanout[x], colval(scanin[x],RED), |