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.3 by greg, Sat Feb 22 02:07:28 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 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   *  aed.c - driver for AED 512 terminal.
6 + */
7 +
8 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10   *
11 < *     2/2/87
11 > * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 > * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 > *
14 > * Redistribution and use in source and binary forms, with or without
15 > * modification, are permitted provided that the following conditions
16 > * are met:
17 > *
18 > * 1. Redistributions of source code must retain the above copyright
19 > *         notice, this list of conditions and the following disclaimer.
20 > *
21 > * 2. Redistributions in binary form must reproduce the above copyright
22 > *       notice, this list of conditions and the following disclaimer in
23 > *       the documentation and/or other materials provided with the
24 > *       distribution.
25 > *
26 > * 3. The end-user documentation included with the redistribution,
27 > *           if any, must include the following acknowledgment:
28 > *             "This product includes Radiance software
29 > *                 (http://radsite.lbl.gov/)
30 > *                 developed by the Lawrence Berkeley National Laboratory
31 > *               (http://www.lbl.gov/)."
32 > *       Alternately, this acknowledgment may appear in the software itself,
33 > *       if and wherever such third-party acknowledgments normally appear.
34 > *
35 > * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 > *       and "The Regents of the University of California" must
37 > *       not be used to endorse or promote products derived from this
38 > *       software without prior written permission. For written
39 > *       permission, please contact [email protected].
40 > *
41 > * 5. Products derived from this software may not be called "Radiance",
42 > *       nor may "Radiance" appear in their name, without prior written
43 > *       permission of Lawrence Berkeley National Laboratory.
44 > *
45 > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 > * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 > * SUCH DAMAGE.
57 > * ====================================================================
58 > *
59 > * This software consists of voluntary contributions made by many
60 > * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 > * information on Lawrence Berkeley National Laboratory, please see
62 > * <http://www.lbl.gov/>.
63   */
64  
65   #include  <stdio.h>
# Line 46 | Line 98 | static char SCCSid[] = "$SunId$ LBL";
98   #define string(s)       fputs(s, stdout)
99   #define flush()         fflush(stdout)
100  
101 < #define  GAMMA          2.0             /* exponent for color correction */
101 > #define  GAMMA          2.5             /* exponent for color correction */
102  
103 < #define  MINCOLOR       8               /* start of device color table */
103 > #define  NCOLORS        248             /* our color table size */
104 > #define  MINPIX         8               /* minimum hardware color */
105  
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
106   #define  NCOLS          512             /* maximum # columns for output */
107 < #define  NROWS          512-COMHT       /* maximum # rows for output */
107 > #define  NROWS          483-COMHT       /* maximum # rows for output */
108   #define  COMHT          16              /* height of command line */
109   #define  COMCW          63              /* maximum chars on command line */
110  
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
111   int  aed_close(), aed_clear(), aed_paintr(),
112                  aed_getcur(), aed_comout(), aed_errout();
113  
114   static struct driver  aed_driver = {
115          aed_close, aed_clear, aed_paintr, aed_getcur,
116 <        aed_comout, NULL,
117 <        NCOLS, NROWS
116 >        aed_comout, NULL, NULL,
117 >        1.0, NCOLS, NROWS
118   };
119  
120  
121   struct driver *
122 < aed_init(name)                          /* open AED */
123 < char  *name;
122 > aed_init(name, id)                      /* open AED */
123 > char  *name, *id;
124   {
125          if (ttyset(&aed_driver, fileno(stdin)) < 0) {   /* set tty driver */
126 <                stderr_v("cannot access terminal\n");
126 >                eputs("cannot access terminal\n");
127                  return(NULL);
128          }
129          command(RST);                                   /* reset AED */
# Line 95 | Line 138 | char  *name;
138          byte(BLK); byte(WHT); byte(15);
139          command(SCP);
140          byte('+'); byte(0); byte(1);
141 <        errvec = aed_errout;                            /* set error vector */
142 <        cmdvec = aed_errout;
143 <        if (wrnvec != NULL)
144 <                wrnvec = aed_errout;
141 >        make_gmap(GAMMA);                               /* make color map */
142 >        erract[USER].pf =                               /* set error vector */
143 >        erract[SYSTEM].pf =
144 >        erract[INTERNAL].pf =
145 >        erract[CONSISTENCY].pf = aed_errout;
146 >        erract[COMMAND].pf = aed_errout;
147 >        if (erract[WARNING].pf != NULL)
148 >                erract[WARNING].pf = aed_errout;
149          return(&aed_driver);
150   }
151  
# Line 106 | Line 153 | char  *name;
153   static
154   aed_close()                                     /* close AED */
155   {
156 <        errvec = stderr_v;                      /* reset error vector */
157 <        cmdvec = NULL;
158 <        if (wrnvec != NULL)
159 <                wrnvec = stderr_v;
156 >        erract[USER].pf =                       /* reset error vector */
157 >        erract[SYSTEM].pf =
158 >        erract[INTERNAL].pf =
159 >        erract[CONSISTENCY].pf = eputs;
160 >        erract[COMMAND].pf = NULL;
161 >        if (erract[WARNING].pf != NULL)
162 >                erract[WARNING].pf = wputs;
163          aedsetcap(0, 0);                        /* go to bottom */
164          command(SEC);
165          byte(WHT);                              /* white text */
# Line 125 | Line 175 | aed_clear(x, y)                                        /* clear AED */
175   int  x, y;
176   {
177          command(FFD);
178 +        new_ctab(NCOLORS);                      /* init color table */
179          flush();
129        makemap();                              /* init color map */
180   }
181  
182  
# Line 135 | Line 185 | aed_paintr(col, xmin, ymin, xmax, ymax)                /* paint a re
185   COLOR  col;
186   int  xmin, ymin, xmax, ymax;
187   {
188 +        extern int  anewcolr();
189          int  ndx;
190  
191 <        if ((ndx = colindex(col)) < 0) {                /* full table? */
192 <                colres >>= 1;
193 <                redraw();
143 <                return;
144 <        }
145 <        command(SEC);                                   /* draw rectangle */
146 <        byte(ndx+MINCOLOR);
191 >        ndx = get_pixel(col, anewcolr);         /* calls anewcolr() */
192 >        command(SEC);                           /* draw rectangle */
193 >        byte(ndx+MINPIX);
194          aedsetcap(xmin, ymin+COMHT);
195          command(DFR);
196          aedcoord(xmax-1, ymax+(-1+COMHT));
# Line 261 | Line 308 | int  *xp, *yp;
308   }
309  
310  
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
311   static
312 < newcolr(index, clr)             /* enter a color into our table */
312 > anewcolr(index, r, g, b)                /* enter a color into our table */
313   int  index;
314 < COLR  clr;
314 > int  r, g, b;
315   {
316          command(SCT);
317 <        byte(index+MINCOLOR);
317 >        byte((index+MINPIX)&255);
318          byte(1);
319 <        byte(clr[RED]);
320 <        byte(clr[GRN]);
321 <        byte(clr[BLU]);
319 >        byte(r);
320 >        byte(g);
321 >        byte(b);
322          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;
323   }
324  
325  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines