Antiprism 0.23

- Main Page
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Static Public Attributes

# col_val Class Reference

Colour holding RGBA or an index number. More...

`#include <col_val.h>`

Collaboration diagram for col_val:
[legend]

List of all members.

## Public Member Functions
| col_val (int idx=-2)
| Constructor.
| col_val (int red, int green, int blue, int alpha=255)
| Constructor.
| col_val (vec3d col)
| Constructor.
| col_val (vec4d col)
| Constructor.
| col_val (double red, double green, double blue, double alpha=1.0)
| Constructor.
void | unset ()
| Unset the colour, indicating no colour is set.
void | set_idx (int idx=-2)
| Set the colour with an index number.
void | set_rgba (int red, int green, int blue, int alpha=255)
| Set the colour with integer RGBA values.
void | set_rgba (double red, double green, double blue, double alpha=1.0)
| Set the colour with floating point RGBA values.
void | set_hsva (double hue, double sat, double val, double alpha=1.0)
| Set the colour with floating point HSVA values.
void | set_hsva (const vec4d &hsva)
| Set the colour with floating point HSVA values.
void | set_hsla (double hue, double sat, double lum, double alpha=1.0)
| Set the colour with floating point hsla values.
void | set_hsla (const vec4d &hsla)
| Set the colour with floating point hsla values.
void | set_complement (col_val col=col_val())
| Set the colour to its complement, or the complement of another colour.
void | set_brightness (double brt_val, col_val col=col_val())
| Set the colour brightness, or from brightening another colour.
int | get_idx () const
| Get the index number.
int | get_trans () const
| Get the transparency in integer format.
double | get_transd () const
| Get the transparency in floating point format.
vec3d | get_vec3d () const
| Get the RGB values.
vec4d | get_vec4d () const
| Get the RGBA values.
unsigned long | get_long () const
| Get the RGBA values as a long integer.
vec4d | get_hsva () const
| Get the HSVA values.
vec4d | get_hsla () const
| Get the HSLA values.
int | operator[] (int i) const
| Read access to the integer RGBA values.
bool | is_set () const
| Check whether a colour is set.
bool | is_val () const
| Check whether a colour is held as RGBA.
bool | is_idx () const
| Check whether a colour is held as an index number.
bool | is_def () const
| Check whether a colour has the default unset colour state.
bool | is_inv () const
| Check whether a colour is invisible.
bool | operator== (col_val c) const
| Check for equality.
bool | operator!= (col_val c) const
| Check for inequality.
bool | read (char *col_str, char *errmsg=0)
| Read a colour given as text, detecting the format.
bool | from_offvals (vector< char * > &vals, char *errmsg=0, int *col_type=0)
| Read an OFF colour given as number strings.
bool | from_decvals (vector< double > &vals, char *errmsg=0)
| Read a colour given as floating point values.
bool | from_intvals (vector< int > &vals, char *errmsg=0)
| Read a colour given as integers.
bool | read_decvals (vector< char * > &vals, char *errmsg=0)
| Read a colour given as decimal strings.
bool | read_intvals (vector< char * > &vals, char *errmsg=0)
| Read a colour given as integer strings.
bool | read_decvals (char *str, char *errmsg=0)
| Read a colour given as decimals in a string.
bool | read_intvals (char *str, char *errmsg=0)
| Read a colour given as integers in a string.
bool | read_hexvals (char *str, char *errmsg=0)
| Read a colour given as hex format in a string.
bool | read_hsva_vals (char *str, char *errmsg=0)
| Read a colour given as HSVA format in a string.
bool | read_colorname (char *str, char *errmsg=0, bool as_index=false)
| Read a colour given by name.
void | dump (const char *var="", FILE *file=stderr) const
| Debugging print of a vector variable.
## Static Public Member Functions
static int | f2i (double f)
| Convert from floating point to integer format.
static double | i2f (int i)
| Convert from integer to floating point format.
static bool | check (int i)
| Check that an integer is in the valid colour range.
static bool | in_range (int r, int g, int b, int a)
| Check that integer components are in the valid colour range.
## Static Public Attributes
static col_val | invisible
| The invisible colour for non-display elements.

## Detailed Description

Colour holding RGBA or an index number.

## Constructor & Destructor Documentation

col_val::col_val | ( | int | idx = `-2` | ) | `[inline]`

Constructor.

Initialise with an index number

Parameters:

  idx | a positive index number (default value `-2` indicates that no colour is set)

col_val::col_val | ( | int | red,
|  | int | green,
|  | int | blue,
|  | int | alpha = `255`
| ) |  | `[inline]`

Constructor.

Initialise with integer RGBA values. Using out of range values will leave the colour unset.

Parameters:

  red | red value in range `0` - `255`
  green | green value in range `0` - `255`
  blue | blue value in range `0` - `255`
  alpha | alpha value in range `0` (clear) - `255` (opaque)

col_val::col_val | ( | vec3d | col | ) | `[inline]`

Constructor.

Initialise with RGB values in a vec3d. Using out of range values will leave the colour unset.

Parameters:

  col | components hold in turn the red, green and blue values, in the range `0.0` to `1.0`

col_val::col_val | ( | vec4d | col | ) | `[inline]`

Constructor.

Initialise with RGBA values in a vec4d. Using out of range values will leave the colour unset.

Parameters:

  col | components hold in turn the red, green, blue and alpha values, in the range `0.0` to `1.0`

col_val::col_val | ( | double | red,
|  | double | green,
|  | double | blue,
|  | double | alpha = `1.0`
| ) |  | `[inline]`

Constructor.

Initialise with floating point RGBA values. Using out of range values will leave the colour unset.

Parameters:

  red | red value in range `0.0` - `1.0`
  green | green value in range `0.0` - `1.0`
  blue | blue value in range `0.0` - `1.0`
  alpha | alpha value in range `0.0` (clear) - `1.0` (opaque)

## Member Function Documentation

bool col_val::check | ( | int | i | ) | `[inline, static]`

Check that an integer is in the valid colour range.

Parameters:

  i | number to check.

Returns:
  `true` if i is in range `0` - `255`, otherwise `false`.

void col_val::dump | ( | const char * | var = `""`,
|  | FILE * | file = `stderr`
| ) |  | const

Debugging print of a vector variable.

Parameters:

  var | a string to identify the vector variable.
  file | file stream to print the variable.

int col_val::f2i | ( | double | f | ) | `[inline, static]`

Convert from floating point to integer format.

Parameters:

  f | a floating point number in range `0.0` - `1.0`.

Returns:
  an integer in range `0` - `255`

bool col_val::from_decvals | ( | vector< double > & | vals,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as floating point values.

Parameters:

  vals | 3 (RGB) or 4 (RGBA) values in range `0.0` - `1.0`.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::from_intvals | ( | vector< int > & | vals,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as integers.

Parameters:

  vals | 3 (RGB) or 4 (RGBA) values in range `0` - `255`.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::from_offvals | ( | vector< char * > & | vals,
|  | char * | errmsg = `0`,
|  | int * | col_type = `0`
| ) |  |

Read an OFF colour given as number strings.

Read decimal values, integer values or an index number

Parameters:

  vals | numbers held as strings.
  errmsg | an array at least `MSG_SZ` chars long to return an error message if col_type is `0`.
  col_type | used to return the colour type that was read `0` - not valid `1` - one integer (index number) `2` - three integer values (RGB) `3` - four integer values (RGBA) `4` - three decimal values (RGB) `5` - four decimal values (RGBA)

Returns:
  true if a valid colour was read or there was no color to read, otherwise false

vec4d col_val::get_hsla | ( |  | ) | const

Get the HSLA values.

Returns:
  The RGBA values as components in range `0.0` to `1.0`.

vec4d col_val::get_hsva | ( |  | ) | const

Get the HSVA values.

Returns:
  The RGBA values as components in range `0.0` to `1.0`.

int col_val::get_idx | ( |  | ) | const`[inline]`

Get the index number.

Returns:
  The index number.

unsigned long col_val::get_long | ( |  | ) | const`[inline]`

Get the RGBA values as a long integer.

Returns:
  The RGBA values converted to a long using 2^12R+2^8G+2^4G+A

int col_val::get_trans | ( |  | ) | const`[inline]`

Get the transparency in integer format.

Returns:
  The transparency in the range `0` (opaque) - `255` (clear).

double col_val::get_transd | ( |  | ) | const`[inline]`

Get the transparency in floating point format.

Returns:
  The transparency in the range `0.0` (opaque) - `1.0` (clear).

vec3d col_val::get_vec3d | ( |  | ) | const`[inline]`

Get the RGB values.

Returns:
  The RGB values as components in range `0.0` to `1.0`.

vec4d col_val::get_vec4d | ( |  | ) | const`[inline]`

Get the RGBA values.

Returns:
  The RGBA values as components in range `0.0` to `1.0`.

double col_val::i2f | ( | int | i | ) | `[inline, static]`

Convert from integer to floating point format.

Parameters:

  i | an integer in range `0` - `255`.

Returns:
  a floating point number in range `0.0` - `1.0`

bool col_val::in_range | ( | int | r,
|  | int | g,
|  | int | b,
|  | int | a
| ) |  | `[inline, static]`

Check that integer components are in the valid colour range.

Parameters:

  r | the red component.
  g | the green component.
  b | the blue component.
  a | the alpha component.

Returns:
  `true` if all components are in the range `0` - `255`, otherwise `false`.

bool col_val::is_def | ( |  | ) | const`[inline]`

Check whether a colour has the default unset colour state.

The opposite of `is_set()`

Returns:
  `true` if the colour has not been set to a valid value, otherwise `false`.

bool col_val::is_idx | ( |  | ) | const`[inline]`

Check whether a colour is held as an index number.

Returns:
  `true` if the colour holds an index number, otherwise `false`.

bool col_val::is_inv | ( |  | ) | const`[inline]`

Check whether a colour is invisible.

Returns:
  `true` if the colour holds the invisible colour value, otherwise `false`.

bool col_val::is_set | ( |  | ) | const`[inline]`

Check whether a colour is set.

Returns:
  `true` if the colour has been set to a valid value, otherwise `false`.

bool col_val::is_val | ( |  | ) | const`[inline]`

Check whether a colour is held as RGBA.

Returns:
  `true` if the colour holds an RGB value, otherwise `false`.

bool col_val::operator!= | ( | col_val | c | ) | const`[inline]`

Check for inequality.

Returns:
  true if colours have unequal index numbers, or they have unequal RGBA values, or only one is set, * otherwise return false.

bool col_val::operator== | ( | col_val | c | ) | const

Check for equality.

Returns:
  true if both have equal index numbers, or both have equal RGBA values, or both are not yet set, otherwise return false.

bool col_val::read | ( | char * | col_str,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as text, detecting the format.

Will read any of the formats below that work with a string

Parameters:

  col_str | the color string.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_colorname | ( | char * | str,
|  | char * | errmsg = `0`,
|  | bool | as_index = `false`
| ) |  |

Read a colour given by name.

Parameters:

  str | the colour name to be looked up in the internal list of colours.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.
  as_index | if true then set the colour as the colour index number in the X11 color map.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_decvals | ( | char * | str,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as decimals in a string.

Parameters:

  str | a string of 3 (RGB) or 4 (RGBA) comma separated decimals in range `0.0` - `1.0`.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_decvals | ( | vector< char * > & | vals,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as decimal strings.

Parameters:

  vals | 3 (RGB) or 4 (RGBA) numbers in range `0.0` - `1.0` held as strings.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_hexvals | ( | char * | str,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as hex format in a string.

Parameters:

  str | a string starting with X, x or # followed by 3 (RGB) or 4 (RGBA) pairs of hexadecimal digits representing integers in range `0` - `255`.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_hsva_vals | ( | char * | str,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as HSVA format in a string.

Parameters:

  str | a string starting with H or h followed by param str a string of 1 (h) value of plus/minus N degrees or 1 (H) decimal value in range `0.0` - `1.0`. and up to 3 (SVA) optional comma separated decimals in range `0.0` - `1.0`.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_intvals | ( | vector< char * > & | vals,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as integer strings.

Parameters:

  vals | 3 (RGB) or 4 (RGBA) numbers in range `0` - `255` held as strings.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

bool col_val::read_intvals | ( | char * | str,
|  | char * | errmsg = `0`
| ) |  |

Read a colour given as integers in a string.

Parameters:

  str | a string of 3 (RGB) or 4 (RGBA) comma separated integers in range `0` - `255`.
  errmsg | an array at least `MSG_SZ` chars long to return any error message.

Returns:
  true if a valid colour was read, otherwise false and the error is detailed in errmsg.

void col_val::set_brightness | ( | double | brt_val,
|  | col_val | col = `col_val()`
| ) |  |

Set the colour brightness, or from brightening another colour.

Parameters:

  brt_val | the value to brighten in the range -1.0 to 1.0. Positive values brighten towards white and negative values darken towards black
  col | the colour as the base to brighten, or use current colour if col is unset (default). If `col` is an index the final colour will be unset

void col_val::set_complement | ( | col_val | col = `col_val()` | ) |

Set the colour to its complement, or the complement of another colour.

Parameters:

  col | the colour to take the complement from, or use current colour if col is unset (default). If `col` is an index the final colour will be unset

void col_val::set_hsla | ( | const vec4d & | hsla | ) |

Set the colour with floating point hsla values.

The hsla values are in the range 0.0-1.0. Using out of range values will leave the colour unset.

void col_val::set_hsla | ( | double | hue,
|  | double | sat,
|  | double | lum,
|  | double | alpha = `1.0`
| ) |  |

Set the colour with floating point hsla values.

Using out of range values will leave the colour unset.

Parameters:

  hue | hue in range `0.0` - `1.0`
  sat | saturation in range `0.0` - `1.0`
  lum | value in range `0.0` - `1.0`
  alpha | alpha value in range `0.0` (clear) - `1.0` (opaque)

void col_val::set_hsva | ( | double | hue,
|  | double | sat,
|  | double | val,
|  | double | alpha = `1.0`
| ) |  |

Set the colour with floating point HSVA values.

Using out of range values will leave the colour unset.

Parameters:

  hue | hue in range `0.0` - `1.0`
  sat | saturation in range `0.0` - `1.0`
  val | value in range `0.0` - `1.0`
  alpha | alpha value in range `0.0` (clear) - `1.0` (opaque)

void col_val::set_hsva | ( | const vec4d & | hsva | ) |

Set the colour with floating point HSVA values.

The HSVA values are in the range 0.0-1.0. Using out of range values will leave the colour unset.

void col_val::set_idx | ( | int | idx = `-2` | ) | `[inline]`

Set the colour with an index number.

Parameters:

  idx | a positive index number (default value `-2` indicates that no colour is set)

void col_val::set_rgba | ( | double | red,
|  | double | green,
|  | double | blue,
|  | double | alpha = `1.0`
| ) |  | `[inline]`

Set the colour with floating point RGBA values.

Using out of range values will leave the colour unset.

Parameters:

  red | red value in range `0.0` - `1.0`
  green | green value in range `0.0` - `1.0`
  blue | blue value in range `0.0` - `1.0`
  alpha | alpha value in range `0.0` (clear) - `1.0` (opaque)

void col_val::set_rgba | ( | int | red,
|  | int | green,
|  | int | blue,
|  | int | alpha = `255`
| ) |  | `[inline]`

Set the colour with integer RGBA values.

Using out of range values will leave the colour unset.

Parameters:

  red | red value in range `0` - `255`
  green | green value in range `0` - `255`
  blue | blue value in range `0` - `255`
  alpha | alpha value in range `0` (clear) - `255` (opaque)

The documentation for this class was generated from the following files:

- base/col_val.h
- base/col_read.cc
- base/col_val.cc