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; |
35 |
|
|
36 |
|
progname = argv[0]; |
37 |
|
|
38 |
+ |
head.ras_type = RT_STANDARD; |
39 |
|
for (i = 1; i < argc; i++) |
40 |
|
if (argv[i][0] == '-') |
41 |
|
switch (argv[i][1]) { |
42 |
|
case 'g': |
43 |
|
gamma = atof(argv[++i]); |
44 |
|
break; |
45 |
+ |
case 'e': |
46 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
47 |
+ |
goto userr; |
48 |
+ |
bradj = atoi(argv[++i]); |
49 |
+ |
break; |
50 |
|
case 'r': |
51 |
< |
reverse = !reverse; |
51 |
> |
if (!strcmp(argv[i], "-rgb")) |
52 |
> |
head.ras_type = RT_FORMAT_RGB; |
53 |
> |
else |
54 |
> |
reverse = 1; |
55 |
|
break; |
56 |
|
default: |
57 |
|
goto userr; |
80 |
|
quiterr("bad raster format"); |
81 |
|
xmax = head.ras_width; |
82 |
|
ymax = head.ras_height; |
83 |
< |
if (head.ras_type != RT_STANDARD || |
84 |
< |
head.ras_maptype != RMT_NONE || |
85 |
< |
head.ras_depth != 24) |
83 |
> |
if ((head.ras_type != RT_STANDARD |
84 |
> |
&& head.ras_type != RT_FORMAT_RGB) |
85 |
> |
|| head.ras_maptype != RMT_NONE |
86 |
> |
|| head.ras_depth != 24) |
87 |
|
quiterr("incompatible format"); |
88 |
|
/* put header */ |
89 |
|
printargs(i, argv, stdout); |
90 |
+ |
fputformat(COLRFMT, stdout); |
91 |
|
putchar('\n'); |
92 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
93 |
|
/* convert file */ |
94 |
< |
pr2ra(); |
94 |
> |
pr2ra(head.ras_type); |
95 |
|
} else { |
96 |
< |
/* discard input header */ |
97 |
< |
getheader(stdin, NULL); |
98 |
< |
/* get resolution */ |
99 |
< |
if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
87 |
< |
quiterr("bad picture size"); |
96 |
> |
/* get header info. */ |
97 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
98 |
> |
fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
99 |
> |
quiterr("bad picture format"); |
100 |
|
/* write rasterfile header */ |
101 |
|
head.ras_magic = RAS_MAGIC; |
102 |
|
head.ras_width = xmax; |
103 |
|
head.ras_height = ymax; |
104 |
|
head.ras_depth = 24; |
105 |
|
head.ras_length = xmax*ymax*3; |
94 |
– |
head.ras_type = RT_STANDARD; |
106 |
|
head.ras_maptype = RMT_NONE; |
107 |
|
head.ras_maplength = 0; |
108 |
|
fwrite((char *)&head, sizeof(head), 1, stdout); |
109 |
|
/* convert file */ |
110 |
< |
ra2pr(); |
110 |
> |
ra2pr(head.ras_type); |
111 |
|
} |
112 |
|
exit(0); |
113 |
|
userr: |
114 |
< |
fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n", |
114 |
> |
fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n", |
115 |
|
progname); |
116 |
|
exit(1); |
117 |
|
} |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
< |
pr2ra() /* convert 24-bit scanlines to Radiance picture */ |
131 |
> |
pr2ra(rf) /* convert 24-bit scanlines to Radiance picture */ |
132 |
> |
int rf; |
133 |
|
{ |
134 |
|
COLR *scanout; |
135 |
|
register int x; |
140 |
|
quiterr("out of memory in pr2ra"); |
141 |
|
/* convert image */ |
142 |
|
for (y = ymax-1; y >= 0; y--) { |
143 |
< |
for (x = 0; x < xmax; x++) { |
144 |
< |
scanout[x][BLU] = getc(stdin); |
145 |
< |
scanout[x][GRN] = getc(stdin); |
146 |
< |
scanout[x][RED] = getc(stdin); |
147 |
< |
} |
143 |
> |
if (rf == RT_FORMAT_RGB) |
144 |
> |
for (x = 0; x < xmax; x++) { |
145 |
> |
scanout[x][RED] = getc(stdin); |
146 |
> |
scanout[x][GRN] = getc(stdin); |
147 |
> |
scanout[x][BLU] = getc(stdin); |
148 |
> |
} |
149 |
> |
else |
150 |
> |
for (x = 0; x < xmax; x++) { |
151 |
> |
scanout[x][BLU] = getc(stdin); |
152 |
> |
scanout[x][GRN] = getc(stdin); |
153 |
> |
scanout[x][RED] = getc(stdin); |
154 |
> |
} |
155 |
|
if (feof(stdin) || ferror(stdin)) |
156 |
|
quiterr("error reading rasterfile"); |
157 |
|
gambs_colrs(scanout, xmax); |
158 |
+ |
if (bradj) |
159 |
+ |
shiftcolrs(scanout, xmax, bradj); |
160 |
|
if (fwritecolrs(scanout, xmax, stdout) < 0) |
161 |
|
quiterr("error writing Radiance picture"); |
162 |
|
} |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
< |
ra2pr() /* convert Radiance scanlines to 24-bit rasterfile */ |
168 |
> |
ra2pr(rf) /* convert Radiance scanlines to 24-bit rasterfile */ |
169 |
> |
int rf; |
170 |
|
{ |
171 |
|
COLR *scanin; |
172 |
|
register int x; |
174 |
|
/* allocate scanline */ |
175 |
|
scanin = (COLR *)malloc(xmax*sizeof(COLR)); |
176 |
|
if (scanin == NULL) |
177 |
< |
quiterr("out of memory in pr2ra"); |
177 |
> |
quiterr("out of memory in ra2pr"); |
178 |
|
/* convert image */ |
179 |
|
for (y = ymax-1; y >= 0; y--) { |
180 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
181 |
|
quiterr("error reading Radiance picture"); |
182 |
+ |
if (bradj) |
183 |
+ |
shiftcolrs(scanin, xmax, bradj); |
184 |
|
colrs_gambs(scanin, xmax); |
185 |
< |
for (x = 0; x < xmax; x++) { |
186 |
< |
putc(scanin[x][BLU], stdout); |
187 |
< |
putc(scanin[x][GRN], stdout); |
188 |
< |
putc(scanin[x][RED], stdout); |
189 |
< |
} |
185 |
> |
if (rf == RT_FORMAT_RGB) |
186 |
> |
for (x = 0; x < xmax; x++) { |
187 |
> |
putc(scanin[x][RED], stdout); |
188 |
> |
putc(scanin[x][GRN], stdout); |
189 |
> |
putc(scanin[x][BLU], stdout); |
190 |
> |
} |
191 |
> |
else |
192 |
> |
for (x = 0; x < xmax; x++) { |
193 |
> |
putc(scanin[x][BLU], stdout); |
194 |
> |
putc(scanin[x][GRN], stdout); |
195 |
> |
putc(scanin[x][RED], stdout); |
196 |
> |
} |
197 |
|
if (ferror(stdout)) |
198 |
|
quiterr("error writing rasterfile"); |
199 |
|
} |