5 |
|
* program to convert between RADIANCE and Windows BMP file |
6 |
|
*/ |
7 |
|
|
8 |
– |
#include <stdio.h> |
8 |
|
#include <math.h> |
10 |
– |
#include <string.h> |
9 |
|
|
10 |
+ |
#include "rtio.h" |
11 |
|
#include "platform.h" |
12 |
|
#include "color.h" |
13 |
|
#include "tonemap.h" |
18 |
|
|
19 |
|
double gamcor = 2.2; /* gamma correction value */ |
20 |
|
|
22 |
– |
char *progname; |
23 |
– |
|
21 |
|
static void quiterr(const char *err); |
22 |
|
static void tmap2bmp(char *fnin, char *fnout, char *expec, |
23 |
|
RGBPRIMP monpri, double gamval); |
41 |
|
RESOLU rs; |
42 |
|
int i; |
43 |
|
|
44 |
< |
progname = argv[0]; |
44 |
> |
fixargv0(argv[0]); /* assigns progname */ |
45 |
|
|
46 |
|
for (i = 1; i < argc; i++) |
47 |
|
if (argv[i][0] == '-' && argv[i][1]) |
157 |
|
if (rgbp == NULL) { |
158 |
|
hdr = BMPmappedHeader(scanlen(&rs), |
159 |
|
numscans(&rs), 0, 256); |
160 |
+ |
/* |
161 |
|
if (outfile != NULL) |
162 |
|
hdr->compr = BI_RLE8; |
163 |
+ |
*/ |
164 |
|
} else |
165 |
|
hdr = BMPtruecolorHeader(scanlen(&rs), |
166 |
|
numscans(&rs), 0); |
208 |
|
static int |
209 |
|
headline(char *s, void *p) |
210 |
|
{ |
211 |
< |
char fmt[32]; |
211 |
> |
char fmt[MAXFMTLEN]; |
212 |
|
|
213 |
|
if (formatval(fmt, s)) { /* check if format string */ |
214 |
|
if (!strcmp(fmt,COLRFMT)) |
217 |
|
rgbinp = TM_XYZPRIM; |
218 |
|
return(0); |
219 |
|
} |
220 |
+ |
if (!strcmp(fmt,SPECFMT)) |
221 |
+ |
return(0); |
222 |
|
return(-1); |
223 |
|
} |
224 |
|
if (isprims(s)) { /* get input primaries */ |
226 |
|
rgbinp = myinprims; |
227 |
|
return(0); |
228 |
|
} |
229 |
+ |
if (isncomp(s)) { |
230 |
+ |
NCSAMP = ncompval(s); |
231 |
+ |
return(0); |
232 |
+ |
} |
233 |
+ |
if (iswlsplit(s)) { |
234 |
+ |
wlsplitval(WLPART, s); |
235 |
+ |
return(0); |
236 |
+ |
} |
237 |
|
/* should I grok colcorr also? */ |
238 |
|
return(0); |
239 |
|
} |
257 |
|
usexfm = (monpri != NULL ? rgbinp != monpri : |
258 |
|
rgbinp != TM_XYZPRIM && rgbinp != stdprims); |
259 |
|
if (usexfm) { |
260 |
< |
double expcomp = pow(2.0, (double)bradj); |
260 |
> |
RGBPRIMP destpri = monpri != NULL ? monpri : stdprims; |
261 |
> |
double expcomp = pow(2.0, (double)bradj); |
262 |
|
if (rgbinp == TM_XYZPRIM) |
263 |
< |
compxyz2rgbWBmat(xfm, monpri); |
263 |
> |
compxyz2rgbWBmat(xfm, destpri); |
264 |
|
else |
265 |
< |
comprgb2rgbWBmat(xfm, rgbinp, monpri); |
265 |
> |
comprgb2rgbWBmat(xfm, rgbinp, destpri); |
266 |
|
for (y = 0; y < 3; y++) |
267 |
|
for (x = 0; x < 3; x++) |
268 |
|
xfm[y][x] *= expcomp; |
277 |
|
} |
278 |
|
/* convert each scanline */ |
279 |
|
for ( ; y != yend; y += ystp) { |
280 |
< |
if (freadcolrs(scanin, bwr->hdr->width, rfp) < 0) |
280 |
> |
if (fread2colrs(scanin, bwr->hdr->width, rfp, NCSAMP, WLPART) < 0) |
281 |
|
quiterr("error reading Radiance picture"); |
282 |
|
if (usexfm) |
283 |
|
for (x = bwr->hdr->width; x--; ) { |
360 |
|
BMPWriter *wtr; |
361 |
|
FILE *fp; |
362 |
|
int xr, yr; |
363 |
< |
BYTE *pa; |
363 |
> |
uby8 *pa; |
364 |
|
int i; |
365 |
|
/* check tone-mapping spec */ |
366 |
|
i = strlen(expec); |
405 |
|
quiterr("cannot allocate writer structure"); |
406 |
|
/* write to BMP file */ |
407 |
|
while (wtr->yscan < yr) { |
408 |
< |
BYTE *scn = pa + xr*((tmflags & TM_F_BW) ? 1 : 3)* |
408 |
> |
uby8 *scn = pa + xr*((tmflags & TM_F_BW) ? 1 : 3)* |
409 |
|
(yr-1 - wtr->yscan); |
410 |
|
if (tmflags & TM_F_BW) |
411 |
|
memcpy((void *)wtr->scanline, (void *)scn, xr); |