BRL-CAD

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 HUE   0
 
#define SAT   1
 
#define VAL   2
 
#define BU_COLOR_NULL   ((struct bu_color *) 0)
 
#define BU_COLOR_INIT(_c)
 
#define BU_COLOR_INIT_ZERO   {{0, 0, 0, 0}}
 
#define BU_COLOR_CPY(_dest, _src)
 

Typedefs

typedef struct bu_color bu_color_t
 

Enumerations

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_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 40 of file color.h.

◆ GRN

#define GRN   1

Definition at line 41 of file color.h.

◆ BLU

#define BLU   2

Definition at line 42 of file color.h.

◆ ALP

#define ALP   3

Definition at line 43 of file color.h.

◆ HUE

#define HUE   0

Definition at line 45 of file color.h.

◆ SAT

#define SAT   1

Definition at line 46 of file color.h.

◆ VAL

#define VAL   2

Definition at line 47 of file color.h.

◆ BU_COLOR_NULL

#define BU_COLOR_NULL   ((struct bu_color *) 0)

Definition at line 58 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]; \
}
#define RED
Definition: color.h:40
#define ALP
Definition: color.h:43
#define BLU
Definition: color.h:42
#define GRN
Definition: color.h:41

initializes a bu_color struct without allocating any memory.

Definition at line 63 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 71 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 76 of file color.h.

Typedef Documentation

◆ bu_color_t

typedef struct bu_color bu_color_t

Definition at line 57 of file color.h.

Enumeration Type Documentation

◆ bu_color_rand_t

random color generating methods

Enumerator
BU_COLOR_RANDOM 
BU_COLOR_RANDOM_LIGHTENED 

Definition at line 85 of file color.h.

Function Documentation

◆ bu_color_rand()

int bu_color_rand ( struct bu_color c,
bu_color_rand_t  type 
)

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 
)

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 
)

◆ bu_color_from_rgb_floats()

int bu_color_from_rgb_floats ( struct bu_color cp,
const fastf_t rgb 
)

Utility functions to convert between various containers for color handling.

FIXME: inconsistent input/output parameters! TODO: consider stdarg ... to consolidate all the from functions, e.g., // 3 colors bu_color_create(struct bu_color **colors, "red", "0/255/0", "#0000ff", NULL);

// 2 colors from existing data struct bu_color *colors = NULL; bu_color_create(&colors, "%d/%d/%d", rgb[0], rgb[1], rgb[2], "hsv(%lf,0.5,0.95)", hsv, NULL); bu_color_destroy(colors);

◆ bu_color_from_rgb_chars()

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

◆ bu_color_from_str()

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

◆ bu_str_to_rgb()

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

◆ bu_color_to_rgb_floats()

int bu_color_to_rgb_floats ( const struct bu_color cp,
fastf_t rgb 
)

◆ bu_color_to_rgb_chars()

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

◆ bu_color_to_rgb_ints()

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