Functions

component (name)

conversion_get_destination_space (conversion)

conversion_get_source_space (conversion)

exit ()

fast_fish (source_format, destination_format, performance)

fish (source_format, destination_format)

format (encoding)

format_exists (name)

format_get_bytes_per_pixel (format)

format_get_encoding (babl)

format_get_model (format)

format_get_n_components (format)

format_get_space (format)

format_get_type (format, component_index)

format_has_alpha (format)

format_is_format_n (format)

format_is_palette (format)

format_n (type, components)

format_with_space (encoding, space)

get_model_flags (model)

get_name (babl)

get_version ()

icc_get_key (icc_data, icc_length, key, language, country)

icc_make_space (icc_data, icc_length, intent, error)

init ()

introspect (babl)

model (name)

model_is (babl, model_name)

model_with_space (name, space)

new_palette (name, format_u8, format_u8_with_alpha)

new_palette_with_space (name, space, format_u8, format_u8_with_alpha)

palette_reset (babl)

palette_set_palette (babl, format, data, count)

process (babl_fish, source, destination, n)

process_rows (babl_fish, source, source_stride, dest, dest_stride, n, rows)

sampling (horizontal, vertical)

space (name)

space_from_chromaticities (name, wx, wy, rx, ry, gx, gy, bx, by, trc_red, trc_green, trc_blue, flags)

space_from_icc (icc_data, icc_length, intent)

space_from_rgbxyz_matrix (name, wx, wy, wz, rx, gx, bx, ry, gy, by, rz, gz, bz, trc_red, trc_green, trc_blue)

space_get (space)

space_get_gamma (space)

space_get_icc (babl)

space_get_rgb_luminance (space)

space_is_cmyk (space)

space_is_gray (space)

space_is_rgb (space)

space_with_trc (space, trc)

trc (name)

trc_gamma (gamma)

type (name)

Details

Babl.component(name)
Parameters:

name (str) –

Return type:

Babl.Object

Returns the babl object representing the color component given by name such as for example “R”, “cyan” or “CIE L”.

Babl.conversion_get_destination_space(conversion)
Parameters:

conversion (Babl.Object) –

Return type:

Babl.Object

Returns the RGB space defined for the destination of conversion.

Babl.conversion_get_source_space(conversion)
Parameters:

conversion (Babl.Object) –

Return type:

Babl.Object

Returns the RGB space defined for the source of conversion.

Babl.exit()

Deinitializes the babl library and frees any resources used when matched with the number of calls to Babl.init().

Babl.fast_fish(source_format, destination_format, performance)
Parameters:
Return type:

Babl.Object

Create a faster than normal fish with specified performance (and thus corresponding precision tradeoff), values tolerance can hold: None and “default”, means do same as Babl.fish(), other values understood in increasing order of speed gain are: “exact” “precise” “fast” “glitch”

Fast fishes should be cached, since they are not internally kept track of/made into singletons by babl and many creations of fast fishes will otherwise be a leak.

Babl.fish(source_format, destination_format)
Parameters:
Return type:

Babl.Object

Create a babl fish capable of converting from source_format to destination_format, source and destination can be either strings with the names of the formats or Babl.Object-format objects.

Babl.format(encoding)
Parameters:

encoding (str) –

Return type:

Babl.Object

Returns the babl object representing the color format given by name such as for example “RGB u8”, “CMYK float” or “CIE Lab u16”, creates a format using the sRGB space, to also specify the color space and TRCs for a format, see Babl.format_with_space.

Babl.format_exists(name)
Parameters:

name (str) –

Return type:

int

Returns 1 if the provided format name is known by babl or 0 if it is not. Can also be used to verify that specific extension formats are available (though this can also be inferred from the version of babl).

Babl.format_get_bytes_per_pixel(format)
Parameters:

format (Babl.Object) –

Return type:

int

Returns the bytes per pixel for a babl color format.

Babl.format_get_encoding(babl)
Parameters:

babl (Babl.Object) –

Return type:

str

Returns the components and data type, without space suffix.

Babl.format_get_model(format)
Parameters:

format (Babl.Object) –

Return type:

Babl.Object

Return the model used for constructing the format.

Babl.format_get_n_components(format)
Parameters:

format (Babl.Object) –

Return type:

int

Returns the number of components for the given format.

Babl.format_get_space(format)
Parameters:

format (Babl.Object) –

Return type:

Babl.Object

Babl.format_get_type(format, component_index)
Parameters:
Return type:

Babl.Object

Returns the type in the given format for the given component_index.

Babl.format_has_alpha(format)
Parameters:

format (Babl.Object) –

Return type:

int

Returns whether the format has an alpha channel.

Babl.format_is_format_n(format)
Parameters:

format (Babl.Object) –

Return type:

int

Returns whether the format is a format_n type.

Babl.format_is_palette(format)
Parameters:

format (Babl.Object) –

Return type:

int

check whether a format is a palette backed format.

Babl.format_n(type, components)
Parameters:
Return type:

Babl.Object

Babl.format_with_space(encoding, space)
Parameters:
Return type:

Babl.Object

