--- ray/src/px/x11raster.c 1992/05/27 14:28:54 2.5 +++ ray/src/px/x11raster.c 2003/04/23 00:52:34 2.11 @@ -1,9 +1,6 @@ -/* Copyright 1990 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: x11raster.c,v 2.11 2003/04/23 00:52:34 greg Exp $"; #endif - /* * x11raster.c - routines to handle images for X windows. * @@ -14,6 +11,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include "color.h" #include "x11raster.h" @@ -41,6 +39,7 @@ int bm_pad; xr->image = XCreateImage(disp,vis->visual,vis->depth, ZPixmap,0,data,width,height,bm_pad,0); xr->image->bitmap_bit_order = MSBFirst; + xr->image->bitmap_unit = bm_pad; xr->image->byte_order = *(char *)&swaptest ? LSBFirst : MSBFirst; if (vis->depth >= 24 && (xr->image->red_mask != 0xff || xr->image->green_mask != 0xff00 || @@ -58,14 +57,14 @@ int bm_pad; int -init_rcolors(xr, rmap, gmap, bmap) /* initialize colors */ +init_rcolors(xr, cmap) /* initialize colors */ register XRASTER *xr; -int rmap[256], gmap[256], bmap[256]; +BYTE cmap[][3]; { register unsigned char *p; register int i; - if (xr->image->depth != 8 || xr->ncolors != 0) + if (xr->image->depth > 8 | xr->ncolors != 0) return(xr->ncolors); xr->pmap = (short *)malloc(256*sizeof(short)); if (xr->pmap == NULL) @@ -79,14 +78,14 @@ int rmap[256], gmap[256], bmap[256]; i = xr->image->width*xr->image->height; i--; p++) if (xr->pmap[*p] == -1) { - xr->cdefs[xr->ncolors].red = rmap[*p] << 8; - xr->cdefs[xr->ncolors].green = gmap[*p] << 8; - xr->cdefs[xr->ncolors].blue = bmap[*p] << 8; + xr->cdefs[xr->ncolors].red = cmap[*p][RED] << 8; + xr->cdefs[xr->ncolors].green = cmap[*p][GRN] << 8; + xr->cdefs[xr->ncolors].blue = cmap[*p][BLU] << 8; xr->cdefs[xr->ncolors].pixel = *p; xr->cdefs[xr->ncolors].flags = DoRed|DoGreen|DoBlue; xr->pmap[*p] = xr->ncolors++; } - xr->cdefs = (XColor *)realloc((char *)xr->cdefs, + xr->cdefs = (XColor *)realloc((void *)xr->cdefs, xr->ncolors*sizeof(XColor)); if (xr->cdefs == NULL) return(0); @@ -95,10 +94,9 @@ int rmap[256], gmap[256], bmap[256]; Colormap -newcmap(disp, scrn, w, vis) /* get colormap and fix b & w */ +newcmap(disp, scrn, vis) /* get colormap and fix b & w */ Display *disp; int scrn; -Window w; Visual *vis; { XColor thiscolor; @@ -107,9 +105,9 @@ Visual *vis; int n; register int i, j; - cmap = XCreateColormap(disp, w, vis, AllocNone); - if (cmap == 0) - return(0); + cmap = XCreateColormap(disp, RootWindow(disp,scrn), vis, AllocNone); + if (cmap == 0 || vis->class != PseudoColor) + return(cmap); pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long)); if (pixels == NULL) return(0); @@ -133,20 +131,20 @@ Visual *vis; i--; } XFreeColors(disp, cmap, pixels, n, 0); - free((char *)pixels); + free((void *)pixels); return(cmap); } unsigned long * -map_rcolors(xr, w) /* get and assign pixels */ +map_rcolors(xr, w) /* get and assign pixels */ register XRASTER *xr; Window w; { register int i; register unsigned char *p; - if (xr->ncolors == 0 || xr->image->depth != 8) + if (xr->ncolors == 0 || xr->image->depth > 8) return(NULL); if (xr->pixels != NULL) return(xr->pixels); @@ -156,13 +154,13 @@ Window w; if (xr->visual == DefaultVisual(xr->disp, xr->screen)) xr->cmap = DefaultColormap(xr->disp, xr->screen); else - xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual); + xr->cmap = newcmap(xr->disp, xr->screen, xr->visual); while (XAllocColorCells(xr->disp, xr->cmap, 0, NULL, 0, xr->pixels, xr->ncolors) == 0) if (xr->cmap == DefaultColormap(xr->disp, xr->screen)) - xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual); + xr->cmap = newcmap(xr->disp, xr->screen, xr->visual); else { - free((char *)xr->pixels); + free((void *)xr->pixels); xr->pixels = NULL; return(NULL); } @@ -189,17 +187,19 @@ Window w; Pixmap -make_rpixmap(xr, d) /* make pixmap for raster */ +make_rpixmap(xr, w) /* make pixmap for raster */ register XRASTER *xr; -Drawable d; +Window w; { + XWindowAttributes xwattr; Pixmap pm; if (xr->pm != 0) return(xr->pm); - pm = XCreatePixmap(xr->disp, d, + XGetWindowAttributes(xr->disp, w, &xwattr); + pm = XCreatePixmap(xr->disp, w, xr->image->width, xr->image->height, - xr->image->depth); + xwattr.depth); if (pm == 0) return(0); put_raster(pm, 0, 0, xr); @@ -252,7 +252,7 @@ register XRASTER *xr; XFreeColors(xr->disp, xr->cmap, xr->pixels, xr->ncolors, 0); if (xr->cmap != DefaultColormap(xr->disp, xr->screen)) XFreeColormap(xr->disp, xr->cmap); - free((char *)xr->pixels); + free((void *)xr->pixels); xr->pixels = NULL; } @@ -273,11 +273,11 @@ register XRASTER *xr; free_rpixmap(xr); if (xr->ncolors > 0) { unmap_rcolors(xr); - free((char *)xr->pmap); - free((char *)xr->cdefs); + free((void *)xr->pmap); + free((void *)xr->cdefs); } XDestroyImage(xr->image); if (xr->gc != 0) XFreeGC(xr->disp, xr->gc); - free((char *)xr); + free((void *)xr); }