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 1.3 by greg, Fri Mar 2 12:22:37 1990 UTC vs.
Revision 1.7 by greg, Thu Aug 30 11:21:34 1990 UTC

# Line 43 | Line 43 | static char SCCSid[] = "$SunId$ LBL";
43   #define  ourroot        RootWindow(thedisplay,ourscreen)
44   #define  ourgc          DefaultGC(thedisplay,ourscreen)
45  
46 + #define  revline(x0,y0,x1,y1)   XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1)
47 +
48   #define  redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras)
49  
50   double  gamcor = 2.2;                   /* gamma correction */
# Line 75 | Line 77 | int  cury = 0;                         /* current scan location */
77  
78   double  exposure = 1.0;                 /* exposure compensation used */
79  
80 + GC      revgc;                          /* graphics context with GXinvert */
81 +
82   XRASTER *ourras;                        /* our stored image */
83   unsigned char   *ourdata;               /* our image data */
84  
# Line 194 | Line 198 | char  *s;
198  
199   init()                  /* get data and open window */
200   {
201 +        XSetWindowAttributes    ourwinattr;
202          XSizeHints  oursizhints;
203          register int  i;
204          
# Line 206 | Line 211 | init()                 /* get data and open window */
211          }
212          if ((thedisplay = XOpenDisplay(NULL)) == NULL)
213                  quiterr("can't open display; DISPLAY variable set?");
209        wind = XCreateSimpleWindow(thedisplay,
210                ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite);
211        if (wind == 0)
212                quiterr("can't create window");
214          if (maxcolors == 0) {           /* get number of available colors */
215                  i = DisplayPlanes(thedisplay,ourscreen);
216                  maxcolors = i > 8 ? 256 : 1<<i;
217                  if (maxcolors > 4) maxcolors -= 2;
218          }
219 +                                /* store image */
220 +        getras();
221 +                                /* open window */
222 +        ourwinattr.border_pixel = ourblack;
223 +        ourwinattr.background_pixel = ourwhite;
224 +        wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH,
225 +                        0, InputOutput, ourras->visual,
226 +                        CWBackPixel|CWBorderPixel, &ourwinattr);
227 +        if (wind == 0)
228 +                quiterr("can't create window");
229 +        width = xmax;
230 +        height = ymax;
231          fontid = XLoadFont(thedisplay, FONTNAME);
232          if (fontid == 0)
233                  quiterr("can't get font");
234          XSetFont(thedisplay, ourgc, fontid);
235 +        revgc = XCreateGC(thedisplay, wind, 0, 0);
236 +        XSetFunction(thedisplay, revgc, GXinvert);
237          XStoreName(thedisplay, wind, fname == NULL ? progname : fname);
238          XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay,
239                          XC_diamond_cross));
# Line 244 | Line 259 | init()                 /* get data and open window */
259                  }
260                  XSetNormalHints(thedisplay, wind, &oursizhints);
261          }
247                                /* store image */
248        getras();
262          XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask
263                          |ButtonMotionMask|StructureNotifyMask
264                          |KeyPressMask|ExposureMask);
# Line 295 | Line 308 | getras()                               /* get raster file */
308                  if (ourras == NULL)
309                          goto fail;
310                  getmono();
311 <        } else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) {
311 >        } else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)
312 >                                                /* kludge for DirectColor */
313 >        || XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) {
314                  ourdata = (unsigned char *)malloc(xmax*ymax*3);
315                  if (ourdata == NULL)
316                          goto fail;
# Line 480 | Line 495 | XButtonPressedEvent  *ebut;
495                  XButtonReleasedEvent  b;
496                  XPointerMovedEvent  m;
497          }  e;
498 <        int     nxo, nyo;
498 >        int     mxo, myo;
499  
500          XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u);
501          while (e.u.type == MotionNotify) {
502 <                nxo = xoff + e.m.x - ebut->x;
503 <                nyo = yoff + e.m.y - ebut->y;
504 <                revbox(nxo, nyo, nxo+xmax, nyo+ymax);
502 >                mxo = e.m.x;
503 >                myo = e.m.y;
504 >                revline(ebut->x, ebut->y, mxo, myo);
505 >                revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y,
506 >                                xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax);
507                  XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u);
508 <                revbox(nxo, nyo, nxo+xmax, nyo+ymax);
508 >                revline(ebut->x, ebut->y, mxo, myo);
509 >                revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y,
510 >                                xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax);
511          }
512          xoff += e.b.x - ebut->x;
513          yoff += e.b.y - ebut->y;
# Line 532 | Line 551 | XButtonPressedEvent  *ebut;
551   revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
552   int  x0, y0, x1, y1;
553   {
554 <        static GC       mygc = 0;
554 >        revline(x0, y0, x1, y0);
555 >        revline(x0, y1, x1, y1);
556 >        revline(x0, y0, x0, y1);
557 >        revline(x1, y0, x1, y1);
558 > }
559  
537        if (mygc == 0) {
538                mygc = XCreateGC(thedisplay, wind, 0, 0);
539                XSetFunction(thedisplay, mygc, GXinvert);
540        }
541        XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0);
542        XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1);
543        XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1);
544        XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1);
545 } /* end of revbox */
560  
547
561   avgbox(clr)                             /* average color over current box */
562   COLOR  clr;
563   {
# Line 590 | Line 603 | getmono()                      /* get monochrome data */
603          register unsigned char  *dp;
604          register int    x, err;
605          int     y;
606 <        rgbpixel        *inline;
606 >        rgbpixel        *inl;
607          short   *cerr;
608  
609 <        if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
609 >        if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
610                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
611                  quit("out of memory in getmono");
612          dp = ourdata - 1;
613          for (y = 0; y < ymax; y++) {
614 <                picreadline3(y, inline);
614 >                picreadline3(y, inl);
615                  err = 0;
616                  for (x = 0; x < xmax; x++) {
617                          if (!(x&7))
618                                  *++dp = 0;
619 <                        err += rgb_bright(&inline[x]) + cerr[x];
619 >                        err += rgb_bright(&inl[x]) + cerr[x];
620                          if (err > 127)
621                                  err -= 255;
622                          else
# Line 611 | Line 624 | getmono()                      /* get monochrome data */
624                          cerr[x] = err >>= 1;
625                  }
626          }
627 <        free((char *)inline);
627 >        free((char *)inl);
628          free((char *)cerr);
629   }
630  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines