| 97 |
|
extern long ftell(); |
| 98 |
|
long scanpos[NROWS]; |
| 99 |
|
|
| 100 |
– |
extern double atof(); |
| 100 |
|
double exposure = 1.0; |
| 101 |
+ |
int wrong_fmt = 0; |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
main(argc, argv) |
| 105 |
|
int argc; |
| 106 |
|
char *argv[]; |
| 107 |
|
{ |
| 108 |
< |
int onintr(); |
| 109 |
< |
double atof(); |
| 108 |
> |
int onintr(), checkhead(); |
| 109 |
|
char sbuf[256]; |
| 110 |
|
register int i; |
| 111 |
|
|
| 140 |
|
quitmsg(errmsg); |
| 141 |
|
} |
| 142 |
|
/* get header */ |
| 143 |
< |
while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n') |
| 144 |
< |
if (!strncmp(sbuf, "EXPOSURE=", 9)) |
| 145 |
< |
exposure *= atof(sbuf+9); |
| 147 |
< |
|
| 143 |
> |
getheader(fin, checkhead, NULL); |
| 144 |
> |
if (wrong_fmt) |
| 145 |
> |
quitmsg("input must be a Radiance picture"); |
| 146 |
|
/* get picture dimensions */ |
| 147 |
< |
if (fgets(sbuf, sizeof(sbuf), fin) == NULL || |
| 150 |
< |
sscanf(sbuf, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
| 147 |
> |
if (fgetresolu(&xmax, &ymax, fin) < 0) |
| 148 |
|
quitmsg("bad picture size"); |
| 149 |
|
if (xmax > NCOLS || ymax > NROWS) |
| 150 |
|
quitmsg("resolution mismatch"); |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
+ |
checkhead(line) /* deal with line from header */ |
| 172 |
+ |
char *line; |
| 173 |
+ |
{ |
| 174 |
+ |
char fmt[32]; |
| 175 |
+ |
|
| 176 |
+ |
if (isexpos(line)) |
| 177 |
+ |
exposure *= exposval(line); |
| 178 |
+ |
else if (isformat(line)) { |
| 179 |
+ |
formatval(fmt, line); |
| 180 |
+ |
wrong_fmt = strcmp(fmt, COLRFMT); |
| 181 |
+ |
} |
| 182 |
+ |
} |
| 183 |
+ |
|
| 184 |
+ |
|
| 185 |
|
init() /* initialize terminal */ |
| 186 |
|
{ |
| 187 |
|
struct sgttyb flags; |
| 323 |
|
break; |
| 324 |
|
case 'l': |
| 325 |
|
case 'L': |
| 326 |
< |
printf("%-3gL", bright(cval)*683.0/exposure); |
| 326 |
> |
printf("%-3gL", luminance(cval)/exposure); |
| 327 |
|
break; |
| 328 |
|
case 'c': |
| 329 |
|
case 'C': |
| 404 |
|
int y; |
| 405 |
|
register rgbpixel *l3; |
| 406 |
|
{ |
| 407 |
< |
register BYTE *l4; |
| 408 |
< |
register int shift, c; |
| 398 |
< |
int i; |
| 399 |
< |
|
| 407 |
> |
register int i; |
| 408 |
> |
/* read scanline */ |
| 409 |
|
getscan(y); |
| 410 |
|
/* convert scanline */ |
| 411 |
< |
for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { |
| 412 |
< |
shift = l4[EXP] - COLXS; |
| 413 |
< |
if (shift >= 8) { |
| 414 |
< |
l3->r = l3->g = l3->b = 255; |
| 415 |
< |
} else if (shift <= -8) { |
| 407 |
< |
l3->r = l3->g = l3->b = 0; |
| 408 |
< |
} else if (shift > 0) { |
| 409 |
< |
c = l4[RED] << shift; |
| 410 |
< |
l3->r = c > 255 ? 255 : c; |
| 411 |
< |
c = l4[GRN] << shift; |
| 412 |
< |
l3->g = c > 255 ? 255 : c; |
| 413 |
< |
c = l4[BLU] << shift; |
| 414 |
< |
l3->b = c > 255 ? 255 : c; |
| 415 |
< |
} else if (shift < 0) { |
| 416 |
< |
l3->r = l4[RED] >> -shift; |
| 417 |
< |
l3->g = l4[GRN] >> -shift; |
| 418 |
< |
l3->b = l4[BLU] >> -shift; |
| 419 |
< |
} else { |
| 420 |
< |
l3->r = l4[RED]; |
| 421 |
< |
l3->g = l4[GRN]; |
| 422 |
< |
l3->b = l4[BLU]; |
| 423 |
< |
} |
| 411 |
> |
normcolrs(scanline, xmax, 0); |
| 412 |
> |
for (i = 0; i < xmax; i++) { |
| 413 |
> |
l3[i].r = scanline[i][RED]; |
| 414 |
> |
l3[i].g = scanline[i][GRN]; |
| 415 |
> |
l3[i].b = scanline[i][BLU]; |
| 416 |
|
} |
| 417 |
|
} |
| 418 |
|
|
| 523 |
|
register int i, val; |
| 524 |
|
|
| 525 |
|
for (i = 0; i < 256; i++) { |
| 526 |
< |
val = pow(i/256.0, 1.0/GAMMA) * 256.0; |
| 526 |
> |
val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0; |
| 527 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
| 528 |
|
} |
| 529 |
|
} |