GRASS GIS 8 Programmer's Manual  8.5.0dev(2025)-93f69d1f13
color_str.c File Reference

GIS library - color management, named color to RGB triplet. More...

#include <math.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/colors.h>
Include dependency graph for color_str.c:

Go to the source code of this file.

Functions

int G_num_standard_colors (void)
 Get number of named colors (RGB triplets) More...
 
struct color_rgb G_standard_color_rgb (int n)
 Get RGB triplet of given color. More...
 
int G_num_standard_color_names (void)
 Get number of named colors (color names) More...
 
const struct color_nameG_standard_color_name (int n)
 Get color name. More...
 
int G_str_to_color (const char *str, int *red, int *grn, int *blu)
 Parse color string and set red,green,blue. More...
 
void G_rgb_to_hsv (int r, int g, int b, float *h, float *s, float *v)
 Converts RGB color values to HSV format. More...
 
void G_color_to_str (int r, int g, int b, ColorFormat clr_frmt, char *str)
 Parse red,green,blue and set color string. More...
 
ColorFormat G_option_to_color_format (const struct Option *option)
 Get color format from the option. More...
 

Detailed Description

GIS library - color management, named color to RGB triplet.

(C) 2001-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
Original author CERL

Definition in file color_str.c.

Function Documentation

◆ G_color_to_str()

void G_color_to_str ( int  r,
int  g,
int  b,
ColorFormat  clr_frmt,
char *  str 
)

Parse red,green,blue and set color string.

Parameters
rred component of RGB color
ggreen component of RGB color
bblue component of RGB color
clr_frmtcolor format to be used (RGB, HEX, HSV, TRIPLET).
[out]strcolor string

Definition at line 210 of file color_str.c.

◆ G_num_standard_color_names()

int G_num_standard_color_names ( void  )

Get number of named colors (color names)

Returns
number of colors

Definition at line 76 of file color_str.c.

Referenced by G_str_to_color().

◆ G_num_standard_colors()

int G_num_standard_colors ( void  )

Get number of named colors (RGB triplets)

Returns
number of colors

Definition at line 56 of file color_str.c.

Referenced by COM_Standard_color(), and D_use_color().

◆ G_option_to_color_format()

ColorFormat G_option_to_color_format ( const struct Option option)

Get color format from the option.

ColorFormat colorFormat;
struct Option *color_format;
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
colorFormat = G_option_to_color_format(color_format);
ColorFormat
Color format identifiers (enum)
Definition: colors.h:55
ColorFormat G_option_to_color_format(const struct Option *)
Get color format from the option.
Definition: color_str.c:254
int G_parser(int, char **)
Parse command line.
Definition: parser.c:321
struct Option * G_define_standard_option(int)
Create standardised Option structure.
@ G_OPT_C_FORMAT
Definition: gis.h:326
Structure that stores option information.
Definition: gis.h:563
Parameters
optionpointer to color format option
Returns
allocated ColorFormat

Definition at line 254 of file color_str.c.

References _, Option::answer, G_fatal_error(), HEX, HSV, RGB, and TRIPLET.

◆ G_rgb_to_hsv()

void G_rgb_to_hsv ( int  r,
int  g,
int  b,
float *  h,
float *  s,
float *  v 
)

Converts RGB color values to HSV format.

Note
This implementation is experimental and may be subject to change.
Parameters
rred component of the RGB color
ggreen component of the RGB color
bblue component of the RGB color
[out]hpointer to store the calculated hue
[out]spointer to store the calculated saturation
[out]vpointer to store the calculated value

Definition at line 168 of file color_str.c.

◆ G_standard_color_name()

const struct color_name* G_standard_color_name ( int  n)

Get color name.

Parameters
ncolor index

Definition at line 86 of file color_str.c.

◆ G_standard_color_rgb()

struct color_rgb G_standard_color_rgb ( int  n)

Get RGB triplet of given color.

Parameters
ncolor index

Definition at line 56 of file color_str.c.

Referenced by COM_Standard_color().

◆ G_str_to_color()

int G_str_to_color ( const char *  str,
int *  red,
int *  grn,
int *  blu 
)

Parse color string and set red,green,blue.

Parameters
strcolor string
[out]redred value
[out]grngreen value
[out]blublue value
Returns
1 OK
2 NONE
0 on error

Definition at line 103 of file color_str.c.

References G_chop(), G_debug(), G_num_standard_color_names(), G_strcasecmp(), G_strlcpy(), and name.

Referenced by Cairo_Graph_set(), I_iclass_add_signature(), Nviz_color_from_str(), and PNG_Graph_set().