ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/x11raster.c
(Generate patch)

Comparing ray/src/px/x11raster.c (file contents):
Revision 1.1 by greg, Thu Mar 1 13:18:23 1990 UTC vs.
Revision 2.2 by greg, Thu May 14 08:58:23 1992 UTC

# Line 34 | Line 34 | int    bm_pad;
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);
# Line 45 | Line 46 | int    bm_pad;
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 >        if (xr->image->bits_per_pixel == 32) {
54 >                xr->image->bytes_per_line = xr->image->bytes_per_line*24/32;
55 >                xr->image->bits_per_pixel = 24;
56 >        }
57          xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0);
58          XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn),
59 <                        GXcopy, ~0L);
59 >                        GXcopy, AllPlanes);
60          return(xr);
61   }
62  
# Line 56 | Line 64 | int    bm_pad;
64   int
65   init_rcolors(xr, rmap, gmap, bmap)              /* initialize colors */
66   register XRASTER        *xr;
67 < unsigned char   rmap[256], gmap[256], bmap[256];
67 > int     rmap[256], gmap[256], bmap[256];
68   {
69          register unsigned char  *p;
70          register int    i;
# Line 89 | Line 97 | unsigned char  rmap[256], gmap[256], bmap[256];
97          return(xr->ncolors);
98   }
99  
100 + Colormap
101 + newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
102 + Display *disp;
103 + int     scrn;
104 + Window  w;
105 + Visual  *vis;
106 + {
107 +        XColor  thiscolor;
108 +        unsigned long   *pixels;
109 +        Colormap        cmap;
110 +        int     n;
111 +        register int    i, j;
112  
113 +        cmap = XCreateColormap(disp, w, vis, AllocNone);
114 +        if (cmap == 0)
115 +                return(0);
116 +        pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long));
117 +        if (pixels == NULL)
118 +                return(0);
119 +        for (n = vis->map_entries; n > 0; n--)
120 +                if (XAllocColorCells(disp, cmap, 0, NULL, 0, pixels, n) != 0)
121 +                        break;
122 +        if (n == 0)
123 +                return(0);
124 +                                        /* reset black and white */
125 +        for (i = 0; i < n; i++) {
126 +                if (pixels[i] != BlackPixel(disp,scrn)
127 +                                && pixels[i] != WhitePixel(disp,scrn))
128 +                        continue;
129 +                thiscolor.pixel = pixels[i];
130 +                thiscolor.flags = DoRed|DoGreen|DoBlue;
131 +                XQueryColor(disp, DefaultColormap(disp,scrn), &thiscolor);
132 +                XStoreColor(disp, cmap, &thiscolor);
133 +                for (j = i; j+1 < n; j++)
134 +                        pixels[j] = pixels[j+1];
135 +                n--;
136 +                i--;
137 +        }
138 +        XFreeColors(disp, cmap, pixels, n, 0);
139 +        free((char *)pixels);
140 +        return(cmap);
141 + }
142 +
143 +
144   unsigned long *
145   map_rcolors(xr, w)                              /* get and assign pixels */
146   register XRASTER        *xr;
# Line 97 | Line 148 | Window w;
148   {
149          register int    i;
150          register unsigned char  *p;
100        int     j;
151  
152          if (xr->ncolors == 0 || xr->image->depth != 8)
153                  return(NULL);
# Line 106 | Line 156 | Window w;
156          xr->pixels = (unsigned long *)malloc(xr->ncolors*sizeof(unsigned long));
157          if (xr->pixels == NULL)
158                  return(NULL);
159 <        if (xr->visual == DefaultVisual(xr->disp, xr->screen)) {
159 >        if (xr->visual == DefaultVisual(xr->disp, xr->screen))
160                  xr->cmap = DefaultColormap(xr->disp, xr->screen);
161 <                goto gotmap;
162 <        }
163 < getmap:
164 <        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) {
161 >        else
162 >                xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
163 >        while (XAllocColorCells(xr->disp, xr->cmap, 0,
164 >                        NULL, 0, xr->pixels, xr->ncolors) == 0)
165                  if (xr->cmap == DefaultColormap(xr->disp, xr->screen))
166 <                        goto getmap;
167 <                free((char *)xr->pixels);
168 <                xr->pixels = NULL;
169 <                return(NULL);
170 <        }
166 >                        xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
167 >                else {
168 >                        free((char *)xr->pixels);
169 >                        xr->pixels = NULL;
170 >                        return(NULL);
171 >                }
172          for (i = 0; i < xr->ncolors; i++)
173                  if (xr->pmap[xr->pixels[i]] == -1)
174                          break;
# Line 152 | Line 200 | register XRASTER       *xr;
200          if (xr->pm != 0)
201                  return(xr->pm);
202          pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen),
203 <                        xr->image->width, xr->image->height, xr->image->depth);
203 >                        xr->image->width, xr->image->height,
204 >                        DisplayPlanes(xr->disp, xr->screen));
205          if (pm == 0)
206                  return(0);
207          put_raster(pm, 0, 0, xr);
208          return(xr->pm = pm);
209 + }
210 +
211 +
212 + patch_raster(d, xsrc, ysrc, xdst, ydst, width, height, xr)      /* redraw */
213 + Drawable        d;
214 + int     xsrc, ysrc, xdst, ydst;
215 + int     width, height;
216 + register XRASTER        *xr;
217 + {
218 +        if (xsrc >= xr->image->width || ysrc >= xr->image->height)
219 +                return;
220 +        if (xsrc < 0) {
221 +                xdst -= xsrc; width += xsrc;
222 +                xsrc = 0;
223 +        }
224 +        if (ysrc < 0) {
225 +                ydst -= ysrc; height += ysrc;
226 +                ysrc = 0;
227 +        }
228 +        if (width <= 0 || height <= 0)
229 +                return;
230 +        if (xsrc + width > xr->image->width)
231 +                width = xr->image->width - xsrc;
232 +        if (ysrc + height > xr->image->height)
233 +                height = xr->image->height - ysrc;
234 +
235 +        if (xr->pm == 0)
236 +                XPutImage(xr->disp, d, xr->gc, xr->image, xsrc, ysrc,
237 +                                xdst, ydst, width, height);
238 +        else
239 +                XCopyArea(xr->disp, xr->pm, d, xr->gc, xsrc, ysrc,
240 +                                width, height, xdst, ydst);
241   }
242  
243  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines