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.8 by greg, Mon Jul 19 15:18:10 1993 UTC vs.
Revision 2.13 by schorsch, Sun Mar 28 20:33:14 2004 UTC

# Line 1 | Line 1
1 /* Copyright 1990 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * x11raster.c - routines to handle images for X windows.
6   *
# Line 17 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14   #include "color.h"
15   #include "x11raster.h"
16  
20 extern char  *malloc(), *realloc(), *calloc();
17  
18 <
19 < XRASTER *
20 < make_raster(disp, vis, npixbits, data, width, height, bm_pad)
21 < Display *disp;
22 < XVisualInfo     *vis;
23 < int     npixbits;
24 < char    *data;
25 < int     width, height;
26 < int     bm_pad;
18 > extern XRASTER *
19 > make_raster(
20 >        Display *disp,
21 >        XVisualInfo     *vis,
22 >        int     npixbits,
23 >        char    *data,
24 >        int     width,
25 >        int height,
26 >        int     bm_pad
27 > )
28   {
29          static long     swaptest = 1;
30          register XRASTER        *xr;
# Line 61 | Line 58 | int    bm_pad;
58   }
59  
60  
61 < int
62 < init_rcolors(xr, cmap)                  /* initialize colors */
63 < register XRASTER        *xr;
64 < BYTE    cmap[][3];
61 > extern int
62 > init_rcolors(                   /* initialize colors */
63 >        register XRASTER        *xr,
64 >        BYTE    cmap[][3]
65 > )
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 90 | Line 88 | BYTE   cmap[][3];
88                          xr->cdefs[xr->ncolors].flags = DoRed|DoGreen|DoBlue;
89                          xr->pmap[*p] = xr->ncolors++;
90                  }
91 <        xr->cdefs = (XColor *)realloc((char *)xr->cdefs,
91 >        xr->cdefs = (XColor *)realloc((void *)xr->cdefs,
92                          xr->ncolors*sizeof(XColor));
93          if (xr->cdefs == NULL)
94                  return(0);
# Line 98 | Line 96 | BYTE   cmap[][3];
96   }
97  
98  
99 < Colormap
100 < newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
101 < Display *disp;
102 < int     scrn;
103 < Window  w;
104 < Visual  *vis;
99 > extern Colormap
100 > newcmap(                /* get colormap and fix b & w */
101 >        Display *disp,
102 >        int     scrn,
103 >        Visual  *vis
104 > )
105   {
106          XColor  thiscolor;
107          unsigned long   *pixels;
# Line 111 | Line 109 | Visual *vis;
109          int     n;
110          register int    i, j;
111  
112 <        cmap = XCreateColormap(disp, w, vis, AllocNone);
113 <        if (cmap == 0)
114 <                return(0);
112 >        cmap = XCreateColormap(disp, RootWindow(disp,scrn), vis, AllocNone);
113 >        if (cmap == 0 || vis->class != PseudoColor)
114 >                return(cmap);
115          pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long));
116          if (pixels == NULL)
117                  return(0);
# Line 137 | Line 135 | Visual *vis;
135                  i--;
136          }
137          XFreeColors(disp, cmap, pixels, n, 0);
138 <        free((char *)pixels);
138 >        free((void *)pixels);
139          return(cmap);
140   }
141  
142  
143 < unsigned long *
144 < map_rcolors(xr, w)                              /* get and assign pixels */
145 < register XRASTER        *xr;
146 < Window  w;
143 > extern unsigned long *
144 > map_rcolors(                    /* get and assign pixels */
145 >        register XRASTER        *xr,
146 >        Window  w
147 > )
148   {
149          register int    i;
150          register unsigned char  *p;
# Line 160 | Line 159 | Window w;
159          if (xr->visual == DefaultVisual(xr->disp, xr->screen))
160                  xr->cmap = DefaultColormap(xr->disp, xr->screen);
161          else
162 <                xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
162 >                xr->cmap = newcmap(xr->disp, xr->screen, xr->visual);
163          while (XAllocColorCells(xr->disp, xr->cmap, 0,
164                          NULL, 0, xr->pixels, xr->ncolors) == 0)
165                  if (xr->cmap == DefaultColormap(xr->disp, xr->screen))
166 <                        xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
166 >                        xr->cmap = newcmap(xr->disp, xr->screen, xr->visual);
167                  else {
168 <                        free((char *)xr->pixels);
168 >                        free((void *)xr->pixels);
169                          xr->pixels = NULL;
170                          return(NULL);
171                  }
# Line 192 | Line 191 | Window w;
191   }
192  
193  
194 < Pixmap
195 < make_rpixmap(xr, w)                     /* make pixmap for raster */
196 < register XRASTER        *xr;
197 < Window  w;
194 > extern Pixmap
195 > make_rpixmap(                   /* make pixmap for raster */
196 >        register XRASTER        *xr,
197 >        Window  w
198 > )
199   {
200          XWindowAttributes       xwattr;
201          Pixmap  pm;
# Line 212 | Line 212 | Window w;
212          return(xr->pm = pm);
213   }
214  
215 <
216 < patch_raster(d, xsrc, ysrc, xdst, ydst, width, height, xr)      /* redraw */
217 < Drawable        d;
218 < int     xsrc, ysrc, xdst, ydst;
219 < int     width, height;
220 < register XRASTER        *xr;
215 > extern void
216 > patch_raster(   /* redraw */
217 >        Drawable        d,
218 >        int     xsrc,
219 >        int     ysrc,
220 >        int     xdst,
221 >        int     ydst,
222 >        int     width,
223 >        int     height,
224 >        register XRASTER        *xr
225 > )
226   {
227          if (xsrc >= xr->image->width || ysrc >= xr->image->height)
228                  return;
# Line 250 | Line 255 | register XRASTER       *xr;
255   }
256  
257  
258 < unmap_rcolors(xr)                       /* free colors */
259 < register XRASTER        *xr;
258 > extern void
259 > unmap_rcolors(                  /* free colors */
260 >        register XRASTER        *xr
261 > )
262   {
263          if (xr->pixels == NULL)
264                  return;
265          XFreeColors(xr->disp, xr->cmap, xr->pixels, xr->ncolors, 0);
266          if (xr->cmap != DefaultColormap(xr->disp, xr->screen))
267                  XFreeColormap(xr->disp, xr->cmap);
268 <        free((char *)xr->pixels);
268 >        free((void *)xr->pixels);
269          xr->pixels = NULL;
270   }
271  
272  
273 < free_rpixmap(xr)                        /* release Pixmap */
274 < register XRASTER        *xr;
273 > extern void
274 > free_rpixmap(                   /* release Pixmap */
275 >        register XRASTER        *xr
276 > )
277   {
278          if (xr->pm == 0)
279                  return;
# Line 273 | Line 282 | register XRASTER       *xr;
282   }
283  
284  
285 < free_raster(xr)                         /* free raster data */
286 < register XRASTER        *xr;
285 > extern void
286 > free_raster(                            /* free raster data */
287 >        register XRASTER        *xr
288 > )
289   {
290          free_rpixmap(xr);
291          if (xr->ncolors > 0) {
292                  unmap_rcolors(xr);
293 <                free((char *)xr->pmap);
294 <                free((char *)xr->cdefs);
293 >                free((void *)xr->pmap);
294 >                free((void *)xr->cdefs);
295          }
296          XDestroyImage(xr->image);
297          if (xr->gc != 0)
298                  XFreeGC(xr->disp, xr->gc);
299 <        free((char *)xr);
299 >        free((void *)xr);
300   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines