Color Management

Color Management — Colors and color tables

Functions

Types and Values

Includes

#include <grx-3.0.h>

Description

The library supports two models for color management. In the 'indirect' (or color table) model, color values are indices to a color table. The color table slots will be allocated with the highest resolution supported by the hardware with respect to the component color intensities. In the 'direct' (or RGB) model, color values map directly into component color intensities with non-overlapping bitfields of the color index representing the component colors.

The color table model is supported up to 256 colors. The RGB model is supported for 256 colors and up.

In the RGB model the color index map to component color intensities depend on the video mode set, so it can't be assumed the component color bitfields.

Functions

grx_color_get ()

GrxColor
grx_color_get (guint8 r,
               guint8 g,
               guint8 b);

Gets a color based on the RGB value.

A new color is allocated in the color table if needed.

The color should be released with grx_color_put() when it is no longer used.

Parameters

r

the red component value

 

g

the green component value

 

b

the blue component value

 

Returns

the composite color value or GRX_COLOR_NONE if there are no more free colors.


grx_color_get_inline ()

GrxColor
grx_color_get_inline (guint8 r,
                      guint8 g,
                      guint8 b);

Gets a color in the color table based on the RGB value.

This is the same as grx_color_get(), but inlined in C code.

[skip]

Parameters

r

the red component value

 

g

the green component value

 

b

the blue component value

 

Returns

the composite color value or GRX_COLOR_NONE if there are no more free colors.


grx_color_get2 ()

GrxColor
grx_color_get2 (guint32 hcolor);

Gets a color in the color table based on hcolor .

A new color is allocated in the color table if needed.

The color should be released with grx_color_put() when it is no longer used.

Parameters

hcolor

the color in 0xRRGGBB format.

 

Returns

the composite color value or GRX_COLOR_NONE if there are no more free colors.


grx_color_get2_inline ()

GrxColor
grx_color_get2_inline (guint32 hcolor);

Gets a color in the color table based on hcolor .

This is the same as grx_color_get2(), but inlined in C code.

[skip]

Parameters

hcolor

the color in 0xRRGGBB format.

 

Returns

the composite color value or GRX_COLOR_NONE if there are no more free colors.


grx_color_put ()

void
grx_color_put (GrxColor c);

Releases a color that was obtained by grx_color_get() and friends.

This has no effect in RGB or grayscale graphics modes.

Parameters

c

the color

 

grx_color_lookup ()

GrxColor
grx_color_lookup (GArray *table,
                  guint index);

Looks up a color in the color table.

Parameters

table

the color table.

[element-type GrxColor]

index

the index in the color table

 

Returns

the color or GRX_COLOR_NONE if index is out of range


grx_color_get_value ()

GrxColor
grx_color_get_value (GrxColor c);

Gets the color component of a color value.

Parameters

c

the source color value

 

Returns

the color component.


grx_color_get_mode ()

GrxColorMode
grx_color_get_mode (GrxColor c);

Gets the GrxColorMode component of a color value.

Parameters

c

the source color value

 

Returns

the GrxColorMode component.


grx_color_to_write_mode ()

GrxColor
grx_color_to_write_mode (GrxColor c);

Sets the color to GRX_COLOR_MODE_WRITE.

Parameters

c

the source color value

 

Returns

the modified color value.


grx_color_to_xor_mode ()

GrxColor
grx_color_to_xor_mode (GrxColor c);

Sets the color to GRX_COLOR_MODE_XOR.

Parameters

c

the source color value

 

Returns

the modified color value.


grx_color_to_or_mode ()

GrxColor
grx_color_to_or_mode (GrxColor c);

Sets the color to GRX_COLOR_MODE_OR.

Parameters

c

the source color value

 

Returns

the modified color value.


grx_color_to_and_mode ()

GrxColor
grx_color_to_and_mode (GrxColor c);

Sets the color to GRX_COLOR_MODE_AND.

Parameters

c

the source color value

 

Returns

the modified color value.


grx_color_to_image_mode ()

GrxColor
grx_color_to_image_mode (GrxColor c);

Sets the color to GRX_COLOR_MODE_IMAGE.

Parameters

c

the source color value

 

Returns

the modified color value.


grx_color_get_black ()

GrxColor
grx_color_get_black (void);

Gets the color value for black.

This is guaranteed to be 0. In C code, you can use GRX_COLOR_BLACK for short.

Returns

the color value.


grx_color_get_white ()

GrxColor
grx_color_get_white (void);

Gets the color value for white.

In C code, you can use GRX_COLOR_WHITE for short.

Returns

the color value.


grx_color_build_rgb ()

GrxColor
grx_color_build_rgb (guint8 r,
                     guint8 g,
                     guint8 b);

Build a RGB color value based on the current graphics mode.

This will not allocate a new color even if a color table is being used.

Parameters

r

the red component value

 

g

the green component value

 

b

the blue component value

 

Returns

a new color value.


grx_color_build_rgb_round ()

GrxColor
grx_color_build_rgb_round (guint8 r,
                           guint8 g,
                           guint8 b);

Build a RGB color value based on the current graphics mode.

This function is similar to grx_color_build_rgb(), but will limit the RGB components to 255 during the scaling.

This will not allocate a new color even if a color table is being used.

Parameters

r

the red component value

 

g

the green component value

 

b

the blue component value

 

Returns

a new color value.


grx_color_build_grayscale ()

GrxColor
grx_color_build_grayscale (guint8 r,
                           guint8 g,
                           guint8 b);

Build a grayscale color value based on the current graphics mode.

This will not allocate a new color even if a color table is being used.

Parameters

r

the red component value

 

g

the green component value

 

b

the blue component value

 

Returns

a new color value.


grx_color_get_red ()

guint8
grx_color_get_red (GrxColor c);

Gets the red component of a color value.

This function only works on RGB colors and not color table values. For color table values, use grx_color_query() instead.

Parameters

c

the source color value.

 

Returns

the red component.


grx_color_get_green ()

guint8
grx_color_get_green (GrxColor c);

Gets the green component of a color value.

This function only works on RGB colors and not color table values. For color table values, use grx_color_query() instead.

Parameters

c

the source color value.

 

Returns

the green component.


grx_color_get_blue ()

guint8
grx_color_get_blue (GrxColor c);

Gets the blue component of a color value.

This function only works on RGB colors and not color table values. For color table values, use grx_color_query() instead.

Parameters

c

the source color value.

 

Returns

the blue component.


grx_color_query ()

void
grx_color_query (GrxColor c,
                 guint8 *r,
                 guint8 *g,
                 guint8 *b);

Gets the RGB color components of a color.

Parameters

c

the color

 

r

the red component.

[out]

g

the green component.

[out]

b

the blue component.

[out]

grx_color_query_inline ()

void
grx_color_query_inline (GrxColor c,
                        guint8 *r,
                        guint8 *g,
                        guint8 *b);

Gets the RGB color components of a color.

This is the same as grx_color_query(), but inlined in C code.

[skip]

Parameters

c

the color

 

r

the red component.

[out]

g

the green component.

[out]

b

the blue component.

[out]

grx_color_query2 ()

void
grx_color_query2 (GrxColor c,
                  guint32 *hcolor);

Gets the RGB color components of a color.

Parameters

c

the color

 

hcolor

the components in 0xRRGGBB format.

[out]

grx_color_query2_inline ()

void
grx_color_query2_inline (GrxColor c,
                         guint32 *hcolor);

Gets the RGB color components of a color.

This is the same as grx_color_query2(), but inlined in C code.

[skip]

Parameters

c

the color

 

hcolor

the components in 0xRRGGBB format.

[out]

grx_color_get_ega_colors ()

GrxColor *
grx_color_get_ega_colors (void);

Gets an array of the 16 classic EGA colors. Use GrxEgaColorIndex to determine the color at each index of the array.

The the colors and the array itself must not be freed.

Returns

array of color indexes.

[array fixed-size=16]


grx_color_cell_get ()

GrxColorCell
grx_color_cell_get (void);

Allocates a new color that can be changed with grx_color_cell_set().

The color must be freed with grx_color_cell_put().

RGB and grayscale graphics modes will always return GRX_COLOR_NONE.

Returns

a newly allocated color cell or GRX_COLOR_NONE if there are no more free cells.


grx_color_cell_set ()

void
grx_color_cell_set (GrxColorCell c,
                    guint8 r,
                    guint8 g,
                    guint8 b);

Sets/changes the color of a cell after it was allocated.

Parameters

c

a color that was allocated by grx_color_cell_get()

 

r

the red component

 

g

the green component

 

b

the blue component

 

grx_color_cell_put ()

void
grx_color_cell_put (GrxColorCell c);

Releases a cell that was obtained with grx_color_cell_get().

Parameters

c

the color

 

grx_color_info_reset_colors ()

void
grx_color_info_reset_colors (void);

Frees all colors (except for black and white).

If grx_color_info_set_palette_type_rgb() was called, this will also change the color system back to using a color table.


grx_color_info_set_palette_type_rgb ()

void
grx_color_info_set_palette_type_rgb (void);

Changes the graphics mode to RGB color values instead of using a color table.

