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.6 by greg, Thu May 28 09:39:22 1992 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19  
20   XRASTER *
21 < make_raster(disp, scrn, depth, data, width, height, bm_pad)
21 > make_raster(disp, vis, npixbits, data, width, height, bm_pad)
22   Display *disp;
23 < int     scrn;
24 < int     depth;
23 > XVisualInfo     *vis;
24 > int     npixbits;
25   char    *data;
26   int     width, height;
27   int     bm_pad;
28   {
29 +        static long     swaptest = 1;
30          register XRASTER        *xr;
31 <        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 > 12) {
38 <                if (!XMatchVisualInfo(disp,scrn,24,TrueColor,&ourvinfo))
39 <                        return(NULL);
40 <        } else
41 <                return(NULL);
31 >
32          if ((xr = (XRASTER *)calloc(1, sizeof(XRASTER))) == NULL)
33                  return(NULL);
34          xr->disp = disp;
35 <        xr->screen = scrn;
36 <        xr->visual = ourvinfo.visual;
37 <        xr->image = XCreateImage(disp,ourvinfo.visual,depth,
38 <                        ZPixmap,0,data,width,height,bm_pad,0);
39 <        xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0);
40 <        XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn),
41 <                        GXcopy, ~0L);
35 >        xr->screen = vis->screen;
36 >        xr->visual = vis->visual;
37 >        if (npixbits == 1)
38 >                xr->image = XCreateImage(disp,vis->visual,1,
39 >                                XYBitmap,0,data,width,height,bm_pad,0);
40 >        else
41 >                xr->image = XCreateImage(disp,vis->visual,vis->depth,
42 >                                ZPixmap,0,data,width,height,bm_pad,0);
43 >        xr->image->bitmap_bit_order = MSBFirst;
44 >        xr->image->bitmap_unit = bm_pad;
45 >        xr->image->byte_order = *(char *)&swaptest ? LSBFirst : MSBFirst;
46 >        if (vis->depth >= 24 && (xr->image->red_mask != 0xff ||
47 >                        xr->image->green_mask != 0xff00 ||
48 >                        xr->image->blue_mask != 0xff0000) &&
49 >                        (xr->image->red_mask != 0xff0000 ||
50 >                        xr->image->green_mask != 0xff00 ||
51 >                        xr->image->blue_mask != 0xff)) {
52 >                xr->image->red_mask = 0xff;
53 >                xr->image->green_mask = 0xff00;
54 >                xr->image->blue_mask = 0xff0000;
55 >        }
56 >        xr->gc = 0;
57          return(xr);
58   }
59  
# Line 56 | Line 61 | int    bm_pad;
61   int
62   init_rcolors(xr, rmap, gmap, bmap)              /* initialize colors */
63   register XRASTER        *xr;
64 < unsigned char   rmap[256], gmap[256], bmap[256];
64 > int     rmap[256], gmap[256], bmap[256];
65   {
66          register unsigned char  *p;
67          register int    i;
68  
69 <        if (xr->image->depth != 8 || xr->ncolors != 0)
69 >        if (xr->image->depth > 8 || xr->ncolors != 0)
70                  return(xr->ncolors);
71          xr->pmap = (short *)malloc(256*sizeof(short));
72          if (xr->pmap == NULL)
# Line 90 | Line 95 | unsigned char  rmap[256], gmap[256], bmap[256];
95   }
96  
97  
98 + Colormap
99 + newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
100 + Display *disp;
101 + int     scrn;
102 + Window  w;
103 + Visual  *vis;
104 + {
105 +        XColor  thiscolor;
106 +        unsigned long   *pixels;
107 +        Colormap        cmap;
108 +        int     n;
109 +        register int    i, j;
110 +
111 +        cmap = XCreateColormap(disp, w, vis, AllocNone);
112 +        if (cmap == 0)
113 +                return(0);
114 +        pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long));
115 +        if (pixels == NULL)
116 +                return(0);
117 +        for (n = vis->map_entries; n > 0; n--)
118 +                if (XAllocColorCells(disp, cmap, 0, NULL, 0, pixels, n) != 0)
119 +                        break;
120 +        if (n == 0)
121 +                return(0);
122 +                                        /* reset black and white */
123 +        for (i = 0; i < n; i++) {
124 +                if (pixels[i] != BlackPixel(disp,scrn)
125 +                                && pixels[i] != WhitePixel(disp,scrn))
126 +                        continue;
127 +                thiscolor.pixel = pixels[i];
128 +                thiscolor.flags = DoRed|DoGreen|DoBlue;
129 +                XQueryColor(disp, DefaultColormap(disp,scrn), &thiscolor);
130 +                XStoreColor(disp, cmap, &thiscolor);
131 +                for (j = i; j+1 < n; j++)
132 +                        pixels[j] = pixels[j+1];
133 +                n--;
134 +                i--;
135 +        }
136 +        XFreeColors(disp, cmap, pixels, n, 0);
137 +        free((char *)pixels);
138 +        return(cmap);
139 + }
140 +
141 +
142   unsigned long *
143   map_rcolors(xr, w)                              /* get and assign pixels */
144   register XRASTER        *xr;
# Line 97 | Line 146 | Window w;
146   {
147          register int    i;
148          register unsigned char  *p;
100        int     j;
149  
150 <        if (xr->ncolors == 0 || xr->image->depth != 8)
150 >        if (xr->ncolors == 0 || xr->image->depth > 8)
151                  return(NULL);
152          if (xr->pixels != NULL)
153                  return(xr->pixels);
154          xr->pixels = (unsigned long *)malloc(xr->ncolors*sizeof(unsigned long));
155          if (xr->pixels == NULL)
156                  return(NULL);
157 <        if (xr->visual == DefaultVisual(xr->disp, xr->screen)) {
157 >        if (xr->visual == DefaultVisual(xr->disp, xr->screen))
158                  xr->cmap = DefaultColormap(xr->disp, xr->screen);
159 <                goto gotmap;
160 <        }
161 < getmap:
162 <        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) {
159 >        else
160 >                xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
161 >        while (XAllocColorCells(xr->disp, xr->cmap, 0,
162 >                        NULL, 0, xr->pixels, xr->ncolors) == 0)
163                  if (xr->cmap == DefaultColormap(xr->disp, xr->screen))
164 <                        goto getmap;
165 <                free((char *)xr->pixels);
166 <                xr->pixels = NULL;
167 <                return(NULL);
168 <        }
164 >                        xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
165 >                else {
166 >                        free((char *)xr->pixels);
167 >                        xr->pixels = NULL;
168 >                        return(NULL);
169 >                }
170          for (i = 0; i < xr->ncolors; i++)
171                  if (xr->pmap[xr->pixels[i]] == -1)
172                          break;
# Line 144 | Line 190 | gotmap:
190  
191  
192   Pixmap
193 < make_rpixmap(xr)                        /* make pixmap for raster */
193 > make_rpixmap(xr, w)                     /* make pixmap for raster */
194   register XRASTER        *xr;
195 + Window  w;
196   {
197 +        XWindowAttributes       xwattr;
198          Pixmap  pm;
199  
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);
202 >        XGetWindowAttributes(xr->disp, w, &xwattr);
203 >        pm = XCreatePixmap(xr->disp, w,
204 >                        xr->image->width, xr->image->height,
205 >                        xwattr.depth);
206          if (pm == 0)
207                  return(0);
208          put_raster(pm, 0, 0, xr);
# Line 160 | Line 210 | register XRASTER       *xr;
210   }
211  
212  
213 + patch_raster(d, xsrc, ysrc, xdst, ydst, width, height, xr)      /* redraw */
214 + Drawable        d;
215 + int     xsrc, ysrc, xdst, ydst;
216 + int     width, height;
217 + register XRASTER        *xr;
218 + {
219 +        if (xsrc >= xr->image->width || ysrc >= xr->image->height)
220 +                return;
221 +        if (xsrc < 0) {
222 +                xdst -= xsrc; width += xsrc;
223 +                xsrc = 0;
224 +        }
225 +        if (ysrc < 0) {
226 +                ydst -= ysrc; height += ysrc;
227 +                ysrc = 0;
228 +        }
229 +        if (width <= 0 || height <= 0)
230 +                return;
231 +        if (xsrc + width > xr->image->width)
232 +                width = xr->image->width - xsrc;
233 +        if (ysrc + height > xr->image->height)
234 +                height = xr->image->height - ysrc;
235 +
236 +        if (xr->gc == 0) {
237 +                xr->gc = XCreateGC(xr->disp, d, 0, 0);
238 +                XSetState(xr->disp, xr->gc, BlackPixel(xr->disp,xr->screen),
239 +                        WhitePixel(xr->disp,xr->screen), GXcopy, AllPlanes);
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 +
250   unmap_rcolors(xr)                       /* free colors */
251   register XRASTER        *xr;
252   {
# Line 193 | Line 280 | register XRASTER       *xr;
280                  free((char *)xr->cdefs);
281          }
282          XDestroyImage(xr->image);
283 <        XFreeGC(xr->disp, xr->gc);
283 >        if (xr->gc != 0)
284 >                XFreeGC(xr->disp, xr->gc);
285          free((char *)xr);
286   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines