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