FvwmPicture *LoadPicture(Display *dpy,Window Root,char *path, int color_limit) { int l; FvwmPicture *p; #ifdef XPM XpmAttributes xpm_attributes; int rc; XpmImage my_image = {0}; #endif p=(FvwmPicture*)safemalloc(sizeof(FvwmPicture)); p->count=1; p->name=path; p->next=NULL; #ifdef XPM /* Try to load it as an X Pixmap first */ xpm_attributes.colormap=PictureCMap; xpm_attributes.closeness=40000; /* Allow for "similar" colors */ xpm_attributes.valuemask= XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; rc =XpmReadFileToXpmImage(path, &my_image, NULL); if (rc == XpmSuccess) { color_reduce_pixmap(&my_image, color_limit); rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, &p->picture,&p->mask, &xpm_attributes); if (rc == XpmSuccess) { p->width = my_image.width; p->height = my_image.height; XpmFreeXpmImage(&my_image); p->depth = DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy)); return p; } XpmFreeXpmImage(&my_image); } #endif /* If no XPM support, or XPM loading failed, try bitmap */ if(XReadBitmapFile(dpy,Root,path,&p->width,&p->height,&p->picture,&l,&l) == BitmapSuccess) { p->depth = 0; p->mask = None; return p; } free(p); return NULL; }
/**************************************************************************** * * Looks for a color XPM icon file * ****************************************************************************/ void GetXPMFile(struct icon_info *item) { #ifdef XPM XpmAttributes xpm_attributes; char *path = NULL; int rc; XpmImage my_image; path = findImageFile(item->icon_file, imagePath,R_OK); if(path == NULL)return; rc = XpmReadFileToXpmImage(path, &my_image, NULL); if (rc != XpmSuccess) { fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); free(path); return; } color_reduce_pixmap(&my_image,save_color_limit); xpm_attributes.visual = Pvisual; xpm_attributes.colormap = Pcmap; xpm_attributes.depth = Pdepth; xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ xpm_attributes.valuemask = XpmVisual | XpmColormap | XpmDepth | XpmCloseness | XpmReturnPixels; rc = XpmCreatePixmapFromXpmImage(dpy,main_win, &my_image, &item->iconPixmap, &item->icon_maskPixmap, &xpm_attributes); if (rc != XpmSuccess) { fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc); free(path); return; } item->icon_w = min(max_icon_width, my_image.width); item->icon_h = min(max_icon_height, my_image.height); item->icon_depth = Pdepth; free(path); #endif /* XPM */ }
Bool GetBackPixmap(void) { #ifdef XPM XpmAttributes xpm_attributes; XpmImage my_image; Pixmap maskPixmap; int rc; #endif char *path = NULL; Pixmap tmp_bitmap; int x, y, w=0, h=0; if (IconwinPixmapFile == NULL) return False; if ((path = findImageFile(IconwinPixmapFile, imagePath,R_OK)) != NULL){ if (XReadBitmapFile(dpy, main_win ,path,(unsigned int *)&w, (unsigned int *)&h, &tmp_bitmap, (int *)&x, (int *)&y)!= BitmapSuccess) w = h = 0; else{ IconwinPixmap = XCreatePixmap(dpy, main_win, w, h, Pdepth); XCopyPlane(dpy, tmp_bitmap, IconwinPixmap, NormalGC, 0, 0, w, h, 0, 0, 1); XFreePixmap(dpy, tmp_bitmap); } free(path); } #ifdef XPM if ( w == 0 && h == 0 && (path = findImageFile(IconwinPixmapFile, imagePath,R_OK)) != NULL) { rc = XpmReadFileToXpmImage(path, &my_image, NULL); if (rc != XpmSuccess) { fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); free(path); return False; } color_reduce_pixmap(&my_image,save_color_limit); xpm_attributes.visual = Pvisual; xpm_attributes.colormap = Pcmap; xpm_attributes.depth = Pdepth; xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ xpm_attributes.valuemask = XpmVisual | XpmColormap | XpmDepth | XpmCloseness | XpmReturnPixels; rc = XpmCreatePixmapFromXpmImage(dpy, main_win, &my_image, &IconwinPixmap, &maskPixmap, &xpm_attributes); if (rc != XpmSuccess) { fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc); free(path); return False; } w = my_image.width; h = my_image.height; free(path); } #endif if (w != 0 && h != 0) return True; return False; }