Browse Source

Merge pull request #180 from JimBobSquarePants/cleanup-color

Cleanup color
af/merge-core
James Jackson-South 9 years ago
committed by GitHub
parent
commit
710257576d
  1. 36
      src/ImageSharp/Colors/Color.Transforms.cs
  2. 96
      src/ImageSharp/Colors/Color.cs
  3. 2
      src/ImageSharp/Colors/ColorVector.Definitions.cs
  4. 5
      src/ImageSharp/Colors/ColorVector.Transforms.cs
  5. 6
      src/ImageSharp/Colors/ColorVector.cs
  6. 2
      src/ImageSharp/Colors/ColorspaceTransforms.cs
  7. 46
      src/ImageSharp/Colors/PackedPixel/Argb32.cs
  8. 2
      src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs
  9. 398
      src/ImageSharp/Colors/PackedPixel/Rgba32.cs
  10. 2
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
  11. 2
      tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs
  12. 8
      tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs
  13. 12
      tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs
  14. 4
      tests/ImageSharp.Tests/Colors/ColorPackingTests.cs
  15. 2
      tests/ImageSharp.Tests/Colors/ColorTests.cs
  16. 48
      tests/ImageSharp.Tests/Colors/PackedPixelTests.cs
  17. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  18. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  19. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs
  20. 5
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  21. 2
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs
  22. 2
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
  23. 6
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
  24. 4
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs
  25. 3
      tests/ImageSharp.Tests/xunit.runner.json

36
src/ImageSharp/Colors/Color.Transforms.cs

@ -6,9 +6,10 @@
namespace ImageSharp
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// 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.
/// </summary>
/// <remarks>
@ -25,10 +26,11 @@ namespace ImageSharp
/// <returns>
/// The <see cref="Color"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color operator +(Color left, Color right)
{
Vector4 add = left.ToVector4() + right.ToVector4();
return Pack(ref add);
return PackNew(ref add);
}
/// <summary>
@ -39,10 +41,11 @@ namespace ImageSharp
/// <returns>
/// The <see cref="Color"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color operator -(Color left, Color right)
{
Vector4 sub = left.ToVector4() - right.ToVector4();
return Pack(ref sub);
return PackNew(ref sub);
}
/// <summary>
@ -56,7 +59,7 @@ namespace ImageSharp
public static Color Normal(Color backdrop, Color source)
{
Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4());
return Pack(ref normal);
return PackNew(ref normal);
}
/// <summary>
@ -76,7 +79,7 @@ namespace ImageSharp
public static Color Multiply(Color backdrop, Color source)
{
Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4());
return Pack(ref multiply);
return PackNew(ref multiply);
}
/// <summary>
@ -95,7 +98,7 @@ namespace ImageSharp
public static Color Screen(Color backdrop, Color source)
{
Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4());
return Pack(ref subtract);
return PackNew(ref subtract);
}
/// <summary>
@ -110,7 +113,7 @@ namespace ImageSharp
public static Color HardLight(Color backdrop, Color source)
{
Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4());
return Pack(ref hardlight);
return PackNew(ref hardlight);
}
/// <summary>
@ -129,7 +132,7 @@ namespace ImageSharp
public static Color Overlay(Color backdrop, Color source)
{
Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4());
return Pack(ref overlay);
return PackNew(ref overlay);
}
/// <summary>
@ -144,7 +147,7 @@ namespace ImageSharp
public static Color Darken(Color backdrop, Color source)
{
Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4());
return Pack(ref darken);
return PackNew(ref darken);
}
/// <summary>
@ -159,7 +162,7 @@ namespace ImageSharp
public static Color Lighten(Color backdrop, Color source)
{
Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4());
return Pack(ref lighten);
return PackNew(ref lighten);
}
/// <summary>
@ -174,7 +177,7 @@ namespace ImageSharp
public static Color SoftLight(Color backdrop, Color source)
{
Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4());
return Pack(ref softlight);
return PackNew(ref softlight);
}
/// <summary>
@ -188,7 +191,7 @@ namespace ImageSharp
public static Color ColorDodge(Color backdrop, Color source)
{
Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4());
return Pack(ref dodge);
return PackNew(ref dodge);
}
/// <summary>
@ -202,7 +205,7 @@ namespace ImageSharp
public static Color ColorBurn(Color backdrop, Color source)
{
Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4());
return Pack(ref burn);
return PackNew(ref burn);
}
/// <summary>
@ -217,7 +220,7 @@ namespace ImageSharp
public static Color Difference(Color backdrop, Color source)
{
Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4());
return Pack(ref difference);
return PackNew(ref difference);
}
/// <summary>
@ -232,7 +235,7 @@ namespace ImageSharp
public static Color Exclusion(Color backdrop, Color source)
{
Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4());
return Pack(ref exclusion);
return PackNew(ref exclusion);
}
/// <summary>
@ -249,7 +252,8 @@ namespace ImageSharp
/// </returns>
public static Color Lerp(Color from, Color to, float amount)
{
return new Color(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount));
Vector4 lerp = Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount);
return PackNew(ref lerp);
}
}
}

