34 |
|
} else if (depth == 8) { |
35 |
|
if (!XMatchVisualInfo(disp,scrn,8,PseudoColor,&ourvinfo)) |
36 |
|
return(NULL); |
37 |
< |
} else if (depth > 12) { |
38 |
< |
if (!XMatchVisualInfo(disp,scrn,24,TrueColor,&ourvinfo)) |
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); |
46 |
|
xr->screen = scrn; |
47 |
|
xr->visual = ourvinfo.visual; |
48 |
|
xr->image = XCreateImage(disp,ourvinfo.visual,depth, |
49 |
< |
ZPixmap,0,data,width,height,bm_pad,0); |
49 |
> |
depth==1 ? XYBitmap : ZPixmap, |
50 |
> |
0,data,width,height,bm_pad,0); |
51 |
> |
xr->image->bitmap_bit_order = MSBFirst; |
52 |
> |
xr->image->byte_order = MSBFirst; |
53 |
> |
xr->image->red_mask = 0xff; |
54 |
> |
xr->image->green_mask = 0xff00; |
55 |
> |
xr->image->blue_mask = 0xff0000; |
56 |
> |
if (xr->image->bits_per_pixel == 32) { |
57 |
> |
xr->image->bytes_per_line = xr->image->bytes_per_line*24/32; |
58 |
> |
xr->image->bits_per_pixel = 24; |
59 |
> |
xr->image->bitmap_unit = 8; |
60 |
> |
while (xr->image->bytes_per_line % (bm_pad/8)) |
61 |
> |
xr->image->bytes_per_line++; |
62 |
> |
} |
63 |
|
xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0); |
64 |
|
XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn), |
65 |
< |
GXcopy, ~0L); |
65 |
> |
GXcopy, AllPlanes); |
66 |
|
return(xr); |
67 |
|
} |
68 |
|
|
70 |
|
int |
71 |
|
init_rcolors(xr, rmap, gmap, bmap) /* initialize colors */ |
72 |
|
register XRASTER *xr; |
73 |
< |
unsigned char rmap[256], gmap[256], bmap[256]; |
73 |
> |
int rmap[256], gmap[256], bmap[256]; |
74 |
|
{ |
75 |
|
register unsigned char *p; |
76 |
|
register int i; |
103 |
|
return(xr->ncolors); |
104 |
|
} |
105 |
|
|
106 |
+ |
Colormap |
107 |
+ |
newcmap(disp, scrn, w, vis) /* get colormap and fix b & w */ |
108 |
+ |
Display *disp; |
109 |
+ |
int scrn; |
110 |
+ |
Window w; |
111 |
+ |
Visual *vis; |
112 |
+ |
{ |
113 |
+ |
XColor thiscolor; |
114 |
+ |
unsigned long *pixels; |
115 |
+ |
Colormap cmap; |
116 |
+ |
int n; |
117 |
+ |
register int i, j; |
118 |
|
|
119 |
+ |
cmap = XCreateColormap(disp, w, vis, AllocNone); |
120 |
+ |
if (cmap == 0) |
121 |
+ |
return(0); |
122 |
+ |
pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long)); |
123 |
+ |
if (pixels == NULL) |
124 |
+ |
return(0); |
125 |
+ |
for (n = vis->map_entries; n > 0; n--) |
126 |
+ |
if (XAllocColorCells(disp, cmap, 0, NULL, 0, pixels, n) != 0) |
127 |
+ |
break; |
128 |
+ |
if (n == 0) |
129 |
+ |
return(0); |
130 |
+ |
/* reset black and white */ |
131 |
+ |
for (i = 0; i < n; i++) { |
132 |
+ |
if (pixels[i] != BlackPixel(disp,scrn) |
133 |
+ |
&& pixels[i] != WhitePixel(disp,scrn)) |
134 |
+ |
continue; |
135 |
+ |
thiscolor.pixel = pixels[i]; |
136 |
+ |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
137 |
+ |
XQueryColor(disp, DefaultColormap(disp,scrn), &thiscolor); |
138 |
+ |
XStoreColor(disp, cmap, &thiscolor); |
139 |
+ |
for (j = i; j+1 < n; j++) |
140 |
+ |
pixels[j] = pixels[j+1]; |
141 |
+ |
n--; |
142 |
+ |
i--; |
143 |
+ |
} |
144 |
+ |
XFreeColors(disp, cmap, pixels, n, 0); |
145 |
+ |
free((char *)pixels); |
146 |
+ |
return(cmap); |
147 |
+ |
} |
148 |
+ |
|
149 |
+ |
|
150 |
|
unsigned long * |
151 |
|
map_rcolors(xr, w) /* get and assign pixels */ |
152 |
|
register XRASTER *xr; |
154 |
|
{ |
155 |
|
register int i; |
156 |
|
register unsigned char *p; |
100 |
– |
int j; |
157 |
|
|
158 |
|
if (xr->ncolors == 0 || xr->image->depth != 8) |
159 |
|
return(NULL); |
162 |
|
xr->pixels = (unsigned long *)malloc(xr->ncolors*sizeof(unsigned long)); |
163 |
|
if (xr->pixels == NULL) |
164 |
|
return(NULL); |
165 |
< |
if (xr->visual == DefaultVisual(xr->disp, xr->screen)) { |
165 |
> |
if (xr->visual == DefaultVisual(xr->disp, xr->screen)) |
166 |
|
xr->cmap = DefaultColormap(xr->disp, xr->screen); |
167 |
< |
goto gotmap; |
168 |
< |
} |
169 |
< |
getmap: |
170 |
< |
xr->cmap = XCreateColormap(xr->disp, w, xr->visual, AllocNone); |
115 |
< |
gotmap: |
116 |
< |
if (XAllocColorCells(xr->disp, xr->cmap, 0, |
117 |
< |
&j, 0, xr->pixels, xr->ncolors) == 0) { |
167 |
> |
else |
168 |
> |
xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual); |
169 |
> |
while (XAllocColorCells(xr->disp, xr->cmap, 0, |
170 |
> |
NULL, 0, xr->pixels, xr->ncolors) == 0) |
171 |
|
if (xr->cmap == DefaultColormap(xr->disp, xr->screen)) |
172 |
< |
goto getmap; |
173 |
< |
free((char *)xr->pixels); |
174 |
< |
xr->pixels = NULL; |
175 |
< |
return(NULL); |
176 |
< |
} |
172 |
> |
xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual); |
173 |
> |
else { |
174 |
> |
free((char *)xr->pixels); |
175 |
> |
xr->pixels = NULL; |
176 |
> |
return(NULL); |
177 |
> |
} |
178 |
|
for (i = 0; i < xr->ncolors; i++) |
179 |
|
if (xr->pmap[xr->pixels[i]] == -1) |
180 |
|
break; |
206 |
|
if (xr->pm != 0) |
207 |
|
return(xr->pm); |
208 |
|
pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen), |
209 |
< |
xr->image->width, xr->image->height, xr->image->depth); |
209 |
> |
xr->image->width, xr->image->height, |
210 |
> |
DisplayPlanes(xr->disp, xr->screen)); |
211 |
|
if (pm == 0) |
212 |
|
return(0); |
213 |
|
put_raster(pm, 0, 0, xr); |
214 |
|
return(xr->pm = pm); |
215 |
+ |
} |
216 |
+ |
|
217 |
+ |
|
218 |
+ |
patch_raster(d, xsrc, ysrc, xdst, ydst, width, height, xr) /* redraw */ |
219 |
+ |
Drawable d; |
220 |
+ |
int xsrc, ysrc, xdst, ydst; |
221 |
+ |
int width, height; |
222 |
+ |
register XRASTER *xr; |
223 |
+ |
{ |
224 |
+ |
if (xsrc >= xr->image->width || ysrc >= xr->image->height) |
225 |
+ |
return; |
226 |
+ |
if (xsrc < 0) { |
227 |
+ |
xdst -= xsrc; width += xsrc; |
228 |
+ |
xsrc = 0; |
229 |
+ |
} |
230 |
+ |
if (ysrc < 0) { |
231 |
+ |
ydst -= ysrc; height += ysrc; |
232 |
+ |
ysrc = 0; |
233 |
+ |
} |
234 |
+ |
if (width <= 0 || height <= 0) |
235 |
+ |
return; |
236 |
+ |
if (xsrc + width > xr->image->width) |
237 |
+ |
width = xr->image->width - xsrc; |
238 |
+ |
if (ysrc + height > xr->image->height) |
239 |
+ |
height = xr->image->height - ysrc; |
240 |
+ |
|
241 |
+ |
if (xr->pm == 0) |
242 |
+ |
XPutImage(xr->disp, d, xr->gc, xr->image, xsrc, ysrc, |
243 |
+ |
xdst, ydst, width, height); |
244 |
+ |
else |
245 |
+ |
XCopyArea(xr->disp, xr->pm, d, xr->gc, xsrc, ysrc, |
246 |
+ |
width, height, xdst, ydst); |
247 |
|
} |
248 |
|
|
249 |
|
|