[comp.windows.x] xsetroot reads compressed .xbm file

bob@primerd.prime.com (03/22/89)

I've modified XReadBitmapFile to read compressed files.  Often our
bitmap directories are quite large, so I keep them in compressed format
and they are uncompressed on the way in.  (If foo.xbm does not exist, it 
checks for and uncompresses foo.xbm.Z)  I basically copied the equivalent
code out of xbgsun.  The question is:  Would this be a reasonable enhancement 
to XReadBitmapFile?  The performance hit is usualy not an issue when you
are using this routine, and it behaves as it always did if the .xbm file
exists.

On a related note, I took the xsetroot modifications for centering the
image and added one minor twiddle to get it to draw a frame around the image.
The code follows.  By the way, you need not bother rebuilding Xlib to
take advantage of this.  Just copy the new version of XRdBitF.c and link it
in with xsetroot.

Bob Pellegrino
Prime Computer, Inc.
bob@deep-thought.prime.com





Changes to XRdBitF.c for compressed images:

124a125
>     char cmd[1024];
129,130c130,145
<     if ((fstream = fopen(filename, "r")) == NULL) {
<       return BitmapOpenFailed;
---
>     if (!strcmp(filename + strlen(filename) - 2, ".Z")) {
>       sprintf (cmd, "uncompress -c %s", filename);
>       fstream = popen(cmd, "r");
>     }
>     else {
>       if ((fstream = fopen(filename, "r")) == NULL) {
>       sprintf(cmd, "%s.Z", filename);
>       if ((fstream = fopen(cmd, "r")) != NULL) {
>         fclose(fstream);
>         sprintf(cmd, "uncompress -c %s.Z", filename);
>         fstream= popen(cmd, "r");
>       }
>       else
>         return BitmapOpenFailed;
>
>       }



Changes to xsetroot for frame drawing. (Note, this assumes you have already
applied the patches for centering that were just posted.)

17a18,19
> XPoint points[4];
>
408a411,424
>
>     XSetLineAttributes(dpy, gc, 6, LineSolid, CapRound, JoinRound);
>     points[0].x =destx;
>     points[0].y =desty;
>     points[1].x =destx+w;
>     points[1].y =desty;
>     points[2].x =destx+w;
>     points[2].y =desty+h;
>     points[3].x =destx;
>     points[3].y =desty+h;
>     points[4].x =destx;
>     points[4].y =desty;
>
>     XDrawLines(dpy, *ppix, gc, points, 5, CoordModeOrigin);