--- ray/src/px/x11raster.c 1992/05/14 08:58:23 2.2 +++ ray/src/px/x11raster.c 1992/10/12 14:52:19 2.7 @@ -14,62 +14,60 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include "color.h" #include "x11raster.h" XRASTER * -make_raster(disp, scrn, depth, data, width, height, bm_pad) +make_raster(disp, vis, npixbits, data, width, height, bm_pad) Display *disp; -int scrn; -int depth; +XVisualInfo *vis; +int npixbits; char *data; int width, height; int bm_pad; { + static long swaptest = 1; register XRASTER *xr; - XVisualInfo ourvinfo; - /* Pick appropriate Visual */ - if (depth == 1) { - ourvinfo.visual = DefaultVisual(disp,scrn); - } else if (depth == 8) { - if (!XMatchVisualInfo(disp,scrn,8,PseudoColor,&ourvinfo)) - return(NULL); - } else if (depth == 24) { - if (!XMatchVisualInfo(disp,scrn,24,TrueColor,&ourvinfo) && - !XMatchVisualInfo(disp,scrn,24,DirectColor,&ourvinfo)) - return(NULL); - } else - return(NULL); + if ((xr = (XRASTER *)calloc(1, sizeof(XRASTER))) == NULL) return(NULL); xr->disp = disp; - xr->screen = scrn; - xr->visual = ourvinfo.visual; - xr->image = XCreateImage(disp,ourvinfo.visual,depth, - depth==1 ? XYBitmap : ZPixmap, - 0,data,width,height,bm_pad,0); + xr->screen = vis->screen; + xr->visual = vis->visual; + if (npixbits == 1) + xr->image = XCreateImage(disp,vis->visual,1, + XYBitmap,0,data,width,height,bm_pad,0); + else + xr->image = XCreateImage(disp,vis->visual,vis->depth, + ZPixmap,0,data,width,height,bm_pad,0); xr->image->bitmap_bit_order = MSBFirst; - xr->image->byte_order = MSBFirst; - if (xr->image->bits_per_pixel == 32) { - xr->image->bytes_per_line = xr->image->bytes_per_line*24/32; - xr->image->bits_per_pixel = 24; + 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 || + xr->image->blue_mask != 0xff0000) && + (xr->image->red_mask != 0xff0000 || + xr->image->green_mask != 0xff00 || + xr->image->blue_mask != 0xff)) { + xr->image->red_mask = 0xff; + xr->image->green_mask = 0xff00; + xr->image->blue_mask = 0xff0000; } - xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0); - XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn), - GXcopy, AllPlanes); + xr->gc = 0; return(xr); } 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) @@ -83,9 +81,9 @@ 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++; @@ -97,6 +95,7 @@ int rmap[256], gmap[256], bmap[256]; return(xr->ncolors); } + Colormap newcmap(disp, scrn, w, vis) /* get colormap and fix b & w */ Display *disp; @@ -149,7 +148,7 @@ 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); @@ -192,16 +191,19 @@ Window w; Pixmap -make_rpixmap(xr) /* make pixmap for raster */ +make_rpixmap(xr, w) /* make pixmap for raster */ register XRASTER *xr; +Window w; { + XWindowAttributes xwattr; Pixmap pm; if (xr->pm != 0) return(xr->pm); - pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen), + XGetWindowAttributes(xr->disp, w, &xwattr); + pm = XCreatePixmap(xr->disp, w, xr->image->width, xr->image->height, - DisplayPlanes(xr->disp, xr->screen)); + xwattr.depth); if (pm == 0) return(0); put_raster(pm, 0, 0, xr); @@ -232,6 +234,11 @@ register XRASTER *xr; if (ysrc + height > xr->image->height) height = xr->image->height - ysrc; + if (xr->gc == 0) { + xr->gc = XCreateGC(xr->disp, d, 0, 0); + XSetState(xr->disp, xr->gc, BlackPixel(xr->disp,xr->screen), + WhitePixel(xr->disp,xr->screen), GXcopy, AllPlanes); + } if (xr->pm == 0) XPutImage(xr->disp, d, xr->gc, xr->image, xsrc, ysrc, xdst, ydst, width, height); @@ -274,6 +281,7 @@ register XRASTER *xr; free((char *)xr->cdefs); } XDestroyImage(xr->image); - XFreeGC(xr->disp, xr->gc); + if (xr->gc != 0) + XFreeGC(xr->disp, xr->gc); free((char *)xr); }