69 |
|
quiterr("bad raster format"); |
70 |
|
xmax = head.ras_width; |
71 |
|
ymax = head.ras_height; |
72 |
< |
if (head.ras_type != RT_STANDARD || |
73 |
< |
head.ras_maptype != RMT_NONE || |
74 |
< |
head.ras_depth != 24) |
72 |
> |
if ((head.ras_type != RT_STANDARD |
73 |
> |
&& head.ras_type != RT_FORMAT_RGB) |
74 |
> |
|| head.ras_maptype != RMT_NONE |
75 |
> |
|| head.ras_depth != 24) |
76 |
|
quiterr("incompatible format"); |
77 |
|
/* put header */ |
78 |
|
printargs(i, argv, stdout); |
79 |
+ |
fputformat(COLRFMT, stdout); |
80 |
|
putchar('\n'); |
81 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
82 |
|
/* convert file */ |
83 |
< |
pr2ra(); |
83 |
> |
pr2ra(head.ras_type); |
84 |
|
} else { |
85 |
< |
/* discard input header */ |
86 |
< |
getheader(stdin, NULL); |
87 |
< |
/* get resolution */ |
88 |
< |
if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
87 |
< |
quiterr("bad picture size"); |
85 |
> |
/* get header info. */ |
86 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
87 |
> |
fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
88 |
> |
quiterr("bad picture format"); |
89 |
|
/* write rasterfile header */ |
90 |
|
head.ras_magic = RAS_MAGIC; |
91 |
|
head.ras_width = xmax; |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
< |
pr2ra() /* convert 24-bit scanlines to Radiance picture */ |
121 |
> |
pr2ra(rf) /* convert 24-bit scanlines to Radiance picture */ |
122 |
> |
int rf; |
123 |
|
{ |
124 |
|
COLR *scanout; |
125 |
|
register int x; |
130 |
|
quiterr("out of memory in pr2ra"); |
131 |
|
/* convert image */ |
132 |
|
for (y = ymax-1; y >= 0; y--) { |
133 |
< |
for (x = 0; x < xmax; x++) { |
134 |
< |
scanout[x][RED] = getc(stdin); |
135 |
< |
scanout[x][GRN] = getc(stdin); |
136 |
< |
scanout[x][BLU] = getc(stdin); |
137 |
< |
} |
133 |
> |
for (x = 0; x < xmax; x++) |
134 |
> |
if (rf == RT_FORMAT_RGB) { |
135 |
> |
scanout[x][RED] = getc(stdin); |
136 |
> |
scanout[x][GRN] = getc(stdin); |
137 |
> |
scanout[x][BLU] = getc(stdin); |
138 |
> |
} else { |
139 |
> |
scanout[x][BLU] = getc(stdin); |
140 |
> |
scanout[x][GRN] = getc(stdin); |
141 |
> |
scanout[x][RED] = getc(stdin); |
142 |
> |
} |
143 |
|
if (feof(stdin) || ferror(stdin)) |
144 |
|
quiterr("error reading rasterfile"); |
145 |
|
gambs_colrs(scanout, xmax); |
166 |
|
quiterr("error reading Radiance picture"); |
167 |
|
colrs_gambs(scanin, xmax); |
168 |
|
for (x = 0; x < xmax; x++) { |
162 |
– |
putc(scanin[x][RED], stdout); |
163 |
– |
putc(scanin[x][GRN], stdout); |
169 |
|
putc(scanin[x][BLU], stdout); |
170 |
+ |
putc(scanin[x][GRN], stdout); |
171 |
+ |
putc(scanin[x][RED], stdout); |
172 |
|
} |
173 |
|
if (ferror(stdout)) |
174 |
|
quiterr("error writing rasterfile"); |