interpolate - multiple declarations
Function interpolate
Blends two encoded sRGB values component by component.
Use this when encoded-sRGB interpolation itself is desired. Both endpoints
remain encoded sRGB. The factor is not clamped, so values
outside [0, 1] extrapolate. No linear-light conversion, clipping, gamut
mapping, or other display policy is applied.
Parameters
| Name | Description |
|---|---|
| first | First encoded-sRGB endpoint. |
| second | Second encoded-sRGB endpoint. |
| t | Interpolation factor. |
Returns
The component-wise interpolated encoded-sRGB value.
Example
import color .rgb : SRgbf;
const first = SRgbf(0.0f, 0.25f, 0.5f);
const second = SRgbf(1.0f, 0.75f, 1.0f);
const value = interpolate(first, second, 0.5f);
assert(value == SRgbf(0.5f, 0.5f, 0.75f));
Function interpolate
Blends two linear-light sRGB values component by component.
LinearSRgb!T interpolate(T)(
LinearSRgb!T first,
LinearSRgb!T second,
T t
) pure nothrow @nogc @safe;
Use this for interpolation in linear light. Both endpoints remain
linear-light sRGB. The factor is not clamped, so
values outside [0, 1] extrapolate. Extended-range values are preserved;
no encoding, clipping, or gamut mapping is applied.
Parameters
| Name | Description |
|---|---|
| first | First linear-light sRGB endpoint. |
| second | Second linear-light sRGB endpoint. |
| t | Interpolation factor. |
Returns
The component-wise interpolated linear-light sRGB value.
Example
import color .rgb : LinearSRgbf;
const first =
LinearSRgbf(-0.25f, 0.25f, 1.25f);
const second =
LinearSRgbf(1.25f, 0.75f, -0.25f);
const value = interpolate(first, second, 0.5f);
assert(value == LinearSRgbf(0.5f, 0.5f, 0.5f));
Function interpolate
Blends two colors in rectangular Oklab coordinates.
Use this when the transition should follow Oklab's lightness and opponent
axes directly. Lightness and both opponent coordinates are interpolated. The
factor is not clamped, so values outside [0, 1] extrapolate. No OKLCH
conversion, hue policy, clipping, or gamut mapping is applied.
Parameters
| Name | Description |
|---|---|
| first | First Oklab endpoint. |
| second | Second Oklab endpoint. |
| t | Interpolation factor. |
Returns
The component-wise interpolated Oklab value.
Example
import color .oklab : Oklabf;
const first =
Oklabf(0.25f, -0.25f, 0.5f);
const second =
Oklabf(0.75f, 0.25f, -0.5f);
const value = interpolate(first, second, 0.5f);
assert(value == Oklabf(0.5f, 0.0f, 0.0f));
Function interpolate
Blends two colors in OKLCH using an explicit route around the hue circle.
Use this for polar perceptual interpolation when hue trajectory matters.
Lightness and chroma are interpolated linearly; hue follows path.
Negative chroma is canonicalized before interpolation. When exactly one
canonicalized endpoint is achromatic, its interpolation hue is borrowed
from the chromatic endpoint. No hidden near-achromatic epsilon is used.
Parameters
| Name | Description |
|---|---|
| first | First OKLCH endpoint. |
| second | Second OKLCH endpoint. |
| t | Interpolation factor; values outside [0, 1] extrapolate. |
| path | Explicit angular hue path. |
Returns
The interpolated OKLCH value.
Standards
Hue-path semantics follow the W3C CSS Color Module Level 4 shorter/longer/increasing/decreasing angular policies.
See Also
HuePath
Example
import color .oklch :
OklabHued,
Oklchd;
const first = Oklchd(
0.25,
0.125,
OklabHued .fromDegrees(350.0)
);
const second = Oklchd(
0.75,
0.375,
OklabHued .fromDegrees(10.0)
);
const value = interpolate(
first,
second,
0.5,
HuePath .shorter
);
assert(value .l == 0.5);
assert(value .c == 0.25);
assert(value .h .rawDegrees == 360.0);
Function interpolate
Interpolates straight-alpha encoded sRGB using alpha-weighted coordinates.
RGB coordinates are multiplied by endpoint alpha before interpolation and divided by interpolated alpha when that alpha is nonzero. This weighting is interpolation mathematics in encoded-sRGB coordinates, not Porter-Duff compositing. At interpolated alpha zero, the weighted coordinates are retained.
Neither t nor alpha is clamped or validated. No color-space conversion,
clipping, or gamut mapping is applied.
Parameters
| Name | Description |
|---|---|
| first | First straight-alpha encoded-sRGB endpoint. |
| second | Second straight-alpha encoded-sRGB endpoint. |
| t | Interpolation factor. |
Returns
The alpha-aware interpolated encoded-sRGB value.
Example
import color .alpha : Alpha;
import color .rgb : SRgbd;
const value = interpolate(
Alpha!SRgbd(
SRgbd(1.0, 0.0, 0.0),
1.0
),
Alpha!SRgbd(
SRgbd(0.0, 0.0, 1.0),
0.0
),
0.5
);
assert(value .color == SRgbd(1.0, 0.0, 0.0));
assert(value .alpha == 0.5);
Function interpolate
Interpolates straight-alpha linear-light sRGB using alpha-weighted coordinates.
RGB coordinates are multiplied by endpoint alpha before interpolation and divided by interpolated alpha when that alpha is nonzero. At interpolated alpha zero, the weighted coordinates are retained rather than reconstructing hidden straight color.
Neither t nor alpha is clamped or validated. Extended-range coordinates
remain representable and no clipping or gamut mapping is applied.
Parameters
| Name | Description |
|---|---|
| first | First straight-alpha linear-light sRGB endpoint. |
| second | Second straight-alpha linear-light sRGB endpoint. |
| t | Interpolation factor. |
Returns
The alpha-aware interpolated linear-light sRGB value.
Example
import color .alpha : Alpha;
import color .rgb : LinearSRgbd;
const value = interpolate(
Alpha!LinearSRgbd(
LinearSRgbd(1.0, 0.0, 0.0),
1.0
),
Alpha!LinearSRgbd(
LinearSRgbd(0.0, 0.0, 1.0),
0.0
),
0.5
);
assert(value .color == LinearSRgbd(1.0, 0.0, 0.0));
assert(value .alpha == 0.5);
Function interpolate
Interpolates straight-alpha Oklab using alpha-weighted coordinates.
L, a, and b are multiplied by endpoint alpha before interpolation and
divided by interpolated alpha when that alpha is nonzero. At interpolated
alpha zero, the weighted coordinates are retained rather than reconstructing
hidden straight Oklab coordinates.
Neither t nor alpha is clamped or validated. No conversion, clipping, or
gamut mapping is applied.
Parameters
| Name | Description |
|---|---|
| first | First straight-alpha Oklab endpoint. |
| second | Second straight-alpha Oklab endpoint. |
| t | Interpolation factor. |
Returns
The alpha-aware interpolated Oklab value.
Example
import color .alpha : Alpha;
import color .oklab : Oklabd;
const value = interpolate(
Alpha!Oklabd(
Oklabd(0.25, 0.5, -0.5),
0.25
),
Alpha!Oklabd(
Oklabd(0.75, -0.5, 0.5),
0.75
),
0.5
);
assert(value .color == Oklabd(0.625, -0.25, 0.25));
assert(value .alpha == 0.5);
Function interpolate
Interpolates straight-alpha OKLCH using explicit polar hue semantics.
Lightness and chroma are alpha-weighted for interpolation; hue is not. Endpoint colors are canonicalized to non-negative chroma and exact achromatic hue borrowing follows the ordinary OKLCH interpolation rules. At interpolated alpha zero, hidden straight lightness/chroma cannot be reconstructed. No clipping, gamut mapping, or color-space conversion occurs.
Parameters
| Name | Description |
|---|---|
| first | First straight-alpha OKLCH endpoint. |
| second | Second straight-alpha OKLCH endpoint. |
| t | Interpolation factor. |
| path | Explicit angular hue path. |
Returns
The alpha-aware interpolated OKLCH value.
Standards
Hue-path and premultiplied interpolation semantics follow the W3C CSS Color Module Level 4 model adapted to color-d's explicit numeric types.
See Also
HuePath
Example
import color .alpha : Alpha;
import color .oklch :
OklabHued,
Oklchd;
const value = interpolate(
Alpha!Oklchd(
Oklchd(
0.4,
0.2,
OklabHued .fromDegrees(30.0)
),
0.0
),
Alpha!Oklchd(
Oklchd(
0.8,
0.2,
OklabHued .fromDegrees(210.0)
),
1.0
),
0.5,
HuePath .shorter
);
assert(value .color .l == 0.8);
assert(value .color .c == 0.2);
assert(value .color .h .rawDegrees == 120.0);
assert(value .alpha == 0.5);