diff --git a/src/ImageSharp/Colors/Color.Transforms.cs b/src/ImageSharp/Colors/Color.Transforms.cs index 31b4aa5be..15935afc4 100644 --- a/src/ImageSharp/Colors/Color.Transforms.cs +++ b/src/ImageSharp/Colors/Color.Transforms.cs @@ -6,9 +6,10 @@ namespace ImageSharp { using System.Numerics; + using System.Runtime.CompilerServices; /// - /// 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. /// /// @@ -25,10 +26,11 @@ namespace ImageSharp /// /// The . /// + [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); } /// @@ -39,10 +41,11 @@ namespace ImageSharp /// /// The . /// + [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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -249,7 +252,8 @@ namespace ImageSharp /// 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); } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index fb2ce38ac..fa83429df 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -10,7 +10,7 @@ namespace ImageSharp using System.Runtime.InteropServices; /// - /// 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. /// /// @@ -18,7 +18,7 @@ namespace ImageSharp /// as it avoids the need to create new values for modification operations. /// [StructLayout(LayoutKind.Explicit)] - public partial struct Color : IPixel + public partial struct Color : IPixel, IPackedVector { /// /// Gets or sets the red component. @@ -44,6 +44,12 @@ namespace ImageSharp [FieldOffset(3)] public byte A; + /// + /// The packed representation of the value. + /// + [FieldOffset(0)] + public uint Rgba; + /// /// The shift count for the red component /// @@ -81,6 +87,7 @@ namespace ImageSharp /// The green component. /// The blue component. /// The alpha component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(byte r, byte g, byte b, byte a = 255) : this() { @@ -97,10 +104,11 @@ namespace ImageSharp /// The green component. /// The blue component. /// The alpha component. + [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); } /// @@ -109,10 +117,11 @@ namespace ImageSharp /// /// The vector containing the components for the packed vector. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Vector3 vector) : this() { - this = Pack(ref vector); + this.Pack(ref vector); } /// @@ -121,12 +130,29 @@ namespace ImageSharp /// /// The vector containing the components for the packed vector. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Vector4 vector) : this() { - this = Pack(ref vector); + this = PackNew(ref vector); + } + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The packed value. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Color(uint packed) + : this() + { + this.Rgba = packed; } + /// + public uint PackedValue { get => this.Rgba; set => this.Rgba = value; } + /// /// Compares two objects for equality. /// @@ -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; } /// @@ -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; } /// @@ -245,7 +265,7 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { - this = Pack(ref vector); + this.Pack(ref vector); } /// @@ -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; } /// @@ -308,12 +325,12 @@ namespace ImageSharp } /// - /// Packs a into a uint. + /// Packs a into a color returning a new instance as a result. /// /// The vector containing the values to pack. /// The [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); } + /// + /// Packs the four floats into a color. + /// + /// The x-component + /// The y-component + /// The z-component + /// The w-component + [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); + } + /// /// Packs a into a uint. /// /// The vector containing the values to pack. - /// The [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); } /// - /// Packs the four floats into a . + /// Packs a into a color. /// - /// The x-component - /// The y-component - /// The z-component - /// The w-component - /// The + /// The vector containing the values to pack. [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; } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorVector.Definitions.cs b/src/ImageSharp/Colors/ColorVector.Definitions.cs index 955c0b9db..150b7209c 100644 --- a/src/ImageSharp/Colors/ColorVector.Definitions.cs +++ b/src/ImageSharp/Colors/ColorVector.Definitions.cs @@ -6,7 +6,7 @@ namespace ImageSharp { /// - /// 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. /// /// diff --git a/src/ImageSharp/Colors/ColorVector.Transforms.cs b/src/ImageSharp/Colors/ColorVector.Transforms.cs index e9666a351..a884f2618 100644 --- a/src/ImageSharp/Colors/ColorVector.Transforms.cs +++ b/src/ImageSharp/Colors/ColorVector.Transforms.cs @@ -6,9 +6,10 @@ namespace ImageSharp { using System.Numerics; + using System.Runtime.CompilerServices; /// - /// 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. /// /// @@ -25,6 +26,7 @@ namespace ImageSharp /// /// The . /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ColorVector operator +(ColorVector left, ColorVector right) { return new ColorVector(left.backingVector + right.backingVector); @@ -38,6 +40,7 @@ namespace ImageSharp /// /// The . /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ColorVector operator -(ColorVector left, ColorVector right) { return new ColorVector(left.backingVector - right.backingVector); diff --git a/src/ImageSharp/Colors/ColorVector.cs b/src/ImageSharp/Colors/ColorVector.cs index 354553982..06ee5b805 100644 --- a/src/ImageSharp/Colors/ColorVector.cs +++ b/src/ImageSharp/Colors/ColorVector.cs @@ -9,7 +9,7 @@ namespace ImageSharp using System.Runtime.CompilerServices; /// - /// 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. /// /// @@ -40,6 +40,7 @@ namespace ImageSharp /// The green component. /// The blue component. /// The alpha component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ColorVector(byte r, byte g, byte b, byte a = 255) : this() { @@ -53,6 +54,7 @@ namespace ImageSharp /// The green component. /// The blue component. /// The alpha component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ColorVector(float r, float g, float b, float a = 1) : this() { @@ -65,6 +67,7 @@ namespace ImageSharp /// /// The vector containing the components for the packed vector. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ColorVector(Vector3 vector) : this() { @@ -77,6 +80,7 @@ namespace ImageSharp /// /// The vector containing the components for the packed vector. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ColorVector(Vector4 vector) : this() { diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index cbf40724e..480caab33 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Colors.Spaces; /// - /// 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. /// /// diff --git a/src/ImageSharp/Colors/PackedPixel/Argb.cs b/src/ImageSharp/Colors/PackedPixel/Argb32.cs similarity index 87% rename from src/ImageSharp/Colors/PackedPixel/Argb.cs rename to src/ImageSharp/Colors/PackedPixel/Argb32.cs index d03c098cd..64255a53b 100644 --- a/src/ImageSharp/Colors/PackedPixel/Argb.cs +++ b/src/ImageSharp/Colors/PackedPixel/Argb32.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -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. /// - public struct Argb : IPixel, IPackedVector + public struct Argb32 : IPixel, IPackedVector { /// /// The shift count for the blue component @@ -50,58 +50,58 @@ namespace ImageSharp private static readonly Vector4 Half = new Vector4(0.5F); /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. - 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); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. - 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); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// - public Argb(Vector3 vector) + public Argb32(Vector3 vector) { this.PackedValue = Pack(ref vector); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// - public Argb(Vector4 vector) + public Argb32(Vector4 vector) { this.PackedValue = Pack(ref vector); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The packed value. /// - public Argb(uint packed = 0) + public Argb32(uint packed = 0) { this.PackedValue = packed; } @@ -182,33 +182,33 @@ namespace ImageSharp } /// - /// Compares two objects for equality. + /// Compares two objects for equality. /// /// - /// The on the left side of the operand. + /// The on the left side of the operand. /// /// - /// The on the right side of the operand. + /// The on the right side of the operand. /// /// /// True if the parameter is equal to the parameter; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(Argb left, Argb right) + public static bool operator ==(Argb32 left, Argb32 right) { return left.PackedValue == right.PackedValue; } /// - /// Compares two objects for equality. + /// Compares two objects for equality. /// - /// The on the left side of the operand. - /// The on the right side of the operand. + /// The on the left side of the operand. + /// The on the right side of the operand. /// /// True if the parameter is not equal to the parameter; otherwise, false. /// [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 } /// - public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations(); + public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -278,12 +278,12 @@ namespace ImageSharp /// public override bool Equals(object obj) { - return obj is Argb && this.Equals((Argb)obj); + return obj is Argb32 && this.Equals((Argb32)obj); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Argb other) + public bool Equals(Argb32 other) { return this.PackedValue == other.PackedValue; } diff --git a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs index 949e44cc0..13727870c 100644 --- a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs +++ b/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) diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs b/src/ImageSharp/Colors/PackedPixel/Rgba32.cs deleted file mode 100644 index 727d91c93..000000000 --- a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs +++ /dev/null @@ -1,398 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System.Numerics; - using System.Runtime.CompilerServices; - - /// - /// 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. - /// - /// - /// 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. - /// - public struct Rgba32 : IPixel, IPackedVector - { - /// - /// The shift count for the red component - /// - private const int RedShift = 0; - - /// - /// The shift count for the green component - /// - private const int GreenShift = 8; - - /// - /// The shift count for the blue component - /// - private const int BlueShift = 16; - - /// - /// The shift count for the alpha component - /// - private const int AlphaShift = 24; - - /// - /// The maximum byte value. - /// - private static readonly Vector4 MaxBytes = new Vector4(255); - - /// - /// The half vector value. - /// - private static readonly Vector4 Half = new Vector4(0.5F); - - /// - /// The packed value. - /// - private uint packedValue; - - /// - /// Initializes a new instance of the struct. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The alpha component. - public Rgba32(byte r, byte g, byte b, byte a = 255) - { - this.packedValue = Pack(r, g, b, a); - } - - /// - /// Initializes a new instance of the struct. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The alpha component. - public Rgba32(float r, float g, float b, float a = 1) - { - this.packedValue = Pack(r, g, b, a); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The vector containing the components for the packed vector. - /// - public Rgba32(Vector3 vector) - { - this.packedValue = Pack(ref vector); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The vector containing the components for the packed vector. - /// - public Rgba32(Vector4 vector) - { - this.packedValue = Pack(ref vector); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The packed value. - /// - public Rgba32(uint packed) - { - this.packedValue = packed; - } - - /// - /// Gets or sets the red component. - /// - public byte R - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> RedShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift; - } - } - - /// - /// Gets or sets the green component. - /// - public byte G - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> GreenShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift; - } - } - - /// - /// Gets or sets the blue component. - /// - public byte B - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> BlueShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift; - } - } - - /// - /// Gets or sets the alpha component. - /// - public byte A - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> AlphaShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift; - } - } - - /// - public uint PackedValue - { - get => this.packedValue; - - set => this.packedValue = value; - } - - /// - /// Compares two objects for equality. - /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the parameter is equal to the parameter; otherwise, false. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(Rgba32 left, Rgba32 right) - { - return left.packedValue == right.packedValue; - } - - /// - /// Compares two objects for equality. - /// - /// The on the left side of the operand. - /// The on the right side of the operand. - /// - /// True if the parameter is not equal to the parameter; otherwise, false. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(Rgba32 left, Rgba32 right) - { - return left.packedValue != right.packedValue; - } - - /// - /// Creates a new instance of the struct. - /// - /// - /// The hexadecimal representation of the combined color components arranged - /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. - /// - /// - /// The . - /// - public static Rgba32 FromHex(string hex) - { - return ColorBuilder.FromHex(hex); - } - - /// - public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations(); - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromBytes(byte x, byte y, byte z, byte w) - { - this.packedValue = Pack(x, y, z, w); - } - - /// - /// Converts the value of this instance to a hexadecimal string. - /// - /// A hexadecimal string representation of the value. - public string ToHex() - { - uint hexOrder = Pack(this.A, this.B, this.G, this.R); - return hexOrder.ToString("X8"); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) - { - bytes[startIndex] = this.R; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.B; - } - - /// - [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; - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) - { - bytes[startIndex] = this.B; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.R; - } - - /// - [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; - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromVector4(Vector4 vector) - { - this.packedValue = Pack(ref vector); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ToVector4() - { - return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; - } - - /// - public override bool Equals(object obj) - { - return (obj is Rgba32) && this.Equals((Rgba32)obj); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Rgba32 other) - { - return this.packedValue == other.packedValue; - } - - /// - /// Gets a string representation of the packed vector. - /// - /// A string representation of the packed vector. - public override string ToString() - { - return this.ToVector4().ToString(); - } - - /// - public override int GetHashCode() - { - return this.packedValue.GetHashCode(); - } - - /// - /// Packs a into a uint. - /// - /// The vector containing the values to pack. - /// The containing the packed values. - [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); - } - - /// - /// Packs a into a uint. - /// - /// The vector containing the values to pack. - /// The containing the packed values. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(ref Vector3 vector) - { - Vector4 value = new Vector4(vector, 1); - return Pack(ref value); - } - - /// - /// Packs the four floats into a . - /// - /// The x-component - /// The y-component - /// The z-component - /// The w-component - /// The - [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); - } - - /// - /// Packs the four floats into a . - /// - /// The x-component - /// The y-component - /// The z-component - /// The w-component - /// The - [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); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index 05fc4094e..f23ca3e5c 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -64,7 +64,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { } - public class ToXyzw_Argb : ToXyzw + public class ToXyzw_Argb : ToXyzw { } } diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs index 0b1e6dc7b..d4b9f6f3a 100644 --- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs @@ -58,7 +58,7 @@ namespace ImageSharp.Tests.Colors } } - public class Argb : BulkPixelOperationsTests + public class Argb : BulkPixelOperationsTests { // For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class: public Argb(ITestOutputHelper output) diff --git a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs b/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs index 83c02635a..d2c5cf845 100644 --- a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs +++ b/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 }; } } diff --git a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs index 42481799f..ffb04e8b2 100644 --- a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Colors new TheoryData() { { 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() { // 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) }, diff --git a/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs b/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs index 7b743e53a..5fbb42b2a 100644 --- a/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs +++ b/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 }; } } diff --git a/tests/ImageSharp.Tests/Colors/ColorTests.cs b/tests/ImageSharp.Tests/Colors/ColorTests.cs index 312e66466..e2c62b507 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTests.cs +++ b/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)); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs index b5e159d9a..52ca86cae 100644 --- a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs +++ b/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 diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index cdd892dce..d83424b24 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/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(TestImageProvider provider) where TColor : struct, IPixel { @@ -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(TestImageProvider provider) where TColor : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index 0833cb868..f900fe782 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/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(TestImageProvider provider, JpegSubsample subSample, int quality) where TColor : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs index d0a7fae33..25fe46aa2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs +++ b/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(TestImageProvider provider) where TColor : struct, IPixel { @@ -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(TestImageProvider provider) where TColor : struct, IPixel { diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index c6f916e00..ff5eccc78 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -19,4 +19,9 @@ + + + PreserveNewest + + \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index c9312eed1..c40abd934 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/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++) diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs index 489ef970a..92a16563a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs +++ b/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, diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index 6760735d1..cea9cfea0 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/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(TestImageProvider provider, string message) where TColor : struct, IPixel { @@ -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(TestImageProvider provider) where TColor : struct, IPixel { @@ -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(TestImageProvider provider) where TColor : struct, IPixel { diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 63c24a157..0d24410ac 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/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()); diff --git a/tests/ImageSharp.Tests/xunit.runner.json b/tests/ImageSharp.Tests/xunit.runner.json new file mode 100644 index 000000000..df1c3d50d --- /dev/null +++ b/tests/ImageSharp.Tests/xunit.runner.json @@ -0,0 +1,3 @@ +{ + "methodDisplay": "method" +} \ No newline at end of file