Path: utzoo!utgpu!water!watmath!clyde!att!ihnp4!upba!eecae!super.upenn.edu!xmos.cis.upenn.edu!bradley
From: bradley@xmos.cis.upenn.edu (John Bradley)
Newsgroups: comp.windows.x
Subject: Patch to 'xmag'
Message-ID: <4634@super.upenn.edu>
Date: 12 May 88 23:08:01 GMT
Sender: news@super.upenn.edu
Reply-To: bradley@xmos.cis.upenn.edu (John Bradley)
Distribution: na
Organization: University of Pennsylvania
Lines: 188


Here's a patch to xmag that let's you click on pixels in the magnified 
window and get their pixel/r/g/b values.  Handy when debugging image processing
thingies, or at least it *should* be.

John Bradley  -  bradley@cis.upenn.edu

-----------------------(cut here)-------------------------
*** xmag.c.std	Thu May 12 16:06:24 1988
--- xmag.c	Thu May 12 18:46:30 1988
***************
*** 29,34 ****
--- 29,36 ----
  #define DEFAULT_CURSOR_SIZE 64
  #define DEFAULT_MAGNIFICATION 5
  
+ #define PIXFONT "8x13"
+ 
  int Argc;				/* copy of argc */
  char **Argv;				/* copy of argv */
  
***************
*** 433,439 ****
      attr.background_pixel = back_pixel;
      attr.border_pixel = border_pixel;
      attr.event_mask = (ExposureMask|ButtonPressMask|KeyPressMask);
!     attr.cursor = XCreateFontCursor (dpy, XC_top_left_arrow);
      valuemask = (CWBackPixel | CWBorderPixel | CWEventMask | CWCursor);
  
      w = XCreateWindow (dpy, root, 
--- 435,441 ----
      attr.background_pixel = back_pixel;
      attr.border_pixel = border_pixel;
      attr.event_mask = (ExposureMask|ButtonPressMask|KeyPressMask);
!     attr.cursor = XCreateFontCursor (dpy, XC_draft_small);
      valuemask = (CWBackPixel | CWBorderPixel | CWEventMask | CWCursor);
  
      w = XCreateWindow (dpy, root, 
***************
*** 608,614 ****
      if (!image) return (False);
  
      /*
!      * Map the window and do the work.  Button press or space means do another;
       * q, Q, or ^C mean quit.
       */
  
--- 610,617 ----
      if (!image) return (False);
  
      /*
!      * Map the window and do the work.  Space means do another;
!      * Button1 press displays pixel value.
       * q, Q, or ^C mean quit.
       */
  
***************
*** 617,623 ****
      XMapWindow (dpy, w);
      for (done = False; !done; ) {
  	XEvent event;
! 	int len;
  	char keybuffer[10];
  
  	XNextEvent (dpy, &event);
--- 620,629 ----
      XMapWindow (dpy, w);
      for (done = False; !done; ) {
  	XEvent event;
!         XButtonEvent *buttevent;
!         XColor def;
!         unsigned long pixel,lastpix;
! 	int len,first;
  	char keybuffer[10];
  
  	XNextEvent (dpy, &event);
***************
*** 626,634 ****
  	    repaint_image (image, &event, magnification, back_pixel);
  	    break;
  	  case ButtonPress:
! 	    domore = True;
! 	    done = True;
  	    break;
  	  case KeyPress:
  	    len = XLookupString (&event, keybuffer, sizeof keybuffer,
  				 NULL, NULL);
--- 632,673 ----
  	    repaint_image (image, &event, magnification, back_pixel);
  	    break;
  	  case ButtonPress:
!             buttevent = (XButtonEvent *) &event;
!             if (buttevent->button != Button1) break;   /* not Button1. fnord */
!             first=1;
!             if (buttevent->y/magnification > height/2) CreatePixWind(w,0);
!                                                   else CreatePixWind(w,1);
!             while (1) {     /* loop until button released */
!                 Window rootW,childW;
!                 int rx,ry,x,y,lx,ly;
!                 unsigned int mask;
!                 char str[64];
! 
!                 if (XQueryPointer(dpy,w,&rootW,&childW,&rx,&ry,&x,&y,&mask)) {
!                     if (!(mask & Button1Mask)) break;    /* button released */
!                     
!                     x=x/magnification;  y=y/magnification;
! 
!                     if ( (first || x!=lx || y!=ly) && 
!                          (x>=0 && x=0 && yfid);
+ 
+     thigh = pixfinfo->ascent + pixfinfo->descent + 4;
+     if (bot) y=h-thigh;  else y=0;
+ 
+     pixwind = XCreateSimpleWindow(dpy, wind, 0, y, w, thigh, 0,0,0);
+ 
+     XMapWindow(dpy,pixwind);
+ }
+ 
+ 
+ DrawPixWind(str)
+ char *str;
+ {
+     XClearWindow(dpy,pixwind);
+     XSetForeground(dpy,fillGC,1);
+     XDrawString(dpy,pixwind,fillGC,4,2+pixfinfo->ascent,str,strlen(str));
+ }
+ 
+ 
+ ClosePixWind()
+ {
+     XDestroyWindow(dpy,pixwind);
+     XFreeFont(dpy,pixfinfo);
+ }
+