| 14 |
|
#include <X11/Xlib.h> |
| 15 |
|
#include <X11/Xutil.h> |
| 16 |
|
|
| 17 |
+ |
#include "color.h" |
| 18 |
|
#include "x11raster.h" |
| 19 |
|
|
| 20 |
+ |
extern char *malloc(), *realloc(), *calloc(); |
| 21 |
|
|
| 22 |
+ |
|
| 23 |
|
XRASTER * |
| 24 |
< |
make_raster(disp, scrn, depth, data, width, height, bm_pad) |
| 24 |
> |
make_raster(disp, vis, npixbits, data, width, height, bm_pad) |
| 25 |
|
Display *disp; |
| 26 |
< |
int scrn; |
| 27 |
< |
int depth; |
| 26 |
> |
XVisualInfo *vis; |
| 27 |
> |
int npixbits; |
| 28 |
|
char *data; |
| 29 |
|
int width, height; |
| 30 |
|
int bm_pad; |
| 31 |
|
{ |
| 32 |
+ |
static long swaptest = 1; |
| 33 |
|
register XRASTER *xr; |
| 34 |
< |
XVisualInfo ourvinfo; |
| 31 |
< |
/* Pick appropriate Visual */ |
| 32 |
< |
if (depth == 1) { |
| 33 |
< |
ourvinfo.visual = DefaultVisual(disp,scrn); |
| 34 |
< |
} else if (depth == 8) { |
| 35 |
< |
if (!XMatchVisualInfo(disp,scrn,8,PseudoColor,&ourvinfo)) |
| 36 |
< |
return(NULL); |
| 37 |
< |
} else if (depth == 24) { |
| 38 |
< |
if (!XMatchVisualInfo(disp,scrn,24,TrueColor,&ourvinfo) && |
| 39 |
< |
!XMatchVisualInfo(disp,scrn,24,DirectColor,&ourvinfo)) |
| 40 |
< |
return(NULL); |
| 41 |
< |
} else |
| 42 |
< |
return(NULL); |
| 34 |
> |
|
| 35 |
|
if ((xr = (XRASTER *)calloc(1, sizeof(XRASTER))) == NULL) |
| 36 |
|
return(NULL); |
| 37 |
|
xr->disp = disp; |
| 38 |
< |
xr->screen = scrn; |
| 39 |
< |
xr->visual = ourvinfo.visual; |
| 40 |
< |
xr->image = XCreateImage(disp,ourvinfo.visual,depth, |
| 41 |
< |
depth==1 ? XYBitmap : ZPixmap, |
| 42 |
< |
0,data,width,height,bm_pad,0); |
| 38 |
> |
xr->screen = vis->screen; |
| 39 |
> |
xr->visual = vis->visual; |
| 40 |
> |
if (npixbits == 1) |
| 41 |
> |
xr->image = XCreateImage(disp,vis->visual,1, |
| 42 |
> |
XYBitmap,0,data,width,height,bm_pad,0); |
| 43 |
> |
else |
| 44 |
> |
xr->image = XCreateImage(disp,vis->visual,vis->depth, |
| 45 |
> |
ZPixmap,0,data,width,height,bm_pad,0); |
| 46 |
|
xr->image->bitmap_bit_order = MSBFirst; |
| 47 |
< |
if (xr->image->bits_per_pixel == 32) { |
| 48 |
< |
xr->image->bytes_per_line = xr->image->bytes_per_line*24/32; |
| 49 |
< |
xr->image->bits_per_pixel = 24; |
| 47 |
> |
xr->image->bitmap_unit = bm_pad; |
| 48 |
> |
xr->image->byte_order = *(char *)&swaptest ? LSBFirst : MSBFirst; |
| 49 |
> |
if (vis->depth >= 24 && (xr->image->red_mask != 0xff || |
| 50 |
> |
xr->image->green_mask != 0xff00 || |
| 51 |
> |
xr->image->blue_mask != 0xff0000) && |
| 52 |
> |
(xr->image->red_mask != 0xff0000 || |
| 53 |
> |
xr->image->green_mask != 0xff00 || |
| 54 |
> |
xr->image->blue_mask != 0xff)) { |
| 55 |
> |
xr->image->red_mask = 0xff; |
| 56 |
> |
xr->image->green_mask = 0xff00; |
| 57 |
> |
xr->image->blue_mask = 0xff0000; |
| 58 |
|
} |
| 59 |
< |
xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0); |
| 57 |
< |
XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn), |
| 58 |
< |
GXcopy, AllPlanes); |
| 59 |
> |
xr->gc = 0; |
| 60 |
|
return(xr); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
int |
| 65 |
< |
init_rcolors(xr, rmap, gmap, bmap) /* initialize colors */ |
| 65 |
> |
init_rcolors(xr, cmap) /* initialize colors */ |
| 66 |
|
register XRASTER *xr; |
| 67 |
< |
int rmap[256], gmap[256], bmap[256]; |
| 67 |
> |
BYTE cmap[][3]; |
| 68 |
|
{ |
| 69 |
|
register unsigned char *p; |
| 70 |
|
register int i; |
| 71 |
|
|
| 72 |
< |
if (xr->image->depth != 8 || xr->ncolors != 0) |
| 72 |
> |
if (xr->image->depth > 8 | xr->ncolors != 0) |
| 73 |
|
return(xr->ncolors); |
| 74 |
|
xr->pmap = (short *)malloc(256*sizeof(short)); |
| 75 |
|
if (xr->pmap == NULL) |
| 83 |
|
i = xr->image->width*xr->image->height; |
| 84 |
|
i--; p++) |
| 85 |
|
if (xr->pmap[*p] == -1) { |
| 86 |
< |
xr->cdefs[xr->ncolors].red = rmap[*p] << 8; |
| 87 |
< |
xr->cdefs[xr->ncolors].green = gmap[*p] << 8; |
| 88 |
< |
xr->cdefs[xr->ncolors].blue = bmap[*p] << 8; |
| 86 |
> |
xr->cdefs[xr->ncolors].red = cmap[*p][RED] << 8; |
| 87 |
> |
xr->cdefs[xr->ncolors].green = cmap[*p][GRN] << 8; |
| 88 |
> |
xr->cdefs[xr->ncolors].blue = cmap[*p][BLU] << 8; |
| 89 |
|
xr->cdefs[xr->ncolors].pixel = *p; |
| 90 |
|
xr->cdefs[xr->ncolors].flags = DoRed|DoGreen|DoBlue; |
| 91 |
|
xr->pmap[*p] = xr->ncolors++; |
| 97 |
|
return(xr->ncolors); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
+ |
|
| 101 |
|
Colormap |
| 102 |
|
newcmap(disp, scrn, w, vis) /* get colormap and fix b & w */ |
| 103 |
|
Display *disp; |
| 150 |
|
register int i; |
| 151 |
|
register unsigned char *p; |
| 152 |
|
|
| 153 |
< |
if (xr->ncolors == 0 || xr->image->depth != 8) |
| 153 |
> |
if (xr->ncolors == 0 || xr->image->depth > 8) |
| 154 |
|
return(NULL); |
| 155 |
|
if (xr->pixels != NULL) |
| 156 |
|
return(xr->pixels); |
| 193 |
|
|
| 194 |
|
|
| 195 |
|
Pixmap |
| 196 |
< |
make_rpixmap(xr) /* make pixmap for raster */ |
| 196 |
> |
make_rpixmap(xr, w) /* make pixmap for raster */ |
| 197 |
|
register XRASTER *xr; |
| 198 |
+ |
Window w; |
| 199 |
|
{ |
| 200 |
+ |
XWindowAttributes xwattr; |
| 201 |
|
Pixmap pm; |
| 202 |
|
|
| 203 |
|
if (xr->pm != 0) |
| 204 |
|
return(xr->pm); |
| 205 |
< |
pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen), |
| 205 |
> |
XGetWindowAttributes(xr->disp, w, &xwattr); |
| 206 |
> |
pm = XCreatePixmap(xr->disp, w, |
| 207 |
|
xr->image->width, xr->image->height, |
| 208 |
< |
DisplayPlanes(xr->disp, xr->screen)); |
| 208 |
> |
xwattr.depth); |
| 209 |
|
if (pm == 0) |
| 210 |
|
return(0); |
| 211 |
|
put_raster(pm, 0, 0, xr); |
| 236 |
|
if (ysrc + height > xr->image->height) |
| 237 |
|
height = xr->image->height - ysrc; |
| 238 |
|
|
| 239 |
+ |
if (xr->gc == 0) { |
| 240 |
+ |
xr->gc = XCreateGC(xr->disp, d, 0, 0); |
| 241 |
+ |
XSetState(xr->disp, xr->gc, BlackPixel(xr->disp,xr->screen), |
| 242 |
+ |
WhitePixel(xr->disp,xr->screen), GXcopy, AllPlanes); |
| 243 |
+ |
} |
| 244 |
|
if (xr->pm == 0) |
| 245 |
|
XPutImage(xr->disp, d, xr->gc, xr->image, xsrc, ysrc, |
| 246 |
|
xdst, ydst, width, height); |
| 283 |
|
free((char *)xr->cdefs); |
| 284 |
|
} |
| 285 |
|
XDestroyImage(xr->image); |
| 286 |
< |
XFreeGC(xr->disp, xr->gc); |
| 286 |
> |
if (xr->gc != 0) |
| 287 |
> |
XFreeGC(xr->disp, xr->gc); |
| 288 |
|
free((char *)xr); |
| 289 |
|
} |