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;
 
  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;
 
void G_free(void *buf)
Free allocated memory. 
int G_add_modular_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule. 
int G_add_d_raster_color_rule(const DCELL *val1, int r1, int g1, int b1, const DCELL *val2, int r2, int g2, int b2, struct Colors *colors)
Adds the floating-point rule (DCELL version) 
int G__color_free_fp_lookup(struct _Color_Info_ *cp)
int G_add_modular_f_raster_color_rule(const FCELL *val1, int r1, int g1, int b1, const FCELL *val2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule (FCELL version) 
def version
Get GRASS version as dictionary. 
int G_add_modular_raster_color_rule(const void *val1, int r1, int g1, int b1, const void *val2, int r2, int g2, int b2, struct Colors *colors, RASTER_MAP_TYPE data_type)
Add modular color rule. 
int G_add_f_raster_color_rule(const FCELL *cat1, int r1, int g1, int b1, const FCELL *cat2, int r2, int g2, int b2, struct Colors *colors)
Adds the floating-point rule (FCELL version) 
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value(). 
int G_add_modular_c_raster_color_rule(const CELL *val1, int r1, int g1, int b1, const CELL *val2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule (CCELL version) 
int G__insert_color_into_lookup(CELL cat, int red, int grn, int blu, struct _Color_Info_ *cp)
int G__interpolate_color_rule(DCELL val, unsigned char *red, unsigned char *grn, unsigned char *blu, const struct _Color_Rule_ *rule)
int G_add_raster_color_rule(const void *val1, int r1, int g1, int b1, const void *val2, int r2, int g2, int b2, struct Colors *colors, RASTER_MAP_TYPE data_type)
Adds the floating-point rule. 
int G__color_free_lookup(struct _Color_Info_ *cp)
int G_add_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2, int r2, int g2, int b2, struct Colors *colors)
Set colors rules. 
int G_add_modular_d_raster_color_rule(const DCELL *val1, int r1, int g1, int b1, const DCELL *val2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule (DCELL version) 
DCELL G_get_raster_value_d(const void *rast, RASTER_MAP_TYPE data_type)
Retrieves the value of type data_type from pointer p,. 
int G_add_c_raster_color_rule(const CELL *cat1, int r1, int g1, int b1, const CELL *cat2, int r2, int g2, int b2, struct Colors *colors)
Adds the floating-point rule (CCELL version)