FVWM: patch for using 24-bit ppms as icons

From: Vladimir Vukicevic <vladimir_at_intrepid.com>
Date: Sat, 30 Mar 1996 15:14:19 -0800

Hi, here's a patch to 2.0.41 for using 24-bit ppms as icon files. This
has only been tested on a 24-bit truecolor visual; chances are that it'll
work on a 16-bit visual. It almost definitively won't work on a 8-bit
visual. #define PPM needs to be somewhere, I put it in configure.h.
Enjoy!

        -- Vladimir
        -- vladimir_at_intrepid.com

diff -ur ../fvwm-2.0.41/configure.h fvwm-2.0.41/configure.h
--- ../fvwm-2.0.41/configure.h Fri Feb 16 17:13:18 1996
+++ fvwm-2.0.41/configure.h Fri Mar 29 21:59:29 1996
_at_@ -52,6 +52,8 @@
 
 #endif /* End of do-it-yourself OS support section */
 
+/* Define for experimental PPM support */
+#define PPM
 
 /***************************************************************************
  * Please translate the strings into the language which you use for
diff -ur ../fvwm-2.0.41/fvwm/icons.c fvwm-2.0.41/fvwm/icons.c
--- ../fvwm-2.0.41/fvwm/icons.c Mon Nov 6 08:49:36 1995
+++ fvwm-2.0.41/fvwm/icons.c Sat Mar 30 01:59:54 1996
_at_@ -70,6 +70,11 @@
   if(tmp_win->icon_bitmap_file != NULL)
     GetBitmapFile(tmp_win);
 
+ /* Next, check for a color PPM */
+ if((tmp_win->icon_bitmap_file != NULL)&&
+ (tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0))
+ GetPPMFile(tmp_win);
+
   /* Next, check for a color pixmap */
   if((tmp_win->icon_bitmap_file != NULL)&&
      (tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0))
_at_@ -615,6 +620,90 @@
   free(path);
 #endif /* XPM */
 }
+
+/****************************************************************************
+ *
+ * Looks for a color PPM icon file
+ *
+ ****************************************************************************/
+void GetPPMFile(FvwmWindow *tmp_win)
+{
+#ifdef PPM
+ Pixmap pix = 0;
+ XImage *ximg = NULL;
+ char *pixptr = NULL;
+ char *buf = NULL;
+ FILE *ppmfile = NULL;
+ extern char *PixmapPath;
+ char *path = NULL;
+ int width, height, maxval;
+
+ /* Only deal with 24-bit depths */
+ if (DefaultDepth(dpy, Scr.screen) != 24) return;
+
+ path = findIconFile (tmp_win->icon_bitmap_file, PixmapPath, R_OK);
+ if (path == NULL) return;
+
+ if ((ppmfile = fopen(path, "rb")) == NULL) goto error;
+ if ((buf = malloc (sizeof(char) * 256)) == NULL) goto error;
+
+ /* Read specs about the file */
+ fgets(buf, 256, ppmfile);
+
+ /* If not a binary ppm file... */
+ if (strncmp (buf, "P6", 2) != 0) goto error;
+
+ /* Read width, height, depth */
+ fgets(buf, 256, ppmfile);
+ sscanf (buf, "%d %d", &width, &height);
+ fgets(buf, 256, ppmfile);
+ sscanf (buf, "%d", &maxval);
+
+ /* Allocate & read data */
+ if ((pixptr = malloc (sizeof(char) * (width * height * 3 + 1))) == NULL)
+ goto error;
+
+ if (fread ((void *)pixptr, sizeof(char), width*height*3, ppmfile)
+ < width*height*3)
+ goto error;
+
+ /* Now make a pixmap */
+ pix = XCreatePixmap (dpy, Scr.Root, width, height, 24);
+ ximg = malloc(sizeof(XImage));
+ fprintf(dbg, "ppm: 5\n"); fflush(dbg);
+ ximg->width = width;
+ ximg->height = height;
+ ximg->xoffset = 0;
+ ximg->format = ZPixmap;
+ ximg->data = pixptr; pixptr = 0; /* so we don't free it */
+ ximg->byte_order = MSBFirst;
+ ximg->bitmap_unit = 8;
+ ximg->bitmap_bit_order = MSBFirst;
+ ximg->bitmap_pad = 8;
+ ximg->depth = 24;
+ ximg->bytes_per_line = width*3;
+ ximg->bits_per_pixel = 24;
+ ximg->red_mask = 0xff0000;
+ ximg->green_mask = 0x00ff00;
+ ximg->blue_mask = 0x0000ff;
+ XInitImage(ximg);
+
+ XPutImage (dpy, pix, DefaultGC(dpy, Scr.screen), ximg, 0, 0, 0, 0,
+ width, height);
+ tmp_win->iconPixmap = pix;
+ tmp_win->icon_maskPixmap = 0;
+ tmp_win->icon_p_width = width;
+ tmp_win->icon_p_height = height;
+ tmp_win->flags |= PIXMAP_OURS;
+ tmp_win->iconDepth = 24;
+error:
+ fclose(dbg);
+ if (ppmfile) fclose(ppmfile);
+ if (buf) free(buf);
+ free(path);
+#endif /* PPM */
+}
+
 
 /****************************************************************************
  *
diff -ur ../fvwm-2.0.41/fvwm/misc.h fvwm-2.0.41/fvwm/misc.h
--- ../fvwm-2.0.41/fvwm/misc.h Sun Feb 18 16:08:32 1996
+++ fvwm-2.0.41/fvwm/misc.h Fri Mar 29 22:00:59 1996
_at_@ -231,6 +231,7 @@
 int find_func_type(char *action);
 extern void GetBitmapFile(FvwmWindow *tmp_win);
 extern void GetXPMFile(FvwmWindow *tmp_win);
+extern void GetPPMFile(FvwmWindow *tmp_win);
 extern void GetIconWindow(FvwmWindow *tmp_win);
 extern void GetIconBitmap(FvwmWindow *tmp_win);
 extern void SmartPlacement(FvwmWindow *t, int width, int height,int *x,int *y);

--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Sat Mar 30 1996 - 17:13:08 GMT

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:58 BST