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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines