| 41 |
|
progname = argv[0]; |
| 42 |
|
|
| 43 |
|
for (i = 1; i < argc; i++) |
| 44 |
< |
if (argv[i][0] == '-') |
| 44 |
> |
if (argv[i][0] == '-' && argv[i][1]) |
| 45 |
|
switch (argv[i][1]) { |
| 46 |
|
case 'b': |
| 47 |
|
rgbp = NULL; |
| 72 |
|
case 'r': |
| 73 |
|
reverse = !reverse; |
| 74 |
|
break; |
| 75 |
– |
case '\0': |
| 76 |
– |
break; |
| 75 |
|
default: |
| 76 |
|
goto userr; |
| 77 |
|
} |
| 162 |
|
if (hdr == NULL) |
| 163 |
|
quiterr("cannot initialize BMP header"); |
| 164 |
|
/* set up output direction */ |
| 165 |
< |
hdr->yIsDown = (rs.rt & YDECR) && |
| 168 |
< |
((outfile == NULL) | (hdr->compr == BI_RLE8)); |
| 165 |
> |
hdr->yIsDown = ((outfile == NULL) | (hdr->compr == BI_RLE8)); |
| 166 |
|
/* open BMP output */ |
| 167 |
|
if (outfile != NULL) |
| 168 |
|
wtr = BMPopenOutputFile(outfile, hdr); |
| 171 |
|
if (wtr == NULL) |
| 172 |
|
quiterr("cannot allocate writer structure"); |
| 173 |
|
/* convert file */ |
| 174 |
< |
rad2bmp(stdin, wtr, !hdr->yIsDown && rs.rt&YDECR, rgbp==NULL); |
| 174 |
> |
rad2bmp(stdin, wtr, !hdr->yIsDown, rgbp==NULL); |
| 175 |
|
/* flush output */ |
| 176 |
|
if (fflush((FILE *)wtr->c_data) < 0) |
| 177 |
|
quiterr("error writing BMP output"); |
| 292 |
|
int tmflags; |
| 293 |
|
BMPHeader *hdr; |
| 294 |
|
BMPWriter *wtr; |
| 298 |
– |
RESOLU rs; |
| 295 |
|
FILE *fp; |
| 296 |
|
int xr, yr; |
| 297 |
|
BYTE *pa; |
| 317 |
|
fprintf(stderr, "%s: cannot open\n", fnin); |
| 318 |
|
exit(1); |
| 319 |
|
} |
| 324 |
– |
/* get picture orientation */ |
| 325 |
– |
if (fnin != NULL) { |
| 326 |
– |
if (getheader(fp, NULL, NULL) < 0 || !fgetsresolu(&rs, fp)) |
| 327 |
– |
quiterr("bad Radiance picture format"); |
| 328 |
– |
rewind(fp); |
| 329 |
– |
} else /* assume stdin has normal orient */ |
| 330 |
– |
rs.rt = PIXSTANDARD; |
| 320 |
|
/* tone-map picture */ |
| 321 |
|
if (tmMapPicture(&pa, &xr, &yr, tmflags, monpri, gamval, |
| 322 |
|
0., 0., fnin, fp) != TM_E_OK) |
| 324 |
|
/* initialize BMP header */ |
| 325 |
|
if (tmflags & TM_F_BW) { |
| 326 |
|
hdr = BMPmappedHeader(xr, yr, 0, 256); |
| 327 |
< |
hdr->compr = BI_RLE8; |
| 327 |
> |
if (fnout != NULL) |
| 328 |
> |
hdr->compr = BI_RLE8; |
| 329 |
|
} else |
| 330 |
|
hdr = BMPtruecolorHeader(xr, yr, 0); |
| 331 |
|
if (hdr == NULL) |
| 340 |
|
/* write to BMP file */ |
| 341 |
|
while (wtr->yscan < yr) { |
| 342 |
|
BYTE *scn = pa + xr*((tmflags & TM_F_BW) ? 1 : 3)* |
| 343 |
< |
((rs.rt & YDECR) ? |
| 354 |
< |
(yr-1 - wtr->yscan) : |
| 355 |
< |
wtr->yscan); |
| 343 |
> |
(yr-1 - wtr->yscan); |
| 344 |
|
if (tmflags & TM_F_BW) |
| 345 |
|
memcpy((void *)wtr->scanline, (void *)scn, xr); |
| 346 |
|
else |
| 356 |
|
if (fflush((FILE *)wtr->c_data) < 0) |
| 357 |
|
quiterr("error writing BMP output"); |
| 358 |
|
/* clean up */ |
| 359 |
+ |
if (fnin != NULL) |
| 360 |
+ |
fclose(fp); |
| 361 |
|
free((void *)pa); |
| 362 |
|
BMPcloseOutput(wtr); |
| 363 |
|
} |