Browse Source

Add implicit operator between Rgba32 and Rgb

pull/144/head
James Jackson-South 9 years ago
parent
commit
c45fb4bcf3
  1. 19
      src/ImageSharp/ColorSpaces/Rgb.cs
  2. 27
      src/ImageSharp/PixelFormats/Rgba32.cs

19
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;
/// <summary>
/// Represents an RGB color with specified <see cref="IRgbWorkingSpace"/> working space
@ -106,6 +109,22 @@ namespace ImageSharp.ColorSpaces
/// <inheritdoc />
public Vector3 Vector => this.backingVector;
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="Rgba32"/> to a
/// <see cref="Rgb"/>.
/// </summary>
/// <param name="color">
/// The instance of <see cref="Rgba32"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="Rgb"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Rgb(Rgba32 color)
{
return new Rgb(color.R / 255F, color.G / 255F, color.B / 255F);
}
/// <summary>
/// Compares two <see cref="Rgb"/> objects for equality.
/// </summary>

27
src/ImageSharp/PixelFormats/Rgba32.cs

@ -9,6 +9,8 @@ namespace ImageSharp.PixelFormats
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ImageSharp.ColorSpaces;
/// <summary>
/// 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
}
/// <inheritdoc/>
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;
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="Rgb"/> to a
/// <see cref="Rgba32"/>.
/// </summary>
/// <param name="color">
/// The instance of <see cref="Rgb"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="Rgba32"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Rgba32(Rgb color)
{
return new Rgba32(color.R, color.G, color.B);
}
/// <summary>
/// Compares two <see cref="Rgba32"/> objects for equality.

Loading…
Cancel
Save