1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
18 |
|
|
19 |
|
double gamma = 2.0; /* gamma correction */ |
20 |
|
|
21 |
+ |
int bradj = 0; /* brightness adjustment */ |
22 |
+ |
|
23 |
|
char *progname; |
24 |
|
|
25 |
|
int xmax, ymax; |
41 |
|
case 'g': |
42 |
|
gamma = atof(argv[++i]); |
43 |
|
break; |
44 |
+ |
case 'e': |
45 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
46 |
+ |
goto userr; |
47 |
+ |
bradj = atoi(argv[++i]); |
48 |
+ |
break; |
49 |
|
case 'r': |
50 |
|
reverse = !reverse; |
51 |
|
break; |
76 |
|
quiterr("bad raster format"); |
77 |
|
xmax = head.ras_width; |
78 |
|
ymax = head.ras_height; |
79 |
< |
if (head.ras_type != RT_STANDARD || |
80 |
< |
head.ras_maptype != RMT_NONE || |
81 |
< |
head.ras_depth != 24) |
79 |
> |
if ((head.ras_type != RT_STANDARD |
80 |
> |
&& head.ras_type != RT_FORMAT_RGB) |
81 |
> |
|| head.ras_maptype != RMT_NONE |
82 |
> |
|| head.ras_depth != 24) |
83 |
|
quiterr("incompatible format"); |
84 |
|
/* put header */ |
85 |
|
printargs(i, argv, stdout); |
86 |
+ |
fputformat(COLRFMT, stdout); |
87 |
|
putchar('\n'); |
88 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
89 |
|
/* convert file */ |
90 |
< |
pr2ra(); |
90 |
> |
pr2ra(head.ras_type); |
91 |
|
} else { |
92 |
< |
/* discard input header */ |
93 |
< |
getheader(stdin, NULL); |
94 |
< |
/* get resolution */ |
95 |
< |
if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
87 |
< |
quiterr("bad picture size"); |
92 |
> |
/* get header info. */ |
93 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
94 |
> |
fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
95 |
> |
quiterr("bad picture format"); |
96 |
|
/* write rasterfile header */ |
97 |
|
head.ras_magic = RAS_MAGIC; |
98 |
|
head.ras_width = xmax; |
108 |
|
} |
109 |
|
exit(0); |
110 |
|
userr: |
111 |
< |
fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n", |
111 |
> |
fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n", |
112 |
|
progname); |
113 |
|
exit(1); |
114 |
|
} |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
< |
pr2ra() /* convert 24-bit scanlines to Radiance picture */ |
128 |
> |
pr2ra(rf) /* convert 24-bit scanlines to Radiance picture */ |
129 |
> |
int rf; |
130 |
|
{ |
131 |
|
COLR *scanout; |
132 |
|
register int x; |
137 |
|
quiterr("out of memory in pr2ra"); |
138 |
|
/* convert image */ |
139 |
|
for (y = ymax-1; y >= 0; y--) { |
140 |
< |
for (x = 0; x < xmax; x++) { |
141 |
< |
scanout[x][BLU] = getc(stdin); |
142 |
< |
scanout[x][GRN] = getc(stdin); |
143 |
< |
scanout[x][RED] = getc(stdin); |
144 |
< |
} |
140 |
> |
for (x = 0; x < xmax; x++) |
141 |
> |
if (rf == RT_FORMAT_RGB) { |
142 |
> |
scanout[x][RED] = getc(stdin); |
143 |
> |
scanout[x][GRN] = getc(stdin); |
144 |
> |
scanout[x][BLU] = getc(stdin); |
145 |
> |
} else { |
146 |
> |
scanout[x][BLU] = getc(stdin); |
147 |
> |
scanout[x][GRN] = getc(stdin); |
148 |
> |
scanout[x][RED] = getc(stdin); |
149 |
> |
} |
150 |
|
if (feof(stdin) || ferror(stdin)) |
151 |
|
quiterr("error reading rasterfile"); |
152 |
|
gambs_colrs(scanout, xmax); |
153 |
+ |
if (bradj) |
154 |
+ |
shiftcolrs(scanout, xmax, bradj); |
155 |
|
if (fwritecolrs(scanout, xmax, stdout) < 0) |
156 |
|
quiterr("error writing Radiance picture"); |
157 |
|
} |
173 |
|
for (y = ymax-1; y >= 0; y--) { |
174 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
175 |
|
quiterr("error reading Radiance picture"); |
176 |
+ |
if (bradj) |
177 |
+ |
shiftcolrs(scanin, xmax, bradj); |
178 |
|
colrs_gambs(scanin, xmax); |
179 |
|
for (x = 0; x < xmax; x++) { |
180 |
|
putc(scanin[x][BLU], stdout); |