GRASS 8 Programmer's Manual 8.6.0dev(2026)-8843f13794
Loading...
Searching...
No Matches
color_get.c
Go to the documentation of this file.
1/*!
2 * \file lib/raster/color_get.c
3 *
4 * \brief Raster Library - Get colors from a raster map.
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 Gets color from raster map
17 *
18 * Looks up the rgb colors for <i>rast</i> in the color table
19 * <i>colors</i>.
20 *
21 * The <i>red, green</i>, and <i>blue</i> intensities for the color
22 * associated with category <i>n</i> are extracted from the
23 * <i>colors</i> structure. The intensities will be in the range 0 -
24 * 255. Also works for null cells.
25 *
26 * \param rast raster cell value
27 * \param[out] red red value
28 * \param[out] grn green value
29 * \param[out] blu blue value
30 * \param colors pointer to Colors structure which holds color info
31 * \param map_type map type (CELL, FCELL, DCELL)
32 *
33 * \return 1 if color is set
34 * \return 0 if color is not set
35 */
36int Rast_get_color(const void *rast, int *red, int *grn, int *blu,
37 struct Colors *colors, RASTER_MAP_TYPE map_type)
38{
39 unsigned char r, g, b, set;
40
41 Rast_lookup_colors(rast, &r, &g, &b, &set, 1, colors, map_type);
42
43 *red = (int)r;
44 *grn = (int)g;
45 *blu = (int)b;
46
47 return (int)set;
48}
49
50/*!
51 * \brief Gets color from raster map (CELL)
52 *
53 * Looks up the rgb colors for <i>rast</i> in the color table
54 * <i>colors</i>.
55 *
56 * \param rast raster cell value
57 * \param[out] red red value
58 * \param[out] grn green value
59 * \param[out] blu blue value
60 * \param colors pointer to Colors structure which holds color info
61 *
62 * \return 1 if color is set
63 * \return 0 if color is not set
64 */
65int Rast_get_c_color(const CELL *rast, int *red, int *grn, int *blu,
66 struct Colors *colors)
67{
68 return Rast_get_color(rast, red, grn, blu, colors, CELL_TYPE);
69}
70
71/*!
72 * \brief Gets color from raster map (FCELL)
73 *
74 * Looks up the rgb colors for <i>rast</i> in the color table
75 * <i>colors</i>.
76 *
77 * \param rast raster cell value
78 * \param[out] red red value
79 * \param[out] grn green value
80 * \param[out] blu blue value
81 * \param colors pointer to Colors structure which holds color info
82 *
83 * \return 1 if color is set
84 * \return 0 if color is not set
85 */
86int Rast_get_f_color(const FCELL *rast, int *red, int *grn, int *blu,
87 struct Colors *colors)
88{
89 return Rast_get_color(rast, red, grn, blu, colors, FCELL_TYPE);
90}
91
92/*!
93 * \brief Gets color from raster map (DCELL)
94 *
95 * Looks up the rgb colors for <i>rast</i> in the color table
96 * <i>colors</i>.
97 *
98 * \param rast raster cell value
99 * \param[out] red red value
100 * \param[out] grn green value
101 * \param[out] blu blue value
102 * \param colors pointer to Colors structure which holds color info
103 *
104 * \return 1 if color is set
105 * \return 0 if color is not set
106 */
107int Rast_get_d_color(const DCELL *rast, int *red, int *grn, int *blu,
108 struct Colors *colors)
109{
110 return Rast_get_color(rast, red, grn, blu, colors, DCELL_TYPE);
111}
112
113/*!
114 * \brief Gets color for null value.
115 *
116 * Puts the red, green, and blue components of <i>colors</i> for the
117 * NULL-value into <i>red, grn, and blu</i>.
118 *
119 * \param[out] red red value
120 * \param[out] grn green value
121 * \param[out] blu blue value
122 * \param colors pointer to Colors structure which holds color info
123 */
124void Rast_get_null_value_color(int *red, int *grn, int *blu,
125 const struct Colors *colors)
126{
127 if (colors->null_set) {
128 *red = (int)colors->null_red;
129 *grn = (int)colors->null_grn;
130 *blu = (int)colors->null_blu;
131 }
132 else if (colors->undef_set) {
133 *red = (int)colors->undef_red;
134 *grn = (int)colors->undef_grn;
135 *blu = (int)colors->undef_blu;
136 }
137 else
138 *red = *blu = *grn = 255; /* white */
139}
140
141/*!
142 * \brief Gets default color.
143 *
144 * Puts the red, green, and blue components of the <tt>"default"</tt>
145 * color into <i>red, grn, and blu</i>.
146 *
147 * \param[out] red red value
148 * \param[out] grn green value
149 * \param[out] blu blue value
150 * \param colors pointer to Colors structure which holds color info
151 */
152void Rast_get_default_color(int *red, int *grn, int *blu,
153 const struct Colors *colors)
154{
155 if (colors->undef_set) {
156 *red = (int)colors->undef_red;
157 *grn = (int)colors->undef_grn;
158 *blu = (int)colors->undef_blu;
159 }
160 else
161 *red = *blu = *grn = 255; /* white */
162}
int Rast_get_c_color(const CELL *rast, int *red, int *grn, int *blu, struct Colors *colors)
Gets color from raster map (CELL)
Definition color_get.c:65
void Rast_get_default_color(int *red, int *grn, int *blu, const struct Colors *colors)
Gets default color.
Definition color_get.c:152
int Rast_get_color(const void *rast, int *red, int *grn, int *blu, struct Colors *colors, RASTER_MAP_TYPE map_type)
Gets color from raster map.
Definition color_get.c:36
int Rast_get_d_color(const DCELL *rast, int *red, int *grn, int *blu, struct Colors *colors)
Gets color from raster map (DCELL)
Definition color_get.c:107
void Rast_get_null_value_color(int *red, int *grn, int *blu, const struct Colors *colors)
Gets color for null value.
Definition color_get.c:124
int Rast_get_f_color(const FCELL *rast, int *red, int *grn, int *blu, struct Colors *colors)
Gets color from raster map (FCELL)
Definition color_get.c:86
void Rast_lookup_colors(const void *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, int, struct Colors *, RASTER_MAP_TYPE)
Lookup an array of colors.
Definition color_look.c:76
float FCELL
Definition gis.h:633
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
#define FCELL_TYPE
Definition raster.h:12
#define DCELL_TYPE
Definition raster.h:13
#define CELL_TYPE
Definition raster.h:11
int RASTER_MAP_TYPE
Definition raster.h:25
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