ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/x11image.c
(Generate patch)

Comparing ray/src/px/x11image.c (file contents):
Revision 2.38 by greg, Tue Sep 20 15:48:15 1994 UTC vs.
Revision 2.43 by greg, Mon Jan 27 15:07:03 1997 UTC

# Line 1 | Line 1
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";
# Line 74 | Line 74 | int  xoff = 0;                         /* x image offset */
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  
# Line 140 | Line 144 | char  *argv[];
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
# Line 214 | Line 228 | char  *argv[];
228  
229          init(argc, argv);                       /* get file and open window */
230  
217        if (parent < 0) {
218                kill(getppid(), SIGCONT);       /* signal parent if child */
219                sigrecv--;
220        }
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][-g gamcor] 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   }
# Line 305 | Line 315 | char **argv;
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;
# Line 353 | Line 366 | char **argv;
366          XSetWMProtocols(thedisplay, wind, &closedownAtom, 1);
367  
368          XMapWindow(thedisplay, wind);
356        return;
369   } /* end of init */
370  
371  
# Line 562 | Line 574 | getevent()                             /* process the next event */
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)
# Line 574 | Line 590 | getevent()                             /* process the next event */
590          case ButtonPress:
591                  if (xev.xbutton.state & (ShiftMask|ControlMask))
592                          moveimage(&xev.xbutton);
577                else if (xev.xbutton.button == Button2)
578                        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) &&
# Line 588 | Line 612 | getevent()                             /* process the next event */
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   }
# Line 784 | Line 832 | XButtonPressedEvent  *ebut;
832                  box.ymin = ebut->y;
833          } else {
834                  box.ysiz = ebut->y - box.ymin + 1;
835 +        }
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines