#include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_AllocColor PRIV_AllocColor; struct priv_AllocColor { unsigned int *pixp; unsigned int *rp; unsigned int *gp; unsigned int *bp; } ; static void done_AllocColor(LX_OP *op, const unsigned char *rep) { PRIV_AllocColor *p; unsigned int pix; unsigned int r; unsigned int g; unsigned int b; p = op->reqpriv; do <"ret"> { if (r_card32(rep+4) != 0) { lx__protoerr(op->conn,"AllocColor response length wrong (%u, expecting 0)",r_card32(rep+4)); break <"ret">; } r = r_card16(rep+8); g = r_card16(rep+10); b = r_card16(rep+12); pix = r_card32(rep+16); if (p->pixp) *p->pixp = pix; if (p->rp) *p->rp = r; if (p->gp) *p->gp = g; if (p->bp) *p->bp = b; } while (0); op->reqpriv = 0; free(p); } LX_OP *lx_AllocColor( LX_CONN *xc, LX_XID cmap, unsigned int r, unsigned int g, unsigned int b, unsigned int *pixp, unsigned int *rp, unsigned int *gp, unsigned int *bp ) { unsigned char req[16]; PRIV_AllocColor *p; if ( (xc->flags & XCF_FAIL) || (r > 65535) || (g > 65535) || (b > 65535) ) { lx__bad_call(xc,"lx_AllocColor"); return(0); } p = malloc(sizeof(PRIV_AllocColor)); if (! p) { lx__nomem_fail(xc); return(0); } p->pixp = pixp; p->rp = rp; p->gp = gp; p->bp = bp; req[0] = XP_REQ_AllocColor; req[1] = 0; w_card16(&req[2],4); w_card32(&req[4],cmap); w_card16(&req[8],r); w_card16(&req[10],g); w_card16(&req[12],b); w_card16(&req[14],0); return(lx__expect_reply(xc,&req[0],-1,&done_AllocColor,p)); }