1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Allocate and control dynamic color table. |
6 |
|
* |
16 |
|
* except there is no color mapping, since the tm library is used. |
17 |
|
*/ |
18 |
|
|
19 |
+ |
#include <string.h> |
20 |
+ |
|
21 |
|
#include "standard.h" |
22 |
+ |
#include "rhdisp.h" |
23 |
|
#include "color.h" |
24 |
|
/* histogram resolution */ |
25 |
|
#define NRED 24 |
43 |
|
static struct tabent { |
44 |
|
long sum[3]; /* sum of colors using this entry */ |
45 |
|
int n; /* number of colors */ |
46 |
< |
BYTE ent[3]; /* current table value */ |
46 |
> |
uby8 ent[3]; /* current table value */ |
47 |
|
} *clrtab = NULL; |
48 |
|
/* color cube partition */ |
49 |
|
static CNODE *ctree = NULL; |
52 |
|
/* initial color cube boundary */ |
53 |
|
static int CLRCUBE[3][2] = {{0,NRED},{0,NGRN},{0,NBLU}}; |
54 |
|
|
55 |
< |
static int split(), cut(); |
55 |
> |
static void cut(CNODE *tree, int level, int box[3][2], int c0, int c1); |
56 |
> |
static int split(int box[3][2]); |
57 |
|
|
58 |
|
|
59 |
< |
int |
60 |
< |
new_ctab(ncolors) /* start new color table with max ncolors */ |
61 |
< |
int ncolors; |
59 |
> |
|
60 |
> |
extern int |
61 |
> |
new_ctab( /* start new color table with max ncolors */ |
62 |
> |
int ncolors |
63 |
> |
) |
64 |
|
{ |
65 |
|
int treesize; |
66 |
|
|
68 |
|
return(0); |
69 |
|
/* free old tables */ |
70 |
|
if (clrtab != NULL) |
71 |
< |
free((char *)clrtab); |
71 |
> |
free((void *)clrtab); |
72 |
|
if (ctree != NULL) |
73 |
< |
free((char *)ctree); |
73 |
> |
free((void *)ctree); |
74 |
|
/* get new tables */ |
75 |
|
for (treesize = 1; treesize < ncolors; treesize <<= 1) |
76 |
|
; |
82 |
|
/* partition color space */ |
83 |
|
cut(ctree, 0, CLRCUBE, 0, ncolors); |
84 |
|
/* clear histogram */ |
85 |
< |
bzero((char *)histo, sizeof(histo)); |
85 |
> |
memset((void *)histo, '\0', sizeof(histo)); |
86 |
|
/* return number of colors used */ |
87 |
|
return(ncolors); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
< |
int |
92 |
< |
get_pixel(rgb, set_pixel) /* get pixel for color */ |
93 |
< |
BYTE rgb[3]; |
94 |
< |
int (*set_pixel)(); |
91 |
> |
extern int |
92 |
> |
get_pixel( /* get pixel for color */ |
93 |
> |
uby8 rgb[3], |
94 |
> |
void (*set_pixel)(int h, int r, int g, int b) |
95 |
> |
) |
96 |
|
{ |
93 |
– |
extern char errmsg[]; |
97 |
|
int r, g, b; |
98 |
|
int cv[3]; |
99 |
|
register CNODE *tp; |
133 |
|
clrtab[h].ent[GRN] = g; /* reassign pixel */ |
134 |
|
clrtab[h].ent[BLU] = b; |
135 |
|
#ifdef DEBUG |
136 |
< |
sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n", |
137 |
< |
h, r, g, b, clrtab[h].n); |
138 |
< |
eputs(errmsg); |
136 |
> |
{ |
137 |
> |
extern char errmsg[]; |
138 |
> |
sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n", |
139 |
> |
h, r, g, b, clrtab[h].n); |
140 |
> |
eputs(errmsg); |
141 |
> |
} |
142 |
|
#endif |
143 |
|
(*set_pixel)(h, r, g, b); |
144 |
|
} |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
< |
static |
150 |
< |
cut(tree, level, box, c0, c1) /* partition color space */ |
151 |
< |
register CNODE *tree; |
152 |
< |
int level; |
153 |
< |
register int box[3][2]; |
154 |
< |
int c0, c1; |
149 |
> |
static void |
150 |
> |
cut( /* partition color space */ |
151 |
> |
register CNODE *tree, |
152 |
> |
int level, |
153 |
> |
register int box[3][2], |
154 |
> |
int c0, |
155 |
> |
int c1 |
156 |
> |
) |
157 |
|
{ |
158 |
|
int kb[3][2]; |
159 |
|
|
163 |
|
} |
164 |
|
/* split box */ |
165 |
|
*tree = split(box); |
166 |
< |
bcopy((char *)box, (char *)kb, sizeof(kb)); |
166 |
> |
memcpy((void *)kb, (void *)box, sizeof(kb)); |
167 |
|
/* do left (lesser) branch */ |
168 |
|
kb[prim(*tree)][1] = part(*tree); |
169 |
|
cut(tree+(1<<level), level+1, kb, c0, (c0+c1)>>1); |
175 |
|
|
176 |
|
|
177 |
|
static int |
178 |
< |
split(box) /* find median cut for box */ |
179 |
< |
register int box[3][2]; |
178 |
> |
split( /* find median cut for box */ |
179 |
> |
register int box[3][2] |
180 |
> |
) |
181 |
|
{ |
182 |
|
#define c0 r |
183 |
|
register int r, g, b; |