GRASS Programmer's Manual
6.4.1(2011)
|
00001 00017 #include <grass/gis.h> 00018 00026 int G_colors_count(const struct Colors *colors) 00027 { 00028 int count = 0; 00029 struct _Color_Rule_ *rule; 00030 00031 if (colors->fixed.rules) { 00032 count++; 00033 rule = colors->fixed.rules; 00034 00035 while (rule->next) { 00036 count++; 00037 rule = rule->next; 00038 } 00039 } 00040 if (colors->modular.rules) { 00041 count++; 00042 rule = colors->modular.rules; 00043 00044 while (rule->next) { 00045 count++; 00046 rule = rule->next; 00047 } 00048 } 00049 return count; 00050 } 00051 00067 int G_get_f_color_rule(DCELL * val1, unsigned char *r1, unsigned char *g1, 00068 unsigned char *b1, DCELL * val2, unsigned char *r2, 00069 unsigned char *g2, unsigned char *b2, 00070 const struct Colors *colors, int rule) 00071 { 00072 int index = -1; 00073 int found = 0; 00074 const struct _Color_Rule_ *rl; 00075 00076 *val1 = *val2 = 0.0; 00077 *r1 = *g1 = *b1 = *r2 = *g2 = *b2 = 0; 00078 00079 /* Find the rule */ 00080 if (colors->fixed.rules) { 00081 rl = colors->fixed.rules; 00082 index++; 00083 if (index == rule) 00084 found = 1; 00085 00086 while (!found && rl->next) { 00087 rl = rl->next; 00088 index++; 00089 if (index == rule) 00090 found = 1; 00091 } 00092 } 00093 if (!found && colors->modular.rules) { 00094 rl = colors->modular.rules; 00095 index++; 00096 if (index == rule) 00097 found = 1; 00098 00099 while (!found && rl->next) { 00100 rl = rl->next; 00101 index++; 00102 if (index == rule) 00103 found = 1; 00104 } 00105 } 00106 00107 if (!found) 00108 return 1; 00109 00110 /* Set values */ 00111 *val1 = rl->low.value; 00112 *val2 = rl->high.value; 00113 00114 *r1 = rl->low.red; 00115 *g1 = rl->low.grn; 00116 *b1 = rl->low.blu; 00117 00118 *r2 = rl->high.red; 00119 *g2 = rl->high.grn; 00120 *b2 = rl->high.blu; 00121 00122 return 0; 00123 }