16 |
|
|
17 |
|
extern double atof(), pow(); |
18 |
|
|
19 |
< |
double gamma = 2.0; /* gamma correction */ |
19 |
> |
double gamma = 2.2; /* gamma correction */ |
20 |
|
|
21 |
|
int bradj = 0; /* brightness adjustment */ |
22 |
|
|
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]) { |
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; |
103 |
|
head.ras_height = ymax; |
104 |
|
head.ras_depth = 24; |
105 |
|
head.ras_length = xmax*ymax*3; |
102 |
– |
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: |
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 |
< |
if (rf == RT_FORMAT_RGB) { |
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 |
< |
} else { |
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); |
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) |
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 |
|
} |