GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
color_set.c
Go to the documentation of this file.
1 /*!
2  * \file lib/raster/color_set.c
3  *
4  * \brief Raster Library - Set colors for raster maps.
5  *
6  * (C) 2001-2009 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public License
9  * (>=v2). Read the file COPYING that comes with GRASS for details.
10  *
11  * \author Original author CERL
12  */
13 
14 #include <grass/gis.h>
15 #include <grass/raster.h>
16 
17 /*!
18  * \brief Set a category color (CELL)
19  *
20  * The <i>red, green</i>, and <i>blue</i> intensities for the color
21  * associated with category <i>cat</i> are set in the <i>colors</i>
22  * structure. The intensities must be in the range 0 - 255. Values
23  * below zero are set as zero, values above 255 are set as 255.
24  *
25  * <b>Warning: Use of this routine is discouraged because it defeats the new
26  * color logic.</b>
27  *
28  * It is provided only for backward compatibility. Overuse can create
29  * large color tables. Rast_add_c_color_rule() should be used whenever
30  * possible.
31  *
32  * <b>Note:</b> The <i>colors</i> structure must have been
33  * initialized by G_init_color().
34  *
35  * \param cat raster cell value
36  * \param r red value
37  * \param g green value
38  * \param b blue value
39  * \param colors pointer to Colors structure which holds color info
40  */
41 void Rast_set_c_color(CELL cat, int r, int g, int b, struct Colors *colors)
42 {
43  if (Rast_is_c_null_value(&cat))
44  Rast_set_null_value_color(r, g, b, colors);
45  else
46  Rast_add_c_color_rule(&cat, r, g, b, &cat, r, g, b, colors);
47 }
48 
49 /*!
50  * \brief Set a category color (DCELL)
51  *
52  * See Rast_set_c_color() for detailed information.
53  *
54  * \param val raster cell value
55  * \param r red value
56  * \param g green value
57  * \param b blue value
58  * \param colors pointer to Colors structure which holds color info
59  */
60 void Rast_set_d_color(DCELL val, int r, int g, int b, struct Colors *colors)
61 {
62  if (Rast_is_d_null_value(&val))
63  Rast_set_null_value_color(r, g, b, colors);
64  else
65  Rast_add_d_color_rule(&val, r, g, b, &val, r, g, b, colors);
66 }
67 
68 /*!
69  * \brief Set color for NULL-value
70  *
71  * Sets the color (in <i>colors</i>) for the NULL-value to
72  * <i>red, green, blue</i>.
73  *
74  * \param red red value
75  * \param grn green value
76  * \param blu blue value
77  * \param colors pointer to Colors structure which holds color info
78  */
79 void Rast_set_null_value_color(int red, int grn, int blu, struct Colors *colors)
80 {
81  colors->null_red = red;
82  colors->null_grn = grn;
83  colors->null_blu = blu;
84  colors->null_set = 1;
85 }
86 
87 /*!
88  * \brief Set default color value
89  *
90  * Sets the default color (in <i>colors</i>) to <i>red, green,
91  * blue</i>. This is the color for values which do not have an
92  * explicit rule.
93  *
94  * \param red red value
95  * \param grn green value
96  * \param blu blue value
97  * \param colors pointer to Colors structure which holds color info
98  */
99 void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
100 {
101  colors->undef_red = red;
102  colors->undef_grn = grn;
103  colors->undef_blu = blu;
104  colors->undef_set = 1;
105 }
void Rast_set_null_value_color(int red, int grn, int blu, struct Colors *colors)
Set color for NULL-value.
Definition: color_set.c:79
void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
Set default color value.
Definition: color_set.c:99
void Rast_set_d_color(DCELL val, int r, int g, int b, struct Colors *colors)
Set a category color (DCELL)
Definition: color_set.c:60
void Rast_set_c_color(CELL cat, int r, int g, int b, struct Colors *colors)
Set a category color (CELL)
Definition: color_set.c:41
void Rast_add_d_color_rule(const DCELL *, int, int, int, const DCELL *, int, int, int, struct Colors *)
Adds the floating-point color rule (DCELL version)
Definition: color_rule.c:38
void Rast_add_c_color_rule(const CELL *, int, int, int, const CELL *, int, int, int, struct Colors *)
Adds the integer color rule (CELL version)
Definition: color_rule.c:76
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:408
#define Rast_is_c_null_value(cellVal)
Definition: defs/raster.h:404
double DCELL
Definition: gis.h:629
int CELL
Definition: gis.h:628
float g
Definition: named_colr.c:7
double b
Definition: r_raster.c:39
double r
Definition: r_raster.c:39
Definition: gis.h:686
int null_set
Definition: gis.h:691
unsigned char undef_blu
Definition: gis.h:698
unsigned char null_blu
Definition: gis.h:694
unsigned char undef_grn
Definition: gis.h:697
unsigned char undef_red
Definition: gis.h:696
int undef_set
Definition: gis.h:695
unsigned char null_grn
Definition: gis.h:693
unsigned char null_red
Definition: gis.h:692