96
src/ImageSharp/Colors/Color.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using System.Runtime.InteropServices;
/// <summary>
/// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// 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.
/// </summary>
/// <remarks>
@ -18,7 +18,7 @@ namespace ImageSharp
/// as it avoids the need to create new values for modification operations.
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
public partial struct Color : IPixel<Color>
public partial struct Color : IPixel<Color>, IPackedVector<uint>
{
/// <summary>
/// Gets or sets the red component.
@ -44,6 +44,12 @@ namespace ImageSharp
[FieldOffset(3)]
public byte A;
/// <summary>
/// The packed representation of the value.
/// </summary>
[FieldOffset(0)]
public uint Rgba;
/// <summary>
/// The shift count for the red component
/// </summary>
@ -81,6 +87,7 @@ namespace ImageSharp
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(byte r, byte g, byte b, byte a = 255)
: this()
{
@ -97,10 +104,11 @@ namespace ImageSharp
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(float r, float g, float b, float a = 1)
: this()
{
this = Pack(r, g, b, a);
this.Pack(r, g, b, a);
}
/// <summary>
@ -109,10 +117,11 @@ namespace ImageSharp
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(Vector3 vector)
: this()
{
this = Pack(ref vector);
this.Pack(ref vector);
}
/// <summary>
@ -121,12 +130,29 @@ namespace ImageSharp
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(Vector4 vector)
: this()
{
this = Pack(ref vector);
this = PackNew(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="packed">
/// The packed value.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(uint packed)
: this()
{
this.Rgba = packed;
}
/// <inheritdoc/>
public uint PackedValue { get => this.Rgba; set => this.Rgba = value; }
/// <summary>
/// Compares two <see cref="Color"/> objects for equality.
/// </summary>
@ -142,10 +168,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Color left, Color right)
{
return left.R == right.R
&& left.G == right.G
&& left.B == right.B
&& left.A == right.A;
return left.Rgba == right.Rgba;
}
/// <summary>
@ -159,10 +182,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Color left, Color right)
{
return left.R != right.R
&& left.G != right.G
&& left.B != right.B
&& left.A != right.A;
return left.Rgba != right.Rgba;
}
/// <summary>
@ -245,7 +265,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromVector4(Vector4 vector)
{
this = Pack(ref vector);
this.Pack(ref vector);
}
/// <inheritdoc/>
@ -265,10 +285,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Color other)
{
return this.R == other.R
&& this.G == other.G
&& this.B == other.B
&& this.A == other.A;
return this.Rgba == other.Rgba;
}
/// <summary>
@ -308,12 +325,12 @@ namespace ImageSharp
}
/// <summary>
/// Packs a <see cref="Vector4"/> into a uint.
/// Packs a <see cref="Vector4"/> into a color returning a new instance as a result.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="Color"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Color Pack(ref Vector4 vector)
private static Color PackNew(ref Vector4 vector)
{
vector *= MaxBytes;
vector += Half;
@ -322,31 +339,46 @@ namespace ImageSharp
return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W);
}
/// <summary>
/// Packs the four floats into a color.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Pack(float x, float y, float z, float w)
{
Vector4 value = new Vector4(x, y, z, w);
this.Pack(ref value);
}
/// <summary>
/// Packs a <see cref="Vector3"/> into a uint.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="Color"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Color Pack(ref Vector3 vector)
private void Pack(ref Vector3 vector)
{
Vector4 value = new Vector4(vector, 1);
return Pack(ref value);
this.Pack(ref value);
}
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// Packs a <see cref="Vector4"/> into a color.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="Color"/></returns>
/// <param name="vector">The vector containing the values to pack.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Color Pack(float x, float y, float z, float w)
private void Pack(ref Vector4 vector)
{
Vector4 value = new Vector4(x, y, z, w);
return Pack(ref value);
vector *= MaxBytes;
vector += Half;
vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
this.R = (byte)vector.X;
this.G = (byte)vector.Y;
this.B = (byte)vector.Z;
this.A = (byte)vector.W;
}
}
}

