#include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_AllocColorCells PRIV_AllocColorCells; struct priv_AllocColorCells { int nc; int np; unsigned int *pixp; unsigned int *planep; } ; static void done_AllocColorCells(LX_CONN *xc, const unsigned char *rep, void *pv) { PRIV_AllocColorCells *p; int i; int o; p = pv; do <"ret"> { if (r_card32(rep+4) != p->nc+p->np) { lx__protoerr(xc,"AllocColorCells response length wrong (%u, expecting %d)",r_card32(rep+4),p->nc+p->np); break <"ret">; } if (r_card16(rep+8) != p->nc) { lx__protoerr(xc,"AllocColorCells pixel count wrong (%u, expecting %d)",r_card16(rep+8),p->nc); break <"ret">; } if (r_card16(rep+10) != p->np) { lx__protoerr(xc,"AllocColorCells plane count wrong (%u, expecting %d)",r_card16(rep+8),p->np); break <"ret">; } if (p->pixp) { o = 32; for (i=p->nc-1;i>=0;i--) p->pixp[i] = r_card32(rep+o+(4*i)); } if (p->planep) { o = 32 + (4 * p->nc); for (i=p->np-1;i>=0;i--) p->planep[i] = r_card32(rep+o+(4*i)); } } while (0); free(p); } LX_OP *lx_AllocColorCells(LX_CONN *xc, LX_XID cmap, int contig, int ncol, int nplanes, unsigned int *pixp, unsigned int *planep) { unsigned char req[12]; PRIV_AllocColorCells *p; if ( (xc->flags & XCF_FAIL) || (ncol < 0) || (ncol > 65535) || (nplanes < 0) || (nplanes > 65535) ) { lx__bad_call(xc,"lx_AllocColorCells"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_AllocColorCells)); if (! p) { lx__nomem_fail(xc); return(0); } p->nc = ncol; p->np = nplanes; p->pixp = pixp; p->planep = planep; req[0] = XP_REQ_AllocColorCells; req[1] = lx__boolean_to_proto(contig); w_card16(&req[2],3); w_card32(&req[4],cmap); w_card16(&req[8],ncol); w_card16(&req[10],nplanes); return(lx__expect_reply(xc,&req[0],-1,&done_AllocColorCells,p)); }