4 #define LOOKUP_COLORS 2048
6 static int organizing = 0;
7 static int organize_lookup(
struct Colors *,
int);
8 static int organize_fp_lookup(
struct Colors *,
int);
9 static int double_comp(
const void *,
const void *);
17 organize_lookup(colors, 0);
18 organize_lookup(colors, 1);
20 organize_fp_lookup(colors, 0);
21 organize_fp_lookup(colors, 1);
29 static int organize_fp_lookup(
struct Colors *colors,
int mod)
33 struct _Color_Info_ *cp;
34 struct _Color_Rule_ *
rule;
37 cp = &colors->modular;
42 if (cp->lookup.active || cp->fp_lookup.active)
47 cp->fp_lookup.vals = (DCELL *)
48 G_calloc(cp->n_rules * 2,
sizeof(DCELL));
50 cp->fp_lookup.rules = (
struct _Color_Rule_ **)
51 G_calloc(cp->n_rules * 2,
sizeof(
struct _Color_Rule_ *));
65 for (rule = cp->rules; rule->next; rule = rule->next) ;
67 for (; rule; rule = rule->prev) {
69 if (i == 0 || rule->low.value != cp->fp_lookup.vals[i - 1])
70 cp->fp_lookup.vals[i++] = rule->low.value;
71 cp->fp_lookup.vals[i++] = rule->high.value;
73 cp->fp_lookup.nalloc = i;
76 qsort((
char *)cp->fp_lookup.vals, cp->fp_lookup.nalloc,
77 sizeof(DCELL), &double_comp);
80 for (i = 0; i < cp->fp_lookup.nalloc - 1; i++) {
81 val = (cp->fp_lookup.vals[i] + cp->fp_lookup.vals[i + 1]) / 2.;
84 for (rule = cp->rules; rule; rule = rule->next)
85 if (rule->low.value <= val && val <= rule->high.value)
90 cp->fp_lookup.rules[i] = rule;
92 cp->fp_lookup.active = 1;
97 static int organize_lookup(
struct Colors *colors,
int mod)
102 struct _Color_Info_ *cp;
105 if (colors->is_float)
109 cp = &colors->modular;
113 if (cp->lookup.active)
116 n = (CELL) cp->max - (CELL) cp->min + 1;
121 for (i = 0; i <
n; i++)
124 cp->lookup.nalloc =
n;
125 cp->lookup.red = (
unsigned char *)G_malloc(n);
126 cp->lookup.grn = (
unsigned char *)G_malloc(n);
127 cp->lookup.blu = (
unsigned char *)G_malloc(n);
128 cp->lookup.set = (
unsigned char *)G_malloc(n);
130 G_zero(cp->lookup.set, n *
sizeof(
unsigned char));
132 cp->lookup.red, cp->lookup.grn, cp->lookup.blu,
133 cp->lookup.set, n, colors, mod, 1, CELL_TYPE);
135 cp->lookup.active = 1;
140 static int double_comp(
const void *xx,
const void *yy)
142 const DCELL *x = xx, *
y = yy;
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
int G__organize_colors(struct Colors *colors)
int G__lookup_colors(const void *raster, unsigned char *red, unsigned char *grn, unsigned char *blu, unsigned char *set, int n, struct Colors *colors, int mod, int rules_only, RASTER_MAP_TYPE data_type)