diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index a2bc5d40a6..adc7c68165 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -8,6 +8,9 @@ namespace ImageSharp.ColorSpaces using System; using System.ComponentModel; using System.Numerics; + using System.Runtime.CompilerServices; + + using ImageSharp.PixelFormats; /// /// Represents an RGB color with specified working space @@ -106,6 +109,22 @@ namespace ImageSharp.ColorSpaces /// public Vector3 Vector => this.backingVector; + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Rgb(Rgba32 color) + { + return new Rgb(color.R / 255F, color.G / 255F, color.B / 255F); + } + /// /// Compares two objects for equality. /// diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index d668be76fd..ff6c0bd2a5 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -9,6 +9,8 @@ namespace ImageSharp.PixelFormats using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using ImageSharp.ColorSpaces; + /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in red, green, blue, and alpha order. @@ -152,7 +154,30 @@ namespace ImageSharp.PixelFormats } /// - public uint PackedValue { get => this.Rgba; set => this.Rgba = value; } + public uint PackedValue + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => this.Rgba; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set => this.Rgba = value; + } + + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Rgba32(Rgb color) + { + return new Rgba32(color.R, color.G, color.B); + } /// /// Compares two objects for equality.