diff --git a/src/ImageSharp/PixelFormats/Alpha8.cs b/src/ImageSharp/PixelFormats/Alpha8.cs index c184ed9cf6..582c28c789 100644 --- a/src/ImageSharp/PixelFormats/Alpha8.cs +++ b/src/ImageSharp/PixelFormats/Alpha8.cs @@ -62,7 +62,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index 3749571c7b..2ca1183a30 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -237,7 +237,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Bgr24.cs b/src/ImageSharp/PixelFormats/Bgr24.cs new file mode 100644 index 0000000000..2555c13a47 --- /dev/null +++ b/src/ImageSharp/PixelFormats/Bgr24.cs @@ -0,0 +1,94 @@ +namespace ImageSharp.PixelFormats +{ + using System; + using System.Numerics; + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + + [StructLayout(LayoutKind.Sequential)] + public struct Bgr24 : IPixel + { + /// + /// Gets or sets the blue component. + /// + public byte B; + + /// + /// Gets or sets the green component. + /// + public byte G; + + /// + /// Gets or sets the red component. + /// + public byte R; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Bgr24(byte r, byte g, byte b) + { + this.R = r; + this.G = g; + this.B = b; + } + + public PixelOperations CreatePixelOperations() => new PixelOperations(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(Bgr24 other) + { + return this.R == other.R && this.G == other.G && this.B == other.B; + } + + public override bool Equals(object obj) + { + return obj.GetType() == typeof(Bgr24) && this.Equals((Bgr24)obj); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() + { + unchecked + { + int hashCode = this.B; + hashCode = (hashCode * 397) ^ this.G; + hashCode = (hashCode * 397) ^ this.R; + return hashCode; + } + } + + public void PackFromBytes(byte x, byte y, byte z, byte w) + { + throw new NotImplementedException(); + } + + public void PackFromVector4(Vector4 vector) + { + throw new NotImplementedException(); + } + + public Vector4 ToVector4() + { + throw new NotImplementedException(); + } + + public void ToXyzBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + + public void ToXyzwBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + + public void ToZyxBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + + public void ToZyxwBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/Bgr565.cs b/src/ImageSharp/PixelFormats/Bgr565.cs index 92bbac14cc..6a568eeb5e 100644 --- a/src/ImageSharp/PixelFormats/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/Bgr565.cs @@ -71,7 +71,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// /// Expands the packed representation into a . diff --git a/src/ImageSharp/PixelFormats/Bgra4444.cs b/src/ImageSharp/PixelFormats/Bgra4444.cs index 0bac00dfe3..2dafd0c98c 100644 --- a/src/ImageSharp/PixelFormats/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/Bgra4444.cs @@ -70,7 +70,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Bgra5551.cs b/src/ImageSharp/PixelFormats/Bgra5551.cs index f151db644a..67fb4e0ec2 100644 --- a/src/ImageSharp/PixelFormats/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/Bgra5551.cs @@ -72,7 +72,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Byte4.cs b/src/ImageSharp/PixelFormats/Byte4.cs index 264bc74972..2a0e6d75c3 100644 --- a/src/ImageSharp/PixelFormats/Byte4.cs +++ b/src/ImageSharp/PixelFormats/Byte4.cs @@ -73,7 +73,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/HalfSingle.cs b/src/ImageSharp/PixelFormats/HalfSingle.cs index 4cc9acc222..b6f93d0593 100644 --- a/src/ImageSharp/PixelFormats/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/HalfSingle.cs @@ -76,7 +76,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// /// Expands the packed representation into a . diff --git a/src/ImageSharp/PixelFormats/HalfVector2.cs b/src/ImageSharp/PixelFormats/HalfVector2.cs index f490f71690..e96c5c0763 100644 --- a/src/ImageSharp/PixelFormats/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/HalfVector2.cs @@ -86,7 +86,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// /// Expands the packed representation into a . diff --git a/src/ImageSharp/PixelFormats/HalfVector4.cs b/src/ImageSharp/PixelFormats/HalfVector4.cs index 7c496c161b..d84a401980 100644 --- a/src/ImageSharp/PixelFormats/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/HalfVector4.cs @@ -89,7 +89,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs index 030cb93f46..4e777cadf7 100644 --- a/src/ImageSharp/PixelFormats/IPixel.cs +++ b/src/ImageSharp/PixelFormats/IPixel.cs @@ -20,7 +20,7 @@ namespace ImageSharp.PixelFormats /// This method is not intended to be consumed directly. Use instead. /// /// The instance. - PixelOperations CreateBulkOperations(); + PixelOperations CreatePixelOperations(); } /// diff --git a/src/ImageSharp/PixelFormats/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/NormalizedByte2.cs index 47a4f30059..d1193e9c1c 100644 --- a/src/ImageSharp/PixelFormats/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte2.cs @@ -91,7 +91,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// /// Expands the packed representation into a . diff --git a/src/ImageSharp/PixelFormats/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/NormalizedByte4.cs index 4559bd082f..565f269719 100644 --- a/src/ImageSharp/PixelFormats/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte4.cs @@ -93,7 +93,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/NormalizedShort2.cs index 648b68905a..5b791eb256 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort2.cs @@ -91,7 +91,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/NormalizedShort4.cs index 7b520aacef..047c6a2507 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort4.cs @@ -93,7 +93,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index 993a11232a..5c51b59f88 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -20,7 +20,7 @@ namespace ImageSharp.PixelFormats /// /// Gets the global instance for the pixel type /// - public static PixelOperations Instance { get; } = default(TPixel).CreateBulkOperations(); + public static PixelOperations Instance { get; } = default(TPixel).CreatePixelOperations(); /// /// Bulk version of diff --git a/src/ImageSharp/PixelFormats/Rg32.cs b/src/ImageSharp/PixelFormats/Rg32.cs index ea7d8729b4..0faf2fe803 100644 --- a/src/ImageSharp/PixelFormats/Rg32.cs +++ b/src/ImageSharp/PixelFormats/Rg32.cs @@ -76,7 +76,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// /// Expands the packed representation into a . diff --git a/src/ImageSharp/PixelFormats/Rgb24.cs b/src/ImageSharp/PixelFormats/Rgb24.cs new file mode 100644 index 0000000000..ff2b237ad8 --- /dev/null +++ b/src/ImageSharp/PixelFormats/Rgb24.cs @@ -0,0 +1,94 @@ +namespace ImageSharp.PixelFormats +{ + using System; + using System.Numerics; + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + + [StructLayout(LayoutKind.Sequential)] + public struct Rgb24 : IPixel + { + /// + /// Gets or sets the red component. + /// + public byte R; + + /// + /// Gets or sets the green component. + /// + public byte G; + + /// + /// Gets or sets the blue component. + /// + public byte B; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Rgb24(byte r, byte g, byte b) + { + this.R = r; + this.G = g; + this.B = b; + } + + public PixelOperations CreatePixelOperations() => new PixelOperations(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(Rgb24 other) + { + return this.R == other.R && this.G == other.G && this.B == other.B; + } + + public override bool Equals(object obj) + { + return obj.GetType() == typeof(Rgb24) && this.Equals((Rgb24)obj); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() + { + unchecked + { + int hashCode = this.R; + hashCode = (hashCode * 397) ^ this.G; + hashCode = (hashCode * 397) ^ this.B; + return hashCode; + } + } + + public void PackFromBytes(byte x, byte y, byte z, byte w) + { + throw new NotImplementedException(); + } + + public void PackFromVector4(Vector4 vector) + { + throw new NotImplementedException(); + } + + public Vector4 ToVector4() + { + throw new NotImplementedException(); + } + + public void ToXyzBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + + public void ToXyzwBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + + public void ToZyxBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + + public void ToZyxwBytes(Span bytes, int startIndex) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/Rgba1010102.cs b/src/ImageSharp/PixelFormats/Rgba1010102.cs index ca7b74fbbd..8eaf5f7713 100644 --- a/src/ImageSharp/PixelFormats/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/Rgba1010102.cs @@ -79,7 +79,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index 446da5abb4..ba46332fbf 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -23,31 +23,27 @@ 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. /// - [StructLayout(LayoutKind.Explicit)] + [StructLayout(LayoutKind.Sequential)] public partial struct Rgba32 : IPixel, IPackedVector { /// /// Gets or sets the red component. /// - [FieldOffset(0)] public byte R; /// /// Gets or sets the green component. /// - [FieldOffset(1)] public byte G; /// /// Gets or sets the blue component. /// - [FieldOffset(2)] public byte B; /// /// Gets or sets the alpha component. /// - [FieldOffset(3)] public byte A; /// @@ -233,7 +229,7 @@ namespace ImageSharp } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs index 4178283686..2101d4ba0e 100644 --- a/src/ImageSharp/PixelFormats/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -78,7 +78,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/RgbaVector.cs b/src/ImageSharp/PixelFormats/RgbaVector.cs index 5332f4a8e7..314ac31e3b 100644 --- a/src/ImageSharp/PixelFormats/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.cs @@ -211,7 +211,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new RgbaVector.PixelOperations(); + public PixelOperations CreatePixelOperations() => new RgbaVector.PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Short2.cs b/src/ImageSharp/PixelFormats/Short2.cs index b848b55053..a6fe95b49f 100644 --- a/src/ImageSharp/PixelFormats/Short2.cs +++ b/src/ImageSharp/PixelFormats/Short2.cs @@ -91,7 +91,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Short4.cs b/src/ImageSharp/PixelFormats/Short4.cs index 763de19bc3..f254c7379f 100644 --- a/src/ImageSharp/PixelFormats/Short4.cs +++ b/src/ImageSharp/PixelFormats/Short4.cs @@ -93,7 +93,7 @@ namespace ImageSharp.PixelFormats } /// - public PixelOperations CreateBulkOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Shared/stylecop.json b/src/Shared/stylecop.json index df8f120a5b..b74a0af91d 100644 --- a/src/Shared/stylecop.json +++ b/src/Shared/stylecop.json @@ -3,7 +3,11 @@ "settings": { "documentationRules": { "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." + "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0.", + + "documentInterfaces": false, + "documentInternalElements": false, + "documentExposedElements": false } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations.cs b/tests/ImageSharp.Sandbox46/Tests/PixelFormats/PixelBlenderTests.cs similarity index 96% rename from tests/ImageSharp.Tests/PixelFormats/PixelOperations.cs rename to tests/ImageSharp.Sandbox46/Tests/PixelFormats/PixelBlenderTests.cs index a9108692ed..7efd3a6fcb 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations.cs +++ b/tests/ImageSharp.Sandbox46/Tests/PixelFormats/PixelBlenderTests.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests.PixelFormats public class PixelOperations { - public static TheoryData blenderMappings = new TheoryData() + public static TheoryData BlenderMappings = new TheoryData() { { new TestPixel(), typeof(DefaultNormalPixelBlender), PixelBlenderMode.Normal }, { new TestPixel(), typeof(DefaultScreenPixelBlender), PixelBlenderMode.Screen }, @@ -39,7 +39,7 @@ namespace ImageSharp.Tests.PixelFormats }; [Theory] - [MemberData(nameof(blenderMappings))] + [MemberData(nameof(BlenderMappings))] public void ReturnsCorrectBlender(TestPixel pixel, Type type, PixelBlenderMode mode) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 55b3c80e35..781e73f9ea 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -7,7 +7,7 @@ True - + diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs new file mode 100644 index 0000000000..3711631637 --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs @@ -0,0 +1,63 @@ +namespace ImageSharp.Tests +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class Bgr24Tests + { + public static readonly TheoryData ColorData = + new TheoryData() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } }; + + [Theory] + [MemberData(nameof(ColorData))] + public void Constructor(byte r, byte g, byte b) + { + var p = new Rgb24(r, g, b); + + Assert.Equal(r, p.R); + Assert.Equal(g, p.G); + Assert.Equal(b, p.B); + } + [Fact] + public unsafe void ByteLayoutIsSequentialBgr() + { + var color = new Bgr24(1, 2, 3); + byte* ptr = (byte*)&color; + + Assert.Equal(3, ptr[0]); + Assert.Equal(2, ptr[1]); + Assert.Equal(1, ptr[2]); + } + + public class Equality + { + public static TheoryData ColorData = Rgb24Tests.ColorData; + + [Theory] + [MemberData(nameof(ColorData))] + public void WhenTrue(byte r, byte g, byte b) + { + var x = new Rgb24(r, g, b); + var y = new Rgb24(r, g, b); + + Assert.True(x.Equals(y)); + Assert.True(x.Equals((object)y)); + Assert.Equal(x.GetHashCode(), y.GetHashCode()); + } + + [Theory] + [InlineData(1, 2, 3, 1, 2, 4)] + [InlineData(0, 255, 0, 0, 244, 0)] + [InlineData(1, 255, 0, 0, 255, 0)] + public void WhenFalse(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2) + { + var a = new Rgb24(1, 2, 3); + var b = new Rgb24(1, 2, 4); + + Assert.False(a.Equals(b)); + Assert.False(a.Equals((object)b)); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs rename to tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs diff --git a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs rename to tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs diff --git a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs rename to tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs diff --git a/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/ColorPackingTests.cs rename to tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs diff --git a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/PackedPixelTests.cs rename to tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs new file mode 100644 index 0000000000..ce81499eda --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.PixelFormats +{ + using System; + using System.Collections.Generic; + using System.Text; + using ImageSharp.PixelFormats; + using ImageSharp.PixelFormats.PixelBlenders; + using ImageSharp.Tests.TestUtilities; + using Xunit; + + public partial class PixelOperationsTests + { + public static TheoryData BlenderMappings = new TheoryData() + { + { new TestPixel(), typeof(DefaultNormalPixelBlender), PixelBlenderMode.Normal }, + { new TestPixel(), typeof(DefaultScreenPixelBlender), PixelBlenderMode.Screen }, + { new TestPixel(), typeof(DefaultHardLightPixelBlender), PixelBlenderMode.HardLight }, + { new TestPixel(), typeof(DefaultOverlayPixelBlender), PixelBlenderMode.Overlay }, + { new TestPixel(), typeof(DefaultDarkenPixelBlender), PixelBlenderMode.Darken }, + { new TestPixel(), typeof(DefaultLightenPixelBlender), PixelBlenderMode.Lighten }, + { new TestPixel(), typeof(DefaultAddPixelBlender), PixelBlenderMode.Add }, + { new TestPixel(), typeof(DefaultSubstractPixelBlender), PixelBlenderMode.Substract }, + { new TestPixel(), typeof(DefaultMultiplyPixelBlender), PixelBlenderMode.Multiply }, + + { new TestPixel(), typeof(DefaultNormalPixelBlender), PixelBlenderMode.Normal }, + { new TestPixel(), typeof(DefaultScreenPixelBlender), PixelBlenderMode.Screen }, + { new TestPixel(), typeof(DefaultHardLightPixelBlender), PixelBlenderMode.HardLight }, + { new TestPixel(), typeof(DefaultOverlayPixelBlender), PixelBlenderMode.Overlay }, + { new TestPixel(), typeof(DefaultDarkenPixelBlender), PixelBlenderMode.Darken }, + { new TestPixel(), typeof(DefaultLightenPixelBlender), PixelBlenderMode.Lighten }, + { new TestPixel(), typeof(DefaultAddPixelBlender), PixelBlenderMode.Add }, + { new TestPixel(), typeof(DefaultSubstractPixelBlender), PixelBlenderMode.Substract }, + { new TestPixel(), typeof(DefaultMultiplyPixelBlender), PixelBlenderMode.Multiply }, + }; + + [Theory] + [MemberData(nameof(BlenderMappings))] + public void ReturnsCorrectBlender(TestPixel pixel, Type type, PixelBlenderMode mode) + where TPixel : struct, IPixel + { + PixelBlender blender = PixelOperations.Instance.GetPixelBlender(mode); + Assert.IsType(type, blender); + } + } +} diff --git a/tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs similarity index 99% rename from tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs rename to tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index c91218ccc7..f387178e58 100644 --- a/tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -1,6 +1,6 @@ // ReSharper disable InconsistentNaming // ReSharper disable AccessToDisposedClosure -namespace ImageSharp.Tests.Colors +namespace ImageSharp.Tests.PixelFormats { using System; using System.Numerics; @@ -11,8 +11,9 @@ namespace ImageSharp.Tests.Colors using Xunit; using Xunit.Abstractions; - public class PixelOperationsTests + public partial class PixelOperationsTests { + public class Color32 : PixelOperationsTests { public Color32(ITestOutputHelper output) diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs new file mode 100644 index 0000000000..934d83bbb7 --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs @@ -0,0 +1,65 @@ +// ReSharper disable InconsistentNaming +namespace ImageSharp.Tests +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class Rgb24Tests + { + public static readonly TheoryData ColorData = + new TheoryData() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } }; + + [Theory] + [MemberData(nameof(ColorData))] + public void Constructor(byte r, byte g, byte b) + { + var p = new Rgb24(r, g, b); + + Assert.Equal(r, p.R); + Assert.Equal(g, p.G); + Assert.Equal(b, p.B); + } + + [Fact] + public unsafe void ByteLayoutIsSequentialRgb() + { + var color = new Rgb24(1, 2, 3); + byte* ptr = (byte*)&color; + + Assert.Equal(1, ptr[0]); + Assert.Equal(2, ptr[1]); + Assert.Equal(3, ptr[2]); + } + + public class Equality + { + public static TheoryData ColorData = Rgb24Tests.ColorData; + + [Theory] + [MemberData(nameof(ColorData))] + public void WhenTrue(byte r, byte g, byte b) + { + var x = new Rgb24(r, g, b); + var y = new Rgb24(r, g, b); + + Assert.True(x.Equals(y)); + Assert.True(x.Equals((object)y)); + Assert.Equal(x.GetHashCode(), y.GetHashCode()); + } + + [Theory] + [InlineData(1, 2, 3, 1, 2, 4)] + [InlineData(0, 255, 0, 0, 244, 0)] + [InlineData(1, 255, 0, 0, 255, 0)] + public void WhenFalse(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2) + { + var a = new Rgb24(1, 2, 3); + var b = new Rgb24(1, 2, 4); + + Assert.False(a.Equals(b)); + Assert.False(a.Equals((object)b)); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/Rgba32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/Rgba32Tests.cs rename to tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs diff --git a/tests/ImageSharp.Tests/Colors/RgbaVectorTests.cs b/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/RgbaVectorTests.cs rename to tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs diff --git a/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs similarity index 100% rename from tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs rename to tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs