LinearColor class final

A colour in linear light, with straight (not premultiplied) alpha.

Linear, because light adds. Two lamps on a wall make the sum of their light, and that sum is only right in linear values; the sRGB numbers a colour picker shows are a curve over them, made for the eye and the display. So a light's colour, a material's albedo and a fog's tint are linear here, and the curve is applied once, at the end of the frame.

r, g and b are not clamped: above 1 is a colour brighter than white, which an emissive surface or an HDR light is. a is coverage, 0 (transparent) to 1 (opaque), and is the same in either space.

A caller holding sRGB values (a hex code, a picker) converts with LinearColor.fromSrgb; a Flutter Color converts in flutter3d, which is the package that knows Flutter.

Available extensions

Constructors

LinearColor(double r, double g, double b, [double a = 1])
A colour from linear components; a defaults to opaque.
const
LinearColor.fromSrgb(double r, double g, double b, [double a = 1])
A colour from sRGB-encoded components in 0..1, decoded with the exact sRGB transfer function (IEC 61966-2-1), the way a caller enters a colour a person picked. a is copied as it is.
factory

Properties

a → double
Coverage, 0 to 1.
final
b → double
Blue, in linear light.
final
g → double
Green, in linear light.
final
hashCode → int
The hash code for this object.
no setteroverride
r → double
Red, in linear light.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
scaled(double factor) → LinearColor
This colour with r, g and b multiplied by factor and a kept, for a caller turning an intensity up or down. In linear light that is exactly "twice as much light".
toColor() → Color

Available on LinearColor, provided by the LinearColorToFlutter extension

This colour as a Flutter Color, for a caller showing an engine colour in a widget.
toJson() → List<double>

Available on LinearColor, provided by the JsonLinearColorWriter extension

[r, g, b], and the coverage after them only when it is not opaque: what JsonObjectReader.linearColor reads back.
toSrgb() → SrgbColor
This colour encoded for display, for a caller showing it to a person (a swatch, a hex code). Each channel goes through the sRGB curve; one above 1 is encoded past 1 rather than clipped, so nothing is lost before the caller decides how to show it.
toString() → String
A string representation of this object.
override
toVector3() → Vector3

Available on LinearColor, provided by the LinearColorVector extension

Red, green and blue as a Vector3, for a caller filling a uniform that has no alpha.
toVector4() → Vector4

Available on LinearColor, provided by the LinearColorVector extension

Red, green, blue and alpha as a Vector4, for a caller filling a uniform or a clear colour.
withAlpha(double alpha) → LinearColor
This colour with its coverage replaced by alpha, for a caller fading something in or out.

Operators

operator ==(Object other) → bool
The equality operator.
override

Static Methods

lerp(LinearColor from, LinearColor to, double t) → LinearColor
The colour a fraction t of the way from from to to, every channel interpolated in linear light, for a caller blending between two.
linearToSrgb(double linear) → double
One linear channel encoded for display: the inverse of srgbToLinear, for a caller writing a colour out where a person reads it.
srgbToLinear(double encoded) → double
One sRGB-encoded channel decoded to linear light: the sRGB EOTF, with its linear toe below 0.04045. Negative input decodes as its mirror, so the curve is odd and a caller's out-of-gamut values survive a round trip.

Constants

black → const LinearColor
Black, opaque.
transparent → const LinearColor
Black with no coverage, which a caller uses for "nothing here".
white → const LinearColor
White, opaque: 1 in every channel.