2
src/ImageSharp/Colors/ColorVector.Definitions.cs

@ -6,7 +6,7 @@
namespace ImageSharp
{
/// <summary>
/// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>

5
src/ImageSharp/Colors/ColorVector.Transforms.cs

@ -6,9 +6,10 @@
namespace ImageSharp
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
/// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
@ -25,6 +26,7 @@ namespace ImageSharp
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorVector operator +(ColorVector left, ColorVector right)
{
return new ColorVector(left.backingVector + right.backingVector);
@ -38,6 +40,7 @@ namespace ImageSharp
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorVector operator -(ColorVector left, ColorVector right)
{
return new ColorVector(left.backingVector - right.backingVector);

6
src/ImageSharp/Colors/ColorVector.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using System.Runtime.CompilerServices;
/// <summary>
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
/// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
@ -40,6 +40,7 @@ namespace ImageSharp
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(byte r, byte g, byte b, byte a = 255)
: this()
{
@ -53,6 +54,7 @@ namespace ImageSharp
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(float r, float g, float b, float a = 1)
: this()
{
@ -65,6 +67,7 @@ namespace ImageSharp
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(Vector3 vector)
: this()
{
@ -77,6 +80,7 @@ namespace ImageSharp
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(Vector4 vector)
: this()
{

2
src/ImageSharp/Colors/ColorspaceTransforms.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Colors.Spaces;
/// <summary>
/// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// 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.
/// </summary>
/// <remarks>

46
src/ImageSharp/Colors/PackedPixel/Argb.cs → src/ImageSharp/Colors/PackedPixel/Argb32.cs

@ -1,4 +1,4 @@
// <copyright file="Argb.cs" company="James Jackson-South">
// <copyright file="Argb32.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -17,7 +17,7 @@ namespace ImageSharp
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
public struct Argb : IPixel<Argb>, IPackedVector<uint>
public struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
{
/// <summary>
/// The shift count for the blue component
@ -50,58 +50,58 @@ namespace ImageSharp
private static readonly Vector4 Half = new Vector4(0.5F);
/// <summary>
/// Initializes a new instance of the <see cref="Argb"/> struct.
/// Initializes a new instance of the <see cref="Argb32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Argb(byte r, byte g, byte b, byte a = 255)
public Argb32(byte r, byte g, byte b, byte a = 255)
{
this.PackedValue = Pack(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="Argb"/> struct.
/// Initializes a new instance of the <see cref="Argb32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Argb(float r, float g, float b, float a = 1)
public Argb32(float r, float g, float b, float a = 1)
{
this.PackedValue = Pack(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="Argb"/> struct.
/// Initializes a new instance of the <see cref="Argb32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public Argb(Vector3 vector)
public Argb32(Vector3 vector)
{
this.PackedValue = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Argb"/> struct.
/// Initializes a new instance of the <see cref="Argb32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public Argb(Vector4 vector)
public Argb32(Vector4 vector)
{
this.PackedValue = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Argb"/> struct.
/// Initializes a new instance of the <see cref="Argb32"/> struct.
/// </summary>
/// <param name="packed">
/// The packed value.
/// </param>
public Argb(uint packed = 0)
public Argb32(uint packed = 0)
{
this.PackedValue = packed;
}
@ -182,33 +182,33 @@ namespace ImageSharp
}
/// <summary>
/// Compares two <see cref="Argb"/> objects for equality.
/// Compares two <see cref="Argb32"/> objects for equality.
/// </summary>
/// <param name="left">
/// The <see cref="Argb"/> on the left side of the operand.
/// The <see cref="Argb32"/> on the left side of the operand.
/// </param>
/// <param name="right">
/// The <see cref="Argb"/> on the right side of the operand.
/// The <see cref="Argb32"/> on the right side of the operand.
/// </param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Argb left, Argb right)
public static bool operator ==(Argb32 left, Argb32 right)
{
return left.PackedValue == right.PackedValue;
}
/// <summary>
/// Compares two <see cref="Argb"/> objects for equality.
/// Compares two <see cref="Argb32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Argb"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Argb"/> on the right side of the operand.</param>
/// <param name="left">The <see cref="Argb32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Argb32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Argb left, Argb right)
public static bool operator !=(Argb32 left, Argb32 right)
{
return left.PackedValue != right.PackedValue;
}
@ -221,7 +221,7 @@ namespace ImageSharp
}
/// <inheritdoc />
public BulkPixelOperations<Argb> CreateBulkOperations() => new BulkPixelOperations<Argb>();
public BulkPixelOperations<Argb32> CreateBulkOperations() => new BulkPixelOperations<Argb32>();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -278,12 +278,12 @@ namespace ImageSharp
/// <inheritdoc/>
public override bool Equals(object obj)
{
return obj is Argb && this.Equals((Argb)obj);
return obj is Argb32 && this.Equals((Argb32)obj);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Argb other)
public bool Equals(Argb32 other)
{
return this.PackedValue == other.PackedValue;
}

2
src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs

@ -300,7 +300,7 @@ namespace ImageSharp
private static bool IsStandardNormalizedType(Type type)
{
return type == typeof(Color)
|| type == typeof(Argb)
|| type == typeof(Argb32)
|| type == typeof(Alpha8)
|| type == typeof(Bgr565)
|| type == typeof(Bgra4444)

398
src/ImageSharp/Colors/PackedPixel/Rgba32.cs

@ -1,398 +0,0 @@
// <copyright file="Rgba32.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <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.
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
public struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
{
/// <summary>
/// The shift count for the red component
/// </summary>
private const int RedShift = 0;
/// <summary>
/// The shift count for the green component
/// </summary>
private const int GreenShift = 8;
/// <summary>
/// The shift count for the blue component
/// </summary>
private const int BlueShift = 16;
/// <summary>
/// The shift count for the alpha component
/// </summary>
private const int AlphaShift = 24;
/// <summary>
/// The maximum byte value.
/// </summary>
private static readonly Vector4 MaxBytes = new Vector4(255);
/// <summary>
/// The half vector value.
/// </summary>
private static readonly Vector4 Half = new Vector4(0.5F);
/// <summary>
/// The packed value.
/// </summary>
private uint packedValue;
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Rgba32(byte r, byte g, byte b, byte a = 255)
{
this.packedValue = Pack(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Rgba32(float r, float g, float b, float a = 1)
{
this.packedValue = Pack(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public Rgba32(Vector3 vector)
{
this.packedValue = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public Rgba32(Vector4 vector)
{
this.packedValue = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="packed">
/// The packed value.
/// </param>
public Rgba32(uint packed)
{
this.packedValue = packed;
}
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> RedShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift;
}
}
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> GreenShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift;
}
}
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> BlueShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift;
}
}
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public byte A
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> AlphaShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift;
}
}
/// <inheritdoc/>
public uint PackedValue
{
get => this.packedValue;
set => this.packedValue = value;
}
/// <summary>
/// Compares two <see cref="Rgba32"/> objects for equality.
/// </summary>
/// <param name="left">
/// The <see cref="Rgba32"/> on the left side of the operand.
/// </param>
/// <param name="right">
/// The <see cref="Rgba32"/> on the right side of the operand.
/// </param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Rgba32 left, Rgba32 right)
{
return left.packedValue == right.packedValue;
}
/// <summary>
/// Compares two <see cref="Rgba32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Rgba32 left, Rgba32 right)
{
return left.packedValue != right.packedValue;
}
/// <summary>
/// Creates a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="hex">
/// The hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param>
/// <returns>
/// The <see cref="Rgba32"/>.
/// </returns>
public static Rgba32 FromHex(string hex)
{
return ColorBuilder<Rgba32>.FromHex(hex);
}
/// <inheritdoc />
public BulkPixelOperations<Rgba32> CreateBulkOperations() => new BulkPixelOperations<Rgba32>();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromBytes(byte x, byte y, byte z, byte w)
{
this.packedValue = Pack(x, y, z, w);
}
/// <summary>
/// Converts the value of this instance to a hexadecimal string.
/// </summary>
/// <returns>A hexadecimal string representation of the value.</returns>
public string ToHex()
{
uint hexOrder = Pack(this.A, this.B, this.G, this.R);
return hexOrder.ToString("X8");
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToXyzBytes(byte[] bytes, int startIndex)
{
bytes[startIndex] = this.R;
bytes[startIndex + 1] = this.G;
bytes[startIndex + 2] = this.B;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToXyzwBytes(byte[] bytes, int startIndex)
{
bytes[startIndex] = this.R;
bytes[startIndex + 1] = this.G;
bytes[startIndex + 2] = this.B;
bytes[startIndex + 3] = this.A;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToZyxBytes(byte[] bytes, int startIndex)
{
bytes[startIndex] = this.B;
bytes[startIndex + 1] = this.G;
bytes[startIndex + 2] = this.R;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToZyxwBytes(byte[] bytes, int startIndex)
{
bytes[startIndex] = this.B;
bytes[startIndex + 1] = this.G;
bytes[startIndex + 2] = this.R;
bytes[startIndex + 3] = this.A;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromVector4(Vector4 vector)
{
this.packedValue = Pack(ref vector);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4 ToVector4()
{
return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
return (obj is Rgba32) && this.Equals((Rgba32)obj);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Rgba32 other)
{
return this.packedValue == other.packedValue;
}
/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override string ToString()
{
return this.ToVector4().ToString();
}
/// <inheritdoc/>
public override int GetHashCode()
{
return this.packedValue.GetHashCode();
}
/// <summary>
/// Packs a <see cref="Vector4"/> into a uint.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="uint"/> containing the packed values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(ref Vector4 vector)
{
vector *= MaxBytes;
vector += Half;
vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
return (uint)(((byte)vector.X << RedShift)
| ((byte)vector.Y << GreenShift)
| ((byte)vector.Z << BlueShift)
| (byte)vector.W << AlphaShift);
}
/// <summary>
/// Packs a <see cref="Vector3"/> into a uint.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="uint"/> containing the packed values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(ref Vector3 vector)
{
Vector4 value = new Vector4(vector, 1);
return Pack(ref value);
}
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(float x, float y, float z, float w)
{
Vector4 value = new Vector4(x, y, z, w);
return Pack(ref value);
}
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(byte x, byte y, byte z, byte w)
{
return (uint)(x << RedShift | y << GreenShift | z << BlueShift | w << AlphaShift);
}
}
}

2
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs

@ -64,7 +64,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk
{
}
public class ToXyzw_Argb : ToXyzw<Argb>
public class ToXyzw_Argb : ToXyzw<Argb32>
{
}
}

2
tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs

@ -58,7 +58,7 @@ namespace ImageSharp.Tests.Colors
}
}
public class Argb : BulkPixelOperationsTests<ImageSharp.Argb>
public class Argb : BulkPixelOperationsTests<ImageSharp.Argb32>
{
// For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class:
public Argb(ITestOutputHelper output)

8
tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs

@ -30,7 +30,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
yield return new object[] { new Argb(vector4), vector4Components };
yield return new object[] { new Argb32(vector4), vector4Components };
yield return new object[] { new Bgra4444(vector4), vector4Components };
yield return new object[] { new Bgra5551(vector4), vector4Components };
yield return new object[] { new Byte4(vector4), vector4Components };
@ -63,7 +63,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
yield return new object[] { new Argb(vector3), vector4Components };
yield return new object[] { new Argb32(vector3), vector4Components };
yield return new object[] { new Bgr565(vector3), vector4Components };
}
}
@ -88,7 +88,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
yield return new object[] { new Argb(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Argb32(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Bgra4444(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Bgra5551(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Byte4(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
@ -121,7 +121,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
yield return new object[] { new Argb(vector3.X, vector3.Y, vector3.Z), vector4Components };
yield return new object[] { new Argb32(vector3.X, vector3.Y, vector3.Z), vector4Components };
yield return new object[] { new Bgr565(vector3.X, vector3.Y, vector3.Z), vector4Components };
}
}

12
tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs

@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Colors
new TheoryData<object, object, Type>()
{
{ new Alpha8(.5F), new Alpha8(.5F), typeof(Alpha8) },
{ new Argb(Vector4.One), new Argb(Vector4.One), typeof(Argb) },
{ new Argb32(Vector4.One), new Argb32(Vector4.One), typeof(Argb32) },
{ new Bgr565(Vector3.One), new Bgr565(Vector3.One), typeof(Bgr565) },
{ new Bgra4444(Vector4.One), new Bgra4444(Vector4.One), typeof(Bgra4444) },
{ new Bgra5551(Vector4.One), new Bgra5551(Vector4.One), typeof(Bgra5551) },
@ -33,7 +33,7 @@ namespace ImageSharp.Tests.Colors
{ new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.One), typeof(NormalizedShort4) },
{ new Rg32(Vector2.One), new Rg32(Vector2.One), typeof(Rg32) },
{ new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.One), typeof(Rgba1010102) },
{ new Rgba32(Vector4.One), new Rgba32(Vector4.One), typeof(Rgba32) },
{ new Color(Vector4.One), new Color(Vector4.One), typeof(Color) },
{ new Rgba64(Vector4.One), new Rgba64(Vector4.One), typeof(Rgba64) },
{ new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.One * 0x7FFF), typeof(Short2) },
{ new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.One * 0x7FFF), typeof(Short4) },
@ -76,7 +76,7 @@ namespace ImageSharp.Tests.Colors
{
// Valid object against null
{ new Alpha8(.5F), null, typeof(Alpha8) },
{ new Argb(Vector4.One), null, typeof(Argb) },
{ new Argb32(Vector4.One), null, typeof(Argb32) },
{ new Bgr565(Vector3.One), null, typeof(Bgr565) },
{ new Bgra4444(Vector4.One), null, typeof(Bgra4444) },
{ new Bgra5551(Vector4.One), null, typeof(Bgra5551) },
@ -111,7 +111,7 @@ namespace ImageSharp.Tests.Colors
new TheoryData<object, object, Type>()
{
// Valid objects of different types but not equal
{ new Alpha8(.5F), new Argb(Vector4.Zero), null },
{ new Alpha8(.5F), new Argb32(Vector4.Zero), null },
{ new HalfSingle(-1F), new NormalizedShort2(Vector2.Zero), null },
{ new Rgba1010102(Vector4.One), new Bgra5551(Vector4.Zero), null },
};
@ -131,7 +131,7 @@ namespace ImageSharp.Tests.Colors
{
// Valid objects of the same type but not equal
{ new Alpha8(.5F), new Alpha8(.8F), typeof(Alpha8) },
{ new Argb(Vector4.One), new Argb(Vector4.Zero), typeof(Argb) },
{ new Argb32(Vector4.One), new Argb32(Vector4.Zero), typeof(Argb32) },
{ new Bgr565(Vector3.One), new Bgr565(Vector3.Zero), typeof(Bgr565) },
{ new Bgra4444(Vector4.One), new Bgra4444(Vector4.Zero), typeof(Bgra4444) },
{ new Bgra5551(Vector4.One), new Bgra5551(Vector4.Zero), typeof(Bgra5551) },
@ -145,7 +145,7 @@ namespace ImageSharp.Tests.Colors
{ new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.Zero), typeof(NormalizedShort4) },
{ new Rg32(Vector2.One), new Rg32(Vector2.Zero), typeof(Rg32) },
{ new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.Zero), typeof(Rgba1010102) },
{ new Rgba32(Vector4.One), new Rgba32(Vector4.Zero), typeof(Rgba32) },
{ new Color(Vector4.One), new Color(Vector4.Zero), typeof(Color) },
{ new Rgba64(Vector4.One), new Rgba64(Vector4.Zero), typeof(Rgba64) },
{ new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.Zero), typeof(Short2) },
{ new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.Zero), typeof(Short4) },

4
tests/ImageSharp.Tests/Colors/ColorPackingTests.cs

@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Colors
{
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
yield return new object[] { new Argb(), vector4Components };
yield return new object[] { new Argb32(), vector4Components };
yield return new object[] { new Bgra4444(), vector4Components };
yield return new object[] { new Bgra5551(), vector4Components };
yield return new object[] { new Byte4(), vector4Components };
@ -60,7 +60,7 @@ namespace ImageSharp.Tests.Colors
{
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
yield return new object[] { new Argb(), vector4Components };
yield return new object[] { new Argb32(), vector4Components };
yield return new object[] { new Bgr565(), vector4Components };
}
}

2
tests/ImageSharp.Tests/Colors/ColorTests.cs

@ -124,6 +124,8 @@ namespace ImageSharp.Tests
Assert.Equal(2, colorBase[1]);
Assert.Equal(3, colorBase[2]);
Assert.Equal(4, colorBase[3]);
Assert.Equal(4, sizeof(Color));
}
}
}

48
tests/ImageSharp.Tests/Colors/PackedPixelTests.cs

@ -62,29 +62,29 @@ namespace ImageSharp.Tests.Colors
}
[Fact]
public void Argb()
public void Argb32()
{
// Test the limits.
Assert.Equal((uint)0x0, new Argb(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFFFFFF, new Argb(Vector4.One).PackedValue);
Assert.Equal((uint)0x0, new Argb32(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFFFFFF, new Argb32(Vector4.One).PackedValue);
// Test ToVector4.
Assert.True(Equal(Vector4.One, new Argb(Vector4.One).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Argb(Vector4.Zero).ToVector4()));
Assert.True(Equal(Vector4.UnitX, new Argb(Vector4.UnitX).ToVector4()));
Assert.True(Equal(Vector4.UnitY, new Argb(Vector4.UnitY).ToVector4()));
Assert.True(Equal(Vector4.UnitZ, new Argb(Vector4.UnitZ).ToVector4()));
Assert.True(Equal(Vector4.UnitW, new Argb(Vector4.UnitW).ToVector4()));
Assert.True(Equal(Vector4.One, new Argb32(Vector4.One).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Argb32(Vector4.Zero).ToVector4()));
Assert.True(Equal(Vector4.UnitX, new Argb32(Vector4.UnitX).ToVector4()));
Assert.True(Equal(Vector4.UnitY, new Argb32(Vector4.UnitY).ToVector4()));
Assert.True(Equal(Vector4.UnitZ, new Argb32(Vector4.UnitZ).ToVector4()));
Assert.True(Equal(Vector4.UnitW, new Argb32(Vector4.UnitW).ToVector4()));
// Test clamping.
Assert.True(Equal(Vector4.Zero, new Argb(Vector4.One * -1234.0f).ToVector4()));
Assert.True(Equal(Vector4.One, new Argb(Vector4.One * +1234.0f).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Argb32(Vector4.One * -1234.0f).ToVector4()));
Assert.True(Equal(Vector4.One, new Argb32(Vector4.One * +1234.0f).ToVector4()));
float x = +0.1f;
float y = -0.3f;
float z = +0.5f;
float w = -0.7f;
Argb argb = new Argb(x, y, z, w);
Argb32 argb = new Argb32(x, y, z, w);
Assert.Equal(0x001a0080u, argb.PackedValue);
// Test ordering
@ -712,29 +712,29 @@ namespace ImageSharp.Tests.Colors
}
[Fact]
public void Rgba32()
public void Color()
{
// Test the limits.
Assert.Equal((uint)0x0, new Rgba32(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFFFFFF, new Rgba32(Vector4.One).PackedValue);
Assert.Equal((uint)0x0, new Color(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFFFFFF, new Color(Vector4.One).PackedValue);
// Test ToVector4.
Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.Zero).ToVector4()));
Assert.True(Equal(Vector4.UnitX, new Rgba32(Vector4.UnitX).ToVector4()));
Assert.True(Equal(Vector4.UnitY, new Rgba32(Vector4.UnitY).ToVector4()));
Assert.True(Equal(Vector4.UnitZ, new Rgba32(Vector4.UnitZ).ToVector4()));
Assert.True(Equal(Vector4.UnitW, new Rgba32(Vector4.UnitW).ToVector4()));
Assert.True(Equal(Vector4.One, new Color(Vector4.One).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Color(Vector4.Zero).ToVector4()));
Assert.True(Equal(Vector4.UnitX, new Color(Vector4.UnitX).ToVector4()));
Assert.True(Equal(Vector4.UnitY, new Color(Vector4.UnitY).ToVector4()));
Assert.True(Equal(Vector4.UnitZ, new Color(Vector4.UnitZ).ToVector4()));
Assert.True(Equal(Vector4.UnitW, new Color(Vector4.UnitW).ToVector4()));
// Test clamping.
Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.One * -1234.0f).ToVector4()));
Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One * +1234.0f).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Color(Vector4.One * -1234.0f).ToVector4()));
Assert.True(Equal(Vector4.One, new Color(Vector4.One * +1234.0f).ToVector4()));
float x = +0.1f;
float y = -0.3f;
float z = +0.5f;
float w = -0.7f;
Rgba32 rgba32 = new Rgba32(x, y, z, w);
Color rgba32 = new Color(x, y, z, w);
Assert.Equal(0x80001Au, rgba32.PackedValue);
// Test ordering

4
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -25,7 +25,7 @@ namespace ImageSharp.Tests
public static string[] ProgressiveTestJpegs = TestImages.Jpeg.Progressive.All;
[Theory]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)]
public void OpenBaselineJpeg_SaveBmp<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{
@ -36,7 +36,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)]
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)]
public void OpenProgressiveJpeg_SaveBmp<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{

4
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

@ -48,8 +48,8 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio444, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio444, 75)]
public void OpenBmp_SaveJpeg<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality)
where TColor : struct, IPixel<TColor>
{

4
tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs

@ -39,7 +39,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)]
public void CopyStretchedRGBTo_FromOrigo<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{
@ -61,7 +61,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)]
public void CopyStretchedRGBTo_WithOffset<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{

5
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -19,4 +19,9 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

2
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -193,7 +193,7 @@ namespace ImageSharp.Tests
int pixelCount = left * top;
uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount);
TColor c = default(TColor);
Rgba32 t = new Rgba32(0);
Color t = new Color(0);
for (int x = left; x < right; x++)
for (int y = top; y < bottom; y++)

