GRASS 8 Programmer's Manual 8.6.0dev(2026)-8843f13794
Loading...
Searching...
No Matches
color_out.c
Go to the documentation of this file.
1/*!
2 \file lib/raster/color_out.c
3
4 \brief Raster Library - Print color table
5
6 SPDX-FileCopyrightText: 2010-2011 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Glynn Clements
10 */
11
12#include <grass/raster.h>
13
14static void write_rule(DCELL *val, DCELL *min, DCELL *max, int r, int g, int b,
15 FILE *fp, int perc)
16{
17 static DCELL v0;
18 static int r0 = -1, g0 = -1, b0 = -1;
19
20 if (v0 == *val && r0 == r && g0 == g && b0 == b)
21 return;
22 v0 = *val, r0 = r, g0 = g, b0 = b;
23
24 if (perc)
25 fprintf(fp, "%g%% %d:%d:%d\n", 100 * (*val - *min) / (*max - *min), r,
26 g, b);
27 else
28 fprintf(fp, "%g %d:%d:%d\n", *val, r, g, b);
29}
30
31/*!
32 \brief Print color table
33
34 \param colors pointer to Colors structure
35 \param min,max minimum and maximum value for percentage output (used only
36 when \p perc is non-zero) \param fp file where to print color table rules
37 \param perc TRUE for percentage output
38 */
39void Rast_print_colors(struct Colors *colors, DCELL min, DCELL max, FILE *fp,
40 int perc)
41{
42 int i, count;
43
44 count = 0;
45 if (colors->version < 0) {
46 /* 3.0 format */
47 CELL lo, hi;
48
49 Rast_get_c_color_range(&lo, &hi, colors);
50
51 for (i = lo; i <= hi; i++) {
52 unsigned char r, g, b, set;
53 DCELL val = (DCELL)i;
54
55 Rast_lookup_c_colors(&i, &r, &g, &b, &set, 1, colors);
56 write_rule(&val, &min, &max, r, g, b, fp, perc);
57 }
58 }
59 else {
60 count = Rast_colors_count(colors);
61
62 for (i = 0; i < count; i++) {
64 unsigned char r1, g1, b1, r2, g2, b2;
65
66 Rast_get_fp_color_rule(&val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2,
67 colors, count - 1 - i);
68
69 write_rule(&val1, &min, &max, r1, g1, b1, fp, perc);
70 write_rule(&val2, &min, &max, r2, g2, b2, fp, perc);
71 }
72 }
73
74 {
75 int r, g, b;
76
77 Rast_get_null_value_color(&r, &g, &b, colors);
78 fprintf(fp, "nv %d:%d:%d\n", r, g, b);
79 Rast_get_default_color(&r, &g, &b, colors);
80 fprintf(fp, "default %d:%d:%d\n", r, g, b);
81 }
82
83 if (fp != stdout)
84 fclose(fp);
85}
void Rast_print_colors(struct Colors *colors, DCELL min, DCELL max, FILE *fp, int perc)
Print color table.
Definition color_out.c:39
int Rast_colors_count(const struct Colors *)
Get both modular and fixed rules count.
void Rast_get_c_color_range(CELL *, CELL *, const struct Colors *)
Get color range values (CELL)
Definition color_range.c:62
int Rast_get_fp_color_rule(DCELL *, unsigned char *, unsigned char *, unsigned char *, DCELL *, unsigned char *, unsigned char *, unsigned char *, const struct Colors *, int)
Get color rule from both modular and fixed rules.
void Rast_get_null_value_color(int *, int *, int *, const struct Colors *)
Gets color for null value.
Definition color_get.c:124
void Rast_lookup_c_colors(const CELL *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, int, struct Colors *)
Lookup an array of colors.
Definition color_look.c:42
void Rast_get_default_color(int *, int *, int *, const struct Colors *)
Gets default color.
Definition color_get.c:152
#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
int count
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 version
Definition gis.h:690