GwyRGBA — Bit depth independet RGBA colors
GwyRGBA * | gwy_rgba_new () |
GwyRGBA * | gwy_rgba_copy () |
void | gwy_rgba_free () |
void | gwy_rgba_to_gdk_color () |
guint16 | gwy_rgba_to_gdk_alpha () |
void | gwy_rgba_from_gdk_color () |
void | gwy_rgba_from_gdk_color_and_alpha () |
void | gwy_rgba_interpolate () |
gboolean | gwy_rgba_get_from_container () |
void | gwy_rgba_store_to_container () |
gboolean | gwy_rgba_remove_from_container () |
void | gwy_rgba_set_gdk_gc_fg () |
void | gwy_rgba_set_gdk_gc_bg () |
void | gwy_rgba_to_hex6 () |
void | gwy_rgba_to_hex8 () |
guint32 | gwy_rgba_to_pixbuf_pixel () |
void | gwy_rgba_from_pixbuf_pixel () |
GwyRGBA |
#include <libdraw/gwydraw.h>
GwyRGBA is a bit depth independent representation of an RGB or RGBA color, using floating point values from the [0,1] interval.
GwyRGBA is not an object, but a simple struct that can be allocated on
stack on created with g_new()
or malloc()
. Helper functions for conversion
between GwyRGBA and GdkColor (gwy_rgba_to_gdk_color()
,
gwy_rgba_from_gdk_color()
) and for GwyContainer storage by component
(gwy_rgba_store_to_container()
, gwy_rgba_get_from_container()
) are provided.
GwyRGBA * gwy_rgba_new (gdouble r
,gdouble g
,gdouble b
,gdouble a
);
Creates RGBA colour specification.
This is mostly useful for language bindings.
r |
The red component. |
|
g |
The green component. |
|
b |
The blue component. |
|
a |
The alpha (opacity) value. |
New RGBA colour structure. The result must be freed with
gwy_rgba_free()
, not g_free()
.
Since: 2.47
GwyRGBA *
gwy_rgba_copy (const GwyRGBA *rgba
);
Makes a copy of a rgba structure. The result must be freed using
gwy_rgba_free()
.
rgba |
A RGBA color. |
A copy of rgba
.
void
gwy_rgba_free (GwyRGBA *rgba
);
Frees an rgba structure created with gwy_rgba_copy()
.
rgba |
A RGBA color. |
void gwy_rgba_to_gdk_color (const GwyRGBA *rgba
,GdkColor *gdkcolor
);
Converts a rgba to a Gdk color.
Note no allocation is performed, just channel value conversion.
rgba |
A RGBA color. |
|
gdkcolor |
A GdkColor. |
guint16
gwy_rgba_to_gdk_alpha (const GwyRGBA *rgba
);
Converts a rgba to a Gdk opacity value.
rgba |
A RGBA color. |
The opacity value as a 16bit integer.
void gwy_rgba_from_gdk_color (GwyRGBA *rgba
,const GdkColor *gdkcolor
);
Converts a Gdk color to a rgba.
The alpha value is unchanged, as GdkColor has no opacity information.
rgba |
A RGBA color. |
|
gdkcolor |
A GdkColor. |
void gwy_rgba_from_gdk_color_and_alpha (GwyRGBA *rgba
,const GdkColor *gdkcolor
,guint16 gdkalpha
);
Converts a Gdk color plus an opacity value to a rgba.
rgba |
A RGBA color. |
|
gdkcolor |
A GdkColor. |
|
gdkalpha |
Gdk 16bit opacity value. |
void gwy_rgba_interpolate (const GwyRGBA *src1
,const GwyRGBA *src2
,gdouble x
,GwyRGBA *rgba
);
Linearly interpolates two colors, including alpha blending.
Correct blending of two not fully opaque colors is tricky. Always use this function, not simple independent interpolation of r, g, b, and a.
src1 |
Color at point |
|
src2 |
Color at point |
|
x |
Point in interval 0..1 to take color from. |
|
rgba |
A GwyRGBA to store the result to. |
gboolean gwy_rgba_get_from_container (GwyRGBA *rgba
,GwyContainer *container
,const gchar *prefix
);
Gets RGBA color components from a container.
This is a convenience function to get the components in the common arrangement.
rgba |
A RGBA color. |
|
container |
A GwyContainer to get the color components from. |
|
prefix |
Prefix in |
Whether all rgba
components were successfully found and set.
void gwy_rgba_store_to_container (const GwyRGBA *rgba
,GwyContainer *container
,const gchar *prefix
);
Stores RGBA color components to a container.
This is a convenience function to store the components in the common arrangement.
rgba |
A RGBA color. |
|
container |
A GwyContainer to store the color components to. |
|
prefix |
Prefix in |
gboolean gwy_rgba_remove_from_container (GwyContainer *container
,const gchar *prefix
);
Removes RGBA color components from a container.
This is a convenience function to remove the components in the common arrangement.
container |
A GwyContainer to remove the color components from. |
|
prefix |
Prefix in |
TRUE
if anything was removed.
void gwy_rgba_set_gdk_gc_fg (const GwyRGBA *rgba
,GdkGC *gc
);
Sets foreground color of a Gdk graphics context from a RGBA color.
This is a convenience wrapper around gdk_gc_set_rgb_fg_color()
, see its
documentation for details and caveats.
rgba |
A RGBA color. Its alpha component is ignored, only RGB is used. |
|
gc |
A Gdk graphics context to set forgeground color of. |
void gwy_rgba_set_gdk_gc_bg (const GwyRGBA *rgba
,GdkGC *gc
);
Sets foreground color of a Gdk graphics context from a RGBA color.
This is a convenience wrapper around gdk_gc_set_rgb_bg_color()
, see its
documentation for details and caveats.
rgba |
A RGBA color. Its alpha component is ignored, only RGB is used. |
|
gc |
A Gdk graphics context to set forgeground color of. |
void gwy_rgba_to_hex6 (const GwyRGBA *rgba
,gchar *hexout
);
Formats the R, G and B components of a RGBA color to hexadecimal string.
The component order is R, G and B. The output has always exactly 6 bytes and does not include any "#" prefix which is used in some contexts.
rgba |
A RGBA color. Its alpha component is ignored, only RGB is used. |
|
hexout |
Buffer at least seven character long where the hexadecimal representation (e.g. "ff0000" for red) will be stored. |
Since: 2.32
void gwy_rgba_to_hex8 (const GwyRGBA *rgba
,gchar *hexout
);
Formats all components of a RGBA color to hexadecimal string.
The component order is A, R, G and B. Note that while this order is a common it is by no means universal. The output has always exactly 8 bytes and does not include any "#" prefix which is used in some contexts.
rgba |
A RGBA color. |
|
hexout |
Buffer at least nine character long where the hexadecimal representation (e.g. "ffff0000" for opaque red) will be stored. |
Since: 2.32
guint32
gwy_rgba_to_pixbuf_pixel (const GwyRGBA *rgba
);
Converts a RGBA color to pixbuf pixel.
The returned pixel value includes opacity. If rgba
is partially
transparent, so is the pixel.
rgba |
A RGBA color. |
The pixel value as a 32-bit integer.
Since: 2.49
void gwy_rgba_from_pixbuf_pixel (GwyRGBA *rgba
,guint32 pixel
);
Converts a pixbuf pixel value to a RGBA color.
The conversion includes opacity. If the opacity channel is undefined or
should be ignored, you need to either set the lowest byte of pixel
to 0xff
or fix rgba
afterwards.
rgba |
A GwyRGBA to store the result to. |
|
pixel |
Pixbuf pixel value as a 32-bit integer. |
Since: 2.49
typedef struct { gdouble r; gdouble g; gdouble b; gdouble a; } GwyRGBA;
RGB[A] color specification type.
All values are from the range [0,1]. The components are not premultiplied.
gdouble |
The red component. |
|
gdouble |
The green component. |
|
gdouble |
The blue component. |
|
gdouble |
The alpha (opacity) value. |