Browse Source

Special case La32 and L16

pull/1801/head
James Jackson-South 5 years ago
parent
commit
90bab39397
  1. 22
      src/ImageSharp/Color/Color.Conversions.cs
  2. 8
      src/ImageSharp/Color/Color.cs

22
src/ImageSharp/Color/Color.Conversions.cs

@ -34,6 +34,28 @@ namespace SixLabors.ImageSharp
this.boxedHighPrecisionPixel = null; this.boxedHighPrecisionPixel = null;
} }
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="La32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(La32 pixel)
{
this.data = new Rgba64(pixel.L, pixel.L, pixel.L, pixel.A);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="L16"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(L16 pixel)
{
this.data = new Rgba64(pixel.PackedValue, pixel.PackedValue, pixel.PackedValue, ushort.MaxValue);
this.boxedHighPrecisionPixel = null;
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct. /// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary> /// </summary>

8
src/ImageSharp/Color/Color.cs

@ -117,6 +117,14 @@ namespace SixLabors.ImageSharp
{ {
return new((Rgb48)(object)pixel); return new((Rgb48)(object)pixel);
} }
else if (typeof(TPixel) == typeof(La32))
{
return new((La32)(object)pixel);
}
else if (typeof(TPixel) == typeof(L16))
{
return new((L16)(object)pixel);
}
else if (Unsafe.SizeOf<TPixel>() <= Unsafe.SizeOf<Rgba32>()) else if (Unsafe.SizeOf<TPixel>() <= Unsafe.SizeOf<Rgba32>())
{ {
Rgba32 p = default; Rgba32 p = default;

Loading…
Cancel
Save