GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
color_range.c
Go to the documentation of this file.
1 /*!
2  * \file lib/raster/color_range.c
3  *
4  * \brief Raster Library - Color range functions.
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 <math.h>
15 #include <grass/gis.h>
16 #include <grass/raster.h>
17 
18 /*!
19  \brief Set color range (CELL version)
20 
21  \param min,max minimum and maximum value
22  \param colors pointer to Colors structure which holds color info
23  */
24 void Rast_set_c_color_range(CELL min, CELL max, struct Colors *colors)
25 {
26  if (min < max) {
27  colors->cmin = (DCELL)min;
28  colors->cmax = (DCELL)max;
29  }
30  else {
31  colors->cmin = (DCELL)max;
32  colors->cmax = (DCELL)min;
33  }
34 }
35 
36 /*!
37  \brief Set color range (DCELL version)
38 
39  \param min,max minimum and maximum value
40  \param colors pointer to Colors structure which holds color info
41  */
43 {
44  if (min < max) {
45  colors->cmin = min;
46  colors->cmax = max;
47  }
48  else {
49  colors->cmin = max;
50  colors->cmax = min;
51  }
52 }
53 
54 /*!
55  \brief Get color range values (CELL)
56 
57  Returns min and max category in the range or huge numbers if the
58  color table is defined on floating cell values and not on
59  categories.
60 
61  \param[out] min,max minimum and maximum value
62  \param colors pointer to Colors structure which holds color info
63  */
64 void Rast_get_c_color_range(CELL *min, CELL *max, const struct Colors *colors)
65 {
66  if (!colors->is_float) {
67  *min = (CELL)floor(colors->cmin);
68  *max = (CELL)ceil(colors->cmax);
69  }
70  else {
71  *min = -255 * 255 * 255;
72  *max = 255 * 255 * 255;
73  }
74 }
75 
76 /*!
77  \brief Get color range values (DCELL)
78 
79  Returns min and max category in the range or huge numbers if the
80  color table is defined on floating cell values and not on
81  categories.
82 
83  \param[out] min,max minimum and maximum value
84  \param colors pointer to Colors structure which holds color info
85  */
86 void Rast_get_d_color_range(DCELL *min, DCELL *max, const struct Colors *colors)
87 {
88  *min = colors->cmin;
89  *max = colors->cmax;
90 }
void Rast_get_d_color_range(DCELL *min, DCELL *max, const struct Colors *colors)
Get color range values (DCELL)
Definition: color_range.c:86
void Rast_get_c_color_range(CELL *min, CELL *max, const struct Colors *colors)
Get color range values (CELL)
Definition: color_range.c:64
void Rast_set_d_color_range(DCELL min, DCELL max, struct Colors *colors)
Set color range (DCELL version)
Definition: color_range.c:42
void Rast_set_c_color_range(CELL min, CELL max, struct Colors *colors)
Set color range (CELL version)
Definition: color_range.c:24
#define min(x, y)
Definition: draw2.c:29
#define max(x, y)
Definition: draw2.c:30
double DCELL
Definition: gis.h:629
int CELL
Definition: gis.h:628
Definition: gis.h:686
int is_float
Definition: gis.h:690
DCELL cmax
Definition: gis.h:702
DCELL cmin
Definition: gis.h:701