13 |
|
|
14 |
|
#include <stdio.h> |
15 |
|
|
16 |
+ |
#include <math.h> |
17 |
+ |
|
18 |
|
#include <signal.h> |
19 |
|
|
20 |
|
#include <sys/ioctl.h> |
99 |
|
extern long ftell(); |
100 |
|
long scanpos[NROWS]; |
101 |
|
|
100 |
– |
extern double atof(); |
102 |
|
double exposure = 1.0; |
103 |
+ |
int wrong_fmt = 0; |
104 |
|
|
105 |
|
|
106 |
|
main(argc, argv) |
142 |
|
quitmsg(errmsg); |
143 |
|
} |
144 |
|
/* get header */ |
145 |
< |
getheader(fin, checkhead); |
145 |
> |
getheader(fin, checkhead, NULL); |
146 |
> |
if (wrong_fmt) |
147 |
> |
quitmsg("input must be a Radiance picture"); |
148 |
|
/* get picture dimensions */ |
149 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
149 |
> |
if (fgetresolu(&xmax, &ymax, fin) < 0) |
150 |
|
quitmsg("bad picture size"); |
151 |
|
if (xmax > NCOLS || ymax > NROWS) |
152 |
|
quitmsg("resolution mismatch"); |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
+ |
int |
174 |
|
checkhead(line) /* deal with line from header */ |
175 |
|
char *line; |
176 |
|
{ |
177 |
+ |
char fmt[32]; |
178 |
+ |
|
179 |
|
if (isexpos(line)) |
180 |
|
exposure *= exposval(line); |
181 |
+ |
else if (isformat(line)) { |
182 |
+ |
formatval(fmt, line); |
183 |
+ |
wrong_fmt = strcmp(fmt, COLRFMT); |
184 |
+ |
} |
185 |
+ |
return(0); |
186 |
|
} |
187 |
|
|
188 |
|
|
327 |
|
break; |
328 |
|
case 'l': |
329 |
|
case 'L': |
330 |
< |
printf("%-3gL", bright(cval)*683.0/exposure); |
330 |
> |
printf("%-3gL", luminance(cval)/exposure); |
331 |
|
break; |
332 |
|
case 'c': |
333 |
|
case 'C': |
412 |
|
/* read scanline */ |
413 |
|
getscan(y); |
414 |
|
/* convert scanline */ |
415 |
< |
normcolrs(scanline, xmax); |
415 |
> |
normcolrs(scanline, xmax, 0); |
416 |
|
for (i = 0; i < xmax; i++) { |
417 |
|
l3[i].r = scanline[i][RED]; |
418 |
|
l3[i].g = scanline[i][GRN]; |
523 |
|
picreadcm(map) /* do gamma correction */ |
524 |
|
colormap map; |
525 |
|
{ |
514 |
– |
extern double pow(); |
526 |
|
register int i, val; |
527 |
|
|
528 |
|
for (i = 0; i < 256; i++) { |
529 |
< |
val = pow(i/256.0, 1.0/GAMMA) * 256.0; |
529 |
> |
val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0; |
530 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
531 |
|
} |
532 |
|
} |