Max 5 API Reference

# Colors [JGraphics]

Collaboration diagram for Colors:

## Data Structures

struct  t_jrgb
A color composed of red, green, and blue components. More...
struct  t_jrgba
A color composed of red, green, blue, and alpha components. More...

## Functions

void jrgba_to_atoms (t_jrgba *c, t_atom *argv)
Get the components of a color in an array of pre-allocated atoms.
t_max_err atoms_to_jrgba (long argc, t_atom *argv, t_jrgba *c)
Set the components of a color by providing an array of atoms.
void jrgba_set (t_jrgba *prgba, double r, double g, double b, double a)
Set the components of a color.
void jrgba_copy (t_jrgba *dest, t_jrgba *src)
Copy a color.
long jrgba_compare (t_jrgba *rgba1, t_jrgba *rgba2)
Compare two colors for equality.
t_max_err jrgba_attr_get (t_jrgba *jrgba, long *argc, t_atom **argv)
Get the value of a t_jrgba struct, returned as an array of atoms with the values for each component.
t_max_err jrgba_attr_set (t_jrgba *jrgba, long argc, t_atom *argv)
Set the value of a t_jrgba struct, given an array of atoms with the values to use.

## Function Documentation

 t_max_err atoms_to_jrgba ( long argc, t_atom * argv, t_jrgba * c )

Set the components of a color by providing an array of atoms.

If it is an array of 3 atoms, then the atoms provided should define the red, green, and blue components (in this order) in a range of [0.0, 1.0]. If a 4th atom is provided, it will define the alpha channel. If the alpha channel is not defined then it is assumed to be 1.0.

Parameters:
 argc The number of atoms in the array provided in argv. This should be 3 or 4 depending on whether or not the alpha channel is being provided. argv The address to the first of an array of atoms that define the color. c The address of a t_jrgba struct for which the color will be defined.
Returns:
A Max error code.
 t_max_err jrgba_attr_get ( t_jrgba * jrgba, long * argc, t_atom ** argv )

Get the value of a t_jrgba struct, returned as an array of atoms with the values for each component.

Parameters:
 jrgba The color struct whose color will be retrieved. argc The address of a variable that will be set with the number of atoms in the argv array. The returned value should be 4. The value of the int should be set to 0 prior to calling this function. argv The address of a t_atom pointer that will receive the a new array of atoms set to the values of the jrgba struct. The pointer should be set to NULL prior to calling this function. There should be 4 atoms returned, representing alpha, red, green, and blue components. When you are done using the atoms, you are responsible for freeing the pointer using sysmem_freeptr().
Returns:
This function returns the error code MAX_ERR_NONE if successful, or one of the other error codes defined in e_max_errorcodes if unsuccessful.
 t_max_err jrgba_attr_set ( t_jrgba * jrgba, long argc, t_atom * argv )

Set the value of a t_jrgba struct, given an array of atoms with the values to use.

Parameters:
 jrgba The color struct whose color will be set. argc The number of atoms in the array. This must be 4. argv The address of the first of the atoms in the array. There must be 4 atoms, representing alpha, red, green, and blue components.
Returns:
This function returns the error code MAX_ERR_NONE if successful, or one of the other error codes defined in e_max_errorcodes if unsuccessful.
 long jrgba_compare ( t_jrgba * rgba1, t_jrgba * rgba2 )

Compare two colors for equality.

Parameters:
 rgba1 The address of a t_jrgba struct to compare. rgba2 The address of another t_jrgba struct to compare.
Returns:
returns 1 if rgba1 == rgba2.
 void jrgba_copy ( t_jrgba * dest, t_jrgba * src )

Copy a color.

Parameters:
 dest The address of a t_jrgba struct to which the color will be copied. src The address of a t_jrgba struct from which the color will be copied.
 void jrgba_set ( t_jrgba * prgba, double r, double g, double b, double a )

Set the components of a color.

Parameters:
 prgba The address of a t_jrgba struct for which the color will be defined. r The value of the red component in a range of [0.0, 1.0]. g The value of the green component in a range of [0.0, 1.0]. b The value of the blue component in a range of [0.0, 1.0]. a The value of the alpha component in a range of [0.0, 1.0].
 void jrgba_to_atoms ( t_jrgba * c, t_atom * argv )

Get the components of a color in an array of pre-allocated atoms.

Parameters:
 argv The address to the first of an array of atoms that will hold the result. At least 4 atoms must be allocated, as 4 atoms will be set by this function for the red, green, blue, and alpha components. c The address of a t_jrgba struct from which the color components will be fetched.