color_conversion.py
rerun.color_conversion
Color conversion utilities.
def u8_array_to_rgba(arr)
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 |
NDArray[float32 | float64]
|
The linear color values to transform. |
required |
Returns:
Type | Description |
---|---|
ndarray[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 |
NDArray[float32 | float64]
|
The linear color pixels to transform. |
required |
Returns:
Type | Description |
---|---|
ndarray[uint8]
|
The gamma encoded color pixels. |