GRASS 8 Programmer's Manual 8.6.0dev(2026)-745b61fbf6
Loading...
Searching...
No Matches
color_rule_get.c
Go to the documentation of this file.
1/*!
2 * \file lib/raster/color_rule_get.c
3 *
4 * \brief Raster Library - Get color rules.
5 *
6 * SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Original author CERL
10 */
11
12#include <grass/gis.h>
13#include <grass/raster.h>
14
15/*!
16 \brief Get both modular and fixed rules count
17
18 \param colors pointer to color table structure
19
20 \return number of rules in color table
21 */
22int Rast_colors_count(const struct Colors *colors)
23{
24 int count = 0;
25 struct _Color_Rule_ *rule;
26
27 if (colors->fixed.rules) {
28 count++;
29 rule = colors->fixed.rules;
30
31 while (rule->next) {
32 count++;
33 rule = rule->next;
34 }
35 }
36 if (colors->modular.rules) {
37 count++;
38 rule = colors->modular.rules;
39
40 while (rule->next) {
41 count++;
42 rule = rule->next;
43 }
44 }
45 return count;
46}
47
48/*!
49 \brief Get color rule from both modular and fixed rules
50
51 Rules are returned in the order as stored in the table
52 (i.e. unexpected, high values first)
53
54 \param val1 color value
55 \param[out] r1,g1,b1 color value
56 \param val2 color value
57 \param[out] r2,g2,b2 color value
58 \param colors pointer to color table structure
59 \param rule rule index from 0 to G_color_count()-1
60
61 \return 0 success
62 \return 1 index out of range
63 */
64int Rast_get_fp_color_rule(DCELL *val1, unsigned char *r1, unsigned char *g1,
65 unsigned char *b1, DCELL *val2, unsigned char *r2,
66 unsigned char *g2, unsigned char *b2,
67 const struct Colors *colors, int rule)
68{
69 int index = -1;
70 int found = 0;
71 const struct _Color_Rule_ *rl;
72
73 *val1 = *val2 = 0.0;
74 *r1 = *g1 = *b1 = *r2 = *g2 = *b2 = 0;
75
76 /* Find the rule */
77 if (colors->fixed.rules) {
78 rl = colors->fixed.rules;
79 index++;
80 if (index == rule)
81 found = 1;
82
83 while (!found && rl->next) {
84 rl = rl->next;
85 index++;
86 if (index == rule)
87 found = 1;
88 }
89 }
90 if (!found && colors->modular.rules) {
91 rl = colors->modular.rules;
92 index++;
93 if (index == rule)
94 found = 1;
95
96 while (!found && rl->next) {
97 rl = rl->next;
98 index++;
99 if (index == rule)
100 found = 1;
101 }
102 }
103
104 if (!found)
105 return 1;
106
107 /* Set values */
108 *val1 = rl->low.value;
109 *val2 = rl->high.value;
110
111 *r1 = rl->low.red;
112 *g1 = rl->low.grn;
113 *b1 = rl->low.blu;
114
115 *r2 = rl->high.red;
116 *g2 = rl->high.grn;
117 *b2 = rl->high.blu;
118
119 return 0;
120}
int Rast_colors_count(const struct Colors *colors)
Get both modular and fixed rules count.
int Rast_get_fp_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.
double DCELL
Definition gis.h:632
int count
Definition gis.h:689
struct _Color_Info_ fixed
Definition gis.h:702
struct _Color_Info_ modular
Definition gis.h:703
struct _Color_Rule_ * next
Definition gis.h:661