Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!shelby!decwrl!gnomee.pa.dec.com!kent From: kent@gnomee.pa.dec.com (Christopher A. Kent) Newsgroups: comp.windows.x Subject: Re: Colormaps (was ...and Visuals) Message-ID: <1890@bacchus.dec.com> Date: 4 Oct 89 22:55:21 GMT References: <8909210815.AA26154@Larry.McRCIM.McGill.EDU> Sender: news@decwrl.dec.com Lines: 49 I had the same problem, and came up with the following code. It's not pretty, and it doesn't leave the cells sharable, but it works. static Bool _AllocContiguousCells(dpy, cmap, pixels, npixels) Display *dpy; Colormap cmap; unsigned long *pixels; /* filled in by routine */ int npixels; { unsigned long *waste = (unsigned long *)NULL; int nwaste = 0; Bool contig = False; int status, i; unsigned long masks = NULL; while (!contig) { status = XAllocColorCells(dpy, cmap, False, &masks, 0, pixels, npixels); if (!status) break; /* can't get enough contiguous cells */ for (i=0; i < (npixels-1); i++) { if (pixels[i] + 1 != pixels[i+1]) { /* isn't contiguous, keep trying */ XFreeColors(dpy, cmap, &pixels[i+1], npixels - (i+1), 0); if (!waste) waste = (unsigned long *)malloc((i + 1) * sizeof(unsigned long)); else waste = (unsigned long *)realloc(waste, (nwaste + (i + 1)) * sizeof(unsigned long)); bcopy(pixels, waste+nwaste, (i+1) * sizeof(unsigned long)); nwaste += (i+1); break; } } if (i == (npixels-1)) contig = True; } /* clean up and return 'contig' */ if (nwaste) { XFreeColors(dpy, cmap, waste, nwaste, 0); free(waste); } return (contig); } Chris Kent Western Software Laboratory Digital Equipment Corporation kent@decwrl.dec.com decwrl!kent (415) 853-6639