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 2.2 by greg, Thu May 14 08:58:23 1992 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 == 24) {
38 <                if (!XMatchVisualInfo(disp,scrn,24,TrueColor,&ourvinfo) &&
39 <                        !XMatchVisualInfo(disp,scrn,24,DirectColor,&ourvinfo))
40 <                        return(NULL);
41 <        } else
42 <                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 <                        depth==1 ? XYBitmap : ZPixmap,
39 <                        0,data,width,height,bm_pad,0);
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->byte_order = MSBFirst;
45 <        if (xr->image->bits_per_pixel == 32) {
46 <                xr->image->bytes_per_line = xr->image->bytes_per_line*24/32;
47 <                xr->image->bits_per_pixel = 24;
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 = XCreateGC(disp, RootWindow(disp,scrn), 0, 0);
58 <        XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn),
59 <                        GXcopy, AllPlanes);
56 >        xr->gc = 0;
57          return(xr);
58   }
59  
# Line 69 | Line 66 | int    rmap[256], gmap[256], bmap[256];
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 97 | Line 94 | int    rmap[256], gmap[256], bmap[256];
94          return(xr->ncolors);
95   }
96  
97 +
98   Colormap
99   newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
100   Display *disp;
# Line 149 | Line 147 | Window w;
147          register int    i;
148          register unsigned char  *p;
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);
# Line 192 | Line 190 | Window w;
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),
202 >        XGetWindowAttributes(xr->disp, w, &xwattr);
203 >        pm = XCreatePixmap(xr->disp, w,
204                          xr->image->width, xr->image->height,
205 <                        DisplayPlanes(xr->disp, xr->screen));
205 >                        xwattr.depth);
206          if (pm == 0)
207                  return(0);
208          put_raster(pm, 0, 0, xr);
# Line 232 | Line 233 | register XRASTER       *xr;
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);
# Line 274 | 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