Class ColorBlindnessSimulator
Simulates how a color appears to a viewer with a color vision deficiency, using the Vienot-Brettel-Mollon (1999) dichromacy matrices.
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public static class ColorBlindnessSimulator
Remarks
Run a palette through Simulate(Color, ColorBlindnessType) and measure the results with OklabDeltaE(Color, Color) to find pairs that collapse into each other for a given deficiency. Two status colors that read as clearly different to most players can become the same color under deuteranopia, which is the single most common accessibility defect in game interfaces.
Simulation happens in linear light: the input is linearized, the matrix is applied, the result is blended toward the original by the type's severity, and the output is encoded back to sRGB. Alpha passes through unchanged.
Methods
GetSimulationMatrix(ColorBlindnessType, out float)
Returns the linear-light simulation matrix and blend severity for a deficiency type.
Declaration
public static Matrix4x4 GetSimulationMatrix(ColorBlindnessType type, out float severity)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorBlindnessType | type | The deficiency to look up. |
| float | severity | Receives the blend weight in |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | The linear-light simulation matrix. |
Remarks
Matrix values are from Vienot, Brettel, and Mollon (1999). The anomalous trichromacy types share the matrix of their matching dichromacy type and differ only in severity, so the caller must apply the blend rather than assuming the matrix is already attenuated.
Normal and Achromatopsia both return the identity matrix at severity 1. Achromatopsia is not expressible as a matrix and is handled separately by Simulate(Color, ColorBlindnessType).
The matrix operates on linear-light RGB. Only the upper 3x3 block is meaningful; the fourth row and column come from the identity.
Simulate(ReadOnlySpan<Color>, Span<Color>, ColorBlindnessType)
Simulates a whole span of colors at once, writing the results into a destination span without allocating.
Declaration
public static void Simulate(ReadOnlySpan<Color> source, Span<Color> destination, ColorBlindnessType type)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<Color> | source | The colors to simulate. |
| Span<Color> | destination | Receives the simulated colors. Must be at least as long as
|
| ColorBlindnessType | type | The deficiency to simulate. |
Remarks
The simulation matrix is resolved once for the whole span rather than per color, which is what makes this the right entry point for transforming a palette or a theme's token table.
The two spans may refer to the same memory, since each element is read before it is written.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Simulate(Color, ColorBlindnessType)
Returns how the given color appears to a viewer with the given color vision deficiency.
Declaration
public static Color Simulate(Color color, ColorBlindnessType type)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color as a viewer with normal vision sees it. |
| ColorBlindnessType | type | The deficiency to simulate. |
Returns
| Type | Description |
|---|---|
| Color | The simulated color, with the original alpha. |
Remarks
Normal returns the input unchanged. Achromatopsia converts to luminance-only greyscale rather than applying a matrix, because no 3x3 matrix can express the rod-only response.