97 lines
2.3 KiB
C
97 lines
2.3 KiB
C
/* convert_x11.c - X11 backend for RImage → Pixmap conversion */
|
|
|
|
#include <config.h>
|
|
#include <X11/Xlib.h>
|
|
#include <X11/Xutil.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "wraster.h"
|
|
#include "convert.h"
|
|
#include "xutil.h"
|
|
|
|
int x11_convert_image(RContext *context, RImage *image, Pixmap *pixmap)
|
|
{
|
|
RXImage *ximg = NULL;
|
|
#ifdef USE_XSHM
|
|
Pixmap tmp;
|
|
#endif
|
|
|
|
switch (context->vclass) {
|
|
case TrueColor:
|
|
ximg = image2TrueColor(context, image);
|
|
break;
|
|
case PseudoColor:
|
|
case StaticColor:
|
|
if (context->attribs->standard_colormap_mode != RIgnoreStdColormap)
|
|
ximg = image2StandardPseudoColor(context, image);
|
|
else
|
|
ximg = image2PseudoColor(context, image);
|
|
break;
|
|
case GrayScale:
|
|
case StaticGray:
|
|
ximg = image2GrayScale(context, image);
|
|
break;
|
|
}
|
|
|
|
if (!ximg)
|
|
return False;
|
|
|
|
*pixmap = XCreatePixmap(context->dpy, context->drawable,
|
|
image->width, image->height, context->depth);
|
|
|
|
#ifdef USE_XSHM
|
|
if (context->flags.use_shared_pixmap && ximg->is_shared)
|
|
tmp = R_CreateXImageMappedPixmap(context, ximg);
|
|
else
|
|
tmp = None;
|
|
if (tmp) {
|
|
XCopyArea(context->dpy, tmp, *pixmap, context->copy_gc,
|
|
0, 0, image->width, image->height, 0, 0);
|
|
XFreePixmap(context->dpy, tmp);
|
|
} else {
|
|
RPutXImage(context, *pixmap, context->copy_gc, ximg,
|
|
0, 0, 0, 0, image->width, image->height);
|
|
}
|
|
#else
|
|
RPutXImage(context, *pixmap, context->copy_gc, ximg,
|
|
0, 0, 0, 0, image->width, image->height);
|
|
#endif
|
|
|
|
RDestroyXImage(context, ximg);
|
|
return True;
|
|
}
|
|
|
|
int x11_convert_image_mask(RContext *context, RImage *image,
|
|
Pixmap *pixmap, Pixmap *mask, int threshold)
|
|
{
|
|
GC gc;
|
|
XGCValues gcv;
|
|
RXImage *ximg;
|
|
|
|
if (!RConvertImage(context, image, pixmap))
|
|
return False;
|
|
|
|
if (image->format == RRGBFormat) {
|
|
*mask = None;
|
|
return True;
|
|
}
|
|
|
|
ximg = image2Bitmap(context, image, threshold);
|
|
if (!ximg)
|
|
return False;
|
|
|
|
*mask = XCreatePixmap(context->dpy, context->drawable,
|
|
image->width, image->height, 1);
|
|
gcv.foreground = context->black;
|
|
gcv.background = context->white;
|
|
gcv.graphics_exposures = False;
|
|
gc = XCreateGC(context->dpy, *mask,
|
|
GCForeground | GCBackground | GCGraphicsExposures, &gcv);
|
|
RPutXImage(context, *mask, gc, ximg, 0, 0, 0, 0,
|
|
image->width, image->height);
|
|
RDestroyXImage(context, ximg);
|
|
XFreeGC(context->dpy, gc);
|
|
return True;
|
|
}
|