Skip to content

color_conversion.py

rerun.color_conversion

Color conversion utilities.

def u8_array_to_rgba(arr)

Convert an array with inner dimension [R,G,B,A] into packed uint32 values.

Parameters:

Name Type Description Default
arr npt.NDArray[np.uint8]

Nx3 or Nx4 [[r,g,b,a], ... ] of uint8 values

required

Returns:

Type Description
npt.NDArray[np.uint32]

Array of uint32 value as 0xRRGGBBAA.

def linear_to_gamma_u8_value(linear)

Transform color values from linear [0.0, 1.0] to gamma encoded [0, 255].

Linear colors are expected to have dtype numpy.floating

Intended to implement the following per color value:

if l <= 0.0 {
    0
} else if l <= 0.0031308 {
    round(3294.6 * l)
} else if l <= 1.0 {
    round(269.025 * l.powf(1.0 / 2.4) - 14.025)
} else {
    255
}

Parameters:

Name Type Description Default
linear npt.NDArray[Union[np.float32, np.float64]]

The linear color values to transform.

required

Returns:

Type Description
np.ndarray[np.uint8]

The gamma encoded color values.

def linear_to_gamma_u8_pixel(linear)

Transform color pixels from linear [0, 1] to gamma encoded [0, 255].

Linear colors are expected to have dtype np.float32 or np.float64.

The last dimension of the colors array linear is expected to represent a single pixel color. - 3 colors means RGB - 4 colors means RGBA

Parameters:

Name Type Description Default
linear npt.NDArray[Union[np.float32, np.float64]]

The linear color pixels to transform.

required

Returns:

Type Description
np.ndarray[np.uint8]

The gamma encoded color pixels.