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 |
|
|
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) { |
362 |
|
{ |
363 |
|
char buf[80]; |
364 |
|
COLOR cval; |
365 |
+ |
Color cvx; |
366 |
|
char *cp; |
367 |
|
int n; |
368 |
|
double comp; |
373 |
|
return(0); |
374 |
|
switch (*cp) { /* interpret command */ |
375 |
|
case 'q': |
376 |
< |
case CTRL(D): /* quiterr */ |
376 |
> |
case CTRL(D): /* quit */ |
377 |
|
quit(0); |
378 |
|
case '\n': |
379 |
|
case '\r': |
387 |
|
sprintf(buf, "%-3g", intens(cval)/exposure); |
388 |
|
break; |
389 |
|
case 'l': /* luminance */ |
390 |
< |
sprintf(buf, "%-3gL", bright(cval)*683.0/exposure); |
390 |
> |
sprintf(buf, "%-3gn", bright(cval)*683.0/exposure); |
391 |
|
break; |
392 |
|
case 'c': /* color */ |
393 |
|
comp = pow(2.0, (double)scale); |
400 |
|
XText(wind, box.xmin, box.ymin, buf, strlen(buf), |
401 |
|
fontid, BlackPixel, WhitePixel); |
402 |
|
return(0); |
403 |
+ |
case 'i': /* identify (contour) */ |
404 |
+ |
if (ourras->pixels == NULL) |
405 |
+ |
return(-1); |
406 |
+ |
n = ourras->data.bz[ekey->x-xoff+BZPixmapSize(xmax,ekey->y-yoff)]; |
407 |
+ |
n = ourras->pmap[n]; |
408 |
+ |
cvx.pixel = ourras->cdefs[n].pixel; |
409 |
+ |
cvx.red = random() & 65535; |
410 |
+ |
cvx.green = random() & 65535; |
411 |
+ |
cvx.blue = random() & 65535; |
412 |
+ |
XStoreColor(&cvx); |
413 |
+ |
return(0); |
414 |
|
case 'p': /* position */ |
415 |
|
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
416 |
|
XText(wind, ekey->x, ekey->y, buf, strlen(buf), |
444 |
|
/* fall through */ |
445 |
|
case CTRL(R): /* redraw */ |
446 |
|
case CTRL(L): |
447 |
+ |
unmap_rcolors(ourras); |
448 |
|
XClear(wind); |
449 |
|
return(redraw(0, 0, width, height)); |
450 |
|
case ' ': /* clear */ |
618 |
|
double sf; |
619 |
|
{ |
620 |
|
register int i; |
621 |
< |
int maxv; |
621 |
> |
long maxv; |
622 |
|
|
623 |
+ |
if (xr->pixels == NULL) |
624 |
+ |
return; |
625 |
+ |
|
626 |
|
sf = pow(sf, 1.0/gamcor); |
627 |
< |
maxv = (1<<16) / sf; |
627 |
> |
maxv = 65535/sf; |
628 |
|
|
629 |
|
for (i = xr->ncolors; i--; ) { |
630 |
< |
xr->cdefs[i].red = xr->cdefs[i].red >= maxv ? |
631 |
< |
(1<<16)-1 : |
630 |
> |
xr->cdefs[i].red = xr->cdefs[i].red > maxv ? |
631 |
> |
65535 : |
632 |
|
xr->cdefs[i].red * sf; |
633 |
< |
xr->cdefs[i].green = xr->cdefs[i].green >= maxv ? |
634 |
< |
(1<<16)-1 : |
633 |
> |
xr->cdefs[i].green = xr->cdefs[i].green > maxv ? |
634 |
> |
65535 : |
635 |
|
xr->cdefs[i].green * sf; |
636 |
< |
xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ? |
637 |
< |
(1<<16)-1 : |
636 |
> |
xr->cdefs[i].blue = xr->cdefs[i].blue > maxv ? |
637 |
> |
65535 : |
638 |
|
xr->cdefs[i].blue * sf; |
639 |
|
} |
640 |
< |
if (xr->pixels != NULL) |
623 |
< |
XStoreColors(xr->ncolors, xr->cdefs); |
640 |
> |
XStoreColors(xr->ncolors, xr->cdefs); |
641 |
|
} |
642 |
|
|
643 |
|
|
665 |
|
int y; |
666 |
|
register rgbpixel *l3; |
667 |
|
{ |
668 |
< |
register BYTE *l4; |
669 |
< |
register int shift, c; |
653 |
< |
int i; |
654 |
< |
|
668 |
> |
register int i; |
669 |
> |
/* read scanline */ |
670 |
|
if (getscan(y) < 0) |
671 |
|
quiterr("cannot seek for picreadline"); |
672 |
|
/* convert scanline */ |
673 |
< |
for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { |
674 |
< |
shift = l4[EXP] - COLXS + scale; |
675 |
< |
if (shift >= 8) { |
676 |
< |
l3->r = l3->g = l3->b = 255; |
677 |
< |
} else if (shift <= -8) { |
678 |
< |
l3->r = l3->g = l3->b = 0; |
679 |
< |
} else if (shift > 0) { |
680 |
< |
c = l4[RED] << shift; |
681 |
< |
l3->r = c > 255 ? 255 : c; |
667 |
< |
c = l4[GRN] << shift; |
668 |
< |
l3->g = c > 255 ? 255 : c; |
669 |
< |
c = l4[BLU] << shift; |
670 |
< |
l3->b = c > 255 ? 255 : c; |
671 |
< |
} else if (shift < 0) { |
672 |
< |
l3->r = l4[RED] >> -shift; |
673 |
< |
l3->g = l4[GRN] >> -shift; |
674 |
< |
l3->b = l4[BLU] >> -shift; |
675 |
< |
} else { |
676 |
< |
l3->r = l4[RED]; |
677 |
< |
l3->g = l4[GRN]; |
678 |
< |
l3->b = l4[BLU]; |
679 |
< |
} |
673 |
> |
if (scale != 0) |
674 |
> |
for (i = 0; i < xmax; i++) |
675 |
> |
if (scanline[i][EXP]+scale >= 0) |
676 |
> |
scanline[i][EXP] += scale; |
677 |
> |
normcolrs(scanline, xmax); |
678 |
> |
for (i = 0; i < xmax; i++) { |
679 |
> |
l3[i].r = scanline[i][RED]; |
680 |
> |
l3[i].g = scanline[i][GRN]; |
681 |
> |
l3[i].b = scanline[i][BLU]; |
682 |
|
} |
683 |
|
} |
684 |
|
|
691 |
|
} |
692 |
|
|
693 |
|
|
694 |
< |
picreadcm(map) /* do gamcor correction */ |
694 |
> |
picreadcm(map) /* do gamma correction */ |
695 |
|
colormap map; |
696 |
|
{ |
697 |
|
extern double pow(); |