Returns the babl object representing the color format given by name such as for example “RGB u8”, “R’G’B’A float”, “Y float” with a specific RGB working space used as the space, the resulting format has -space suffixed to it, unless the space requested is sRGB then the unsuffixed version is used. If a format is passed in as space the space of the format is used.

Babl.get_model_flags(model)
Parameters:

model (Babl.Object) –

Return type:

Babl.ModelFlag

Babl.get_name(babl)
Parameters:

babl (Babl.Object) –

Return type:

str

Returns a string describing a Babl.Object object.

Babl.get_version()
Returns:

major:

The major version number

minor:

The minor version number

micro:

The micro version number

Return type:

(major: int, minor: int, micro: int)

Get the version information on the babl library

Babl.icc_get_key(icc_data, icc_length, key, language, country)
Parameters:
  • icc_data (str) –

  • icc_length (int) –

  • key (str) –

  • language (str) –

  • country (str) –

Return type:

str

Babl.icc_make_space(icc_data, icc_length, intent, error)
Parameters:
Return type:

Babl.Object

Babl.init()

Initializes the babl library.

Babl.introspect(babl)
Parameters:

babl (Babl.Object) – A Babl.Object

introspect a given BablObject

Babl.model(name)
Parameters:

name (str) –

Return type:

Babl.Object

Returns the babl object representing the color model given by name such as for example “RGB”, “CMYK” or “CIE Lab”.

Babl.model_is(babl, model_name)
Parameters:
Returns:

0 if the name of the model in babl does not correspond to the provided model name.

Return type:

int

Babl.model_with_space(name, space)
Parameters:
Return type:

Babl.Object

The models for formats also have a space in babl, try to avoid code needing to use this.

Babl.new_palette(name, format_u8, format_u8_with_alpha)
Parameters:
Return type:

Babl.Object

create a new palette based format, name is optional pass in None to get an anonymous format. If you pass in with_alpha the format also gets an 8bit alpha channel. Returns the BablModel of the color model. If you pass in the same name the previous formats will be provided again.

Babl.new_palette_with_space(name, space, format_u8, format_u8_with_alpha)
Parameters:
Return type:

Babl.Object

create a new palette based format, name is optional pass in None to get an anonymous format. If you pass in with_alpha the format also gets an 8bit alpha channel. Returns the BablModel of the color model. If you pass in the same name the previous formats will be provided again.

Babl.palette_reset(babl)
Parameters:

babl (Babl.Object) –

reset a palette to initial state, frees up some caches that optimize conversions.

Babl.palette_set_palette(babl, format, data, count)
Parameters:

Assign a palette to a palette format, the data is a single span of pixels representing the colors of the palette.

Babl.process(babl_fish, source, destination, n)
Parameters:
Return type:

int

Process n pixels from source to destination using Babl.fish, returns number of pixels converted.

Babl.process_rows(babl_fish, source, source_stride, dest, dest_stride, n, rows)
Parameters:
Return type:

int

Babl.sampling(horizontal, vertical)
Parameters:
  • horizontal (int) –

  • vertical (int) –

Return type:

Babl.Object

Returns the babl object representing the horizontal and vertical sampling such as for example 2, 2 for the chroma components in YCbCr.

Babl.space(name)
Parameters:

name (str) –

Return type:

Babl.Object

Returns the babl object representing the specific RGB matrix color working space referred to by name. Babl.Object knows of: sRGB, Rec2020, Adobish, Apple and ProPhoto

Babl.space_from_chromaticities(name, wx, wy, rx, ry, gx, gy, bx, by, trc_red, trc_green, trc_blue, flags)
Parameters:
  • name (str or None) – The name for the color space

  • wx (float) – The X-coordinate of the color space’s white point

  • wy (float) – The Y-coordinate of the color space’s white point

  • rx (float) – The X-coordinate of the red primary

  • ry (float) – The Y-coordinate of the red primary

  • gx (float) – The X-coordinate of the green primary

  • gy (float) – The Y-coordinate of the green primary

  • bx (float) – The X-coordinate of the blue primary

  • by (float) – The Y-coordinate of the blue primary

  • trc_red (Babl.Object) – The red component of the TRC.

  • trc_green (Babl.Object or None) – The green component of the TRC (can be None if it’s the same as trc_red).

  • trc_blue (Babl.Object or None) – The blue component of the TRC (can be None if it’s the same as trc_red).

  • flags (Babl.SpaceFlags) – The Babl.SpaceFlags

Return type:

Babl.Object

Creates a new babl-space/ RGB matrix color space definition with the specified CIE xy(Y) values for white point: wx, wy and primary chromaticities: rx,ry,gx,gy,bx,by and TRCs to be used. After registering a new babl-space it can be used with Babl.space() passing its name;

Internally this does the math to derive the RGBXYZ matrix as used in an ICC profile.

Babl.space_from_icc(icc_data, icc_length, intent)
Parameters:
  • icc_data (str) – pointer to icc profile in memory

  • icc_length (int) – length of icc profile in bytes

  • intent (Babl.IccIntent) – the intent from the ICC profile to use.

Returns:

error:

pointer to a string where decoding errors can be stored, if an error occurs, None is returned and an error message is provided in error.

