arul@sdsu.UUCP (Arul Ananthanarayanan) (09/15/88)
Is there a way to display x bitmaps other than using xsetroot -bitmap? I used the portable bitmap package to convert sun raster files to X bitmaps, but using xsetroot take several minutes to display the pictures. For what its worth we are running X11R2 on a Sun 3/50 O.S. 3.5 Thanks, Arul -- San Diego State University Math Sciences Dept. Celerity 1230 BSD 4.3 UUCP: ....!ucsd!sdsu!arul work:(619) 594-7208 ARPA: arul%sdsu.uucp@ucsd.edu home:(619) 583-0439
mdb@silvlis.COM (Mark D. Baushke) (09/15/88)
> Date: 14 Sep 88 20:41:15 GMT > From: sun!ucsd.edu!ucsdhub!sdsu!arul (Arul Ananthanarayanan) > > Is there a way to display x bitmaps other than using xsetroot > -bitmap? I used the portable bitmap package to convert sun raster > files to X bitmaps, but using xsetroot take several minutes to > display the pictures. > > For what its worth we are running X11R2 on a Sun 3/50 O.S. 3.5 If you apply the following patch to xsetroot.c, you will be able to use sun raster file format in "xsetroot -rast some-raster-file". I use this and have all my bitmap run-length encoded to take up less disk space...it is also much faster on my Sun 3/50 SunOS 3.4 w/X11R2. ------------------------------------------------------------------------------ Mark D. Baushke Internet: mdb%silvlis.com@sun.com Silvar-Lisco, Inc. Nameservers: mdb@silvlis.com 1080 Marsh Road Usenet: {pyramid,sun}!silvlis!mdb Menlo Park, CA 94025-1053 Telephone: +1 415 853-6411 / +1 415 969-8328 *** xsetroot.c.orig Thu Feb 25 21:12:18 1988 --- xsetroot.c Fri Jun 3 12:26:28 1988 *************** *** 6,11 **** --- 6,14 ---- #include <stdio.h> #include "X11/bitmaps/gray" + #ifdef sun + #include <pixrect/pixrect_hs.h> + #endif /* * xsetroot.c MIT Project Athena, X Window system root window * parameter setting utility. This program will set *************** *** 13,18 **** --- 16,23 ---- * * Author: Mark Lillibridge, MIT Project Athena * 11-Jun-87 + * Modified: Mark Baushke <mdb@silvlis.com>, to add -rast option + * 2-Jun-88 */ char *index(); *************** *** 45,50 **** --- 50,56 ---- fprintf(stderr, " -solid <color>\n"); fprintf(stderr, " -gray or -grey\n"); fprintf(stderr, " -bitmap <filename>\n"); + fprintf(stderr, " -rast <filename>\n"); fprintf(stderr, " -mod <x> <y>\n"); exit(1); /*NOTREACHED*/ *************** *** 51,56 **** --- 57,65 ---- } Pixmap MakeModulaBitmap(), ReadBitmapFile(); + #ifdef sun + Pixmap ReadSunRasterFile(), XCreateBitmapFromSunPixrectData(); + #endif /* sun */ XColor NameToXColor(); unsigned long NameToPixel(); *************** *** 69,74 **** --- 78,84 ---- Cursor cursor; int gray = 0; char *bitmap_file = NULL; + char *rast_file = NULL; int mod_x = 0; int mod_y = 0; register int i; *************** *** 131,136 **** --- 141,159 ---- excl++; continue; } + if (!strcmp("-rast", argv[i])) { + #ifdef sun + if (++i>=argc) usage(); + rast_file = argv[i]; + excl++; + continue; + #else + fprintf(stderr, "%s: "-rast" option not implemented.\n", + program_name); + if (++i>=argc) usage(); + continue; + #endif /* sun */ + } if (!strcmp("-mod", argv[i])) { if (++i>=argc) usage(); mod_x = atoi(argv[i]); *************** *** 150,157 **** --- 173,186 ---- /* Check for multiple use of exclusive options */ if (excl > 1) { + #ifdef sun + fprintf(stderr, + "%s: choose only one of {solid, gray, bitmap, rast, mod}\n", + program_name); + #else fprintf(stderr, "%s: choose only one of {solid, gray, bitmap, mod}\n", program_name); + #endif /* sun */ usage(); } *************** *** 196,201 **** --- 225,238 ---- SetBackgroundToBitmap(bitmap, ww, hh); } + #ifdef sun + /* Handle -rast option */ + if (rast_file) { + bitmap = ReadSunRasterFile(rast_file, &ww, &hh); + SetBackgroundToBitmap(bitmap, ww, hh); + } + #endif /* sun */ + /* Handle set background to a modula pattern */ if (mod_x) { bitmap = MakeModulaBitmap(mod_x, mod_y); *************** *** 435,437 **** --- 472,607 ---- exit(1); /*NOTREACHED*/ } + + #ifdef sun + char *malloc(); + + Pixmap ReadSunRasterFile(filename, width, height) + char *filename; + unsigned int *width, *height; + { + Pixmap bitmap; + int status; + int rows, cols, linebytes; + short *data; + FILE *file; + struct rasterfile header; + struct pixrect *pr, *pr_load_image(); + int firsttime, value, i, data_length; + + file = fopen(filename, "r"); + if (file == NULL) { + fprintf(stderr, "%s: can't open file: %s\n", program_name, + filename); + exit(1); + } + + cols = rows = -1; + + /* Get the raster file's header. */ + if (pr_load_header(file, &header) != 0) { + fprintf(stderr, "%s: Unable to read in raster file header.\n", + filename); + exit(1); + } + + /* can only handle monochrome bitmaps. */ + if (header.ras_depth != 1) { + fprintf(stderr, "%s: Invalid depth.\n", filename); + exit(1); + } + + cols = header.ras_width; + rows = header.ras_height; + if (cols <= 0) { + fprintf(stderr, "%s: Invalid width: %d.\n", filename, cols); + exit(1); + } + + if (rows <= 0) { + fprintf(stderr, "%s: Invalid height: %d.\n", filename, rows); + exit(1); + } + + /* If there is a color map, skip over it. */ + if (header.ras_maptype != RMT_NONE && header.ras_maplength != 0) { + if (pr_load_colormap(file, &header, NULL) != 0) { + fprintf(stderr, "%s: Unable to skip colormap data.\n", filename); + exit(1); + } + } + + /* Now load the data. The pixrect returned is a memory pixrect. */ + if ((pr = pr_load_image(file, &header, NULL)) == NULL) { + fprintf(stderr, + "Unable to read in the image from the raster file: %s.\n", + filename); + exit(1); + } + fclose(file); + + linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes; + data = ((struct mpr_data *)pr->pr_data)->md_image; + + *width = cols; + *height = rows; + bitmap = XCreateBitmapFromSunPixrectData(dpy, root, (char *) data, + *width, *height, linebytes); + if (!bitmap) { + fprintf(stderr, "%s: insufficient memory for bitmap: %s", + program_name, filename); + exit(1); + } + return(bitmap); + } + + + /* + * XCreateBitmapFromSunPixrectData: Routine to make a pixmap of depth 1 from user supplied data. + * D is any drawable on the same screen that the pixmap will be used in. + * Data is a pointer to the bit data, and + * width & height give the size in bits of the pixmap. + * + * The following format is assumed for data: + * + * format=XYPixmap + * bit_order=MSBFirst + * byte_order=MSBFirst + * padding=8 + * bitmap_unit=8 + * xoffset=0 + * rows are rounded up to 16-bit boundaries + */ + Pixmap XCreateBitmapFromSunPixrectData(display, d, data, width, + height, linebytes) + Display *display; + Drawable d; + char *data; + unsigned int width, height; + int linebytes; + { + XImage ximage; + GC gc; + Pixmap pix; + + pix = XCreatePixmap(display, d, width, height, 1); + if (!pix) + return(0); + gc = XCreateGC(display, pix, (unsigned long)0, (XGCValues *)0); + ximage.height = height; + ximage.width = width; + ximage.depth = 1; + ximage.xoffset = 0; + ximage.format = XYPixmap; + ximage.data = data; + ximage.byte_order = MSBFirst; + ximage.bitmap_unit = 8; + ximage.bitmap_bit_order = MSBFirst; + ximage.bitmap_pad = 8; + ximage.bytes_per_line = (linebytes == 0) ? (((width+15)>>3) & ~1) : linebytes; + + XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); + XFreeGC(display, gc); + return(pix); + } + #endif /* sun */ *** xsetroot.man.orig Mon Feb 29 06:15:37 1988 --- xsetroot.man Thu Jun 2 23:35:09 1988 *************** *** 6,10 **** --- 6,11 ---- [-help] [-def] [-display \fIdisplay\fP] [-cursor \fIcursorfile maskfile\fP] [-bitmap \fIfilename\fP] + [-rast \fIfilename\fP] [-mod \fIx y\fP] [-gray] [-grey] [-fg \fIcolor\fP] [-bg \fIcolor\fP] [-rv] [-solid \fIcolor\fP] [-name \fIstring\fP] .SH DESCRIPTION *************** *** 25,31 **** characteristics will be reset to the default state. .PP Only one of the background color/tileing changing options ! (-solid, -gray, -grey, -bitmap, and -mod) may be specified at a time. .SH OPTIONS .PP The various options are as follows: --- 26,32 ---- characteristics will be reset to the default state. .PP Only one of the background color/tileing changing options ! (-solid, -gray, -grey, -bitmap, -rast, and -mod) may be specified at a time. .SH OPTIONS .PP The various options are as follows: *************** *** 47,52 **** --- 48,59 ---- .I bitmap(1) program. The entire background will be made up of repeated "tiles" of the bitmap. + .IP "\fB-rast\fP \fIfilename\fP" + Use the sun raster file specified in the file to set the window + pattern. You can make your own sun raster files (little pictures) using the + .I screendump(1) + program. The entire background will be made up of repeated "tiles" of + the raster file. .IP "\fB-mod\fP \fIx\fP \fIy\fP" This is used if you want a plaid-like grid pattern on your screen. x and y are integers ranging from 1 to 16. Try the different combinations. *************** *** 72,78 **** .IP "\fB-display\fP \fIdisplay\fP" Specifies the server to connect to; see \fIX(1)\fP. .SH "SEE ALSO" ! X(1), xset(1), xrdb(1) .SH COPYRIGHT Copyright 1988, Massachusetts Institute of Technology. .br --- 79,85 ---- .IP "\fB-display\fP \fIdisplay\fP" Specifies the server to connect to; see \fIX(1)\fP. .SH "SEE ALSO" ! X(1), xset(1), xrdb(1), screendump(1), screenload(1) .SH COPYRIGHT Copyright 1988, Massachusetts Institute of Technology. .br