GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
raster/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. More...
 
const char * Rast_parse_color_rule_error (int code)
 Parse color rule. More...
 
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. More...
 
int Rast_read_color_rules (struct Colors *colors, DCELL min, DCELL max, read_rule_fn *read_rule, void *closure)
 Read color rules from file. More...
 
int Rast_load_colors (struct Colors *colors, const char *path, CELL min, CELL max)
 Load color rules from file. More...
 
int Rast_load_fp_colors (struct Colors *colors, const char *path, DCELL min, DCELL max)
 Load color floating-point rules from file. More...
 
void Rast_make_colors (struct Colors *colors, const char *name, CELL min, CELL max)
 Load color rules from predefined color table. More...
 
void Rast_make_fp_colors (struct Colors *colors, const char *name, DCELL min, DCELL max)
 Load color rules from predefined floating-point color table. More...
 

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

enum rule_error
Enumerator
CR_OK 
CR_ERROR_RULE_SYNTAX 
CR_ERROR_COLOR_SYNTAX 
CR_ERROR_PERCENT 
CR_ERROR_VALUE 

Definition at line 29 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 300 of file raster/color_rules.c.

◆ 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 316 of file raster/color_rules.c.

◆ 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 340 of file raster/color_rules.c.

◆ 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 353 of file raster/color_rules.c.

◆ 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 60 of file raster/color_rules.c.

◆ 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 114 of file raster/color_rules.c.

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

◆ 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 152 of file raster/color_rules.c.

◆ 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 198 of file raster/color_rules.c.