Return type:

(Babl.Object, error: str)

Create a babl space from an in memory ICC profile, the profile does no longer need to be loaded for the space to work, multiple calls with the same icc profile and same intent will result in the same babl space.

On a profile that doesn’t contain A2B0 and B2A0 CLUTs perceptual and relative-colorimetric intents are treated the same.

If a BablSpace cannot be created from the profile None is returned and a static string is set on the const str *value pointed at with &value containing a message describing why the provided data does not yield a babl space.

Babl.space_from_rgbxyz_matrix(name, wx, wy, wz, rx, gx, bx, ry, gy, by, rz, gz, bz, trc_red, trc_green, trc_blue)
Parameters:
  • name (str or None) – The name for the color space

  • wx (float) – The X-coordinate of the color space’s white point

  • wy (float) – The Y-coordinate of the color space’s white point

  • wz (float) – The Z-coordinate of the color space’s white point

  • rx (float) – The X-coordinate of the red primary

  • gx (float) – The X-coordinate of the green primary

  • bx (float) – The X-coordinate of the blue primary

  • ry (float) – The Y-coordinate of the red primary

  • gy (float) – The Y-coordinate of the green primary

  • by (float) – The Y-coordinate of the blue primary

  • rz (float) – The Z-coordinate of the red primary

  • gz (float) – The Z-coordinate of the green primary

  • bz (float) – The Z-coordinate of the blue primary

  • trc_red (Babl.Object) – The red component of the TRC.

  • trc_green (Babl.Object or None) – The green component of the TRC (can be None if it’s the same as trc_red).

  • trc_blue (Babl.Object or None) – The blue component of the TRC (can be None if it’s the same as trc_red).

Return type:

Babl.Object

Creates a new RGB matrix color space definition using a precomputed D50 adapted 3x3 matrix and associated CIE XYZ whitepoint, as possibly read from an ICC profile.

Babl.space_get(space)
Parameters:

space (Babl.Object) – A Babl.Object instance

Returns:

xw:

The X-coordinate of the color space’s white point

yw:

The Y-coordinate of the color space’s white point

xr:

The X-coordinate of the red primary

yr:

The Y-coordinate of the red primary

xg:

The X-coordinate of the blue primary

yg:

The Y-coordinate of the green primary

xb:

The X-coordinate of the blue primary

yb:

The Y-coordinate of the blue primary

red_trc:

The red component of the TRC.

green_trc:

The green component of the TRC (can be None if it’s the same as red_trc).

blue_trc:

The blue component of the TRC (can be None if it’s the same as red_trc).

Return type:

(xw: float, yw: float, xr: float, yr: float, xg: float, yg: float, xb: float, yb: float, red_trc: Babl.Object, green_trc: Babl.Object, blue_trc: Babl.Object)

query the chromaticities of white point and primaries as well as trcs used for r g a nd b, all arguments are optional (can be None).

Babl.space_get_gamma(space)
Parameters:

space (Babl.Object) –

Return type:

float

Babl.space_get_icc(babl)
Parameters:

babl (Babl.Object) – a Babl.Object

Returns:

pointer to ICC profile data.

length:

Length of the profile in bytes.

Return type:

(str, length: int)

Return pointer to ICC profile for space note that this is the ICC profile for R’G’B’, though in formats only supporting linear like EXR GEGL chooses to load this lienar data as RGB and use the sRGB TRC.

Babl.space_get_rgb_luminance(space)
Parameters:

space (Babl.Object) – a BablSpace

Returns:

red_luminance:

Location for the red luminance factor.

green_luminance:

Location for the green luminance factor.

blue_luminance:

Location for the blue luminance factor.

Return type:

(red_luminance: float, green_luminance: float, blue_luminance: float)

Retrieve the relevant RGB luminance constants for a babl space.

Note: these luminance coefficients should only ever be used on linear data. If your input space is non-linear, you should convert your pixel values to the linearized variant of space before making any computation with these coefficients. See #83.

Babl.space_is_cmyk(space)
Parameters:

space (Babl.Object) –

Returns:

1 if space is CMYK, 0 otherwise.

Return type:

int

Babl.space_is_gray(space)
Parameters:

space (Babl.Object) –

Returns:

1 if space is grayscale, 0 otherwise.

Return type:

int

Babl.space_is_rgb(space)
Parameters:

space (Babl.Object) –

Returns:

1 if space is RGB, 0 otherwise.

Return type:

int

Babl.space_with_trc(space, trc)
Parameters:
Return type:

Babl.Object

Creates a variant of an existing space with different trc.

Babl.trc(name)
Parameters:

name (str) –

Return type:

Babl.Object

Look up a TRC by name, “sRGB” and “linear” are recognized strings in a stock babl configuration.

Babl.trc_gamma(gamma)
Parameters:

gamma (float) –

Return type:

Babl.Object

Creates a Babl.Object TRC for a specific gamma value, it will be given a name that is a short string representation of the value.

Babl.type(name)
Parameters:

name (str) –

Return type:

Babl.Object

Returns the babl object representing the data type given by name such as for example “u8”, “u16” or “float”.