1 |
< |
/* Copyright (c) 1993 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
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 |
+ |
|
81 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
82 |
|
int gotview = 0; /* got parameters from file */ |
83 |
|
|
116 |
|
|
117 |
|
char errmsg[128]; |
118 |
|
|
119 |
< |
extern BYTE clrtab[256][3]; /* global color map */ |
119 |
> |
BYTE clrtab[256][3]; /* global color map */ |
120 |
|
|
121 |
|
extern long ftell(); |
122 |
|
|
143 |
|
for (i = 1; i < argc; i++) |
144 |
|
if (argv[i][0] == '-') |
145 |
|
switch (argv[i][1]) { |
146 |
< |
case 'c': |
146 |
> |
case 'c': /* number of colors */ |
147 |
|
maxcolors = atoi(argv[++i]); |
148 |
|
break; |
149 |
< |
case 'b': |
149 |
> |
case 'b': /* greyscale only */ |
150 |
|
greyscale = !greyscale; |
151 |
|
break; |
152 |
< |
case 'm': |
152 |
> |
case 'm': /* monochrome */ |
153 |
> |
greyscale = 1; |
154 |
|
maxcolors = 2; |
155 |
|
break; |
156 |
< |
case 'd': |
156 |
> |
case 'd': /* display or dither */ |
157 |
|
if (argv[i][2] == 'i') |
158 |
|
dispname = argv[++i]; |
159 |
|
else |
160 |
|
dither = !dither; |
161 |
|
break; |
162 |
< |
case 'f': |
162 |
> |
case 'f': /* save pixmap */ |
163 |
|
fast = !fast; |
164 |
|
break; |
165 |
< |
case 'e': |
165 |
> |
case 's': /* one at a time */ |
166 |
> |
sequential = !sequential; |
167 |
> |
break; |
168 |
> |
case 'o': /* 't' output */ |
169 |
> |
tout = argv[i]+2; |
170 |
> |
break; |
171 |
> |
case 'e': /* exposure comp. */ |
172 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
173 |
|
goto userr; |
174 |
|
scale = atoi(argv[++i]); |
175 |
|
break; |
176 |
< |
case 'g': |
176 |
> |
case 'g': /* gamma comp. */ |
177 |
|
if (argv[i][2] == 'e') |
178 |
|
geometry = argv[++i]; |
179 |
|
else |
224 |
|
|
225 |
|
init(argc, argv); /* get file and open window */ |
226 |
|
|
217 |
– |
if (parent < 0) { |
218 |
– |
kill(getppid(), SIGCONT); /* signal parent if child */ |
219 |
– |
sigrecv--; |
220 |
– |
} |
227 |
|
for ( ; ; ) |
228 |
|
getevent(); /* main loop */ |
229 |
|
userr: |
230 |
|
fprintf(stderr, |
231 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor] pic ..\n", |
231 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor][-s] pic ..\n", |
232 |
|
progname); |
233 |
|
exit(1); |
234 |
|
} |
282 |
|
if (gamstr == NULL) /* get it from the X server */ |
283 |
|
gamstr = XGetDefault(thedisplay, "radiance", "gamma"); |
284 |
|
if (gamstr == NULL) /* get it from the environment */ |
285 |
< |
gamstr = getenv("GAMMA"); |
285 |
> |
gamstr = getenv("DISPLAY_GAMMA"); |
286 |
|
if (gamstr != NULL) |
287 |
|
gamcor = atof(gamstr); |
288 |
|
/* get best visual for default screen */ |
311 |
|
} |
312 |
|
} |
313 |
|
/* open window */ |
314 |
+ |
i = CWEventMask|CWCursor|CWBackPixel|CWBorderPixel; |
315 |
|
ourwinattr.border_pixel = ourwhite; |
316 |
|
ourwinattr.background_pixel = ourblack; |
317 |
< |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
318 |
< |
ourvis.visual, AllocNone); |
317 |
> |
if (ourvis.visual != DefaultVisual(thedisplay,ourscreen)) { |
318 |
> |
ourwinattr.colormap = newcmap(thedisplay, ourscreen, ourvis.visual); |
319 |
> |
i |= CWColormap; |
320 |
> |
} |
321 |
|
ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| |
322 |
|
ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; |
323 |
|
ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); |
324 |
|
wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, |
325 |
|
xszhints.width, xszhints.height, BORWIDTH, |
326 |
< |
ourvis.depth, InputOutput, ourvis.visual, CWEventMask| |
327 |
< |
CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
326 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
327 |
> |
i, &ourwinattr); |
328 |
|
if (wind == 0) |
329 |
|
quiterr("cannot create window"); |
330 |
|
width = xmax; |
362 |
|
XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); |
363 |
|
|
364 |
|
XMapWindow(thedisplay, wind); |
356 |
– |
return; |
365 |
|
} /* end of init */ |
366 |
|
|
367 |
|
|
570 |
|
map_rcolors(ourras, wind); |
571 |
|
if (fast) |
572 |
|
make_rpixmap(ourras, wind); |
573 |
+ |
if (!sequential & parent < 0 & sigrecv == 0) { |
574 |
+ |
kill(getppid(), SIGCONT); |
575 |
+ |
sigrecv--; |
576 |
+ |
} |
577 |
|
break; |
578 |
|
case UnmapNotify: |
579 |
|
if (!fast) |
600 |
|
} |
601 |
|
|
602 |
|
|
603 |
< |
traceray(xpos, ypos) /* print ray corresponding to pixel */ |
603 |
> |
traceray(xpos, ypos) /* print requested pixel data */ |
604 |
|
int xpos, ypos; |
605 |
|
{ |
606 |
+ |
extern char *index(); |
607 |
|
FLOAT hv[2]; |
608 |
|
FVECT rorg, rdir; |
609 |
+ |
COLOR cval; |
610 |
+ |
register char *cp; |
611 |
|
|
612 |
< |
if (!gotview) { /* no view, no can do */ |
613 |
< |
XBell(thedisplay, 0); |
614 |
< |
return(-1); |
615 |
< |
} |
612 |
> |
box.xmin = xpos; box.xsiz = 1; |
613 |
> |
box.ymin = ypos; box.ysiz = 1; |
614 |
> |
avgbox(cval); |
615 |
> |
scalecolor(cval, 1./exposure); |
616 |
|
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
617 |
< |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
618 |
< |
return(-1); |
619 |
< |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
620 |
< |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
617 |
> |
if (!gotview || viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
618 |
> |
rorg[0] = rorg[1] = rorg[2] = |
619 |
> |
rdir[0] = rdir[1] = rdir[2] = 0.; |
620 |
> |
|
621 |
> |
for (cp = tout; *cp; cp++) /* print what they asked for */ |
622 |
> |
switch (*cp) { |
623 |
> |
case 'o': /* origin */ |
624 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
625 |
> |
break; |
626 |
> |
case 'd': /* direction */ |
627 |
> |
printf("%e %e %e ", rdir[0], rdir[1], rdir[2]); |
628 |
> |
break; |
629 |
> |
case 'v': /* radiance value */ |
630 |
> |
printf("%e %e %e ", colval(cval,RED), |
631 |
> |
colval(cval,GRN), colval(cval,BLU)); |
632 |
> |
break; |
633 |
> |
case 'l': /* luminance */ |
634 |
> |
printf("%e ", luminance(cval)); |
635 |
> |
break; |
636 |
> |
case 'p': /* pixel position */ |
637 |
> |
printf("%d %d ", (int)(hv[0]*inpres.xr), |
638 |
> |
(int)(hv[1]*inpres.yr)); |
639 |
> |
break; |
640 |
> |
} |
641 |
> |
putchar('\n'); |
642 |
|
fflush(stdout); |
643 |
|
return(0); |
644 |
|
} |
1035 |
|
/* set gamma correction */ |
1036 |
|
setcolrgam(gamcor); |
1037 |
|
/* make histogram */ |
1038 |
< |
new_histo(); |
1038 |
> |
if (new_histo((long)xmax*ymax) == -1) |
1039 |
> |
quiterr("cannot initialize histogram"); |
1040 |
|
for (y = 0; y < ymax; y++) { |
1041 |
|
if (getscan(y) < 0) |
1042 |
|
break; |