Initially, graphics modes with 256 colors or less use a color table. Currently, this function only works for modes with 16 or 256 colors.

This has no effect if the color mode is already RGB or if it is grayscale.


grx_color_info_get_palette_type ()

GrxColorPaletteType
grx_color_info_get_palette_type (void);

Gets the current color palette type.

Returns

a GrxColorPaletteType.


grx_color_info_refresh_colors ()

void
grx_color_info_refresh_colors (void);

Reloads the currently allocated color values into the video hardware.

This function is not needed in typical applications, unless the display adapter is programmed directly by the application.


grx_color_info_n_colors ()

gint
grx_color_info_n_colors (void);

Gets the number of colors supported by the current graphics mode.

Returns

the number of colors.


grx_color_info_n_free_colors ()

gint
grx_color_info_n_free_colors (void);

Gets the number of unallocated colors remaining for the current graphics mode.

For RGB graphics modes, this will always return 0.

Returns

the number of unallocated colors.


grx_color_info_get_save_buffer_size ()

gint
grx_color_info_get_save_buffer_size (void);

grx_color_info_save_colors ()

void
grx_color_info_save_colors (gpointer buffer);

grx_color_info_restore_colors ()

void
grx_color_info_restore_colors (gpointer buffer);

Types and Values

GrxColor

typedef guint32 GrxColor;

32-bit integer for storing color information.

The lower 24 bits are the actual color value and the upper 8 bits are the GrxColorMode.


enum GrxColorMode

Values added to a GrxColor to affect how the color is used in drawing operations.

Members

GRX_COLOR_MODE_WRITE

Overwrite any existing color

 

GRX_COLOR_MODE_XOR

XOR this color with the existing color

 

GRX_COLOR_MODE_OR

OR this color with the existing color

 

GRX_COLOR_MODE_AND

AND this color with the existing color

 

GRX_COLOR_MODE_IMAGE

Overwrite existing color unless this color is GRX_COLOR_NONE. Only works with bitblt operations.

 

GRX_COLOR_VALUE_MASK

#define GRX_COLOR_VALUE_MASK 0x00ffffffUL

Used to get the color portion of a GrxColor.


GRX_COLOR_MODE_MASK

#define GRX_COLOR_MODE_MASK 0xff000000UL

Used to get the GrxColorMode portion of a GrxColor.


GRX_COLOR_NONE

#define GRX_COLOR_NONE ((GrxColor)(GRX_COLOR_MODE_XOR | 0))

Used to indicate transparency in bitblt operations.

See GrxColorMode.


enum GrxColorPaletteType

Indicates the type of color palette that is in use.

Members

GRX_COLOR_PALETTE_TYPE_GRAYSCALE

RGB color values will be converted to grayscale.

 

GRX_COLOR_PALETTE_TYPE_COLOR_TABLE

Colors use a lookup table.

 

GRX_COLOR_PALETTE_TYPE_RGB

RGB values are used directly.

 

GRX_COLOR_BLACK

#define GRX_COLOR_BLACK grx_color_get_black()

Convenience macro for grx_color_get_black().


GRX_COLOR_WHITE

#define GRX_COLOR_WHITE grx_color_get_white()

Convenience macro for grx_color_get_white().


enum GrxEgaColorIndex

Indexes for use with the array returned by grx_color_get_ega_colors().

Members

GRX_EGA_COLOR_INDEX_BLACK

black

 

GRX_EGA_COLOR_INDEX_BLUE

blue

 

GRX_EGA_COLOR_INDEX_GREEN

green

 

GRX_EGA_COLOR_INDEX_CYAN

cyan

 

GRX_EGA_COLOR_INDEX_RED

red

 

GRX_EGA_COLOR_INDEX_MAGENTA

magenta

 

GRX_EGA_COLOR_INDEX_BROWN

brown

 

GRX_EGA_COLOR_INDEX_LIGHT_GRAY

light gray

 

GRX_EGA_COLOR_INDEX_DARK_GRAY

dark gray

 

GRX_EGA_COLOR_INDEX_LIGHT_BLUE

light blue

 

GRX_EGA_COLOR_INDEX_LIGHT_GREEN

light green

 

GRX_EGA_COLOR_INDEX_LIGHT_CYAN

light cyan

 

GRX_EGA_COLOR_INDEX_LIGHT_RED

light red

 

GRX_EGA_COLOR_INDEX_LIGHT_MAGENTA

light magenta

 

GRX_EGA_COLOR_INDEX_YELLOW

yellow

 

GRX_EGA_COLOR_INDEX_WHITE

white

 

GrxColorCell

typedef GrxColor GrxColorCell;

A mutable color value.