GRASS 8 Programmer's Manual 8.6.0dev(2026)-8843f13794
Loading...
Searching...
No Matches
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 * 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 Set a category color (CELL)
17 *
18 * The <i>red, green</i>, and <i>blue</i> intensities for the color
19 * associated with category <i>cat</i> are set in the <i>colors</i>
20 * structure. The intensities must be in the range 0 - 255. Values
21 * below zero are set as zero, values above 255 are set as 255.
22 *
23 * <b>Warning: Use of this routine is discouraged because it defeats the new
24 * color logic.</b>
25 *
26 * It is provided only for backward compatibility. Overuse can create
27 * large color tables. Rast_add_c_color_rule() should be used whenever
28 * possible.
29 *
30 * <b>Note:</b> The <i>colors</i> structure must have been
31 * initialized by G_init_color().
32 *
33 * \param cat raster cell value
34 * \param r red value
35 * \param g green value
36 * \param b blue value
37 * \param colors pointer to Colors structure which holds color info
38 */
39void Rast_set_c_color(CELL cat, int r, int g, int b, struct Colors *colors)
40{
41 if (Rast_is_c_null_value(&cat))
42 Rast_set_null_value_color(r, g, b, colors);
43 else
44 Rast_add_c_color_rule(&cat, r, g, b, &cat, r, g, b, colors);
45}
46
47/*!
48 * \brief Set a category color (DCELL)
49 *
50 * See Rast_set_c_color() for detailed information.
51 *
52 * \param val raster cell value
53 * \param r red value
54 * \param g green value
55 * \param b blue value
56 * \param colors pointer to Colors structure which holds color info
57 */
58void Rast_set_d_color(DCELL val, int r, int g, int b, struct Colors *colors)
59{
60 if (Rast_is_d_null_value(&val))
61 Rast_set_null_value_color(r, g, b, colors);
62 else
63 Rast_add_d_color_rule(&val, r, g, b, &val, r, g, b, colors);
64}
65
66/*!
67 * \brief Set color for NULL-value
68 *
69 * Sets the color (in <i>colors</i>) for the NULL-value to
70 * <i>red, green, blue</i>.
71 *
72 * \param red red value
73 * \param grn green value
74 * \param blu blue value
75 * \param colors pointer to Colors structure which holds color info
76 */
77void Rast_set_null_value_color(int red, int grn, int blu, struct Colors *colors)
78{
79 colors->null_red = red;
80 colors->null_grn = grn;
81 colors->null_blu = blu;
82 colors->null_set = 1;
83}
84
85/*!
86 * \brief Set default color value
87 *
88 * Sets the default color (in <i>colors</i>) to <i>red, green,
89 * blue</i>. This is the color for values which do not have an
90 * explicit rule.
91 *
92 * \param red red value
93 * \param grn green value
94 * \param blu blue value
95 * \param colors pointer to Colors structure which holds color info
96 */
97void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
98{
99 colors->undef_red = red;
100 colors->undef_grn = grn;
101 colors->undef_blu = blu;
102 colors->undef_set = 1;
103}
void Rast_set_null_value_color(int red, int grn, int blu, struct Colors *colors)
Set color for NULL-value.
Definition color_set.c:77
void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
Set default color value.
Definition color_set.c:97
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:58
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:39
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:36
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:74
#define Rast_is_d_null_value(dcellVal)
#define Rast_is_c_null_value(cellVal)
double DCELL
Definition gis.h:632
int CELL
Definition gis.h:631
float g
Definition named_colr.c:7
double b
Definition r_raster.c:37
double r
Definition r_raster.c:37
Definition gis.h:689
int null_set
Definition gis.h:694
unsigned char undef_blu
Definition gis.h:701
unsigned char null_blu
Definition gis.h:697
unsigned char undef_grn
Definition gis.h:700
unsigned char undef_red
Definition gis.h:699
int undef_set
Definition gis.h:698
unsigned char null_grn
Definition gis.h:696
unsigned char null_red
Definition gis.h:695