#include #include #include "lx.h" #include "proto.h" #include "internal.h" void lx_StoreColors(LX_CONN *xc, LX_XID cmap, int n, const LX_RGBPF *items) { unsigned char *req; int reqlen; int i; int o; unsigned int f; if (xc->flags & XCF_FAIL) { lx__bad_call(xc,"lx_StoreColors"); return; } lx__nochain(xc); if ((n < 0) || (n > (65535-2)/3)) { lx__bad_call(xc,"lx_StoreColors"); return; } reqlen = 2 + (3 * n); req = malloc(reqlen); if (! req) { lx__nomem_fail(xc); return; } req[0] = XP_REQ_StoreColors; req[1] = 0; w_card16(req+2,reqlen); w_card32(req+4,cmap); o = 8 + (12 * (n - 1)); for (i=n-1;i>=0;i--,o-=12) { w_card32(req+o,items[i].pixel); w_card16(req+o+4,items[i].r); w_card16(req+o+6,items[i].g); w_card16(req+o+8,items[i].b); f = items[i].flags; if (f & ~LX_DO_ALL) { free(req); lx__bad_call(xc,"lx_StoreColors"); return; } #if (LX_DO_R == 1) && (LX_DO_G == 2) && (LX_DO_B == 4) req[o+10] = f; #else req[o+10] = ((f & LX_DO_R) ? 1 : 0) | ((f & LX_DO_G) ? 2 : 0) | ((f & LX_DO_B) ? 4 : 0); #endif } lx__send_req_free(xc,req,reqlen*4); }