| 29 |
|
|
| 30 |
|
#include "pic.h" |
| 31 |
|
|
| 32 |
+ |
#include "random.h" |
| 33 |
+ |
|
| 34 |
|
#define controlshift(e) (((XButtonEvent *)(e))->detail & (ShiftMask|ControlMask)) |
| 35 |
|
|
| 36 |
|
#define FONTNAME "9x15" /* text font we'll use */ |
| 40 |
|
#define BORWIDTH 5 /* border width */ |
| 41 |
|
#define BARHEIGHT 25 /* menu bar size */ |
| 42 |
|
|
| 43 |
< |
double gamcor = 2.0; /* gamma correction */ |
| 43 |
> |
double gamcor = 2.2; /* gamma correction */ |
| 44 |
|
|
| 45 |
|
XRASTER *ourras = NULL; /* our stored raster image */ |
| 46 |
|
|
| 139 |
|
sprintf(errmsg, "can't open file \"%s\"", fname); |
| 140 |
|
quiterr(errmsg); |
| 141 |
|
} |
| 142 |
< |
} else |
| 141 |
< |
goto userr; |
| 142 |
< |
|
| 142 |
> |
} |
| 143 |
|
/* get header */ |
| 144 |
|
getheader(fin, headline); |
| 145 |
|
/* get picture dimensions */ |
| 146 |
< |
if (fscanf(fin, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
| 146 |
> |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
| 147 |
|
quiterr("bad picture size"); |
| 148 |
|
/* set view parameters */ |
| 149 |
|
if (gotview) { |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
– |
char * |
| 189 |
– |
sskip(s) /* skip a word */ |
| 190 |
– |
register char *s; |
| 191 |
– |
{ |
| 192 |
– |
while (isspace(*s)) s++; |
| 193 |
– |
while (*s && !isspace(*s)) s++; |
| 194 |
– |
return(s); |
| 195 |
– |
} |
| 196 |
– |
|
| 197 |
– |
|
| 188 |
|
init() /* get data and open window */ |
| 189 |
|
{ |
| 190 |
|
register int i; |
| 337 |
|
int x, y; |
| 338 |
|
int w, h; |
| 339 |
|
{ |
| 340 |
< |
if (map_rcolors(ourras) == NULL) { |
| 340 |
> |
if (ourras->ncolors && map_rcolors(ourras) == NULL) { |
| 341 |
|
fprintf(stderr, "%s: cannot allocate colors\n", progname); |
| 342 |
|
return(-1); |
| 343 |
|
} |
| 352 |
|
{ |
| 353 |
|
char buf[80]; |
| 354 |
|
COLOR cval; |
| 355 |
+ |
Color cvx; |
| 356 |
|
char *cp; |
| 357 |
|
int n; |
| 358 |
|
double comp; |
| 363 |
|
return(0); |
| 364 |
|
switch (*cp) { /* interpret command */ |
| 365 |
|
case 'q': |
| 366 |
< |
case CTRL(D): /* quiterr */ |
| 366 |
> |
case CTRL(D): /* quit */ |
| 367 |
|
quit(0); |
| 368 |
|
case '\n': |
| 369 |
|
case '\r': |
| 374 |
|
switch (*cp) { |
| 375 |
|
case '\n': |
| 376 |
|
case '\r': /* radiance */ |
| 377 |
< |
sprintf(buf, "%-3g", intens(cval)/exposure); |
| 377 |
> |
sprintf(buf, "%.3f", intens(cval)/exposure); |
| 378 |
|
break; |
| 379 |
|
case 'l': /* luminance */ |
| 380 |
< |
sprintf(buf, "%-3gL", bright(cval)*683.0/exposure); |
| 380 |
> |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
| 381 |
|
break; |
| 382 |
|
case 'c': /* color */ |
| 383 |
|
comp = pow(2.0, (double)scale); |
| 390 |
|
XText(wind, box.xmin, box.ymin, buf, strlen(buf), |
| 391 |
|
fontid, BlackPixel, WhitePixel); |
| 392 |
|
return(0); |
| 393 |
+ |
case 'i': /* identify (contour) */ |
| 394 |
+ |
if (ourras->pixels == NULL) |
| 395 |
+ |
return(-1); |
| 396 |
+ |
n = ourras->data.bz[ekey->x-xoff+BZPixmapSize(xmax,ekey->y-yoff)]; |
| 397 |
+ |
n = ourras->pmap[n]; |
| 398 |
+ |
cvx.pixel = ourras->cdefs[n].pixel; |
| 399 |
+ |
cvx.red = random() & 65535; |
| 400 |
+ |
cvx.green = random() & 65535; |
| 401 |
+ |
cvx.blue = random() & 65535; |
| 402 |
+ |
XStoreColor(&cvx); |
| 403 |
+ |
return(0); |
| 404 |
|
case 'p': /* position */ |
| 405 |
|
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
| 406 |
|
XText(wind, ekey->x, ekey->y, buf, strlen(buf), |
| 421 |
|
if (avgbox(cval) == -1) |
| 422 |
|
return(-1); |
| 423 |
|
n = log(.5/bright(cval))/.69315 - scale; /* truncate */ |
| 424 |
< |
if (n == 0) { |
| 423 |
< |
XFeep(0); |
| 424 |
> |
if (n == 0) |
| 425 |
|
return(0); |
| 425 |
– |
} |
| 426 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
| 427 |
|
scale += n; |
| 428 |
|
sprintf(buf, "%+d", scale); |
| 433 |
|
getras(); |
| 434 |
|
/* fall through */ |
| 435 |
|
case CTRL(R): /* redraw */ |
| 436 |
+ |
case CTRL(L): |
| 437 |
+ |
unmap_rcolors(ourras); |
| 438 |
|
XClear(wind); |
| 439 |
|
return(redraw(0, 0, width, height)); |
| 440 |
|
case ' ': /* clear */ |
| 608 |
|
double sf; |
| 609 |
|
{ |
| 610 |
|
register int i; |
| 611 |
< |
int maxv; |
| 611 |
> |
long maxv; |
| 612 |
|
|
| 613 |
+ |
if (xr->pixels == NULL) |
| 614 |
+ |
return; |
| 615 |
+ |
|
| 616 |
|
sf = pow(sf, 1.0/gamcor); |
| 617 |
< |
maxv = (1<<16) / sf; |
| 617 |
> |
maxv = 65535/sf; |
| 618 |
|
|
| 619 |
|
for (i = xr->ncolors; i--; ) { |
| 620 |
< |
xr->cdefs[i].red = xr->cdefs[i].red >= maxv ? |
| 621 |
< |
(1<<16)-1 : |
| 620 |
> |
xr->cdefs[i].red = xr->cdefs[i].red > maxv ? |
| 621 |
> |
65535 : |
| 622 |
|
xr->cdefs[i].red * sf; |
| 623 |
< |
xr->cdefs[i].green = xr->cdefs[i].green >= maxv ? |
| 624 |
< |
(1<<16)-1 : |
| 623 |
> |
xr->cdefs[i].green = xr->cdefs[i].green > maxv ? |
| 624 |
> |
65535 : |
| 625 |
|
xr->cdefs[i].green * sf; |
| 626 |
< |
xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ? |
| 627 |
< |
(1<<16)-1 : |
| 626 |
> |
xr->cdefs[i].blue = xr->cdefs[i].blue > maxv ? |
| 627 |
> |
65535 : |
| 628 |
|
xr->cdefs[i].blue * sf; |
| 629 |
|
} |
| 630 |
< |
if (xr->pixels != NULL) |
| 626 |
< |
XStoreColors(xr->ncolors, xr->cdefs); |
| 630 |
> |
XStoreColors(xr->ncolors, xr->cdefs); |
| 631 |
|
} |
| 632 |
|
|
| 633 |
|
|
| 655 |
|
int y; |
| 656 |
|
register rgbpixel *l3; |
| 657 |
|
{ |
| 658 |
< |
register BYTE *l4; |
| 659 |
< |
register int shift, c; |
| 656 |
< |
int i; |
| 657 |
< |
|
| 658 |
> |
register int i; |
| 659 |
> |
/* read scanline */ |
| 660 |
|
if (getscan(y) < 0) |
| 661 |
|
quiterr("cannot seek for picreadline"); |
| 662 |
|
/* convert scanline */ |
| 663 |
< |
for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { |
| 664 |
< |
shift = l4[EXP] - COLXS + scale; |
| 665 |
< |
if (shift >= 8) { |
| 666 |
< |
l3->r = l3->g = l3->b = 255; |
| 667 |
< |
} else if (shift <= -8) { |
| 668 |
< |
l3->r = l3->g = l3->b = 0; |
| 669 |
< |
} else if (shift > 0) { |
| 670 |
< |
c = l4[RED] << shift; |
| 671 |
< |
l3->r = c > 255 ? 255 : c; |
| 670 |
< |
c = l4[GRN] << shift; |
| 671 |
< |
l3->g = c > 255 ? 255 : c; |
| 672 |
< |
c = l4[BLU] << shift; |
| 673 |
< |
l3->b = c > 255 ? 255 : c; |
| 674 |
< |
} else if (shift < 0) { |
| 675 |
< |
l3->r = l4[RED] >> -shift; |
| 676 |
< |
l3->g = l4[GRN] >> -shift; |
| 677 |
< |
l3->b = l4[BLU] >> -shift; |
| 678 |
< |
} else { |
| 679 |
< |
l3->r = l4[RED]; |
| 680 |
< |
l3->g = l4[GRN]; |
| 681 |
< |
l3->b = l4[BLU]; |
| 682 |
< |
} |
| 663 |
> |
if (scale) |
| 664 |
> |
for (i = 0; i < xmax; i++) |
| 665 |
> |
if (scanline[i][EXP]) |
| 666 |
> |
scanline[i][EXP] += scale; |
| 667 |
> |
normcolrs(scanline, xmax); |
| 668 |
> |
for (i = 0; i < xmax; i++) { |
| 669 |
> |
l3[i].r = scanline[i][RED]; |
| 670 |
> |
l3[i].g = scanline[i][GRN]; |
| 671 |
> |
l3[i].b = scanline[i][BLU]; |
| 672 |
|
} |
| 673 |
|
} |
| 674 |
|
|
| 681 |
|
} |
| 682 |
|
|
| 683 |
|
|
| 684 |
< |
picreadcm(map) /* do gamcor correction */ |
| 684 |
> |
picreadcm(map) /* do gamma correction */ |
| 685 |
|
colormap map; |
| 686 |
|
{ |
| 687 |
|
extern double pow(); |