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

Comparing ray/src/px/clrtab.c (file contents):
Revision 2.15 by schorsch, Mon Jun 30 14:59:12 2003 UTC vs.
Revision 2.18 by greg, Mon Sep 19 02:23:58 2005 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11  
12   #include "standard.h"
13   #include "color.h"
14 + #include "clrtab.h"
15  
16                                  /* histogram resolution */
17   #define NRED            36
# Line 29 | Line 30 | extern BYTE    clrtab[256][3];
30   static unsigned histo[NRED][NGRN][NBLU];
31   #define cndx(c)         histo[((c)[RED]*NRED)>>8][((c)[GRN]*NGRN)>>8][((c)[BLU]*NBLU)>>8]
32                                  /* initial color cube boundary */
33 < static int      CLRCUBE[3][2] = {0,NRED,0,NGRN,0,NBLU};
33 > static int      CLRCUBE[3][2] = {{0,NRED},{0,NGRN},{0,NBLU}};
34                                  /* maximum propagated error during dithering */
35   #define MAXERR          20
36                                  /* define CLOSEST to get closest colors */
37   #ifndef CLOSEST
37 #ifdef SPEED
38 #if  SPEED > 8
38   #define CLOSEST         1       /* this step takes a little longer */
39   #endif
41 #endif
42 #endif
40  
44 static  cut(), mktabent(), closest(), addneigh(), setclosest();
45 static int      split();
46 static unsigned dist();
41  
42 + #ifdef CLOSEST
43 + static void closest(int n);
44 + static void setclosest(BYTE *nl[], int r, int g, int b);
45 + static void addneigh(BYTE *nl[], int i, int j);
46 + static unsigned int dist(BYTE col[3], int r, int g, int b);
47 + #endif
48 + static void cut(int box[3][2], int c0, int c1);
49 + static int split(int box[3][2]);
50 + static void mktabent(int p, int box[3][2]);
51  
52 < new_histo(n)            /* clear our histogram */
53 < int     n;
52 >
53 > extern int
54 > new_histo(              /* clear our histogram */
55 >        int     n
56 > )
57   {
58          memset((void *)histo, '\0', sizeof(histo));
59          return(0);
60   }
61  
62  
63 < cnt_pixel(col)          /* add pixel to our histogram */
64 < register BYTE   col[];
63 > extern void
64 > cnt_pixel(              /* add pixel to our histogram */
65 >        register BYTE   col[]
66 > )
67   {
68          cndx(col)++;
69   }
70  
71  
72 < cnt_colrs(cs, n)                /* add a scanline to our histogram */
73 < register COLR   *cs;
74 < register int    n;
72 > extern void
73 > cnt_colrs(              /* add a scanline to our histogram */
74 >        register COLR   *cs,
75 >        register int    n
76 > )
77   {
78          while (n-- > 0) {
79                  cndx(cs[0])++;
# Line 72 | Line 82 | register int   n;
82   }
83  
84  
85 < new_clrtab(ncolors)             /* make new color table using ncolors */
86 < int     ncolors;
85 > extern int
86 > new_clrtab(             /* make new color table using ncolors */
87 >        int     ncolors
88 > )
89   {
90          if (ncolors < 1)
91                  return(0);
# Line 91 | Line 103 | int    ncolors;
103   }
104  
105  
106 < int
107 < map_pixel(col)                  /* get pixel for color */
108 < register BYTE   col[];
106 > extern int
107 > map_pixel(                      /* get pixel for color */
108 >        register BYTE   col[]
109 > )
110   {
111      return(cndx(col));
112   }
113  
114  
115 < map_colrs(bs, cs, n)            /* convert a scanline to color index values */
116 < register BYTE   *bs;
117 < register COLR   *cs;
118 < register int    n;
115 > extern void
116 > map_colrs(              /* convert a scanline to color index values */
117 >        register BYTE   *bs,
118 >        register COLR   *cs,
119 >        register int    n
120 > )
121   {
122          while (n-- > 0) {
123                  *bs++ = cndx(cs[0]);
# Line 111 | Line 126 | register int   n;
126   }
127  
128  
129 < dith_colrs(bs, cs, n)           /* convert scanline to dithered index values */
130 < register BYTE   *bs;
131 < register COLR   *cs;
132 < int     n;
129 > extern void
130 > dith_colrs(             /* convert scanline to dithered index values */
131 >        register BYTE   *bs,
132 >        register COLR   *cs,
133 >        int     n
134 > )
135   {
136          static short    (*cerr)[3] = NULL;
137          static int      N = 0;
# Line 159 | Line 176 | int    n;
176   }
177  
178  
179 < static
180 < cut(box, c0, c1)                        /* partition color space */
181 < register int    box[3][2];
182 < int     c0, c1;
179 > static void
180 > cut(                    /* partition color space */
181 >        register int    box[3][2],
182 >        int     c0,
183 >        int     c1
184 > )
185   {
186          register int    branch;
187          int     kb[3][2];
# Line 185 | Line 204 | int    c0, c1;
204  
205  
206   static int
207 < split(box)                              /* find median cut for box */
208 < register int    box[3][2];
207 > split(                          /* find median cut for box */
208 >        register int    box[3][2]
209 > )
210   {
211   #define c0      r
212          register int    r, g, b;
# Line 242 | Line 262 | register int   box[3][2];
262   }
263  
264  
265 < static
266 < mktabent(p, box)        /* compute average color for box and assign */
267 < int     p;
268 < register int    box[3][2];
265 > static void
266 > mktabent(       /* compute average color for box and assign */
267 >        int     p,
268 >        register int    box[3][2]
269 > )
270   {
271          unsigned long   sum[3];
272          unsigned        r, g;
# Line 257 | Line 278 | register int   box[3][2];
278          for (r = box[RED][0]; r < box[RED][1]; r++)
279              for (g = box[GRN][0]; g < box[GRN][1]; g++)
280                  for (b = box[BLU][0]; b < box[BLU][1]; b++) {
281 <                    if (c = histo[r][g][b]) {
281 >                    if ( (c = histo[r][g][b]) ) {
282                          n += c;
283                          sum[RED] += (long)c*r;
284                          sum[GRN] += (long)c*g;
# Line 285 | Line 306 | register int   box[3][2];
306  
307   #ifdef CLOSEST
308   #define NBSIZ           32
309 < static
310 < closest(n)                      /* make sure we have the closest colors */
311 < int     n;
309 > static void
310 > closest(                        /* make sure we have the closest colors */
311 >        int     n
312 > )
313   {
314          BYTE    *neigh[256];
315          register int    r, g, b;
# Line 324 | Line 346 | int    n;
346   }
347  
348  
349 < static
350 < addneigh(nl, i, j)              /* i and j are neighbors; add them to list */
351 < register BYTE   *nl[];
352 < register int    i;
353 < int     j;
349 > static void
350 > addneigh(               /* i and j are neighbors; add them to list */
351 >        register BYTE   *nl[],
352 >        register int    i,
353 >        int     j
354 > )
355   {
356          int     nc;
357          char    *nnl;
# Line 354 | Line 377 | int    j;
377   }
378  
379  
380 < static unsigned
381 < dist(col, r, g, b)              /* find distance from clrtab entry to r,g,b */
382 < register BYTE   col[3];
383 < int     r, g, b;
380 > static unsigned int
381 > dist(           /* find distance from clrtab entry to r,g,b */
382 >        register BYTE   col[3],
383 >        int     r,
384 >        int     g,
385 >        int     b
386 > )
387   {
388          register int    tmp;
389          register unsigned       sum;
# Line 372 | Line 398 | int    r, g, b;
398   }
399  
400  
401 < static
402 < setclosest(nl, r, g, b)         /* find index closest to color and assign */
403 < BYTE    *nl[];
404 < int     r, g, b;
401 > static void
402 > setclosest(             /* find index closest to color and assign */
403 >        BYTE    *nl[],
404 >        int     r,
405 >        int     g,
406 >        int     b
407 > )
408   {
409          int     ident;
410          unsigned        min;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines