--- ray/src/rt/colortab.c 1989/10/03 11:10:10 1.3 +++ ray/src/rt/colortab.c 1989/10/16 13:43:26 1.9 @@ -27,53 +27,58 @@ static char SCCSid[] = "$SunId$ LBL"; /* minimum box count for adaptive partition */ #define MINSAMP 7 /* maximum distance^2 before color reassign */ -#define MAXDST2 5 - /* maximum frame buffer depth */ -#define FBDEPTH 8 - /* color map resolution */ -#define MAPSIZ 256 +#define MAXDST2 12 /* map a color */ -#define map_col(c,p) clrmap[ colval(c,p)<1. ? \ - (int)(colval(c,p)*MAPSIZ) : MAPSIZ-1 ] +#define map_col(c,p) clrmap[p][ colval(c,p)<1. ? \ + (int)(colval(c,p)*256.) : 255 ] /* color partition tree */ #define CNODE short #define set_branch(p,c) ((c)<<2|(p)) #define set_pval(pv) ((pv)<<2|3) +#define is_branch(cn) (((cn)&3)!=3) #define is_pval(cn) (((cn)&3)==3) #define part(cn) ((cn)>>2) #define prim(cn) ((cn)&3) #define pval(cn) ((cn)>>2) /* our color table */ -struct tabent { +static struct tabent { long sum[3]; /* sum of colors using this entry */ long n; /* number of colors */ short ent[3]; /* current table value */ -} clrtab[1< 1< 0; h--) { - if (is_pval(*p.t)) - break; + for (p.t = ctree, h = 0; is_branch(*p.t); h++) if (cv[prim(*p.t)] < part(*p.t)) - p.t++; /* left branch */ + p.t += 1<>1); + cut(tree+(1<>1); /* do right branch */ kb[prim(*tree)][0] = part(*tree); kb[prim(*tree)][1] = box[prim(*tree)][1]; - cut(tree+(1<>1, c1); + cut(tree+(1<<(level+1)), level+1, kb, (c0+c1)>>1, c1); }