ColorManagement

Manages the working color space and conversions between color spaces.

Ported from three.js ColorManagement (created via createColorManagement()). Modelled as a Kotlin object so that ported three.js code keeps calling ColorManagement.convert(...) etc. verbatim. Like three.js, this holds mutable global state (enabled, workingColorSpace) and is not thread-safe.

The renderer-facing helpers (getToneMappingMode, _getDrawingBufferColorSpace, _getUnpackColorSpace, define, Display-P3 spaces) are omitted from the math port because the color-space definitions here do not carry the optional outputColorSpaceConfig/workingColorSpaceConfig; they belong to the (not yet ported) renderer layer.

Properties

Link copied to clipboard

Whether color management (automatic conversions) is enabled.

Link copied to clipboard

Implementations of supported color spaces, keyed by ColorSpace. Mirrors three.js's ColorManagement.spaces.

Link copied to clipboard

The working color space. Colors store their components in this space.

Functions

Link copied to clipboard
fun colorSpaceToWorking(color: Color, sourceColorSpace: ColorSpace): Color
Link copied to clipboard
fun convert(color: Color, sourceColorSpace: ColorSpace, targetColorSpace: ColorSpace): Color

Converts the given color from sourceColorSpace to targetColorSpace, mutating and returning it. Returns the color unchanged when color management is disabled, the spaces match, or either space is ColorSpace.NoColorSpace.

Link copied to clipboard

Registers (or overrides) the given colorSpaces into spaces. Corresponds to three.js's ColorManagement.define().

Link copied to clipboard
fun fromWorkingColorSpace(color: Color, targetColorSpace: ColorSpace): Color

Deprecated alias for workingToColorSpace (renamed in three.js r177).

Link copied to clipboard
fun getLuminanceCoefficients(target: Vector3, colorSpace: ColorSpace = workingColorSpace): Vector3

Writes the luminance coefficients of the given colorSpace into target.

Link copied to clipboard
fun getMatrix(targetMatrix: Matrix3, sourceColorSpace: ColorSpace, targetColorSpace: ColorSpace): Matrix3

Copies spaces[sourceColorSpace].toXYZ into targetMatrix and multiplies it by spaces[targetColorSpace].fromXYZ, producing the source->target RGB transform.

Link copied to clipboard

Returns the primaries (chromaticity coordinates) of the given colorSpace.

Link copied to clipboard

Returns the transfer function of the given colorSpace. Returns ColorTransfer.Linear for ColorSpace.NoColorSpace.

Link copied to clipboard
fun toWorkingColorSpace(color: Color, sourceColorSpace: ColorSpace): Color

Deprecated alias for colorSpaceToWorking (renamed in three.js r177).

Link copied to clipboard
fun workingToColorSpace(color: Color, targetColorSpace: ColorSpace): Color