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.6 by greg, Thu May 28 09:39:22 1992 UTC vs.
Revision 2.11 by greg, Wed Apr 23 00:52:34 2003 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 14 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   #include <X11/Xlib.h>
12   #include <X11/Xutil.h>
13  
14 + #include "color.h"
15   #include "x11raster.h"
16  
17  
# Line 59 | Line 57 | int    bm_pad;
57  
58  
59   int
60 < init_rcolors(xr, rmap, gmap, bmap)              /* initialize colors */
60 > init_rcolors(xr, cmap)                  /* initialize colors */
61   register XRASTER        *xr;
62 < int     rmap[256], gmap[256], bmap[256];
62 > BYTE    cmap[][3];
63   {
64          register unsigned char  *p;
65          register int    i;
66  
67 <        if (xr->image->depth > 8 || xr->ncolors != 0)
67 >        if (xr->image->depth > 8 | xr->ncolors != 0)
68                  return(xr->ncolors);
69          xr->pmap = (short *)malloc(256*sizeof(short));
70          if (xr->pmap == NULL)
# Line 80 | Line 78 | int    rmap[256], gmap[256], bmap[256];
78                          i = xr->image->width*xr->image->height;
79                          i--; p++)
80                  if (xr->pmap[*p] == -1) {
81 <                        xr->cdefs[xr->ncolors].red = rmap[*p] << 8;
82 <                        xr->cdefs[xr->ncolors].green = gmap[*p] << 8;
83 <                        xr->cdefs[xr->ncolors].blue = bmap[*p] << 8;
81 >                        xr->cdefs[xr->ncolors].red = cmap[*p][RED] << 8;
82 >                        xr->cdefs[xr->ncolors].green = cmap[*p][GRN] << 8;
83 >                        xr->cdefs[xr->ncolors].blue = cmap[*p][BLU] << 8;
84                          xr->cdefs[xr->ncolors].pixel = *p;
85                          xr->cdefs[xr->ncolors].flags = DoRed|DoGreen|DoBlue;
86                          xr->pmap[*p] = xr->ncolors++;
87                  }
88 <        xr->cdefs = (XColor *)realloc((char *)xr->cdefs,
88 >        xr->cdefs = (XColor *)realloc((void *)xr->cdefs,
89                          xr->ncolors*sizeof(XColor));
90          if (xr->cdefs == NULL)
91                  return(0);
# Line 96 | Line 94 | int    rmap[256], gmap[256], bmap[256];
94  
95  
96   Colormap
97 < newcmap(disp, scrn, w, vis)             /* get colormap and fix b & w */
97 > newcmap(disp, scrn, vis)                /* get colormap and fix b & w */
98   Display *disp;
99   int     scrn;
102 Window  w;
100   Visual  *vis;
101   {
102          XColor  thiscolor;
# Line 108 | Line 105 | Visual *vis;
105          int     n;
106          register int    i, j;
107  
108 <        cmap = XCreateColormap(disp, w, vis, AllocNone);
109 <        if (cmap == 0)
110 <                return(0);
108 >        cmap = XCreateColormap(disp, RootWindow(disp,scrn), vis, AllocNone);
109 >        if (cmap == 0 || vis->class != PseudoColor)
110 >                return(cmap);
111          pixels=(unsigned long *)malloc(vis->map_entries*sizeof(unsigned long));
112          if (pixels == NULL)
113                  return(0);
# Line 134 | Line 131 | Visual *vis;
131                  i--;
132          }
133          XFreeColors(disp, cmap, pixels, n, 0);
134 <        free((char *)pixels);
134 >        free((void *)pixels);
135          return(cmap);
136   }
137  
138  
139   unsigned long *
140 < map_rcolors(xr, w)                              /* get and assign pixels */
140 > map_rcolors(xr, w)                      /* get and assign pixels */
141   register XRASTER        *xr;
142   Window  w;
143   {
# Line 157 | Line 154 | Window w;
154          if (xr->visual == DefaultVisual(xr->disp, xr->screen))
155                  xr->cmap = DefaultColormap(xr->disp, xr->screen);
156          else
157 <                xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
157 >                xr->cmap = newcmap(xr->disp, xr->screen, xr->visual);
158          while (XAllocColorCells(xr->disp, xr->cmap, 0,
159                          NULL, 0, xr->pixels, xr->ncolors) == 0)
160                  if (xr->cmap == DefaultColormap(xr->disp, xr->screen))
161 <                        xr->cmap = newcmap(xr->disp, xr->screen, w, xr->visual);
161 >                        xr->cmap = newcmap(xr->disp, xr->screen, xr->visual);
162                  else {
163 <                        free((char *)xr->pixels);
163 >                        free((void *)xr->pixels);
164                          xr->pixels = NULL;
165                          return(NULL);
166                  }
# Line 255 | Line 252 | register XRASTER       *xr;
252          XFreeColors(xr->disp, xr->cmap, xr->pixels, xr->ncolors, 0);
253          if (xr->cmap != DefaultColormap(xr->disp, xr->screen))
254                  XFreeColormap(xr->disp, xr->cmap);
255 <        free((char *)xr->pixels);
255 >        free((void *)xr->pixels);
256          xr->pixels = NULL;
257   }
258  
# Line 276 | Line 273 | register XRASTER       *xr;
273          free_rpixmap(xr);
274          if (xr->ncolors > 0) {
275                  unmap_rcolors(xr);
276 <                free((char *)xr->pmap);
277 <                free((char *)xr->cdefs);
276 >                free((void *)xr->pmap);
277 >                free((void *)xr->cdefs);
278          }
279          XDestroyImage(xr->image);
280          if (xr->gc != 0)
281                  XFreeGC(xr->disp, xr->gc);
282 <        free((char *)xr);
282 >        free((void *)xr);
283   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines