GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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  */
65  const struct Colors *colors)
66 {
67  if (!colors->is_float) {
68  *min = (CELL) floor(colors->cmin);
69  *max = (CELL) ceil(colors->cmax);
70  }
71  else {
72  *min = -255 * 255 * 255;
73  *max = 255 * 255 * 255;
74  }
75 }
76 
77 /*!
78  \brief Get color range values (DCELL)
79 
80  Returns min and max category in the range or huge numbers if the
81  color table is defined on floating cell values and not on
82  categories.
83 
84  \param[out] min,max minimum and maximum value
85  \param colors pointer to Colors structure which holds color info
86  */
88  const struct Colors *colors)
89 {
90  *min = colors->cmin;
91  *max = colors->cmax;
92 }
#define min(x, y)
Definition: draw2.c:31
double DCELL
Definition: gis.h:614
DCELL cmax
Definition: gis.h:693
int is_float
Definition: gis.h:681
#define max(x, y)
Definition: draw2.c:32
DCELL cmin
Definition: gis.h:692
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_c_color_range(CELL min, CELL max, struct Colors *colors)
Set color range (CELL version)
Definition: color_range.c:24
Definition: gis.h:676
void Rast_set_d_color_range(DCELL min, DCELL max, struct Colors *colors)
Set color range (DCELL version)
Definition: color_range.c:42
int CELL
Definition: gis.h:613
void Rast_get_d_color_range(DCELL *min, DCELL *max, const struct Colors *colors)
Get color range values (DCELL)
Definition: color_range.c:87