#include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_AllocColorPlanes PRIV_AllocColorPlanes; struct priv_AllocColorPlanes { int n; unsigned int *pixp; unsigned int *rmp; unsigned int *gmp; unsigned int *bmp; } ; static void done_AllocColorPlanes(LX_OP *op, const unsigned char *rep, void *pv) { PRIV_AllocColorPlanes *p; int i; p = pv; do <"ret"> { if (r_card32(rep+4) != p->n) { lx__protoerr(op->conn,"AllocColorPlanes response length wrong (%u, expecting %d)",r_card32(rep+4),p->n); break <"ret">; } if (r_card16(rep+8) != p->n) { lx__protoerr(op->conn,"AllocColorPlanes pixel count wrong (%u, expecting %d)",r_card16(rep+8),p->n); break <"ret">; } if (p->rmp) *p->rmp = r_card32(rep+12); if (p->gmp) *p->gmp = r_card32(rep+16); if (p->bmp) *p->bmp = r_card32(rep+20); if (p->pixp) for (i=p->n-1;i>=0;i--) p->pixp[i] = r_card32(rep+32+(4*i)); } while (0); free(p); } LX_OP *lx_AllocColorPlanes( LX_CONN *xc, LX_XID cmap, int contig, int ncol, int nr, int ng, int nb, unsigned int *pixp, unsigned int *rmp, unsigned int *gmp, unsigned int *bmp ) { unsigned char req[16]; PRIV_AllocColorPlanes *p; if ( (xc->flags & XCF_FAIL) || (ncol < 0) || (ncol > 65535) || (nr < 0) || (nr > 65535) || (ng < 0) || (ng > 65535) || (nb < 0) || (nb > 65535) ) { lx__bad_call(xc,"lx_AllocColorPlanes"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_AllocColorPlanes)); if (! p) { lx__nomem_fail(xc); return(0); } p->n = ncol; p->pixp = pixp; p->rmp = rmp; p->gmp = gmp; p->bmp = bmp; req[0] = XP_REQ_AllocColorPlanes; req[1] = lx__boolean_to_proto(contig); w_card16(&req[2],4); w_card32(&req[4],cmap); w_card16(&req[8],ncol); w_card16(&req[10],nr); w_card16(&req[12],ng); w_card16(&req[14],nb); return(lx__expect_reply(xc,&req[0],-1,&done_AllocColorPlanes,p)); }