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.3 by greg, Tue May 19 13:10:07 1992 UTC vs.
Revision 2.7 by greg, Mon Oct 12 14:52:19 1992 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14   #include <X11/Xlib.h>
15   #include <X11/Xutil.h>
16  
17 + #include "color.h"
18   #include "x11raster.h"
19  
20  
21   XRASTER *
22 < make_raster(disp, scrn, depth, data, width, height, bm_pad)
22 > make_raster(disp, vis, npixbits, data, width, height, bm_pad)
23   Display *disp;
24 < int     scrn;
25 < int     depth;
24 > XVisualInfo     *vis;
25 > int     npixbits;
26   char    *data;
27   int     width, height;
28   int     bm_pad;
29   {
30 +        static long     swaptest = 1;
31          register XRASTER        *xr;
32 <        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);
32 >
33          if ((xr = (XRASTER *)calloc(1, sizeof(XRASTER))) == NULL)
34                  return(NULL);
35          xr->disp = disp;
36 <        xr->screen = scrn;
37 <        xr->visual = ourvinfo.visual;
38 <        xr->image = XCreateImage(disp,ourvinfo.visual,depth,
39 <                        depth==1 ? XYBitmap : ZPixmap,
40 <                        0,data,width,height,bm_pad,0);
41 <        if (depth == 1) {
42 <                xr->image->bitmap_bit_order = MSBFirst;
43 <                xr->image->byte_order = MSBFirst;
44 <        } else
45 <                xr->image->byte_order = LSBFirst;
46 <        if (xr->image->bits_per_pixel == 32) {
47 <                xr->image->bytes_per_line = xr->image->bytes_per_line*24/32;
48 <                xr->image->bits_per_pixel = 24;
36 >        xr->screen = vis->screen;
37 >        xr->visual = vis->visual;
38 >        if (npixbits == 1)
39 >                xr->image = XCreateImage(disp,vis->visual,1,
40 >                                XYBitmap,0,data,width,height,bm_pad,0);
41 >        else
42 >                xr->image = XCreateImage(disp,vis->visual,vis->depth,
43 >                                ZPixmap,0,data,width,height,bm_pad,0);
44 >        xr->image->bitmap_bit_order = MSBFirst;
45 >        xr->image->bitmap_unit = bm_pad;
46 >        xr->image->byte_order = *(char *)&swaptest ? LSBFirst : MSBFirst;
47 >        if (vis->depth >= 24 && (xr->image->red_mask != 0xff ||
48 >                        xr->image->green_mask != 0xff00 ||
49 >                        xr->image->blue_mask != 0xff0000) &&
50 >                        (xr->image->red_mask != 0xff0000 ||
51 >                        xr->image->green_mask != 0xff00 ||
52 >                        xr->image->blue_mask != 0xff)) {
53 >                xr->image->red_mask = 0xff;
54 >                xr->image->green_mask = 0xff00;
55 >                xr->image->blue_mask = 0xff0000;
56          }
57 <        xr->gc = XCreateGC(disp, RootWindow(disp,scrn), 0, 0);
61 <        XSetState(disp, xr->gc, BlackPixel(disp,scrn), WhitePixel(disp,scrn),
62 <                        GXcopy, AllPlanes);
57 >        xr->gc = 0;
58          return(xr);
59   }
60  
61  
62   int
63 < init_rcolors(xr, rmap, gmap, bmap)              /* initialize colors */
63 > init_rcolors(xr, cmap)                  /* initialize colors */
64   register XRASTER        *xr;
65 < int     rmap[256], gmap[256], bmap[256];
65 > BYTE    cmap[][3];
66   {
67          register unsigned char  *p;
68          register int    i;
69  
70 <        if (xr->image->depth != 8 || xr->ncolors != 0)
70 >        if (xr->image->depth > 8 | xr->ncolors != 0)
71                  return(xr->ncolors);
72          xr->pmap = (short *)malloc(256*sizeof(short));
73          if (xr->pmap == NULL)
# Line 86 | Line 81 | int    rmap[256], gmap[256], bmap[256];
81                          i = xr->image->width*xr->image->height;
82                          i--; p++)
83                  if (xr->pmap[*p] == -1) {
84 <                        xr->cdefs[xr->ncolors].red = rmap[*p] << 8;
85 <                        xr->cdefs[xr->ncolors].green = gmap[*p] << 8;
86 <                        xr->cdefs[xr->ncolors].blue = bmap[*p] << 8;
84 >                        xr->cdefs[xr->ncolors].red = cmap[*p][RED] << 8;
85 >                        xr->cdefs[xr->ncolors].green = cmap[*p][GRN] << 8;
86 >                        xr->cdefs[xr->ncolors].blue = cmap[*p][BLU] << 8;
87                          xr->cdefs[xr->ncolors].pixel = *p;
88                          xr->cdefs[xr->ncolors].flags = DoRed|DoGreen|DoBlue;
89                          xr->pmap[*p] = xr->ncolors++;
# Line 100 | Line 95 | int    rmap[256], gmap[256], bmap[256];
95          return(xr->ncolors);
96   }
97  
98 +
99   Colormap
100   newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
101   Display *disp;
# Line 152 | Line 148 | Window w;
148          register int    i;
149          register unsigned char  *p;
150  
151 <        if (xr->ncolors == 0 || xr->image->depth != 8)
151 >        if (xr->ncolors == 0 || xr->image->depth > 8)
152                  return(NULL);
153          if (xr->pixels != NULL)
154                  return(xr->pixels);
# Line 195 | Line 191 | Window w;
191  
192  
193   Pixmap
194 < make_rpixmap(xr)                        /* make pixmap for raster */
194 > make_rpixmap(xr, w)                     /* make pixmap for raster */
195   register XRASTER        *xr;
196 + Window  w;
197   {
198 +        XWindowAttributes       xwattr;
199          Pixmap  pm;
200  
201          if (xr->pm != 0)
202                  return(xr->pm);
203 <        pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen),
203 >        XGetWindowAttributes(xr->disp, w, &xwattr);
204 >        pm = XCreatePixmap(xr->disp, w,
205                          xr->image->width, xr->image->height,
206 <                        DisplayPlanes(xr->disp, xr->screen));
206 >                        xwattr.depth);
207          if (pm == 0)
208                  return(0);
209          put_raster(pm, 0, 0, xr);
# Line 235 | Line 234 | register XRASTER       *xr;
234          if (ysrc + height > xr->image->height)
235                  height = xr->image->height - ysrc;
236  
237 +        if (xr->gc == 0) {
238 +                xr->gc = XCreateGC(xr->disp, d, 0, 0);
239 +                XSetState(xr->disp, xr->gc, BlackPixel(xr->disp,xr->screen),
240 +                        WhitePixel(xr->disp,xr->screen), GXcopy, AllPlanes);
241 +        }
242          if (xr->pm == 0)
243                  XPutImage(xr->disp, d, xr->gc, xr->image, xsrc, ysrc,
244                                  xdst, ydst, width, height);
# Line 277 | Line 281 | register XRASTER       *xr;
281                  free((char *)xr->cdefs);
282          }
283          XDestroyImage(xr->image);
284 <        XFreeGC(xr->disp, xr->gc);
284 >        if (xr->gc != 0)
285 >                XFreeGC(xr->disp, xr->gc);
286          free((char *)xr);
287   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines