GRASS 8 Programmer's Manual 8.6.0dev(2026)-5f4f7ad06c
Loading...
Searching...
No Matches
color_rules.c File Reference

Raster Library - Read and parse color rules file. More...

#include <stdio.h>
#include <grass/gis.h>
#include <grass/colors.h>
#include <grass/raster.h>
#include <grass/glocale.h>
Include dependency graph for raster/color_rules.c:

Go to the source code of this file.

Enumerations

enum  rule_error {
  CR_OK = 0 , CR_ERROR_RULE_SYNTAX , CR_ERROR_COLOR_SYNTAX , CR_ERROR_PERCENT ,
  CR_ERROR_VALUE
}
 

Functions

int Rast_parse_color_rule (DCELL min, DCELL max, const char *buf, DCELL *val, int *r, int *g, int *b, int *norm, int *nval, int *dflt)
 Read color rule.
 
const charRast_parse_color_rule_error (int code)
 Parse color rule.
 
int Rast_read_color_rule (void *closure, DCELL min, DCELL max, DCELL *val, int *r, int *g, int *b, int *norm, int *nval, int *dflt)
 Read color rule.
 
int Rast_read_color_rules (struct Colors *colors, DCELL min, DCELL max, read_rule_fn *read_rule, void *closure)
 Read color rules from file.
 
int Rast_load_colors (struct Colors *colors, const char *path, CELL min, CELL max)
 Load color rules from file.
 
int Rast_load_fp_colors (struct Colors *colors, const char *path, DCELL min, DCELL max)
 Load color floating-point rules from file.
 
void Rast_make_colors (struct Colors *colors, const char *name, CELL min, CELL max)
 Load color rules from predefined color table.
 
void Rast_make_fp_colors (struct Colors *colors, const char *name, DCELL min, DCELL max)
 Load color rules from predefined floating-point color table.
 

Detailed Description

Raster Library - Read and parse color rules file.

(C) 2007-2016 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Glynn Clements

Definition in file raster/color_rules.c.

Enumeration Type Documentation

◆ rule_error

Enumerator
CR_OK 
CR_ERROR_RULE_SYNTAX 
CR_ERROR_COLOR_SYNTAX 
CR_ERROR_PERCENT 
CR_ERROR_VALUE 

Definition at line 28 of file raster/color_rules.c.

Function Documentation

◆ Rast_load_colors()

int Rast_load_colors ( struct Colors colors,
const char path,
CELL  min,
CELL  max 
)

Load color rules from file.

Parameters
[out]colorspointer to Colors structure
pathpath to the color rules file
min,maxmin & max values (used only when color rules are in percentage)
Returns
0 on failure
1 on success

Definition at line 293 of file raster/color_rules.c.

References max, and min.

◆ Rast_load_fp_colors()

int Rast_load_fp_colors ( struct Colors colors,
const char path,
DCELL  min,
DCELL  max 
)

Load color floating-point rules from file.

Parameters
[out]colorspointer to Colors structure
pathpath to the color rules file
min,maxmin & max values (used only when color rules are in percentage)
Returns
0 on failure
1 on success

Definition at line 310 of file raster/color_rules.c.

References max, and min.

◆ Rast_make_colors()

void Rast_make_colors ( struct Colors colors,
const char name,
CELL  min,
CELL  max 
)

Load color rules from predefined color table.

Parameters
[out]colorspointer to Colors structure
namename of color table to load
min,maxmin & max values (used only when color rules are in percentage)

Definition at line 335 of file raster/color_rules.c.

References max, min, and name.

Referenced by Rast_make_aspect_colors(), Rast_make_bgyr_colors(), Rast_make_byg_colors(), Rast_make_byr_colors(), Rast_make_grey_scale_colors(), Rast_make_gyr_colors(), Rast_make_rainbow_colors(), Rast_make_ramp_colors(), Rast_make_ryg_colors(), Rast_make_wave_colors(), and Rast_read_colors().

◆ Rast_make_fp_colors()

