14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
+ |
#include "resolu.h" |
18 |
+ |
|
19 |
|
extern double atof(), pow(); |
20 |
|
|
21 |
< |
double gamma = 2.0; /* gamma correction */ |
21 |
> |
double gamma = 2.2; /* gamma correction */ |
22 |
|
|
23 |
|
int bradj = 0; /* brightness adjustment */ |
24 |
|
|
37 |
|
|
38 |
|
progname = argv[0]; |
39 |
|
|
40 |
+ |
head.ras_type = RT_STANDARD; |
41 |
|
for (i = 1; i < argc; i++) |
42 |
|
if (argv[i][0] == '-') |
43 |
|
switch (argv[i][1]) { |
50 |
|
bradj = atoi(argv[++i]); |
51 |
|
break; |
52 |
|
case 'r': |
53 |
< |
reverse = !reverse; |
53 |
> |
if (!strcmp(argv[i], "-rgb")) |
54 |
> |
head.ras_type = RT_FORMAT_RGB; |
55 |
> |
else |
56 |
> |
reverse = 1; |
57 |
|
break; |
58 |
|
default: |
59 |
|
goto userr; |
91 |
|
printargs(i, argv, stdout); |
92 |
|
fputformat(COLRFMT, stdout); |
93 |
|
putchar('\n'); |
94 |
< |
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
94 |
> |
fprtresolu(xmax, ymax, stdout); |
95 |
|
/* convert file */ |
96 |
|
pr2ra(head.ras_type); |
97 |
|
} else { |
98 |
|
/* get header info. */ |
99 |
|
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
100 |
< |
fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
100 |
> |
fgetresolu(&xmax, &ymax, stdin) < 0) |
101 |
|
quiterr("bad picture format"); |
102 |
|
/* write rasterfile header */ |
103 |
|
head.ras_magic = RAS_MAGIC; |
105 |
|
head.ras_height = ymax; |
106 |
|
head.ras_depth = 24; |
107 |
|
head.ras_length = xmax*ymax*3; |
102 |
– |
head.ras_type = RT_STANDARD; |
108 |
|
head.ras_maptype = RMT_NONE; |
109 |
|
head.ras_maplength = 0; |
110 |
|
fwrite((char *)&head, sizeof(head), 1, stdout); |
111 |
|
/* convert file */ |
112 |
< |
ra2pr(); |
112 |
> |
ra2pr(head.ras_type); |
113 |
|
} |
114 |
|
exit(0); |
115 |
|
userr: |
142 |
|
quiterr("out of memory in pr2ra"); |
143 |
|
/* convert image */ |
144 |
|
for (y = ymax-1; y >= 0; y--) { |
145 |
< |
for (x = 0; x < xmax; x++) |
146 |
< |
if (rf == RT_FORMAT_RGB) { |
145 |
> |
if (rf == RT_FORMAT_RGB) |
146 |
> |
for (x = 0; x < xmax; x++) { |
147 |
|
scanout[x][RED] = getc(stdin); |
148 |
|
scanout[x][GRN] = getc(stdin); |
149 |
|
scanout[x][BLU] = getc(stdin); |
150 |
< |
} else { |
150 |
> |
} |
151 |
> |
else |
152 |
> |
for (x = 0; x < xmax; x++) { |
153 |
|
scanout[x][BLU] = getc(stdin); |
154 |
|
scanout[x][GRN] = getc(stdin); |
155 |
|
scanout[x][RED] = getc(stdin); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
< |
ra2pr() /* convert Radiance scanlines to 24-bit rasterfile */ |
170 |
> |
ra2pr(rf) /* convert Radiance scanlines to 24-bit rasterfile */ |
171 |
> |
int rf; |
172 |
|
{ |
173 |
|
COLR *scanin; |
174 |
|
register int x; |
184 |
|
if (bradj) |
185 |
|
shiftcolrs(scanin, xmax, bradj); |
186 |
|
colrs_gambs(scanin, xmax); |
187 |
< |
for (x = 0; x < xmax; x++) { |
188 |
< |
putc(scanin[x][BLU], stdout); |
189 |
< |
putc(scanin[x][GRN], stdout); |
190 |
< |
putc(scanin[x][RED], stdout); |
191 |
< |
} |
187 |
> |
if (rf == RT_FORMAT_RGB) |
188 |
> |
for (x = 0; x < xmax; x++) { |
189 |
> |
putc(scanin[x][RED], stdout); |
190 |
> |
putc(scanin[x][GRN], stdout); |
191 |
> |
putc(scanin[x][BLU], stdout); |
192 |
> |
} |
193 |
> |
else |
194 |
> |
for (x = 0; x < xmax; x++) { |
195 |
> |
putc(scanin[x][BLU], stdout); |
196 |
> |
putc(scanin[x][GRN], stdout); |
197 |
> |
putc(scanin[x][RED], stdout); |
198 |
> |
} |
199 |
|
if (ferror(stdout)) |
200 |
|
quiterr("error writing rasterfile"); |
201 |
|
} |