7 #define umalloc(n) (unsigned char *) G_malloc((size_t)n)
8 #define urealloc(s,n) (unsigned char *) G_realloc(s,(size_t)n)
10 #define LIMIT(x) if (x < 0) x = 0; else if (x > 255) x = 255;
13 int red,
int grn,
int blu,
14 struct _Color_Info_ *cp)
18 long newlen, curlen, gap;
25 if (!cp->lookup.active) {
26 cp->lookup.active = 1;
27 cp->lookup.nalloc = 256;
28 cp->lookup.red =
umalloc(cp->lookup.nalloc);
29 cp->lookup.grn =
umalloc(cp->lookup.nalloc);
30 cp->lookup.blu =
umalloc(cp->lookup.nalloc);
31 cp->lookup.set =
umalloc(cp->lookup.nalloc);
32 cp->max = cp->min =
cat;
36 else if (cat > cp->max) {
37 curlen = cp->max - cp->min + 1;
38 newlen = cat - cp->min + 1;
40 if (nalloc != (
int)nalloc)
43 if (nalloc > cp->lookup.nalloc) {
44 while (cp->lookup.nalloc < nalloc)
45 cp->lookup.nalloc += 256;
46 nalloc = cp->lookup.nalloc;
48 cp->lookup.red =
urealloc((
char *)cp->lookup.red, nalloc);
49 cp->lookup.grn =
urealloc((
char *)cp->lookup.grn, nalloc);
50 cp->lookup.blu =
urealloc((
char *)cp->lookup.blu, nalloc);
51 cp->lookup.set =
urealloc((
char *)cp->lookup.set, nalloc);
55 for (i = curlen; i < newlen; i++) {
56 cp->lookup.red[i] = 255;
57 cp->lookup.grn[i] = 255;
58 cp->lookup.blu[i] = 255;
59 cp->lookup.set[i] = 0;
63 else if (cat < cp->
min) {
64 curlen = cp->max - cp->min + 1;
65 newlen = cp->max - cat + 1;
66 gap = newlen - curlen;
68 if (nalloc != (
int)nalloc)
71 if (nalloc > cp->lookup.nalloc) {
72 while (cp->lookup.nalloc < nalloc)
73 cp->lookup.nalloc += 256;
74 nalloc = cp->lookup.nalloc;
76 cp->lookup.red =
urealloc((
char *)cp->lookup.red, nalloc);
77 cp->lookup.grn =
urealloc((
char *)cp->lookup.grn, nalloc);
78 cp->lookup.blu =
urealloc((
char *)cp->lookup.blu, nalloc);
79 cp->lookup.set =
urealloc((
char *)cp->lookup.set, nalloc);
83 for (i = 1; i <= curlen; i++) {
84 cp->lookup.red[newlen - i] = cp->lookup.red[curlen - i];
85 cp->lookup.grn[newlen - i] = cp->lookup.grn[curlen - i];
86 cp->lookup.blu[newlen - i] = cp->lookup.blu[curlen - i];
87 cp->lookup.set[newlen - i] = cp->lookup.set[curlen - i];
91 for (i = 1; i < gap; i++) {
92 cp->lookup.red[i] = 255;
93 cp->lookup.grn[i] = 255;
94 cp->lookup.blu[i] = 255;
95 cp->lookup.set[i] = 0;
102 cp->lookup.red[i] = red;
103 cp->lookup.grn[i] = grn;
104 cp->lookup.blu[i] = blu;
105 cp->lookup.set[i] = 1;
int G__insert_color_into_lookup(CELL cat, int red, int grn, int blu, struct _Color_Info_ *cp)