<-- Back to AG_Intro.3


#include <agar/core.h>
#include <agar/gui.h>


The AG_Color structure describes a color in terms of Red, Green, Blue, and Alpha components. The AG_Color structure is declared as:
typedef struct ag_color {
	Uint16 r,g,b,a;
	Uint8  r,g,b,a;
} AG_Color;

Support for 16-bit component depth requires the AG_LARGE memory model which can handle 64-bit wide pixels.

The alpha component may or may not be used in a given context. A value of 0 (or AG_TRANSPARENT or AG_COLOR_FIRST) is fully transparent, while AG_OPAQUE (or AG_COLOR_LAST) is fully opaque.


AG_Color AG_ColorRGB_8 (Uint8 r, Uint8 g, Uint8 b)

AG_Color AG_ColorRGBA_8 (Uint8 r, Uint8 g, Uint8 b, Uint8 a)

AG_Color AG_ColorRGB_16 (Uint16 r, Uint16 g, Uint16 b)

AG_Color AG_ColorRGBA_16 (Uint16 r, Uint16 g, Uint16 b, Uint16 a)

void AG_HSV2Color (float hue, float sat, float val, AG_Color *C)

void AG_Color2HSV (AG_Color c, float *hue, float *sat, float *val)

AG_Color AG_ColorHex16 (Uint16 hex)

AG_Color AG_ColorHex32 (Uint32 hex)

AG_Color AG_ColorHex64 (Uint64 hex)

AG_Color AG_ColorFromString (const char *spec, const AG_Color *parentColor)

AG_Color AG_ColorAdd (AG_Color c, AG_ColorOffset offs)

int AG_ColorCompare (AG_Color a, AG_Color b)

AG_ColorRGB_8() and AG_ColorRGB_16() return an AG_Color from 8- or 16-bit red, green and blue components (with alpha set to fully opaque).

AG_ColorRGBA_8() and AG_ColorRGBA_16() return an AG_Color from 8- or 16-bit RGB and alpha components.

AG_HSV2Color() maps a color in HSV space to the closest approximation in RGB space, and copies the A component as-is. The inverse operation is performed by AG_Color2HSV(). Note: H and V become increasingly lossy as S->0.

The AG_ColorHex16(), AG_ColorHex32() and AG_ColorHex64() routines convert a color packed into 0xRGBA (4-bit components), 0xRRGGBBAA (8-bit components), or 0xRRRRGGGGBBBBAAAA (16-bit components) into an AG_Color.

AG_ColorFromString() converts a text-based color representation to an AG_Color. The following formats are allowed:
	"hsv(h,s,v[,a])"    (if HAVE_FLOAT)

Components with a terminating "%" character are interpreted as a percentage of the corresponding component in parentColor (if non-NULL).

AG_ColorAdd() adds the components of a color c to the signed components of offs and returns the clamped result. The AG_ColorOffset structure is declared as:
typedef struct ag_color_offset {
	Sint16 r,g,b,a;
	Sint8  r,g,b,a;
} AG_ColorOffset;

AG_ColorCompare() returns non-zero if the two colors differ.


AG_Intro(3), AG_MapColorRGB(3), AG_MapColorRGBA(3), AG_MapPixelRGB(3), AG_MapPixelRGBA(3), AG_Widget(3)


AG_Color was introduced in Agar 1.4 (previously only 32-bit packed pixel values in a reference surface format were used). Agar 1.6 added support for 16-bit component depth under the AG_LARGE memory model, and increased the maximum packed-pixel width to 64-bit.