2
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -18,7 +18,7 @@ namespace ImageSharp.Tests
Alpha8 = 1 << 0,
Argb = 1 << 1,
Argb32 = 1 << 1,
Bgr565 = 1 << 2,

6
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -20,7 +20,7 @@ namespace ImageSharp.Tests
private ITestOutputHelper Output { get; }
[Theory]
[WithBlankImages(42, 666, PixelTypes.Color | PixelTypes.Argb | PixelTypes.HalfSingle, "hello")]
[WithBlankImages(42, 666, PixelTypes.Color | PixelTypes.Argb32 | PixelTypes.HalfSingle, "hello")]
public void Use_WithEmptyImageAttribute<TColor>(TestImageProvider<TColor> provider, string message)
where TColor : struct, IPixel<TColor>
{
@ -86,7 +86,7 @@ namespace ImageSharp.Tests
public static string[] AllBmpFiles => TestImages.Bmp.All;
[Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb32)]
public void Use_WithFileCollection<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{
@ -96,7 +96,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Color | PixelTypes.Argb)]
[WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Color | PixelTypes.Argb32)]
public void Use_WithSolidFilledImagesAttribute<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{

4
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -85,7 +85,7 @@ namespace ImageSharp.Tests
[Theory]
[InlineData(PixelTypes.Color, typeof(Color))]
[InlineData(PixelTypes.Argb, typeof(Argb))]
[InlineData(PixelTypes.Argb32, typeof(Argb32))]
[InlineData(PixelTypes.HalfVector4, typeof(HalfVector4))]
[InlineData(PixelTypes.StandardImageClass, typeof(Color))]
public void ToType(PixelTypes pt, Type expectedType)
@ -95,7 +95,7 @@ namespace ImageSharp.Tests
[Theory]
[InlineData(typeof(Color), PixelTypes.Color)]
[InlineData(typeof(Argb), PixelTypes.Argb)]
[InlineData(typeof(Argb32), PixelTypes.Argb32)]
public void GetPixelType(Type clrType, PixelTypes expectedPixelType)
{
Assert.Equal(expectedPixelType, clrType.GetPixelType());

3
tests/ImageSharp.Tests/xunit.runner.json

@ -0,0 +1,3 @@
{
"methodDisplay": "method"
}
Loading…
Cancel
Save