home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume2 / xsetroot / patch1 next >
Text File  |  1988-12-06  |  10KB  |  344 lines

  1. Path: uunet!wyse!mikew
  2. From: mikew@wyse.wyse.com (Mike Wexler)
  3. Newsgroups: comp.sources.x
  4. Subject: v02i034:  set the root background, Patch1
  5. Message-ID: <1882@wyse.wyse.com>
  6. Date: 6 Dec 88 23:24:28 GMT
  7. Organization: Wyse Technology, San Jose
  8. Lines: 333
  9. Approved: mikew@wyse.com
  10.  
  11. Submitted-by: Bob Sutterfield <bob@cis.ohio-state.edu>
  12. Posting-number: Volume 2, Issue 34
  13. Archive-name: xsetroot/patch1
  14.  
  15.  
  16.  
  17. Long ago, Mark Baushke (mdb@silvlis.com) posted changes for the X11R2
  18. xsetroot so that it could use Sun rasterfile format bitmaps as its
  19. input.  I simply merged those changes back into the X11R3 xsetroot.    --Bob
  20.  
  21. diff -rc2 X.V11R3/clients/xsetroot/xsetroot.c.dist X.V11R3/clients/xsetroot/xsetroot.c
  22. *** X.V11R3/clients/xsetroot/xsetroot.c.dist    Tue Nov 29 23:29:55 1988
  23. --- X.V11R3/clients/xsetroot/xsetroot.c    Wed Nov 30 00:22:17 1988
  24. ***************
  25. *** 7,10 ****
  26. --- 7,14 ----
  27.   #include "X11/bitmaps/gray"
  28.   
  29. + #ifdef sun
  30. + #include <pixrect/pixrect_hs.h>
  31. + #endif /* sun */
  32.   /*
  33.    * xsetroot.c     MIT Project Athena, X Window system root window 
  34. ***************
  35. *** 14,17 ****
  36. --- 18,26 ----
  37.    *  Author:    Mark Lillibridge, MIT Project Athena
  38.    *        11-Jun-87
  39. +  *  Modified: Mark Baushke <mdb@silvlis.com>, to add -rast option
  40. +  *            2-Jun-88
  41. +  *            Bob Sutterfield <bob@cis.ohio-state.edu>, re-merged
  42. +  *            mdb's -rast changes into X11R3.
  43. +  *            30-Nov-88
  44.    */
  45.   
  46. ***************
  47. *** 46,49 ****
  48. --- 55,59 ----
  49.       fprintf(stderr, "  -gray   or   -grey\n");
  50.       fprintf(stderr, "  -bitmap <filename>\n");
  51. +     fprintf(stderr, "  -rast <filename>\n");
  52.       fprintf(stderr, "  -mod <x> <y>\n");
  53.       exit(1);
  54. ***************
  55. *** 52,55 ****
  56. --- 62,68 ----
  57.   
  58.   Pixmap MakeModulaBitmap(), ReadBitmapFile();
  59. + #ifdef sun
  60. + Pixmap  ReadSunRasterFile(), XCreateBitmapFromSunPixrectData();
  61. + #endif /* sun */
  62.   XColor NameToXColor();
  63.   unsigned long NameToPixel();
  64. ***************
  65. *** 70,73 ****
  66. --- 83,89 ----
  67.       int gray = 0;
  68.       char *bitmap_file = NULL;
  69. + #ifdef sun
  70. +     char *rast_file = NULL;
  71. + #endif /* sun */
  72.       int mod_x = 0;
  73.       int mod_y = 0;
  74. ***************
  75. *** 132,135 ****
  76. --- 148,164 ----
  77.           continue;
  78.       }
  79. +     if (!strcmp("-rast", argv[i])) {
  80. + #ifdef sun
  81. +          if (++i>=argc) usage();
  82. +          rast_file = argv[i];
  83. +          excl++;
  84. +          continue;
  85. + #else /* sun */
  86. +          fprintf(stderr, "%s: "-rast" option not implemented.\n",
  87. +              program_name);
  88. +          if (++i>=argc) usage();
  89. +          continue;
  90. + #endif /* sun */
  91. +     }
  92.       if (!strcmp("-mod", argv[i])) {
  93.           if (++i>=argc) usage();
  94. ***************
  95. *** 151,157 ****
  96.       /* Check for multiple use of exclusive options */
  97.       if (excl > 1) {
  98. !     fprintf(stderr, "%s: choose only one of {solid, gray, bitmap, mod}\n",
  99. !         program_name);
  100. !     usage();
  101.       }
  102.   
  103. --- 180,192 ----
  104.       /* Check for multiple use of exclusive options */
  105.       if (excl > 1) {
  106. ! #ifdef sun
  107. !      fprintf(stderr,
  108. !          "%s: choose only one of {solid, gray, bitmap, rast, mod}\n",
  109. !          program_name);
  110. ! #else /* sun */
  111. !      fprintf(stderr, "%s: choose only one of {solid, gray, bitmap, mod}\n",
  112. !          program_name);
  113. ! #endif /* sun */
  114. !      usage();
  115.       }
  116.   
  117. ***************
  118. *** 196,200 ****
  119.       SetBackgroundToBitmap(bitmap, ww, hh);
  120.       }
  121. !   
  122.       /* Handle set background to a modula pattern */
  123.       if (mod_x) {
  124. --- 231,243 ----
  125.       SetBackgroundToBitmap(bitmap, ww, hh);
  126.       }
  127. ! #ifdef sun
  128. !     /* Handle -rast option */
  129. !     if (rast_file) {
  130. !      bitmap = ReadSunRasterFile(rast_file, &ww, &hh);
  131. !      SetBackgroundToBitmap(bitmap, ww, hh);
  132. !     }
  133. ! #endif /* sun */
  134.       /* Handle set background to a modula pattern */
  135.       if (mod_x) {
  136. ***************
  137. *** 441,442 ****
  138. --- 484,618 ----
  139.       /*NOTREACHED*/
  140.   }
  141. + #ifdef sun
  142. + char *malloc();
  143. + Pixmap ReadSunRasterFile(filename, width, height)
  144. +     char *filename;
  145. +     unsigned int *width, *height;
  146. + {
  147. +     Pixmap bitmap;
  148. +     int status;
  149. +     int rows, cols, linebytes;
  150. +     short *data;
  151. +     FILE *file;
  152. +     struct rasterfile header;
  153. +     struct pixrect *pr, *pr_load_image();
  154. +     int firsttime, value, i, data_length;
  155. +     
  156. +     file = fopen(filename, "r");
  157. +     if (file == NULL) {
  158. +     fprintf(stderr, "%s: can't open file: %s\n", program_name,
  159. +         filename);
  160. +     exit(1);
  161. +     }
  162. +     cols = rows = -1;
  163. +     /* Get the raster file's header. */
  164. +     if (pr_load_header(file, &header) != 0) {
  165. +     fprintf(stderr, "%s: Unable to read in raster file header.\n",
  166. +         filename);
  167. +     exit(1);
  168. +     }
  169. +     /* can only handle monochrome bitmaps. */
  170. +     if (header.ras_depth != 1) {
  171. +     fprintf(stderr, "%s: Invalid depth.\n", filename);
  172. +     exit(1);
  173. +     }
  174. +     cols = header.ras_width;
  175. +     rows = header.ras_height;
  176. +     if (cols <= 0) {
  177. +     fprintf(stderr, "%s: Invalid width: %d.\n", filename, cols);
  178. +     exit(1);
  179. +     }
  180. +     
  181. +     if (rows <= 0) {
  182. +     fprintf(stderr, "%s: Invalid height: %d.\n", filename, rows);
  183. +     exit(1);
  184. +     }
  185. +     /* If there is a color map, skip over it. */
  186. +     if (header.ras_maptype != RMT_NONE && header.ras_maplength != 0) {
  187. +     if (pr_load_colormap(file, &header, NULL) != 0) {
  188. +         fprintf(stderr, "%s: Unable to skip colormap data.\n", filename);
  189. +         exit(1);
  190. +     }
  191. +     }
  192. +     /* Now load the data.  The pixrect returned is a memory pixrect. */
  193. +     if ((pr = pr_load_image(file, &header, NULL)) == NULL) {
  194. +     fprintf(stderr,
  195. +         "Unable to read in the image from the raster file: %s.\n",
  196. +         filename);
  197. +     exit(1);
  198. +     }
  199. +     fclose(file);
  200. +     linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes;
  201. +     data = ((struct mpr_data *)pr->pr_data)->md_image;
  202. +     *width = cols;
  203. +     *height = rows;
  204. +     bitmap = XCreateBitmapFromSunPixrectData(dpy, root, (char *) data,
  205. +                         *width, *height, linebytes);
  206. +     if (!bitmap) {
  207. +     fprintf(stderr, "%s: insufficient memory for bitmap: %s",
  208. +         program_name, filename);
  209. +     exit(1);
  210. +     }
  211. +     return(bitmap);
  212. + }
  213. + /*
  214. +  * XCreateBitmapFromSunPixrectData: Routine to make a pixmap of depth 1 from user supplied data.
  215. +  *             D is any drawable on the same screen that the pixmap will be used in.
  216. +  *             Data is a pointer to the bit data, and 
  217. +  *             width & height give the size in bits of the pixmap.
  218. +  *
  219. +  * The following format is assumed for data:
  220. +  *
  221. +  *    format=XYPixmap
  222. +  *    bit_order=MSBFirst
  223. +  *    byte_order=MSBFirst
  224. +  *    padding=8
  225. +  *    bitmap_unit=8
  226. +  *    xoffset=0
  227. +  *    rows are rounded up to 16-bit boundaries
  228. +  */  
  229. + Pixmap XCreateBitmapFromSunPixrectData(display, d, data, width,
  230. +                        height, linebytes)
  231. +      Display *display;
  232. +      Drawable d;
  233. +      char *data;
  234. +      unsigned int width, height;
  235. +      int linebytes;
  236. + {
  237. +     XImage ximage;
  238. +     GC gc;
  239. +     Pixmap pix;
  240. +     pix = XCreatePixmap(display, d, width, height, 1);
  241. +     if (!pix)
  242. +       return(0);
  243. +     gc = XCreateGC(display, pix, (unsigned long)0, (XGCValues *)0);
  244. +     ximage.height = height;
  245. +     ximage.width = width;
  246. +     ximage.depth = 1;
  247. +     ximage.xoffset = 0;
  248. +     ximage.format = XYPixmap;
  249. +     ximage.data = data;
  250. +     ximage.byte_order = MSBFirst;
  251. +     ximage.bitmap_unit = 8;
  252. +     ximage.bitmap_bit_order = MSBFirst;
  253. +     ximage.bitmap_pad = 8;
  254. +     ximage.bytes_per_line = (linebytes == 0) ? (((width+15)>>3) & ~1) : linebytes; 
  255. +     
  256. +     XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
  257. +     XFreeGC(display, gc);
  258. +     return(pix);
  259. + }
  260. + #endif /* sun */
  261.  
  262. diff -rc2 X.V11R3/clients/xsetroot/xsetroot.man.dist X.V11R3/clients/xsetroot/xsetroot.man
  263. *** X.V11R3/clients/xsetroot/xsetroot.man.dist    Tue Nov 29 23:30:08 1988
  264. --- X.V11R3/clients/xsetroot/xsetroot.man    Wed Nov 30 00:04:43 1988
  265. ***************
  266. *** 6,9 ****
  267. --- 6,10 ----
  268.   [-help] [-def] [-display \fIdisplay\fP]
  269.   [-cursor \fIcursorfile maskfile\fP] [-bitmap \fIfilename\fP]
  270. + [-rast \fIfilename\fP]
  271.   [-mod \fIx y\fP] [-gray] [-grey] [-fg \fIcolor\fP] [-bg \fIcolor\fP] [-rv]
  272.   [-solid \fIcolor\fP] [-name \fIstring\fP]
  273. ***************
  274. *** 26,30 ****
  275.   .PP
  276.   Only one of the background color/tiling changing options 
  277. ! (-solid, -gray, -grey, -bitmap, and -mod) may be specified at a time.
  278.   .SH OPTIONS
  279.   .PP
  280. --- 27,31 ----
  281.   .PP
  282.   Only one of the background color/tiling changing options 
  283. ! (-solid, -gray, -grey, -bitmap, -rast, and -mod) may be specified at a time.
  284.   .SH OPTIONS
  285.   .PP
  286. ***************
  287. *** 48,51 ****
  288. --- 49,58 ----
  289.   program.  The entire background will be made up of repeated "tiles" of
  290.   the bitmap.
  291. + .IP "\fB-rast\fP \fIfilename\fP"
  292. + Use the sun raster file specified in the file to set the window
  293. + pattern.  You can make your own sun raster files (little pictures) using the
  294. + .I screendump(1)
  295. + program.  The entire background will be made up of repeated "tiles" of
  296. + the raster file.
  297.   .IP "\fB-mod\fP \fIx\fP \fIy\fP"
  298.   This is used if you want a plaid-like grid pattern on your screen.
  299. ***************
  300. *** 74,78 ****
  301.   Specifies the server to connect to; see \fIX(1)\fP.
  302.   .SH "SEE ALSO"
  303. ! X(1), xset(1), xrdb(1)
  304.   .SH COPYRIGHT
  305.   Copyright 1988, Massachusetts Institute of Technology.
  306. --- 81,85 ----
  307.   Specifies the server to connect to; see \fIX(1)\fP.
  308.   .SH "SEE ALSO"
  309. ! X(1), xset(1), xrdb(1), screendump(1), screenload(1)
  310.   .SH COPYRIGHT
  311.   Copyright 1988, Massachusetts Institute of Technology.
  312.  
  313. diff -rc2 X.V11R3/clients/xsetroot/Imakefile.dist X.V11R3/clients/xsetroot/Imakefile
  314. *** X.V11R3/clients/xsetroot/Imakefile.dist    Tue Nov 29 23:46:29 1988
  315. --- X.V11R3/clients/xsetroot/Imakefile    Tue Nov 29 23:47:15 1988
  316. ***************
  317. *** 1,3 ****
  318. ! LOCAL_LIBRARIES = $(XLIB)
  319.              SRCS = xsetroot.c
  320.              OBJS = xsetroot.o
  321. --- 1,3 ----
  322. ! LOCAL_LIBRARIES = $(XLIB) /usr/lib/libpixrect.a
  323.              SRCS = xsetroot.c
  324.              OBJS = xsetroot.o
  325. -- 
  326. Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
  327. Moderator of comp.sources.x
  328.