Skip to content

Color Space

color_space

Define and convert to common display color spaces.

Classes:

  • ColorSpace

    Store color space gamut data and provide CIE XYZ conversion matrices.

Functions:

Attributes:

COLOR_SPACES module-attribute

COLOR_SPACES = {
    "Rec. 709": ColorSpace(0.3127, 0.329, 0.64, 0.33, 0.3, 0.6, 0.15, 0.06),
    "Display P3": ColorSpace(0.3127, 0.329, 0.68, 0.32, 0.2651, 0.69, 0.15, 0.06),
    "Rec. 2020": ColorSpace(0.3127, 0.329, 0.708, 0.292, 0.17, 0.797, 0.131, 0.046),
    "ACES AP1": ColorSpace(0.32168, 0.33767, 0.713, 0.293, 0.165, 0.83, 0.128, 0.044),
    "ACES AP0": ColorSpace(0.32168, 0.33767, 0.7347, 0.2653, 0.0, 1.0, 0.0001, -0.077),
    "CIE XYZ": None,
    "DCI-P3": ColorSpace(0.314, 0.351, 0.68, 0.32, 0.2651, 0.69, 0.15, 0.06),
    "DCI-P3 D60": ColorSpace(0.32168, 0.33767, 0.68, 0.32, 0.2651, 0.69, 0.15, 0.06),
}

The Default output color spaces.

GAMMA_FUNCTIONS module-attribute

GAMMA_FUNCTIONS = {
    "Linear": lambda x: x,
    "Gamma 1.8": lambda x: x ** (1 / 1.8),
    "Gamma 2.0": lambda x: x ** (1 / 2.0),
    "Gamma 2.2": lambda x: x ** (1 / 2.2),
    "Gamma 2.4": lambda x: x ** (1 / 2.4),
    "Gamma 2.6": lambda x: x ** (1 / 2.6),
    "Rec. 709": rec_709_encoding,
    "sRGB": srgb_encoding,
    "HLG": hlg_encoding,
    "PQ": pq_encoding,
}

Different gamma functions for output encoding.

ColorSpace dataclass

ColorSpace(
    w_x: float,
    w_y: float,
    r_x: float,
    r_y: float,
    g_x: float,
    g_y: float,
    b_x: float,
    b_y: float,
)

Store color space gamut data and provide CIE XYZ conversion matrices.

hlg_encoding

hlg_encoding(x, peak=203)

HLG (Hybrid Log-Gamma) OETF as per ARIB STD-B67

pq_encoding

pq_encoding(x, peak=203)

PQ (SMPTE ST 2084) OETF

rec_709_encoding

rec_709_encoding(x)

The Rec. 709 OETF.

srgb_encoding

srgb_encoding(x)

The sRGB OETF.