|
|
1.1 ! root 1: #include "copyright.h" ! 2: ! 3: /* $Header: XGetImage.c,v 11.17 87/09/13 20:21:40 newman Exp $ */ ! 4: /* Copyright Massachusetts Institute of Technology 1986 */ ! 5: ! 6: #define NEED_REPLIES ! 7: #include "Xlibint.h" ! 8: #include <errno.h> ! 9: ! 10: #define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad)) ! 11: ! 12: extern XImage *XCreateImage(); ! 13: ! 14: static int Ones(mask) /* HACKMEM 169 */ ! 15: unsigned long mask; ! 16: { ! 17: register int y; ! 18: ! 19: y = (mask >> 1) &033333333333; ! 20: y = mask - y - ((y >>1) & 033333333333); ! 21: return (((y + (y >> 3)) & 030707070707) % 077); ! 22: } ! 23: ! 24: XImage *XGetImage (dpy, d, x, y, width, height, plane_mask, format) ! 25: register Display *dpy; ! 26: Drawable d; ! 27: int x, y; ! 28: unsigned int width, height; ! 29: long plane_mask; ! 30: int format; /* either XYPixmap or ZPixmap */ ! 31: { ! 32: xGetImageReply rep; ! 33: register xGetImageReq *req; ! 34: char *data; ! 35: long nbytes; ! 36: XImage *image; ! 37: LockDisplay(dpy); ! 38: GetReq (GetImage, req); ! 39: /* ! 40: * first set up the standard stuff in the request ! 41: */ ! 42: req->drawable = d; ! 43: req->x = x; ! 44: req->y = y; ! 45: req->width = width; ! 46: req->height = height; ! 47: req->planeMask = plane_mask; ! 48: req->format = format; ! 49: ! 50: if (_XReply (dpy, (xReply *) &rep, 0, xFalse) == 0) { ! 51: UnlockDisplay(dpy); ! 52: SyncHandle(); ! 53: return (XImage *)NULL; ! 54: } ! 55: ! 56: nbytes = (long)rep.length << 2; ! 57: data = (char *) Xmalloc((unsigned) nbytes); ! 58: _XReadPad (dpy, data, nbytes); ! 59: if (format == XYPixmap) ! 60: image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual), ! 61: Ones (plane_mask & ((1 << rep.depth) - 1)), ! 62: format, 0, data, width, height, dpy->bitmap_pad, 0); ! 63: else /* format == ZPixmap */ ! 64: image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual), ! 65: rep.depth, ZPixmap, 0, data, width, height, ! 66: _XGetScanlinePad(dpy, rep.depth), 0); ! 67: ! 68: UnlockDisplay(dpy); ! 69: SyncHandle(); ! 70: return (image); ! 71: } ! 72: ! 73: XGetSubImage(dpy, d, x, y, width, height, plane_mask, format, ! 74: dest_image, dest_x, dest_y) ! 75: register Display *dpy; ! 76: Drawable d; ! 77: int x, y; ! 78: unsigned int width, height; ! 79: unsigned long plane_mask; ! 80: int format; /* either XYFormat or ZFormat */ ! 81: XImage *dest_image; ! 82: int dest_x, dest_y; ! 83: { ! 84: XImage *temp_image; ! 85: temp_image = XGetImage(dpy, d, x, y, width, height, ! 86: plane_mask, format); ! 87: _XSetImage(temp_image, dest_image, dest_x, dest_y); ! 88: _XDestroyImage(temp_image); ! 89: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.