# ColorMatrix

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/struct-colormatrix/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct ColorMatrix
```

A colour transform of the form `out = in * M`: `in` is the row
`[R, G, B, A, 1]` of a colour with straight (not premultiplied) alpha,
each channel from 0 to 1, and `M` has five rows of four columns.

Row `i` holds what input channel `i` (red, green, blue, alpha) adds to
each output channel (red, green, blue, alpha); the fifth row is the
offset of each output channel. This is the layout of the `Matrix5x4` of
WinUI (`M11` .. `M54`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L14)

## Members

- [`rows`](#struct_field-rows)
- [`IDENTITY`](#assoc_const-identity)
- [`new`](#function-new)
- [`from_matrix5x4`](#function-from_matrix5x4)
- [`saturation`](#function-saturation)
- [`luminance_to_alpha`](#function-luminance_to_alpha)
- [`tint`](#function-tint)
- [`invert`](#function-invert)
- [`grayscale`](#function-grayscale)
- [`sepia`](#function-sepia)
- [`lerp`](#function-lerp)
- [`scale_and_offset`](#function-scale_and_offset)
- [`is_identity`](#function-is_identity)
- [`then`](#function-then)
- [`apply`](#function-apply)
- [`apply_premultiplied`](#function-apply_premultiplied)
- [`apply_to_rgba8`](#function-apply_to_rgba8)
- [`apply_to_premultiplied_rgba8`](#function-apply_to_premultiplied_rgba8)
- [`to_row_major_4x5`](#function-to_row_major_4x5)

<a id="struct_field-rows"></a>

### rows

```rust
rows: [[f32; 4]; 5]
```

The rows: red, green, blue and alpha in, then the offsets.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L16)

<a id="assoc_const-identity"></a>

### IDENTITY

```rust
const IDENTITY: ColorMatrix
```

The matrix that changes nothing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L45)

<a id="function-new"></a>

### new

```rust
const fn new(rows: [[f32; 4]; 5]) -> ColorMatrix
```

A matrix from its rows.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L50)

<a id="function-from_matrix5x4"></a>

### from_matrix5x4

```rust
fn from_matrix5x4(m: [f32; 20]) -> ColorMatrix
```

A matrix from the twenty members of WinUI's `Matrix5x4`, in the order
`M11, M12, M13, M14, M21, ..., M54`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L56)

<a id="function-saturation"></a>

### saturation

```rust
fn saturation(saturation: f32) -> ColorMatrix
```

The saturation matrix of Win2D's `SaturationEffect` (the
`saturate` colour matrix of SVG): 0 is grey, 1 changes nothing,
values above 1 saturate more.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L67)

<a id="function-luminance_to_alpha"></a>

### luminance_to_alpha

```rust
fn luminance_to_alpha() -> ColorMatrix
```

Win2D's `LuminanceToAlphaEffect`: the luminance of the colour becomes
its alpha, the colour black.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L80)

<a id="function-tint"></a>

### tint

```rust
fn tint(tint: [f32; 4]) -> ColorMatrix
```

Win2D's `TintEffect`: each channel multiplied by the channel of
`tint` (red, green, blue, alpha from 0 to 1).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L87)

<a id="function-invert"></a>

### invert

```rust
fn invert() -> ColorMatrix
```

Win2D's `InvertEffect`: each colour channel `c` becomes `1 - c`; the
alpha is kept.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L99)

<a id="function-grayscale"></a>

### grayscale

```rust
fn grayscale() -> ColorMatrix
```

Win2D's `GrayscaleEffect`: each colour channel becomes
`0.299 R + 0.587 G + 0.114 B`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L111)

<a id="function-sepia"></a>

### sepia

```rust
fn sepia(intensity: f32) -> ColorMatrix
```

Win2D's `SepiaEffect`: the identity at intensity 0, the sepia
matrix (red `0.393 R + 0.769 G + 0.189 B`, green `0.349 R + 0.686 G
+ 0.168 B`, blue `0.272 R + 0.534 G + 0.131 B`) at 1, and the
interpolation of the two in between; the intensity is clamped to
0..1, the alpha kept.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L121)

<a id="function-lerp"></a>

### lerp

```rust
fn lerp(self: &Self, to: &ColorMatrix, t: f32) -> ColorMatrix
```

The matrix `self + (to - self) * t`, member by member.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L134)

<a id="function-scale_and_offset"></a>

### scale_and_offset

```rust
fn scale_and_offset(scale: [f32; 4], offset: [f32; 4]) -> ColorMatrix
```

The matrix that scales each channel and adds an offset:
`out = in * scale + offset`, channel by channel.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L146)

<a id="function-is_identity"></a>

### is_identity

```rust
fn is_identity(self: &Self) -> bool
```

Whether the matrix changes nothing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L156)

<a id="function-then"></a>

### then

```rust
fn then(self: &Self, next: &ColorMatrix) -> ColorMatrix
```

The matrix that applies `self`, then `next`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L161)

<a id="function-apply"></a>

### apply

```rust
fn apply(self: &Self, color: [f32; 4]) -> [f32; 4]
```

Applies the matrix to a colour with straight alpha, each channel from
0 to 1. The result is clamped to 0..1.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L177)

<a id="function-apply_premultiplied"></a>

### apply_premultiplied

```rust
fn apply_premultiplied(self: &Self, color: [f32; 4], mode: ColorMatrixAlphaMode) -> [f32; 4]
```

Applies the matrix to a premultiplied colour, each channel from 0 to
1, in `mode`; the result is premultiplied, clamped to 0..1, its colour
channels no larger than its alpha.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L190)

<a id="function-apply_to_rgba8"></a>

### apply_to_rgba8

```rust
fn apply_to_rgba8(self: &Self, pixels: &mut [u8], mode: ColorMatrixAlphaMode)
```

Applies the matrix in `mode` to premultiplied RGBA pixels of eight
bits a channel, in place.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L207)

<a id="function-apply_to_premultiplied_rgba8"></a>

### apply_to_premultiplied_rgba8

```rust
fn apply_to_premultiplied_rgba8(self: &Self, pixels: &mut [u8])
```

Applies the matrix to premultiplied RGBA pixels of eight bits a
channel, in place: each pixel is unpremultiplied, transformed and
premultiplied again (the straight alpha mode).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L223)

<a id="function-to_row_major_4x5"></a>

### to_row_major_4x5

```rust
fn to_row_major_4x5(self: &Self) -> [f32; 20]
```

The matrix in the row-major 4 x 5 form of Skia and SVG: a row per
output channel, its last column the offset.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/color_matrix.rs#L238)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
