|
3 | 3 |
|
4 | 4 | using System; |
5 | 5 | using osuTK.Graphics; |
| 6 | +using SixLabors.ImageSharp.PixelFormats; |
6 | 7 |
|
7 | 8 | namespace osu.Framework.Graphics.Colour |
8 | 9 | { |
9 | 10 | /// <summary> |
10 | | - /// Represents a <see cref="Color4"/> provided in premultiplied-alpha form. |
| 11 | + /// Represents a structure for containing a "premultiplied colour". |
11 | 12 | /// </summary> |
12 | 13 | public readonly struct PremultipliedColour : IEquatable<PremultipliedColour> |
13 | 14 | { |
14 | 15 | /// <summary> |
15 | | - /// The <see cref="Color4"/> after alpha multiplication. |
| 16 | + /// The red component of this colour multiplied by the value of <see cref="Occlusion"/>. |
16 | 17 | /// </summary> |
17 | | - public readonly Color4 Premultiplied; |
| 18 | + public readonly float PremultipliedR; |
18 | 19 |
|
19 | | - private PremultipliedColour(Color4 premultiplied) |
20 | | - { |
21 | | - Premultiplied = premultiplied; |
22 | | - } |
| 20 | + /// <summary> |
| 21 | + /// The green component of this colour multiplied by the value of <see cref="Occlusion"/>. |
| 22 | + /// </summary> |
| 23 | + public readonly float PremultipliedG; |
23 | 24 |
|
24 | 25 | /// <summary> |
25 | | - /// Creates a <see cref="PremultipliedColour"/> from a straight-alpha colour. |
| 26 | + /// The blue component of this colour multiplied by the value of <see cref="Occlusion"/>. |
26 | 27 | /// </summary> |
27 | | - /// <param name="colour">The straight-alpha colour.</param> |
28 | | - public static PremultipliedColour FromStraight(Color4 colour) |
| 28 | + public readonly float PremultipliedB; |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// The alpha component of this colour, often referred to as "occlusion" instead of "opacity" in the context of premultiplied colours. |
| 32 | + /// </summary> |
| 33 | + public readonly float Occlusion; |
| 34 | + |
| 35 | + public PremultipliedColour(float premultipliedR, float premultipliedG, float premultipliedB, float occlusion) |
29 | 36 | { |
30 | | - colour.R *= colour.A; |
31 | | - colour.G *= colour.A; |
32 | | - colour.B *= colour.A; |
33 | | - return new PremultipliedColour(colour); |
| 37 | + PremultipliedR = premultipliedR; |
| 38 | + PremultipliedG = premultipliedG; |
| 39 | + PremultipliedB = premultipliedB; |
| 40 | + Occlusion = occlusion; |
34 | 41 | } |
35 | 42 |
|
36 | 43 | /// <summary> |
37 | | - /// Creates a <see cref="PremultipliedColour"/> from a premultiplied-alpha colour. |
| 44 | + /// Creates a <see cref="Rgba32"/> containing the premultiplied components of this colour. |
38 | 45 | /// </summary> |
39 | | - /// <param name="colour">The premultiplied-alpha colour.</param> |
40 | | - public static PremultipliedColour FromPremultiplied(Color4 colour) => new PremultipliedColour(colour); |
| 46 | + public Rgba32 ToPremultipliedRgba32() => new Rgba32(PremultipliedR, PremultipliedG, PremultipliedB, Occlusion); |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Creates a <see cref="PremultipliedColour"/> from a straight-alpha colour. |
| 50 | + /// </summary> |
| 51 | + /// <param name="colour">The straight-alpha colour.</param> |
| 52 | + public static PremultipliedColour FromStraight(Color4 colour) => new PremultipliedColour( |
| 53 | + colour.R * colour.A, |
| 54 | + colour.G * colour.A, |
| 55 | + colour.B * colour.A, |
| 56 | + colour.A); |
41 | 57 |
|
42 | | - public bool Equals(PremultipliedColour other) => Premultiplied.Equals(other.Premultiplied); |
| 58 | + public bool Equals(PremultipliedColour other) |
| 59 | + => PremultipliedR == other.PremultipliedR && |
| 60 | + PremultipliedG == other.PremultipliedG && |
| 61 | + PremultipliedB == other.PremultipliedB && |
| 62 | + Occlusion == other.Occlusion; |
43 | 63 | } |
44 | 64 | } |
0 commit comments