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

Comparing ray/src/rt/aed.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:16 1989 UTC vs.
Revision 2.2 by gregl, Tue Nov 11 19:55:02 1997 UTC

# Line 46 | Line 46 | static char SCCSid[] = "$SunId$ LBL";
46   #define string(s)       fputs(s, stdout)
47   #define flush()         fflush(stdout)
48  
49 < #define  GAMMA          2.0             /* exponent for color correction */
49 > #define  GAMMA          2.5             /* exponent for color correction */
50  
51 < #define  MINCOLOR       8               /* start of device color table */
51 > #define  NCOLORS        248             /* our color table size */
52 > #define  MINPIX         8               /* minimum hardware color */
53  
53 #define  NCOLORS        241             /* our color table size (prime) */
54
55 #define  hashcolr(c)    ((67*(c)[RED]+59*(c)[GRN]+71*(c)[BLU])%NCOLORS)
56
54   #define  NCOLS          512             /* maximum # columns for output */
55 < #define  NROWS          512-COMHT       /* maximum # rows for output */
55 > #define  NROWS          483-COMHT       /* maximum # rows for output */
56   #define  COMHT          16              /* height of command line */
57   #define  COMCW          63              /* maximum chars on command line */
58  
62 static COLR  colrmap[256];              /* our color map */
63
64 static COLR  colrtbl[NCOLORS];          /* our color table */
65
66 static int  colres = 64;                /* color resolution */
67
59   int  aed_close(), aed_clear(), aed_paintr(),
60                  aed_getcur(), aed_comout(), aed_errout();
61  
62   static struct driver  aed_driver = {
63          aed_close, aed_clear, aed_paintr, aed_getcur,
64 <        aed_comout, NULL,
65 <        NCOLS, NROWS
64 >        aed_comout, NULL, NULL,
65 >        1.0, NCOLS, NROWS
66   };
67  
68  
69   struct driver *
70 < aed_init(name)                          /* open AED */
71 < char  *name;
70 > aed_init(name, id)                      /* open AED */
71 > char  *name, *id;
72   {
73          if (ttyset(&aed_driver, fileno(stdin)) < 0) {   /* set tty driver */
74 <                stderr_v("cannot access terminal\n");
74 >                eputs("cannot access terminal\n");
75                  return(NULL);
76          }
77          command(RST);                                   /* reset AED */
# Line 95 | Line 86 | char  *name;
86          byte(BLK); byte(WHT); byte(15);
87          command(SCP);
88          byte('+'); byte(0); byte(1);
89 <        errvec = aed_errout;                            /* set error vector */
90 <        cmdvec = aed_errout;
91 <        if (wrnvec != NULL)
92 <                wrnvec = aed_errout;
89 >        make_gmap(GAMMA);                               /* make color map */
90 >        erract[USER].pf =                               /* set error vector */
91 >        erract[SYSTEM].pf =
92 >        erract[INTERNAL].pf =
93 >        erract[CONSISTENCY].pf = aed_errout;
94 >        erract[COMMAND].pf = aed_errout;
95 >        if (erract[WARNING].pf != NULL)
96 >                erract[WARNING].pf = aed_errout;
97          return(&aed_driver);
98   }
99  
# Line 106 | Line 101 | char  *name;
101   static
102   aed_close()                                     /* close AED */
103   {
104 <        errvec = stderr_v;                      /* reset error vector */
105 <        cmdvec = NULL;
106 <        if (wrnvec != NULL)
107 <                wrnvec = stderr_v;
104 >        erract[USER].pf =                       /* reset error vector */
105 >        erract[SYSTEM].pf =
106 >        erract[INTERNAL].pf =
107 >        erract[CONSISTENCY].pf = eputs;
108 >        erract[COMMAND].pf = NULL;
109 >        if (erract[WARNING].pf != NULL)
110 >                erract[WARNING].pf = wputs;
111          aedsetcap(0, 0);                        /* go to bottom */
112          command(SEC);
113          byte(WHT);                              /* white text */
# Line 125 | Line 123 | aed_clear(x, y)                                        /* clear AED */
123   int  x, y;
124   {
125          command(FFD);
126 +        new_ctab(NCOLORS);                      /* init color table */
127          flush();
129        makemap();                              /* init color map */
128   }
129  
130  
# Line 135 | Line 133 | aed_paintr(col, xmin, ymin, xmax, ymax)                /* paint a re
133   COLOR  col;
134   int  xmin, ymin, xmax, ymax;
135   {
136 +        extern int  anewcolr();
137          int  ndx;
138  
139 <        if ((ndx = colindex(col)) < 0) {                /* full table? */
140 <                colres >>= 1;
141 <                redraw();
143 <                return;
144 <        }
145 <        command(SEC);                                   /* draw rectangle */
146 <        byte(ndx+MINCOLOR);
139 >        ndx = get_pixel(col, anewcolr);         /* calls anewcolr() */
140 >        command(SEC);                           /* draw rectangle */
141 >        byte(ndx+MINPIX);
142          aedsetcap(xmin, ymin+COMHT);
143          command(DFR);
144          aedcoord(xmax-1, ymax+(-1+COMHT));
# Line 261 | Line 256 | int  *xp, *yp;
256   }
257  
258  
264 static int
265 colindex(col)                   /* return table index for color */
266 COLOR  col;
267 {
268        static COLR  clr;
269        int  hval;
270        register int  ndx, i;
271        
272        mapcolor(clr, col);
273
274        hval = ndx = hashcolr(clr);
275        
276        for (i = 1; i < NCOLORS; i++) {
277                if (colrtbl[ndx][EXP] == 0) {
278                        colrtbl[ndx][RED] = clr[RED];
279                        colrtbl[ndx][GRN] = clr[GRN];
280                        colrtbl[ndx][BLU] = clr[BLU];
281                        colrtbl[ndx][EXP] = COLXS;
282                        newcolr(ndx, clr);
283                        return(ndx);
284                }
285                if (            colrtbl[ndx][RED] == clr[RED] &&
286                                colrtbl[ndx][GRN] == clr[GRN] &&
287                                colrtbl[ndx][BLU] == clr[BLU]   )
288                        return(ndx);
289                ndx = (hval + i*i) % NCOLORS;
290        }
291        return(-1);
292 }
293
294
259   static
260 < newcolr(index, clr)             /* enter a color into our table */
260 > anewcolr(index, r, g, b)                /* enter a color into our table */
261   int  index;
262 < COLR  clr;
262 > int  r, g, b;
263   {
264          command(SCT);
265 <        byte(index+MINCOLOR);
265 >        byte((index+MINPIX)&255);
266          byte(1);
267 <        byte(clr[RED]);
268 <        byte(clr[GRN]);
269 <        byte(clr[BLU]);
267 >        byte(r);
268 >        byte(g);
269 >        byte(b);
270          flush();
307 }
308
309
310 static
311 mapcolor(clr, col)                      /* map to our color space */
312 COLR  clr;
313 COLOR  col;
314 {
315        register int  i, p;
316                                        /* compute color table value */
317        for (i = 0; i < 3; i++) {
318                p = colval(col,i) * 256.0;
319                if (p < 0) p = 0;
320                else if (p >= 256) p = 255;
321                clr[i] = colrmap[p][i];
322        }
323        clr[EXP] = COLXS;
324 }
325
326
327 static
328 makemap()                               /* initialize the color map */
329 {
330        double  pow();
331        int  val;
332        register int  i;
333
334        for (i = 0; i < 256; i++) {
335                val = pow(i/256.0, 1.0/GAMMA) * colres;
336                val = (val*256 + 128) / colres;
337                colrmap[i][RED] = colrmap[i][GRN] = colrmap[i][BLU] = val;
338                colrmap[i][EXP] = COLXS;
339        }
340        for (i = 0; i < NCOLORS; i++)
341                colrtbl[i][EXP] = 0;
271   }
272  
273  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines