| 1 |
< |
/* Copyright (c) 1993 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 56 |
|
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
| 57 |
|
|
| 58 |
|
double gamcor = 2.2; /* gamma correction */ |
| 59 |
+ |
char *gamstr = NULL; /* gamma value override */ |
| 60 |
|
|
| 61 |
|
int dither = 1; /* dither colors? */ |
| 62 |
|
int fast = 0; /* keep picture in Pixmap? */ |
| 74 |
|
int yoff = 0; /* y image offset */ |
| 75 |
|
|
| 76 |
|
int parent = 0; /* number of children, -1 if child */ |
| 77 |
+ |
int sequential = 0; /* display images in sequence */ |
| 78 |
|
|
| 79 |
+ |
char *tout = "od"; /* output of 't' command */ |
| 80 |
+ |
int tinterv = 0; /* interval between mouse reports */ |
| 81 |
+ |
|
| 82 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
| 83 |
|
int gotview = 0; /* got parameters from file */ |
| 84 |
|
|
| 117 |
|
|
| 118 |
|
char errmsg[128]; |
| 119 |
|
|
| 120 |
< |
extern BYTE clrtab[256][3]; /* global color map */ |
| 120 |
> |
BYTE clrtab[256][3]; /* global color map */ |
| 121 |
|
|
| 122 |
|
extern long ftell(); |
| 123 |
|
|
| 124 |
+ |
extern char *getenv(); |
| 125 |
+ |
|
| 126 |
|
Display *thedisplay; |
| 127 |
|
Atom closedownAtom, wmProtocolsAtom; |
| 128 |
|
|
| 135 |
|
int argc; |
| 136 |
|
char *argv[]; |
| 137 |
|
{ |
| 131 |
– |
extern char *getenv(); |
| 132 |
– |
char *gv; |
| 138 |
|
int headline(); |
| 139 |
|
int i; |
| 140 |
|
int pid; |
| 141 |
|
|
| 142 |
|
progname = argv[0]; |
| 138 |
– |
if ((gv = getenv("GAMMA")) != NULL) |
| 139 |
– |
gamcor = atof(gv); |
| 143 |
|
|
| 144 |
|
for (i = 1; i < argc; i++) |
| 145 |
|
if (argv[i][0] == '-') |
| 146 |
|
switch (argv[i][1]) { |
| 147 |
< |
case 'c': |
| 147 |
> |
case 'c': /* number of colors */ |
| 148 |
|
maxcolors = atoi(argv[++i]); |
| 149 |
|
break; |
| 150 |
< |
case 'b': |
| 150 |
> |
case 'b': /* greyscale only */ |
| 151 |
|
greyscale = !greyscale; |
| 152 |
|
break; |
| 153 |
< |
case 'm': |
| 153 |
> |
case 'm': /* monochrome */ |
| 154 |
> |
greyscale = 1; |
| 155 |
|
maxcolors = 2; |
| 156 |
|
break; |
| 157 |
< |
case 'd': |
| 157 |
> |
case 'd': /* display or dither */ |
| 158 |
|
if (argv[i][2] == 'i') |
| 159 |
|
dispname = argv[++i]; |
| 160 |
|
else |
| 161 |
|
dither = !dither; |
| 162 |
|
break; |
| 163 |
< |
case 'f': |
| 163 |
> |
case 'f': /* save pixmap */ |
| 164 |
|
fast = !fast; |
| 165 |
|
break; |
| 166 |
< |
case 'e': |
| 166 |
> |
case 's': /* one at a time */ |
| 167 |
> |
sequential = !sequential; |
| 168 |
> |
break; |
| 169 |
> |
case 'o': /* 't' output */ |
| 170 |
> |
tout = argv[i]+2; |
| 171 |
> |
break; |
| 172 |
> |
case 't': /* msec interval */ |
| 173 |
> |
tinterv = atoi(argv[++i]); |
| 174 |
> |
break; |
| 175 |
> |
case 'e': /* exposure comp. */ |
| 176 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
| 177 |
|
goto userr; |
| 178 |
|
scale = atoi(argv[++i]); |
| 179 |
|
break; |
| 180 |
< |
case 'g': |
| 180 |
> |
case 'g': /* gamma comp. */ |
| 181 |
|
if (argv[i][2] == 'e') |
| 182 |
|
geometry = argv[++i]; |
| 183 |
|
else |
| 184 |
< |
gamcor = atof(argv[++i]); |
| 184 |
> |
gamstr = argv[++i]; |
| 185 |
|
break; |
| 186 |
|
default: |
| 187 |
|
goto userr; |
| 228 |
|
|
| 229 |
|
init(argc, argv); /* get file and open window */ |
| 230 |
|
|
| 218 |
– |
if (parent < 0) { |
| 219 |
– |
kill(getppid(), SIGCONT); /* signal parent if child */ |
| 220 |
– |
sigrecv--; |
| 221 |
– |
} |
| 231 |
|
for ( ; ; ) |
| 232 |
|
getevent(); /* main loop */ |
| 233 |
|
userr: |
| 234 |
|
fprintf(stderr, |
| 235 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n", |
| 235 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor][-s][-ospec][-t intvl] pic ..\n", |
| 236 |
|
progname); |
| 237 |
|
exit(1); |
| 238 |
|
} |
| 282 |
|
name += i+1; |
| 283 |
|
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
| 284 |
|
quiterr("cannot open display"); |
| 285 |
+ |
/* set gamma value */ |
| 286 |
+ |
if (gamstr == NULL) /* get it from the X server */ |
| 287 |
+ |
gamstr = XGetDefault(thedisplay, "radiance", "gamma"); |
| 288 |
+ |
if (gamstr == NULL) /* get it from the environment */ |
| 289 |
+ |
gamstr = getenv("DISPLAY_GAMMA"); |
| 290 |
+ |
if (gamstr != NULL) |
| 291 |
+ |
gamcor = atof(gamstr); |
| 292 |
|
/* get best visual for default screen */ |
| 293 |
|
getbestvis(); |
| 294 |
|
/* store image */ |
| 315 |
|
} |
| 316 |
|
} |
| 317 |
|
/* open window */ |
| 318 |
+ |
i = CWEventMask|CWCursor|CWBackPixel|CWBorderPixel; |
| 319 |
|
ourwinattr.border_pixel = ourwhite; |
| 320 |
|
ourwinattr.background_pixel = ourblack; |
| 321 |
< |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
| 322 |
< |
ourvis.visual, AllocNone); |
| 321 |
> |
if (ourvis.visual != DefaultVisual(thedisplay,ourscreen)) { |
| 322 |
> |
ourwinattr.colormap = newcmap(thedisplay, ourscreen, ourvis.visual); |
| 323 |
> |
i |= CWColormap; |
| 324 |
> |
} |
| 325 |
|
ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| |
| 326 |
|
ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; |
| 327 |
|
ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); |
| 328 |
|
wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, |
| 329 |
|
xszhints.width, xszhints.height, BORWIDTH, |
| 330 |
< |
ourvis.depth, InputOutput, ourvis.visual, CWEventMask| |
| 331 |
< |
CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
| 330 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
| 331 |
> |
i, &ourwinattr); |
| 332 |
|
if (wind == 0) |
| 333 |
|
quiterr("cannot create window"); |
| 334 |
|
width = xmax; |
| 366 |
|
XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); |
| 367 |
|
|
| 368 |
|
XMapWindow(thedisplay, wind); |
| 350 |
– |
return; |
| 369 |
|
} /* end of init */ |
| 370 |
|
|
| 371 |
|
|
| 378 |
|
if (es = err != NULL) |
| 379 |
|
fprintf(stderr, "%s: %s: %s\n", progname, |
| 380 |
|
fname==NULL?"<stdin>":fname, err); |
| 381 |
< |
if (parent > 0 & wind != 0) { |
| 382 |
< |
XDestroyWindow(thedisplay, wind); |
| 383 |
< |
XFlush(thedisplay); |
| 366 |
< |
} else if (parent < 0 & sigrecv == 0) |
| 381 |
> |
if (thedisplay != NULL) |
| 382 |
> |
XCloseDisplay(thedisplay); |
| 383 |
> |
if (parent < 0 & sigrecv == 0) |
| 384 |
|
kill(getppid(), SIGCONT); |
| 385 |
|
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
| 386 |
|
if (es == 0) |
| 574 |
|
map_rcolors(ourras, wind); |
| 575 |
|
if (fast) |
| 576 |
|
make_rpixmap(ourras, wind); |
| 577 |
+ |
if (!sequential & parent < 0 & sigrecv == 0) { |
| 578 |
+ |
kill(getppid(), SIGCONT); |
| 579 |
+ |
sigrecv--; |
| 580 |
+ |
} |
| 581 |
|
break; |
| 582 |
|
case UnmapNotify: |
| 583 |
|
if (!fast) |
| 590 |
|
case ButtonPress: |
| 591 |
|
if (xev.xbutton.state & (ShiftMask|ControlMask)) |
| 592 |
|
moveimage(&xev.xbutton); |
| 572 |
– |
else if (xev.xbutton.button == Button2) |
| 573 |
– |
traceray(xev.xbutton.x, xev.xbutton.y); |
| 593 |
|
else |
| 594 |
< |
getbox(&xev.xbutton); |
| 594 |
> |
switch (xev.xbutton.button) { |
| 595 |
> |
case Button1: |
| 596 |
> |
getbox(&xev.xbutton); |
| 597 |
> |
break; |
| 598 |
> |
case Button2: |
| 599 |
> |
traceray(xev.xbutton.x, xev.xbutton.y); |
| 600 |
> |
break; |
| 601 |
> |
case Button3: |
| 602 |
> |
trackrays(&xev.xbutton); |
| 603 |
> |
break; |
| 604 |
> |
} |
| 605 |
|
break; |
| 606 |
|
case ClientMessage: |
| 607 |
|
if ((xev.xclient.message_type == wmProtocolsAtom) && |
| 612 |
|
} |
| 613 |
|
|
| 614 |
|
|
| 615 |
< |
traceray(xpos, ypos) /* print ray corresponding to pixel */ |
| 615 |
> |
traceray(xpos, ypos) /* print requested pixel data */ |
| 616 |
|
int xpos, ypos; |
| 617 |
|
{ |
| 618 |
+ |
extern char *index(); |
| 619 |
|
FLOAT hv[2]; |
| 620 |
|
FVECT rorg, rdir; |
| 621 |
+ |
COLOR cval; |
| 622 |
+ |
register char *cp; |
| 623 |
|
|
| 624 |
< |
if (!gotview) { /* no view, no can do */ |
| 625 |
< |
XBell(thedisplay, 0); |
| 626 |
< |
return(-1); |
| 627 |
< |
} |
| 624 |
> |
box.xmin = xpos; box.xsiz = 1; |
| 625 |
> |
box.ymin = ypos; box.ysiz = 1; |
| 626 |
> |
avgbox(cval); |
| 627 |
> |
scalecolor(cval, 1./exposure); |
| 628 |
|
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
| 629 |
< |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
| 630 |
< |
return(-1); |
| 631 |
< |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
| 632 |
< |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
| 629 |
> |
if (!gotview || viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
| 630 |
> |
rorg[0] = rorg[1] = rorg[2] = |
| 631 |
> |
rdir[0] = rdir[1] = rdir[2] = 0.; |
| 632 |
> |
|
| 633 |
> |
for (cp = tout; *cp; cp++) /* print what they asked for */ |
| 634 |
> |
switch (*cp) { |
| 635 |
> |
case 'o': /* origin */ |
| 636 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
| 637 |
> |
break; |
| 638 |
> |
case 'd': /* direction */ |
| 639 |
> |
printf("%e %e %e ", rdir[0], rdir[1], rdir[2]); |
| 640 |
> |
break; |
| 641 |
> |
case 'v': /* radiance value */ |
| 642 |
> |
printf("%e %e %e ", colval(cval,RED), |
| 643 |
> |
colval(cval,GRN), colval(cval,BLU)); |
| 644 |
> |
break; |
| 645 |
> |
case 'l': /* luminance */ |
| 646 |
> |
printf("%e ", luminance(cval)); |
| 647 |
> |
break; |
| 648 |
> |
case 'p': /* pixel position */ |
| 649 |
> |
printf("%d %d ", (int)(hv[0]*inpres.xr), |
| 650 |
> |
(int)(hv[1]*inpres.yr)); |
| 651 |
> |
break; |
| 652 |
> |
} |
| 653 |
> |
putchar('\n'); |
| 654 |
|
fflush(stdout); |
| 655 |
|
return(0); |
| 656 |
|
} |
| 836 |
|
} |
| 837 |
|
|
| 838 |
|
|
| 839 |
+ |
trackrays(ebut) /* trace rays as mouse moves */ |
| 840 |
+ |
XButtonPressedEvent *ebut; |
| 841 |
+ |
{ |
| 842 |
+ |
XEvent e; |
| 843 |
+ |
unsigned long lastrept; |
| 844 |
+ |
|
| 845 |
+ |
traceray(ebut->x, ebut->y); |
| 846 |
+ |
lastrept = ebut->time; |
| 847 |
+ |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
| 848 |
+ |
while (e.type == MotionNotify) { |
| 849 |
+ |
if (e.xmotion.time >= lastrept + tinterv) { |
| 850 |
+ |
traceray(e.xmotion.x, e.xmotion.y); |
| 851 |
+ |
lastrept = e.xmotion.time; |
| 852 |
+ |
} |
| 853 |
+ |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
| 854 |
+ |
} |
| 855 |
+ |
} |
| 856 |
+ |
|
| 857 |
+ |
|
| 858 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
| 859 |
|
int x0, y0, x1, y1; |
| 860 |
|
{ |
| 1014 |
|
colrs_gambs(scanline, xmax); |
| 1015 |
|
if (ourras->image->blue_mask & 1) |
| 1016 |
|
for (x = 0; x < xmax; x++) |
| 1017 |
< |
*dp++ = scanline[x][RED] << 16 | |
| 1018 |
< |
scanline[x][GRN] << 8 | |
| 1019 |
< |
scanline[x][BLU] ; |
| 1017 |
> |
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
| 1018 |
> |
(unsigned int4)scanline[x][GRN] << 8 | |
| 1019 |
> |
(unsigned int4)scanline[x][BLU] ; |
| 1020 |
|
else |
| 1021 |
|
for (x = 0; x < xmax; x++) |
| 1022 |
< |
*dp++ = scanline[x][RED] | |
| 1023 |
< |
scanline[x][GRN] << 8 | |
| 1024 |
< |
scanline[x][BLU] << 16 ; |
| 1022 |
> |
*dp++ = (unsigned int4)scanline[x][RED] | |
| 1023 |
> |
(unsigned int4)scanline[x][GRN] << 8 | |
| 1024 |
> |
(unsigned int4)scanline[x][BLU] << 16 ; |
| 1025 |
|
} |
| 1026 |
|
} |
| 1027 |
|
|
| 1066 |
|
/* set gamma correction */ |
| 1067 |
|
setcolrgam(gamcor); |
| 1068 |
|
/* make histogram */ |
| 1069 |
< |
new_histo(); |
| 1069 |
> |
if (new_histo((long)xmax*ymax) == -1) |
| 1070 |
> |
quiterr("cannot initialize histogram"); |
| 1071 |
|
for (y = 0; y < ymax; y++) { |
| 1072 |
|
if (getscan(y) < 0) |
| 1073 |
|
break; |