6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <string.h> |
10 |
+ |
|
11 |
|
#include "platform.h" |
12 |
|
#include "color.h" |
13 |
|
#include "resolu.h" |
19 |
|
|
20 |
|
char *progname; |
21 |
|
|
22 |
< |
void quiterr(const char *); |
23 |
< |
void rad2bmp(FILE *rfp, BMPWriter *bwr, int inv, int gry); |
24 |
< |
void bmp2rad(BMPReader *brd, FILE *rfp, int inv); |
22 |
> |
static void quiterr(const char *); |
23 |
> |
static void rad2bmp(FILE *rfp, BMPWriter *bwr, int inv, int gry); |
24 |
> |
static void bmp2rad(BMPReader *brd, FILE *rfp, int inv); |
25 |
|
|
26 |
|
|
27 |
|
int |
102 |
|
rs.xr = rdr->hdr->width; |
103 |
|
rs.yr = rdr->hdr->height; |
104 |
|
rs.rt = YMAJOR; |
105 |
+ |
/* write scans downward if we can */ |
106 |
|
if (rdr->hdr->yIsDown || inpfile != NULL) |
107 |
|
rs.rt |= YDECR; |
108 |
|
fputsresolu(&rs, stdout); |
109 |
|
/* convert file */ |
110 |
|
bmp2rad(rdr, stdout, !rdr->hdr->yIsDown && inpfile!=NULL); |
111 |
|
/* flush output */ |
112 |
< |
BMPcloseInput(rdr); /* COMMENT OUT LATER */ |
112 |
> |
BMPcloseInput(rdr); |
113 |
|
if (fflush(stdout) < 0) |
114 |
|
quiterr("error writing Radiance output"); |
115 |
|
} else { |
126 |
|
!fgetsresolu(&rs, stdin)) |
127 |
|
quiterr("bad Radiance picture format"); |
128 |
|
/* initialize BMP header */ |
129 |
< |
if (gryflag) |
129 |
> |
if (gryflag) { |
130 |
|
hdr = BMPmappedHeader(numscans(&rs), |
131 |
|
scanlen(&rs), 0, 256); |
132 |
< |
else |
132 |
> |
if (outfile != NULL) |
133 |
> |
hdr->compr = BI_RLE8; |
134 |
> |
} else |
135 |
|
hdr = BMPtruecolorHeader(numscans(&rs), |
136 |
|
scanlen(&rs), 0); |
137 |
|
if (hdr == NULL) |
138 |
|
quiterr("cannot initialize BMP header"); |
139 |
< |
hdr->yIsDown = (rs.rt & YDECR) && outfile == NULL; |
139 |
> |
/* set up output direction */ |
140 |
> |
hdr->yIsDown = (rs.rt & YDECR) && |
141 |
> |
((outfile == NULL) | (hdr->compr == BI_RLE8)); |
142 |
|
/* open BMP output */ |
143 |
|
if (outfile != NULL) |
144 |
|
wtr = BMPopenOutputFile(outfile, hdr); |
145 |
|
else |
146 |
|
wtr = BMPopenOutputStream(stdout, hdr); |
147 |
+ |
if (wtr == NULL) |
148 |
+ |
quiterr("cannot allocate writer structure"); |
149 |
|
/* convert file */ |
150 |
|
rad2bmp(stdin, wtr, !hdr->yIsDown && (rs.rt&YDECR), gryflag); |
151 |
|
/* flush output */ |
152 |
|
if (fflush((FILE *)wtr->c_data) < 0) |
153 |
|
quiterr("error writing BMP output"); |
154 |
< |
BMPcloseOutput(wtr); /* COMMENT OUT LATER */ |
154 |
> |
BMPcloseOutput(wtr); |
155 |
|
} |
156 |
|
exit(0); /* success */ |
157 |
|
userr: |
159 |
|
"Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n", |
160 |
|
progname); |
161 |
|
exit(1); |
162 |
< |
return(1); /* to keep compiler happy */ |
162 |
> |
return(1); /* gratis return */ |
163 |
|
} |
164 |
|
|
165 |
|
/* print message and exit */ |
166 |
< |
void |
166 |
> |
static void |
167 |
|
quiterr(const char *err) |
168 |
|
{ |
169 |
|
if (err != NULL) { |
174 |
|
} |
175 |
|
|
176 |
|
/* convert Radiance picture to BMP */ |
177 |
< |
void |
177 |
> |
static void |
178 |
|
rad2bmp(FILE *rfp, BMPWriter *bwr, int inv, int gry) |
179 |
|
{ |
180 |
|
COLR *scanin; |
220 |
|
} |
221 |
|
|
222 |
|
/* convert BMP file to Radiance */ |
223 |
< |
void |
223 |
> |
static void |
224 |
|
bmp2rad(BMPReader *brd, FILE *rfp, int inv) |
225 |
|
{ |
226 |
|
COLR *scanout; |