17 #include <grass/gis.h>
19 #define LIMIT(x) if (x < 0) x = 0; else if (x > 255) x = 255;
21 static int add_color_rule(
const void *,
int,
int,
int,
22 const void *,
int,
int,
int,
23 struct _Color_Info_ *,
int,
24 DCELL *, DCELL *, RASTER_MAP_TYPE);
42 const DCELL * val2,
int r2,
int g2,
int b2,
43 struct Colors *colors)
45 add_color_rule(val1, r1, g1, b1, val2, r2, g2, b2, &colors->fixed,
46 colors->version, &colors->cmin, &colors->cmax, DCELL_TYPE);
66 const FCELL * cat2,
int r2,
int g2,
int b2,
67 struct Colors *colors)
69 add_color_rule(cat1, r1, g1, b1, cat2, r2, g2, b2, &colors->fixed,
70 colors->version, &colors->cmin, &colors->cmax, FCELL_TYPE);
90 const CELL * cat2,
int r2,
int g2,
int b2,
91 struct Colors *colors)
93 add_color_rule(cat1, r1, g1, b1, cat2, r2, g2, b2, &colors->fixed,
94 colors->version, &colors->cmin, &colors->cmax, CELL_TYPE);
123 const void *val2,
int r2,
int g2,
int b2,
124 struct Colors *colors, RASTER_MAP_TYPE data_type)
126 add_color_rule(val1, r1, g1, b1, val2, r2, g2, b2, &colors->fixed,
127 colors->version, &colors->cmin, &colors->cmax, data_type);
166 int b2,
struct Colors *colors)
168 add_color_rule((
void *)&cat1, r1, g1, b1, (
void *)&cat2, r2, g2, b2,
169 &colors->fixed, colors->version, &colors->cmin,
170 &colors->cmax, CELL_TYPE);
188 const DCELL * val2,
int r2,
int g2,
int b2,
189 struct Colors *colors)
193 if (colors->version < 0)
197 add_color_rule(val1, r1, g1, b1, val2, r2, g2, b2, &colors->modular, 0,
198 &colors->cmin, &colors->cmax, DCELL_TYPE);
219 const FCELL * val2,
int r2,
int g2,
int b2,
220 struct Colors *colors)
224 if (colors->version < 0)
228 add_color_rule(val1, r1, g1, b1, val2, r2, g2, b2, &colors->modular, 0,
229 &colors->cmin, &colors->cmax, FCELL_TYPE);
250 const CELL * val2,
int r2,
int g2,
int b2,
251 struct Colors *colors)
275 const void *val2,
int r2,
int g2,
int b2,
276 struct Colors *colors,
277 RASTER_MAP_TYPE data_type)
281 if (colors->version < 0)
285 add_color_rule(val1, r1, g1, b1, val2, r2, g2, b2, &colors->modular, 0,
286 &colors->cmin, &colors->cmax, data_type);
311 int g2,
int b2,
struct Colors *colors)
315 if (colors->version < 0)
319 add_color_rule((
void *)&cat1, r1, g1, b1, (
void *)&cat2, r2, g2, b2,
320 &colors->modular, 0, &colors->cmin, &colors->cmax,
328 static int add_color_rule(
const void *pt1,
int r1,
int g1,
int b1,
329 const void *pt2,
int r2,
int g2,
int b2,
330 struct _Color_Info_ *cp,
int version, DCELL * cmin,
331 DCELL * cmax, RASTER_MAP_TYPE data_type)
333 struct _Color_Rule_ *
rule, *next;
334 unsigned char red, grn, blu;
335 DCELL
min,
max, val1, val2;
341 rule = (
struct _Color_Rule_ *)G_malloc(
sizeof(*rule));
342 rule->next = rule->prev =
NULL;
355 rule->low.value = rule->high.value = val1;
356 rule->low.red = rule->high.red = (r1 + r2) / 2;
357 rule->low.grn = rule->high.grn = (g1 + g2) / 2;
358 rule->low.blu = rule->high.blu = (b1 + b2) / 2;
360 else if (val1 < val2) {
361 rule->low.value = val1;
366 rule->high.value = val2;
372 rule->low.value = val2;
377 rule->high.value = val1;
388 min = rule->low.value;
389 max = rule->high.value;
391 if (cp->min > cp->max) {
423 for (cat = (CELL)
min; cat <= (CELL) max; cat++) {
432 cp->rules->prev = rule;
433 rule->next = cp->rules;
439 min = rule->low.value;
440 max = rule->high.value;
442 for (rule = rule->next; rule; rule = next) {
444 if (min <= rule->low.value && max >= rule->high.value) {
445 if ((rule->prev->next = next))
446 next->prev = rule->prev;