void Rast_make_fp_colors ( struct Colors colors,
const char name,
DCELL  min,
DCELL  max 
)

Load color rules from predefined floating-point color table.

Parameters
[out]colorspointer to Colors structure
namename of color table to load
min,maxmin & max values (used only when color rules are in percentage)

Definition at line 349 of file raster/color_rules.c.

References max, min, and name.

Referenced by Rast3d_read_colors(), Rast_make_aspect_fp_colors(), Rast_make_bgyr_fp_colors(), Rast_make_byg_fp_colors(), Rast_make_byr_fp_colors(), Rast_make_grey_scale_fp_colors(), Rast_make_gyr_fp_colors(), Rast_make_rainbow_fp_colors(), Rast_make_ramp_fp_colors(), Rast_make_ryg_fp_colors(), Rast_make_wave_fp_colors(), and Rast_read_colors().

◆ Rast_parse_color_rule()

int Rast_parse_color_rule ( DCELL  min,
DCELL  max,
const char buf,
DCELL val,
int r,
int g,
int b,
int norm,
int nval,
int dflt 
)

Read color rule.

The val output parameter is always an absolute value and is derived from the rule and the min and max values in case the rule is in percents.

Always only one of the norm, nval, and dflt output parameters is set to non-zero value, the others are set to zero.

The return code can be translated to an error message using the Rast_parse_color_rule_error() function.

Parameters
min,maxmin & max values (used only when color rules are in percentage)
bufstring with the color rule
[out]valvalue which the color is assigned to
[out]r,g,bcolor values
[out]normset to non-zero value if the value and color are set
[out]nvalset to non-zero value if rule is for null value
[out]dfltset to non-zero value if rule specifies the default color
Returns
enum rule_error values (non-zero on failure)

Definition at line 57 of file raster/color_rules.c.

References b, CR_ERROR_COLOR_SYNTAX, CR_ERROR_PERCENT, CR_ERROR_RULE_SYNTAX, CR_ERROR_VALUE, CR_OK, g, G_chop(), G_str_to_color(), G_strcasecmp(), max, min, r, and x.

Referenced by Rast_read_color_rule().

◆ Rast_parse_color_rule_error()

const char * Rast_parse_color_rule_error ( int  code)

Parse color rule.

Parameters
code
Returns
pointer to buffer with error message

Definition at line 111 of file raster/color_rules.c.

References _, CR_ERROR_COLOR_SYNTAX, CR_ERROR_PERCENT, CR_ERROR_RULE_SYNTAX, CR_ERROR_VALUE, and CR_OK.

Referenced by Rast_read_color_rule().

◆ Rast_read_color_rule()

int Rast_read_color_rule ( void closure,
DCELL  min,
DCELL  max,
DCELL val,
int r,
int g,
int b,
int norm,
int nval,
int dflt 
)

Read color rule.

Parameters
closure
min,maxmin & max values (used only when color rules are in percentage)
valvalue
[out]r,g,bcolor values
norm
nval
dflt
Returns
0 on failure
1 on success

Definition at line 147 of file raster/color_rules.c.

References _, b, g, G_debug(), G_fatal_error(), G_getl2(), G_strip(), max, min, r, Rast_parse_color_rule(), and Rast_parse_color_rule_error().

Referenced by Rast_read_color_rules().

◆ Rast_read_color_rules()

int Rast_read_color_rules ( struct Colors colors,
DCELL  min,
DCELL  max,
read_rule_fn read_rule,
void closure 
)

Read color rules from file.

Parameters
[out]colorspointer to Colors structure
min,maxmin & max values (used only when color rules are in percentage)
read_rulepointer to read_rule_fn structure
closure
Returns
0 on failure
1 on success

Definition at line 191 of file raster/color_rules.c.

References _, b, g, G_fatal_error(), G_free(), G_realloc, max, min, NULL, r, Rast_add_d_color_rule(), Rast_init_colors(), Rast_read_color_rule(), Rast_set_d_color(), Rast_set_default_color(), and Rast_set_null_value_color().