34 |
|
} else if (depth == 8) { |
35 |
|
if (!XMatchVisualInfo(disp,scrn,8,PseudoColor,&ourvinfo)) |
36 |
|
return(NULL); |
37 |
< |
} else if (depth > 12) { |
37 |
> |
} else if (depth == 24) { |
38 |
|
if (!XMatchVisualInfo(disp,scrn,24,TrueColor,&ourvinfo)) |
39 |
|
return(NULL); |
40 |
|
} else |
45 |
|
xr->screen = scrn; |
46 |
|
xr->visual = ourvinfo.visual; |
47 |
|
xr->image = XCreateImage(disp,ourvinfo.visual,depth, |
48 |
< |
ZPixmap,0,data,width,height,bm_pad,0); |
48 |
> |
depth==1 ? XYBitmap : ZPixmap, |
49 |
> |
0,data,width,height,bm_pad,0); |
50 |
> |
xr->image->bitmap_bit_order = MSBFirst; |
51 |
|
xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0); |
52 |
|
XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn), |
53 |
|
GXcopy, AllPlanes); |
58 |
|
int |
59 |
|
init_rcolors(xr, rmap, gmap, bmap) /* initialize colors */ |
60 |
|
register XRASTER *xr; |
61 |
< |
unsigned char rmap[256], gmap[256], bmap[256]; |
61 |
> |
int rmap[256], gmap[256], bmap[256]; |
62 |
|
{ |
63 |
|
register unsigned char *p; |
64 |
|
register int i; |
91 |
|
return(xr->ncolors); |
92 |
|
} |
93 |
|
|
94 |
+ |
Colormap |
95 |
+ |
newcmap(disp, scrn, w, vis) /* get colormap and fix b & w */ |
96 |
+ |
Display *disp; |
97 |
+ |
int scrn; |
98 |
+ |
Window w; |
99 |
+ |
Visual *vis; |
100 |
+ |
{ |
101 |
+ |
XColor thiscolor; |
102 |
+ |
unsigned long *pixels; |
103 |
+ |
Colormap cmap; |
104 |
+ |
int n; |
105 |
+ |
register int i, j; |
106 |
|
|
107 |
+ |
cmap = XCreateColormap(disp, w, vis, AllocNone); |
108 |
+ |
if (cmap == 0) |
109 |
+ |
return(0); |
110 |
+ |
pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long)); |
111 |
+ |
if (pixels == NULL) |
112 |
+ |
return(0); |
113 |
+ |
for (n = vis->map_entries; n > 0; n--) |
114 |
+ |
if (XAllocColorCells(disp, cmap, 0, NULL, 0, pixels, n) != 0) |
115 |
+ |
break; |
116 |
+ |
if (n == 0) |
117 |
+ |
return(0); |
118 |
+ |
/* reset black and white */ |
119 |
+ |
for (i = 0; i < n; i++) { |
120 |
+ |
if (pixels[i] != BlackPixel(disp,scrn) |
121 |
+ |
&& pixels[i] != WhitePixel(disp,scrn)) |
122 |
+ |
continue; |
123 |
+ |
thiscolor.pixel = pixels[i]; |
124 |
+ |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
125 |
+ |
XQueryColor(disp, DefaultColormap(disp,scrn), &thiscolor); |
126 |
+ |
XStoreColor(disp, cmap, &thiscolor); |
127 |
+ |
for (j = i; j+1 < n; j++) |
128 |
+ |
pixels[j] = pixels[j+1]; |
129 |
+ |
n--; |
130 |
+ |
i--; |
131 |
+ |
} |
132 |
+ |
XFreeColors(disp, cmap, pixels, n, 0); |
133 |
+ |
free((char *)pixels); |
134 |
+ |
return(cmap); |
135 |
+ |
} |
136 |
+ |
|
137 |
+ |
|
138 |
|
unsigned long * |
139 |
|
map_rcolors(xr, w) /* get and assign pixels */ |
140 |
|
register XRASTER *xr; |
142 |
|
{ |
143 |
|
register int i; |
144 |
|
register unsigned char *p; |
100 |
– |
int j; |
145 |
|
|
146 |
|
if (xr->ncolors == 0 || xr->image->depth != 8) |
147 |
|
return(NULL); |
150 |
|
xr->pixels = (unsigned long *)malloc(xr->ncolors*sizeof(unsigned long)); |
151 |
|
if (xr->pixels == NULL) |
152 |
|
return(NULL); |
153 |
< |
if (xr->visual == DefaultVisual(xr->disp, xr->screen)) { |
153 |
> |
if (xr->visual == DefaultVisual(xr->disp, xr->screen)) |
154 |
|
xr->cmap = DefaultColormap(xr->disp, xr->screen); |
155 |
< |
goto gotmap; |
156 |
< |
} |
157 |
< |
getmap: |
158 |
< |
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) { |
155 |
> |
else |
156 |
> |
xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual); |
157 |
> |
while (XAllocColorCells(xr->disp, xr->cmap, 0, |
158 |
> |
NULL, 0, xr->pixels, xr->ncolors) == 0) |
159 |
|
if (xr->cmap == DefaultColormap(xr->disp, xr->screen)) |
160 |
< |
goto getmap; |
161 |
< |
free((char *)xr->pixels); |
162 |
< |
xr->pixels = NULL; |
163 |
< |
return(NULL); |
164 |
< |
} |
160 |
> |
xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual); |
161 |
> |
else { |
162 |
> |
free((char *)xr->pixels); |
163 |
> |
xr->pixels = NULL; |
164 |
> |
return(NULL); |
165 |
> |
} |
166 |
|
for (i = 0; i < xr->ncolors; i++) |
167 |
|
if (xr->pmap[xr->pixels[i]] == -1) |
168 |
|
break; |
194 |
|
if (xr->pm != 0) |
195 |
|
return(xr->pm); |
196 |
|
pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen), |
197 |
< |
xr->image->width, xr->image->height, xr->image->depth); |
197 |
> |
xr->image->width, xr->image->height, |
198 |
> |
DisplayPlanes(xr->disp, xr->screen)); |
199 |
|
if (pm == 0) |
200 |
|
return(0); |
201 |
|
put_raster(pm, 0, 0, xr); |