ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/x10.c
(Generate patch)

Comparing ray/src/rt/x10.c (file contents):
Revision 1.5 by greg, Thu May 25 19:33:19 1989 UTC vs.
Revision 1.12 by greg, Mon Oct 2 17:12:39 1989 UTC

# Line 24 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24  
25   #include  "xtwind.h"
26  
27 < #define GAMMA           2.0             /* exponent for color correction */
27 > #define GAMMA           2.2             /* exponent for color correction */
28  
29   #define BORWIDTH        5               /* border width */
30   #define BARHEIGHT       25              /* menu bar size */
# Line 39 | Line 39 | static char SCCSid[] = "$SunId$ LBL";
39   #define WFLUSH          30              /* flush after this many rays */
40   #endif
41  
42 < #define  hashcolr(c)    ((67*(c)[RED]+59*(c)[GRN]+71*(c)[BLU])%ncolors)
42 > #define  checkinp()     while (XPending() > 0) getevent()
43  
44 #define  flush()        while (XPending() > 0) getevent()
45
44   #define  levptr(etype)  ((etype *)&thisevent)
45  
46   static char  *clientname;               /* calling client's name */
47  
48   static XEvent  thisevent;               /* current event */
49  
52 static int  colres = 128;               /* color resolution */
53 static COLR  colrmap[256];              /* our color mapping */
54
50   static int  ncolors = 0;                /* color table size */
51 < static COLR  *colrtbl;                  /* our color table */
57 < static int  *pixval;                    /* associated pixel values */
51 > static int  *pixval;                    /* allocated pixel values */
52  
53   static Display  *ourdisplay = NULL;     /* our display */
54  
# Line 67 | Line 61 | static int  gheight = 0;               /* graphics window height */
61  
62   static TEXTWIND  *comline = NULL;       /* our command line */
63  
70 static int  c_erase, c_kill;            /* erase and kill characters */
71
64   static char  c_queue[64];               /* input queue */
65   static int  c_first = 0;                /* first character in queue */
66   static int  c_last = 0;                 /* last character in queue */
# Line 89 | Line 81 | struct driver *
81   x_init(name)                    /* initialize driver */
82   char  *name;
83   {
92        struct sgttyb  ttymode;
93        
94        if (isatty(0)) {
95                ioctl(0, TIOCGETP, &ttymode);
96                c_erase = ttymode.sg_erase;
97                c_kill = ttymode.sg_kill;
98        } else {
99                c_erase = 'H'-'@';
100                c_kill = 'U'-'@';
101        }
84          ourdisplay = XOpenDisplay(NULL);
85          if (ourdisplay == NULL) {
86                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 108 | Line 90 | char  *name;
90                  stderr_v("not enough colors\n");
91                  return(NULL);
92          }
93 <        if (getmap() < 0)                       /* not fatal */
93 >        make_cmap(GAMMA);                       /* make color map */
94 >        if (getpixels() < 0)                    /* get pixels */
95                  stderr_v("cannot allocate colors\n");
96  
97          pickcursor = XCreateCursor(bcross_width, bcross_height,
# Line 142 | Line 125 | x_close()                      /* close our display */
125                  gwidth = gheight = 0;
126          }
127          XFreeCursor(pickcursor);
128 <        freemap();
128 >        freepixels();
129          XCloseDisplay(ourdisplay);
130          ourdisplay = NULL;
131   }
# Line 173 | Line 156 | int  xres, yres;
156                  gheight = yres;
157          } else                                          /* just clear */
158                  XClear(gwind);
159 <        newmap();
160 <        flush();
159 >        if (newtab() < 0) {
160 >                stderr_v("Color allocation error\n");
161 >                quit(1);
162 >        }
163 >        checkinp();
164          return;
165   fail:
166          stderr_v("Failure opening window in x_clear\n");
# Line 189 | Line 175 | int  xmin, ymin, xmax, ymax;
175   {
176          extern long  nrays;             /* global ray count */
177          static long  lastflush = 0;     /* ray count at last flush */
192        int  ndx;
178  
179          if (ncolors > 0) {
195                if ((ndx = colindex(col)) < 0) {
196                        colres >>= 1;
197                        redraw();
198                        return;
199                }
180                  XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin,
181 <                                pixval[ndx]);
181 >                                pixval[get_pixel(col)]);
182          }
183          if (nrays - lastflush >= WFLUSH) {
184 <                flush();                /* also checks for input */
184 >                if (ncolors <= 0)       /* output necessary for death */
185 >                        XPixSet(gwind,0,0,1,1,BlackPixel);
186 >                checkinp();
187                  lastflush = nrays;
188          }
189   }
# Line 214 | Line 196 | char  *inp;
196          int  x_getc(), x_comout();
197  
198          xt_cursor(comline, TBLKCURS);
199 <        editline(inp, x_getc, x_comout, c_erase, c_kill);
199 >        editline(inp, x_getc, x_comout);
200          xt_cursor(comline, TNOCURS);
201   }
202  
# Line 225 | Line 207 | char  *out;
207   {
208          if (comline != NULL)
209                  xt_puts(out, comline);
210 +        XFlush();
211   }
212  
213  
# Line 251 | Line 234 | int  *xp, *yp;
234          *yp = gheight-1 - levptr(XKeyOrButtonEvent)->y;
235          XFocusKeyboard(RootWindow);
236          XUngrabMouse();
237 <        flush();                                /* insure release */
237 >        XFlush();                               /* insure release */
238          if (c_last > c_first)                   /* key pressed */
239                  return(x_getc());
240                                                  /* button pressed */
# Line 267 | Line 250 | int  *xp, *yp;
250   }
251  
252  
270 static int
271 colindex(col)                   /* return index for color */
272 COLOR  col;
273 {
274        static COLR  clr;
275        int  hval;
276        register int  ndx, i;
277
278        mapcolor(clr, col);
279
280        hval = ndx = hashcolr(clr);
281        
282        for (i = 1; i < ncolors; i++) {
283                if (colrtbl[ndx][EXP] == 0) {
284                        colrtbl[ndx][RED] = clr[RED];
285                        colrtbl[ndx][GRN] = clr[GRN];
286                        colrtbl[ndx][BLU] = clr[BLU];
287                        colrtbl[ndx][EXP] = COLXS;
288                        newcolr(ndx, clr);
289                        return(ndx);
290                }
291                if (            colrtbl[ndx][RED] == clr[RED] &&
292                                colrtbl[ndx][GRN] == clr[GRN] &&
293                                colrtbl[ndx][BLU] == clr[BLU]   )
294                        return(ndx);
295                ndx = (hval + i*i) % ncolors;
296        }
297        return(-1);
298 }
299
300
253   static
254   newcolr(ndx, clr)               /* enter a color into hardware table */
255   int  ndx;
# Line 315 | Line 267 | COLR  clr;
267  
268  
269   static
270 < mapcolor(clr, col)                      /* map to our color space */
319 < COLR  clr;
320 < COLOR  col;
270 > newtab()                        /* assign new color table */
271   {
272 <        register int  i, p;
273 <                                        /* compute color table value */
274 <        for (i = 0; i < 3; i++) {
275 <                p = colval(col,i) * 255.0 + 0.5;
276 <                if (p < 0) p = 0;
277 <                else if (p > 255) p = 255;
278 <                clr[i] = colrmap[p][i];
272 >        extern COLR     *get_ctab();
273 >        COLR    *ctab;
274 >        Color   *defs;
275 >        register int    i;
276 >
277 >        if ((ctab = get_ctab(ncolors)) == NULL)
278 >                return(-1);
279 >        if ((defs = (Color *)malloc(ncolors*sizeof(Color))) == NULL)
280 >                return(-1);
281 >        for (i = 0; i < ncolors; i++) {
282 >                defs[i].pixel = pixval[i];
283 >                defs[i].red = ctab[i][RED] << 8;
284 >                defs[i].green = ctab[i][GRN] << 8;
285 >                defs[i].blue = ctab[i][BLU] << 8;
286          }
287 <        clr[EXP] = COLXS;
287 >        XStoreColors(ncolors, defs);
288 >        free((char *)defs);
289 >        return(0);
290   }
291  
292  
293   static
294 < getmap()                                /* get the color map */
294 > getpixels()                             /* get the color map */
295   {
296          int  planes;
297  
298          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
340                colrtbl = (COLR *)malloc(ncolors*sizeof(COLR));
299                  pixval = (int *)malloc(ncolors*sizeof(int));
300 <                if (colrtbl == NULL || pixval == NULL)
301 <                        return(-1);
300 >                if (pixval == NULL)
301 >                        break;
302                  if (XGetColorCells(0,ncolors,0,&planes,pixval) != 0)
303                          return(0);
346                free((char *)colrtbl);
304                  free((char *)pixval);
305          }
306          ncolors = 0;
# Line 352 | Line 309 | getmap()                               /* get the color map */
309  
310  
311   static
312 < freemap()                               /* free our color map */
312 > freepixels()                            /* free our pixels */
313   {
314          if (ncolors == 0)
315                  return;
316          XFreeColors(pixval, ncolors, 0);
360        free((char *)colrtbl);
317          free((char *)pixval);
318          ncolors = 0;
319   }
320  
321  
366 static
367 newmap()                                /* initialize the color map */
368 {
369        double  pow();
370        int  val;
371        register int  i;
372
373        for (i = 0; i < 256; i++) {
374                val = pow(i/256.0, 1.0/GAMMA) * colres;
375                val = (val*256 + 128) / colres;
376                colrmap[i][RED] = colrmap[i][GRN] = colrmap[i][BLU] = val;
377                colrmap[i][EXP] = COLXS;
378        }
379        for (i = 0; i < ncolors; i++)
380                colrtbl[i][EXP] = 0;
381 }
382
383
322   static int
323   x_getc()                        /* get a command character */
324   {
# Line 403 | Line 341 | getevent()                     /* get next event */
341                  break;
342          case ExposeWindow:
343                  if (ncolors == 0 && levptr(XExposeEvent)->subwindow == 0)
344 <                        if (getmap() < 0)
344 >                        if (getpixels() < 0)
345                                  stderr_v("cannot grab colors\n");
346                          else
347 <                                newmap();
347 >                                newtab();
348                  /* fall through */
349          case ExposeRegion:
350                  fixwindow(levptr(XExposeEvent));
351                  break;
352          case UnmapWindow:
353                  if (levptr(XUnmapEvent)->subwindow == 0)
354 <                        freemap();
354 >                        freepixels();
355                  break;
356          case ButtonPressed:             /* handled in x_getcur() */
357                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines