GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72741
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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

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.

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.

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.

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().

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.

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().

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.

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

Referenced by Rast_read_color_rule().

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.

Referenced by 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.

References _, G_debug(), G_fatal_error(), G_getl2(), G_strip(), Rast_parse_color_rule(), and Rast_parse_color_rule_error().

Referenced by 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.

References _, b, g, G_fatal_error(), G_free(), 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().