cutcutcodec.core.classes.colorspace.Colorspace
- class cutcutcodec.core.classes.colorspace.Colorspace(space: str | Self, primaries: str | None = None, transfer: str | None = None)[source]
Structure to ensure color space consistency.
See
cutcutcodec.core.colorspacefor more details and explanations.Attributes
- color_primariesint
The ffmpeg primaries code.
- color_trcint
The ffmpeg transfere function.
- primariesstr or None
The tristimulus primaries colors name (gamut). All available values are the keys of
cutcutcodec.core.colorspace.cst.PRIMARIES, defined in the modulecutcutcodec.core.colorspace.cst.- spacestr
The main space name, one of « y’pbpr », « r’g’b” », « rgb », « xyz ». It is defined in
cutcutcodec.core.colorspace.cst.SYMBS.- symbolstuple[sympy.Symbol, sympy.Symbol, sympy.Symbol]
The sympy symbols used as input of the expression given by the methode
to.- transferstr or None
The non-linear transfer function name (gamma). All available values are the keys of
cutcutcodec.core.colorspace.cst.TRC, defined in the modulecutcutcodec.core.colorspace.cst.
Parse the colorspace.
Parameters
- spaceColorspace | str
The colorspace formatted as {name}[_{colorspace}], with name in « y’pbpr », « r’g’b” », « rgb », « xyz » (readonly). When several names are given, the first matching in alphabetic order is taken.
- primariesstr, optional
If supplied, this is given priority over
spacefor the gamut (read and write).- transferstr, optional
If supplied, this is given priority over
spacefor the gamma (read and write).
- property color_primaries: int
Return the ffmpeg code for the flag -color_primaries.
Examples
>>> from cutcutcodec.core.classes.colorspace import Colorspace >>> Colorspace("r'g'b'", "bt2020", "bt2020").color_primaries 9 >>>
- property color_trc: int
Return the ffmpeg code for the flag -color_trc.
Examples
>>> from cutcutcodec.core.classes.colorspace import Colorspace >>> Colorspace("r'g'b'", "bt2020", "bt2020").color_trc 1 >>>
- classmethod from_default_target() Self[source]
Create the default y’pbpr working colorspace.
The default primaries and transfer are taken from the attributes
target_primandtarget_trcof the classcutcutcodec.config.config.Config.The default value can be overwitten in the file ~/.config/cutcutcodec/conf.ini
Examples
>>> from cutcutcodec.core.classes.colorspace import Colorspace >>> Colorspace.from_default_target() Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') >>>
- classmethod from_default_target_rgb() Self[source]
Construct same as
from_default_targetin r’g’b” space.
- classmethod from_default_working() Self[source]
Create the default rgb working colorspace.
The default primaries is taken from the attribute
working_primof the classcutcutcodec.config.config.Config.The default value can be overwitten in the file ~/.config/cutcutcodec/conf.ini
Examples
>>> from cutcutcodec.core.classes.colorspace import Colorspace >>> Colorspace.from_default_working() Colorspace('rgb', 'bt709') >>>
- to_equation(dst: Self | str) tuple[Basic, Basic, Basic][source]
Find the symbolic expressions of the colorspace conversion.
Attributes
- dstColorspace or str
The target colorspace, transmitted to
cutcutcodec.core.colorspace.func.convert().
Returns
- channel_1, channel_2, channel_3sympy.core.basic.Basic
Symbolic expressions for each channel.
- to_function(dst: Self | str) callable[source]
Compile the colorspace conversion function.
Attributes
- dstColorspace or str
The target colorspace, transmitted to
cutcutcodec.core.colorspace.func.convert().
Returns
- funccallable
The function that eats 3 channels in source space and sends them back to target space.
Examples
>>> import torch >>> from cutcutcodec.core.classes.colorspace import Colorspace >>> src, dst = Colorspace("rgb", "smpte240m"), Colorspace("y'pbpr", "bt709", "gamma22") >>> func = src.to_function(dst) >>> r, g, b = torch.rand(1080, 1920), torch.rand(1080, 1920), torch.rand(1080, 1920) >>> y, u, v = func(r=r, g=g, b=b) >>>