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

Comparing ray/src/common/color.c (file contents):
Revision 2.8 by greg, Sat Mar 26 13:44:38 1994 UTC vs.
Revision 2.9 by greg, Sat Feb 22 02:07:22 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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   *  color.c - routines for color calculations.
6   *
7 < *     10/10/85
7 > *  Externals declared in color.h
8   */
9  
10 + /* ====================================================================
11 + * The Radiance Software License, Version 1.0
12 + *
13 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 + *
16 + * Redistribution and use in source and binary forms, with or without
17 + * modification, are permitted provided that the following conditions
18 + * are met:
19 + *
20 + * 1. Redistributions of source code must retain the above copyright
21 + *         notice, this list of conditions and the following disclaimer.
22 + *
23 + * 2. Redistributions in binary form must reproduce the above copyright
24 + *       notice, this list of conditions and the following disclaimer in
25 + *       the documentation and/or other materials provided with the
26 + *       distribution.
27 + *
28 + * 3. The end-user documentation included with the redistribution,
29 + *           if any, must include the following acknowledgment:
30 + *             "This product includes Radiance software
31 + *                 (http://radsite.lbl.gov/)
32 + *                 developed by the Lawrence Berkeley National Laboratory
33 + *               (http://www.lbl.gov/)."
34 + *       Alternately, this acknowledgment may appear in the software itself,
35 + *       if and wherever such third-party acknowledgments normally appear.
36 + *
37 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 + *       and "The Regents of the University of California" must
39 + *       not be used to endorse or promote products derived from this
40 + *       software without prior written permission. For written
41 + *       permission, please contact [email protected].
42 + *
43 + * 5. Products derived from this software may not be called "Radiance",
44 + *       nor may "Radiance" appear in their name, without prior written
45 + *       permission of Lawrence Berkeley National Laboratory.
46 + *
47 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 + * SUCH DAMAGE.
59 + * ====================================================================
60 + *
61 + * This software consists of voluntary contributions made by many
62 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 + * information on Lawrence Berkeley National Laboratory, please see
64 + * <http://www.lbl.gov/>.
65 + */
66 +
67   #include  <stdio.h>
68  
69 + #include  <stdlib.h>
70 +
71   #include  <math.h>
72  
73   #include  "color.h"
# Line 23 | Line 79 | static char SCCSid[] = "$SunId$ LBL";
79  
80   char *
81   tempbuffer(len)                 /* get a temporary buffer */
82 < unsigned  len;
82 > unsigned int  len;
83   {
28        extern char  *malloc(), *realloc();
84          static char  *tempbuf = NULL;
85          static unsigned  tempbuflen = 0;
86  
87          if (len > tempbuflen) {
88                  if (tempbuflen > 0)
89 <                        tempbuf = realloc(tempbuf, len);
89 >                        tempbuf = (char *)realloc(tempbuf, len);
90                  else
91 <                        tempbuf = malloc(len);
91 >                        tempbuf = (char *)malloc(len);
92                  tempbuflen = tempbuf==NULL ? 0 : len;
93          }
94          return(tempbuf);
95   }
96  
97  
98 + int
99   fwritecolrs(scanline, len, fp)          /* write out a colr scanline */
100   register COLR  *scanline;
101 < unsigned  len;
101 > int  len;
102   register FILE  *fp;
103   {
104 <        register int  i, j, beg, cnt;
104 >        register int  i, j, beg, cnt = 1;
105          int  c2;
106          
107          if (len < MINELEN | len > MAXELEN)      /* OOBs, write out flat */
# Line 92 | Line 148 | register FILE  *fp;
148   }
149  
150  
151 + static int
152 + oldreadcolrs(scanline, len, fp)         /* read in an old colr scanline */
153 + register COLR  *scanline;
154 + int  len;
155 + register FILE  *fp;
156 + {
157 +        int  rshift;
158 +        register int  i;
159 +        
160 +        rshift = 0;
161 +        
162 +        while (len > 0) {
163 +                scanline[0][RED] = getc(fp);
164 +                scanline[0][GRN] = getc(fp);
165 +                scanline[0][BLU] = getc(fp);
166 +                scanline[0][EXP] = getc(fp);
167 +                if (feof(fp) || ferror(fp))
168 +                        return(-1);
169 +                if (scanline[0][RED] == 1 &&
170 +                                scanline[0][GRN] == 1 &&
171 +                                scanline[0][BLU] == 1) {
172 +                        for (i = scanline[0][EXP] << rshift; i > 0; i--) {
173 +                                copycolr(scanline[0], scanline[-1]);
174 +                                scanline++;
175 +                                len--;
176 +                        }
177 +                        rshift += 8;
178 +                } else {
179 +                        scanline++;
180 +                        len--;
181 +                        rshift = 0;
182 +                }
183 +        }
184 +        return(0);
185 + }
186 +
187 +
188 + int
189   freadcolrs(scanline, len, fp)           /* read in an encoded colr scanline */
190   register COLR  *scanline;
191   int  len;
# Line 126 | Line 220 | register FILE  *fp;
220                      return(-1);
221                  if (code > 128) {       /* run */
222                      code &= 127;
223 <                    val = getc(fp);
223 >                    if ((val = getc(fp)) == EOF)
224 >                        return -1;
225                      while (code--)
226                          scanline[j++][i] = val;
227                  } else                  /* non-run */
228 <                    while (code--)
229 <                        scanline[j++][i] = getc(fp);
228 >                    while (code--) {
229 >                        if ((val = getc(fp)) == EOF)
230 >                            return -1;
231 >                        scanline[j++][i] = val;
232 >                    }
233              }
136        return(feof(fp) ? -1 : 0);
137 }
138
139
140 oldreadcolrs(scanline, len, fp)         /* read in an old colr scanline */
141 register COLR  *scanline;
142 int  len;
143 register FILE  *fp;
144 {
145        int  rshift;
146        register int  i;
147        
148        rshift = 0;
149        
150        while (len > 0) {
151                scanline[0][RED] = getc(fp);
152                scanline[0][GRN] = getc(fp);
153                scanline[0][BLU] = getc(fp);
154                scanline[0][EXP] = getc(fp);
155                if (feof(fp) || ferror(fp))
156                        return(-1);
157                if (scanline[0][RED] == 1 &&
158                                scanline[0][GRN] == 1 &&
159                                scanline[0][BLU] == 1) {
160                        for (i = scanline[0][EXP] << rshift; i > 0; i--) {
161                                copycolr(scanline[0], scanline[-1]);
162                                scanline++;
163                                len--;
164                        }
165                        rshift += 8;
166                } else {
167                        scanline++;
168                        len--;
169                        rshift = 0;
170                }
171        }
234          return(0);
235   }
236  
237  
238 + int
239   fwritescan(scanline, len, fp)           /* write out a scanline */
240   register COLOR  *scanline;
241   int  len;
# Line 198 | Line 261 | FILE  *fp;
261   }
262  
263  
264 + int
265   freadscan(scanline, len, fp)            /* read in a scanline */
266   register COLOR  *scanline;
267   int  len;
# Line 225 | Line 289 | FILE  *fp;
289   }
290  
291  
292 + void
293   setcolr(clr, r, g, b)           /* assign a short color value */
294   register COLR  clr;
295   double  r, g, b;
# Line 250 | Line 315 | double  r, g, b;
315   }
316  
317  
318 + void
319   colr_color(col, clr)            /* convert short to float color */
320   register COLOR  col;
321   register COLR  clr;
# Line 267 | Line 333 | register COLR  clr;
333   }
334  
335  
336 + int
337   bigdiff(c1, c2, md)                     /* c1 delta c2 > md? */
338   register COLOR  c1, c2;
339   double  md;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines