BRL-CAD
Loading...
Searching...
No Matches

Support for storing and manipulating color data. More...

Collaboration diagram for Color:

Files

file  color.h
 

Data Structures

struct  bu_color
 

Macros

#define RED   0
 
#define GRN   1
 
#define BLU   2
 
#define ALP   3
 
#define BU_COLOR_INDEX_RED   0
 
#define BU_COLOR_INDEX_GREEN   1
 
#define BU_COLOR_INDEX_BLUE   2
 
#define BU_COLOR_INDEX_ALPHA   3
 
#define HUE   0
 
#define SAT   1
 
#define VAL   2
 
#define BU_COLOR_INDEX_HUE   0
 
#define BU_COLOR_INDEX_SATURATION   1
 
#define BU_COLOR_INDEX_VALUE   2
 
#define BU_COLOR_NULL   ((struct bu_color *) 0)
 
#define BU_COLOR_INIT(_c)
 
#define BU_COLOR_NEAR_EQUAL(_c1, _c2, _tol)    HNEAR_EQUAL(_c1.buc_rgb, _c2.buc_rgb, _tol)
 
#define BU_COLOR_INIT_ZERO   {{0, 0, 0, 0}}
 
#define BU_COLOR_BLUE   {{0, 0, 1, 0}}
 
#define BU_COLOR_CYAN   {{0, 1, 1, 0}}
 
#define BU_COLOR_GREEN   {{0, 1, 0, 0}}
 
#define BU_COLOR_PURPLE   {{1, 0, 1, 0}}
 
#define BU_COLOR_RED   {{1, 0, 0, 0}}
 
#define BU_COLOR_WHITE   {{1, 1, 1, 0}}
 
#define BU_COLOR_YELLOW   {{1, 1, 0, 0}}
 
#define BU_COLOR_CPY(_dest, _src)
 

Typedefs

typedef struct bu_color bu_color_t
 
typedef enum bu_color_space bu_color_space_t
 
typedef enum bu_color_format bu_color_format_t
 

Enumerations

enum  bu_color_space { BU_COLOR_SPACE_RGB = 0 , BU_COLOR_SPACE_HSL , BU_COLOR_SPACE_HSV }
 
enum  bu_color_format {
  BU_COLOR_FORMAT_RGB = 0 , BU_COLOR_FORMAT_RGBA , BU_COLOR_FORMAT_HEX , BU_COLOR_FORMAT_HEXA ,
  BU_COLOR_FORMAT_HSL , BU_COLOR_FORMAT_HSLA , BU_COLOR_FORMAT_HSV , BU_COLOR_FORMAT_HSVA ,
  BU_COLOR_FORMAT_NAME
}
 
enum  bu_color_rand_t { BU_COLOR_RANDOM = 0 , BU_COLOR_RANDOM_LIGHTENED }
 

Functions

int bu_color_rand (struct bu_color *c, bu_color_rand_t type)
 
void bu_rgb_to_hsv (const unsigned char *rgb, fastf_t *hsv)
 
int bu_hsv_to_rgb (const fastf_t *hsv, unsigned char *rgb)
 
int bu_color_parse (const char *str, struct bu_color *color)
 
int bu_color_format (const struct bu_color *color, bu_color_format_t format, struct bu_vls *output)
 
int bu_color_convert (const double in[4], bu_color_space_t in_space, bu_color_space_t out_space, double out[4])
 
int bu_color_from_rgb_floats (struct bu_color *cp, const fastf_t *rgb)
 
int bu_color_from_rgb_chars (struct bu_color *cp, const unsigned char *rgb)
 
int bu_color_from_str (struct bu_color *cp, const char *str)
 
int bu_str_to_rgb (const char *str, unsigned char *rgb)
 
int bu_color_to_rgb_floats (const struct bu_color *cp, fastf_t *rgb)
 
int bu_color_to_rgb_chars (const struct bu_color *cp, unsigned char *rgb)
 
int bu_color_to_rgb_ints (const struct bu_color *cp, int *r, int *g, int *b)
 

Detailed Description

Support for storing and manipulating color data.

Macro Definition Documentation

◆ RED

#define RED   0

Definition at line 42 of file color.h.

◆ GRN

#define GRN   1

Definition at line 43 of file color.h.

◆ BLU

#define BLU   2

Definition at line 44 of file color.h.

◆ ALP

#define ALP   3

Definition at line 45 of file color.h.

◆ BU_COLOR_INDEX_RED

#define BU_COLOR_INDEX_RED   0

Definition at line 47 of file color.h.

◆ BU_COLOR_INDEX_GREEN

#define BU_COLOR_INDEX_GREEN   1

Definition at line 48 of file color.h.

◆ BU_COLOR_INDEX_BLUE

#define BU_COLOR_INDEX_BLUE   2

Definition at line 49 of file color.h.

◆ BU_COLOR_INDEX_ALPHA

#define BU_COLOR_INDEX_ALPHA   3

Definition at line 50 of file color.h.

◆ HUE

#define HUE   0

Definition at line 52 of file color.h.

◆ SAT

#define SAT   1

Definition at line 53 of file color.h.

◆ VAL

#define VAL   2

Definition at line 54 of file color.h.

◆ BU_COLOR_INDEX_HUE

#define BU_COLOR_INDEX_HUE   0

Definition at line 56 of file color.h.

◆ BU_COLOR_INDEX_SATURATION

#define BU_COLOR_INDEX_SATURATION   1

Definition at line 57 of file color.h.

◆ BU_COLOR_INDEX_VALUE

#define BU_COLOR_INDEX_VALUE   2

Definition at line 58 of file color.h.

◆ BU_COLOR_NULL

#define BU_COLOR_NULL   ((struct bu_color *) 0)

Definition at line 68 of file color.h.

◆ BU_COLOR_INIT

#define BU_COLOR_INIT (   _c)
Value:
{ \
(_c)->buc_rgb[RED] = (_c)->buc_rgb[GRN] = (_c)->buc_rgb[BLU] = 0; (_c)->buc_rgb[ALP] = 0; \
}
Definition dvec.h:74
#define RED
Definition color.h:42
#define ALP
Definition color.h:45
#define BLU
Definition color.h:44
#define GRN
Definition color.h:43

initializes a bu_color struct without allocating any memory.

Definition at line 93 of file color.h.

◆ BU_COLOR_NEAR_EQUAL

#define BU_COLOR_NEAR_EQUAL (   _c1,
  _c2,
  _tol 
)     HNEAR_EQUAL(_c1.buc_rgb, _c2.buc_rgb, _tol)

Check whether two colors are equal within a tolerance.

Definition at line 100 of file color.h.

◆ BU_COLOR_INIT_ZERO

#define BU_COLOR_INIT_ZERO   {{0, 0, 0, 0}}

macro suitable for declaration statement initialization of a bu_color struct. does not allocate memory.

Definition at line 108 of file color.h.

◆ BU_COLOR_BLUE

#define BU_COLOR_BLUE   {{0, 0, 1, 0}}

Definition at line 111 of file color.h.

◆ BU_COLOR_CYAN

#define BU_COLOR_CYAN   {{0, 1, 1, 0}}

Definition at line 112 of file color.h.

◆ BU_COLOR_GREEN

#define BU_COLOR_GREEN   {{0, 1, 0, 0}}

Definition at line 113 of file color.h.

◆ BU_COLOR_PURPLE

#define BU_COLOR_PURPLE   {{1, 0, 1, 0}}

Definition at line 114 of file color.h.

◆ BU_COLOR_RED

#define BU_COLOR_RED   {{1, 0, 0, 0}}

Definition at line 115 of file color.h.

◆ BU_COLOR_WHITE

#define BU_COLOR_WHITE   {{1, 1, 1, 0}}

Definition at line 116 of file color.h.

◆ BU_COLOR_YELLOW

#define BU_COLOR_YELLOW   {{1, 1, 0, 0}}

Definition at line 117 of file color.h.

◆ BU_COLOR_CPY

#define BU_COLOR_CPY (   _dest,
  _src 
)
Value:
{\
(_dest)->buc_rgb[RED] = (_src)->buc_rgb[RED]; \
(_dest)->buc_rgb[GRN] = (_src)->buc_rgb[GRN]; \
(_dest)->buc_rgb[BLU] = (_src)->buc_rgb[BLU]; \
(_dest)->buc_rgb[ALP] = (_src)->buc_rgb[ALP]; \
}

Copy a bu_color

Definition at line 122 of file color.h.

Typedef Documentation

◆ bu_color_t

Definition at line 67 of file color.h.

◆ bu_color_space_t

◆ bu_color_format_t

Text representations supported by bu_color_format().

Enumeration Type Documentation

◆ bu_color_space

Color spaces supported by bu_color_convert().

Enumerator
BU_COLOR_SPACE_RGB 
BU_COLOR_SPACE_HSL 
BU_COLOR_SPACE_HSV 

Definition at line 71 of file color.h.

◆ bu_color_format

Text representations supported by bu_color_format().

Enumerator
BU_COLOR_FORMAT_RGB 
BU_COLOR_FORMAT_RGBA 
BU_COLOR_FORMAT_HEX 
BU_COLOR_FORMAT_HEXA 
BU_COLOR_FORMAT_HSL 
BU_COLOR_FORMAT_HSLA 
BU_COLOR_FORMAT_HSV 
BU_COLOR_FORMAT_HSVA 
BU_COLOR_FORMAT_NAME 

Definition at line 78 of file color.h.

◆ bu_color_rand_t

random color generating methods

Enumerator
BU_COLOR_RANDOM 
BU_COLOR_RANDOM_LIGHTENED 

Definition at line 131 of file color.h.

Function Documentation

◆ bu_color_rand()

int bu_color_rand ( struct bu_color c,
bu_color_rand_t  type 
)
extern

Function to generate random color

Refactoring points: truly random color 3dm-g: src/libgcv/plugins/rhino/rhino_read.cpp "constrained" random BRLCADWrapper:getRandomColor(): src/conv/step/BRLCADWrapper.cpp

◆ bu_rgb_to_hsv()

void bu_rgb_to_hsv ( const unsigned char rgb,
fastf_t hsv 
)
extern

Convert between RGB and HSV color models

R, G, and B are in {0, 1, ..., 255},

H is in [0.0, 360.0), and S and V are in [0.0, 1.0],

If S == 0.0, H is achromatic and set to 0.0

These two routines are adapted from: pp. 592-3 of J.D. Foley, A. van Dam, S.K. Feiner, and J.F. Hughes, Computer graphics: principles and practice, 2nd ed., Addison-Wesley, Reading, MA, 1990.

◆ bu_hsv_to_rgb()

int bu_hsv_to_rgb ( const fastf_t hsv,
unsigned char rgb 
)
extern

◆ bu_color_parse()

int bu_color_parse ( const char str,
struct bu_color color 
)
extern

Parse a human-readable color specification.

Accepted representations include the legacy BRL-CAD integer and normalized floating point RGB triplets, hexadecimal RGB and RGBA, CSS named colors, and RGB(A), HSL(A), and HSV(A) functional notation. RGB and alpha are normalized to [0.0, 1.0] in color. An omitted alpha channel is set to 1.0 (opaque).

Returns 1 on success and 0 on failure. On failure, color is unchanged.

◆ bu_color_format()

int bu_color_format ( const struct bu_color color,
bu_color_format_t  format,
struct bu_vls output 
)
extern

Append a human-readable representation of color to output.

RGB(A) uses functional notation with 8-bit RGB channels and normalized alpha. HSL(A) and HSV(A) use hue in degrees, percentages for the other model channels, and normalized alpha. Hexadecimal output uses CSS RGBA channel order. Named output fails when color has no exact CSS name.

Returns 1 on success and 0 on failure. On failure, output is unchanged.

◆ bu_color_convert()

int bu_color_convert ( const double  in[4],
bu_color_space_t  in_space,
bu_color_space_t  out_space,
double  out[4] 
)
extern

Convert a numeric color between RGB, HSL, and HSV.

RGB channels, saturation, lightness, value, and alpha use [0.0, 1.0]. Hue is expressed in degrees and is wrapped to [0.0, 360.0). Alpha is copied without conversion. All four input components must be finite.

Returns 1 on success and 0 on failure. On failure, out is unchanged.

◆ bu_color_from_rgb_floats()

int bu_color_from_rgb_floats ( struct bu_color cp,
const fastf_t rgb 
)
extern

Legacy utility functions for converting RGB storage containers. New color-space and text conversions should use bu_color_convert(), bu_color_parse(), and bu_color_format().

◆ bu_color_from_rgb_chars()

int bu_color_from_rgb_chars ( struct bu_color cp,
const unsigned char rgb 
)
extern

◆ bu_color_from_str()

int bu_color_from_str ( struct bu_color cp,
const char str 
)
extern

Compatibility parser equivalent to bu_color_parse(), except that cp's alpha channel is left unchanged.

◆ bu_str_to_rgb()

int bu_str_to_rgb ( const char str,
unsigned char rgb 
)
extern

◆ bu_color_to_rgb_floats()

int bu_color_to_rgb_floats ( const struct bu_color cp,
fastf_t rgb 
)
extern

◆ bu_color_to_rgb_chars()

int bu_color_to_rgb_chars ( const struct bu_color cp,
unsigned char rgb 
)
extern

◆ bu_color_to_rgb_ints()

int bu_color_to_rgb_ints ( const struct bu_color cp,
int *  r,
int *  g,
int *  b 
)
extern