Ejemplo n.º 1
0
void
scalePixmap (Display * dpy, MyPixmap * src, MyPixmap * dst, int width,
	     int height)
{
  XpmImage xi_src, xi_dst;
  int x, y, sx, sy;
  unsigned int *src_data, *dst_data;

#ifdef DEBUG
  printf ("entering scalePixmap\n");
#endif

  /* don't ask me why but sometimes this function gets _REALLY_ big imagesizes
   * so there must be something totally wrong somewhere... */
  if (width > 20000)
    return;
  if (height > 20000)
    return;
  if (width < 1)
    return;
  if (height < 1)
    return;
  /* I currently don't know exactly but it _IS_ a bug in here */

  XpmCreateXpmImageFromPixmap (dpy, src->pixmap, src->mask, &xi_src, NULL);
  dst->width = width;
  dst->height = height;
  xi_dst.width = width;
  xi_dst.height = height;
  xi_dst.cpp = xi_src.cpp;
  xi_dst.ncolors = xi_src.ncolors;
  xi_dst.colorTable = xi_src.colorTable;
  xi_dst.data = malloc (sizeof (int) * (xi_dst.width * xi_dst.height));
  dst_data = xi_dst.data;
  src_data = xi_src.data;
#ifdef DEBUG
  printf ("xi_dst.width %i\n", xi_dst.width);
  printf ("xi_dst.height %i\n", xi_dst.height);
  printf ("xi_src.width %i\n", xi_src.width);
  printf ("xi_src.height %i\n", xi_src.height);
#endif
  for (y = 0; y < xi_dst.height; y++)
    {
      dst_data = xi_dst.data + (y * xi_dst.width);
      for (x = 0; x < xi_dst.width; x++)
	{
	  sx = (x * xi_src.width) / xi_dst.width;
	  sy = (y * xi_src.height) / xi_dst.height;
	  *dst_data = *(src_data + sx + (sy * xi_src.width));
	  dst_data++;
	}
    }
  XpmCreatePixmapFromXpmImage (dpy, DefaultRootWindow (dpy), &xi_dst,
			       &dst->pixmap, &dst->mask, NULL);
  free (xi_dst.data);
  XpmFreeXpmImage (&xi_src);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
int
SetPixmapsBackground(Image * image, Drawable drawable, Pixel color)
{
  XpmImage xpmimage;
  XpmAttributes xpmattr;
  XpmColorSymbol xpmcolor[1];
  unsigned int i;

  xpmattr.valuemask = XpmCloseness;
  xpmattr.closeness = 32768;

  /*
   * By default, the XPM library assumes screen 0, so we have
   * to pass in the real values. Submitted by Caveh Frank Jalali
   */
  xpmattr.valuemask |= XpmVisual | XpmColormap | XpmDepth;
  xpmattr.visual = Scr->d_visual;
  xpmattr.colormap = XDefaultColormap(dpy, Scr->screen);
  xpmattr.depth = Scr->d_depth;

  if (XpmCreateXpmImageFromPixmap(dpy, image->pixmap, image->mask, &xpmimage, &xpmattr) != XpmSuccess)
  {
    fprintf(stderr, "Failed to XpmCreateImage\n");
    return (0);
  }

  for (i = 0; i < xpmimage.ncolors; i++)
    if (!strcmp(xpmimage.colorTable[i].c_color, "None"))
      break;

  if (i < xpmimage.ncolors)
  {
    XFreePixmap(dpy, image->pixmap);
    XFreePixmap(dpy, image->mask);

    xpmcolor[0].name = NULL;
    xpmcolor[0].value = "none";
    xpmcolor[0].pixel = color;

    xpmattr.colorsymbols = xpmcolor;
    xpmattr.numsymbols = 1;
    xpmattr.valuemask |= XpmColorSymbols;

    XpmCreatePixmapFromXpmImage(dpy, drawable, &xpmimage, &image->pixmap, &image->mask, &xpmattr);
  }

  i = xpmimage.ncolors;
  XpmFreeXpmImage(&xpmimage);

  return (i);
}
Ejemplo n.º 4
0
Archivo: icons.c Proyecto: att/uwin
/****************************************************************************
 *
 * 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 */
}
Ejemplo n.º 5
0
Archivo: icons.c Proyecto: att/uwin
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;
}