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 |
|
/* |
15 |
|
#endif |
16 |
|
#include "color.h" |
17 |
|
|
18 |
< |
#define GAMVAL 1.47 /* gamma value for pixels */ |
18 |
> |
#define CODE6GAM 1.47 /* gamma for 6-bit codes */ |
19 |
> |
#define DEFDGAM 1.0 /* default device gamma */ |
20 |
|
|
21 |
|
#define GRY -1 /* artificial index for grey */ |
22 |
|
|
36 |
|
int wrongformat = 0; /* input in wrong format? */ |
37 |
|
double pixaspect = 1.0; /* pixel aspect ratio */ |
38 |
|
|
39 |
+ |
double devgam = DEFDGAM; /* device gamma response */ |
40 |
|
int docolor = 0; /* produce color image? */ |
41 |
|
int bradj = 0; /* brightness adjustment */ |
42 |
|
int ncopies = 1; /* number of copies */ |
91 |
|
case 'C': /* compressed ASCII encoding */ |
92 |
|
putprim = Cputprim; |
93 |
|
break; |
94 |
+ |
case 'g': |
95 |
+ |
devgam = atof(argv[++i]); |
96 |
+ |
break; |
97 |
|
case 'e': /* exposure adjustment */ |
98 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
99 |
|
goto userr; |
129 |
|
quiterr("bad picture format"); |
130 |
|
/* gamma compression */ |
131 |
|
if (putprim == Cputprim) |
132 |
< |
setcolrgam(GAMVAL); |
132 |
> |
setcolrgam(CODE6GAM/devgam); |
133 |
> |
else if (devgam != 1.) |
134 |
> |
setcolrgam(1./devgam); |
135 |
|
/* write header */ |
136 |
|
PSheader(i <= argc-1 ? argv[i] : "<stdin>"); |
137 |
|
/* convert file */ |
140 |
|
PStrailer(); |
141 |
|
exit(0); |
142 |
|
userr: |
143 |
< |
fprintf(stderr, "Usage: %s [-b|c][-A|B|C][-e +/-stops] [input [output]]\n", |
143 |
> |
fprintf(stderr, "Usage: %s [-b|c][-A|B|C][-e +/-stops][-g gamma] [input [output]]\n", |
144 |
|
progname); |
145 |
|
exit(1); |
146 |
|
} |
225 |
|
printf("%d %d 8 [%d 0 0 %d 0 %d]\n", xmax, ymax, xmax, -ymax, ymax); |
226 |
|
if (putprim == Cputprim) { |
227 |
|
if (docolor) { |
228 |
< |
puts("{redline read6bitRLE grnline read6bitRLE"); |
229 |
< |
puts("bluline read6bitRLE} true 3 colorimage"); |
228 |
> |
puts("{redline read6bitRLE}"); |
229 |
> |
puts("{grnline read6bitRLE}"); |
230 |
> |
puts("{bluline read6bitRLE}"); |
231 |
> |
puts("true 3 colorimage"); |
232 |
|
} else |
233 |
|
puts("{gryline read6bitRLE} image"); |
234 |
|
} else { |
265 |
|
for (i = 0; i < 128; i++) /* clear */ |
266 |
|
itab[i] = -1; |
267 |
|
for (i = 1; i < 63; i++) /* assign greys */ |
268 |
< |
itab[code[i]] = 256.0*pow((i+.5)/64.0, GAMVAL); |
268 |
> |
itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM); |
269 |
|
itab[code[0]] = 0; /* black is black */ |
270 |
|
itab[code[63]] = 255; /* and white is white */ |
271 |
|
printf("/codetab ["); |
308 |
|
for (y = ymax-1; y >= 0; y--) { |
309 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
310 |
|
quiterr("error reading Radiance picture"); |
311 |
< |
if (putprim == Cputprim) { |
311 |
> |
if (putprim == Cputprim || devgam != 1.) { |
312 |
|
if (bradj) /* adjust exposure */ |
313 |
|
shiftcolrs(scanin, xmax, bradj); |
314 |
|
colrs_gambs(scanin, xmax); /* gamma compression */ |