From: Maurice L. <ml...@us...> - 2005-03-23 09:51:37
|
Update of /cvsroot/plplot/plplot/drivers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23556 Modified Files: xwin.c Log Message: Allocate space at startup for cmap0 & cmap1 XColor arrays, and free upon exit. In AllocCmap0(), do a realloc if pls->ncol0 increases above currently the allocated space. (No need in cmap1 since the internal number is fixed.) Index: xwin.c =================================================================== RCS file: /cvsroot/plplot/plplot/drivers/xwin.c,v retrieving revision 1.124 retrieving revision 1.125 diff -u -d -r1.124 -r1.125 --- xwin.c 8 Mar 2005 05:39:21 -0000 1.124 +++ xwin.c 23 Mar 2005 09:51:28 -0000 1.125 @@ -547,6 +547,8 @@ XFreeGC(xwd->display, dev->gc); XFreeGC(xwd->display, xwd->gcXor); XCloseDisplay(xwd->display); + free_mem(xwd->cmap0); + free_mem(xwd->cmap1); free_mem(xwDisplay[ixwd]); } /* ANR: if we set this here the tmp file will not be closed */ @@ -925,18 +927,15 @@ if (synchronize) XSynchronize(xwd->display, 1); -/* Get colormap and visual */ - + /* Get colormap and visual */ xwd->map = DefaultColormap(xwd->display, xwd->screen); - GetVisual(pls); -/* - * Figure out if we have a color display or not. - * Default is color IF the user hasn't specified and IF the output device is - * not grayscale. - */ - + /* + * Figure out if we have a color display or not. + * Default is color IF the user hasn't specified and IF the output device + * is not grayscale. + */ if (pls->colorset) xwd->color = pls->color; else { @@ -944,8 +943,18 @@ xwd->color = ! AreWeGrayscale(xwd->display); } -/* Allocate & set background and foreground colors */ + /* Allocate space for colors */ + xwd->ncol0_alloc = pls->ncol0; + xwd->cmap0 = (XColor *) calloc(pls->ncol0, (size_t) sizeof(XColor)); + if (xwd->cmap0 == 0) + plexit("couldn't allocate space for cmap0 colors"); + + xwd->ncol1_alloc = CMAP1_COLORS; + xwd->cmap1 = (XColor *) calloc(CMAP1_COLORS, (size_t) sizeof(XColor)); + if (xwd->cmap1 == 0) + plexit("couldn't allocate space for cmap1 colors"); + /* Allocate & set background and foreground colors */ AllocBGFG(pls); SetBGFG(pls); } @@ -2791,6 +2800,15 @@ XFreeColors(xwd->display, xwd->map, &pixel, 1, 0); } +/* If the number of colors increased, need to allocate enough space for them */ + if ( pls->ncol0 > xwd->ncol0_alloc ) { + xwd->ncol0_alloc = pls->ncol0; + xwd->cmap0 = (XColor *) + realloc( xwd->cmap0, (size_t) pls->ncol0 * sizeof(XColor) ); + if (xwd->cmap0 == 0) + plexit("couldn't allocate space for cmap0 colors"); + } + if (xwd->rw_cmap) { int npixels; unsigned long plane_masks[1], pixels[MAX_COLORS]; |