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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines