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.5 by greg, Wed May 27 14:28:54 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->byte_order = *(char *)&swaptest ? LSBFirst : MSBFirst;
45 >        if (vis->depth >= 24 && (xr->image->red_mask != 0xff ||
46 >                        xr->image->green_mask != 0xff00 ||
47 >                        xr->image->blue_mask != 0xff0000) &&
48 >                        (xr->image->red_mask != 0xff0000 ||
49 >                        xr->image->green_mask != 0xff00 ||
50 >                        xr->image->blue_mask != 0xff)) {
51 >                xr->image->red_mask = 0xff;
52 >                xr->image->green_mask = 0xff00;
53 >                xr->image->blue_mask = 0xff0000;
54 >        }
55 >        xr->gc = 0;
56          return(xr);
57   }
58  
# Line 56 | Line 60 | int    bm_pad;
60   int
61   init_rcolors(xr, rmap, gmap, bmap)              /* initialize colors */
62   register XRASTER        *xr;
63 < unsigned char   rmap[256], gmap[256], bmap[256];
63 > int     rmap[256], gmap[256], bmap[256];
64   {
65          register unsigned char  *p;
66          register int    i;
# Line 90 | Line 94 | unsigned char  rmap[256], gmap[256], bmap[256];
94   }
95  
96  
97 + Colormap
98 + newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
99 + Display *disp;
100 + int     scrn;
101 + Window  w;
102 + Visual  *vis;
103 + {
104 +        XColor  thiscolor;
105 +        unsigned long   *pixels;
106 +        Colormap        cmap;
107 +        int     n;
108 +        register int    i, j;
109 +
110 +        cmap = XCreateColormap(disp, w, vis, AllocNone);
111 +        if (cmap == 0)
112 +                return(0);
113 +        pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long));
114 +        if (pixels == NULL)
115 +                return(0);
116 +        for (n = vis->map_entries; n > 0; n--)
117 +                if (XAllocColorCells(disp, cmap, 0, NULL, 0, pixels, n) != 0)
118 +                        break;
119 +        if (n == 0)
120 +                return(0);
121 +                                        /* reset black and white */
122 +        for (i = 0; i < n; i++) {
123 +                if (pixels[i] != BlackPixel(disp,scrn)
124 +                                && pixels[i] != WhitePixel(disp,scrn))
125 +                        continue;
126 +                thiscolor.pixel = pixels[i];
127 +                thiscolor.flags = DoRed|DoGreen|DoBlue;
128 +                XQueryColor(disp, DefaultColormap(disp,scrn), &thiscolor);
129 +                XStoreColor(disp, cmap, &thiscolor);
130 +                for (j = i; j+1 < n; j++)
131 +                        pixels[j] = pixels[j+1];
132 +                n--;
133 +                i--;
134 +        }
135 +        XFreeColors(disp, cmap, pixels, n, 0);
136 +        free((char *)pixels);
137 +        return(cmap);
138 + }
139 +
140 +
141   unsigned long *
142   map_rcolors(xr, w)                              /* get and assign pixels */
143   register XRASTER        *xr;
# Line 97 | Line 145 | Window w;
145   {
146          register int    i;
147          register unsigned char  *p;
100        int     j;
148  
149          if (xr->ncolors == 0 || xr->image->depth != 8)
150                  return(NULL);
# Line 106 | Line 153 | Window w;
153          xr->pixels = (unsigned long *)malloc(xr->ncolors*sizeof(unsigned long));
154          if (xr->pixels == NULL)
155                  return(NULL);
156 <        if (xr->visual == DefaultVisual(xr->disp, xr->screen)) {
156 >        if (xr->visual == DefaultVisual(xr->disp, xr->screen))
157                  xr->cmap = DefaultColormap(xr->disp, xr->screen);
158 <                goto gotmap;
159 <        }
160 < getmap:
161 <        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) {
158 >        else
159 >                xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
160 >        while (XAllocColorCells(xr->disp, xr->cmap, 0,
161 >                        NULL, 0, xr->pixels, xr->ncolors) == 0)
162                  if (xr->cmap == DefaultColormap(xr->disp, xr->screen))
163 <                        goto getmap;
164 <                free((char *)xr->pixels);
165 <                xr->pixels = NULL;
166 <                return(NULL);
167 <        }
163 >                        xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
164 >                else {
165 >                        free((char *)xr->pixels);
166 >                        xr->pixels = NULL;
167 >                        return(NULL);
168 >                }
169          for (i = 0; i < xr->ncolors; i++)
170                  if (xr->pmap[xr->pixels[i]] == -1)
171                          break;
# Line 144 | Line 189 | gotmap:
189  
190  
191   Pixmap
192 < make_rpixmap(xr)                        /* make pixmap for raster */
192 > make_rpixmap(xr, d)                     /* make pixmap for raster */
193   register XRASTER        *xr;
194 + Drawable        d;
195   {
196          Pixmap  pm;
197  
198          if (xr->pm != 0)
199                  return(xr->pm);
200 <        pm = XCreatePixmap(xr->disp, RootWindow(xr->disp, xr->screen),
201 <                        xr->image->width, xr->image->height, xr->image->depth);
200 >        pm = XCreatePixmap(xr->disp, d,
201 >                        xr->image->width, xr->image->height,
202 >                        xr->image->depth);
203          if (pm == 0)
204                  return(0);
205          put_raster(pm, 0, 0, xr);
# Line 160 | Line 207 | register XRASTER       *xr;
207   }
208  
209  
210 + patch_raster(d, xsrc, ysrc, xdst, ydst, width, height, xr)      /* redraw */
211 + Drawable        d;
212 + int     xsrc, ysrc, xdst, ydst;
213 + int     width, height;
214 + register XRASTER        *xr;
215 + {
216 +        if (xsrc >= xr->image->width || ysrc >= xr->image->height)
217 +                return;
218 +        if (xsrc < 0) {
219 +                xdst -= xsrc; width += xsrc;
220 +                xsrc = 0;
221 +        }
222 +        if (ysrc < 0) {
223 +                ydst -= ysrc; height += ysrc;
224 +                ysrc = 0;
225 +        }
226 +        if (width <= 0 || height <= 0)
227 +                return;
228 +        if (xsrc + width > xr->image->width)
229 +                width = xr->image->width - xsrc;
230 +        if (ysrc + height > xr->image->height)
231 +                height = xr->image->height - ysrc;
232 +
233 +        if (xr->gc == 0) {
234 +                xr->gc = XCreateGC(xr->disp, d, 0, 0);
235 +                XSetState(xr->disp, xr->gc, BlackPixel(xr->disp,xr->screen),
236 +                        WhitePixel(xr->disp,xr->screen), GXcopy, AllPlanes);
237 +        }
238 +        if (xr->pm == 0)
239 +                XPutImage(xr->disp, d, xr->gc, xr->image, xsrc, ysrc,
240 +                                xdst, ydst, width, height);
241 +        else
242 +                XCopyArea(xr->disp, xr->pm, d, xr->gc, xsrc, ysrc,
243 +                                width, height, xdst, ydst);
244 + }
245 +
246 +
247   unmap_rcolors(xr)                       /* free colors */
248   register XRASTER        *xr;
249   {
# Line 193 | Line 277 | register XRASTER       *xr;
277                  free((char *)xr->cdefs);
278          }
279          XDestroyImage(xr->image);
280 <        XFreeGC(xr->disp, xr->gc);
280 >        if (xr->gc != 0)
281 >                XFreeGC(xr->disp, xr->gc);
282          free((char *)xr);
283   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines