## Color Type Color Type — A generic color definition |

## Synopsis

    struct              CoglColor;
    CoglColor *         cogl_color_new                      (void);
    CoglColor *         cogl_color_copy                     (const CoglColor *color);
    void                cogl_color_free                     (CoglColor *color);
    void                cogl_color_init_from_4f             (CoglColor *color,
                                                             float red,
                                                             float green,
                                                             float blue,
                                                             float alpha);
    void                cogl_color_init_from_4fv            (CoglColor *color,
                                                             float *color_array);
    void                cogl_color_init_from_4ub            (CoglColor *color,
                                                             guint8 red,
                                                             guint8 green,
                                                             guint8 blue,
                                                             guint8 alpha);
    void                cogl_color_set_from_4ub             (CoglColor *color,
                                                             guint8 red,
                                                             guint8 green,
                                                             guint8 blue,
                                                             guint8 alpha);
    void                cogl_color_set_from_4f              (CoglColor *color,
                                                             float red,
                                                             float green,
                                                             float blue,
                                                             float alpha);

    float               cogl_color_get_red                  (const CoglColor *color);
    float               cogl_color_get_green                (const CoglColor *color);
    float               cogl_color_get_blue                 (const CoglColor *color);
    float               cogl_color_get_alpha                (const CoglColor *color);

    unsigned char       cogl_color_get_red_byte             (const CoglColor *color);
    unsigned char       cogl_color_get_green_byte           (const CoglColor *color);
    unsigned char       cogl_color_get_blue_byte            (const CoglColor *color);
    unsigned char       cogl_color_get_alpha_byte           (const CoglColor *color);

    float               cogl_color_get_red_float            (const CoglColor *color);
    float               cogl_color_get_green_float          (const CoglColor *color);
    float               cogl_color_get_blue_float           (const CoglColor *color);
    float               cogl_color_get_alpha_float          (const CoglColor *color);

    void                cogl_color_set_red                  (CoglColor *color,
                                                             float red);
    void                cogl_color_set_green                (CoglColor *color,
                                                             float green);
    void                cogl_color_set_blue                 (CoglColor *color,
                                                             float blue);
    void                cogl_color_set_alpha                (CoglColor *color,
                                                             float alpha);

    void                cogl_color_set_red_byte             (CoglColor *color,
                                                             unsigned char red);
    void                cogl_color_set_green_byte           (CoglColor *color,
                                                             unsigned char green);
    void                cogl_color_set_blue_byte            (CoglColor *color,
                                                             unsigned char blue);
    void                cogl_color_set_alpha_byte           (CoglColor *color,
                                                             unsigned char alpha);

    void                cogl_color_set_red_float            (CoglColor *color,
                                                             float red);
    void                cogl_color_set_green_float          (CoglColor *color,
                                                             float green);
    void                cogl_color_set_blue_float           (CoglColor *color,
                                                             float blue);
    void                cogl_color_set_alpha_float          (CoglColor *color,
                                                             float alpha);

    void                cogl_color_premultiply              (CoglColor *color);
    void                cogl_color_unpremultiply            (CoglColor *color);
    gboolean            cogl_color_equal                    (gconstpointer v1,
                                                             gconstpointer v2);

## Description

CoglColor is a simple structure holding the definition of a color such that it can be efficiently used by GL

## Details

### struct CoglColor

    struct CoglColor {
    };

A structure for holding a color definition. The contents of the CoglColor structure are private and should never by accessed directly.

Since 1.0

### cogl_color_new ()

    CoglColor *         cogl_color_new                      (void);

Creates a new (empty) color

Returns : | a newly-allocated CoglColor. Use `cogl_color_free()` to free the allocated resources

Since 1.0

### cogl_color_copy ()

    CoglColor *         cogl_color_copy                     (const CoglColor *color);

Creates a copy of `color`

`color` : | the color to copy
Returns : | a newly-allocated CoglColor. Use `cogl_color_free()` to free the allocate resources

Since 1.0

### cogl_color_free ()

    void                cogl_color_free                     (CoglColor *color);

Frees the resources allocated by `cogl_color_new()` and `cogl_color_copy()`

`color` : | the color to free

Since 1.0

### cogl_color_init_from_4f ()

    void                cogl_color_init_from_4f             (CoglColor *color,
                                                             float red,
                                                             float green,
                                                             float blue,
                                                             float alpha);

Sets the values of the passed channels into a CoglColor

`color` : | A pointer to a CoglColor to initialize
`red` : | value of the red channel, between 0 and `1`.0
`green` : | value of the green channel, between 0 and `1`.0
`blue` : | value of the blue channel, between 0 and `1`.0
`alpha` : | value of the alpha channel, between 0 and `1`.0

Since 1.4

### cogl_color_init_from_4fv ()

    void                cogl_color_init_from_4fv            (CoglColor *color,
                                                             float *color_array);

Sets the values of the passed channels into a CoglColor

`color` : | A pointer to a CoglColor to initialize
`color_array` : | a pointer to an array of 4 float color components

Since 1.4

### cogl_color_init_from_4ub ()

    void                cogl_color_init_from_4ub            (CoglColor *color,
                                                             guint8 red,
                                                             guint8 green,
                                                             guint8 blue,
                                                             guint8 alpha);

Sets the values of the passed channels into a CoglColor.

`color` : | A pointer to a CoglColor to initialize
`red` : | value of the red channel, between 0 and 255
`green` : | value of the green channel, between 0 and 255
`blue` : | value of the blue channel, between 0 and 255
`alpha` : | value of the alpha channel, between 0 and 255

Since 1.4

### cogl_color_set_from_4ub ()

    void                cogl_color_set_from_4ub             (CoglColor *color,
                                                             guint8 red,
                                                             guint8 green,
                                                             guint8 blue,
                                                             guint8 alpha);

### Warning

`cogl_color_set_from_4ub` has been deprecated since version 1.4 and should not be used in newly-written code. Use cogl_color_init_from_4ub instead.

Sets the values of the passed channels into a CoglColor.

`color` : | A pointer to a CoglColor to initialize
`red` : | value of the red channel, between 0 and 255
`green` : | value of the green channel, between 0 and 255
`blue` : | value of the blue channel, between 0 and 255
`alpha` : | value of the alpha channel, between 0 and 255

Since 1.0

### cogl_color_set_from_4f ()

    void                cogl_color_set_from_4f              (CoglColor *color,
                                                             float red,
                                                             float green,
                                                             float blue,
                                                             float alpha);

### Warning

`cogl_color_set_from_4f` has been deprecated since version 1.4 and should not be used in newly-written code. Use cogl_color_init_from_4f instead.

Sets the values of the passed channels into a CoglColor

`color` : | A pointer to a CoglColor to initialize
`red` : | value of the red channel, between 0 and `1`.0
`green` : | value of the green channel, between 0 and `1`.0
`blue` : | value of the blue channel, between 0 and `1`.0
`alpha` : | value of the alpha channel, between 0 and `1`.0

Since 1.0

### cogl_color_get_red ()

    float               cogl_color_get_red                  (const CoglColor *color);

Retrieves the red channel of `color` as a fixed point value between 0 and `1`.0.

`color` : | a CoglColor
Returns : | the red channel of the passed color

Since 1.0

### cogl_color_get_green ()

    float               cogl_color_get_green                (const CoglColor *color);

Retrieves the green channel of `color` as a fixed point value between 0 and `1`.0.

`color` : | a CoglColor
Returns : | the green channel of the passed color

Since 1.0

### cogl_color_get_blue ()

    float               cogl_color_get_blue                 (const CoglColor *color);

Retrieves the blue channel of `color` as a fixed point value between 0 and `1`.0.

`color` : | a CoglColor
Returns : | the blue channel of the passed color

Since 1.0

### cogl_color_get_alpha ()

    float               cogl_color_get_alpha                (const CoglColor *color);

Retrieves the alpha channel of `color` as a fixed point value between 0 and `1`.0.

`color` : | a CoglColor
Returns : | the alpha channel of the passed color

Since 1.0

### cogl_color_get_red_byte ()

    unsigned char       cogl_color_get_red_byte             (const CoglColor *color);

Retrieves the red channel of `color` as a byte value between 0 and 255

`color` : | a CoglColor
Returns : | the red channel of the passed color

Since 1.0

### cogl_color_get_green_byte ()

    unsigned char       cogl_color_get_green_byte           (const CoglColor *color);

Retrieves the green channel of `color` as a byte value between 0 and 255

`color` : | a CoglColor
Returns : | the green channel of the passed color

Since 1.0

### cogl_color_get_blue_byte ()

    unsigned char       cogl_color_get_blue_byte            (const CoglColor *color);

Retrieves the blue channel of `color` as a byte value between 0 and 255

`color` : | a CoglColor
Returns : | the blue channel of the passed color

Since 1.0

### cogl_color_get_alpha_byte ()

    unsigned char       cogl_color_get_alpha_byte           (const CoglColor *color);

Retrieves the alpha channel of `color` as a byte value between 0 and 255

`color` : | a CoglColor
Returns : | the alpha channel of the passed color

Since 1.0

### cogl_color_get_red_float ()

    float               cogl_color_get_red_float            (const CoglColor *color);

Retrieves the red channel of `color` as a floating point value between 0.0 and 1.0

`color` : | a CoglColor
Returns : | the red channel of the passed color

