GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
color_rule_get.c
Go to the documentation of this file.
1 
17 #include <grass/gis.h>
18 
26 int G_colors_count(const struct Colors *colors)
27 {
28  int count = 0;
29  struct _Color_Rule_ *rule;
30 
31  if (colors->fixed.rules) {
32  count++;
33  rule = colors->fixed.rules;
34 
35  while (rule->next) {
36  count++;
37  rule = rule->next;
38  }
39  }
40  if (colors->modular.rules) {
41  count++;
42  rule = colors->modular.rules;
43 
44  while (rule->next) {
45  count++;
46  rule = rule->next;
47  }
48  }
49  return count;
50 }
51 
67 int G_get_f_color_rule(DCELL * val1, unsigned char *r1, unsigned char *g1,
68  unsigned char *b1, DCELL * val2, unsigned char *r2,
69  unsigned char *g2, unsigned char *b2,
70  const struct Colors *colors, int rule)
71 {
72  int index = -1;
73  int found = 0;
74  const struct _Color_Rule_ *rl;
75 
76  *val1 = *val2 = 0.0;
77  *r1 = *g1 = *b1 = *r2 = *g2 = *b2 = 0;
78 
79  /* Find the rule */
80  if (colors->fixed.rules) {
81  rl = colors->fixed.rules;
82  index++;
83  if (index == rule)
84  found = 1;
85 
86  while (!found && rl->next) {
87  rl = rl->next;
88  index++;
89  if (index == rule)
90  found = 1;
91  }
92  }
93  if (!found && colors->modular.rules) {
94  rl = colors->modular.rules;
95  index++;
96  if (index == rule)
97  found = 1;
98 
99  while (!found && rl->next) {
100  rl = rl->next;
101  index++;
102  if (index == rule)
103  found = 1;
104  }
105  }
106 
107  if (!found)
108  return 1;
109 
110  /* Set values */
111  *val1 = rl->low.value;
112  *val2 = rl->high.value;
113 
114  *r1 = rl->low.red;
115  *g1 = rl->low.grn;
116  *b1 = rl->low.blu;
117 
118  *r2 = rl->high.red;
119  *g2 = rl->high.grn;
120  *b2 = rl->high.blu;
121 
122  return 0;
123 }
int G_colors_count(const struct Colors *colors)
Get both modular and fixed rules count.
DCELL val1
Definition: g3dcats.c:91
int count
DCELL val2
Definition: g3dcats.c:91
int G_get_f_color_rule(DCELL *val1, unsigned char *r1, unsigned char *g1, unsigned char *b1, DCELL *val2, unsigned char *r2, unsigned char *g2, unsigned char *b2, const struct Colors *colors, int rule)
Get color rule from both modular and fixed rules.