예제 #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);
}
예제 #2
0
파일: image_formats.c 프로젝트: mcr/vtwm
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);
}