Since 1.0

### cogl_color_get_green_float ()

    float               cogl_color_get_green_float          (const CoglColor *color);

Retrieves the green channel of `color` as a floating point value between 0.0 and 1.0

`color` : | a CoglColor
Returns : | the green channel of the passed color

Since 1.0

### cogl_color_get_blue_float ()

    float               cogl_color_get_blue_float           (const CoglColor *color);

Retrieves the blue channel of `color` as a floating point value between 0.0 and 1.0

`color` : | a CoglColor
Returns : | the blue channel of the passed color

Since 1.0

### cogl_color_get_alpha_float ()

    float               cogl_color_get_alpha_float          (const CoglColor *color);

Retrieves the alpha channel of `color` as a floating point value between 0.0 and 1.0

`color` : | a CoglColor
Returns : | the alpha channel of the passed color

Since 1.0

### cogl_color_set_red ()

    void                cogl_color_set_red                  (CoglColor *color,
                                                             float red);

Sets the red channel of `color` to `red`.

`color` : | a CoglColor
`red` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_green ()

    void                cogl_color_set_green                (CoglColor *color,
                                                             float green);

Sets the green channel of `color` to `green`.

`color` : | a CoglColor
`green` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_blue ()

    void                cogl_color_set_blue                 (CoglColor *color,
                                                             float blue);

Sets the blue channel of `color` to `blue`.

`color` : | a CoglColor
`blue` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_alpha ()

    void                cogl_color_set_alpha                (CoglColor *color,
                                                             float alpha);

Sets the alpha channel of `color` to `alpha`.

`color` : | a CoglColor
`alpha` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_red_byte ()

    void                cogl_color_set_red_byte             (CoglColor *color,
                                                             unsigned char red);

Sets the red channel of `color` to `red`.

`color` : | a CoglColor
`red` : | a byte value between 0 and 255

Since 1.4

### cogl_color_set_green_byte ()

    void                cogl_color_set_green_byte           (CoglColor *color,
                                                             unsigned char green);

Sets the green channel of `color` to `green`.

`color` : | a CoglColor
`green` : | a byte value between 0 and 255

Since 1.4

### cogl_color_set_blue_byte ()

    void                cogl_color_set_blue_byte            (CoglColor *color,
                                                             unsigned char blue);

Sets the blue channel of `color` to `blue`.

`color` : | a CoglColor
`blue` : | a byte value between 0 and 255

Since 1.4

### cogl_color_set_alpha_byte ()

    void                cogl_color_set_alpha_byte           (CoglColor *color,
                                                             unsigned char alpha);

Sets the alpha channel of `color` to `alpha`.

`color` : | a CoglColor
`alpha` : | a byte value between 0 and 255

Since 1.4

### cogl_color_set_red_float ()

    void                cogl_color_set_red_float            (CoglColor *color,
                                                             float red);

Sets the red channel of `color` to `red`.

`color` : | a CoglColor
`red` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_green_float ()

    void                cogl_color_set_green_float          (CoglColor *color,
                                                             float green);

Sets the green channel of `color` to `green`.

`color` : | a CoglColor
`green` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_blue_float ()

    void                cogl_color_set_blue_float           (CoglColor *color,
                                                             float blue);

Sets the blue channel of `color` to `blue`.

`color` : | a CoglColor
`blue` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_set_alpha_float ()

    void                cogl_color_set_alpha_float          (CoglColor *color,
                                                             float alpha);

Sets the alpha channel of `color` to `alpha`.

`color` : | a CoglColor
`alpha` : | a float value between 0.0f and 1.0f

Since 1.4

### cogl_color_premultiply ()

    void                cogl_color_premultiply              (CoglColor *color);

Converts a non-premultiplied color to a pre-multiplied color. For example, semi-transparent red is (1.0, 0, 0, 0.5) when non-premultiplied and (0.5, 0, 0, 0.5) when premultiplied.

`color` : | the color to premultiply

Since 1.0

### cogl_color_unpremultiply ()

    void                cogl_color_unpremultiply            (CoglColor *color);

Converts a pre-multiplied color to a non-premultiplied color. For example, semi-transparent red is (0.5, 0, 0, 0.5) when premultiplied and (1.0, 0, 0, 0.5) when non-premultiplied.

`color` : | the color to unpremultiply

Since 1.4

### cogl_color_equal ()

    gboolean            cogl_color_equal                    (gconstpointer v1,
                                                             gconstpointer v2);

Compares two CoglColors and checks if they are the same.

This function can be passed to `g_hash_table_new()` as the `key_equal_func` parameter, when using CoglColors as keys in a GHashTable.

`v1` : | a CoglColor
`v2` : | a CoglColor
Returns : | `TRUE` if the two colors are the same.

Since 1.0