[comp.windows.x] Diffs to make xphoon work under X11

spencer@CITI.UMICH.EDU (08/22/88)

Here is the set of changes I came up with to make xphoon work under
X11.  The only non-obvious change is the necessity to byte-swap the
image data on big-endian machines (since it is stored as shorts
instead of chars).

=Spencer (spencer@crim.eecs.umich.edu)

diff -c ./cheapmoon.c ../cheapmoon.c
*** ./cheapmoon.c	Mon Aug 22 10:41:47 1988
--- ../cheapmoon.c	Mon Aug 22 10:31:44 1988
***************
*** 3,9 ****
      "@(#) $Header: cheapmoon.c,v 1.3 88/06/07 17:56:02 leres Exp $ (LBL)";
  #endif
  
- #include <X/Xlib.h>
  #include <cheapmoon.bitmap>
  
  getbitmap(w, h, bits, cx, cy, r)
--- 3,8 ----
diff -c ./xphoon.c ../xphoon.c
*** ./xphoon.c	Mon Aug 22 10:41:46 1988
--- ../xphoon.c	Mon Aug 22 10:38:30 1988
***************
*** 3,9 ****
      "@(#) $Header: xphoon.c,v 1.7 88/08/15 21:34:28 jef Exp $ (LBL)";
  #endif
  
! #include <X/Xlib.h>
  #include <stdio.h>
  #include <math.h>
  #include "tws.h"
--- 3,9 ----
      "@(#) $Header: xphoon.c,v 1.7 88/08/15 21:34:28 jef Exp $ (LBL)";
  #endif
  
! #include <X11/Xlib.h>
  #include <stdio.h>
  #include <math.h>
  #include "tws.h"
***************
*** 11,16 ****
--- 11,19 ----
  char *argv0;
  int blackflag = 0;
  int demoflag = 0;
+ Display * dpy;
+ int screen;
+ Window root;
  
  char *malloc();
  
***************
*** 83,101 ****
  		
  	}
  
! 	if (XOpenDisplay(display) == 0) {
  		fprintf(stderr, "%s: Can't open display \"%s\"\n",
  		    argv0, XDisplayName(display));
  		exit(1);
  	}
  
  	if (delayminutes <= 0 && ! demoflag) {
  		hackbits(dtwstime(), w, h, bits, cx, cy, r);
  		setroot(w, h, bits);
  		exit(0);
  	}
  
! 	size = BitmapSize(w, h);
  	xbits = (short *)malloc(size);
  	for (;;) {
  		bcopy((char *)bits, (char *)xbits, size);
--- 86,107 ----
  		
  	}
  
! 	if ((dpy = XOpenDisplay(display)) == 0) {
  		fprintf(stderr, "%s: Can't open display \"%s\"\n",
  		    argv0, XDisplayName(display));
  		exit(1);
  	}
+ 	screen = DefaultScreen(dpy);
+ 	root = RootWindow(dpy, screen);
  
  	if (delayminutes <= 0 && ! demoflag) {
  		hackbits(dtwstime(), w, h, bits, cx, cy, r);
  		setroot(w, h, bits);
+ 		XCloseDisplay(dpy);
  		exit(0);
  	}
  
! 	size = 2 * ((w+15)/16) * h;
  	xbits = (short *)malloc(size);
  	for (;;) {
  		bcopy((char *)bits, (char *)xbits, size);
***************
*** 114,140 ****
  	int w, h;
  	short *bits;
  {
! 	Bitmap bitmap;
  	Pixmap pixmap;
  
! 	bitmap = XStoreBitmap(w, h, bits);
  
  	if (bitmap == 0) {
! 		fprintf(stderr, "%s: Unable to store Bitmap", argv0);
  		exit(1);
  	}
  	
! 	pixmap = XMakePixmap(bitmap, BlackPixel, WhitePixel);
! 	if (pixmap == 0) {
! 		fprintf(stderr, "%s: Unable to store Pixmap", argv0);
  		exit(1);
  	}
! 
! 	XChangeBackground(RootWindow, pixmap);
! 	XClear(RootWindow);
! 	XFreeBitmap(bitmap);
! 	XFreePixmap(pixmap);
! 	XFlush();
  }
  
  
--- 120,155 ----
  	int w, h;
  	short *bits;
  {
! 	Pixmap bitmap;
  	Pixmap pixmap;
+ 	GC gc;
+ 	XGCValues gc_init;
  
! 	gc_init.foreground = BlackPixel(dpy, screen);
! 	gc_init.background = WhitePixel(dpy, screen);
  
+ 	bitmap = XCreateBitmapFromData(dpy, root, bits, w, h);
+ 
  	if (bitmap == 0) {
! 		fprintf(stderr, "%s: Unable to create Bitmap\n", argv0);
  		exit(1);
  	}
  	
! 	gc = XCreateGC(dpy, root, GCForeground|GCBackground, &gc_init);
! 	pixmap = XCreatePixmap(dpy, root, w, h,
! 			    (unsigned int)DefaultDepth(dpy, screen));
! 	if ( pixmap == 0 ) {
! 		fprintf(stderr, "%s: Unable to create pixmap\n", argv0);
  		exit(1);
  	}
! 	XCopyPlane(dpy, bitmap, pixmap, gc, 0, 0, w, h, 0, 0,
! 		   (unsigned long)1);
! 	XSetWindowBackgroundPixmap(dpy, root, pixmap);
! 	XFreeGC(dpy, gc);
! 	XFreePixmap(dpy, bitmap);
! 	XFreePixmap(dpy, pixmap);
! 	XClearWindow(dpy, root);
! 	XFlush(dpy);
  }
  
  
***************
*** 209,215 ****
--- 224,233 ----
  	int shadeindex;
  	short shade;
  	static double demoinc = 0.0;
+ 	static short byteorder = 0x0102;
+ 	register unsigned char * bp, tmp;
  
+ 
  	jd = jtime( t );
  	if ( demoflag ) {
  		/* Jump ahead a day each time through. */
***************
*** 266,269 ****
--- 284,299 ----
  		}
  	}
  	
+ 	/* Swap bytes if necessary */
+ 	if ( *(unsigned char *)&byteorder == 0x01 )
+ 	{
+ 	    for ( bp = (unsigned char *)bits,
+ 		  i = ((w + 15) / 16) * h;
+ 		  i > 0; i--, bp++ )
+ 	    {
+ 		tmp = *bp;
+ 		*bp = *(bp + 1);
+ 		*++bp = tmp;
+ 	    }
+ 	}
  }

jef@HELIOS.EE.LBL.GOV (Jef Poskanzer) (08/23/88)

Please ignore spencer@CITI.UMICH.EDU's diffs.  The byte swap hack he
came up with proves that he doesn't know what he is doing.

I also received a set of diffs by mail from one David Koblas.  His diffs
look good, except for the extremely weird thing he did with the shade
masks.

Some time within the next week, I will make the official X11 xphoon
available.
---
Jef

             Jef Poskanzer   jef@rtsg.ee.lbl.gov   ...well!pokey
Flon's Law: There is not now, and never will be, a language in which it is the
                  least bit difficult to write bad programs.