Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!CITI.UMICH.EDU!spencer From: spencer@CITI.UMICH.EDU Newsgroups: comp.windows.x Subject: Diffs to make xphoon work under X11 Message-ID: <8808221454.AA15230@EXPO.LCS.MIT.EDU> Date: 22 Aug 88 14:51:00 GMT Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 193 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 #include 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 #include #include #include "tws.h" --- 3,9 ---- "@(#) $Header: xphoon.c,v 1.7 88/08/15 21:34:28 jef Exp $ (LBL)"; #endif ! #include #include #include #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; + } + } }