Module gwy :: Class RGBA
[hide private]
[frames] | no frames]

Class RGBA

source code

Bit depth independet RGBA colors

RGBA is a bit depth independent representation of an RGB or RGBA color, using floating point values from the [0,1] interval.

RGBA 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 RGBA and GdkColor (RGBA.to_gdk_color(), RGBA.from_gdk_color()) and for Container storage by component (RGBA.store_to_container(), RGBA.get_from_container()) are provided.

Instance Methods [hide private]
 
__init__(r, g, b, a)
Creates RGBA colour specification.
source code
 
copy()
Makes a copy of a rgba structure.
source code
 
free()
Frees an rgba structure created with RGBA.copy().
source code
 
to_gdk_alpha()
Converts a rgba to a Gdk opacity value.
source code
 
interpolate(src2, x, rgba)
Linearly interpolates two colors, including alpha blending.
source code
 
get_from_container(container, prefix)
Gets RGBA color components from a container.
source code
 
store_to_container(container, prefix)
Stores RGBA color components to a container.
source code
 
set_gdk_gc_fg(gc)
Sets foreground color of a Gdk graphics context from a RGBA color.
source code
 
set_gdk_gc_bg(gc)
Sets foreground color of a Gdk graphics context from a RGBA color.
source code
 
to_hex6(hexout)
Formats the R, G and B components of a RGBA color to hexadecimal string.
source code
 
to_hex8(hexout)
Formats all components of a RGBA color to hexadecimal string.
source code
 
to_pixbuf_pixel()
Converts a RGBA color to pixbuf pixel.
source code
 
from_pixbuf_pixel(pixel)
Converts a pixbuf pixel value to a RGBA color.
source code
Method Details [hide private]

__init__(r, g, b, a)
(Constructor)

source code 

Creates RGBA colour specification.

This is mostly useful for language bindings.

Parameters:
  • r - The red component. (float)
  • g - The green component. (float)
  • b - The blue component. (float)
  • a - The alpha (opacity) value. (float)
Returns:
New RGBA colour structure. The result must be freed with RGBA.free(), not g_free(). (RGBA)

Since: 2.47

copy()

source code 

Makes a copy of a rgba structure. The result must be freed using RGBA.free().

Returns:
A copy of rgba. (RGBA)

to_gdk_alpha()

source code 

Converts a rgba to a Gdk opacity value.

Returns:
The opacity value as a 16bit integer. (guint16)

interpolate(src2, x, rgba)

source code 

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.

Parameters:
  • src2 - Color at point x = 1.0. (const-RGBA*)
  • x - Point in interval 0..1 to take color from. (float)
  • rgba - A RGBA to store the result to. (RGBA)

get_from_container(container, prefix)

source code 

Gets RGBA color components from a container.

This is a convenience function to get the components in the common arrangement.

Parameters:
  • container - A Container to get the color components from. (Container)
  • prefix - Prefix in container, e.g. "/0/mask" (it would try to fetch "/0/mask/red", "/0/mask/green", etc. then). (string)
Returns:
Whether all rgba components were successfully found and set. (bool)

store_to_container(container, prefix)

source code 

Stores RGBA color components to a container.

This is a convenience function to store the components in the common arrangement.

Parameters:
  • container - A Container to store the color components to. (Container)
  • prefix - Prefix in container, e.g. "/0/mask" (it will store "/0/mask/red", "/0/mask/green", etc. then). (string)

set_gdk_gc_fg(gc)

source code 

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.

Parameters:
  • gc - A Gdk graphics context to set forgeground color of. (gdk.GC)

set_gdk_gc_bg(gc)

source code 

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.

Parameters:
  • gc - A Gdk graphics context to set forgeground color of. (gdk.GC)

to_hex6(hexout)

source code 

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.

Parameters:
  • hexout - Buffer at least seven character long where the hexadecimal representation (e.g. "ff0000" for red) will be stored. (string)

Since: 2.32

to_hex8(hexout)

source code 

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.

Parameters:
  • hexout - Buffer at least nine character long where the hexadecimal representation (e.g. "ffff0000" for opaque red) will be stored. (string)

Since: 2.32

to_pixbuf_pixel()

source code 

Converts a RGBA color to pixbuf pixel.

The returned pixel value includes opacity. If rgba is partially transparent, so is the pixel.

Returns:
The pixel value as a 32-bit integer. (guint32)

Since: 2.49

from_pixbuf_pixel(pixel)

source code 

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.

Parameters:
  • pixel - Pixbuf pixel value as a 32-bit integer. (guint32)

Since: 2.49