GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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,
80  struct Colors *colors)
81 {
82  colors->null_red = red;
83  colors->null_grn = grn;
84  colors->null_blu = blu;
85  colors->null_set = 1;
86 }
87 
88 /*!
89  * \brief Set default color value
90  *
91  * Sets the default color (in <i>colors</i>) to <i>red, green,
92  * blue</i>. This is the color for values which do not have an
93  * explicit rule.
94  *
95  * \param red red value
96  * \param grn green value
97  * \param blu blue value
98  * \param colors pointer to Colors structure which holds color info
99  */
100 void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
101 {
102  colors->undef_red = red;
103  colors->undef_grn = grn;
104  colors->undef_blu = blu;
105  colors->undef_set = 1;
106 }
int null_set
Definition: gis.h:671
unsigned char null_blu
Definition: gis.h:674
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:75
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:420
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
unsigned char null_grn
Definition: gis.h:673
double DCELL
Definition: gis.h:603
unsigned char undef_red
Definition: gis.h:676
void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
Set default color value.
Definition: color_set.c:100
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
double b
Definition: r_raster.c:39
float g
Definition: named_colr.c:8
unsigned char null_red
Definition: gis.h:672
Definition: gis.h:665
unsigned char undef_blu
Definition: gis.h:678
unsigned char undef_grn
Definition: gis.h:677
int CELL
Definition: gis.h:602
int undef_set
Definition: gis.h:675
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:35
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
#define Rast_is_c_null_value(cellVal)
Definition: defs/raster.h:416
double r
Definition: r_raster.c:39