Loading...
Searching...
No Matches
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).
struct color_rgb | G_standard_color_rgb (int n)
| Get RGB triplet of given color.
int | G_num_standard_color_names (void)
| Get number of named colors (color names).
const struct color_name * | G_standard_color_name (int n)
| Get color name.
int | G_str_to_color (const char *str, int *red, int *grn, int *blu)
| Parse color string and set red,green,blue.
void | G_rgb_to_hsv (int r, int g, int b, float *h, float *s, float *v)
| Converts RGB color values to HSV format.
void | G_color_to_str (int r, int g, int b, ColorFormat clr_frmt, char *str)
| Parse red,green,blue and set color string.
ColorFormat | G_option_to_color_format (const struct Option *option)
| Get color format from the option.

## 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

  | r | red component of RGB color
  | g | green component of RGB color
  | b | blue component of RGB color
  | clr_frmt | color format to be used (RGB, HEX, HSV, TRIPLET).
  [out] | str | color string

Since
  version 8.5

Definition at line 214 of file color_str.c.

References b, g, G_rgb_to_hsv(), and r.

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

## 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;
color_format = G_define_standard_option(G_OPT_C_FORMAT);
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
colorFormat = G_option_to_color_format(color_format);
G_option_to_color_format
ColorFormat G_option_to_color_format(const struct Option *option)
Get color format from the option.
Definition color_str.c:260
G_parser
int G_parser(int argc, char **argv)
Parse command line.
Definition parser.c:320
G_define_standard_option
struct Option * G_define_standard_option(int opt)
Create standardised Option structure.
Definition parser_standard_options.c:143

Parameters

  option | pointer to color format option

Returns
  allocated ColorFormat

Since
  version 8.5

Definition at line 260 of file color_str.c.

References G_fatal_error().

## 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

  | r | red component of the RGB color
  | g | green component of the RGB color
  | b | blue component of the RGB color
  [out] | h | pointer to store the calculated hue
  [out] | s | pointer to store the calculated saturation
  [out] | v | pointer to store the calculated value

Since
  version 8.5

Definition at line 170 of file color_str.c.

References b, g, MAX, MIN, and r.

Referenced by G_color_to_str().

## G_standard_color_name()

const struct color_name * G_standard_color_name | ( | int | n | ) |

Get color name.

Parameters

  n | color 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

  n | color index

Definition at line 66 of file color_str.c.

References G_standard_color_rgb().

Referenced by COM_Standard_color(), and G_standard_color_rgb().

## 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

  | str | color string
  [out] | red | red value
  [out] | grn | green value
  [out] | blu | blue 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(), Gp_load_sites_thematic(), Gv_load_vect_thematic(), Nviz_color_from_str(), and PNG_Graph_set().