#include #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_GetImage PRIV_GetImage; struct priv_GetImage { int *depthp; LX_XID *visualp; int *sizep; void **bitsp; } ; static void done_GetImage(LX_OP *op, const unsigned char *rep, void *pv) { PRIV_GetImage *p; int len; LX_XID v; char *data; p = pv; do <"ret"> { if (p->depthp) *p->depthp = rep[1]; len = r_card32(rep+4); if (p->visualp) { v = r_card32(rep+8); if (v == 0) v = LX_VISUAL_None; *p->visualp = v; } if (p->sizep) *p->sizep = len * 4; if (p->bitsp) { data = malloc(len*4); if (! data) { lx__nomem_fail(op->conn); break <"ret">; } bcopy(rep+32,data,len+4); *p->bitsp = data; } } while (0); free(p); } LX_OP *lx_GetImage( LX_CONN *xc, LX_XID drawable, LX_IMAGEFORMAT fmt, int x, int y, int w , int h, unsigned int planes, int *depthp, LX_XID *visualp, int *sizep, void **bitsp) { unsigned char req[20]; PRIV_GetImage *p; int pf; if ( (xc->flags & XCF_FAIL) || (x < -32768) || (x > 32767) || (y < -32768) || (y > 32767) || (w < 0) || (w > 65535) || (h < 0) || (h > 65535) || (fmt == LX_IMAGEFORMAT_Bitmap) ) { lx__bad_call(xc,"lx_GetImage"); return(0); } lx__nochain(xc); pf = lx__imageformat_to_proto(fmt); if (pf < 0) { lx__bad_call(xc,"lx_GetImage"); return(0); } p = malloc(sizeof(PRIV_GetImage)); if (! p) { lx__nomem_fail(xc); return(0); } p->depthp = depthp; p->visualp = visualp; p->sizep = sizep; p->bitsp = bitsp; req[0] = XP_REQ_GetImage; req[1] = pf; w_card16(&req[2],5); w_card32(&req[4],drawable); w_int16(&req[8],x); w_int16(&req[10],y); w_card16(&req[12],w); w_card16(&req[14],y); w_card32(&req[16],planes); return(lx__expect_reply(xc,&req[0],-1,&done_GetImage,p)); }