From 2d96be9d6698d179ad69b2049970cb3dbae1736e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 9 Apr 2017 01:46:53 +0200 Subject: [PATCH 01/34] DangerousGetPinnableReference() + PixelIndexing benchmarks --- src/ImageSharp/Common/Memory/BufferSpan{T}.cs | 8 + .../Bulk/PackFromVector4ReferenceVsPointer.cs | 74 ++++++ .../General/PixelIndexing.cs | 238 ++++++++++++++++++ .../Common/BufferSpanTests.cs | 15 ++ 4 files changed, 335 insertions(+) create mode 100644 tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs create mode 100644 tests/ImageSharp.Benchmarks/General/PixelIndexing.cs diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs index 8ef88814c..5efa7bc07 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs @@ -158,6 +158,14 @@ namespace ImageSharp return result; } + /// + /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element + /// would have been stored. Such a reference can be used for pinning but must never be dereferenced. + /// + /// The reference to the 0th element + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref T DangerousGetPinnableReference() => ref Unsafe.AsRef((void*)this.PointerAtOffset); + /// /// Forms a slice out of the given BufferSpan, beginning at 'start'. /// diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs new file mode 100644 index 000000000..e912ea29f --- /dev/null +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -0,0 +1,74 @@ +namespace ImageSharp.Benchmarks +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + using BenchmarkDotNet.Attributes; + + using ImageSharp; + + /// + /// Compares two implementation candidates for general BulkPixelOperations.ToVector4(): + /// - One iterating with pointers + /// - One iterating with ref locals + /// + public unsafe class PackFromVector4ReferenceVsPointer + { + private PinnedBuffer destination; + + private PinnedBuffer source; + + [Params(16, 128, 1024)] + public int Count { get; set; } + + [Setup] + public void Setup() + { + this.destination = new PinnedBuffer(this.Count); + this.source = new PinnedBuffer(this.Count * 4); + } + + [Cleanup] + public void Cleanup() + { + this.source.Dispose(); + this.destination.Dispose(); + } + + [Benchmark(Baseline = true)] + public void PackUsingPointers() + { + Vector4* sp = (Vector4*)this.source.Pointer; + byte* dp = (byte*)this.destination.Pointer; + int count = this.Count; + int size = sizeof(ImageSharp.Color); + + for (int i = 0; i < count; i++) + { + Vector4 v = Unsafe.Read(sp); + ImageSharp.Color c = default(ImageSharp.Color); + c.PackFromVector4(v); + Unsafe.Write(dp, c); + + sp++; + dp += size; + } + } + + [Benchmark] + public void PackUsingReferences() + { + ref Vector4 sp = ref this.source.Array[0]; + ref ImageSharp.Color dp = ref this.destination.Array[0]; + int count = this.Count; + + for (int i = 0; i < count; i++) + { + dp.PackFromVector4(sp); + + sp = Unsafe.Add(ref sp, 1); + dp = Unsafe.Add(ref dp, 1); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs new file mode 100644 index 000000000..8dc8744eb --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -0,0 +1,238 @@ +namespace ImageSharp.Benchmarks.General +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + using BenchmarkDotNet.Attributes; + + public abstract unsafe class PixelIndexing + { + /// + /// https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System/Pinnable.cs + /// + protected class Pinnable + { + public T Data; + } + + /// + /// The indexer methods are encapsulated into a struct to make sure everything is inlined. + /// + internal struct Data + { + private Vector4* pointer; + + private Pinnable pinnable; + + private int width; + + public Data(PinnedImageBuffer buffer) + { + this.pointer = (Vector4*)buffer.Pointer; + this.pinnable = Unsafe.As>(buffer.Array); + this.width = buffer.Width; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 GetPointersBasicImpl(int x, int y) + { + return this.pointer[y * this.width + x]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 GetPointersSrcsUnsafeImpl(int x, int y) + { + return Unsafe.Read((byte*)this.pointer + (((y * this.width) + x) * Unsafe.SizeOf())); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 GetReferencesImpl(int x, int y) + { + int elementOffset = (y * this.width) + x; + return Unsafe.Add(ref this.pinnable.Data, elementOffset); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref Vector4 GetReferencesRefReturnsImpl(int x, int y) + { + int elementOffset = (y * this.width) + x; + return ref Unsafe.Add(ref this.pinnable.Data, elementOffset); + } + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void IndexWithPointersBasicImpl(int x, int y, Vector4 v) + { + this.pointer[y * this.width + x] = v; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void IndexWithPointersSrcsUnsafeImpl(int x, int y, Vector4 v) + { + Unsafe.Write((byte*)this.pointer + (((y * this.width) + x) * Unsafe.SizeOf()), v); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void IndexWithReferencesImpl(int x, int y, Vector4 v) + { + int elementOffset = (y * this.width) + x; + Unsafe.Add(ref this.pinnable.Data, elementOffset) = v; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref Vector4 IndexWithReferencesRefReturnImpl(int x, int y) + { + int elementOffset = (y * this.width) + x; + return ref Unsafe.Add(ref this.pinnable.Data, elementOffset); + } + } + + internal PinnedImageBuffer buffer; + + protected int width; + + protected int startIndex; + + protected int endIndex; + + protected Vector4* pointer; + + protected Vector4[] array; + + protected Pinnable pinnable; + + [Params(64, 256, 1024)] + public int Count { get; set; } + + [Setup] + public void Setup() + { + this.width = 2048; + this.buffer = new PinnedImageBuffer(2048, 2048); + this.pointer = (Vector4*)this.buffer.Pointer; + this.array = this.buffer.Array; + this.pinnable = Unsafe.As>(this.array); + + this.startIndex = 2048 / 2 - (this.Count / 2); + this.endIndex = 2048 / 2 + (this.Count / 2); + } + + [Cleanup] + public void Cleanup() + { + this.buffer.Dispose(); + } + + } + + public unsafe class PixelIndexingGetter : PixelIndexing + { + [Benchmark(Description = "Index.Get: Pointers+arithmetics", Baseline = true)] + public Vector4 IndexWithPointersBasic() + { + Vector4 sum = Vector4.Zero; + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + sum += data.GetPointersBasicImpl(i, i); + } + + return sum; + } + + [Benchmark(Description = "Index.Get: Pointers+SRCS.Unsafe")] + public Vector4 IndexWithPointersSrcsUnsafe() + { + Vector4 sum = Vector4.Zero; + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + sum += data.GetPointersSrcsUnsafeImpl(i, i); + } + + return sum; + } + + [Benchmark(Description = "Index.Get: References")] + public Vector4 IndexWithReferences() + { + Vector4 sum = Vector4.Zero; + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + sum += data.GetReferencesImpl(i, i); + } + + return sum; + } + + [Benchmark(Description = "Index.Get: References+refreturns")] + public Vector4 IndexWithReferencesRefReturns() + { + Vector4 sum = Vector4.Zero; + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + sum += data.GetReferencesRefReturnsImpl(i, i); + } + + return sum; + } + } + + public unsafe class PixelIndexingSetter : PixelIndexing + { + [Benchmark(Description = "Index.Set: Pointers+arithmetics", Baseline = true)] + public void IndexWithPointersBasic() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + data.IndexWithPointersBasicImpl(i, i, v); + } + } + + [Benchmark(Description = "Index.Set: Pointers+SRCS.Unsafe")] + public void IndexWithPointersSrcsUnsafe() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + data.IndexWithPointersSrcsUnsafeImpl(i, i, v); + } + } + + [Benchmark(Description = "Index.Set: References")] + public void IndexWithReferencesBasic() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + data.IndexWithReferencesImpl(i, i, v); + } + } + + [Benchmark(Description = "Index.Set: References+refreturn")] + public void IndexWithReferencesRefReturn() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + data.IndexWithReferencesRefReturnImpl(i, i) = v; + } + } + + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index aee032acc..32ec5dec6 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -201,6 +201,21 @@ namespace ImageSharp.Tests.Common } } + [Theory] + [InlineData(0, 4)] + [InlineData(2, 4)] + [InlineData(3, 4)] + public void DangerousGetPinnableReference(int start, int length) + { + Foo[] a = Foo.CreateArray(length); + fixed (Foo* p = a) + { + BufferSpan span = new BufferSpan(a, p, start); + ref Foo r = ref span.DangerousGetPinnableReference(); + + Assert.True(Unsafe.AreSame(ref a[start], ref r)); + } + } public class Copy { From 84725f452396ffdef590ce948fee2696b5101810 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 12 Apr 2017 02:49:58 +0200 Subject: [PATCH 02/34] refactored all BufferSpan pointers to ref-s --- src/ImageSharp/Colors/Color.BulkOperations.cs | 171 +++++++----- src/ImageSharp/Colors/Color.cs | 5 + .../BulkPixelOperations{TColor}.cs | 132 +++++----- src/ImageSharp/Common/Memory/BufferSpan.cs | 116 ++++++--- src/ImageSharp/Common/Memory/BufferSpan{T}.cs | 71 +---- .../Common/Memory/PinnedBuffer{T}.cs | 12 +- .../ResamplingWeightedProcessor.Weights.cs | 28 +- .../Transforms/ResamplingWeightedProcessor.cs | 11 +- .../Common/BufferSpanTests.cs | 243 +++++++----------- .../Common/PinnedBufferTests.cs | 23 +- .../Common/PinnedImageBufferTests.cs | 19 +- 11 files changed, 438 insertions(+), 393 deletions(-) diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 7d3b12ea0..08d70330d 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -62,21 +62,20 @@ namespace ImageSharp int unpackedRawCount = count * 4; - uint* src = (uint*)sourceColors.PointerAtOffset; - uint* srcEnd = src + count; + ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); - using (PinnedBuffer tempBuf = new PinnedBuffer( - unpackedRawCount + Vector.Count)) + using (PinnedBuffer tempBuf = new PinnedBuffer(unpackedRawCount + Vector.Count)) { uint* tPtr = (uint*)tempBuf.Pointer; uint[] temp = tempBuf.Array; float[] fTemp = Unsafe.As(temp); UnpackedRGBA* dst = (UnpackedRGBA*)tPtr; - for (; src < srcEnd; src++, dst++) + for (int i = 0; i < count; i++) { // This call is the bottleneck now: - dst->Load(*src); + ref uint sp = ref Unsafe.Add(ref src, i); + dst->Load(sp); } for (int i = 0; i < unpackedRawCount; i += vecSize) @@ -123,39 +122,44 @@ namespace ImageSharp } /// - internal override unsafe void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromXyzBytes( + BufferSpan sourceBytes, + BufferSpan destColors, + int count) { - byte* source = (byte*)sourceBytes; - byte* destination = (byte*)destColors; + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color destRef = ref destColors.DangerousGetPinnableReference(); - for (int x = 0; x < count; x++) + for (int i = 0; i < count; i++) { - Unsafe.Write(destination, (uint)(*source << 0 | *(source + 1) << 8 | *(source + 2) << 16 | 255 << 24)); + ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color dp = ref Unsafe.Add(ref destRef, i); - source += 3; - destination += 4; + Unsafe.As(ref dp) = sp; + dp.A = 255; } } /// - internal override unsafe void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - byte* source = (byte*)sourceColors; - byte* destination = (byte*)destBytes; + ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - for (int x = 0; x < count; x++) + for (int i = 0; i < count; i++) { - *destination = *(source + 0); - *(destination + 1) = *(source + 1); - *(destination + 2) = *(source + 2); + ref Color sp = ref Unsafe.Add(ref sourceRef, i); + ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - source += 4; - destination += 3; + dp = Unsafe.As(ref sp); } } /// - internal override void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromXyzwBytes( + BufferSpan sourceBytes, + BufferSpan destColors, + int count) { BufferSpan.Copy(sourceBytes, destColors, count); } @@ -167,87 +171,132 @@ namespace ImageSharp } /// - internal override unsafe void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromZyxBytes( + BufferSpan sourceBytes, + BufferSpan destColors, + int count) { - byte* source = (byte*)sourceBytes; - byte* destination = (byte*)destColors; + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color destRef = ref destColors.DangerousGetPinnableReference(); - for (int x = 0; x < count; x++) + for (int i = 0; i < count; i++) { - Unsafe.Write(destination, (uint)(*(source + 2) << 0 | *(source + 1) << 8 | *source << 16 | 255 << 24)); + ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color dp = ref Unsafe.Add(ref destRef, i); - source += 3; - destination += 4; + Unsafe.As(ref dp) = sp.ToZyx(); + dp.A = 255; } } /// - internal override unsafe void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToZyxBytes( + BufferSpan sourceColors, + BufferSpan destBytes, + int count) { - byte* source = (byte*)sourceColors; - byte* destination = (byte*)destBytes; + ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - for (int x = 0; x < count; x++) + for (int i = 0; i < count; i++) { - *destination = *(source + 2); - *(destination + 1) = *(source + 1); - *(destination + 2) = *(source + 0); + ref Color sp = ref Unsafe.Add(ref sourceRef, i); + ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - source += 4; - destination += 3; + dp = Unsafe.As(ref sp).ToZyx(); } } /// - internal override unsafe void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromZyxwBytes( + BufferSpan sourceBytes, + BufferSpan destColors, + int count) { - byte* source = (byte*)sourceBytes; - byte* destination = (byte*)destColors; + ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color destRef = ref destColors.DangerousGetPinnableReference(); - for (int x = 0; x < count; x++) + for (int i = 0; i < count; i++) { - Unsafe.Write(destination, (uint)(*(source + 2) << 0 | *(source + 1) << 8 | *source << 16 | *(source + 3) << 24)); - - source += 4; - destination += 4; + ref RGBA32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color dp = ref Unsafe.Add(ref destRef, i); + RGBA32 zyxw = sp.ToZyxw(); + dp = Unsafe.As(ref zyxw); } } /// - internal override unsafe void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToZyxwBytes( + BufferSpan sourceColors, + BufferSpan destBytes, + int count) { - byte* source = (byte*)sourceColors; - byte* destination = (byte*)destBytes; + ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - for (int x = 0; x < count; x++) + for (int i = 0; i < count; i++) { - *destination = *(source + 2); - *(destination + 1) = *(source + 1); - *(destination + 2) = *(source + 0); - *(destination + 3) = *(source + 3); - - source += 4; - destination += 4; + ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); + ref RGBA32 dp = ref Unsafe.Add(ref destRef, i); + dp = sp.ToZyxw(); } } + /// + /// Helper struct to manipulate 3-byte RGB data. + /// + [StructLayout(LayoutKind.Sequential)] + private struct RGB24 + { + private byte x; + + private byte y; + + private byte z; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RGB24 ToZyx() => new RGB24 { x = this.z, y = this.y, z = this.x }; + } + + /// + /// Helper struct to manipulate 4-byte RGBA data. + /// + [StructLayout(LayoutKind.Sequential)] + private struct RGBA32 + { + private byte x; + + private byte y; + + private byte z; + + private byte w; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RGBA32 ToZyxw() => new RGBA32 { x = this.z, y = this.y, z = this.x, w = this.w }; + } + /// /// Value type to store -s unpacked into multiple -s. /// + [StructLayout(LayoutKind.Sequential)] private struct UnpackedRGBA { private uint r; + private uint g; + private uint b; + private uint a; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Load(uint p) { this.r = p; - this.g = p >> Color.GreenShift; - this.b = p >> Color.BlueShift; - this.a = p >> Color.AlphaShift; + this.g = p >> GreenShift; + this.b = p >> BlueShift; + this.a = p >> AlphaShift; } } } diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index 597730937..1e1e73bab 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -62,6 +62,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.packedValue = Pack(r, g, b, a); @@ -74,6 +75,7 @@ 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.packedValue = Pack(r, g, b, a); @@ -85,6 +87,7 @@ namespace ImageSharp /// /// The vector containing the components for the packed vector. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Vector3 vector) { this.packedValue = Pack(ref vector); @@ -96,6 +99,7 @@ namespace ImageSharp /// /// The vector containing the components for the packed vector. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Vector4 vector) { this.packedValue = Pack(ref vector); @@ -107,6 +111,7 @@ namespace ImageSharp /// /// The packed value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(uint packed) { this.packedValue = packed; diff --git a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs index 7b6169f9c..a3bd32825 100644 --- a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs +++ b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs @@ -13,14 +13,9 @@ namespace ImageSharp /// for pixel buffers of type . /// /// The pixel format. - public unsafe class BulkPixelOperations + public class BulkPixelOperations where TColor : struct, IPixel { - /// - /// The size of in bytes - /// - private static readonly int ColorSize = Unsafe.SizeOf(); - /// /// Gets the global instance for the pixel type /// @@ -37,18 +32,14 @@ namespace ImageSharp BufferSpan destColors, int count) { - Vector4* sp = (Vector4*)sourceVectors.PointerAtOffset; - byte* dp = (byte*)destColors; + ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference(); + ref TColor destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - Vector4 v = Unsafe.Read(sp); - TColor c = default(TColor); - c.PackFromVector4(v); - Unsafe.Write(dp, c); - - sp++; - dp += ColorSize; + ref Vector4 sp = ref Unsafe.Add(ref sourceRef, i); + ref TColor dp = ref Unsafe.Add(ref destRef, i); + dp.PackFromVector4(sp); } } @@ -63,15 +54,14 @@ namespace ImageSharp BufferSpan destVectors, int count) { - byte* sp = (byte*)sourceColors; - Vector4* dp = (Vector4*)destVectors.PointerAtOffset; + ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - TColor c = Unsafe.Read(sp); - *dp = c.ToVector4(); - sp += ColorSize; - dp++; + ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + ref Vector4 dp = ref Unsafe.Add(ref destRef, i); + dp = sp.ToVector4(); } } @@ -86,16 +76,18 @@ namespace ImageSharp BufferSpan destColors, int count) { - byte* sp = (byte*)sourceBytes; - byte* dp = (byte*)destColors.PointerAtOffset; + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); + ref TColor destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - TColor c = default(TColor); - c.PackFromBytes(sp[0], sp[1], sp[2], 255); - Unsafe.Write(dp, c); - sp += 3; - dp += ColorSize; + int i3 = i * 3; + ref TColor dp = ref Unsafe.Add(ref destRef, i); + dp.PackFromBytes( + Unsafe.Add(ref sourceRef, i3), + Unsafe.Add(ref sourceRef, i3 + 1), + Unsafe.Add(ref sourceRef, i3 + 2), + 255); } } @@ -107,14 +99,13 @@ namespace ImageSharp /// The number of pixels to convert. internal virtual void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - byte* sp = (byte*)sourceColors; + ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; - for (int i = destBytes.Start; i < destBytes.Start + (count * 3); i += 3) + for (int i = 0; i < count; i++) { - TColor c = Unsafe.Read(sp); - c.ToXyzBytes(dest, i); - sp += ColorSize; + ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + sp.ToXyzBytes(dest, i * 3); } } @@ -129,16 +120,18 @@ namespace ImageSharp BufferSpan destColors, int count) { - byte* sp = (byte*)sourceBytes; - byte* dp = (byte*)destColors.PointerAtOffset; + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); + ref TColor destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - TColor c = default(TColor); - c.PackFromBytes(sp[0], sp[1], sp[2], sp[3]); - Unsafe.Write(dp, c); - sp += 4; - dp += ColorSize; + int i4 = i * 4; + ref TColor dp = ref Unsafe.Add(ref destRef, i); + dp.PackFromBytes( + Unsafe.Add(ref sourceRef, i4), + Unsafe.Add(ref sourceRef, i4 + 1), + Unsafe.Add(ref sourceRef, i4 + 2), + Unsafe.Add(ref sourceRef, i4 + 3)); } } @@ -153,14 +146,13 @@ namespace ImageSharp BufferSpan destBytes, int count) { - byte* sp = (byte*)sourceColors; + ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; - for (int i = destBytes.Start; i < destBytes.Start + (count * 4); i += 4) + for (int i = 0; i < count; i++) { - TColor c = Unsafe.Read(sp); - c.ToXyzwBytes(dest, i); - sp += ColorSize; + ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + sp.ToXyzwBytes(dest, i * 4); } } @@ -175,16 +167,18 @@ namespace ImageSharp BufferSpan destColors, int count) { - byte* sp = (byte*)sourceBytes; - byte* dp = (byte*)destColors.PointerAtOffset; + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); + ref TColor destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - TColor c = default(TColor); - c.PackFromBytes(sp[2], sp[1], sp[0], 255); - Unsafe.Write(dp, c); - sp += 3; - dp += ColorSize; + int i3 = i * 3; + ref TColor dp = ref Unsafe.Add(ref destRef, i); + dp.PackFromBytes( + Unsafe.Add(ref sourceRef, i3 + 2), + Unsafe.Add(ref sourceRef, i3 + 1), + Unsafe.Add(ref sourceRef, i3), + 255); } } @@ -196,14 +190,13 @@ namespace ImageSharp /// The number of pixels to convert. internal virtual void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - byte* sp = (byte*)sourceColors; + ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; - for (int i = destBytes.Start; i < destBytes.Start + (count * 3); i += 3) + for (int i = 0; i < count; i++) { - TColor c = Unsafe.Read(sp); - c.ToZyxBytes(dest, i); - sp += ColorSize; + ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + sp.ToZyxBytes(dest, i * 3); } } @@ -218,16 +211,18 @@ namespace ImageSharp BufferSpan destColors, int count) { - byte* sp = (byte*)sourceBytes; - byte* dp = (byte*)destColors.PointerAtOffset; + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); + ref TColor destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - TColor c = default(TColor); - c.PackFromBytes(sp[2], sp[1], sp[0], sp[3]); - Unsafe.Write(dp, c); - sp += 4; - dp += ColorSize; + int i4 = i * 4; + ref TColor dp = ref Unsafe.Add(ref destRef, i); + dp.PackFromBytes( + Unsafe.Add(ref sourceRef, i4 + 2), + Unsafe.Add(ref sourceRef, i4 + 1), + Unsafe.Add(ref sourceRef, i4), + Unsafe.Add(ref sourceRef, i4 + 3)); } } @@ -242,14 +237,13 @@ namespace ImageSharp BufferSpan destBytes, int count) { - byte* sp = (byte*)sourceColors; + ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; - for (int i = destBytes.Start; i < destBytes.Start + (count * 4); i += 4) + for (int i = 0; i < count; i++) { - TColor c = Unsafe.Read(sp); - c.ToZyxwBytes(dest, i); - sp += ColorSize; + ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + sp.ToZyxwBytes(dest, i * 4); } } } diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index 42a6fbc6b..09adadc7d 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -6,7 +6,6 @@ namespace ImageSharp { using System; - using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -49,25 +48,42 @@ namespace ImageSharp } /// - /// Copy 'countInDest' number of elements into 'dest' from a raw byte buffer defined by 'source'. + /// Copy 'countInDest' number of elements into 'dest' from a raw byte buffer defined by 'source'. /// - /// The element type. + /// The element type. /// The raw source buffer to copy from"/> /// The destination buffer"/> - /// The number of elements to copy. + /// The number of elements to copy. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Copy(BufferSpan source, BufferSpan destination, int countInDest) - where T : struct + public static unsafe void Copy(BufferSpan source, BufferSpan destination, int countInDest) + where TDest : struct { - int byteCount = SizeOf(countInDest); + // TODO: Refactor this method when Unsafe.CopyBlock(ref T, ref T) gets available! + int byteCount = SizeOf(countInDest); - if (byteCount > (int)ByteCountThreshold) + if (PerTypeValues.IsPrimitiveType) { - Marshal.Copy(source.Array, source.Start, destination.PointerAtOffset, byteCount); + Buffer.BlockCopy(source.Array, source.ByteOffset, destination.Array, destination.ByteOffset, byteCount); + } + else if (byteCount > ByteCountThreshold) + { + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + + fixed (void* pinnedPtr = &destRef) + { + Marshal.Copy(source.Array, source.Start, (IntPtr)pinnedPtr, byteCount); + } } else { - Unsafe.CopyBlock((void*)destination.PointerAtOffset, (void*)source.PointerAtOffset, (uint)byteCount); + ref byte srcRef = ref source.DangerousGetPinnableReference(); + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + + fixed (void* pinnedSrc = &srcRef) + fixed (void* pinnedDest = &destRef) + { + Unsafe.CopyBlock(pinnedDest, pinnedSrc, (uint)byteCount); + } } } @@ -93,37 +109,77 @@ namespace ImageSharp => (uint)SizeOf(count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe void CopyImpl(BufferSpan source, BufferSpan destination, int count) + private static unsafe void CopyImpl(BufferSpan source, BufferSpan destination, int countInSource) where T : struct where TDest : struct { - int byteCount = SizeOf(count); + // TODO: Refactor this method when Unsafe.CopyBlock(ref T, ref T) gets available! + int byteCount = SizeOf(countInSource); - if (byteCount > ByteCountThreshold) + if (PerTypeValues.IsPrimitiveType && PerTypeValues.IsPrimitiveType) { - if (Unsafe.SizeOf() == sizeof(long)) - { - Marshal.Copy(Unsafe.As(source.Array), source.Start, destination.PointerAtOffset, count); - return; - } - else if (Unsafe.SizeOf() == sizeof(int)) - { - Marshal.Copy(Unsafe.As(source.Array), source.Start, destination.PointerAtOffset, count); - return; - } - else if (Unsafe.SizeOf() == sizeof(short)) + Buffer.BlockCopy(source.Array, source.ByteOffset, destination.Array, destination.ByteOffset, byteCount); + } + else if (byteCount > ByteCountThreshold) + { + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + + fixed (void* pinnedPtr = &destRef) { - Marshal.Copy(Unsafe.As(source.Array), source.Start, destination.PointerAtOffset, count); - return; + IntPtr ptr = (IntPtr)pinnedPtr; + if (Unsafe.SizeOf() == sizeof(long)) + { + Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + } + else if (Unsafe.SizeOf() == sizeof(int)) + { + Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + } + else if (Unsafe.SizeOf() == sizeof(short)) + { + Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + } + else if (Unsafe.SizeOf() == sizeof(byte)) + { + Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + } } - else if (Unsafe.SizeOf() == sizeof(byte)) + } + else + { + ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + + fixed (void* pinnedSrc = &srcRef) + fixed (void* pinnedDest = &destRef) { - Marshal.Copy(Unsafe.As(source.Array), source.Start, destination.PointerAtOffset, count); - return; + Unsafe.CopyBlock(pinnedDest, pinnedSrc, (uint)byteCount); } } + } - Unsafe.CopyBlock((void*)destination.PointerAtOffset, (void*)source.PointerAtOffset, (uint)byteCount); + /// + /// Per-type static value cache for type 'T' + /// + /// The type + internal class PerTypeValues + { + /// + /// Gets a value indicating whether 'T' is a primitive type. + /// + public static readonly bool IsPrimitiveType = + typeof(T) == typeof(byte) || + typeof(T) == typeof(char) || + typeof(T) == typeof(short) || + typeof(T) == typeof(ushort) || + typeof(T) == typeof(int) || + typeof(T) == typeof(uint) || + typeof(T) == typeof(float) || + typeof(T) == typeof(double) || + typeof(T) == typeof(long) || + typeof(T) == typeof(ulong) || + typeof(T) == typeof(IntPtr) || + typeof(T) == typeof(UIntPtr); } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs index 5efa7bc07..25d01631d 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs @@ -30,13 +30,12 @@ namespace ImageSharp /// Initializes a new instance of the struct from a pinned array and an start. /// /// The pinned array - /// Pointer to the beginning of the array /// The index at which to begin the span. /// The length [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan(T[] array, void* pointerToArray, int start, int length) + public BufferSpan(T[] array, int start, int length) { - GuardArrayAndPointer(array, pointerToArray); + GuardArray(array); DebugGuard.MustBeLessThanOrEqualTo(start, array.Length, nameof(start)); DebugGuard.MustBeLessThanOrEqualTo(length, array.Length - start, nameof(length)); @@ -44,41 +43,36 @@ namespace ImageSharp this.Array = array; this.Length = length; this.Start = start; - this.PointerAtOffset = (IntPtr)pointerToArray + (Unsafe.SizeOf() * start); } /// /// Initializes a new instance of the struct from a pinned array and an start. /// /// The pinned array - /// Pointer to the beginning of the array /// The index at which to begin the span. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan(T[] array, void* pointerToArray, int start) + public BufferSpan(T[] array, int start) { - GuardArrayAndPointer(array, pointerToArray); + GuardArray(array); DebugGuard.MustBeLessThanOrEqualTo(start, array.Length, nameof(start)); this.Array = array; this.Length = array.Length - start; this.Start = start; - this.PointerAtOffset = (IntPtr)pointerToArray + (Unsafe.SizeOf() * start); } /// /// Initializes a new instance of the struct from a pinned array. /// /// The pinned array - /// Pointer to the start of 'array' [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan(T[] array, void* pointerToArray) + public BufferSpan(T[] array) { - GuardArrayAndPointer(array, pointerToArray); + GuardArray(array); this.Array = array; this.Start = 0; this.Length = array.Length; - this.PointerAtOffset = (IntPtr)pointerToArray; } /// @@ -101,11 +95,6 @@ namespace ImageSharp /// public int ByteOffset => this.Start * Unsafe.SizeOf(); - /// - /// Gets the pointer to the offseted array position - /// - public IntPtr PointerAtOffset { get; private set; } - /// /// Returns a reference to specified element of the span. /// @@ -117,35 +106,14 @@ namespace ImageSharp get { DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); - - byte* ptr = (byte*)this.PointerAtOffset + BufferSpan.SizeOf(index); - return ref Unsafe.AsRef(ptr); + ref T arrayRef = ref this.DangerousGetPinnableReference(); + return ref Unsafe.Add(ref arrayRef, this.Start); } } - /// - /// Convertes instance to a raw 'void*' pointer - /// - /// The to convert - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static explicit operator void*(BufferSpan bufferSpan) - { - return (void*)bufferSpan.PointerAtOffset; - } - - /// - /// Converts instance to a raw 'byte*' pointer - /// - /// The to convert - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static explicit operator byte*(BufferSpan bufferSpan) - { - return (byte*)bufferSpan.PointerAtOffset; - } - /// /// Converts generic to a of bytes - /// setting it's and to correct values. + /// setting it's to correct value. /// /// The to convert [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -154,7 +122,6 @@ namespace ImageSharp BufferSpan result = default(BufferSpan); result.Array = Unsafe.As(source.Array); result.Start = source.Start * Unsafe.SizeOf(); - result.PointerAtOffset = source.PointerAtOffset; return result; } @@ -164,7 +131,7 @@ namespace ImageSharp /// /// The reference to the 0th element [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T DangerousGetPinnableReference() => ref Unsafe.AsRef((void*)this.PointerAtOffset); + public ref T DangerousGetPinnableReference() => ref this.Array[this.Start]; /// /// Forms a slice out of the given BufferSpan, beginning at 'start'. @@ -179,7 +146,6 @@ namespace ImageSharp BufferSpan result = default(BufferSpan); result.Array = this.Array; result.Start = this.Start + start; - result.PointerAtOffset = this.PointerAtOffset + (Unsafe.SizeOf() * start); result.Length = this.Length - start; return result; } @@ -199,7 +165,6 @@ namespace ImageSharp BufferSpan result = default(BufferSpan); result.Array = this.Array; result.Start = this.Start + start; - result.PointerAtOffset = this.PointerAtOffset + (Unsafe.SizeOf() * start); result.Length = length; return result; } @@ -213,14 +178,8 @@ namespace ImageSharp { DebugGuard.MustBeLessThanOrEqualTo(count, this.Length, nameof(count)); - if (count < 256) - { - Unsafe.InitBlock((void*)this.PointerAtOffset, 0, BufferSpan.USizeOf(count)); - } - else - { - System.Array.Clear(this.Array, this.Start, count); - } + // TODO: Use Unsafe.InitBlock(ref T) for small arrays, when it get's official + System.Array.Clear(this.Array, this.Start, count); } /// @@ -233,13 +192,9 @@ namespace ImageSharp } [Conditional("DEBUG")] - private static void GuardArrayAndPointer(T[] array, void* pointerToArray) + private static void GuardArray(T[] array) { DebugGuard.NotNull(array, nameof(array)); - DebugGuard.IsFalse( - pointerToArray == (void*)0, - nameof(pointerToArray), - "pointerToArray should not be null pointer!"); } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs b/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs index 611688c99..665e92e09 100644 --- a/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs +++ b/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs @@ -126,9 +126,9 @@ namespace ImageSharp /// /// The to convert. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe implicit operator BufferSpan(PinnedBuffer buffer) + public static implicit operator BufferSpan(PinnedBuffer buffer) { - return new BufferSpan(buffer.Array, (void*)buffer.Pointer, 0, buffer.Length); + return new BufferSpan(buffer.Array, 0, buffer.Length); } /// @@ -150,9 +150,9 @@ namespace ImageSharp /// The start /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe BufferSpan Slice(int start) + public BufferSpan Slice(int start) { - return new BufferSpan(this.Array, (void*)this.Pointer, start, this.Length - start); + return new BufferSpan(this.Array, start, this.Length - start); } /// @@ -162,9 +162,9 @@ namespace ImageSharp /// The length of the slice /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe BufferSpan Slice(int start, int length) + public BufferSpan Slice(int start, int length) { - return new BufferSpan(this.Array, (void*)this.Pointer, start, length); + return new BufferSpan(this.Array, start, length); } /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs index 99b143de6..886c05569 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs @@ -41,7 +41,7 @@ namespace ImageSharp.Processing.Processors /// /// Gets an unsafe float* pointer to the beginning of . /// - public float* Ptr => (float*)this.Span.PointerAtOffset; + public ref float Ptr => ref this.Span.DangerousGetPinnableReference(); /// /// Gets the lenghth of the weights window @@ -56,19 +56,18 @@ namespace ImageSharp.Processing.Processors [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ComputeWeightedRowSum(BufferSpan rowSpan) { - float* horizontalValues = this.Ptr; + ref float horizontalValues = ref this.Ptr; int left = this.Left; - Vector4* vecPtr = (Vector4*)rowSpan.PointerAtOffset; - vecPtr += left; + ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left); // Destination color components Vector4 result = Vector4.Zero; for (int i = 0; i < this.Length; i++) { - float weight = horizontalValues[i]; - result += (*vecPtr) * weight; - vecPtr++; + float weight = Unsafe.Add(ref horizontalValues, i); + Vector4 v = Unsafe.Add(ref vecPtr, i); + result += v * weight; } return result; @@ -83,19 +82,18 @@ namespace ImageSharp.Processing.Processors [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ComputeExpandedWeightedRowSum(BufferSpan rowSpan) { - float* horizontalValues = this.Ptr; + ref float horizontalValues = ref this.Ptr; int left = this.Left; - Vector4* vecPtr = (Vector4*)rowSpan.PointerAtOffset; - vecPtr += left; + ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left); // Destination color components Vector4 result = Vector4.Zero; for (int i = 0; i < this.Length; i++) { - float weight = horizontalValues[i]; - result += (*vecPtr).Expand() * weight; - vecPtr++; + float weight = Unsafe.Add(ref horizontalValues, i); + Vector4 v = Unsafe.Add(ref vecPtr, i); + result += v.Expand() * weight; } return result; @@ -111,7 +109,7 @@ namespace ImageSharp.Processing.Processors [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ComputeWeightedColumnSum(PinnedImageBuffer firstPassPixels, int x) { - float* verticalValues = this.Ptr; + ref float verticalValues = ref this.Ptr; int left = this.Left; // Destination color components @@ -119,7 +117,7 @@ namespace ImageSharp.Processing.Processors for (int i = 0; i < this.Length; i++) { - float yw = verticalValues[i]; + float yw = Unsafe.Add(ref verticalValues, i); int index = left + i; result += firstPassPixels[x, index] * yw; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs index 1374e5815..50c75a3fd 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Processing.Processors { using System; using System.Buffers; + using System.Runtime.CompilerServices; using System.Runtime.InteropServices; /// @@ -111,13 +112,15 @@ namespace ImageSharp.Processing.Processors WeightsWindow ws = result.GetWeightsWindow(i, left, right); result.Weights[i] = ws; - float* weights = ws.Ptr; + ref float weights = ref ws.Ptr; for (int j = left; j <= right; j++) { float weight = sampler.GetValue((j - center) / scale); sum += weight; - weights[j - left] = weight; + + // weights[j - left] = weight: + Unsafe.Add(ref weights, j - left) = weight; } // Normalise, best to do it here rather than in the pixel loop later on. @@ -125,7 +128,9 @@ namespace ImageSharp.Processing.Processors { for (int w = 0; w < ws.Length; w++) { - weights[w] = weights[w] / sum; + // weights[w] = weights[w] / sum: + ref float wRef = ref Unsafe.Add(ref weights, w); + wRef = wRef / sum; } } } diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index 32ec5dec6..f2fcb2539 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -1,5 +1,6 @@ // ReSharper disable ObjectCreationAsStatement // ReSharper disable InconsistentNaming + namespace ImageSharp.Tests.Common { using System; @@ -8,9 +9,20 @@ namespace ImageSharp.Tests.Common using Xunit; using static TestStructs; - + public unsafe class BufferSpanTests { + // ReSharper disable once ClassNeverInstantiated.Local + private class Assert : Xunit.Assert + { + public static void SameRefs(ref T1 a, ref T2 b) + { + ref T1 bb = ref Unsafe.As(ref b); + + True(Unsafe.AreSame(ref a, ref bb), "References are not same!"); + } + } + [Fact] public void AsBytes() { @@ -19,10 +31,10 @@ namespace ImageSharp.Tests.Common using (PinnedBuffer colorBuf = new PinnedBuffer(fooz)) { BufferSpan orig = colorBuf.Slice(1); - BufferSpan asBytes = (BufferSpan < byte > )orig; + BufferSpan asBytes = (BufferSpan)orig; Assert.Equal(asBytes.Start, sizeof(Foo)); - Assert.Equal(orig.PointerAtOffset, asBytes.PointerAtOffset); + Assert.SameRefs(ref orig.DangerousGetPinnableReference(), ref asBytes.DangerousGetPinnableReference()); } } @@ -32,16 +44,14 @@ namespace ImageSharp.Tests.Common public void Basic() { Foo[] array = Foo.CreateArray(3); - fixed (Foo* p = array) - { - // Act: - BufferSpan span = new BufferSpan(array, p); - // Assert: - Assert.Equal(array, span.Array); - Assert.Equal((IntPtr)p, span.PointerAtOffset); - Assert.Equal(3, span.Length); - } + // Act: + BufferSpan span = new BufferSpan(array); + + // Assert: + Assert.Equal(array, span.Array); + Assert.Equal(3, span.Length); + Assert.SameRefs(ref array[0], ref span.DangerousGetPinnableReference()); } [Fact] @@ -49,17 +59,15 @@ namespace ImageSharp.Tests.Common { Foo[] array = Foo.CreateArray(4); int start = 2; - fixed (Foo* p = array) - { - // Act: - BufferSpan span = new BufferSpan(array, p, start); - - // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(start, span.Start); - Assert.Equal((IntPtr)(p + start), span.PointerAtOffset); - Assert.Equal(array.Length - start, span.Length); - } + + // Act: + BufferSpan span = new BufferSpan(array, start); + + // Assert: + Assert.Equal(array, span.Array); + Assert.Equal(start, span.Start); + Assert.SameRefs(ref array[start], ref span.DangerousGetPinnableReference()); + Assert.Equal(array.Length - start, span.Length); } [Fact] @@ -68,17 +76,14 @@ namespace ImageSharp.Tests.Common Foo[] array = Foo.CreateArray(10); int start = 2; int length = 3; - fixed (Foo* p = array) - { - // Act: - BufferSpan span = new BufferSpan(array, p, start, length); - - // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(start, span.Start); - Assert.Equal((IntPtr)(p + start), span.PointerAtOffset); - Assert.Equal(length, span.Length); - } + // Act: + BufferSpan span = new BufferSpan(array, start, length); + + // Assert: + Assert.Equal(array, span.Array); + Assert.Equal(start, span.Start); + Assert.SameRefs(ref array[start], ref span.DangerousGetPinnableReference()); + Assert.Equal(length, span.Length); } } @@ -92,19 +97,16 @@ namespace ImageSharp.Tests.Common int start1 = 2; int totalOffset = start0 + start1; - fixed (Foo* p = array) - { - BufferSpan span = new BufferSpan(array, p, start0); + BufferSpan span = new BufferSpan(array, start0); - // Act: - span = span.Slice(start1); + // Act: + span = span.Slice(start1); - // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(totalOffset, span.Start); - Assert.Equal((IntPtr)(p + totalOffset), span.PointerAtOffset); - Assert.Equal(array.Length - totalOffset, span.Length); - } + // Assert: + Assert.Equal(array, span.Array); + Assert.Equal(totalOffset, span.Start); + Assert.SameRefs(ref array[totalOffset], ref span.DangerousGetPinnableReference()); + Assert.Equal(array.Length - totalOffset, span.Length); } [Fact] @@ -116,24 +118,19 @@ namespace ImageSharp.Tests.Common int totalOffset = start0 + start1; int sliceLength = 3; - fixed (Foo* p = array) - { - BufferSpan span = new BufferSpan(array, p, start0); + BufferSpan span = new BufferSpan(array, start0); - // Act: - span = span.Slice(start1, sliceLength); + // Act: + span = span.Slice(start1, sliceLength); - // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(totalOffset, span.Start); - Assert.Equal((IntPtr)(p + totalOffset), span.PointerAtOffset); - Assert.Equal(sliceLength, span.Length); - } + // Assert: + Assert.Equal(array, span.Array); + Assert.Equal(totalOffset, span.Start); + Assert.SameRefs(ref array[totalOffset], ref span.DangerousGetPinnableReference()); + Assert.Equal(sliceLength, span.Length); } } - - [Theory] [InlineData(4)] [InlineData(1500)] @@ -142,21 +139,17 @@ namespace ImageSharp.Tests.Common Foo[] array = Foo.CreateArray(count + 42); int offset = 2; - fixed (Foo* p = array) - { - BufferSpan ap = new BufferSpan(array, p, offset); + BufferSpan ap = new BufferSpan(array, offset); - // Act: - ap.Clear(count); + // Act: + ap.Clear(count); - Assert.NotEqual(default(Foo), array[offset-1]); - Assert.Equal(default(Foo), array[offset]); - Assert.Equal(default(Foo), array[offset + count-1]); - Assert.NotEqual(default(Foo), array[offset + count]); - } + Assert.NotEqual(default(Foo), array[offset - 1]); + Assert.Equal(default(Foo), array[offset]); + Assert.Equal(default(Foo), array[offset + count - 1]); + Assert.NotEqual(default(Foo), array[offset + count]); } - public class Indexer { public static readonly TheoryData IndexerData = @@ -175,14 +168,11 @@ namespace ImageSharp.Tests.Common public void Read(int length, int start, int index) { Foo[] a = Foo.CreateArray(length); - fixed (Foo* p = a) - { - BufferSpan span = new BufferSpan(a, p, start); + BufferSpan span = new BufferSpan(a, start); - Foo element = span[index]; + Foo element = span[index]; - Assert.Equal(a[start + index], element); - } + Assert.Equal(a[start + index], element); } [Theory] @@ -190,14 +180,11 @@ namespace ImageSharp.Tests.Common public void Write(int length, int start, int index) { Foo[] a = Foo.CreateArray(length); - fixed (Foo* p = a) - { - BufferSpan span = new BufferSpan(a, p, start); + BufferSpan span = new BufferSpan(a, start); - span[index] = new Foo(666, 666); + span[index] = new Foo(666, 666); - Assert.Equal(new Foo(666, 666), a[start + index]); - } + Assert.Equal(new Foo(666, 666), a[start + index]); } } @@ -208,13 +195,10 @@ namespace ImageSharp.Tests.Common public void DangerousGetPinnableReference(int start, int length) { Foo[] a = Foo.CreateArray(length); - fixed (Foo* p = a) - { - BufferSpan span = new BufferSpan(a, p, start); - ref Foo r = ref span.DangerousGetPinnableReference(); + BufferSpan span = new BufferSpan(a, start); + ref Foo r = ref span.DangerousGetPinnableReference(); - Assert.True(Unsafe.AreSame(ref a[start], ref r)); - } + Assert.True(Unsafe.AreSame(ref a[start], ref r)); } public class Copy @@ -253,14 +237,10 @@ namespace ImageSharp.Tests.Common Foo[] source = Foo.CreateArray(count + 2); Foo[] dest = new Foo[count + 5]; - fixed (Foo* pSource = source) - fixed (Foo* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource, 1); - BufferSpan apDest = new BufferSpan(dest, pDest, 1); + BufferSpan apSource = new BufferSpan(source, 1); + BufferSpan apDest = new BufferSpan(dest, 1); - BufferSpan.Copy(apSource, apDest, count-1); - } + BufferSpan.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); AssertNotDefault(dest, 1); @@ -268,7 +248,7 @@ namespace ImageSharp.Tests.Common Assert.NotEqual(source[0], dest[0]); Assert.Equal(source[1], dest[1]); Assert.Equal(source[2], dest[2]); - Assert.Equal(source[count-1], dest[count-1]); + Assert.Equal(source[count - 1], dest[count - 1]); Assert.NotEqual(source[count], dest[count]); } @@ -280,14 +260,10 @@ namespace ImageSharp.Tests.Common AlignedFoo[] source = AlignedFoo.CreateArray(count + 2); AlignedFoo[] dest = new AlignedFoo[count + 5]; - fixed (AlignedFoo* pSource = source) - fixed (AlignedFoo* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource, 1); - BufferSpan apDest = new BufferSpan(dest, pDest, 1); + BufferSpan apSource = new BufferSpan(source, 1); + BufferSpan apDest = new BufferSpan(dest, 1); - BufferSpan.Copy(apSource, apDest, count - 1); - } + BufferSpan.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); AssertNotDefault(dest, 1); @@ -304,17 +280,13 @@ namespace ImageSharp.Tests.Common [InlineData(1500)] public void IntToInt(int count) { - int[] source = CreateTestInts(count+2); + int[] source = CreateTestInts(count + 2); int[] dest = new int[count + 5]; - fixed (int* pSource = source) - fixed (int* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource, 1); - BufferSpan apDest = new BufferSpan(dest, pDest, 1); + BufferSpan apSource = new BufferSpan(source, 1); + BufferSpan apDest = new BufferSpan(dest, 1); - BufferSpan.Copy(apSource, apDest, count -1); - } + BufferSpan.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); AssertNotDefault(dest, 1); @@ -332,17 +304,13 @@ namespace ImageSharp.Tests.Common public void GenericToBytes(int count) { int destCount = count * sizeof(Foo); - Foo[] source = Foo.CreateArray(count+2); - byte[] dest = new byte[destCount + sizeof(Foo)*2]; + Foo[] source = Foo.CreateArray(count + 2); + byte[] dest = new byte[destCount + sizeof(Foo) * 2]; - fixed (Foo* pSource = source) - fixed (byte* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource, 1); - BufferSpan apDest = new BufferSpan(dest, pDest, sizeof(Foo)); + BufferSpan apSource = new BufferSpan(source, 1); + BufferSpan apDest = new BufferSpan(dest, sizeof(Foo)); - BufferSpan.Copy(apSource, apDest, count - 1); - } + BufferSpan.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); @@ -362,14 +330,10 @@ namespace ImageSharp.Tests.Common AlignedFoo[] source = AlignedFoo.CreateArray(count + 2); byte[] dest = new byte[destCount + sizeof(AlignedFoo) * 2]; - fixed (AlignedFoo* pSource = source) - fixed (byte* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource, 1); - BufferSpan apDest = new BufferSpan(dest, pDest, sizeof(AlignedFoo)); + BufferSpan apSource = new BufferSpan(source, 1); + BufferSpan apDest = new BufferSpan(dest, sizeof(AlignedFoo)); - BufferSpan.Copy(apSource, apDest, count - 1); - } + BufferSpan.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); @@ -386,17 +350,13 @@ namespace ImageSharp.Tests.Common public void IntToBytes(int count) { int destCount = count * sizeof(int); - int[] source = CreateTestInts(count+2); + int[] source = CreateTestInts(count + 2); byte[] dest = new byte[destCount + sizeof(int) + 1]; - fixed (int* pSource = source) - fixed (byte* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource); - BufferSpan apDest = new BufferSpan(dest, pDest); + BufferSpan apSource = new BufferSpan(source); + BufferSpan apDest = new BufferSpan(dest); - BufferSpan.Copy(apSource, apDest, count); - } + BufferSpan.Copy(apSource, apDest, count); AssertNotDefault(source, 1); @@ -413,15 +373,11 @@ namespace ImageSharp.Tests.Common int srcCount = count * sizeof(Foo); byte[] source = CreateTestBytes(srcCount); Foo[] dest = new Foo[count + 2]; - - fixed(byte* pSource = source) - fixed (Foo* pDest = dest) - { - BufferSpan apSource = new BufferSpan(source, pSource); - BufferSpan apDest = new BufferSpan(dest, pDest); - BufferSpan.Copy(apSource, apDest, count); - } + BufferSpan apSource = new BufferSpan(source); + BufferSpan apDest = new BufferSpan(dest); + + BufferSpan.Copy(apSource, apDest, count); AssertNotDefault(source, sizeof(Foo) + 1); AssertNotDefault(dest, 1); @@ -438,7 +394,7 @@ namespace ImageSharp.Tests.Common Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), }; using (PinnedBuffer colorBuf = new PinnedBuffer(colors)) - using (PinnedBuffer byteBuf = new PinnedBuffer(colors.Length*4)) + using (PinnedBuffer byteBuf = new PinnedBuffer(colors.Length * 4)) { BufferSpan.Copy(colorBuf, byteBuf, colorBuf.Length); @@ -451,7 +407,6 @@ namespace ImageSharp.Tests.Common } } - internal static bool ElementsAreEqual(Foo[] array, byte[] rawArray, int index) { fixed (Foo* pArray = array) diff --git a/tests/ImageSharp.Tests/Common/PinnedBufferTests.cs b/tests/ImageSharp.Tests/Common/PinnedBufferTests.cs index 5e812d5a0..67430976a 100644 --- a/tests/ImageSharp.Tests/Common/PinnedBufferTests.cs +++ b/tests/ImageSharp.Tests/Common/PinnedBufferTests.cs @@ -11,6 +11,19 @@ public unsafe class PinnedBufferTests { + private class Assert : Xunit.Assert + { + public static void SpanPointsTo(IntPtr ptr, BufferSpan span) + where T : struct + { + ref byte r = ref Unsafe.As(ref span.DangerousGetPinnableReference()); + + void* p = Unsafe.AsPointer(ref r); + + Assert.Equal(ptr, (IntPtr)p); + } + } + [Theory] [InlineData(42)] [InlineData(1111)] @@ -121,7 +134,7 @@ Assert.True(buffer.IsDisposedOrLostArrayOwnership); } - + [Theory] [InlineData(7)] [InlineData(123)] @@ -133,7 +146,7 @@ Assert.Equal(buffer.Array, span.Array); Assert.Equal(0, span.Start); - Assert.Equal(buffer.Pointer, span.PointerAtOffset); + Assert.SpanPointsTo(buffer.Pointer, span); Assert.Equal(span.Length, bufferLength); } } @@ -147,7 +160,7 @@ Assert.Equal(buffer.Array, span.Array); Assert.Equal(0, span.Start); - Assert.Equal(buffer.Pointer, span.PointerAtOffset); + Assert.SpanPointsTo(buffer.Pointer, span); Assert.Equal(span.Length, 42); } } @@ -166,7 +179,7 @@ Assert.Equal(buffer.Array, span.Array); Assert.Equal(start, span.Start); - Assert.Equal(buffer.Pointer + start * Unsafe.SizeOf(), span.PointerAtOffset); + Assert.SpanPointsTo(buffer.Pointer + start * Unsafe.SizeOf(), span); Assert.Equal(span.Length, bufferLength - start); } } @@ -182,7 +195,7 @@ Assert.Equal(buffer.Array, span.Array); Assert.Equal(start, span.Start); - Assert.Equal(buffer.Pointer + start * Unsafe.SizeOf(), span.PointerAtOffset); + Assert.SpanPointsTo(buffer.Pointer + start * Unsafe.SizeOf(), span); Assert.Equal(span.Length, spanLength); } } diff --git a/tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs b/tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs index a23f93a70..a8ccea5eb 100644 --- a/tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs +++ b/tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs @@ -1,6 +1,7 @@ // ReSharper disable InconsistentNaming namespace ImageSharp.Tests.Common { + using System; using System.Runtime.CompilerServices; using Xunit; @@ -9,6 +10,20 @@ namespace ImageSharp.Tests.Common public unsafe class PinnedImageBufferTests { + // ReSharper disable once ClassNeverInstantiated.Local + private class Assert : Xunit.Assert + { + public static void SpanPointsTo(IntPtr ptr, BufferSpan span) + where T : struct + { + ref byte r = ref Unsafe.As(ref span.DangerousGetPinnableReference()); + + void* p = Unsafe.AsPointer(ref r); + + Assert.Equal(ptr, (IntPtr)p); + } + } + [Theory] [InlineData(7, 42)] [InlineData(1025, 17)] @@ -65,7 +80,7 @@ namespace ImageSharp.Tests.Common Assert.Equal(width * y, span.Start); Assert.Equal(width, span.Length); - Assert.Equal(buffer.Pointer + sizeof(Foo) * width * y, span.PointerAtOffset); + Assert.SpanPointsTo(buffer.Pointer + sizeof(Foo) * width * y, span); } } @@ -81,7 +96,7 @@ namespace ImageSharp.Tests.Common Assert.Equal(width * y + x, span.Start); Assert.Equal(width - x, span.Length); - Assert.Equal(buffer.Pointer + sizeof(Foo) * (width * y + x), span.PointerAtOffset); + Assert.SpanPointsTo(buffer.Pointer + sizeof(Foo) * (width * y + x), span); } } From ec1aa928c54a6aa9df0ec6d9747c820bc635469e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 12 Apr 2017 03:12:16 +0200 Subject: [PATCH 03/34] fixed DangerousGetPinnableReference() --- src/ImageSharp/Common/Memory/BufferSpan{T}.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs index 25d01631d..23b8bece7 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs @@ -76,7 +76,7 @@ namespace ImageSharp } /// - /// Gets the backing array + /// Gets the backing array. /// public T[] Array { get; private set; } @@ -122,6 +122,7 @@ namespace ImageSharp BufferSpan result = default(BufferSpan); result.Array = Unsafe.As(source.Array); result.Start = source.Start * Unsafe.SizeOf(); + result.Length = source.Length * Unsafe.SizeOf(); return result; } @@ -131,7 +132,11 @@ namespace ImageSharp /// /// The reference to the 0th element [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T DangerousGetPinnableReference() => ref this.Array[this.Start]; + public ref T DangerousGetPinnableReference() + { + ref T origin = ref this.Array[0]; + return ref Unsafe.Add(ref origin, this.Start); + } /// /// Forms a slice out of the given BufferSpan, beginning at 'start'. From d8e0efa14b105374eb49b7680bbfd9e5d21639a1 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 12 Apr 2017 13:00:31 +0200 Subject: [PATCH 04/34] fixed copy --- src/ImageSharp/Common/Memory/BufferSpan.cs | 65 ++++++++++++++-------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index 09adadc7d..6dad393c3 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -64,26 +64,34 @@ namespace ImageSharp if (PerTypeValues.IsPrimitiveType) { Buffer.BlockCopy(source.Array, source.ByteOffset, destination.Array, destination.ByteOffset, byteCount); + return; } - else if (byteCount > ByteCountThreshold) - { - ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); - fixed (void* pinnedPtr = &destRef) + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + + fixed (void* pinnedDest = &destRef) + { +#if !NETSTANDARD1_1 + ref byte srcRef = ref source.DangerousGetPinnableReference(); + fixed (void* pinnedSrc = &srcRef) { - Marshal.Copy(source.Array, source.Start, (IntPtr)pinnedPtr, byteCount); + Buffer.MemoryCopy(pinnedSrc, pinnedDest, byteCount, byteCount); + return; } - } - else - { +#else + if (byteCount > ByteCountThreshold) + { + IntPtr ptr = (IntPtr)pinnedDest; + Marshal.Copy(source.Array, source.Start, ptr, byteCount); + } + ref byte srcRef = ref source.DangerousGetPinnableReference(); - ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); fixed (void* pinnedSrc = &srcRef) - fixed (void* pinnedDest = &destRef) { - Unsafe.CopyBlock(pinnedDest, pinnedSrc, (uint)byteCount); + Unsafe.CopyBlock(pinnedSrc, pinnedDest, (uint)byteCount); } +#endif } } @@ -113,48 +121,59 @@ namespace ImageSharp where T : struct where TDest : struct { - // TODO: Refactor this method when Unsafe.CopyBlock(ref T, ref T) gets available! + // TODO: Use Unsafe.CopyBlock(ref T, ref T) for small buffers when it gets available! int byteCount = SizeOf(countInSource); if (PerTypeValues.IsPrimitiveType && PerTypeValues.IsPrimitiveType) { Buffer.BlockCopy(source.Array, source.ByteOffset, destination.Array, destination.ByteOffset, byteCount); + return; } - else if (byteCount > ByteCountThreshold) - { - ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); - fixed (void* pinnedPtr = &destRef) + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + + fixed (void* pinnedDest = &destRef) + { +#if !NETSTANDARD1_1 + ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); + fixed (void* pinnedSrc = &srcRef) { - IntPtr ptr = (IntPtr)pinnedPtr; + Buffer.MemoryCopy(pinnedSrc, pinnedDest, byteCount, byteCount); + return; + } +#else + if (byteCount > ByteCountThreshold) + { + IntPtr ptr = (IntPtr)pinnedDest; if (Unsafe.SizeOf() == sizeof(long)) { Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + return; } else if (Unsafe.SizeOf() == sizeof(int)) { Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + return; } else if (Unsafe.SizeOf() == sizeof(short)) { Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + return; } else if (Unsafe.SizeOf() == sizeof(byte)) { Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); + return; } } - } - else - { + ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); - ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); fixed (void* pinnedSrc = &srcRef) - fixed (void* pinnedDest = &destRef) { - Unsafe.CopyBlock(pinnedDest, pinnedSrc, (uint)byteCount); + Unsafe.CopyBlock(pinnedSrc, pinnedDest, (uint)byteCount); } +#endif } } From 0aca7275e5e3bd8deb9e1883088d0a18f2af7cf5 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 12 Apr 2017 14:39:35 +0200 Subject: [PATCH 05/34] additional PixelIndexing benchmarks --- .../General/PixelIndexing.cs | 68 +++++++++++++++---- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index 8dc8744eb..bc5c85002 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -24,12 +24,15 @@ private Pinnable pinnable; + private Vector4[] array; + private int width; public Data(PinnedImageBuffer buffer) { this.pointer = (Vector4*)buffer.Pointer; this.pinnable = Unsafe.As>(buffer.Array); + this.array = buffer.Array; this.width = buffer.Width; } @@ -69,22 +72,38 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void IndexWithPointersSrcsUnsafeImpl(int x, int y, Vector4 v) { + // incorrect, because also should add byte offset here Unsafe.Write((byte*)this.pointer + (((y * this.width) + x) * Unsafe.SizeOf()), v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void IndexWithReferencesImpl(int x, int y, Vector4 v) + public void IndexWithReferencesOnPinnableIncorrectImpl(int x, int y, Vector4 v) { int elementOffset = (y * this.width) + x; + // incorrect, because also should add byte offset here Unsafe.Add(ref this.pinnable.Data, elementOffset) = v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref Vector4 IndexWithReferencesRefReturnImpl(int x, int y) + public ref Vector4 IndexWithReferencesOnPinnableIncorrectRefReturnImpl(int x, int y) { int elementOffset = (y * this.width) + x; return ref Unsafe.Add(ref this.pinnable.Data, elementOffset); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void IndexWithReferencesOnArrayImpl(int x, int y, Vector4 v) + { + int elementOffset = (y * this.width) + x; + Unsafe.Add(ref this.array[0], elementOffset) = v; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref Vector4 IndexWithReferencesOnArrayRefReturnImpl(int x, int y) + { + int elementOffset = (y * this.width) + x; + return ref Unsafe.Add(ref this.array[0], elementOffset); + } } internal PinnedImageBuffer buffer; @@ -101,7 +120,7 @@ protected Pinnable pinnable; - [Params(64, 256, 1024)] + [Params(1024)] public int Count { get; set; } [Setup] @@ -169,7 +188,7 @@ return sum; } - [Benchmark(Description = "Index.Get: References+refreturns")] + [Benchmark(Description = "Index.Get: References|refreturns")] public Vector4 IndexWithReferencesRefReturns() { Vector4 sum = Vector4.Zero; @@ -186,7 +205,7 @@ public unsafe class PixelIndexingSetter : PixelIndexing { - [Benchmark(Description = "Index.Set: Pointers+arithmetics", Baseline = true)] + [Benchmark(Description = "Index.Set: Pointers|arithmetics", Baseline = true)] public void IndexWithPointersBasic() { Vector4 v = new Vector4(1, 2, 3, 4); @@ -198,7 +217,7 @@ } } - [Benchmark(Description = "Index.Set: Pointers+SRCS.Unsafe")] + [Benchmark(Description = "Index.Set: Pointers|SRCS.Unsafe")] public void IndexWithPointersSrcsUnsafe() { Vector4 v = new Vector4(1, 2, 3, 4); @@ -210,29 +229,54 @@ } } - [Benchmark(Description = "Index.Set: References")] - public void IndexWithReferencesBasic() + [Benchmark(Description = "Index.Set: References|IncorrectPinnable")] + public void IndexWithReferencesPinnableBasic() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + data.IndexWithReferencesOnPinnableIncorrectImpl(i, i, v); + } + } + + [Benchmark(Description = "Index.Set: References|IncorrectPinnable|refreturn")] + public void IndexWithReferencesPinnableRefReturn() { Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); for (int i = this.startIndex; i < this.endIndex; i++) { - data.IndexWithReferencesImpl(i, i, v); + data.IndexWithReferencesOnPinnableIncorrectRefReturnImpl(i, i) = v; } } - [Benchmark(Description = "Index.Set: References+refreturn")] - public void IndexWithReferencesRefReturn() + + + [Benchmark(Description = "Index.Set: References|Array[0]")] + public void IndexWithReferencesArrayBasic() { Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); for (int i = this.startIndex; i < this.endIndex; i++) { - data.IndexWithReferencesRefReturnImpl(i, i) = v; + data.IndexWithReferencesOnArrayImpl(i, i, v); } } + [Benchmark(Description = "Index.Set: References|Array[0]|refreturn")] + public void IndexWithReferencesArrayRefReturn() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + for (int i = this.startIndex; i < this.endIndex; i++) + { + data.IndexWithReferencesOnArrayRefReturnImpl(i, i) = v; + } + } } } \ No newline at end of file From 497279b0df113aca7536e6eb6e5f24c2d19cdcfc Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 13 Apr 2017 00:05:20 +0200 Subject: [PATCH 06/34] PixelIndexing.SmartUnsafe() benchmark --- .../General/PixelIndexing.cs | 84 ++++++++++++------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index bc5c85002..3bc874317 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -5,6 +5,7 @@ using BenchmarkDotNet.Attributes; + // Pixel indexing benchmarks compare different methods for getting/setting all pixel values in a subsegment of a single pixel row. public abstract unsafe class PixelIndexing { /// @@ -72,7 +73,6 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void IndexWithPointersSrcsUnsafeImpl(int x, int y, Vector4 v) { - // incorrect, because also should add byte offset here Unsafe.Write((byte*)this.pointer + (((y * this.width) + x) * Unsafe.SizeOf()), v); } @@ -80,7 +80,7 @@ public void IndexWithReferencesOnPinnableIncorrectImpl(int x, int y, Vector4 v) { int elementOffset = (y * this.width) + x; - // incorrect, because also should add byte offset here + // Incorrect, because also should add a runtime-specific byte offset here. See https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System/Span.cs#L68 Unsafe.Add(ref this.pinnable.Data, elementOffset) = v; } @@ -88,6 +88,7 @@ public ref Vector4 IndexWithReferencesOnPinnableIncorrectRefReturnImpl(int x, int y) { int elementOffset = (y * this.width) + x; + // Incorrect, because also should add a runtime-specific byte offset here. See https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System/Span.cs#L68 return ref Unsafe.Add(ref this.pinnable.Data, elementOffset); } @@ -120,8 +121,8 @@ protected Pinnable pinnable; - [Params(1024)] - public int Count { get; set; } + // [Params(1024)] + public int Count { get; set; } = 1024; [Setup] public void Setup() @@ -144,17 +145,17 @@ } - public unsafe class PixelIndexingGetter : PixelIndexing + public class PixelIndexingGetter : PixelIndexing { [Benchmark(Description = "Index.Get: Pointers+arithmetics", Baseline = true)] public Vector4 IndexWithPointersBasic() { Vector4 sum = Vector4.Zero; Data data = new Data(this.buffer); - - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - sum += data.GetPointersBasicImpl(i, i); + sum += data.GetPointersBasicImpl(x, y); } return sum; @@ -166,9 +167,10 @@ Vector4 sum = Vector4.Zero; Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - sum += data.GetPointersSrcsUnsafeImpl(i, i); + sum += data.GetPointersSrcsUnsafeImpl(x, y); } return sum; @@ -180,9 +182,10 @@ Vector4 sum = Vector4.Zero; Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - sum += data.GetReferencesImpl(i, i); + sum += data.GetReferencesImpl(x, y); } return sum; @@ -194,16 +197,17 @@ Vector4 sum = Vector4.Zero; Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - sum += data.GetReferencesRefReturnsImpl(i, i); + sum += data.GetReferencesRefReturnsImpl(x, y); } return sum; } } - public unsafe class PixelIndexingSetter : PixelIndexing + public class PixelIndexingSetter : PixelIndexing { [Benchmark(Description = "Index.Set: Pointers|arithmetics", Baseline = true)] public void IndexWithPointersBasic() @@ -211,9 +215,10 @@ Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithPointersBasicImpl(i, i, v); + data.IndexWithPointersBasicImpl(x, y, v); } } @@ -223,9 +228,10 @@ Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithPointersSrcsUnsafeImpl(i, i, v); + data.IndexWithPointersSrcsUnsafeImpl(x, y, v); } } @@ -235,9 +241,10 @@ Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithReferencesOnPinnableIncorrectImpl(i, i, v); + data.IndexWithReferencesOnPinnableIncorrectImpl(x, y, v); } } @@ -247,23 +254,23 @@ Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithReferencesOnPinnableIncorrectRefReturnImpl(i, i) = v; + data.IndexWithReferencesOnPinnableIncorrectRefReturnImpl(x, y) = v; } } - - [Benchmark(Description = "Index.Set: References|Array[0]")] public void IndexWithReferencesArrayBasic() { Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithReferencesOnArrayImpl(i, i, v); + data.IndexWithReferencesOnArrayImpl(x, y, v); } } @@ -273,9 +280,28 @@ Vector4 v = new Vector4(1, 2, 3, 4); Data data = new Data(this.buffer); - for (int i = this.startIndex; i < this.endIndex; i++) + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) + { + data.IndexWithReferencesOnArrayRefReturnImpl(x, y) = v; + } + } + + [Benchmark(Description = "Index.Set: SmartUnsafe")] + public void SmartUnsafe() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + // This method is basically an unsafe variant of .GetRowSpan(y) + indexing individual pixels in the row. + // If a user seriously needs by-pixel manipulation to be performant, we should provide this option. + + ref Vector4 rowStart = ref data.IndexWithReferencesOnArrayRefReturnImpl(this.startIndex, this.startIndex); + + for (int i = 0; i < this.Count; i++) { - data.IndexWithReferencesOnArrayRefReturnImpl(i, i) = v; + // We don't have to add 'Width * y' here! + Unsafe.Add(ref rowStart, i) = v; } } } From 6e14748acdaa15e3ec51360f27623b522e598b8a Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 13 Apr 2017 00:31:31 +0200 Subject: [PATCH 07/34] more PixelIndexing benchmark clenup --- .../General/PixelIndexing.cs | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index 3bc874317..a5fa5d0f2 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -93,18 +93,36 @@ } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void IndexWithReferencesOnArrayImpl(int x, int y, Vector4 v) + public void IndexWithUnsafeReferenceArithmeticsOnArray0Impl(int x, int y, Vector4 v) { int elementOffset = (y * this.width) + x; Unsafe.Add(ref this.array[0], elementOffset) = v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref Vector4 IndexWithReferencesOnArrayRefReturnImpl(int x, int y) + public ref Vector4 IndexWithUnsafeReferenceArithmeticsOnArray0RefReturnImpl(int x, int y) { int elementOffset = (y * this.width) + x; return ref Unsafe.Add(ref this.array[0], elementOffset); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void IndexSetArrayStraightforward(int x, int y, Vector4 v) + { + // No magic. + // We just index right into the array as normal people do. + // And it looks like this is the fastest way! + this.array[(y * this.width) + x] = v; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref Vector4 IndexWithReferencesOnArrayStraightforwardRefReturnImpl(int x, int y) + { + // No magic. + // We just index right into the array as normal people do. + // And it looks like this is the fastest way! + return ref this.array[(y * this.width) + x]; + } } internal PinnedImageBuffer buffer; @@ -209,7 +227,7 @@ public class PixelIndexingSetter : PixelIndexing { - [Benchmark(Description = "Index.Set: Pointers|arithmetics", Baseline = true)] + [Benchmark(Description = "!!! Index.Set: Pointers|arithmetics", Baseline = true)] public void IndexWithPointersBasic() { Vector4 v = new Vector4(1, 2, 3, 4); @@ -261,7 +279,7 @@ } } - [Benchmark(Description = "Index.Set: References|Array[0]")] + [Benchmark(Description = "Index.Set: References|Array[0]Unsafe")] public void IndexWithReferencesArrayBasic() { Vector4 v = new Vector4(1, 2, 3, 4); @@ -270,11 +288,11 @@ int y = this.startIndex; for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithReferencesOnArrayImpl(x, y, v); + data.IndexWithUnsafeReferenceArithmeticsOnArray0Impl(x, y, v); } } - [Benchmark(Description = "Index.Set: References|Array[0]|refreturn")] + [Benchmark(Description = "Index.Set: References|Array[0]Unsafe|refreturn")] public void IndexWithReferencesArrayRefReturn() { Vector4 v = new Vector4(1, 2, 3, 4); @@ -283,11 +301,44 @@ int y = this.startIndex; for (int x = this.startIndex; x < this.endIndex; x++) { - data.IndexWithReferencesOnArrayRefReturnImpl(x, y) = v; + data.IndexWithUnsafeReferenceArithmeticsOnArray0RefReturnImpl(x, y) = v; + } + } + + [Benchmark(Description = "!!! Index.Set: References|Array+Straight")] + public void IndexWithReferencesArrayStraightforward() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) + { + // No magic. + // We just index right into the array as normal people do. + // And it looks like this is the fastest way! + data.IndexSetArrayStraightforward(x, y, v); + } + } + + + [Benchmark(Description = "!!! Index.Set: References|Array+Straight|refreturn")] + public void IndexWithReferencesArrayStraightforwardRefReturn() + { + Vector4 v = new Vector4(1, 2, 3, 4); + Data data = new Data(this.buffer); + + int y = this.startIndex; + for (int x = this.startIndex; x < this.endIndex; x++) + { + // No magic. + // We just index right into the array as normal people do. + // And it looks like this is the fastest way! + data.IndexWithReferencesOnArrayStraightforwardRefReturnImpl(x, y) = v; } } - [Benchmark(Description = "Index.Set: SmartUnsafe")] + [Benchmark(Description = "!!! Index.Set: SmartUnsafe")] public void SmartUnsafe() { Vector4 v = new Vector4(1, 2, 3, 4); @@ -296,7 +347,7 @@ // This method is basically an unsafe variant of .GetRowSpan(y) + indexing individual pixels in the row. // If a user seriously needs by-pixel manipulation to be performant, we should provide this option. - ref Vector4 rowStart = ref data.IndexWithReferencesOnArrayRefReturnImpl(this.startIndex, this.startIndex); + ref Vector4 rowStart = ref data.IndexWithReferencesOnArrayStraightforwardRefReturnImpl(this.startIndex, this.startIndex); for (int i = 0; i < this.Count; i++) { From 548fc417113976c95ccfbfb2458b3082730a4cbb Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 13 Apr 2017 02:24:59 +0200 Subject: [PATCH 08/34] fixed indexer and copy operations --- src/ImageSharp/Colors/Color.BulkOperations.cs | 10 +- src/ImageSharp/Common/Memory/BufferSpan.cs | 158 ++---------------- src/ImageSharp/Common/Memory/BufferSpan{T}.cs | 16 +- .../Colors/BulkPixelOperationsTests.cs | 4 +- .../Common/BufferSpanTests.cs | 35 +++- tests/ImageSharp.Tests/Common/TestStructs.cs | 2 + 6 files changed, 59 insertions(+), 166 deletions(-) diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 08d70330d..d5c55ba81 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -90,7 +90,7 @@ namespace ImageSharp vf.CopyTo(fTemp, i); } - BufferSpan.Copy(tempBuf, (BufferSpan)destVectors, unpackedRawCount); + BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount); } } @@ -156,18 +156,18 @@ namespace ImageSharp } /// - internal override void PackFromXyzwBytes( + internal override unsafe void PackFromXyzwBytes( BufferSpan sourceBytes, BufferSpan destColors, int count) { - BufferSpan.Copy(sourceBytes, destColors, count); + BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color)); } /// - internal override void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - BufferSpan.Copy(sourceColors, destBytes, count); + BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Color)); } /// diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index 6dad393c3..5db1cd7da 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -14,11 +14,6 @@ namespace ImageSharp /// internal static class BufferSpan { - /// - /// It's worth to use Marshal.Copy() or Buffer.BlockCopy() over this size. - /// - private const int ByteCountThreshold = 1024; - /// /// Copy 'count' number of elements of the same type from 'source' to 'dest' /// @@ -27,69 +22,29 @@ namespace ImageSharp /// The destination . /// The number of elements to copy [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy(BufferSpan source, BufferSpan destination, int count) + public static unsafe void Copy(BufferSpan source, BufferSpan destination, int count) where T : struct { - CopyImpl(source, destination, count); - } - - /// - /// Copy 'countInSource' elements of from 'source' into the raw byte buffer 'destination'. - /// - /// The element type. - /// The source buffer of elements to copy from. - /// The destination buffer. - /// The number of elements to copy from 'source' - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy(BufferSpan source, BufferSpan destination, int countInSource) - where T : struct - { - CopyImpl(source, destination, countInSource); - } - - /// - /// Copy 'countInDest' number of elements into 'dest' from a raw byte buffer defined by 'source'. - /// - /// The element type. - /// The raw source buffer to copy from"/> - /// The destination buffer"/> - /// The number of elements to copy. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Copy(BufferSpan source, BufferSpan destination, int countInDest) - where TDest : struct - { - // TODO: Refactor this method when Unsafe.CopyBlock(ref T, ref T) gets available! - int byteCount = SizeOf(countInDest); - - if (PerTypeValues.IsPrimitiveType) - { - Buffer.BlockCopy(source.Array, source.ByteOffset, destination.Array, destination.ByteOffset, byteCount); - return; - } + ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); + ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); - ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); + int byteCount = Unsafe.SizeOf() * count; - fixed (void* pinnedDest = &destRef) + // TODO: Use unfixed Unsafe.CopyBlock(ref T, ref T, int) for small blocks, when it gets available! + fixed (byte* pSrc = &srcRef) + fixed (byte* pDest = &destRef) { -#if !NETSTANDARD1_1 - ref byte srcRef = ref source.DangerousGetPinnableReference(); - fixed (void* pinnedSrc = &srcRef) - { - Buffer.MemoryCopy(pinnedSrc, pinnedDest, byteCount, byteCount); - return; - } +#if NETSTANDARD1_1 + Unsafe.CopyBlock(pDest, pSrc, (uint) byteCount); #else - if (byteCount > ByteCountThreshold) + if (byteCount > 512) { - IntPtr ptr = (IntPtr)pinnedDest; - Marshal.Copy(source.Array, source.Start, ptr, byteCount); + int destLength = destination.Length * Unsafe.SizeOf(); + Buffer.MemoryCopy(pSrc, pDest, destLength, byteCount); } - - ref byte srcRef = ref source.DangerousGetPinnableReference(); - - fixed (void* pinnedSrc = &srcRef) + else { - Unsafe.CopyBlock(pinnedSrc, pinnedDest, (uint)byteCount); + Unsafe.CopyBlock(pDest, pSrc, (uint)byteCount); } #endif } @@ -115,90 +70,5 @@ namespace ImageSharp public static uint USizeOf(int count) where T : struct => (uint)SizeOf(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe void CopyImpl(BufferSpan source, BufferSpan destination, int countInSource) - where T : struct - where TDest : struct - { - // TODO: Use Unsafe.CopyBlock(ref T, ref T) for small buffers when it gets available! - int byteCount = SizeOf(countInSource); - - if (PerTypeValues.IsPrimitiveType && PerTypeValues.IsPrimitiveType) - { - Buffer.BlockCopy(source.Array, source.ByteOffset, destination.Array, destination.ByteOffset, byteCount); - return; - } - - ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); - - fixed (void* pinnedDest = &destRef) - { -#if !NETSTANDARD1_1 - ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); - fixed (void* pinnedSrc = &srcRef) - { - Buffer.MemoryCopy(pinnedSrc, pinnedDest, byteCount, byteCount); - return; - } -#else - if (byteCount > ByteCountThreshold) - { - IntPtr ptr = (IntPtr)pinnedDest; - if (Unsafe.SizeOf() == sizeof(long)) - { - Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); - return; - } - else if (Unsafe.SizeOf() == sizeof(int)) - { - Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); - return; - } - else if (Unsafe.SizeOf() == sizeof(short)) - { - Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); - return; - } - else if (Unsafe.SizeOf() == sizeof(byte)) - { - Marshal.Copy(Unsafe.As(source.Array), source.Start, ptr, countInSource); - return; - } - } - - ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); - - fixed (void* pinnedSrc = &srcRef) - { - Unsafe.CopyBlock(pinnedSrc, pinnedDest, (uint)byteCount); - } -#endif - } - } - - /// - /// Per-type static value cache for type 'T' - /// - /// The type - internal class PerTypeValues - { - /// - /// Gets a value indicating whether 'T' is a primitive type. - /// - public static readonly bool IsPrimitiveType = - typeof(T) == typeof(byte) || - typeof(T) == typeof(char) || - typeof(T) == typeof(short) || - typeof(T) == typeof(ushort) || - typeof(T) == typeof(int) || - typeof(T) == typeof(uint) || - typeof(T) == typeof(float) || - typeof(T) == typeof(double) || - typeof(T) == typeof(long) || - typeof(T) == typeof(ulong) || - typeof(T) == typeof(IntPtr) || - typeof(T) == typeof(UIntPtr); - } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs index 23b8bece7..d61f7f77c 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs @@ -106,23 +106,23 @@ namespace ImageSharp get { DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); - ref T arrayRef = ref this.DangerousGetPinnableReference(); - return ref Unsafe.Add(ref arrayRef, this.Start); + ref T startRef = ref this.DangerousGetPinnableReference(); + return ref Unsafe.Add(ref startRef, index); } } /// /// Converts generic to a of bytes - /// setting it's to correct value. + /// setting it's and to correct values. /// - /// The to convert + /// The span of bytes [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static explicit operator BufferSpan(BufferSpan source) + public BufferSpan AsBytes() { BufferSpan result = default(BufferSpan); - result.Array = Unsafe.As(source.Array); - result.Start = source.Start * Unsafe.SizeOf(); - result.Length = source.Length * Unsafe.SizeOf(); + result.Array = Unsafe.As(this.Array); + result.Start = this.Start * Unsafe.SizeOf(); + result.Length = this.Length * Unsafe.SizeOf(); return result; } diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs index 60e25aa04..fe005ad01 100644 --- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests.Colors } // For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class: - public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; + //public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; [Fact] public void IsSpecialImplementation() @@ -66,7 +66,7 @@ namespace ImageSharp.Tests.Colors { } - public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; + //public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; } [Theory] diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index f2fcb2539..58a217b18 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -31,13 +31,14 @@ namespace ImageSharp.Tests.Common using (PinnedBuffer colorBuf = new PinnedBuffer(fooz)) { BufferSpan orig = colorBuf.Slice(1); - BufferSpan asBytes = (BufferSpan)orig; + BufferSpan asBytes = orig.AsBytes(); Assert.Equal(asBytes.Start, sizeof(Foo)); + Assert.Equal(orig.Length * Unsafe.SizeOf(), asBytes.Length); Assert.SameRefs(ref orig.DangerousGetPinnableReference(), ref asBytes.DangerousGetPinnableReference()); } } - + public class Construct { [Fact] @@ -186,6 +187,26 @@ namespace ImageSharp.Tests.Common Assert.Equal(new Foo(666, 666), a[start + index]); } + + [Theory] + [InlineData(10, 0, 0, 5)] + [InlineData(10, 1, 1, 5)] + [InlineData(10, 1, 1, 6)] + [InlineData(10, 1, 1, 7)] + public void AsBytes_Read(int length, int start, int index, int byteOffset) + { + Foo[] a = Foo.CreateArray(length); + BufferSpan span = new BufferSpan(a, start); + + BufferSpan bytes = span.AsBytes(); + + byte actual = bytes[index * Unsafe.SizeOf() + byteOffset]; + + ref byte baseRef = ref Unsafe.As(ref a[0]); + byte expected = Unsafe.Add(ref baseRef, (start + index) * Unsafe.SizeOf() + byteOffset); + + Assert.Equal(expected, actual); + } } [Theory] @@ -310,7 +331,7 @@ namespace ImageSharp.Tests.Common BufferSpan apSource = new BufferSpan(source, 1); BufferSpan apDest = new BufferSpan(dest, sizeof(Foo)); - BufferSpan.Copy(apSource, apDest, count - 1); + BufferSpan.Copy(apSource.AsBytes(), apDest, (count - 1)*sizeof(Foo)); AssertNotDefault(source, 1); @@ -333,7 +354,7 @@ namespace ImageSharp.Tests.Common BufferSpan apSource = new BufferSpan(source, 1); BufferSpan apDest = new BufferSpan(dest, sizeof(AlignedFoo)); - BufferSpan.Copy(apSource, apDest, count - 1); + BufferSpan.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(AlignedFoo)); AssertNotDefault(source, 1); @@ -356,7 +377,7 @@ namespace ImageSharp.Tests.Common BufferSpan apSource = new BufferSpan(source); BufferSpan apDest = new BufferSpan(dest); - BufferSpan.Copy(apSource, apDest, count); + BufferSpan.Copy(apSource.AsBytes(), apDest, count*sizeof(int)); AssertNotDefault(source, 1); @@ -377,7 +398,7 @@ namespace ImageSharp.Tests.Common BufferSpan apSource = new BufferSpan(source); BufferSpan apDest = new BufferSpan(dest); - BufferSpan.Copy(apSource, apDest, count); + BufferSpan.Copy(apSource, apDest.AsBytes(), count*sizeof(Foo)); AssertNotDefault(source, sizeof(Foo) + 1); AssertNotDefault(dest, 1); @@ -396,7 +417,7 @@ namespace ImageSharp.Tests.Common using (PinnedBuffer colorBuf = new PinnedBuffer(colors)) using (PinnedBuffer byteBuf = new PinnedBuffer(colors.Length * 4)) { - BufferSpan.Copy(colorBuf, byteBuf, colorBuf.Length); + BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length*sizeof(Color)); byte[] a = byteBuf.Array; diff --git a/tests/ImageSharp.Tests/Common/TestStructs.cs b/tests/ImageSharp.Tests/Common/TestStructs.cs index 9e762bbd1..f7f09bea2 100644 --- a/tests/ImageSharp.Tests/Common/TestStructs.cs +++ b/tests/ImageSharp.Tests/Common/TestStructs.cs @@ -25,6 +25,8 @@ namespace ImageSharp.Tests.Common } return result; } + + public override string ToString() => $"({this.A},{this.B})"; } From 0e96fd4c96f33d438e99af9c331ef4a0ea195787 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 13 Apr 2017 02:39:19 +0200 Subject: [PATCH 09/34] fixed ToVector4SimdAligned() --- src/ImageSharp/Colors/Color.BulkOperations.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index d5c55ba81..d80941615 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -64,18 +64,20 @@ namespace ImageSharp ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); - using (PinnedBuffer tempBuf = new PinnedBuffer(unpackedRawCount + Vector.Count)) + using (PinnedBuffer tempBuf = new PinnedBuffer( + unpackedRawCount + Vector.Count)) { uint* tPtr = (uint*)tempBuf.Pointer; uint[] temp = tempBuf.Array; float[] fTemp = Unsafe.As(temp); UnpackedRGBA* dst = (UnpackedRGBA*)tPtr; - for (int i = 0; i < count; i++) + for (int i = 0; i < count; i++, dst++) { + uint sVal = Unsafe.Add(ref src, i); + // This call is the bottleneck now: - ref uint sp = ref Unsafe.Add(ref src, i); - dst->Load(sp); + dst->Load(sVal); } for (int i = 0; i < unpackedRawCount; i += vecSize) @@ -90,7 +92,7 @@ namespace ImageSharp vf.CopyTo(fTemp, i); } - BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount); + BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint)); } } From 819e048a5395193416c039277cb2d57dddcebee9 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 13 Apr 2017 02:57:04 +0200 Subject: [PATCH 10/34] fix CopyTo***Bytes() --- .../Colors/PackedPixel/BulkPixelOperations{TColor}.cs | 8 ++++---- src/ImageSharp/Common/Memory/BufferSpan.cs | 2 +- tests/ImageSharp.Benchmarks/General/PixelIndexing.cs | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs index a3bd32825..ccb1c2261 100644 --- a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs +++ b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs @@ -105,7 +105,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToXyzBytes(dest, i * 3); + sp.ToXyzBytes(dest, destBytes.Start + (i * 3)); } } @@ -152,7 +152,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToXyzwBytes(dest, i * 4); + sp.ToXyzwBytes(dest, destBytes.Start + (i * 4)); } } @@ -196,7 +196,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToZyxBytes(dest, i * 3); + sp.ToZyxBytes(dest, destBytes.Start + (i * 3)); } } @@ -243,7 +243,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToZyxwBytes(dest, i * 4); + sp.ToZyxwBytes(dest, destBytes.Start + (i * 4)); } } } diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index 5db1cd7da..cf5d99746 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -35,7 +35,7 @@ namespace ImageSharp fixed (byte* pDest = &destRef) { #if NETSTANDARD1_1 - Unsafe.CopyBlock(pDest, pSrc, (uint) byteCount); + Unsafe.CopyBlock(pDest, pSrc, (uint)byteCount); #else if (byteCount > 512) { diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index a5fa5d0f2..6db0eef36 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -46,6 +46,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 GetPointersSrcsUnsafeImpl(int x, int y) { + // This is the original solution in PixelAccessor: return Unsafe.Read((byte*)this.pointer + (((y * this.width) + x) * Unsafe.SizeOf())); } From 5c24f441b6aab7a1c547a296341cf9f41d762f00 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 14 Apr 2017 02:46:50 +0200 Subject: [PATCH 11/34] simplified BufferSpan.Copy() --- src/ImageSharp/Common/Memory/BufferSpan.cs | 11 +----- .../General/ArrayCopy.cs | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index cf5d99746..3675084f2 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -37,15 +37,8 @@ namespace ImageSharp #if NETSTANDARD1_1 Unsafe.CopyBlock(pDest, pSrc, (uint)byteCount); #else - if (byteCount > 512) - { - int destLength = destination.Length * Unsafe.SizeOf(); - Buffer.MemoryCopy(pSrc, pDest, destLength, byteCount); - } - else - { - Unsafe.CopyBlock(pDest, pSrc, (uint)byteCount); - } + int destLength = destination.Length * Unsafe.SizeOf(); + Buffer.MemoryCopy(pSrc, pDest, destLength, byteCount); #endif } } diff --git a/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs b/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs index 72fd6dc24..31e9cc0e3 100644 --- a/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs +++ b/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Benchmarks.General using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; - + [Config(typeof(Config.Short))] public class ArrayCopy { @@ -58,8 +58,7 @@ namespace ImageSharp.Benchmarks.General Buffer.MemoryCopy(pinnedSource, pinnedDestination, this.Count, this.Count); } } - - + [Benchmark(Description = "Copy using Marshal.Copy")] public unsafe void CopyUsingMarshalCopy() { @@ -68,5 +67,37 @@ namespace ImageSharp.Benchmarks.General Marshal.Copy(this.source, 0, (IntPtr)pinnedDestination, this.Count); } } + + /***************************************************************************************************************** + *************** RESULTS on i7-4810MQ 2.80GHz + Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1085.0 ******************** + ***************************************************************************************************************** + * + * Method | Count | Mean | StdErr | StdDev | Scaled | Scaled-StdDev | + * ---------------------------------- |------ |------------ |----------- |----------- |------- |-------------- | + * 'Copy using Array.Copy()' | 10 | 20.3074 ns | 0.1194 ns | 0.2068 ns | 1.00 | 0.00 | + * 'Copy using Unsafe' | 10 | 6.1002 ns | 0.1981 ns | 0.3432 ns | 0.30 | 0.01 | + * 'Copy using Buffer.BlockCopy()' | 10 | 10.7879 ns | 0.0984 ns | 0.1705 ns | 0.53 | 0.01 | + * 'Copy using Buffer.MemoryCopy' | 10 | 4.9625 ns | 0.0200 ns | 0.0347 ns | 0.24 | 0.00 | + * 'Copy using Marshal.Copy' | 10 | 16.1782 ns | 0.0919 ns | 0.1592 ns | 0.80 | 0.01 | + * + * 'Copy using Array.Copy()' | 100 | 31.5945 ns | 0.2908 ns | 0.5037 ns | 1.00 | 0.00 | + * 'Copy using Unsafe' | 100 | 10.2722 ns | 0.5202 ns | 0.9010 ns | 0.33 | 0.02 | + * 'Copy using Buffer.BlockCopy()' | 100 | 22.0322 ns | 0.0284 ns | 0.0493 ns | 0.70 | 0.01 | + * 'Copy using Buffer.MemoryCopy' | 100 | 10.2472 ns | 0.0359 ns | 0.0622 ns | 0.32 | 0.00 | + * 'Copy using Marshal.Copy' | 100 | 34.3820 ns | 1.1868 ns | 2.0555 ns | 1.09 | 0.05 | + * + * 'Copy using Array.Copy()' | 1000 | 40.9743 ns | 0.0521 ns | 0.0902 ns | 1.00 | 0.00 | + * 'Copy using Unsafe' | 1000 | 42.7840 ns | 2.0139 ns | 3.4882 ns | 1.04 | 0.07 | + * 'Copy using Buffer.BlockCopy()' | 1000 | 33.7361 ns | 0.0751 ns | 0.1300 ns | 0.82 | 0.00 | + * 'Copy using Buffer.MemoryCopy' | 1000 | 35.7541 ns | 0.0480 ns | 0.0832 ns | 0.87 | 0.00 | + * 'Copy using Marshal.Copy' | 1000 | 42.2028 ns | 0.2769 ns | 0.4795 ns | 1.03 | 0.01 | + * + * 'Copy using Array.Copy()' | 10000 | 200.0438 ns | 0.2251 ns | 0.3899 ns | 1.00 | 0.00 | + * 'Copy using Unsafe' | 10000 | 389.6957 ns | 13.2770 ns | 22.9964 ns | 1.95 | 0.09 | + * 'Copy using Buffer.BlockCopy()' | 10000 | 191.3478 ns | 0.1557 ns | 0.2697 ns | 0.96 | 0.00 | + * 'Copy using Buffer.MemoryCopy' | 10000 | 196.4679 ns | 0.2731 ns | 0.4730 ns | 0.98 | 0.00 | + * 'Copy using Marshal.Copy' | 10000 | 202.5392 ns | 0.5561 ns | 0.9631 ns | 1.01 | 0.00 | + * + */ } } From b443026cb31f6dfb509228b981a3b0e889fabe36 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 14 Apr 2017 03:14:00 +0200 Subject: [PATCH 12/34] more pointers got removed --- src/ImageSharp/Colors/Color.BulkOperations.cs | 9 ++-- src/ImageSharp/Common/Memory/BufferSpan.cs | 18 +++++++- .../Formats/Jpeg/JpegEncoderCore.cs | 11 ++--- .../Formats/Jpeg/Utils/JpegUtils.cs | 45 +++++++++---------- src/ImageSharp/Image/PixelAccessor{TColor}.cs | 25 +++-------- src/ImageSharp/Image/PixelArea{TColor}.cs | 16 +------ 6 files changed, 55 insertions(+), 69 deletions(-) diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index d80941615..462d0c052 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -67,17 +67,18 @@ namespace ImageSharp using (PinnedBuffer tempBuf = new PinnedBuffer( unpackedRawCount + Vector.Count)) { - uint* tPtr = (uint*)tempBuf.Pointer; uint[] temp = tempBuf.Array; float[] fTemp = Unsafe.As(temp); - UnpackedRGBA* dst = (UnpackedRGBA*)tPtr; - for (int i = 0; i < count; i++, dst++) + ref UnpackedRGBA tempBase = ref Unsafe.As(ref tempBuf[0]); + + for (int i = 0; i < count; i++) { uint sVal = Unsafe.Add(ref src, i); + ref UnpackedRGBA dst = ref Unsafe.Add(ref tempBase, i); // This call is the bottleneck now: - dst->Load(sVal); + dst.Load(sVal); } for (int i = 0; i < unpackedRawCount; i += vecSize) diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index 3675084f2..c51c110be 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -18,13 +18,16 @@ namespace ImageSharp /// Copy 'count' number of elements of the same type from 'source' to 'dest' /// /// The element type. - /// The input + /// The to copy elements from. /// The destination . /// The number of elements to copy [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe void Copy(BufferSpan source, BufferSpan destination, int count) where T : struct { + DebugGuard.MustBeLessThanOrEqualTo(count, source.Length, nameof(count)); + DebugGuard.MustBeLessThanOrEqualTo(count, destination.Length, nameof(count)); + ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference()); ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference()); @@ -43,6 +46,19 @@ namespace ImageSharp } } + /// + /// Copy all elements of 'source' into 'destination'. + /// + /// The element type. + /// The to copy elements from. + /// The destination . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Copy(BufferSpan source, BufferSpan destination) + where T : struct + { + Copy(source, destination, source.Length); + } + /// /// Gets the size of `count` elements in bytes. /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 66f400c01..c3cf75a0f 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -307,7 +307,8 @@ namespace ImageSharp.Formats rgbBytes.Reset(); pixels.CopyRGBBytesStretchedTo(rgbBytes, y, x); - byte* data = (byte*)rgbBytes.DataPointer; + ref byte data0 = ref rgbBytes.Bytes[0]; + int dataIdx = 0; for (int j = 0; j < 8; j++) { @@ -315,9 +316,9 @@ namespace ImageSharp.Formats for (int i = 0; i < 8; i++) { // Convert returned bytes into the YCbCr color space. Assume RGBA - int r = data[0]; - int g = data[1]; - int b = data[2]; + int r = Unsafe.Add(ref data0, dataIdx); + int g = Unsafe.Add(ref data0, dataIdx + 1); + int b = Unsafe.Add(ref data0, dataIdx + 2); // Speed up the algorithm by removing floating point calculation // Scale by 65536, add .5F and truncate value. We use bit shifting to divide the result @@ -343,7 +344,7 @@ namespace ImageSharp.Formats cbBlockRaw[index] = cb; crBlockRaw[index] = cr; - data += 3; + dataIdx += 3; } } } diff --git a/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs b/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs index dd96985d9..ace309812 100644 --- a/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs +++ b/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs @@ -6,6 +6,7 @@ namespace ImageSharp.Formats.Jpg { using System; using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; /// /// Jpeg specific utilities and extension methods @@ -33,19 +34,6 @@ namespace ImageSharp.Formats.Jpg StretchPixels(dest, stretchFromX, stretchFromY); } - /// - /// Copy an RGB value - /// - /// Source pointer - /// Destination pointer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CopyRgb(byte* source, byte* dest) - { - *dest++ = *source++; // R - *dest++ = *source++; // G - *dest = *source; // B - } - // Nothing to stretch if (fromX, fromY) is outside the area, or is at (0,0) [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsInvalidStretchStartingPosition(PixelArea area, int fromX, int fromY) @@ -64,31 +52,38 @@ namespace ImageSharp.Formats.Jpg for (int y = 0; y < fromY; y++) { - byte* ptrBase = (byte*)area.DataPointer + (y * area.RowStride); + ref RGB24 ptrBase = ref GetRowStart(area, y); for (int x = fromX; x < area.Width; x++) { - byte* prevPtr = ptrBase + ((x - 1) * 3); - byte* currPtr = ptrBase + (x * 3); - - CopyRgb(prevPtr, currPtr); + // Copy the left neighbour pixel to the current one + Unsafe.Add(ref ptrBase, x) = Unsafe.Add(ref ptrBase, x - 1); } } for (int y = fromY; y < area.Height; y++) { - byte* currBase = (byte*)area.DataPointer + (y * area.RowStride); - byte* prevBase = (byte*)area.DataPointer + ((y - 1) * area.RowStride); + ref RGB24 currBase = ref GetRowStart(area, y); + ref RGB24 prevBase = ref GetRowStart(area, y - 1); for (int x = 0; x < area.Width; x++) { - int x3 = 3 * x; - byte* currPtr = currBase + x3; - byte* prevPtr = prevBase + x3; - - CopyRgb(prevPtr, currPtr); + // Copy the top neighbour pixel to the current one + Unsafe.Add(ref currBase, x) = Unsafe.Add(ref prevBase, x); } } } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ref RGB24 GetRowStart(PixelArea area, int y) + where TColor : struct, IPixel + { + return ref Unsafe.As(ref area.GetRowSpan(y).DangerousGetPinnableReference()); + } + + [StructLayout(LayoutKind.Sequential, Size = 3)] + private struct RGB24 + { + } } } \ No newline at end of file diff --git a/src/ImageSharp/Image/PixelAccessor{TColor}.cs b/src/ImageSharp/Image/PixelAccessor{TColor}.cs index f5393cfb3..5ff2911d4 100644 --- a/src/ImageSharp/Image/PixelAccessor{TColor}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TColor}.cs @@ -15,14 +15,9 @@ namespace ImageSharp /// Provides per-pixel access to generic pixels. /// /// The pixel format. - public sealed unsafe class PixelAccessor : IDisposable, IPinnedImageBuffer + public sealed class PixelAccessor : IDisposable, IPinnedImageBuffer where TColor : struct, IPixel { - /// - /// The position of the first pixel in the image. - /// - private byte* pixelsBase; - /// /// A value indicating whether this instance of the given entity has been disposed. /// @@ -93,11 +88,6 @@ namespace ImageSharp /// public TColor[] PixelArray => this.pixelBuffer.Array; - /// - /// Gets the pointer to the pixel buffer. - /// - public IntPtr DataPointer => this.pixelBuffer.Pointer; - /// /// Gets the size of a single pixel in the number of bytes. /// @@ -139,15 +129,13 @@ namespace ImageSharp get { this.CheckCoordinates(x, y); - - return Unsafe.Read(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf())); + return this.PixelArray[(y * this.Width) + x]; } set { this.CheckCoordinates(x, y); - - Unsafe.Write(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf()), value); + this.PixelArray[(y * this.Width) + x] = value; } } @@ -179,7 +167,7 @@ namespace ImageSharp /// public void Reset() { - Unsafe.InitBlock(this.pixelsBase, 0, (uint)(this.RowStride * this.Height)); + this.pixelBuffer.Clear(); } /// @@ -262,9 +250,7 @@ namespace ImageSharp /// The target pixel buffer accessor. internal void CopyTo(PixelAccessor target) { - uint byteCount = (uint)(this.Width * this.Height * Unsafe.SizeOf()); - - Unsafe.CopyBlock(target.pixelsBase, this.pixelsBase, byteCount); + BufferSpan.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span); } /// @@ -436,7 +422,6 @@ namespace ImageSharp private void SetPixelBufferUnsafe(int width, int height, PinnedImageBuffer pixels) { this.pixelBuffer = pixels; - this.pixelsBase = (byte*)pixels.Pointer; this.Width = width; this.Height = height; diff --git a/src/ImageSharp/Image/PixelArea{TColor}.cs b/src/ImageSharp/Image/PixelArea{TColor}.cs index bd10c9b6b..87e679205 100644 --- a/src/ImageSharp/Image/PixelArea{TColor}.cs +++ b/src/ImageSharp/Image/PixelArea{TColor}.cs @@ -13,7 +13,7 @@ namespace ImageSharp /// Represents an area of generic pixels. /// /// The pixel format. - internal sealed unsafe class PixelArea : IDisposable + internal sealed class PixelArea : IDisposable where TColor : struct, IPixel { /// @@ -67,7 +67,6 @@ namespace ImageSharp this.Length = bytes.Length; // TODO: Is this the right value for Length? this.byteBuffer = new PinnedBuffer(bytes); - this.PixelBase = (byte*)this.byteBuffer.Pointer; } /// @@ -118,7 +117,6 @@ namespace ImageSharp this.Length = this.RowStride * height; this.byteBuffer = new PinnedBuffer(this.Length); - this.PixelBase = (byte*)this.byteBuffer.Pointer; } /// @@ -136,21 +134,11 @@ namespace ImageSharp /// public ComponentOrder ComponentOrder { get; } - /// - /// Gets the pointer to the pixel buffer. - /// - public IntPtr DataPointer => this.byteBuffer.Pointer; - /// /// Gets the height. /// public int Height { get; } - /// - /// Gets the data pointer. - /// - public byte* PixelBase { get; private set; } - /// /// Gets the width of one row in the number of bytes. /// @@ -198,7 +186,7 @@ namespace ImageSharp /// public void Reset() { - Unsafe.InitBlock(this.PixelBase, 0, (uint)(this.RowStride * this.Height)); + this.byteBuffer.Clear(); } /// From 615163d3601fc02670fc0c39ff56901a15e11500 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 14 Apr 2017 13:10:46 +0200 Subject: [PATCH 13/34] PinnedBuffer ==> Buffer with explicit pinning capability --- .../Brushes/ImageBrush{TColor}.cs | 2 +- .../Brushes/PatternBrush{TColor}.cs | 2 +- .../Brushes/Processors/BrushApplicator.cs | 2 +- .../Brushes/RecolorBrush{TColor}.cs | 2 +- .../Brushes/SolidBrush{TColor}.cs | 2 +- src/ImageSharp/Colors/Color.BulkOperations.cs | 2 +- .../Memory/{PinnedBuffer{T}.cs => Buffer.cs} | 89 ++++++++++-------- .../{PinnedImageBuffer{T}.cs => Buffer2D.cs} | 22 ++--- src/ImageSharp/Common/Memory/BufferSpan{T}.cs | 2 +- ...{IPinnedImageBuffer{T}.cs => IBuffer2D.cs} | 4 +- .../Memory/PinnedImageBufferExtensions.cs | 6 +- src/ImageSharp/Image/PixelAccessor{TColor}.cs | 18 ++-- src/ImageSharp/Image/PixelArea{TColor}.cs | 6 +- .../ResamplingWeightedProcessor.Weights.cs | 6 +- .../Processors/Transforms/ResizeProcessor.cs | 4 +- .../Bulk/PackFromVector4ReferenceVsPointer.cs | 14 +-- .../Color/Bulk/PackFromXyzw.cs | 8 +- .../Color/Bulk/ToVector4.cs | 8 +- .../ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 8 +- .../Color/Bulk/ToXyzw.cs | 8 +- .../General/ClearBuffer.cs | 6 +- .../General/IterateArray.cs | 7 +- .../General/PixelIndexing.cs | 10 +- .../Colors/BulkPixelOperationsTests.cs | 16 ++-- ...edImageBufferTests.cs => Buffer2DTests.cs} | 27 +++--- .../Common/BufferSpanTests.cs | 6 +- .../{PinnedBufferTests.cs => BufferTests.cs} | 93 +++++++++++++------ 27 files changed, 211 insertions(+), 169 deletions(-) rename src/ImageSharp/Common/Memory/{PinnedBuffer{T}.cs => Buffer.cs} (72%) rename src/ImageSharp/Common/Memory/{PinnedImageBuffer{T}.cs => Buffer2D.cs} (69%) rename src/ImageSharp/Common/Memory/{IPinnedImageBuffer{T}.cs => IBuffer2D.cs} (86%) rename tests/ImageSharp.Tests/Common/{PinnedImageBufferTests.cs => Buffer2DTests.cs} (72%) rename tests/ImageSharp.Tests/Common/{PinnedBufferTests.cs => BufferTests.cs} (63%) diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs index ace929bd6..b68b02eff 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs @@ -117,7 +117,7 @@ namespace ImageSharp.Drawing.Brushes { Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth)); - using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer)) + using (Buffer buffer = new Buffer(scanlineBuffer)) { BufferSpan slice = buffer.Slice(offset); diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs index df492a764..1af58bc62 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs @@ -150,7 +150,7 @@ namespace ImageSharp.Drawing.Brushes { Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth)); - using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer)) + using (Buffer buffer = new Buffer(scanlineBuffer)) { BufferSpan slice = buffer.Slice(offset); diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 46444e550..0ef11e161 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -55,7 +55,7 @@ namespace ImageSharp.Drawing.Processors { DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth)); - using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer)) + using (Buffer buffer = new Buffer(scanlineBuffer)) { BufferSpan slice = buffer.Slice(offset); diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs index 257eeb3ae..4e3cd01ae 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs @@ -141,7 +141,7 @@ namespace ImageSharp.Drawing.Brushes { Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth)); - using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer)) + using (Buffer buffer = new Buffer(scanlineBuffer)) { BufferSpan slice = buffer.Slice(offset); diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs index 125b07bca..74c7081b3 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs @@ -89,7 +89,7 @@ namespace ImageSharp.Drawing.Brushes { Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth)); - using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer)) + using (Buffer buffer = new Buffer(scanlineBuffer)) { BufferSpan slice = buffer.Slice(offset); diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 462d0c052..e67e29356 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -64,7 +64,7 @@ namespace ImageSharp ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); - using (PinnedBuffer tempBuf = new PinnedBuffer( + using (Buffer tempBuf = new Buffer( unpackedRawCount + Vector.Count)) { uint[] temp = tempBuf.Array; diff --git a/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs b/src/ImageSharp/Common/Memory/Buffer.cs similarity index 72% rename from src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs rename to src/ImageSharp/Common/Memory/Buffer.cs index 665e92e09..c26b8ea18 100644 --- a/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs +++ b/src/ImageSharp/Common/Memory/Buffer.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,13 +11,18 @@ namespace ImageSharp using System.Runtime.InteropServices; /// - /// Manages a pinned buffer of value type objects as a Disposable resource. + /// Manages a buffer of value type objects as a Disposable resource. /// The backing array is either pooled or comes from the outside. /// /// The value type. - internal class PinnedBuffer : IDisposable + internal class Buffer : IDisposable where T : struct { + /// + /// A pointer to the first element of when pinned. + /// + private IntPtr pointer; + /// /// A handle that allows to access the managed as an unmanaged memory by pinning. /// @@ -25,40 +30,38 @@ namespace ImageSharp /// /// A value indicating wheter should be returned to - /// when disposing this instance. + /// when disposing this instance. /// private bool isPoolingOwner; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The desired count of elements. (Minimum size for ) - public PinnedBuffer(int length) + public Buffer(int length) { this.Length = length; this.Array = PixelDataPool.Rent(length); this.isPoolingOwner = true; - this.Pin(); } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The array to pin. - public PinnedBuffer(T[] array) + public Buffer(T[] array) { this.Length = array.Length; this.Array = array; this.isPoolingOwner = false; - this.Pin(); } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The array to pin. /// The count of "relevant" elements in 'array'. - public PinnedBuffer(T[] array, int length) + public Buffer(T[] array, int length) { if (array.Length < length) { @@ -68,19 +71,18 @@ namespace ImageSharp this.Length = length; this.Array = array; this.isPoolingOwner = false; - this.Pin(); } /// - /// Finalizes an instance of the class. + /// Finalizes an instance of the class. /// - ~PinnedBuffer() + ~Buffer() { this.UnPin(); } /// - /// Gets a value indicating whether this instance is disposed, or has lost ownership of . + /// Gets a value indicating whether this instance is disposed, or has lost ownership of . /// public bool IsDisposedOrLostArrayOwnership { get; private set; } @@ -94,11 +96,6 @@ namespace ImageSharp /// public T[] Array { get; private set; } - /// - /// Gets a pointer to the pinned . - /// - public IntPtr Pointer { get; private set; } - /// /// Gets a to the backing buffer. /// @@ -109,37 +106,35 @@ namespace ImageSharp /// /// The index /// The reference to the specified element - public unsafe ref T this[int index] + public ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); - - byte* ptr = (byte*)this.Pointer + BufferSpan.SizeOf(index); - return ref Unsafe.AsRef(ptr); + return ref this.Array[index]; } } /// - /// Converts to an . + /// Converts to an . /// - /// The to convert. + /// The to convert. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator BufferSpan(PinnedBuffer buffer) + public static implicit operator BufferSpan(Buffer buffer) { return new BufferSpan(buffer.Array, 0, buffer.Length); } /// - /// Creates a clean instance of initializing it's elements with 'default(T)'. + /// Creates a clean instance of initializing it's elements with 'default(T)'. /// /// The desired count of elements. (Minimum size for ) - /// The instance + /// The instance [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static PinnedBuffer CreateClean(int count) + public static Buffer CreateClean(int count) { - PinnedBuffer buffer = new PinnedBuffer(count); + Buffer buffer = new Buffer(count); buffer.Clear(); return buffer; } @@ -168,7 +163,7 @@ namespace ImageSharp } /// - /// Disposes the instance by unpinning the array, and returning the pooled buffer when necessary. + /// Disposes the instance by unpinning the array, and returning the pooled buffer when necessary. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() @@ -199,11 +194,11 @@ namespace ImageSharp /// /// The unpinned [MethodImpl(MethodImplOptions.AggressiveInlining)] - public T[] UnPinAndTakeArrayOwnership() + public T[] TakeArrayOwnership() { if (this.IsDisposedOrLostArrayOwnership) { - throw new InvalidOperationException("UnPinAndTakeArrayOwnership() is invalid: either PinnedBuffer is disposed or UnPinAndTakeArrayOwnership() has been called multiple times!"); + throw new InvalidOperationException("TakeArrayOwnership() is invalid: either Buffer is disposed or TakeArrayOwnership() has been called multiple times!"); } this.IsDisposedOrLostArrayOwnership = true; @@ -220,17 +215,29 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Clear() { - ((BufferSpan)this).Clear(); + this.Span.Clear(); } /// /// Pins . /// + /// The pinned pointer [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void Pin() + public IntPtr Pin() { - this.handle = GCHandle.Alloc(this.Array, GCHandleType.Pinned); - this.Pointer = this.handle.AddrOfPinnedObject(); + if (this.IsDisposedOrLostArrayOwnership) + { + throw new InvalidOperationException( + "Pin() is invalid on a buffer with IsDisposedOrLostArrayOwnership == true!"); + } + + if (this.pointer == IntPtr.Zero) + { + this.handle = GCHandle.Alloc(this.Array, GCHandleType.Pinned); + this.pointer = this.handle.AddrOfPinnedObject(); + } + + return this.pointer; } /// @@ -239,13 +246,13 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] private void UnPin() { - if (this.Pointer == IntPtr.Zero || !this.handle.IsAllocated) + if (this.pointer == IntPtr.Zero || !this.handle.IsAllocated) { return; } this.handle.Free(); - this.Pointer = IntPtr.Zero; + this.pointer = IntPtr.Zero; } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Memory/PinnedImageBuffer{T}.cs b/src/ImageSharp/Common/Memory/Buffer2D.cs similarity index 69% rename from src/ImageSharp/Common/Memory/PinnedImageBuffer{T}.cs rename to src/ImageSharp/Common/Memory/Buffer2D.cs index 3ff174c5d..c4eb50700 100644 --- a/src/ImageSharp/Common/Memory/PinnedImageBuffer{T}.cs +++ b/src/ImageSharp/Common/Memory/Buffer2D.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -9,19 +9,19 @@ namespace ImageSharp using System.Runtime.CompilerServices; /// - /// Represents a pinned buffer of value type objects + /// Represents a buffer of value type objects /// interpreted as a 2D region of x elements. /// /// The value type. - internal class PinnedImageBuffer : PinnedBuffer, IPinnedImageBuffer + internal class Buffer2D : Buffer, IBuffer2D where T : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The number of elements in a row /// The number of rows - public PinnedImageBuffer(int width, int height) + public Buffer2D(int width, int height) : base(width * height) { this.Width = width; @@ -29,12 +29,12 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The array to pin /// The number of elements in a row /// The number of rows - public PinnedImageBuffer(T[] array, int width, int height) + public Buffer2D(T[] array, int width, int height) : base(array, width * height) { this.Width = width; @@ -63,14 +63,14 @@ namespace ImageSharp } /// - /// Creates a clean instance of initializing it's elements with 'default(T)'. + /// Creates a clean instance of initializing it's elements with 'default(T)'. /// /// The number of elements in a row /// The number of rows - /// The instance - public static PinnedImageBuffer CreateClean(int width, int height) + /// The instance + public static Buffer2D CreateClean(int width, int height) { - PinnedImageBuffer buffer = new PinnedImageBuffer(width, height); + Buffer2D buffer = new Buffer2D(width, height); buffer.Clear(); return buffer; } diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs index d61f7f77c..1b0bef314 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Represents a contiguous region of a pinned managed array. - /// The array is usually owned by a instance. + /// The array is usually owned by a instance. /// /// /// is very similar to corefx System.Span<T>, and we try to maintain a compatible API. diff --git a/src/ImageSharp/Common/Memory/IPinnedImageBuffer{T}.cs b/src/ImageSharp/Common/Memory/IBuffer2D.cs similarity index 86% rename from src/ImageSharp/Common/Memory/IPinnedImageBuffer{T}.cs rename to src/ImageSharp/Common/Memory/IBuffer2D.cs index 374cbed99..1ba08e49f 100644 --- a/src/ImageSharp/Common/Memory/IPinnedImageBuffer{T}.cs +++ b/src/ImageSharp/Common/Memory/IBuffer2D.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -10,7 +10,7 @@ namespace ImageSharp /// interpreted as a 2D region of x elements. /// /// The value type. - internal interface IPinnedImageBuffer + internal interface IBuffer2D where T : struct { /// diff --git a/src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs b/src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs index fcd5b3831..f47bc666e 100644 --- a/src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs +++ b/src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs @@ -9,7 +9,7 @@ namespace ImageSharp using System.Runtime.CompilerServices; /// - /// Defines extension methods for . + /// Defines extension methods for . /// internal static class PinnedImageBufferExtensions { @@ -22,7 +22,7 @@ namespace ImageSharp /// The element type /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static BufferSpan GetRowSpan(this IPinnedImageBuffer buffer, int x, int y) + public static BufferSpan GetRowSpan(this IBuffer2D buffer, int x, int y) where T : struct { return buffer.Span.Slice((y * buffer.Width) + x, buffer.Width - x); @@ -36,7 +36,7 @@ namespace ImageSharp /// The element type /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static BufferSpan GetRowSpan(this IPinnedImageBuffer buffer, int y) + public static BufferSpan GetRowSpan(this IBuffer2D buffer, int y) where T : struct { return buffer.Span.Slice(y * buffer.Width, buffer.Width); diff --git a/src/ImageSharp/Image/PixelAccessor{TColor}.cs b/src/ImageSharp/Image/PixelAccessor{TColor}.cs index 5ff2911d4..fb3613adf 100644 --- a/src/ImageSharp/Image/PixelAccessor{TColor}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TColor}.cs @@ -15,7 +15,7 @@ namespace ImageSharp /// Provides per-pixel access to generic pixels. /// /// The pixel format. - public sealed class PixelAccessor : IDisposable, IPinnedImageBuffer + public sealed class PixelAccessor : IDisposable, IBuffer2D where TColor : struct, IPixel { /// @@ -30,9 +30,9 @@ namespace ImageSharp private bool isDisposed; /// - /// The containing the pixel data. + /// The containing the pixel data. /// - private PinnedImageBuffer pixelBuffer; + private Buffer2D pixelBuffer; /// /// Initializes a new instance of the class. @@ -54,7 +54,7 @@ namespace ImageSharp /// The width of the image represented by the pixel buffer. /// The height of the image represented by the pixel buffer. public PixelAccessor(int width, int height) - : this(width, height, PinnedImageBuffer.CreateClean(width, height)) + : this(width, height, Buffer2D.CreateClean(width, height)) { } @@ -64,7 +64,7 @@ namespace ImageSharp /// The width of the image represented by the pixel buffer. /// The height of the image represented by the pixel buffer. /// The pixel buffer. - private PixelAccessor(int width, int height, PinnedImageBuffer pixels) + private PixelAccessor(int width, int height, Buffer2D pixels) { Guard.NotNull(pixels, nameof(pixels)); Guard.MustBeGreaterThan(width, 0, nameof(width)); @@ -114,7 +114,7 @@ namespace ImageSharp public ParallelOptions ParallelOptions { get; } /// - BufferSpan IPinnedImageBuffer.Span => this.pixelBuffer; + BufferSpan IBuffer2D.Span => this.pixelBuffer; private static BulkPixelOperations Operations => BulkPixelOperations.Instance; @@ -239,7 +239,7 @@ namespace ImageSharp /// If is true then caller is responsible for ensuring is called. internal TColor[] ReturnCurrentPixelsAndReplaceThemInternally(int width, int height, TColor[] pixels) { - TColor[] oldPixels = this.pixelBuffer.UnPinAndTakeArrayOwnership(); + TColor[] oldPixels = this.pixelBuffer.TakeArrayOwnership(); this.SetPixelBufferUnsafe(width, height, pixels); return oldPixels; } @@ -410,7 +410,7 @@ namespace ImageSharp private void SetPixelBufferUnsafe(int width, int height, TColor[] pixels) { - this.SetPixelBufferUnsafe(width, height, new PinnedImageBuffer(pixels, width, height)); + this.SetPixelBufferUnsafe(width, height, new Buffer2D(pixels, width, height)); } /// @@ -419,7 +419,7 @@ namespace ImageSharp /// The width. /// The height. /// The pixel buffer - private void SetPixelBufferUnsafe(int width, int height, PinnedImageBuffer pixels) + private void SetPixelBufferUnsafe(int width, int height, Buffer2D pixels) { this.pixelBuffer = pixels; diff --git a/src/ImageSharp/Image/PixelArea{TColor}.cs b/src/ImageSharp/Image/PixelArea{TColor}.cs index 87e679205..176eb0a16 100644 --- a/src/ImageSharp/Image/PixelArea{TColor}.cs +++ b/src/ImageSharp/Image/PixelArea{TColor}.cs @@ -30,7 +30,7 @@ namespace ImageSharp /// /// The underlying buffer containing the raw pixel data. /// - private PinnedBuffer byteBuffer; + private Buffer byteBuffer; /// /// Initializes a new instance of the class. @@ -66,7 +66,7 @@ namespace ImageSharp this.RowStride = width * GetComponentCount(componentOrder); this.Length = bytes.Length; // TODO: Is this the right value for Length? - this.byteBuffer = new PinnedBuffer(bytes); + this.byteBuffer = new Buffer(bytes); } /// @@ -116,7 +116,7 @@ namespace ImageSharp this.RowStride = (width * GetComponentCount(componentOrder)) + padding; this.Length = this.RowStride * height; - this.byteBuffer = new PinnedBuffer(this.Length); + this.byteBuffer = new Buffer(this.Length); } /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs index 886c05569..4c43d654d 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs @@ -107,7 +107,7 @@ namespace ImageSharp.Processing.Processors /// The column position /// The weighted sum [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ComputeWeightedColumnSum(PinnedImageBuffer firstPassPixels, int x) + public Vector4 ComputeWeightedColumnSum(Buffer2D firstPassPixels, int x) { ref float verticalValues = ref this.Ptr; int left = this.Left; @@ -131,7 +131,7 @@ namespace ImageSharp.Processing.Processors /// internal class WeightsBuffer : IDisposable { - private PinnedImageBuffer dataBuffer; + private Buffer2D dataBuffer; /// /// Initializes a new instance of the class. @@ -140,7 +140,7 @@ namespace ImageSharp.Processing.Processors /// The size of the destination window public WeightsBuffer(int sourceSize, int destinationSize) { - this.dataBuffer = PinnedImageBuffer.CreateClean(sourceSize, destinationSize); + this.dataBuffer = Buffer2D.CreateClean(sourceSize, destinationSize); this.Weights = new WeightsWindow[destinationSize]; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 944e245ac..08d96e283 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -106,7 +106,7 @@ namespace ImageSharp.Processing.Processors using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { using (PixelAccessor sourcePixels = source.Lock()) - using (PinnedImageBuffer firstPassPixels = new PinnedImageBuffer(width, source.Height)) + using (Buffer2D firstPassPixels = new Buffer2D(width, source.Height)) { firstPassPixels.Clear(); @@ -117,7 +117,7 @@ namespace ImageSharp.Processing.Processors y => { // TODO: Without Parallel.For() this buffer object could be reused: - using (PinnedBuffer tempRowBuffer = new PinnedBuffer(sourcePixels.Width)) + using (Buffer tempRowBuffer = new Buffer(sourcePixels.Width)) { BufferSpan sourceRow = sourcePixels.GetRowSpan(y); diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs index e912ea29f..f02cf5663 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -14,9 +14,9 @@ /// public unsafe class PackFromVector4ReferenceVsPointer { - private PinnedBuffer destination; + private Buffer destination; - private PinnedBuffer source; + private Buffer source; [Params(16, 128, 1024)] public int Count { get; set; } @@ -24,8 +24,10 @@ [Setup] public void Setup() { - this.destination = new PinnedBuffer(this.Count); - this.source = new PinnedBuffer(this.Count * 4); + this.destination = new Buffer(this.Count); + this.source = new Buffer(this.Count * 4); + this.source.Pin(); + this.destination.Pin(); } [Cleanup] @@ -38,8 +40,8 @@ [Benchmark(Baseline = true)] public void PackUsingPointers() { - Vector4* sp = (Vector4*)this.source.Pointer; - byte* dp = (byte*)this.destination.Pointer; + Vector4* sp = (Vector4*)this.source.Pin(); + byte* dp = (byte*)this.destination.Pin(); int count = this.Count; int size = sizeof(ImageSharp.Color); diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 1c541d28b..33969b8fb 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -8,9 +8,9 @@ namespace ImageSharp.Benchmarks.Color.Bulk public abstract class PackFromXyzw where TColor : struct, IPixel { - private PinnedBuffer destination; + private Buffer destination; - private PinnedBuffer source; + private Buffer source; [Params(16, 128, 1024)] public int Count { get; set; } @@ -18,8 +18,8 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.destination = new PinnedBuffer(this.Count); - this.source = new PinnedBuffer(this.Count * 4); + this.destination = new Buffer(this.Count); + this.source = new Buffer(this.Count * 4); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index b48eaa35a..4cabfc01f 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -8,9 +8,9 @@ namespace ImageSharp.Benchmarks.Color.Bulk public abstract class ToVector4 where TColor : struct, IPixel { - private PinnedBuffer source; + private Buffer source; - private PinnedBuffer destination; + private Buffer destination; [Params(64, 300, 1024)] public int Count { get; set; } @@ -18,8 +18,8 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.source = new PinnedBuffer(this.Count); - this.destination = new PinnedBuffer(this.Count); + this.source = new Buffer(this.Count); + this.destination = new Buffer(this.Count); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index bc59dba4e..f6ae4256d 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -8,9 +8,9 @@ namespace ImageSharp.Benchmarks.Color.Bulk public abstract class ToXyz where TColor : struct, IPixel { - private PinnedBuffer source; + private Buffer source; - private PinnedBuffer destination; + private Buffer destination; [Params(16, 128, 1024)] public int Count { get; set; } @@ -18,8 +18,8 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.source = new PinnedBuffer(this.Count); - this.destination = new PinnedBuffer(this.Count * 3); + this.source = new Buffer(this.Count); + this.destination = new Buffer(this.Count * 3); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index a4ec6f6dc..05fc4094e 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -13,9 +13,9 @@ namespace ImageSharp.Benchmarks.Color.Bulk public abstract class ToXyzw where TColor : struct, IPixel { - private PinnedBuffer source; + private Buffer source; - private PinnedBuffer destination; + private Buffer destination; [Params(16, 128, 1024)] public int Count { get; set; } @@ -23,8 +23,8 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.source = new PinnedBuffer(this.Count); - this.destination = new PinnedBuffer(this.Count * 4); + this.source = new Buffer(this.Count); + this.destination = new Buffer(this.Count * 4); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs index 9aa836de5..e2f96f191 100644 --- a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs +++ b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Benchmarks.General public unsafe class ClearBuffer { - private PinnedBuffer buffer; + private Buffer buffer; [Params(32, 128, 512)] public int Count { get; set; } @@ -19,7 +19,7 @@ namespace ImageSharp.Benchmarks.General [Setup] public void Setup() { - this.buffer = new PinnedBuffer(this.Count); + this.buffer = new Buffer(this.Count); } [Cleanup] @@ -37,7 +37,7 @@ namespace ImageSharp.Benchmarks.General [Benchmark] public void Unsafe_InitBlock() { - Unsafe.InitBlock((void*)this.buffer.Pointer, default(byte), (uint)this.Count*sizeof(uint)); + Unsafe.InitBlock((void*)this.buffer.Pin(), default(byte), (uint)this.Count*sizeof(uint)); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/IterateArray.cs b/tests/ImageSharp.Benchmarks/General/IterateArray.cs index 48f2316a2..eeab6506a 100644 --- a/tests/ImageSharp.Benchmarks/General/IterateArray.cs +++ b/tests/ImageSharp.Benchmarks/General/IterateArray.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Benchmarks.General public class IterateArray { // Usual pinned stuff - private PinnedBuffer buffer; + private Buffer buffer; // An array that's not pinned by intent! private Vector4[] array; @@ -19,7 +19,8 @@ namespace ImageSharp.Benchmarks.General [Setup] public void Setup() { - this.buffer = new PinnedBuffer(this.Length); + this.buffer = new Buffer(this.Length); + this.buffer.Pin(); this.array = new Vector4[this.Length]; } @@ -41,7 +42,7 @@ namespace ImageSharp.Benchmarks.General { Vector4 sum = new Vector4(); - Vector4* ptr = (Vector4*) this.buffer.Pointer; + Vector4* ptr = (Vector4*) this.buffer.Pin(); Vector4* end = ptr + this.Length; for (; ptr < end; ptr++) diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index 6db0eef36..d9237b801 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -29,9 +29,9 @@ private int width; - public Data(PinnedImageBuffer buffer) + public Data(Buffer2D buffer) { - this.pointer = (Vector4*)buffer.Pointer; + this.pointer = (Vector4*)buffer.Pin(); this.pinnable = Unsafe.As>(buffer.Array); this.array = buffer.Array; this.width = buffer.Width; @@ -126,7 +126,7 @@ } } - internal PinnedImageBuffer buffer; + internal Buffer2D buffer; protected int width; @@ -147,8 +147,8 @@ public void Setup() { this.width = 2048; - this.buffer = new PinnedImageBuffer(2048, 2048); - this.pointer = (Vector4*)this.buffer.Pointer; + this.buffer = new Buffer2D(2048, 2048); + this.pointer = (Vector4*)this.buffer.Pin(); this.array = this.buffer.Array; this.pinnable = Unsafe.As>(this.array); diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs index fe005ad01..7db5a45f3 100644 --- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs @@ -45,8 +45,8 @@ namespace ImageSharp.Tests.Colors int times = 200000; int count = 1024; - using (PinnedBuffer source = new PinnedBuffer(count)) - using (PinnedBuffer dest = new PinnedBuffer(count)) + using (Buffer source = new Buffer(count)) + using (Buffer dest = new Buffer(count)) { this.Measure( times, @@ -310,18 +310,18 @@ namespace ImageSharp.Tests.Colors where TSource : struct where TDest : struct { - public PinnedBuffer SourceBuffer { get; } - public PinnedBuffer ActualDestBuffer { get; } - public PinnedBuffer ExpectedDestBuffer { get; } + public Buffer SourceBuffer { get; } + public Buffer ActualDestBuffer { get; } + public Buffer ExpectedDestBuffer { get; } public BufferSpan Source => this.SourceBuffer; public BufferSpan ActualDest => this.ActualDestBuffer; public TestBuffers(TSource[] source, TDest[] expectedDest) { - this.SourceBuffer = new PinnedBuffer(source); - this.ExpectedDestBuffer = new PinnedBuffer(expectedDest); - this.ActualDestBuffer = new PinnedBuffer(expectedDest.Length); + this.SourceBuffer = new Buffer(source); + this.ExpectedDestBuffer = new Buffer(expectedDest); + this.ActualDestBuffer = new Buffer(expectedDest.Length); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs b/tests/ImageSharp.Tests/Common/Buffer2DTests.cs similarity index 72% rename from tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs rename to tests/ImageSharp.Tests/Common/Buffer2DTests.cs index a8ccea5eb..ac92ab87b 100644 --- a/tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs +++ b/tests/ImageSharp.Tests/Common/Buffer2DTests.cs @@ -8,19 +8,18 @@ namespace ImageSharp.Tests.Common using static TestStructs; - public unsafe class PinnedImageBufferTests + public unsafe class Buffer2DTests { // ReSharper disable once ClassNeverInstantiated.Local private class Assert : Xunit.Assert { - public static void SpanPointsTo(IntPtr ptr, BufferSpan span) + public static void SpanPointsTo(BufferSpan span, Buffer buffer, int bufferOffset = 0) where T : struct { - ref byte r = ref Unsafe.As(ref span.DangerousGetPinnableReference()); + ref T actual = ref span.DangerousGetPinnableReference(); + ref T expected = ref Unsafe.Add(ref buffer[0], bufferOffset); - void* p = Unsafe.AsPointer(ref r); - - Assert.Equal(ptr, (IntPtr)p); + Assert.True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position"); } } @@ -29,7 +28,7 @@ namespace ImageSharp.Tests.Common [InlineData(1025, 17)] public void Construct(int width, int height) { - using (PinnedImageBuffer buffer = new PinnedImageBuffer(width, height)) + using (Buffer2D buffer = new Buffer2D(width, height)) { Assert.Equal(width, buffer.Width); Assert.Equal(height, buffer.Height); @@ -43,7 +42,7 @@ namespace ImageSharp.Tests.Common public void Construct_FromExternalArray(int width, int height) { Foo[] array = new Foo[width * height + 10]; - using (PinnedImageBuffer buffer = new PinnedImageBuffer(array, width, height)) + using (Buffer2D buffer = new Buffer2D(array, width, height)) { Assert.Equal(width, buffer.Width); Assert.Equal(height, buffer.Height); @@ -57,7 +56,7 @@ namespace ImageSharp.Tests.Common { for (int i = 0; i < 100; i++) { - using (PinnedImageBuffer buffer = PinnedImageBuffer.CreateClean(42, 42)) + using (Buffer2D buffer = Buffer2D.CreateClean(42, 42)) { for (int j = 0; j < buffer.Length; j++) { @@ -74,13 +73,13 @@ namespace ImageSharp.Tests.Common [InlineData(17, 42, 41)] public void GetRowSpanY(int width, int height, int y) { - using (PinnedImageBuffer buffer = new PinnedImageBuffer(width, height)) + using (Buffer2D buffer = new Buffer2D(width, height)) { BufferSpan span = buffer.GetRowSpan(y); Assert.Equal(width * y, span.Start); Assert.Equal(width, span.Length); - Assert.SpanPointsTo(buffer.Pointer + sizeof(Foo) * width * y, span); + Assert.SpanPointsTo(span, buffer, width * y); } } @@ -90,13 +89,13 @@ namespace ImageSharp.Tests.Common [InlineData(17, 42, 0, 41)] public void GetRowSpanXY(int width, int height, int x, int y) { - using (PinnedImageBuffer buffer = new PinnedImageBuffer(width, height)) + using (Buffer2D buffer = new Buffer2D(width, height)) { BufferSpan span = buffer.GetRowSpan(x, y); Assert.Equal(width * y + x, span.Start); Assert.Equal(width - x, span.Length); - Assert.SpanPointsTo(buffer.Pointer + sizeof(Foo) * (width * y + x), span); + Assert.SpanPointsTo(span, buffer, width * y + x); } } @@ -106,7 +105,7 @@ namespace ImageSharp.Tests.Common [InlineData(99, 88, 98, 87)] public void Indexer(int width, int height, int x, int y) { - using (PinnedImageBuffer buffer = new PinnedImageBuffer(width, height)) + using (Buffer2D buffer = new Buffer2D(width, height)) { Foo[] array = buffer.Array; diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index 58a217b18..067ef6622 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -28,7 +28,7 @@ namespace ImageSharp.Tests.Common { Foo[] fooz = { new Foo(1, 2), new Foo(3, 4), new Foo(5, 6) }; - using (PinnedBuffer colorBuf = new PinnedBuffer(fooz)) + using (Buffer colorBuf = new Buffer(fooz)) { BufferSpan orig = colorBuf.Slice(1); BufferSpan asBytes = orig.AsBytes(); @@ -414,8 +414,8 @@ namespace ImageSharp.Tests.Common { Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), }; - using (PinnedBuffer colorBuf = new PinnedBuffer(colors)) - using (PinnedBuffer byteBuf = new PinnedBuffer(colors.Length * 4)) + using (Buffer colorBuf = new Buffer(colors)) + using (Buffer byteBuf = new Buffer(colors.Length * 4)) { BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length*sizeof(Color)); diff --git a/tests/ImageSharp.Tests/Common/PinnedBufferTests.cs b/tests/ImageSharp.Tests/Common/BufferTests.cs similarity index 63% rename from tests/ImageSharp.Tests/Common/PinnedBufferTests.cs rename to tests/ImageSharp.Tests/Common/BufferTests.cs index 67430976a..23205d012 100644 --- a/tests/ImageSharp.Tests/Common/PinnedBufferTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferTests.cs @@ -1,4 +1,5 @@ -namespace ImageSharp.Tests.Common +// ReSharper disable InconsistentNaming +namespace ImageSharp.Tests.Common { using System; using System.Runtime.CompilerServices; @@ -9,18 +10,23 @@ using static TestStructs; - public unsafe class PinnedBufferTests + public unsafe class BufferTests { + // ReSharper disable once ClassNeverInstantiated.Local private class Assert : Xunit.Assert { - public static void SpanPointsTo(IntPtr ptr, BufferSpan span) + public static void SpanPointsTo(BufferSpan span, Buffer buffer, int bufferOffset = 0) where T : struct { - ref byte r = ref Unsafe.As(ref span.DangerousGetPinnableReference()); + ref T actual = ref span.DangerousGetPinnableReference(); + ref T expected = ref Unsafe.Add(ref buffer[0], bufferOffset); - void* p = Unsafe.AsPointer(ref r); + Assert.True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position"); + } - Assert.Equal(ptr, (IntPtr)p); + public static void Equal(void* expected, void* actual) + { + Assert.Equal((IntPtr)expected, (IntPtr)actual); } } @@ -29,14 +35,12 @@ [InlineData(1111)] public void ConstructWithOwnArray(int count) { - using (PinnedBuffer buffer = new PinnedBuffer(count)) + using (Buffer buffer = new Buffer(count)) { Assert.False(buffer.IsDisposedOrLostArrayOwnership); Assert.NotNull(buffer.Array); Assert.Equal(count, buffer.Length); Assert.True(buffer.Array.Length >= count); - - VerifyPointer(buffer); } } @@ -46,13 +50,11 @@ public void ConstructWithExistingArray(int count) { Foo[] array = new Foo[count]; - using (PinnedBuffer buffer = new PinnedBuffer(array)) + using (Buffer buffer = new Buffer(array)) { Assert.False(buffer.IsDisposedOrLostArrayOwnership); Assert.Equal(array, buffer.Array); Assert.Equal(count, buffer.Length); - - VerifyPointer(buffer); } } @@ -62,7 +64,7 @@ public void Clear(int count) { Foo[] a = { new Foo() { A = 1, B = 2 }, new Foo() { A = 3, B = 4 } }; - using (PinnedBuffer buffer = new PinnedBuffer(a)) + using (Buffer buffer = new Buffer(a)) { buffer.Clear(); @@ -76,7 +78,7 @@ { for (int i = 0; i < 100; i++) { - using (PinnedBuffer buffer = PinnedBuffer.CreateClean(42)) + using (Buffer buffer = Buffer.CreateClean(42)) { for (int j = 0; j < buffer.Length; j++) { @@ -103,7 +105,7 @@ { Foo[] a = Foo.CreateArray(length); - using (PinnedBuffer buffer = new PinnedBuffer(a)) + using (Buffer buffer = new Buffer(a)) { Foo element = buffer[index]; @@ -117,7 +119,7 @@ { Foo[] a = Foo.CreateArray(length); - using (PinnedBuffer buffer = new PinnedBuffer(a)) + using (Buffer buffer = new Buffer(a)) { buffer[index] = new Foo(666, 666); @@ -129,7 +131,7 @@ [Fact] public void Dispose() { - PinnedBuffer buffer = new PinnedBuffer(42); + Buffer buffer = new Buffer(42); buffer.Dispose(); Assert.True(buffer.IsDisposedOrLostArrayOwnership); @@ -140,13 +142,13 @@ [InlineData(123)] public void CastToSpan(int bufferLength) { - using (PinnedBuffer buffer = new PinnedBuffer(bufferLength)) + using (Buffer buffer = new Buffer(bufferLength)) { BufferSpan span = buffer; Assert.Equal(buffer.Array, span.Array); Assert.Equal(0, span.Start); - Assert.SpanPointsTo(buffer.Pointer, span); + Assert.SpanPointsTo(span, buffer); Assert.Equal(span.Length, bufferLength); } } @@ -154,13 +156,13 @@ [Fact] public void Span() { - using (PinnedBuffer buffer = new PinnedBuffer(42)) + using (Buffer buffer = new Buffer(42)) { BufferSpan span = buffer.Span; Assert.Equal(buffer.Array, span.Array); Assert.Equal(0, span.Start); - Assert.SpanPointsTo(buffer.Pointer, span); + Assert.SpanPointsTo(span, buffer); Assert.Equal(span.Length, 42); } } @@ -173,13 +175,13 @@ [InlineData(123, 17)] public void WithStartOnly(int bufferLength, int start) { - using (PinnedBuffer buffer = new PinnedBuffer(bufferLength)) + using (Buffer buffer = new Buffer(bufferLength)) { BufferSpan span = buffer.Slice(start); Assert.Equal(buffer.Array, span.Array); Assert.Equal(start, span.Start); - Assert.SpanPointsTo(buffer.Pointer + start * Unsafe.SizeOf(), span); + Assert.SpanPointsTo(span, buffer, start); Assert.Equal(span.Length, bufferLength - start); } } @@ -189,13 +191,13 @@ [InlineData(123, 17, 42)] public void WithStartAndLength(int bufferLength, int start, int spanLength) { - using (PinnedBuffer buffer = new PinnedBuffer(bufferLength)) + using (Buffer buffer = new Buffer(bufferLength)) { BufferSpan span = buffer.Slice(start, spanLength); Assert.Equal(buffer.Array, span.Array); Assert.Equal(start, span.Start); - Assert.SpanPointsTo(buffer.Pointer + start * Unsafe.SizeOf(), span); + Assert.SpanPointsTo(span, buffer, start); Assert.Equal(span.Length, spanLength); } } @@ -205,9 +207,9 @@ public void UnPinAndTakeArrayOwnership() { Foo[] data = null; - using (PinnedBuffer buffer = new PinnedBuffer(42)) + using (Buffer buffer = new Buffer(42)) { - data = buffer.UnPinAndTakeArrayOwnership(); + data = buffer.TakeArrayOwnership(); Assert.True(buffer.IsDisposedOrLostArrayOwnership); } @@ -215,10 +217,41 @@ Assert.True(data.Length >= 42); } - private static void VerifyPointer(PinnedBuffer buffer) + public class Pin { - IntPtr ptr = (IntPtr)Unsafe.AsPointer(ref buffer.Array[0]); - Assert.Equal(ptr, buffer.Pointer); + [Fact] + public void ReturnsPinnedPointerToTheBeginningOfArray() + { + using (Buffer buffer = new Buffer(42)) + { + Foo* actual = (Foo*)buffer.Pin(); + fixed (Foo* expected = buffer.Array) + { + Assert.Equal(expected, actual); + } + } + } + + [Fact] + public void SecondCallReturnsTheSamePointer() + { + using (Buffer buffer = new Buffer(42)) + { + IntPtr ptr1 = buffer.Pin(); + IntPtr ptr2 = buffer.Pin(); + + Assert.Equal(ptr1, ptr2); + } + } + + [Fact] + public void WhenCalledOnDisposedBuffer_ThrowsInvalidOperationException() + { + Buffer buffer = new Buffer(42); + buffer.Dispose(); + + Assert.Throws(() => buffer.Pin()); + } } } } \ No newline at end of file From 0e6e570e1425b7c50b9330d302d20bb41f68837e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 14 Apr 2017 14:27:33 +0200 Subject: [PATCH 14/34] renamed PinnedImageBufferExtensions -> Buffer2DExtensions --- .../{PinnedImageBufferExtensions.cs => Buffer2DExtensions.cs} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/ImageSharp/Common/Memory/{PinnedImageBufferExtensions.cs => Buffer2DExtensions.cs} (92%) diff --git a/src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs b/src/ImageSharp/Common/Memory/Buffer2DExtensions.cs similarity index 92% rename from src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs rename to src/ImageSharp/Common/Memory/Buffer2DExtensions.cs index f47bc666e..4c3cc4d40 100644 --- a/src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs +++ b/src/ImageSharp/Common/Memory/Buffer2DExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,7 +11,7 @@ namespace ImageSharp /// /// Defines extension methods for . /// - internal static class PinnedImageBufferExtensions + internal static class Buffer2DExtensions { /// /// Gets a to the row 'y' beginning from the pixel at 'x'. From 9c29fadcebe550cdbc0d0447738a6141f09e1ac1 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 15 Apr 2017 13:25:27 +1000 Subject: [PATCH 15/34] Fix quantization altering the original image. --- src/ImageSharp/Quantizers/Quantizer.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Quantizers/Quantizer.cs b/src/ImageSharp/Quantizers/Quantizer.cs index bb856ccc5..492ec5f2b 100644 --- a/src/ImageSharp/Quantizers/Quantizer.cs +++ b/src/ImageSharp/Quantizers/Quantizer.cs @@ -68,7 +68,20 @@ namespace ImageSharp.Quantizers // Collect the palette. Required before the second pass runs. colorPalette = this.GetPalette(); - this.SecondPass(pixels, quantizedPixels, width, height); + + if (this.Dither) + { + // We clone the image as we don't want to alter the original. + using (Image clone = new Image(image)) + using (PixelAccessor clonedPixels = clone.Lock()) + { + this.SecondPass(clonedPixels, quantizedPixels, width, height); + } + } + else + { + this.SecondPass(pixels, quantizedPixels, width, height); + } } return new QuantizedImage(width, height, colorPalette, quantizedPixels); From 7eac3f59f8781778af8c67b42bce2d7658d09472 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 15 Apr 2017 13:58:38 +1000 Subject: [PATCH 16/34] Correct clamping on WuQuantizer --- src/ImageSharp/Quantizers/WuQuantizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Quantizers/WuQuantizer.cs b/src/ImageSharp/Quantizers/WuQuantizer.cs index c1c81d0ac..46af6fab9 100644 --- a/src/ImageSharp/Quantizers/WuQuantizer.cs +++ b/src/ImageSharp/Quantizers/WuQuantizer.cs @@ -136,7 +136,7 @@ namespace ImageSharp.Quantizers { Guard.NotNull(image, nameof(image)); - this.colors = maxColors.Clamp(1, 256); + this.colors = maxColors.Clamp(1, 255); try { From d56322866c84e476beef4bc6fc3c42a81e6676b2 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 16 Apr 2017 10:04:14 +0200 Subject: [PATCH 17/34] Fixed solution items. --- ImageSharp.sln | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ImageSharp.sln b/ImageSharp.sln index 6e389421e..8ec2cf53b 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -1,18 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.9 +VisualStudioVersion = 15.0.26403.3 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .travis.yml = .travis.yml appveyor.yml = appveyor.yml + codecov.yml = codecov.yml CodeCoverage.runsettings = CodeCoverage.runsettings - contributing.md = contributing.md - dotnet-latest.ps1 = dotnet-latest.ps1 + .github\CONTRIBUTING.md = .github\CONTRIBUTING.md features.md = features.md - global.json = global.json ImageSharp.ruleset = ImageSharp.ruleset ImageSharp.sln.DotSettings = ImageSharp.sln.DotSettings NuGet.config = NuGet.config From 88c3fb3888ba576b4b4179704e57f556f6e8d021 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 16 Apr 2017 10:29:06 +0200 Subject: [PATCH 18/34] Added extra checks to the ExifReader (fixes #175). --- .../MetaData/Profiles/Exif/ExifReader.cs | 10 +++++- .../MetaData/Profiles/Exif/ExifReaderTests.cs | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index 58f32bdd8..6164bd228 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -73,6 +73,8 @@ namespace ImageSharp /// public Collection Read(byte[] data) { + DebugGuard.NotNull(data, nameof(data)); + Collection result = new Collection(); this.exifData = data; @@ -390,7 +392,13 @@ namespace ImageSharp private string GetString(uint length) { - return ToString(this.GetBytes(length)); + byte[] data = this.GetBytes(length); + if (data == null || data.Length == 0) + { + return null; + } + + return ToString(data); } private void GetThumbnail(uint offset) diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs new file mode 100644 index 000000000..dc62f1cbf --- /dev/null +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests +{ + using System.Collections.ObjectModel; + using Xunit; + + public class ExifReaderTests + { + [Fact] + public void Read_DataIsEmpty_ReturnsEmptyCollection() + { + ExifReader reader = new ExifReader(); + byte[] data = new byte[] { }; + + Collection result = reader.Read(data); + + Assert.Equal(0, result.Count); + } + + [Fact] + public void Read_DataIsMinimal_ReturnsEmptyCollection() + { + ExifReader reader = new ExifReader(); + byte[] data = new byte[] { 69, 120, 105, 102, 0, 0 }; + + Collection result = reader.Read(data); + + Assert.Equal(0, result.Count); + } + } +} From 9c7a96536b20adbfa479d12cfb7fd429506f458c Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 16 Apr 2017 19:59:08 +1000 Subject: [PATCH 19/34] Inint remove packing from Color. --- src/ImageSharp/Colors/Color.cs | 226 ++++------ src/ImageSharp/Colors/ColorTransforms.cs | 28 +- src/ImageSharp/Colors/PackedPixel/Rgba32.cs | 398 ++++++++++++++++++ .../ImageProviders/TestPatternProvider.cs | 10 +- 4 files changed, 503 insertions(+), 159 deletions(-) create mode 100644 src/ImageSharp/Colors/PackedPixel/Rgba32.cs diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index 597730937..c9d777c59 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -5,10 +5,9 @@ namespace ImageSharp { - using System; - using System.Globalization; using System.Numerics; using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. @@ -18,8 +17,33 @@ 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 partial struct Color : IPixel, IPackedVector + [StructLayout(LayoutKind.Explicit)] + public partial struct Color : IPixel { + /// + /// 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; + /// /// The shift count for the red component /// @@ -50,11 +74,6 @@ namespace ImageSharp /// private static readonly Vector4 Half = new Vector4(0.5F); - /// - /// The packed value. - /// - private uint packedValue; - /// /// Initializes a new instance of the struct. /// @@ -63,8 +82,12 @@ namespace ImageSharp /// The blue component. /// The alpha component. public Color(byte r, byte g, byte b, byte a = 255) + : this() { - this.packedValue = Pack(r, g, b, a); + this.R = r; + this.G = g; + this.B = b; + this.A = a; } /// @@ -75,8 +98,9 @@ namespace ImageSharp /// The blue component. /// The alpha component. public Color(float r, float g, float b, float a = 1) + : this() { - this.packedValue = Pack(r, g, b, a); + this = Pack(r, g, b, a); } /// @@ -86,8 +110,9 @@ namespace ImageSharp /// The vector containing the components for the packed vector. /// public Color(Vector3 vector) + : this() { - this.packedValue = Pack(ref vector); + this = Pack(ref vector); } /// @@ -97,105 +122,9 @@ namespace ImageSharp /// The vector containing the components for the packed vector. /// public Color(Vector4 vector) + : this() { - this.packedValue = Pack(ref vector); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The packed value. - /// - public Color(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 - { - return this.packedValue; - } - - set - { - this.packedValue = value; - } + this = Pack(ref vector); } /// @@ -213,7 +142,10 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Color left, Color right) { - return left.packedValue == right.packedValue; + return left.R == right.R + && left.G == right.G + && left.B == right.B + && left.A == right.A; } /// @@ -227,7 +159,10 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Color left, Color right) { - return left.packedValue != right.packedValue; + return left.R != right.R + && left.G != right.G + && left.B != right.B + && left.A != right.A; } /// @@ -246,13 +181,16 @@ namespace ImageSharp } /// - public BulkPixelOperations CreateBulkOperations() => new Color.BulkOperations(); + public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { - this.packedValue = Pack(x, y, z, w); + this.R = x; + this.G = y; + this.B = z; + this.A = w; } /// @@ -307,7 +245,7 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { - this.packedValue = Pack(ref vector); + this = Pack(ref vector); } /// @@ -327,7 +265,10 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Color other) { - return this.packedValue == other.packedValue; + return this.R == other.R + && this.G == other.G + && this.B == other.B + && this.A == other.A; } /// @@ -342,33 +283,52 @@ namespace ImageSharp /// public override int GetHashCode() { - return this.packedValue.GetHashCode(); + unchecked + { + int hashCode = this.R.GetHashCode(); + hashCode = (hashCode * 397) ^ this.G.GetHashCode(); + hashCode = (hashCode * 397) ^ this.B.GetHashCode(); + hashCode = (hashCode * 397) ^ this.A.GetHashCode(); + return hashCode; + } + } + + /// + /// 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); } /// /// Packs a into a uint. /// /// The vector containing the values to pack. - /// The containing the packed values. + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(ref Vector4 vector) + private static Color 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); + + return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); } /// /// Packs a into a uint. /// /// The vector containing the values to pack. - /// The containing the packed values. + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(ref Vector3 vector) + private static Color Pack(ref Vector3 vector) { Vector4 value = new Vector4(vector, 1); return Pack(ref value); @@ -381,26 +341,12 @@ namespace ImageSharp /// The y-component /// The z-component /// The w-component - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(float x, float y, float z, float w) + private static Color 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/src/ImageSharp/Colors/ColorTransforms.cs b/src/ImageSharp/Colors/ColorTransforms.cs index f61afbf5b..e392d7d98 100644 --- a/src/ImageSharp/Colors/ColorTransforms.cs +++ b/src/ImageSharp/Colors/ColorTransforms.cs @@ -28,7 +28,7 @@ namespace ImageSharp public static Color operator +(Color left, Color right) { Vector4 add = left.ToVector4() + right.ToVector4(); - return new Color(Pack(ref add)); + return Pack(ref add); } /// @@ -42,7 +42,7 @@ namespace ImageSharp public static Color operator -(Color left, Color right) { Vector4 sub = left.ToVector4() - right.ToVector4(); - return new Color(Pack(ref sub)); + return Pack(ref sub); } /// @@ -56,7 +56,7 @@ namespace ImageSharp public static Color Normal(Color backdrop, Color source) { Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref normal)); + return Pack(ref normal); } /// @@ -76,7 +76,7 @@ namespace ImageSharp public static Color Multiply(Color backdrop, Color source) { Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref multiply)); + return Pack(ref multiply); } /// @@ -95,7 +95,7 @@ namespace ImageSharp public static Color Screen(Color backdrop, Color source) { Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref subtract)); + return Pack(ref subtract); } /// @@ -110,7 +110,7 @@ namespace ImageSharp public static Color HardLight(Color backdrop, Color source) { Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref hardlight)); + return Pack(ref hardlight); } /// @@ -129,7 +129,7 @@ namespace ImageSharp public static Color Overlay(Color backdrop, Color source) { Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref overlay)); + return Pack(ref overlay); } /// @@ -144,7 +144,7 @@ namespace ImageSharp public static Color Darken(Color backdrop, Color source) { Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref darken)); + return Pack(ref darken); } /// @@ -159,7 +159,7 @@ namespace ImageSharp public static Color Lighten(Color backdrop, Color source) { Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref lighten)); + return Pack(ref lighten); } /// @@ -174,7 +174,7 @@ namespace ImageSharp public static Color SoftLight(Color backdrop, Color source) { Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref softlight)); + return Pack(ref softlight); } /// @@ -188,7 +188,7 @@ namespace ImageSharp public static Color ColorDodge(Color backdrop, Color source) { Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref dodge)); + return Pack(ref dodge); } /// @@ -202,7 +202,7 @@ namespace ImageSharp public static Color ColorBurn(Color backdrop, Color source) { Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref burn)); + return Pack(ref burn); } /// @@ -217,7 +217,7 @@ namespace ImageSharp public static Color Difference(Color backdrop, Color source) { Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref difference)); + return Pack(ref difference); } /// @@ -232,7 +232,7 @@ namespace ImageSharp public static Color Exclusion(Color backdrop, Color source) { Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4()); - return new Color(Pack(ref exclusion)); + return Pack(ref exclusion); } /// diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs b/src/ImageSharp/Colors/PackedPixel/Rgba32.cs new file mode 100644 index 000000000..727d91c93 --- /dev/null +++ b/src/ImageSharp/Colors/PackedPixel/Rgba32.cs @@ -0,0 +1,398 @@ +// +// 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.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 39ce61495..c9312eed1 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -61,7 +61,7 @@ namespace ImageSharp.Tests BlackWhiteChecker(pixels); // top left VirticalBars(pixels); // top right TransparentGradients(pixels); // bottom left - Rainbow(pixels); // bottom right + Rainbow(pixels); // bottom right } } /// @@ -70,7 +70,7 @@ namespace ImageSharp.Tests /// private static void VirticalBars(PixelAccessor pixels) { - // topLeft + // topLeft int left = pixels.Width / 2; int right = pixels.Width; int top = 0; @@ -101,7 +101,7 @@ namespace ImageSharp.Tests /// private static void BlackWhiteChecker(PixelAccessor pixels) { - // topLeft + // topLeft int left = 0; int right = pixels.Width / 2; int top = 0; @@ -140,7 +140,7 @@ namespace ImageSharp.Tests /// private static void TransparentGradients(PixelAccessor pixels) { - // topLeft + // topLeft int left = 0; int right = pixels.Width / 2; int top = pixels.Height / 2; @@ -193,7 +193,7 @@ namespace ImageSharp.Tests int pixelCount = left * top; uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount); TColor c = default(TColor); - Color t = new Color(0); + Rgba32 t = new Rgba32(0); for (int x = left; x < right; x++) for (int y = top; y < bottom; y++) From 3c5e3a966ea65fa372ed00ba73a5460bd6536997 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 16 Apr 2017 21:06:29 +1000 Subject: [PATCH 20/34] Rename Color to Color32 --- src/ImageSharp.Drawing/Brushes/Brushes.cs | 60 +- src/ImageSharp.Drawing/Brushes/ImageBrush.cs | 6 +- .../Brushes/PatternBrush.cs | 8 +- .../Brushes/RecolorBrush.cs | 4 +- src/ImageSharp.Drawing/Brushes/SolidBrush.cs | 6 +- src/ImageSharp.Drawing/Pens/Pen.cs | 12 +- src/ImageSharp.Drawing/Pens/Pens.cs | 20 +- src/ImageSharp/Colors/Color.BulkOperations.cs | 35 +- ...lorTransforms.cs => Color32.Transforms.cs} | 66 +- .../Colors/{Color.cs => Color32.cs} | 62 +- src/ImageSharp/Colors/Color32Constants.cs | 179 +++++ src/ImageSharp/Colors/Color32Definitions.cs | 728 ++++++++++++++++++ src/ImageSharp/Colors/ColorConstants.cs | 179 ----- src/ImageSharp/Colors/ColorDefinitions.cs | 728 ------------------ src/ImageSharp/Colors/ColorspaceTransforms.cs | 60 +- src/ImageSharp/Colors/ComponentOrder.cs | 8 +- src/ImageSharp/Colors/NamedColors{TColor}.cs | 284 +++---- src/ImageSharp/Colors/PackedPixel/IPixel.cs | 8 +- .../PackedPixel/PackedPixelConverterHelper.cs | 2 +- src/ImageSharp/Colors/Spaces/Bgra32.cs | 6 +- src/ImageSharp/Colors/Spaces/CieLab.cs | 6 +- src/ImageSharp/Colors/Spaces/CieXyz.cs | 6 +- src/ImageSharp/Colors/Spaces/Cmyk.cs | 4 +- src/ImageSharp/Colors/Spaces/Hsl.cs | 6 +- src/ImageSharp/Colors/Spaces/Hsv.cs | 6 +- src/ImageSharp/Colors/Spaces/YCbCr.cs | 6 +- .../Common/Extensions/Vector4Extensions.cs | 2 +- src/ImageSharp/Image.Create.cs | 6 +- src/ImageSharp/Image.FromFile.cs | 2 +- src/ImageSharp/Image.FromStream.cs | 4 +- src/ImageSharp/Image.cs | 4 +- .../ColorMatrix/ColorMatrixProcessor.cs | 2 +- src/ImageSharp/Quantizers/PaletteQuantizer.cs | 2 +- .../Bulk/PackFromVector4ReferenceVsPointer.cs | 10 +- .../Color/Bulk/PackFromXyzw.cs | 4 +- .../Color/Bulk/ToVector4.cs | 2 +- .../ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 4 +- .../Color/Bulk/ToXyzw.cs | 4 +- .../Color/ColorEquality.cs | 2 +- .../Drawing/DrawBeziers.cs | 2 +- .../Drawing/DrawLines.cs | 2 +- .../Drawing/DrawPolygon.cs | 2 +- .../Drawing/FillPolygon.cs | 2 +- .../Drawing/FillRectangle.cs | 2 +- .../Drawing/FillWithPattern.cs | 2 +- .../General/ClearBuffer.cs | 6 +- .../ImageSharp.Benchmarks/Image/CopyPixels.cs | 2 +- .../Image/EncodeIndexedPng.cs | 10 +- .../ImageSharp.Benchmarks/Image/EncodePng.cs | 8 +- .../Image/GetSetPixel.cs | 2 +- .../Colors/BulkPixelOperationsTests.cs | 12 +- .../Colors/ColorConversionTests.cs | 106 +-- .../Colors/ColorDefinitionTests.cs | 10 +- tests/ImageSharp.Tests/Colors/ColorTests.cs | 36 +- .../Colors/ColorTransformTests.cs | 58 +- .../Common/BufferSpanTests.cs | 6 +- .../Common/PixelDataPoolTests.cs | 8 +- .../ImageSharp.Tests/Drawing/BeziersTests.cs | 32 +- .../ImageSharp.Tests/Drawing/DrawPathTests.cs | 22 +- .../Drawing/FillPatternTests.cs | 176 ++--- .../Drawing/FillRegionProcessorTests.cs | 4 +- .../Drawing/FillSolidBrushTests.cs | 26 +- .../Drawing/LineComplexPolygonTests.cs | 80 +- tests/ImageSharp.Tests/Drawing/LineTests.cs | 64 +- .../Drawing/Paths/DrawBeziersTests.cs | 30 +- .../Drawing/Paths/DrawLinesTests.cs | 30 +- .../Drawing/Paths/DrawPath.cs | 30 +- .../Drawing/Paths/DrawPolygon.cs | 30 +- .../Drawing/Paths/DrawRectangle.cs | 30 +- .../Drawing/Paths/FillPath.cs | 16 +- .../Drawing/Paths/FillPolygon.cs | 16 +- .../Drawing/Paths/FillRectangle.cs | 16 +- .../Drawing/Paths/ProcessorWatchingImage.cs | 8 +- .../ImageSharp.Tests/Drawing/PolygonTests.cs | 42 +- .../Drawing/RecolorImageTest.cs | 4 +- .../Drawing/SolidBezierTests.cs | 22 +- .../Drawing/SolidComplexPolygonTests.cs | 30 +- .../Drawing/SolidPolygonTests.cs | 76 +- .../ImageSharp.Tests/Drawing/Text/DrawText.cs | 86 +-- .../Drawing/Text/OutputText.cs | 4 +- .../Formats/Jpg/JpegProfilingBenchmarks.cs | 6 +- .../ImageSharp.Tests/Image/ImageLoadTests.cs | 100 +-- .../ImageSharp.Tests/Image/ImageSaveTests.cs | 24 +- .../Image/PixelAccessorTests.cs | 16 +- .../Profiles/Exif/ExifProfileTests.cs | 2 +- .../Processors/Filters/BackgroundColorTest.cs | 2 +- .../Processors/Filters/GlowTest.cs | 2 +- .../Filters/ResizeProfilingBenchmarks.cs | 6 +- .../Processors/Filters/VignetteTest.cs | 2 +- .../TestUtilities/Factories/ImageFactory.cs | 8 +- .../ImageProviders/TestPatternProvider.cs | 6 +- .../TestUtilities/TestUtilityExtensions.cs | 8 +- .../Tests/TestImageProviderTests.cs | 4 +- .../Tests/TestUtilityExtensionsTests.cs | 18 +- 94 files changed, 1948 insertions(+), 1949 deletions(-) rename src/ImageSharp/Colors/{ColorTransforms.cs => Color32.Transforms.cs} (82%) rename src/ImageSharp/Colors/{Color.cs => Color32.cs} (83%) create mode 100644 src/ImageSharp/Colors/Color32Constants.cs create mode 100644 src/ImageSharp/Colors/Color32Definitions.cs delete mode 100644 src/ImageSharp/Colors/ColorConstants.cs delete mode 100644 src/ImageSharp/Colors/ColorDefinitions.cs diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs index e8269848c..5912dbd51 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs @@ -6,7 +6,7 @@ namespace ImageSharp.Drawing.Brushes { /// - /// A collection of methods for creating brushes. Brushes use for painting. + /// A collection of methods for creating brushes. Brushes use for painting. /// public class Brushes { @@ -15,7 +15,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// A Brush - public static SolidBrush Solid(Color color) + public static SolidBrush Solid(Color32 color) => new SolidBrush(color); /// @@ -24,8 +24,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Percent10(Color foreColor) - => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent)); + public static PatternBrush Percent10(Color32 foreColor) + => new PatternBrush(Brushes.Percent10(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Percent10 Hatch Pattern with @@ -34,8 +34,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent10(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Percent10(foreColor, backColor)); + public static PatternBrush Percent10(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.Percent10(foreColor, backColor)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -43,8 +43,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Percent20(Color foreColor) - => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent)); + public static PatternBrush Percent20(Color32 foreColor) + => new PatternBrush(Brushes.Percent20(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -53,8 +53,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent20(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Percent20(foreColor, backColor)); + public static PatternBrush Percent20(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.Percent20(foreColor, backColor)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -62,8 +62,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Horizontal(Color foreColor) - => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent)); + public static PatternBrush Horizontal(Color32 foreColor) + => new PatternBrush(Brushes.Horizontal(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -72,8 +72,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Horizontal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); + public static PatternBrush Horizontal(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -81,8 +81,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Min(Color foreColor) - => new PatternBrush(Brushes.Min(foreColor, Color.Transparent)); + public static PatternBrush Min(Color32 foreColor) + => new PatternBrush(Brushes.Min(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -91,8 +91,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Min(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Min(foreColor, backColor)); + public static PatternBrush Min(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.Min(foreColor, backColor)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -100,8 +100,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Vertical(Color foreColor) - => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent)); + public static PatternBrush Vertical(Color32 foreColor) + => new PatternBrush(Brushes.Vertical(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -110,8 +110,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Vertical(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Vertical(foreColor, backColor)); + public static PatternBrush Vertical(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.Vertical(foreColor, backColor)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -119,8 +119,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush ForwardDiagonal(Color foreColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent)); + public static PatternBrush ForwardDiagonal(Color32 foreColor) + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -129,8 +129,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); + public static PatternBrush ForwardDiagonal(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -138,8 +138,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush BackwardDiagonal(Color foreColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent)); + public static PatternBrush BackwardDiagonal(Color32 foreColor) + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color32.Transparent)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -148,7 +148,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); + public static PatternBrush BackwardDiagonal(Color32 foreColor, Color32 backColor) + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs index a7124bfe8..9ffd7e42b 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs @@ -6,15 +6,15 @@ namespace ImageSharp.Drawing.Brushes { /// - /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. + /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. /// - public class ImageBrush : ImageBrush + public class ImageBrush : ImageBrush { /// /// Initializes a new instance of the class. /// /// The image to paint. - public ImageBrush(IImageBase image) + public ImageBrush(IImageBase image) : base(image) { } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs index 5093a7df0..027029718 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs @@ -6,9 +6,9 @@ namespace ImageSharp.Drawing.Brushes { /// - /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. + /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. /// - public class PatternBrush : PatternBrush + public class PatternBrush : PatternBrush { /// /// Initializes a new instance of the class. @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the fore. /// Color of the back. /// The pattern. - public PatternBrush(Color foreColor, Color backColor, bool[,] pattern) + public PatternBrush(Color32 foreColor, Color32 backColor, bool[,] pattern) : base(foreColor, backColor, pattern) { } @@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Brushes /// Initializes a new instance of the class. /// /// The brush. - internal PatternBrush(PatternBrush brush) + internal PatternBrush(PatternBrush brush) : base(brush) { } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs index 0452a3f01..fce052cb8 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Drawing.Brushes /// /// Provides an implementation of a recolor brush for painting color changes. /// - public class RecolorBrush : RecolorBrush + public class RecolorBrush : RecolorBrush { /// /// Initializes a new instance of the class. @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the source. /// Color of the target. /// The threshold. - public RecolorBrush(Color sourceColor, Color targetColor, float threshold) + public RecolorBrush(Color32 sourceColor, Color32 targetColor, float threshold) : base(sourceColor, targetColor, threshold) { } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs index 123d8a7e3..93e2af6a4 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs @@ -6,15 +6,15 @@ namespace ImageSharp.Drawing.Brushes { /// - /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. + /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. /// - public class SolidBrush : SolidBrush + public class SolidBrush : SolidBrush { /// /// Initializes a new instance of the class. /// /// The color. - public SolidBrush(Color color) + public SolidBrush(Color32 color) : base(color) { } diff --git a/src/ImageSharp.Drawing/Pens/Pen.cs b/src/ImageSharp.Drawing/Pens/Pen.cs index 09fe89419..1b75c38b7 100644 --- a/src/ImageSharp.Drawing/Pens/Pen.cs +++ b/src/ImageSharp.Drawing/Pens/Pen.cs @@ -6,16 +6,16 @@ namespace ImageSharp.Drawing.Pens { /// - /// Represents a in the color space. + /// Represents a in the color space. /// - public class Pen : Pen + public class Pen : Pen { /// /// Initializes a new instance of the class. /// /// The color. /// The width. - public Pen(Color color, float width) + public Pen(Color32 color, float width) : base(color, width) { } @@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Pens /// /// The brush. /// The width. - public Pen(IBrush brush, float width) + public Pen(IBrush brush, float width) : base(brush, width) { } @@ -36,7 +36,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) + public Pen(IBrush brush, float width, float[] pattern) : base(brush, width, pattern) { } @@ -45,7 +45,7 @@ namespace ImageSharp.Drawing.Pens /// Initializes a new instance of the class. /// /// The pen. - internal Pen(Pen pen) + internal Pen(Pen pen) : base(pen) { } diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Pens/Pens.cs index 039b7113f..b45695ceb 100644 --- a/src/ImageSharp.Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Pens/Pens.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Solid(Color color, float width) => new Pen(color, width); + public static Pen Solid(Color32 color, float width) => new Pen(color, width); /// /// Create a solid pen with out any drawing patterns @@ -24,7 +24,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); + public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); /// /// Create a pen with a 'Dash' drawing patterns @@ -32,7 +32,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dash(Color color, float width) => new Pen(Pens.Dash(color, width)); + public static Pen Dash(Color32 color, float width) => new Pen(Pens.Dash(color, width)); /// /// Create a pen with a 'Dash' drawing patterns @@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); + public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -48,7 +48,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dot(Color color, float width) => new Pen(Pens.Dot(color, width)); + public static Pen Dot(Color32 color, float width) => new Pen(Pens.Dot(color, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -56,7 +56,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); + public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -64,7 +64,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDot(Color color, float width) => new Pen(Pens.DashDot(color, width)); + public static Pen DashDot(Color32 color, float width) => new Pen(Pens.DashDot(color, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -72,7 +72,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); + public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -80,7 +80,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDotDot(Color color, float width) => new Pen(Pens.DashDotDot(color, width)); + public static Pen DashDotDot(Color32 color, float width) => new Pen(Pens.DashDotDot(color, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -88,6 +88,6 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); + public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 7d3b12ea0..9101b6b23 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -8,17 +8,16 @@ namespace ImageSharp using System; using System.Numerics; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; /// /// Conains the definition of /// - public partial struct Color + public partial struct Color32 { /// - /// implementation optimized for . + /// implementation optimized for . /// - internal class BulkOperations : BulkPixelOperations + internal class BulkOperations : BulkPixelOperations { /// /// SIMD optimized bulk implementation of @@ -38,7 +37,7 @@ namespace ImageSharp /// /// internal static unsafe void ToVector4SimdAligned( - BufferSpan sourceColors, + BufferSpan sourceColors, BufferSpan destVectors, int count) { @@ -96,7 +95,7 @@ namespace ImageSharp } /// - internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) { if (count < 256 || !Vector.IsHardwareAccelerated) { @@ -123,7 +122,7 @@ namespace ImageSharp } /// - internal override unsafe void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override unsafe void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { byte* source = (byte*)sourceBytes; byte* destination = (byte*)destColors; @@ -138,7 +137,7 @@ namespace ImageSharp } /// - internal override unsafe void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override unsafe void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { byte* source = (byte*)sourceColors; byte* destination = (byte*)destBytes; @@ -155,19 +154,19 @@ namespace ImageSharp } /// - internal override void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { BufferSpan.Copy(sourceBytes, destColors, count); } /// - internal override void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { BufferSpan.Copy(sourceColors, destBytes, count); } /// - internal override unsafe void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override unsafe void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { byte* source = (byte*)sourceBytes; byte* destination = (byte*)destColors; @@ -182,7 +181,7 @@ namespace ImageSharp } /// - internal override unsafe void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override unsafe void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { byte* source = (byte*)sourceColors; byte* destination = (byte*)destBytes; @@ -199,7 +198,7 @@ namespace ImageSharp } /// - internal override unsafe void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override unsafe void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { byte* source = (byte*)sourceBytes; byte* destination = (byte*)destColors; @@ -214,7 +213,7 @@ namespace ImageSharp } /// - internal override unsafe void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override unsafe void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { byte* source = (byte*)sourceColors; byte* destination = (byte*)destBytes; @@ -232,7 +231,7 @@ namespace ImageSharp } /// - /// Value type to store -s unpacked into multiple -s. + /// Value type to store -s unpacked into multiple -s. /// private struct UnpackedRGBA { @@ -245,9 +244,9 @@ namespace ImageSharp public void Load(uint p) { this.r = p; - this.g = p >> Color.GreenShift; - this.b = p >> Color.BlueShift; - this.a = p >> Color.AlphaShift; + this.g = p >> Color32.GreenShift; + this.b = p >> Color32.BlueShift; + this.a = p >> Color32.AlphaShift; } } } diff --git a/src/ImageSharp/Colors/ColorTransforms.cs b/src/ImageSharp/Colors/Color32.Transforms.cs similarity index 82% rename from src/ImageSharp/Colors/ColorTransforms.cs rename to src/ImageSharp/Colors/Color32.Transforms.cs index e392d7d98..43c947b8b 100644 --- a/src/ImageSharp/Colors/ColorTransforms.cs +++ b/src/ImageSharp/Colors/Color32.Transforms.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -15,7 +15,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 partial struct Color + public partial struct Color32 { /// /// Adds the second color to the first. @@ -23,9 +23,9 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// - public static Color operator +(Color left, Color right) + public static Color32 operator +(Color32 left, Color32 right) { Vector4 add = left.ToVector4() + right.ToVector4(); return Pack(ref add); @@ -37,9 +37,9 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// - public static Color operator -(Color left, Color right) + public static Color32 operator -(Color32 left, Color32 right) { Vector4 sub = left.ToVector4() - right.ToVector4(); return Pack(ref sub); @@ -51,9 +51,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Normal(Color backdrop, Color source) + public static Color32 Normal(Color32 backdrop, Color32 source) { Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4()); return Pack(ref normal); @@ -71,9 +71,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Multiply(Color backdrop, Color source) + public static Color32 Multiply(Color32 backdrop, Color32 source) { Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4()); return Pack(ref multiply); @@ -90,9 +90,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Screen(Color backdrop, Color source) + public static Color32 Screen(Color32 backdrop, Color32 source) { Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4()); return Pack(ref subtract); @@ -105,9 +105,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color HardLight(Color backdrop, Color source) + public static Color32 HardLight(Color32 backdrop, Color32 source) { Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4()); return Pack(ref hardlight); @@ -124,9 +124,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Overlay(Color backdrop, Color source) + public static Color32 Overlay(Color32 backdrop, Color32 source) { Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4()); return Pack(ref overlay); @@ -139,9 +139,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Darken(Color backdrop, Color source) + public static Color32 Darken(Color32 backdrop, Color32 source) { Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4()); return Pack(ref darken); @@ -154,9 +154,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Lighten(Color backdrop, Color source) + public static Color32 Lighten(Color32 backdrop, Color32 source) { Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4()); return Pack(ref lighten); @@ -169,9 +169,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color SoftLight(Color backdrop, Color source) + public static Color32 SoftLight(Color32 backdrop, Color32 source) { Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4()); return Pack(ref softlight); @@ -183,9 +183,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color ColorDodge(Color backdrop, Color source) + public static Color32 ColorDodge(Color32 backdrop, Color32 source) { Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4()); return Pack(ref dodge); @@ -197,9 +197,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color ColorBurn(Color backdrop, Color source) + public static Color32 ColorBurn(Color32 backdrop, Color32 source) { Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4()); return Pack(ref burn); @@ -212,9 +212,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Difference(Color backdrop, Color source) + public static Color32 Difference(Color32 backdrop, Color32 source) { Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4()); return Pack(ref difference); @@ -227,9 +227,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Exclusion(Color backdrop, Color source) + public static Color32 Exclusion(Color32 backdrop, Color32 source) { Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4()); return Pack(ref exclusion); @@ -245,11 +245,11 @@ namespace ImageSharp /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// /// - /// The + /// The /// - public static Color Lerp(Color from, Color to, float amount) + public static Color32 Lerp(Color32 from, Color32 to, float amount) { - return new Color(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount)); + return new Color32(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color32.cs similarity index 83% rename from src/ImageSharp/Colors/Color.cs rename to src/ImageSharp/Colors/Color32.cs index c9d777c59..f7f1aceec 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color32.cs @@ -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 Color32 : IPixel { /// /// Gets or sets the red component. @@ -75,13 +75,13 @@ 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 Color(byte r, byte g, byte b, byte a = 255) + public Color32(byte r, byte g, byte b, byte a = 255) : this() { this.R = r; @@ -91,56 +91,56 @@ namespace ImageSharp } /// - /// 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 Color(float r, float g, float b, float a = 1) + public Color32(float r, float g, float b, float a = 1) : this() { this = 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 Color(Vector3 vector) + public Color32(Vector3 vector) : this() { this = 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 Color(Vector4 vector) + public Color32(Vector4 vector) : this() { this = Pack(ref vector); } /// - /// 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 ==(Color left, Color right) + public static bool operator ==(Color32 left, Color32 right) { return left.R == right.R && left.G == right.G @@ -149,15 +149,15 @@ namespace ImageSharp } /// - /// 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 !=(Color left, Color right) + public static bool operator !=(Color32 left, Color32 right) { return left.R != right.R && left.G != right.G @@ -166,22 +166,22 @@ namespace ImageSharp } /// - /// Creates a new instance of the struct. + /// 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 . + /// The . /// - public static Color FromHex(string hex) + public static Color32 FromHex(string hex) { - return ColorBuilder.FromHex(hex); + return ColorBuilder.FromHex(hex); } /// - public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); + public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -258,12 +258,12 @@ namespace ImageSharp /// public override bool Equals(object obj) { - return (obj is Color) && this.Equals((Color)obj); + return (obj is Color32) && this.Equals((Color32)obj); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Color other) + public bool Equals(Color32 other) { return this.R == other.R && this.G == other.G @@ -311,24 +311,24 @@ namespace ImageSharp /// Packs a into a uint. /// /// The vector containing the values to pack. - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Color Pack(ref Vector4 vector) + private static Color32 Pack(ref Vector4 vector) { vector *= MaxBytes; vector += Half; vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); - return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); + return new Color32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); } /// /// Packs a into a uint. /// /// The vector containing the values to pack. - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Color Pack(ref Vector3 vector) + private static Color32 Pack(ref Vector3 vector) { Vector4 value = new Vector4(vector, 1); return Pack(ref value); @@ -341,9 +341,9 @@ namespace ImageSharp /// The y-component /// The z-component /// The w-component - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Color Pack(float x, float y, float z, float w) + private static Color32 Pack(float x, float y, float z, float w) { Vector4 value = new Vector4(x, y, z, w); return Pack(ref value); diff --git a/src/ImageSharp/Colors/Color32Constants.cs b/src/ImageSharp/Colors/Color32Constants.cs new file mode 100644 index 000000000..7c88b8117 --- /dev/null +++ b/src/ImageSharp/Colors/Color32Constants.cs @@ -0,0 +1,179 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Collections.Generic; + + /// + /// Provides useful color definitions. + /// + public static class Color32Constants + { + /// + /// Provides a lazy, one time method of returning the colors. + /// + private static readonly Lazy SafeColors = new Lazy(GetWebSafeColors); + + /// + /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. + /// + public static Color32[] WebSafeColors => SafeColors.Value; + + /// + /// Returns an array of web safe colors. + /// + /// The + private static Color32[] GetWebSafeColors() + { + return new List + { + Color32.AliceBlue, + Color32.AntiqueWhite, + Color32.Aqua, + Color32.Aquamarine, + Color32.Azure, + Color32.Beige, + Color32.Bisque, + Color32.Black, + Color32.BlanchedAlmond, + Color32.Blue, + Color32.BlueViolet, + Color32.Brown, + Color32.BurlyWood, + Color32.CadetBlue, + Color32.Chartreuse, + Color32.Chocolate, + Color32.Coral, + Color32.CornflowerBlue, + Color32.Cornsilk, + Color32.Crimson, + Color32.Cyan, + Color32.DarkBlue, + Color32.DarkCyan, + Color32.DarkGoldenrod, + Color32.DarkGray, + Color32.DarkGreen, + Color32.DarkKhaki, + Color32.DarkMagenta, + Color32.DarkOliveGreen, + Color32.DarkOrange, + Color32.DarkOrchid, + Color32.DarkRed, + Color32.DarkSalmon, + Color32.DarkSeaGreen, + Color32.DarkSlateBlue, + Color32.DarkSlateGray, + Color32.DarkTurquoise, + Color32.DarkViolet, + Color32.DeepPink, + Color32.DeepSkyBlue, + Color32.DimGray, + Color32.DodgerBlue, + Color32.Firebrick, + Color32.FloralWhite, + Color32.ForestGreen, + Color32.Fuchsia, + Color32.Gainsboro, + Color32.GhostWhite, + Color32.Gold, + Color32.Goldenrod, + Color32.Gray, + Color32.Green, + Color32.GreenYellow, + Color32.Honeydew, + Color32.HotPink, + Color32.IndianRed, + Color32.Indigo, + Color32.Ivory, + Color32.Khaki, + Color32.Lavender, + Color32.LavenderBlush, + Color32.LawnGreen, + Color32.LemonChiffon, + Color32.LightBlue, + Color32.LightCoral, + Color32.LightCyan, + Color32.LightGoldenrodYellow, + Color32.LightGray, + Color32.LightGreen, + Color32.LightPink, + Color32.LightSalmon, + Color32.LightSeaGreen, + Color32.LightSkyBlue, + Color32.LightSlateGray, + Color32.LightSteelBlue, + Color32.LightYellow, + Color32.Lime, + Color32.LimeGreen, + Color32.Linen, + Color32.Magenta, + Color32.Maroon, + Color32.MediumAquamarine, + Color32.MediumBlue, + Color32.MediumOrchid, + Color32.MediumPurple, + Color32.MediumSeaGreen, + Color32.MediumSlateBlue, + Color32.MediumSpringGreen, + Color32.MediumTurquoise, + Color32.MediumVioletRed, + Color32.MidnightBlue, + Color32.MintCream, + Color32.MistyRose, + Color32.Moccasin, + Color32.NavajoWhite, + Color32.Navy, + Color32.OldLace, + Color32.Olive, + Color32.OliveDrab, + Color32.Orange, + Color32.OrangeRed, + Color32.Orchid, + Color32.PaleGoldenrod, + Color32.PaleGreen, + Color32.PaleTurquoise, + Color32.PaleVioletRed, + Color32.PapayaWhip, + Color32.PeachPuff, + Color32.Peru, + Color32.Pink, + Color32.Plum, + Color32.PowderBlue, + Color32.Purple, + Color32.RebeccaPurple, + Color32.Red, + Color32.RosyBrown, + Color32.RoyalBlue, + Color32.SaddleBrown, + Color32.Salmon, + Color32.SandyBrown, + Color32.SeaGreen, + Color32.SeaShell, + Color32.Sienna, + Color32.Silver, + Color32.SkyBlue, + Color32.SlateBlue, + Color32.SlateGray, + Color32.Snow, + Color32.SpringGreen, + Color32.SteelBlue, + Color32.Tan, + Color32.Teal, + Color32.Thistle, + Color32.Tomato, + Color32.Transparent, + Color32.Turquoise, + Color32.Violet, + Color32.Wheat, + Color32.White, + Color32.WhiteSmoke, + Color32.Yellow, + Color32.YellowGreen + }.ToArray(); + } + } +} diff --git a/src/ImageSharp/Colors/Color32Definitions.cs b/src/ImageSharp/Colors/Color32Definitions.cs new file mode 100644 index 000000000..5c361b428 --- /dev/null +++ b/src/ImageSharp/Colors/Color32Definitions.cs @@ -0,0 +1,728 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + /// + /// Packed vector 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 partial struct Color32 + { + /// + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// + public static readonly Color32 AliceBlue = NamedColors.AliceBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// + public static readonly Color32 AntiqueWhite = NamedColors.AntiqueWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly Color32 Aqua = NamedColors.Aqua; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// + public static readonly Color32 Aquamarine = NamedColors.Aquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// + public static readonly Color32 Azure = NamedColors.Azure; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// + public static readonly Color32 Beige = NamedColors.Beige; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// + public static readonly Color32 Bisque = NamedColors.Bisque; + + /// + /// Represents a matching the W3C definition that has an hex value of #000000. + /// + public static readonly Color32 Black = NamedColors.Black; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// + public static readonly Color32 BlanchedAlmond = NamedColors.BlanchedAlmond; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// + public static readonly Color32 Blue = NamedColors.Blue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// + public static readonly Color32 BlueViolet = NamedColors.BlueViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// + public static readonly Color32 Brown = NamedColors.Brown; + + /// + /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// + public static readonly Color32 BurlyWood = NamedColors.BurlyWood; + + /// + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// + public static readonly Color32 CadetBlue = NamedColors.CadetBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// + public static readonly Color32 Chartreuse = NamedColors.Chartreuse; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// + public static readonly Color32 Chocolate = NamedColors.Chocolate; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// + public static readonly Color32 Coral = NamedColors.Coral; + + /// + /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// + public static readonly Color32 CornflowerBlue = NamedColors.CornflowerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// + public static readonly Color32 Cornsilk = NamedColors.Cornsilk; + + /// + /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// + public static readonly Color32 Crimson = NamedColors.Crimson; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly Color32 Cyan = NamedColors.Cyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #00008B. + /// + public static readonly Color32 DarkBlue = NamedColors.DarkBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// + public static readonly Color32 DarkCyan = NamedColors.DarkCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// + public static readonly Color32 DarkGoldenrod = NamedColors.DarkGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// + public static readonly Color32 DarkGray = NamedColors.DarkGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #006400. + /// + public static readonly Color32 DarkGreen = NamedColors.DarkGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// + public static readonly Color32 DarkKhaki = NamedColors.DarkKhaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// + public static readonly Color32 DarkMagenta = NamedColors.DarkMagenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// + public static readonly Color32 DarkOliveGreen = NamedColors.DarkOliveGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// + public static readonly Color32 DarkOrange = NamedColors.DarkOrange; + + /// + /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// + public static readonly Color32 DarkOrchid = NamedColors.DarkOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// + public static readonly Color32 DarkRed = NamedColors.DarkRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// + public static readonly Color32 DarkSalmon = NamedColors.DarkSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// + public static readonly Color32 DarkSeaGreen = NamedColors.DarkSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// + public static readonly Color32 DarkSlateBlue = NamedColors.DarkSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// + public static readonly Color32 DarkSlateGray = NamedColors.DarkSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// + public static readonly Color32 DarkTurquoise = NamedColors.DarkTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// + public static readonly Color32 DarkViolet = NamedColors.DarkViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// + public static readonly Color32 DeepPink = NamedColors.DeepPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// + public static readonly Color32 DeepSkyBlue = NamedColors.DeepSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #696969. + /// + public static readonly Color32 DimGray = NamedColors.DimGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// + public static readonly Color32 DodgerBlue = NamedColors.DodgerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #B22222. + /// + public static readonly Color32 Firebrick = NamedColors.Firebrick; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// + public static readonly Color32 FloralWhite = NamedColors.FloralWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #228B22. + /// + public static readonly Color32 ForestGreen = NamedColors.ForestGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly Color32 Fuchsia = NamedColors.Fuchsia; + + /// + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// + public static readonly Color32 Gainsboro = NamedColors.Gainsboro; + + /// + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// + public static readonly Color32 GhostWhite = NamedColors.GhostWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// + public static readonly Color32 Gold = NamedColors.Gold; + + /// + /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// + public static readonly Color32 Goldenrod = NamedColors.Goldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #808080. + /// + public static readonly Color32 Gray = NamedColors.Gray; + + /// + /// Represents a matching the W3C definition that has an hex value of #008000. + /// + public static readonly Color32 Green = NamedColors.Green; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// + public static readonly Color32 GreenYellow = NamedColors.GreenYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// + public static readonly Color32 Honeydew = NamedColors.Honeydew; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// + public static readonly Color32 HotPink = NamedColors.HotPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// + public static readonly Color32 IndianRed = NamedColors.IndianRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// + public static readonly Color32 Indigo = NamedColors.Indigo; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// + public static readonly Color32 Ivory = NamedColors.Ivory; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// + public static readonly Color32 Khaki = NamedColors.Khaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// + public static readonly Color32 Lavender = NamedColors.Lavender; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// + public static readonly Color32 LavenderBlush = NamedColors.LavenderBlush; + + /// + /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// + public static readonly Color32 LawnGreen = NamedColors.LawnGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// + public static readonly Color32 LemonChiffon = NamedColors.LemonChiffon; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// + public static readonly Color32 LightBlue = NamedColors.LightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F08080. + /// + public static readonly Color32 LightCoral = NamedColors.LightCoral; + + /// + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// + public static readonly Color32 LightCyan = NamedColors.LightCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// + public static readonly Color32 LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// + public static readonly Color32 LightGray = NamedColors.LightGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// + public static readonly Color32 LightGreen = NamedColors.LightGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// + public static readonly Color32 LightPink = NamedColors.LightPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// + public static readonly Color32 LightSalmon = NamedColors.LightSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// + public static readonly Color32 LightSeaGreen = NamedColors.LightSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// + public static readonly Color32 LightSkyBlue = NamedColors.LightSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #778899. + /// + public static readonly Color32 LightSlateGray = NamedColors.LightSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// + public static readonly Color32 LightSteelBlue = NamedColors.LightSteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// + public static readonly Color32 LightYellow = NamedColors.LightYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// + public static readonly Color32 Lime = NamedColors.Lime; + + /// + /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// + public static readonly Color32 LimeGreen = NamedColors.LimeGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// + public static readonly Color32 Linen = NamedColors.Linen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly Color32 Magenta = NamedColors.Magenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #800000. + /// + public static readonly Color32 Maroon = NamedColors.Maroon; + + /// + /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// + public static readonly Color32 MediumAquamarine = NamedColors.MediumAquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// + public static readonly Color32 MediumBlue = NamedColors.MediumBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// + public static readonly Color32 MediumOrchid = NamedColors.MediumOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// + public static readonly Color32 MediumPurple = NamedColors.MediumPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// + public static readonly Color32 MediumSeaGreen = NamedColors.MediumSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// + public static readonly Color32 MediumSlateBlue = NamedColors.MediumSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// + public static readonly Color32 MediumSpringGreen = NamedColors.MediumSpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// + public static readonly Color32 MediumTurquoise = NamedColors.MediumTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #C71585. + /// + public static readonly Color32 MediumVioletRed = NamedColors.MediumVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #191970. + /// + public static readonly Color32 MidnightBlue = NamedColors.MidnightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// + public static readonly Color32 MintCream = NamedColors.MintCream; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// + public static readonly Color32 MistyRose = NamedColors.MistyRose; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// + public static readonly Color32 Moccasin = NamedColors.Moccasin; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// + public static readonly Color32 NavajoWhite = NamedColors.NavajoWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #000080. + /// + public static readonly Color32 Navy = NamedColors.Navy; + + /// + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// + public static readonly Color32 OldLace = NamedColors.OldLace; + + /// + /// Represents a matching the W3C definition that has an hex value of #808000. + /// + public static readonly Color32 Olive = NamedColors.Olive; + + /// + /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// + public static readonly Color32 OliveDrab = NamedColors.OliveDrab; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// + public static readonly Color32 Orange = NamedColors.Orange; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// + public static readonly Color32 OrangeRed = NamedColors.OrangeRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// + public static readonly Color32 Orchid = NamedColors.Orchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// + public static readonly Color32 PaleGoldenrod = NamedColors.PaleGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// + public static readonly Color32 PaleGreen = NamedColors.PaleGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// + public static readonly Color32 PaleTurquoise = NamedColors.PaleTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// + public static readonly Color32 PaleVioletRed = NamedColors.PaleVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// + public static readonly Color32 PapayaWhip = NamedColors.PapayaWhip; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// + public static readonly Color32 PeachPuff = NamedColors.PeachPuff; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// + public static readonly Color32 Peru = NamedColors.Peru; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// + public static readonly Color32 Pink = NamedColors.Pink; + + /// + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// + public static readonly Color32 Plum = NamedColors.Plum; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// + public static readonly Color32 PowderBlue = NamedColors.PowderBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #800080. + /// + public static readonly Color32 Purple = NamedColors.Purple; + + /// + /// Represents a matching the W3C definition that has an hex value of #663399. + /// + public static readonly Color32 RebeccaPurple = NamedColors.RebeccaPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// + public static readonly Color32 Red = NamedColors.Red; + + /// + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// + public static readonly Color32 RosyBrown = NamedColors.RosyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// + public static readonly Color32 RoyalBlue = NamedColors.RoyalBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// + public static readonly Color32 SaddleBrown = NamedColors.SaddleBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// + public static readonly Color32 Salmon = NamedColors.Salmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// + public static readonly Color32 SandyBrown = NamedColors.SandyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// + public static readonly Color32 SeaGreen = NamedColors.SeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// + public static readonly Color32 SeaShell = NamedColors.SeaShell; + + /// + /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// + public static readonly Color32 Sienna = NamedColors.Sienna; + + /// + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// + public static readonly Color32 Silver = NamedColors.Silver; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// + public static readonly Color32 SkyBlue = NamedColors.SkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// + public static readonly Color32 SlateBlue = NamedColors.SlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #708090. + /// + public static readonly Color32 SlateGray = NamedColors.SlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// + public static readonly Color32 Snow = NamedColors.Snow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// + public static readonly Color32 SpringGreen = NamedColors.SpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// + public static readonly Color32 SteelBlue = NamedColors.SteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// + public static readonly Color32 Tan = NamedColors.Tan; + + /// + /// Represents a matching the W3C definition that has an hex value of #008080. + /// + public static readonly Color32 Teal = NamedColors.Teal; + + /// + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// + public static readonly Color32 Thistle = NamedColors.Thistle; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// + public static readonly Color32 Tomato = NamedColors.Tomato; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly Color32 Transparent = NamedColors.Transparent; + + /// + /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// + public static readonly Color32 Turquoise = NamedColors.Turquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// + public static readonly Color32 Violet = NamedColors.Violet; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// + public static readonly Color32 Wheat = NamedColors.Wheat; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly Color32 White = NamedColors.White; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// + public static readonly Color32 WhiteSmoke = NamedColors.WhiteSmoke; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// + public static readonly Color32 Yellow = NamedColors.Yellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// + public static readonly Color32 YellowGreen = NamedColors.YellowGreen; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorConstants.cs b/src/ImageSharp/Colors/ColorConstants.cs deleted file mode 100644 index 1397b6da6..000000000 --- a/src/ImageSharp/Colors/ColorConstants.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - - /// - /// Provides useful color definitions. - /// - public static class ColorConstants - { - /// - /// Provides a lazy, one time method of returning the colors. - /// - private static readonly Lazy SafeColors = new Lazy(GetWebSafeColors); - - /// - /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. - /// - public static Color[] WebSafeColors => SafeColors.Value; - - /// - /// Returns an array of web safe colors. - /// - /// The - private static Color[] GetWebSafeColors() - { - return new List - { - Color.AliceBlue, - Color.AntiqueWhite, - Color.Aqua, - Color.Aquamarine, - Color.Azure, - Color.Beige, - Color.Bisque, - Color.Black, - Color.BlanchedAlmond, - Color.Blue, - Color.BlueViolet, - Color.Brown, - Color.BurlyWood, - Color.CadetBlue, - Color.Chartreuse, - Color.Chocolate, - Color.Coral, - Color.CornflowerBlue, - Color.Cornsilk, - Color.Crimson, - Color.Cyan, - Color.DarkBlue, - Color.DarkCyan, - Color.DarkGoldenrod, - Color.DarkGray, - Color.DarkGreen, - Color.DarkKhaki, - Color.DarkMagenta, - Color.DarkOliveGreen, - Color.DarkOrange, - Color.DarkOrchid, - Color.DarkRed, - Color.DarkSalmon, - Color.DarkSeaGreen, - Color.DarkSlateBlue, - Color.DarkSlateGray, - Color.DarkTurquoise, - Color.DarkViolet, - Color.DeepPink, - Color.DeepSkyBlue, - Color.DimGray, - Color.DodgerBlue, - Color.Firebrick, - Color.FloralWhite, - Color.ForestGreen, - Color.Fuchsia, - Color.Gainsboro, - Color.GhostWhite, - Color.Gold, - Color.Goldenrod, - Color.Gray, - Color.Green, - Color.GreenYellow, - Color.Honeydew, - Color.HotPink, - Color.IndianRed, - Color.Indigo, - Color.Ivory, - Color.Khaki, - Color.Lavender, - Color.LavenderBlush, - Color.LawnGreen, - Color.LemonChiffon, - Color.LightBlue, - Color.LightCoral, - Color.LightCyan, - Color.LightGoldenrodYellow, - Color.LightGray, - Color.LightGreen, - Color.LightPink, - Color.LightSalmon, - Color.LightSeaGreen, - Color.LightSkyBlue, - Color.LightSlateGray, - Color.LightSteelBlue, - Color.LightYellow, - Color.Lime, - Color.LimeGreen, - Color.Linen, - Color.Magenta, - Color.Maroon, - Color.MediumAquamarine, - Color.MediumBlue, - Color.MediumOrchid, - Color.MediumPurple, - Color.MediumSeaGreen, - Color.MediumSlateBlue, - Color.MediumSpringGreen, - Color.MediumTurquoise, - Color.MediumVioletRed, - Color.MidnightBlue, - Color.MintCream, - Color.MistyRose, - Color.Moccasin, - Color.NavajoWhite, - Color.Navy, - Color.OldLace, - Color.Olive, - Color.OliveDrab, - Color.Orange, - Color.OrangeRed, - Color.Orchid, - Color.PaleGoldenrod, - Color.PaleGreen, - Color.PaleTurquoise, - Color.PaleVioletRed, - Color.PapayaWhip, - Color.PeachPuff, - Color.Peru, - Color.Pink, - Color.Plum, - Color.PowderBlue, - Color.Purple, - Color.RebeccaPurple, - Color.Red, - Color.RosyBrown, - Color.RoyalBlue, - Color.SaddleBrown, - Color.Salmon, - Color.SandyBrown, - Color.SeaGreen, - Color.SeaShell, - Color.Sienna, - Color.Silver, - Color.SkyBlue, - Color.SlateBlue, - Color.SlateGray, - Color.Snow, - Color.SpringGreen, - Color.SteelBlue, - Color.Tan, - Color.Teal, - Color.Thistle, - Color.Tomato, - Color.Transparent, - Color.Turquoise, - Color.Violet, - Color.Wheat, - Color.White, - Color.WhiteSmoke, - Color.Yellow, - Color.YellowGreen - }.ToArray(); - } - } -} diff --git a/src/ImageSharp/Colors/ColorDefinitions.cs b/src/ImageSharp/Colors/ColorDefinitions.cs deleted file mode 100644 index 65165289d..000000000 --- a/src/ImageSharp/Colors/ColorDefinitions.cs +++ /dev/null @@ -1,728 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - /// - /// Packed vector 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 partial struct Color - { - /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. - /// - public static readonly Color AliceBlue = NamedColors.AliceBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. - /// - public static readonly Color AntiqueWhite = NamedColors.AntiqueWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly Color Aqua = NamedColors.Aqua; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. - /// - public static readonly Color Aquamarine = NamedColors.Aquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. - /// - public static readonly Color Azure = NamedColors.Azure; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. - /// - public static readonly Color Beige = NamedColors.Beige; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. - /// - public static readonly Color Bisque = NamedColors.Bisque; - - /// - /// Represents a matching the W3C definition that has an hex value of #000000. - /// - public static readonly Color Black = NamedColors.Black; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. - /// - public static readonly Color BlanchedAlmond = NamedColors.BlanchedAlmond; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. - /// - public static readonly Color Blue = NamedColors.Blue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. - /// - public static readonly Color BlueViolet = NamedColors.BlueViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. - /// - public static readonly Color Brown = NamedColors.Brown; - - /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. - /// - public static readonly Color BurlyWood = NamedColors.BurlyWood; - - /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. - /// - public static readonly Color CadetBlue = NamedColors.CadetBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. - /// - public static readonly Color Chartreuse = NamedColors.Chartreuse; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. - /// - public static readonly Color Chocolate = NamedColors.Chocolate; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. - /// - public static readonly Color Coral = NamedColors.Coral; - - /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. - /// - public static readonly Color CornflowerBlue = NamedColors.CornflowerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. - /// - public static readonly Color Cornsilk = NamedColors.Cornsilk; - - /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. - /// - public static readonly Color Crimson = NamedColors.Crimson; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly Color Cyan = NamedColors.Cyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #00008B. - /// - public static readonly Color DarkBlue = NamedColors.DarkBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. - /// - public static readonly Color DarkCyan = NamedColors.DarkCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. - /// - public static readonly Color DarkGoldenrod = NamedColors.DarkGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. - /// - public static readonly Color DarkGray = NamedColors.DarkGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #006400. - /// - public static readonly Color DarkGreen = NamedColors.DarkGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. - /// - public static readonly Color DarkKhaki = NamedColors.DarkKhaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. - /// - public static readonly Color DarkMagenta = NamedColors.DarkMagenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. - /// - public static readonly Color DarkOliveGreen = NamedColors.DarkOliveGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. - /// - public static readonly Color DarkOrange = NamedColors.DarkOrange; - - /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. - /// - public static readonly Color DarkOrchid = NamedColors.DarkOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. - /// - public static readonly Color DarkRed = NamedColors.DarkRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. - /// - public static readonly Color DarkSalmon = NamedColors.DarkSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. - /// - public static readonly Color DarkSeaGreen = NamedColors.DarkSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. - /// - public static readonly Color DarkSlateBlue = NamedColors.DarkSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. - /// - public static readonly Color DarkSlateGray = NamedColors.DarkSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. - /// - public static readonly Color DarkTurquoise = NamedColors.DarkTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. - /// - public static readonly Color DarkViolet = NamedColors.DarkViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. - /// - public static readonly Color DeepPink = NamedColors.DeepPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. - /// - public static readonly Color DeepSkyBlue = NamedColors.DeepSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #696969. - /// - public static readonly Color DimGray = NamedColors.DimGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. - /// - public static readonly Color DodgerBlue = NamedColors.DodgerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #B22222. - /// - public static readonly Color Firebrick = NamedColors.Firebrick; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. - /// - public static readonly Color FloralWhite = NamedColors.FloralWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #228B22. - /// - public static readonly Color ForestGreen = NamedColors.ForestGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly Color Fuchsia = NamedColors.Fuchsia; - - /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. - /// - public static readonly Color Gainsboro = NamedColors.Gainsboro; - - /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. - /// - public static readonly Color GhostWhite = NamedColors.GhostWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. - /// - public static readonly Color Gold = NamedColors.Gold; - - /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. - /// - public static readonly Color Goldenrod = NamedColors.Goldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #808080. - /// - public static readonly Color Gray = NamedColors.Gray; - - /// - /// Represents a matching the W3C definition that has an hex value of #008000. - /// - public static readonly Color Green = NamedColors.Green; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. - /// - public static readonly Color GreenYellow = NamedColors.GreenYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. - /// - public static readonly Color Honeydew = NamedColors.Honeydew; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. - /// - public static readonly Color HotPink = NamedColors.HotPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. - /// - public static readonly Color IndianRed = NamedColors.IndianRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. - /// - public static readonly Color Indigo = NamedColors.Indigo; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. - /// - public static readonly Color Ivory = NamedColors.Ivory; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. - /// - public static readonly Color Khaki = NamedColors.Khaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. - /// - public static readonly Color Lavender = NamedColors.Lavender; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. - /// - public static readonly Color LavenderBlush = NamedColors.LavenderBlush; - - /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. - /// - public static readonly Color LawnGreen = NamedColors.LawnGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. - /// - public static readonly Color LemonChiffon = NamedColors.LemonChiffon; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. - /// - public static readonly Color LightBlue = NamedColors.LightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F08080. - /// - public static readonly Color LightCoral = NamedColors.LightCoral; - - /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. - /// - public static readonly Color LightCyan = NamedColors.LightCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. - /// - public static readonly Color LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. - /// - public static readonly Color LightGray = NamedColors.LightGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. - /// - public static readonly Color LightGreen = NamedColors.LightGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. - /// - public static readonly Color LightPink = NamedColors.LightPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. - /// - public static readonly Color LightSalmon = NamedColors.LightSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. - /// - public static readonly Color LightSeaGreen = NamedColors.LightSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. - /// - public static readonly Color LightSkyBlue = NamedColors.LightSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #778899. - /// - public static readonly Color LightSlateGray = NamedColors.LightSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. - /// - public static readonly Color LightSteelBlue = NamedColors.LightSteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. - /// - public static readonly Color LightYellow = NamedColors.LightYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. - /// - public static readonly Color Lime = NamedColors.Lime; - - /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. - /// - public static readonly Color LimeGreen = NamedColors.LimeGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. - /// - public static readonly Color Linen = NamedColors.Linen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly Color Magenta = NamedColors.Magenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #800000. - /// - public static readonly Color Maroon = NamedColors.Maroon; - - /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. - /// - public static readonly Color MediumAquamarine = NamedColors.MediumAquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. - /// - public static readonly Color MediumBlue = NamedColors.MediumBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. - /// - public static readonly Color MediumOrchid = NamedColors.MediumOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. - /// - public static readonly Color MediumPurple = NamedColors.MediumPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. - /// - public static readonly Color MediumSeaGreen = NamedColors.MediumSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. - /// - public static readonly Color MediumSlateBlue = NamedColors.MediumSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. - /// - public static readonly Color MediumSpringGreen = NamedColors.MediumSpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. - /// - public static readonly Color MediumTurquoise = NamedColors.MediumTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #C71585. - /// - public static readonly Color MediumVioletRed = NamedColors.MediumVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #191970. - /// - public static readonly Color MidnightBlue = NamedColors.MidnightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. - /// - public static readonly Color MintCream = NamedColors.MintCream; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. - /// - public static readonly Color MistyRose = NamedColors.MistyRose; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. - /// - public static readonly Color Moccasin = NamedColors.Moccasin; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. - /// - public static readonly Color NavajoWhite = NamedColors.NavajoWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #000080. - /// - public static readonly Color Navy = NamedColors.Navy; - - /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. - /// - public static readonly Color OldLace = NamedColors.OldLace; - - /// - /// Represents a matching the W3C definition that has an hex value of #808000. - /// - public static readonly Color Olive = NamedColors.Olive; - - /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. - /// - public static readonly Color OliveDrab = NamedColors.OliveDrab; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. - /// - public static readonly Color Orange = NamedColors.Orange; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. - /// - public static readonly Color OrangeRed = NamedColors.OrangeRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. - /// - public static readonly Color Orchid = NamedColors.Orchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. - /// - public static readonly Color PaleGoldenrod = NamedColors.PaleGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. - /// - public static readonly Color PaleGreen = NamedColors.PaleGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. - /// - public static readonly Color PaleTurquoise = NamedColors.PaleTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. - /// - public static readonly Color PaleVioletRed = NamedColors.PaleVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. - /// - public static readonly Color PapayaWhip = NamedColors.PapayaWhip; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. - /// - public static readonly Color PeachPuff = NamedColors.PeachPuff; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. - /// - public static readonly Color Peru = NamedColors.Peru; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. - /// - public static readonly Color Pink = NamedColors.Pink; - - /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. - /// - public static readonly Color Plum = NamedColors.Plum; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. - /// - public static readonly Color PowderBlue = NamedColors.PowderBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #800080. - /// - public static readonly Color Purple = NamedColors.Purple; - - /// - /// Represents a matching the W3C definition that has an hex value of #663399. - /// - public static readonly Color RebeccaPurple = NamedColors.RebeccaPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. - /// - public static readonly Color Red = NamedColors.Red; - - /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. - /// - public static readonly Color RosyBrown = NamedColors.RosyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. - /// - public static readonly Color RoyalBlue = NamedColors.RoyalBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. - /// - public static readonly Color SaddleBrown = NamedColors.SaddleBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. - /// - public static readonly Color Salmon = NamedColors.Salmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. - /// - public static readonly Color SandyBrown = NamedColors.SandyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. - /// - public static readonly Color SeaGreen = NamedColors.SeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. - /// - public static readonly Color SeaShell = NamedColors.SeaShell; - - /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. - /// - public static readonly Color Sienna = NamedColors.Sienna; - - /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. - /// - public static readonly Color Silver = NamedColors.Silver; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. - /// - public static readonly Color SkyBlue = NamedColors.SkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. - /// - public static readonly Color SlateBlue = NamedColors.SlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #708090. - /// - public static readonly Color SlateGray = NamedColors.SlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. - /// - public static readonly Color Snow = NamedColors.Snow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. - /// - public static readonly Color SpringGreen = NamedColors.SpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. - /// - public static readonly Color SteelBlue = NamedColors.SteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. - /// - public static readonly Color Tan = NamedColors.Tan; - - /// - /// Represents a matching the W3C definition that has an hex value of #008080. - /// - public static readonly Color Teal = NamedColors.Teal; - - /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. - /// - public static readonly Color Thistle = NamedColors.Thistle; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. - /// - public static readonly Color Tomato = NamedColors.Tomato; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly Color Transparent = NamedColors.Transparent; - - /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. - /// - public static readonly Color Turquoise = NamedColors.Turquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. - /// - public static readonly Color Violet = NamedColors.Violet; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. - /// - public static readonly Color Wheat = NamedColors.Wheat; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly Color White = NamedColors.White; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. - /// - public static readonly Color WhiteSmoke = NamedColors.WhiteSmoke; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. - /// - public static readonly Color Yellow = NamedColors.Yellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. - /// - public static readonly Color YellowGreen = NamedColors.YellowGreen; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 74f5cb717..ec713f915 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -17,46 +17,46 @@ 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 partial struct Color + public partial struct Color32 { /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Color(Bgra32 color) + public static implicit operator Color32(Bgra32 color) { - return new Color(color.R, color.G, color.B, color.A); + return new Color32(color.R, color.G, color.B, color.A); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(Cmyk cmykColor) + public static implicit operator Color32(Cmyk cmykColor) { float r = (1 - cmykColor.C) * (1 - cmykColor.K); float g = (1 - cmykColor.M) * (1 - cmykColor.K); float b = (1 - cmykColor.Y) * (1 - cmykColor.K); - return new Color(r, g, b, 1); + return new Color32(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(YCbCr color) + public static implicit operator Color32(YCbCr color) { float y = color.Y; float cb = color.Cb - 128; @@ -66,18 +66,18 @@ namespace ImageSharp byte g = (byte)(y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); byte b = (byte)(y + (1.772F * cb)).Clamp(0, 255); - return new Color(r, g, b); + return new Color32(r, g, b); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(CieXyz color) + public static implicit operator Color32(CieXyz color) { float x = color.X / 100F; float y = color.Y / 100F; @@ -89,25 +89,25 @@ namespace ImageSharp float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); Vector4 vector = new Vector4(r, g, b, 1).Compress(); - return new Color(vector); + return new Color32(vector); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(Hsv color) + public static implicit operator Color32(Hsv color) { float s = color.S; float v = color.V; if (MathF.Abs(s) < Constants.Epsilon) { - return new Color(v, v, v, 1); + return new Color32(v, v, v, 1); } float h = (MathF.Abs(color.H - 360) < Constants.Epsilon) ? 0 : color.H / 60; @@ -158,18 +158,18 @@ namespace ImageSharp break; } - return new Color(r, g, b, 1); + return new Color32(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(Hsl color) + public static implicit operator Color32(Hsl color) { float rangedH = color.H / 360F; float r = 0; @@ -195,18 +195,18 @@ namespace ImageSharp } } - return new Color(r, g, b, 1); + return new Color32(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(CieLab cieLabColor) + public static implicit operator Color32(CieLab cieLabColor) { // First convert back to XYZ... float y = (cieLabColor.L + 16F) / 116F; @@ -229,7 +229,7 @@ namespace ImageSharp float g = (x * -0.9689F) + (y * 1.8758F) + (z * 0.0415F); float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); - return new Color(new Vector4(r, g, b, 1F).Compress()); + return new Color32(new Vector4(r, g, b, 1F).Compress()); } /// diff --git a/src/ImageSharp/Colors/ComponentOrder.cs b/src/ImageSharp/Colors/ComponentOrder.cs index 03fa3bbf8..804bc49b1 100644 --- a/src/ImageSharp/Colors/ComponentOrder.cs +++ b/src/ImageSharp/Colors/ComponentOrder.cs @@ -11,22 +11,22 @@ namespace ImageSharp public enum ComponentOrder { /// - /// Z-> Y-> X order. Equivalent to B-> G-> R in + /// Z-> Y-> X order. Equivalent to B-> G-> R in /// Zyx, /// - /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in + /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// Zyxw, /// - /// X-> Y-> Z order. Equivalent to R-> G-> B in + /// X-> Y-> Z order. Equivalent to R-> G-> B in /// Xyz, /// - /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in + /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// Xyzw, } diff --git a/src/ImageSharp/Colors/NamedColors{TColor}.cs b/src/ImageSharp/Colors/NamedColors{TColor}.cs index bcad4dd40..4edba660a 100644 --- a/src/ImageSharp/Colors/NamedColors{TColor}.cs +++ b/src/ImageSharp/Colors/NamedColors{TColor}.cs @@ -15,712 +15,712 @@ namespace ImageSharp where TColor : struct, IPixel { /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. /// public static readonly TColor AliceBlue = ColorBuilder.FromRGBA(240, 248, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. /// public static readonly TColor AntiqueWhite = ColorBuilder.FromRGBA(250, 235, 215, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// Represents a matching the W3C definition that has an hex value of #00FFFF. /// public static readonly TColor Aqua = ColorBuilder.FromRGBA(0, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. /// public static readonly TColor Aquamarine = ColorBuilder.FromRGBA(127, 255, 212, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. /// public static readonly TColor Azure = ColorBuilder.FromRGBA(240, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. /// public static readonly TColor Beige = ColorBuilder.FromRGBA(245, 245, 220, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. /// public static readonly TColor Bisque = ColorBuilder.FromRGBA(255, 228, 196, 255); /// - /// Represents a matching the W3C definition that has an hex value of #000000. + /// Represents a matching the W3C definition that has an hex value of #000000. /// public static readonly TColor Black = ColorBuilder.FromRGBA(0, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. /// public static readonly TColor BlanchedAlmond = ColorBuilder.FromRGBA(255, 235, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// Represents a matching the W3C definition that has an hex value of #0000FF. /// public static readonly TColor Blue = ColorBuilder.FromRGBA(0, 0, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. /// public static readonly TColor BlueViolet = ColorBuilder.FromRGBA(138, 43, 226, 255); /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// Represents a matching the W3C definition that has an hex value of #A52A2A. /// public static readonly TColor Brown = ColorBuilder.FromRGBA(165, 42, 42, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// Represents a matching the W3C definition that has an hex value of #DEB887. /// public static readonly TColor BurlyWood = ColorBuilder.FromRGBA(222, 184, 135, 255); /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. /// public static readonly TColor CadetBlue = ColorBuilder.FromRGBA(95, 158, 160, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// Represents a matching the W3C definition that has an hex value of #7FFF00. /// public static readonly TColor Chartreuse = ColorBuilder.FromRGBA(127, 255, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// Represents a matching the W3C definition that has an hex value of #D2691E. /// public static readonly TColor Chocolate = ColorBuilder.FromRGBA(210, 105, 30, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// Represents a matching the W3C definition that has an hex value of #FF7F50. /// public static readonly TColor Coral = ColorBuilder.FromRGBA(255, 127, 80, 255); /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// Represents a matching the W3C definition that has an hex value of #6495ED. /// public static readonly TColor CornflowerBlue = ColorBuilder.FromRGBA(100, 149, 237, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. /// public static readonly TColor Cornsilk = ColorBuilder.FromRGBA(255, 248, 220, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// Represents a matching the W3C definition that has an hex value of #DC143C. /// public static readonly TColor Crimson = ColorBuilder.FromRGBA(220, 20, 60, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// Represents a matching the W3C definition that has an hex value of #00FFFF. /// public static readonly TColor Cyan = ColorBuilder.FromRGBA(0, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00008B. + /// Represents a matching the W3C definition that has an hex value of #00008B. /// public static readonly TColor DarkBlue = ColorBuilder.FromRGBA(0, 0, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// Represents a matching the W3C definition that has an hex value of #008B8B. /// public static readonly TColor DarkCyan = ColorBuilder.FromRGBA(0, 139, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// Represents a matching the W3C definition that has an hex value of #B8860B. /// public static readonly TColor DarkGoldenrod = ColorBuilder.FromRGBA(184, 134, 11, 255); /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. /// public static readonly TColor DarkGray = ColorBuilder.FromRGBA(169, 169, 169, 255); /// - /// Represents a matching the W3C definition that has an hex value of #006400. + /// Represents a matching the W3C definition that has an hex value of #006400. /// public static readonly TColor DarkGreen = ColorBuilder.FromRGBA(0, 100, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// Represents a matching the W3C definition that has an hex value of #BDB76B. /// public static readonly TColor DarkKhaki = ColorBuilder.FromRGBA(189, 183, 107, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// Represents a matching the W3C definition that has an hex value of #8B008B. /// public static readonly TColor DarkMagenta = ColorBuilder.FromRGBA(139, 0, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// Represents a matching the W3C definition that has an hex value of #556B2F. /// public static readonly TColor DarkOliveGreen = ColorBuilder.FromRGBA(85, 107, 47, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// Represents a matching the W3C definition that has an hex value of #FF8C00. /// public static readonly TColor DarkOrange = ColorBuilder.FromRGBA(255, 140, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// Represents a matching the W3C definition that has an hex value of #9932CC. /// public static readonly TColor DarkOrchid = ColorBuilder.FromRGBA(153, 50, 204, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// Represents a matching the W3C definition that has an hex value of #8B0000. /// public static readonly TColor DarkRed = ColorBuilder.FromRGBA(139, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// Represents a matching the W3C definition that has an hex value of #E9967A. /// public static readonly TColor DarkSalmon = ColorBuilder.FromRGBA(233, 150, 122, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. /// public static readonly TColor DarkSeaGreen = ColorBuilder.FromRGBA(143, 188, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// Represents a matching the W3C definition that has an hex value of #483D8B. /// public static readonly TColor DarkSlateBlue = ColorBuilder.FromRGBA(72, 61, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. /// public static readonly TColor DarkSlateGray = ColorBuilder.FromRGBA(47, 79, 79, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// Represents a matching the W3C definition that has an hex value of #00CED1. /// public static readonly TColor DarkTurquoise = ColorBuilder.FromRGBA(0, 206, 209, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// Represents a matching the W3C definition that has an hex value of #9400D3. /// public static readonly TColor DarkViolet = ColorBuilder.FromRGBA(148, 0, 211, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// Represents a matching the W3C definition that has an hex value of #FF1493. /// public static readonly TColor DeepPink = ColorBuilder.FromRGBA(255, 20, 147, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// Represents a matching the W3C definition that has an hex value of #00BFFF. /// public static readonly TColor DeepSkyBlue = ColorBuilder.FromRGBA(0, 191, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #696969. + /// Represents a matching the W3C definition that has an hex value of #696969. /// public static readonly TColor DimGray = ColorBuilder.FromRGBA(105, 105, 105, 255); /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// Represents a matching the W3C definition that has an hex value of #1E90FF. /// public static readonly TColor DodgerBlue = ColorBuilder.FromRGBA(30, 144, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B22222. + /// Represents a matching the W3C definition that has an hex value of #B22222. /// public static readonly TColor Firebrick = ColorBuilder.FromRGBA(178, 34, 34, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. /// public static readonly TColor FloralWhite = ColorBuilder.FromRGBA(255, 250, 240, 255); /// - /// Represents a matching the W3C definition that has an hex value of #228B22. + /// Represents a matching the W3C definition that has an hex value of #228B22. /// public static readonly TColor ForestGreen = ColorBuilder.FromRGBA(34, 139, 34, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// Represents a matching the W3C definition that has an hex value of #FF00FF. /// public static readonly TColor Fuchsia = ColorBuilder.FromRGBA(255, 0, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. /// public static readonly TColor Gainsboro = ColorBuilder.FromRGBA(220, 220, 220, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. /// public static readonly TColor GhostWhite = ColorBuilder.FromRGBA(248, 248, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// Represents a matching the W3C definition that has an hex value of #FFD700. /// public static readonly TColor Gold = ColorBuilder.FromRGBA(255, 215, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// Represents a matching the W3C definition that has an hex value of #DAA520. /// public static readonly TColor Goldenrod = ColorBuilder.FromRGBA(218, 165, 32, 255); /// - /// Represents a matching the W3C definition that has an hex value of #808080. + /// Represents a matching the W3C definition that has an hex value of #808080. /// public static readonly TColor Gray = ColorBuilder.FromRGBA(128, 128, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #008000. + /// Represents a matching the W3C definition that has an hex value of #008000. /// public static readonly TColor Green = ColorBuilder.FromRGBA(0, 128, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. /// public static readonly TColor GreenYellow = ColorBuilder.FromRGBA(173, 255, 47, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. /// public static readonly TColor Honeydew = ColorBuilder.FromRGBA(240, 255, 240, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// Represents a matching the W3C definition that has an hex value of #FF69B4. /// public static readonly TColor HotPink = ColorBuilder.FromRGBA(255, 105, 180, 255); /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. /// public static readonly TColor IndianRed = ColorBuilder.FromRGBA(205, 92, 92, 255); /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// Represents a matching the W3C definition that has an hex value of #4B0082. /// public static readonly TColor Indigo = ColorBuilder.FromRGBA(75, 0, 130, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. /// public static readonly TColor Ivory = ColorBuilder.FromRGBA(255, 255, 240, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// Represents a matching the W3C definition that has an hex value of #F0E68C. /// public static readonly TColor Khaki = ColorBuilder.FromRGBA(240, 230, 140, 255); /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. /// public static readonly TColor Lavender = ColorBuilder.FromRGBA(230, 230, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. /// public static readonly TColor LavenderBlush = ColorBuilder.FromRGBA(255, 240, 245, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// Represents a matching the W3C definition that has an hex value of #7CFC00. /// public static readonly TColor LawnGreen = ColorBuilder.FromRGBA(124, 252, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// Represents a matching the W3C definition that has an hex value of #FFFACD. /// public static readonly TColor LemonChiffon = ColorBuilder.FromRGBA(255, 250, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. /// public static readonly TColor LightBlue = ColorBuilder.FromRGBA(173, 216, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F08080. + /// Represents a matching the W3C definition that has an hex value of #F08080. /// public static readonly TColor LightCoral = ColorBuilder.FromRGBA(240, 128, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. /// public static readonly TColor LightCyan = ColorBuilder.FromRGBA(224, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. /// public static readonly TColor LightGoldenrodYellow = ColorBuilder.FromRGBA(250, 250, 210, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. /// public static readonly TColor LightGray = ColorBuilder.FromRGBA(211, 211, 211, 255); /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// Represents a matching the W3C definition that has an hex value of #90EE90. /// public static readonly TColor LightGreen = ColorBuilder.FromRGBA(144, 238, 144, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. /// public static readonly TColor LightPink = ColorBuilder.FromRGBA(255, 182, 193, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// Represents a matching the W3C definition that has an hex value of #FFA07A. /// public static readonly TColor LightSalmon = ColorBuilder.FromRGBA(255, 160, 122, 255); /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// Represents a matching the W3C definition that has an hex value of #20B2AA. /// public static readonly TColor LightSeaGreen = ColorBuilder.FromRGBA(32, 178, 170, 255); /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// Represents a matching the W3C definition that has an hex value of #87CEFA. /// public static readonly TColor LightSkyBlue = ColorBuilder.FromRGBA(135, 206, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #778899. + /// Represents a matching the W3C definition that has an hex value of #778899. /// public static readonly TColor LightSlateGray = ColorBuilder.FromRGBA(119, 136, 153, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. /// public static readonly TColor LightSteelBlue = ColorBuilder.FromRGBA(176, 196, 222, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. /// public static readonly TColor LightYellow = ColorBuilder.FromRGBA(255, 255, 224, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// Represents a matching the W3C definition that has an hex value of #00FF00. /// public static readonly TColor Lime = ColorBuilder.FromRGBA(0, 255, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// Represents a matching the W3C definition that has an hex value of #32CD32. /// public static readonly TColor LimeGreen = ColorBuilder.FromRGBA(50, 205, 50, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. /// public static readonly TColor Linen = ColorBuilder.FromRGBA(250, 240, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// Represents a matching the W3C definition that has an hex value of #FF00FF. /// public static readonly TColor Magenta = ColorBuilder.FromRGBA(255, 0, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #800000. + /// Represents a matching the W3C definition that has an hex value of #800000. /// public static readonly TColor Maroon = ColorBuilder.FromRGBA(128, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// Represents a matching the W3C definition that has an hex value of #66CDAA. /// public static readonly TColor MediumAquamarine = ColorBuilder.FromRGBA(102, 205, 170, 255); /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// Represents a matching the W3C definition that has an hex value of #0000CD. /// public static readonly TColor MediumBlue = ColorBuilder.FromRGBA(0, 0, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// Represents a matching the W3C definition that has an hex value of #BA55D3. /// public static readonly TColor MediumOrchid = ColorBuilder.FromRGBA(186, 85, 211, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// Represents a matching the W3C definition that has an hex value of #9370DB. /// public static readonly TColor MediumPurple = ColorBuilder.FromRGBA(147, 112, 219, 255); /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// Represents a matching the W3C definition that has an hex value of #3CB371. /// public static readonly TColor MediumSeaGreen = ColorBuilder.FromRGBA(60, 179, 113, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// Represents a matching the W3C definition that has an hex value of #7B68EE. /// public static readonly TColor MediumSlateBlue = ColorBuilder.FromRGBA(123, 104, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// Represents a matching the W3C definition that has an hex value of #00FA9A. /// public static readonly TColor MediumSpringGreen = ColorBuilder.FromRGBA(0, 250, 154, 255); /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// Represents a matching the W3C definition that has an hex value of #48D1CC. /// public static readonly TColor MediumTurquoise = ColorBuilder.FromRGBA(72, 209, 204, 255); /// - /// Represents a matching the W3C definition that has an hex value of #C71585. + /// Represents a matching the W3C definition that has an hex value of #C71585. /// public static readonly TColor MediumVioletRed = ColorBuilder.FromRGBA(199, 21, 133, 255); /// - /// Represents a matching the W3C definition that has an hex value of #191970. + /// Represents a matching the W3C definition that has an hex value of #191970. /// public static readonly TColor MidnightBlue = ColorBuilder.FromRGBA(25, 25, 112, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. /// public static readonly TColor MintCream = ColorBuilder.FromRGBA(245, 255, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. /// public static readonly TColor MistyRose = ColorBuilder.FromRGBA(255, 228, 225, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. /// public static readonly TColor Moccasin = ColorBuilder.FromRGBA(255, 228, 181, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. /// public static readonly TColor NavajoWhite = ColorBuilder.FromRGBA(255, 222, 173, 255); /// - /// Represents a matching the W3C definition that has an hex value of #000080. + /// Represents a matching the W3C definition that has an hex value of #000080. /// public static readonly TColor Navy = ColorBuilder.FromRGBA(0, 0, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. /// public static readonly TColor OldLace = ColorBuilder.FromRGBA(253, 245, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #808000. + /// Represents a matching the W3C definition that has an hex value of #808000. /// public static readonly TColor Olive = ColorBuilder.FromRGBA(128, 128, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// Represents a matching the W3C definition that has an hex value of #6B8E23. /// public static readonly TColor OliveDrab = ColorBuilder.FromRGBA(107, 142, 35, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// Represents a matching the W3C definition that has an hex value of #FFA500. /// public static readonly TColor Orange = ColorBuilder.FromRGBA(255, 165, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// Represents a matching the W3C definition that has an hex value of #FF4500. /// public static readonly TColor OrangeRed = ColorBuilder.FromRGBA(255, 69, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// Represents a matching the W3C definition that has an hex value of #DA70D6. /// public static readonly TColor Orchid = ColorBuilder.FromRGBA(218, 112, 214, 255); /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. /// public static readonly TColor PaleGoldenrod = ColorBuilder.FromRGBA(238, 232, 170, 255); /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// Represents a matching the W3C definition that has an hex value of #98FB98. /// public static readonly TColor PaleGreen = ColorBuilder.FromRGBA(152, 251, 152, 255); /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. /// public static readonly TColor PaleTurquoise = ColorBuilder.FromRGBA(175, 238, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// Represents a matching the W3C definition that has an hex value of #DB7093. /// public static readonly TColor PaleVioletRed = ColorBuilder.FromRGBA(219, 112, 147, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. /// public static readonly TColor PapayaWhip = ColorBuilder.FromRGBA(255, 239, 213, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. /// public static readonly TColor PeachPuff = ColorBuilder.FromRGBA(255, 218, 185, 255); /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// Represents a matching the W3C definition that has an hex value of #CD853F. /// public static readonly TColor Peru = ColorBuilder.FromRGBA(205, 133, 63, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. /// public static readonly TColor Pink = ColorBuilder.FromRGBA(255, 192, 203, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. /// public static readonly TColor Plum = ColorBuilder.FromRGBA(221, 160, 221, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. /// public static readonly TColor PowderBlue = ColorBuilder.FromRGBA(176, 224, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #800080. + /// Represents a matching the W3C definition that has an hex value of #800080. /// public static readonly TColor Purple = ColorBuilder.FromRGBA(128, 0, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #663399. + /// Represents a matching the W3C definition that has an hex value of #663399. /// public static readonly TColor RebeccaPurple = ColorBuilder.FromRGBA(102, 51, 153, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// Represents a matching the W3C definition that has an hex value of #FF0000. /// public static readonly TColor Red = ColorBuilder.FromRGBA(255, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. /// public static readonly TColor RosyBrown = ColorBuilder.FromRGBA(188, 143, 143, 255); /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// Represents a matching the W3C definition that has an hex value of #4169E1. /// public static readonly TColor RoyalBlue = ColorBuilder.FromRGBA(65, 105, 225, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// Represents a matching the W3C definition that has an hex value of #8B4513. /// public static readonly TColor SaddleBrown = ColorBuilder.FromRGBA(139, 69, 19, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// Represents a matching the W3C definition that has an hex value of #FA8072. /// public static readonly TColor Salmon = ColorBuilder.FromRGBA(250, 128, 114, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// Represents a matching the W3C definition that has an hex value of #F4A460. /// public static readonly TColor SandyBrown = ColorBuilder.FromRGBA(244, 164, 96, 255); /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// Represents a matching the W3C definition that has an hex value of #2E8B57. /// public static readonly TColor SeaGreen = ColorBuilder.FromRGBA(46, 139, 87, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. /// public static readonly TColor SeaShell = ColorBuilder.FromRGBA(255, 245, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// Represents a matching the W3C definition that has an hex value of #A0522D. /// public static readonly TColor Sienna = ColorBuilder.FromRGBA(160, 82, 45, 255); /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. /// public static readonly TColor Silver = ColorBuilder.FromRGBA(192, 192, 192, 255); /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// Represents a matching the W3C definition that has an hex value of #87CEEB. /// public static readonly TColor SkyBlue = ColorBuilder.FromRGBA(135, 206, 235, 255); /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. /// public static readonly TColor SlateBlue = ColorBuilder.FromRGBA(106, 90, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #708090. + /// Represents a matching the W3C definition that has an hex value of #708090. /// public static readonly TColor SlateGray = ColorBuilder.FromRGBA(112, 128, 144, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. /// public static readonly TColor Snow = ColorBuilder.FromRGBA(255, 250, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// Represents a matching the W3C definition that has an hex value of #00FF7F. /// public static readonly TColor SpringGreen = ColorBuilder.FromRGBA(0, 255, 127, 255); /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// Represents a matching the W3C definition that has an hex value of #4682B4. /// public static readonly TColor SteelBlue = ColorBuilder.FromRGBA(70, 130, 180, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// Represents a matching the W3C definition that has an hex value of #D2B48C. /// public static readonly TColor Tan = ColorBuilder.FromRGBA(210, 180, 140, 255); /// - /// Represents a matching the W3C definition that has an hex value of #008080. + /// Represents a matching the W3C definition that has an hex value of #008080. /// public static readonly TColor Teal = ColorBuilder.FromRGBA(0, 128, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. /// public static readonly TColor Thistle = ColorBuilder.FromRGBA(216, 191, 216, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// Represents a matching the W3C definition that has an hex value of #FF6347. /// public static readonly TColor Tomato = ColorBuilder.FromRGBA(255, 99, 71, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. /// public static readonly TColor Transparent = ColorBuilder.FromRGBA(255, 255, 255, 0); /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// Represents a matching the W3C definition that has an hex value of #40E0D0. /// public static readonly TColor Turquoise = ColorBuilder.FromRGBA(64, 224, 208, 255); /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// Represents a matching the W3C definition that has an hex value of #EE82EE. /// public static readonly TColor Violet = ColorBuilder.FromRGBA(238, 130, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. /// public static readonly TColor Wheat = ColorBuilder.FromRGBA(245, 222, 179, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. /// public static readonly TColor White = ColorBuilder.FromRGBA(255, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. /// public static readonly TColor WhiteSmoke = ColorBuilder.FromRGBA(245, 245, 245, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// Represents a matching the W3C definition that has an hex value of #FFFF00. /// public static readonly TColor Yellow = ColorBuilder.FromRGBA(255, 255, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// Represents a matching the W3C definition that has an hex value of #9ACD32. /// public static readonly TColor YellowGreen = ColorBuilder.FromRGBA(154, 205, 50, 255); } diff --git a/src/ImageSharp/Colors/PackedPixel/IPixel.cs b/src/ImageSharp/Colors/PackedPixel/IPixel.cs index 67e013a42..7fbe76bfc 100644 --- a/src/ImageSharp/Colors/PackedPixel/IPixel.cs +++ b/src/ImageSharp/Colors/PackedPixel/IPixel.cs @@ -52,7 +52,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in + /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in /// /// The bytes to set the color in. /// The starting index of the . @@ -60,7 +60,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in + /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// /// The bytes to set the color in. /// The starting index of the . @@ -68,7 +68,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in + /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in /// /// The bytes to set the color in. /// The starting index of the . @@ -76,7 +76,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in + /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// /// The bytes to set the color in. /// The starting index of the . diff --git a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs index 949e44cc0..4f6b029dd 100644 --- a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs +++ b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs @@ -299,7 +299,7 @@ namespace ImageSharp /// The private static bool IsStandardNormalizedType(Type type) { - return type == typeof(Color) + return type == typeof(Color32) || type == typeof(Argb) || type == typeof(Alpha8) || type == typeof(Bgr565) diff --git a/src/ImageSharp/Colors/Spaces/Bgra32.cs b/src/ImageSharp/Colors/Spaces/Bgra32.cs index cbd1d6119..33b683d0b 100644 --- a/src/ImageSharp/Colors/Spaces/Bgra32.cs +++ b/src/ImageSharp/Colors/Spaces/Bgra32.cs @@ -79,16 +79,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator Bgra32(Color color) + public static implicit operator Bgra32(Color32 color) { return new Bgra32(color.B, color.G, color.R, color.A); } diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index 921158174..18e915f54 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -72,16 +72,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator CieLab(Color color) + public static implicit operator CieLab(Color32 color) { // First convert to CIE XYZ Vector4 vector = color.ToVector4().Expand(); diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index 5bd1eac63..db8f15d58 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -63,16 +63,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator CieXyz(Color color) + public static implicit operator CieXyz(Color32 color) { Vector4 vector = color.ToVector4().Expand(); diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index c81a55c0b..cfbed9aa5 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -78,7 +78,7 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -87,7 +87,7 @@ namespace ImageSharp.Colors.Spaces /// /// An instance of . /// - public static implicit operator Cmyk(Color color) + public static implicit operator Cmyk(Color32 color) { float c = 1f - (color.R / 255F); float m = 1f - (color.G / 255F); diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index 1d655ec32..1058330a7 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -70,14 +70,14 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Hsl(Color color) + public static implicit operator Hsl(Color32 color) { float r = color.R / 255F; float g = color.G / 255F; diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index e171c9528..5c360c9e6 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -70,14 +70,14 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Hsv(Color color) + public static implicit operator Hsv(Color32 color) { float r = color.R / 255F; float g = color.G / 255F; diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index ef9f4462b..d490375c1 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -72,16 +72,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator YCbCr(Color color) + public static implicit operator YCbCr(Color32 color) { byte r = color.R; byte g = color.G; diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index 9f3aa405e..eadc629eb 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -32,7 +32,7 @@ namespace ImageSharp /// /// /// - /// The whose signal to expand. + /// The whose signal to expand. /// The . public static Vector4 Expand(this Vector4 gamma) { diff --git a/src/ImageSharp/Image.Create.cs b/src/ImageSharp/Image.Create.cs index fcecefd7b..1b54c427a 100644 --- a/src/ImageSharp/Image.Create.cs +++ b/src/ImageSharp/Image.Create.cs @@ -29,12 +29,12 @@ namespace ImageSharp /// The configuration providing initialization code which allows extending the library. /// /// - /// A new unless is in which case it returns + /// A new unless is in which case it returns /// internal static Image Create(int width, int height, ImageMetaData metadata, Configuration configuration) where TColor : struct, IPixel { - if (typeof(TColor) == typeof(Color)) + if (typeof(TColor) == typeof(Color32)) { return new Image(width, height, metadata, configuration) as Image; } @@ -55,7 +55,7 @@ namespace ImageSharp /// The configuration providing initialization code which allows extending the library. /// /// - /// A new unless is in which case it returns + /// A new unless is in which case it returns /// internal static Image Create(int width, int height, Configuration configuration) where TColor : struct, IPixel diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 40cdfe3ef..7c6062bea 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -83,7 +83,7 @@ namespace ImageSharp /// The image public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) { - return new Image(Load(path, decoder, options)); + return new Image(Load(path, decoder, options)); } /// diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index 112b8a109..0f0493a5e 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -83,7 +83,7 @@ namespace ImageSharp /// The image public static Image Load(Configuration config, Stream stream, IDecoderOptions options) { - Image image = Load(config, stream, options); + Image image = Load(config, stream, options); return image as Image ?? new Image(image); } @@ -100,7 +100,7 @@ namespace ImageSharp /// The image public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) { - Image image = new Image(Load(stream, decoder, options)); + Image image = new Image(Load(stream, decoder, options)); return image as Image ?? new Image(image); } diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index 00688afc9..e681bfc0e 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -16,7 +16,7 @@ namespace ImageSharp /// packed into a single unsigned integer value. /// [DebuggerDisplay("Image: {Width}x{Height}")] - public sealed partial class Image : Image + public sealed partial class Image : Image { /// /// Initializes a new instance of the class @@ -49,7 +49,7 @@ namespace ImageSharp /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + public Image(Image other) : base(other) { } diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs index c75da0003..e0e72a2a1 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs @@ -75,7 +75,7 @@ namespace ImageSharp.Processing.Processors /// The matrix. /// Whether to compand the color during processing. /// - /// The . + /// The . /// private TColor ApplyMatrix(TColor color, Matrix4x4 matrix, bool compand) { diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer.cs b/src/ImageSharp/Quantizers/PaletteQuantizer.cs index f039fe0c5..30d3a9026 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer.cs +++ b/src/ImageSharp/Quantizers/PaletteQuantizer.cs @@ -44,7 +44,7 @@ namespace ImageSharp.Quantizers { if (palette == null) { - Color[] constants = ColorConstants.WebSafeColors; + Color32[] constants = Color32Constants.WebSafeColors; TColor[] safe = new TColor[constants.Length + 1]; for (int i = 0; i < constants.Length; i++) diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs index e912ea29f..6611d571c 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -14,7 +14,7 @@ /// public unsafe class PackFromVector4ReferenceVsPointer { - private PinnedBuffer destination; + private PinnedBuffer destination; private PinnedBuffer source; @@ -24,7 +24,7 @@ [Setup] public void Setup() { - this.destination = new PinnedBuffer(this.Count); + this.destination = new PinnedBuffer(this.Count); this.source = new PinnedBuffer(this.Count * 4); } @@ -41,12 +41,12 @@ Vector4* sp = (Vector4*)this.source.Pointer; byte* dp = (byte*)this.destination.Pointer; int count = this.Count; - int size = sizeof(ImageSharp.Color); + int size = sizeof(ImageSharp.Color32); for (int i = 0; i < count; i++) { Vector4 v = Unsafe.Read(sp); - ImageSharp.Color c = default(ImageSharp.Color); + ImageSharp.Color32 c = default(ImageSharp.Color32); c.PackFromVector4(v); Unsafe.Write(dp, c); @@ -59,7 +59,7 @@ public void PackUsingReferences() { ref Vector4 sp = ref this.source.Array[0]; - ref ImageSharp.Color dp = ref this.destination.Array[0]; + ref ImageSharp.Color32 dp = ref this.destination.Array[0]; int count = this.Count; for (int i = 0; i < count; i++) diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 1c541d28b..bc38328a8 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -3,7 +3,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using Color32 = ImageSharp.Color32; public abstract class PackFromXyzw where TColor : struct, IPixel @@ -57,7 +57,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class PackFromXyzw_Color : PackFromXyzw + public class PackFromXyzw_Color : PackFromXyzw { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index b48eaa35a..178719cca 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -55,7 +55,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToVector4_Color : ToVector4 + public class ToVector4_Color : ToVector4 { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index bc59dba4e..64b21b079 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -3,7 +3,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using Color32 = ImageSharp.Color32; public abstract class ToXyz where TColor : struct, IPixel @@ -55,7 +55,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToXyz_Color : ToXyz + public class ToXyz_Color : ToXyz { } } \ 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 a4ec6f6dc..946914966 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using Color32 = ImageSharp.Color32; public abstract class ToXyzw where TColor : struct, IPixel @@ -60,7 +60,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToXyzw_Color : ToXyzw + public class ToXyzw_Color : ToXyzw { } diff --git a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs index 3ee28d06b..4e75c94ac 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Benchmarks { using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using SystemColor = System.Drawing.Color; public class ColorEquality diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index 3e60cae4d..69945cf89 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index ee97866e2..b0ea1bf7f 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 047cacb42..99ae6d538 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using System.IO; using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index 782306deb..7a2ced766 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -13,7 +13,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreImage = ImageSharp.Image; public class FillPolygon : BenchmarkBase diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 691955e8e..2a677b5f8 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CoreRectangle = ImageSharp.Rectangle; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreSize = ImageSharp.Size; using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index dcd22d6fb..8667573c6 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreImage = ImageSharp.Image; public class FillWithPattern diff --git a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs index 9aa836de5..5428462be 100644 --- a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs +++ b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs @@ -7,11 +7,11 @@ namespace ImageSharp.Benchmarks.General using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using Color32 = ImageSharp.Color32; public unsafe class ClearBuffer { - private PinnedBuffer buffer; + private PinnedBuffer buffer; [Params(32, 128, 512)] public int Count { get; set; } @@ -19,7 +19,7 @@ namespace ImageSharp.Benchmarks.General [Setup] public void Setup() { - this.buffer = new PinnedBuffer(this.Count); + this.buffer = new PinnedBuffer(this.Count); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index 335d8247d..b226c2611 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreImage = ImageSharp.Image; public class CopyPixels : BenchmarkBase diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index 1318c1674..c7f1040fd 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -51,7 +51,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new OctreeQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new OctreeQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -62,7 +62,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new OctreeQuantizer { Dither = false }, Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new OctreeQuantizer { Dither = false }, Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -73,7 +73,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -84,7 +84,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer { Dither = false }, Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer { Dither = false }, Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -95,7 +95,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new WuQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new WuQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index 4c1feb6c2..5740e0561 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -66,10 +66,10 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - Quantizer quantizer = this.UseOctreeQuantizer - ? (Quantizer) - new OctreeQuantizer() - : new PaletteQuantizer(); + Quantizer quantizer = this.UseOctreeQuantizer + ? (Quantizer) + new OctreeQuantizer() + : new PaletteQuantizer(); PngEncoderOptions options = new PngEncoderOptions() { Quantizer = quantizer }; this.bmpCore.SaveAsPng(memoryStream, options); diff --git a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs index 78295e27d..801acd1c7 100644 --- a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using CoreColor = ImageSharp.Color32; using CoreImage = ImageSharp.Image; using SystemColor = System.Drawing.Color; diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs index 60e25aa04..edfa7901e 100644 --- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs @@ -10,7 +10,7 @@ namespace ImageSharp.Tests.Colors public class BulkPixelOperationsTests { - public class Color : BulkPixelOperationsTests + public class Color : BulkPixelOperationsTests { public Color(ITestOutputHelper output) : base(output) @@ -23,19 +23,19 @@ namespace ImageSharp.Tests.Colors [Fact] public void IsSpecialImplementation() { - Assert.IsType(BulkPixelOperations.Instance); + Assert.IsType(BulkPixelOperations.Instance); } [Fact] public void ToVector4SimdAligned() { - ImageSharp.Color[] source = CreatePixelTestData(64); + ImageSharp.Color32[] source = CreatePixelTestData(64); Vector4[] expected = CreateExpectedVector4Data(source); TestOperation( source, expected, - (s, d) => ImageSharp.Color.BulkOperations.ToVector4SimdAligned(s, d, 64) + (s, d) => ImageSharp.Color32.BulkOperations.ToVector4SimdAligned(s, d, 64) ); } @@ -45,14 +45,14 @@ namespace ImageSharp.Tests.Colors int times = 200000; int count = 1024; - using (PinnedBuffer source = new PinnedBuffer(count)) + using (PinnedBuffer source = new PinnedBuffer(count)) using (PinnedBuffer dest = new PinnedBuffer(count)) { this.Measure( times, () => { - BulkPixelOperations.Instance.ToVector4(source, dest, count); + BulkPixelOperations.Instance.ToVector4(source, dest, count); }); } } diff --git a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs index 9ed1c67a7..74214056e 100644 --- a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests public class ColorConversionTests { /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -28,7 +28,7 @@ namespace ImageSharp.Tests public void ColorToYCbCr() { // White - Color color = Color.White; + Color32 color = Color32.White; YCbCr yCbCr = color; Assert.Equal(255, yCbCr.Y); @@ -36,14 +36,14 @@ namespace ImageSharp.Tests Assert.Equal(128, yCbCr.Cr); // Black - Color color2 = Color.Black; + Color32 color2 = Color32.Black; YCbCr yCbCr2 = color2; Assert.Equal(0, yCbCr2.Y); Assert.Equal(128, yCbCr2.Cb); Assert.Equal(128, yCbCr2.Cr); // Gray - Color color3 = Color.Gray; + Color32 color3 = Color32.Gray; YCbCr yCbCr3 = color3; Assert.Equal(128, yCbCr3.Y); Assert.Equal(128, yCbCr3.Cb); @@ -51,7 +51,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -60,7 +60,7 @@ namespace ImageSharp.Tests { // White YCbCr yCbCr = new YCbCr(255, 128, 128); - Color color = yCbCr; + Color32 color = yCbCr; Assert.Equal(255, color.R); Assert.Equal(255, color.G); @@ -69,7 +69,7 @@ namespace ImageSharp.Tests // Black YCbCr yCbCr2 = new YCbCr(0, 128, 128); - Color color2 = yCbCr2; + Color32 color2 = yCbCr2; Assert.Equal(0, color2.R); Assert.Equal(0, color2.G); @@ -78,7 +78,7 @@ namespace ImageSharp.Tests // Gray YCbCr yCbCr3 = new YCbCr(128, 128, 128); - Color color3 = yCbCr3; + Color32 color3 = yCbCr3; Assert.Equal(128, color3.R); Assert.Equal(128, color3.G); @@ -87,7 +87,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-xyz /// @@ -95,7 +95,7 @@ namespace ImageSharp.Tests public void ColorToCieXyz() { // White - Color color = Color.White; + Color32 color = Color32.White; CieXyz ciexyz = color; Assert.Equal(95.05f, ciexyz.X, 3); @@ -103,21 +103,21 @@ namespace ImageSharp.Tests Assert.Equal(108.900f, ciexyz.Z, 3); // Black - Color color2 = Color.Black; + Color32 color2 = Color32.Black; CieXyz ciexyz2 = color2; Assert.Equal(0, ciexyz2.X, 3); Assert.Equal(0, ciexyz2.Y, 3); Assert.Equal(0, ciexyz2.Z, 3); // Gray - Color color3 = Color.Gray; + Color32 color3 = Color32.Gray; CieXyz ciexyz3 = color3; Assert.Equal(20.518, ciexyz3.X, 3); Assert.Equal(21.586, ciexyz3.Y, 3); Assert.Equal(23.507, ciexyz3.Z, 3); // Cyan - Color color4 = Color.Cyan; + Color32 color4 = Color32.Cyan; CieXyz ciexyz4 = color4; Assert.Equal(53.810f, ciexyz4.X, 3); Assert.Equal(78.740f, ciexyz4.Y, 3); @@ -125,7 +125,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-xyz /// @@ -134,7 +134,7 @@ namespace ImageSharp.Tests { // Dark moderate pink. CieXyz ciexyz = new CieXyz(13.337f, 9.297f, 14.727f); - Color color = ciexyz; + Color32 color = ciexyz; Assert.Equal(128, color.R); Assert.Equal(64, color.G); @@ -142,7 +142,7 @@ namespace ImageSharp.Tests // Ochre CieXyz ciexyz2 = new CieXyz(31.787f, 26.147f, 4.885f); - Color color2 = ciexyz2; + Color32 color2 = ciexyz2; Assert.Equal(204, color2.R); Assert.Equal(119, color2.G); @@ -150,7 +150,7 @@ namespace ImageSharp.Tests // Black CieXyz ciexyz3 = new CieXyz(0, 0, 0); - Color color3 = ciexyz3; + Color32 color3 = ciexyz3; Assert.Equal(0, color3.R); Assert.Equal(0, color3.G); @@ -167,7 +167,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -175,7 +175,7 @@ namespace ImageSharp.Tests public void ColorToHsv() { // Black - Color b = Color.Black; + Color32 b = Color32.Black; Hsv h = b; Assert.Equal(0, h.H, 1); @@ -183,7 +183,7 @@ namespace ImageSharp.Tests Assert.Equal(0, h.V, 1); // White - Color color = Color.White; + Color32 color = Color32.White; Hsv hsv = color; Assert.Equal(0f, hsv.H, 1); @@ -191,7 +191,7 @@ namespace ImageSharp.Tests Assert.Equal(1f, hsv.V, 1); // Dark moderate pink. - Color color2 = new Color(128, 64, 106); + Color32 color2 = new Color32(128, 64, 106); Hsv hsv2 = color2; Assert.Equal(320.6f, hsv2.H, 1); @@ -199,7 +199,7 @@ namespace ImageSharp.Tests Assert.Equal(0.502f, hsv2.V, 2); // Ochre. - Color color3 = new Color(204, 119, 34); + Color32 color3 = new Color32(204, 119, 34); Hsv hsv3 = color3; Assert.Equal(30f, hsv3.H, 1); @@ -208,14 +208,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void HsvToColor() { // Dark moderate pink. Hsv hsv = new Hsv(320.6f, 0.5f, 0.502f); - Color color = hsv; + Color32 color = hsv; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -223,7 +223,7 @@ namespace ImageSharp.Tests // Ochre Hsv hsv2 = new Hsv(30, 0.833f, 0.8f); - Color color2 = hsv2; + Color32 color2 = hsv2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -231,7 +231,7 @@ namespace ImageSharp.Tests // White Hsv hsv3 = new Hsv(0, 0, 1); - Color color3 = hsv3; + Color32 color3 = hsv3; Assert.Equal(color3.B, 255); Assert.Equal(color3.G, 255); @@ -248,7 +248,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -256,7 +256,7 @@ namespace ImageSharp.Tests public void ColorToHsl() { // Black - Color b = Color.Black; + Color32 b = Color32.Black; Hsl h = b; Assert.Equal(0, h.H, 1); @@ -264,7 +264,7 @@ namespace ImageSharp.Tests Assert.Equal(0, h.L, 1); // White - Color color = Color.White; + Color32 color = Color32.White; Hsl hsl = color; Assert.Equal(0f, hsl.H, 1); @@ -272,7 +272,7 @@ namespace ImageSharp.Tests Assert.Equal(1f, hsl.L, 1); // Dark moderate pink. - Color color2 = new Color(128, 64, 106); + Color32 color2 = new Color32(128, 64, 106); Hsl hsl2 = color2; Assert.Equal(320.6f, hsl2.H, 1); @@ -280,7 +280,7 @@ namespace ImageSharp.Tests Assert.Equal(0.376f, hsl2.L, 2); // Ochre. - Color color3 = new Color(204, 119, 34); + Color32 color3 = new Color32(204, 119, 34); Hsl hsl3 = color3; Assert.Equal(30f, hsl3.H, 1); @@ -289,14 +289,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void HslToColor() { // Dark moderate pink. Hsl hsl = new Hsl(320.6f, 0.33f, 0.376f); - Color color = hsl; + Color32 color = hsl; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -304,7 +304,7 @@ namespace ImageSharp.Tests // Ochre Hsl hsl2 = new Hsl(30, 0.714f, 0.467f); - Color color2 = hsl2; + Color32 color2 = hsl2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -312,7 +312,7 @@ namespace ImageSharp.Tests // White Hsl hsl3 = new Hsl(0, 0, 1); - Color color3 = hsl3; + Color32 color3 = hsl3; Assert.Equal(color3.R, 255); Assert.Equal(color3.G, 255); @@ -329,7 +329,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -337,7 +337,7 @@ namespace ImageSharp.Tests public void ColorToCmyk() { // White - Color color = Color.White; + Color32 color = Color32.White; Cmyk cmyk = color; Assert.Equal(0, cmyk.C, 1); @@ -346,7 +346,7 @@ namespace ImageSharp.Tests Assert.Equal(0, cmyk.K, 1); // Black - Color color2 = Color.Black; + Color32 color2 = Color32.Black; Cmyk cmyk2 = color2; Assert.Equal(0, cmyk2.C, 1); Assert.Equal(0, cmyk2.M, 1); @@ -354,7 +354,7 @@ namespace ImageSharp.Tests Assert.Equal(1, cmyk2.K, 1); // Gray - Color color3 = Color.Gray; + Color32 color3 = Color32.Gray; Cmyk cmyk3 = color3; Assert.Equal(0f, cmyk3.C, 1); Assert.Equal(0f, cmyk3.M, 1); @@ -362,7 +362,7 @@ namespace ImageSharp.Tests Assert.Equal(0.498, cmyk3.K, 2); // Checked with other online converters. // Cyan - Color color4 = Color.Cyan; + Color32 color4 = Color32.Cyan; Cmyk cmyk4 = color4; Assert.Equal(1, cmyk4.C, 1); Assert.Equal(0f, cmyk4.M, 1); @@ -371,14 +371,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void CmykToColor() { // Dark moderate pink. Cmyk cmyk = new Cmyk(0f, .5f, .171f, .498f); - Color color = cmyk; + Color32 color = cmyk; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -386,7 +386,7 @@ namespace ImageSharp.Tests // Ochre Cmyk cmyk2 = new Cmyk(0, .416f, .833f, .199f); - Color color2 = cmyk2; + Color32 color2 = cmyk2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -394,7 +394,7 @@ namespace ImageSharp.Tests // White Cmyk cmyk3 = new Cmyk(0, 0, 0, 0); - Color color3 = cmyk3; + Color32 color3 = cmyk3; Assert.Equal(color3.R, 255); Assert.Equal(color3.G, 255); @@ -411,7 +411,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-lab /// @@ -419,7 +419,7 @@ namespace ImageSharp.Tests public void ColorToCieLab() { // White - Color color = Color.White; + Color32 color = Color32.White; CieLab cielab = color; Assert.Equal(100, cielab.L, 3); @@ -427,21 +427,21 @@ namespace ImageSharp.Tests Assert.Equal(-0.010, cielab.B, 3); // Black - Color color2 = Color.Black; + Color32 color2 = Color32.Black; CieLab cielab2 = color2; Assert.Equal(0, cielab2.L, 3); Assert.Equal(0, cielab2.A, 3); Assert.Equal(0, cielab2.B, 3); // Gray - Color color3 = Color.Gray; + Color32 color3 = Color32.Gray; CieLab cielab3 = color3; Assert.Equal(53.585, cielab3.L, 3); Assert.Equal(0.003, cielab3.A, 3); Assert.Equal(-0.006, cielab3.B, 3); // Cyan - Color color4 = Color.Cyan; + Color32 color4 = Color32.Cyan; CieLab cielab4 = color4; Assert.Equal(91.117, cielab4.L, 3); Assert.Equal(-48.080, cielab4.A, 3); @@ -449,7 +449,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-lab @@ -458,7 +458,7 @@ namespace ImageSharp.Tests { // Dark moderate pink. CieLab cielab = new CieLab(36.5492f, 33.3173f, -12.0615f); - Color color = cielab; + Color32 color = cielab; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -466,7 +466,7 @@ namespace ImageSharp.Tests // Ochre CieLab cielab2 = new CieLab(58.1758f, 27.3399f, 56.8240f); - Color color2 = cielab2; + Color32 color2 = cielab2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -474,7 +474,7 @@ namespace ImageSharp.Tests // Black CieLab cielab3 = new CieLab(0, 0, 0); - Color color3 = cielab3; + Color32 color3 = cielab3; Assert.Equal(color3.R, 0); Assert.Equal(color3.G, 0); diff --git a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs b/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs index 899ce4f77..dc0555f1f 100644 --- a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs @@ -15,14 +15,14 @@ namespace ImageSharp.Tests using Xunit; public class ColorDefinitionTests { - public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name }); + public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name }); [Theory] [MemberData(nameof(ColorNames))] public void AllColorsAreOnGenericAndBaseColor(string name) { - FieldInfo generic = typeof(NamedColors).GetTypeInfo().GetField(name); - FieldInfo specific = typeof(Color).GetTypeInfo().GetField(name); + FieldInfo generic = typeof(NamedColors).GetTypeInfo().GetField(name); + FieldInfo specific = typeof(Color32).GetTypeInfo().GetField(name); Assert.NotNull(specific); Assert.NotNull(generic); @@ -30,8 +30,8 @@ namespace ImageSharp.Tests Assert.True(specific.Attributes.HasFlag(FieldAttributes.Static), "specific must be static"); Assert.True(generic.Attributes.HasFlag(FieldAttributes.Public), "generic must be public"); Assert.True(generic.Attributes.HasFlag(FieldAttributes.Static), "generic must be static"); - Color expected = (Color)generic.GetValue(null); - Color actual = (Color)specific.GetValue(null); + Color32 expected = (Color32)generic.GetValue(null); + Color32 actual = (Color32)specific.GetValue(null); Assert.Equal(expected, actual); } } diff --git a/tests/ImageSharp.Tests/Colors/ColorTests.cs b/tests/ImageSharp.Tests/Colors/ColorTests.cs index 312e66466..97f9231ba 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorTests.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Tests using Xunit; /// - /// Tests the struct. + /// Tests the struct. /// public class ColorTests { @@ -21,12 +21,12 @@ namespace ImageSharp.Tests [Fact] public void AreEqual() { - Color color1 = new Color(0, 0, 0); - Color color2 = new Color(0, 0, 0, 1F); - Color color3 = Color.FromHex("#000"); - Color color4 = Color.FromHex("#000F"); - Color color5 = Color.FromHex("#000000"); - Color color6 = Color.FromHex("#000000FF"); + Color32 color1 = new Color32(0, 0, 0); + Color32 color2 = new Color32(0, 0, 0, 1F); + Color32 color3 = Color32.FromHex("#000"); + Color32 color4 = Color32.FromHex("#000F"); + Color32 color5 = Color32.FromHex("#000000"); + Color32 color6 = Color32.FromHex("#000000FF"); Assert.Equal(color1, color2); Assert.Equal(color1, color3); @@ -41,11 +41,11 @@ namespace ImageSharp.Tests [Fact] public void AreNotEqual() { - Color color1 = new Color(255, 0, 0, 255); - Color color2 = new Color(0, 0, 0, 255); - Color color3 = Color.FromHex("#000"); - Color color4 = Color.FromHex("#000000"); - Color color5 = Color.FromHex("#FF000000"); + Color32 color1 = new Color32(255, 0, 0, 255); + Color32 color2 = new Color32(0, 0, 0, 255); + Color32 color3 = Color32.FromHex("#000"); + Color32 color4 = Color32.FromHex("#000000"); + Color32 color5 = Color32.FromHex("#FF000000"); Assert.NotEqual(color1, color2); Assert.NotEqual(color1, color3); @@ -59,25 +59,25 @@ namespace ImageSharp.Tests [Fact] public void ConstructorAssignsProperties() { - Color color1 = new Color(1, .1f, .133f, .864f); + Color32 color1 = new Color32(1, .1f, .133f, .864f); Assert.Equal(255, color1.R); Assert.Equal((byte)Math.Round(.1f * 255), color1.G); Assert.Equal((byte)Math.Round(.133f * 255), color1.B); Assert.Equal((byte)Math.Round(.864f * 255), color1.A); - Color color2 = new Color(1, .1f, .133f); + Color32 color2 = new Color32(1, .1f, .133f); Assert.Equal(255, color2.R); Assert.Equal(Math.Round(.1f * 255), color2.G); Assert.Equal(Math.Round(.133f * 255), color2.B); Assert.Equal(255, color2.A); - Color color4 = new Color(new Vector3(1, .1f, .133f)); + Color32 color4 = new Color32(new Vector3(1, .1f, .133f)); Assert.Equal(255, color4.R); Assert.Equal(Math.Round(.1f * 255), color4.G); Assert.Equal(Math.Round(.133f * 255), color4.B); Assert.Equal(255, color4.A); - Color color5 = new Color(new Vector4(1, .1f, .133f, .5f)); + Color32 color5 = new Color32(new Vector4(1, .1f, .133f, .5f)); Assert.Equal(255, color5.R); Assert.Equal(Math.Round(.1f * 255), color5.G); Assert.Equal(Math.Round(.133f * 255), color5.B); @@ -90,7 +90,7 @@ namespace ImageSharp.Tests [Fact] public void FromAndToHex() { - Color color = Color.FromHex("#AABBCCDD"); + Color32 color = Color32.FromHex("#AABBCCDD"); Assert.Equal(170, color.R); Assert.Equal(187, color.G); Assert.Equal(204, color.B); @@ -118,7 +118,7 @@ namespace ImageSharp.Tests [Fact] public unsafe void ByteLayout() { - Color color = new Color(1, 2, 3, 4); + Color32 color = new Color32(1, 2, 3, 4); byte* colorBase = (byte*)&color; Assert.Equal(1, colorBase[0]); Assert.Equal(2, colorBase[1]); diff --git a/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs b/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs index 064bdf2d0..1d655e880 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs @@ -16,101 +16,101 @@ namespace ImageSharp.Tests.Colors /// /// Orange backdrop /// - private static readonly Color Backdrop = new Color(204, 102, 0); + private static readonly Color32 Backdrop = new Color32(204, 102, 0); /// /// Blue source /// - private static readonly Color Source = new Color(0, 102, 153); + private static readonly Color32 Source = new Color32(0, 102, 153); [Fact] public void Normal() { - Color normal = Color.Normal(Backdrop, Source); + Color32 normal = Color32.Normal(Backdrop, Source); Assert.True(normal == Source); } [Fact] public void Multiply() { - Assert.True(Color.Multiply(Backdrop, Color.Black) == Color.Black); - Assert.True(Color.Multiply(Backdrop, Color.White) == Backdrop); + Assert.True(Color32.Multiply(Backdrop, Color32.Black) == Color32.Black); + Assert.True(Color32.Multiply(Backdrop, Color32.White) == Backdrop); - Color multiply = Color.Multiply(Backdrop, Source); - Assert.True(multiply == new Color(0, 41, 0)); + Color32 multiply = Color32.Multiply(Backdrop, Source); + Assert.True(multiply == new Color32(0, 41, 0)); } [Fact] public void Screen() { - Assert.True(Color.Screen(Backdrop, Color.Black) == Backdrop); - Assert.True(Color.Screen(Backdrop, Color.White) == Color.White); + Assert.True(Color32.Screen(Backdrop, Color32.Black) == Backdrop); + Assert.True(Color32.Screen(Backdrop, Color32.White) == Color32.White); - Color screen = Color.Screen(Backdrop, Source); - Assert.True(screen == new Color(204, 163, 153)); + Color32 screen = Color32.Screen(Backdrop, Source); + Assert.True(screen == new Color32(204, 163, 153)); } [Fact] public void HardLight() { - Color hardLight = Color.HardLight(Backdrop, Source); - Assert.True(hardLight == new Color(0, 82, 51)); + Color32 hardLight = Color32.HardLight(Backdrop, Source); + Assert.True(hardLight == new Color32(0, 82, 51)); } [Fact] public void Overlay() { - Color overlay = Color.Overlay(Backdrop, Source); - Assert.True(overlay == new Color(153, 82, 0)); + Color32 overlay = Color32.Overlay(Backdrop, Source); + Assert.True(overlay == new Color32(153, 82, 0)); } [Fact] public void Darken() { - Color darken = Color.Darken(Backdrop, Source); - Assert.True(darken == new Color(0, 102, 0)); + Color32 darken = Color32.Darken(Backdrop, Source); + Assert.True(darken == new Color32(0, 102, 0)); } [Fact] public void Lighten() { - Color lighten = Color.Lighten(Backdrop, Source); - Assert.True(lighten == new Color(204, 102, 153)); + Color32 lighten = Color32.Lighten(Backdrop, Source); + Assert.True(lighten == new Color32(204, 102, 153)); } [Fact] public void SoftLight() { - Color softLight = Color.SoftLight(Backdrop, Source); - Assert.True(softLight == new Color(163, 90, 0)); + Color32 softLight = Color32.SoftLight(Backdrop, Source); + Assert.True(softLight == new Color32(163, 90, 0)); } [Fact] public void ColorDodge() { - Color colorDodge = Color.ColorDodge(Backdrop, Source); - Assert.True(colorDodge == new Color(204, 170, 0)); + Color32 colorDodge = Color32.ColorDodge(Backdrop, Source); + Assert.True(colorDodge == new Color32(204, 170, 0)); } [Fact] public void ColorBurn() { - Color colorBurn = Color.ColorBurn(Backdrop, Source); - Assert.True(colorBurn == new Color(0, 0, 0)); + Color32 colorBurn = Color32.ColorBurn(Backdrop, Source); + Assert.True(colorBurn == new Color32(0, 0, 0)); } [Fact] public void Difference() { - Color difference = Color.Difference(Backdrop, Source); - Assert.True(difference == new Color(204, 0, 153)); + Color32 difference = Color32.Difference(Backdrop, Source); + Assert.True(difference == new Color32(204, 0, 153)); } [Fact] public void Exclusion() { - Color exclusion = Color.Exclusion(Backdrop, Source); - Assert.True(exclusion == new Color(204, 122, 153)); + Color32 exclusion = Color32.Exclusion(Backdrop, Source); + Assert.True(exclusion == new Color32(204, 122, 153)); } } } diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index aee032acc..f3bed942a 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -420,12 +420,12 @@ namespace ImageSharp.Tests.Common [Fact] public void ColorToBytes() { - Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), }; + Color32[] colors = { new Color32(0, 1, 2, 3), new Color32(4, 5, 6, 7), new Color32(8, 9, 10, 11), }; - using (PinnedBuffer colorBuf = new PinnedBuffer(colors)) + using (PinnedBuffer colorBuf = new PinnedBuffer(colors)) using (PinnedBuffer byteBuf = new PinnedBuffer(colors.Length*4)) { - BufferSpan.Copy(colorBuf, byteBuf, colorBuf.Length); + BufferSpan.Copy(colorBuf, byteBuf, colorBuf.Length); byte[] a = byteBuf.Array; diff --git a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs index 403dffba9..78d1ca4b0 100644 --- a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs +++ b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests [Fact] public void PixelDataPoolRentsMinimumSize() { - Color[] pixels = PixelDataPool.Rent(1024); + Color32[] pixels = PixelDataPool.Rent(1024); Assert.True(pixels.Length >= 1024); } @@ -26,9 +26,9 @@ namespace ImageSharp.Tests [Fact] public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() { - Color[] pixels = new Color[1024]; + Color32[] pixels = new Color32[1024]; - PixelDataPool.Return(pixels); + PixelDataPool.Return(pixels); Assert.True(pixels.Length >= 1024); } @@ -39,7 +39,7 @@ namespace ImageSharp.Tests public void CalculateMaxArrayLength(bool isRawData) { int max = isRawData ? PixelDataPool.CalculateMaxArrayLength() - : PixelDataPool.CalculateMaxArrayLength(); + : PixelDataPool.CalculateMaxArrayLength(); Assert.Equal(max < int.MaxValue, !isRawData); } diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index a1d4d3fd5..3335fd070 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -23,8 +23,8 @@ namespace ImageSharp.Tests.Drawing { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { - image.BackgroundColor(Color.Blue) - .DrawBeziers(Color.HotPink, 5, + image.BackgroundColor(Color32.Blue) + .DrawBeziers(Color32.HotPink, 5, new[] { new Vector2(10, 400), new Vector2(30, 10), @@ -34,21 +34,21 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve - Assert.Equal(Color.HotPink, sourcePixels[138, 115]); + Assert.Equal(Color32.HotPink, sourcePixels[138, 115]); //start points - Assert.Equal(Color.HotPink, sourcePixels[10, 400]); - Assert.Equal(Color.HotPink, sourcePixels[300, 400]); + Assert.Equal(Color32.HotPink, sourcePixels[10, 400]); + Assert.Equal(Color32.HotPink, sourcePixels[300, 400]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[30, 10]); - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Color32.Blue, sourcePixels[30, 10]); + Assert.Equal(Color32.Blue, sourcePixels[240, 30]); // inside shape should be empty - Assert.Equal(Color.Blue, sourcePixels[200, 250]); + Assert.Equal(Color32.Blue, sourcePixels[200, 250]); } } } @@ -59,13 +59,13 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "BezierLine"); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { - image.BackgroundColor(Color.Blue) + image.BackgroundColor(Color32.Blue) .DrawBeziers(color, 10, new[] { @@ -78,9 +78,9 @@ namespace ImageSharp.Tests.Drawing } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve Assert.Equal(mergedColor, sourcePixels[138, 115]); @@ -90,11 +90,11 @@ namespace ImageSharp.Tests.Drawing Assert.Equal(mergedColor, sourcePixels[300, 400]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[30, 10]); - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Color32.Blue, sourcePixels[30, 10]); + Assert.Equal(Color32.Blue, sourcePixels[240, 30]); // inside shape should be empty - Assert.Equal(Color.Blue, sourcePixels[200, 250]); + Assert.Equal(Color32.Blue, sourcePixels[200, 250]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index fc231a89d..9b5a10b32 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -38,18 +38,18 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, p) + .BackgroundColor(Color32.Blue) + .Draw(Color32.HotPink, 5, p) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); } } } @@ -60,7 +60,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Path"); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); LinearLineSegment linerSegemnt = new LinearLineSegment( @@ -81,21 +81,21 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .Draw(color, 10, p) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 8162bc531..c0c7e9c95 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests.Drawing public class FillPatternBrushTests : FileTestBase { - private void Test(string name, Color background, IBrush brush, Color[,] expectedPattern) + private void Test(string name, Color32 background, IBrush brush, Color32[,] expectedPattern) { string path = this.CreateOutputDirectory("Fill", "PatternBrush"); using (Image image = new Image(20, 20)) @@ -29,11 +29,11 @@ namespace ImageSharp.Tests.Drawing image.Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { // lets pick random spots to start checking Random r = new Random(); - Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); + Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); int xStride = expectedPatternFast.Width; int yStride = expectedPatternFast.Height; int offsetX = r.Next(image.Width / xStride) * xStride; @@ -44,8 +44,8 @@ namespace ImageSharp.Tests.Drawing { int actualX = x + offsetX; int actualY = y + offsetY; - Color expected = expectedPatternFast[y, x]; // inverted pattern - Color actual = sourcePixels[actualX, actualY]; + Color32 expected = expectedPatternFast[y, x]; // inverted pattern + Color32 actual = sourcePixels[actualX, actualY]; if (expected != actual) { Assert.True(false, $"Expected {expected} but found {actual} at ({actualX},{actualY})"); @@ -63,73 +63,73 @@ namespace ImageSharp.Tests.Drawing [Fact] public void ImageShouldBeFloodFilledWithPercent10() { - this.Test("Percent10", Color.Blue, Brushes.Percent10(Color.HotPink, Color.LimeGreen), + this.Test("Percent10", Color32.Blue, Brushes.Percent10(Color32.HotPink, Color32.LimeGreen), new[,] { - { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} + { Color32.HotPink , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink , Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent10Transparent() { - Test("Percent10_Transparent", Color.Blue, Brushes.Percent10(Color.HotPink), - new Color[,] { - { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink , Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue, Color.Blue} + Test("Percent10_Transparent", Color32.Blue, Brushes.Percent10(Color32.HotPink), + new Color32[,] { + { Color32.HotPink , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.HotPink , Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.Blue, Color32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent20() { - Test("Percent20", Color.Blue, Brushes.Percent20(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, - { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen} + Test("Percent20", Color32.Blue, Brushes.Percent20(Color32.HotPink, Color32.LimeGreen), + new Color32[,] { + { Color32.HotPink , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink , Color32.LimeGreen}, + { Color32.HotPink , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink , Color32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent20_transparent() { - Test("Percent20_Transparent", Color.Blue, Brushes.Percent20(Color.HotPink), - new Color[,] { - { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink , Color.Blue}, - { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink , Color.Blue} + Test("Percent20_Transparent", Color32.Blue, Brushes.Percent20(Color32.HotPink), + new Color32[,] { + { Color32.HotPink , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.HotPink , Color32.Blue}, + { Color32.HotPink , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.HotPink , Color32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithHorizontal() { - Test("Horizontal", Color.Blue, Brushes.Horizontal(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen , Color.LimeGreen} + Test("Horizontal", Color32.Blue, Brushes.Horizontal(Color32.HotPink, Color32.LimeGreen), + new Color32[,] { + { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink}, + { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen , Color32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithHorizontal_transparent() { - Test("Horizontal_Transparent", Color.Blue, Brushes.Horizontal(Color.HotPink), - new Color[,] { - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue , Color.Blue} + Test("Horizontal_Transparent", Color32.Blue, Brushes.Horizontal(Color32.HotPink), + new Color32[,] { + { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink}, + { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.Blue , Color32.Blue} }); } @@ -138,96 +138,96 @@ namespace ImageSharp.Tests.Drawing [Fact] public void ImageShouldBeFloodFilledWithMin() { - Test("Min", Color.Blue, Brushes.Min(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen , Color.LimeGreen}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink} + Test("Min", Color32.Blue, Brushes.Min(Color32.HotPink, Color32.LimeGreen), + new Color32[,] { + { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen , Color32.LimeGreen}, + { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink} }); } [Fact] public void ImageShouldBeFloodFilledWithMin_transparent() { - Test("Min_Transparent", Color.Blue, Brushes.Min(Color.HotPink), - new Color[,] { - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue , Color.Blue}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, + Test("Min_Transparent", Color32.Blue, Brushes.Min(Color32.HotPink), + new Color32[,] { + { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.Blue , Color32.Blue}, + { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink}, }); } [Fact] public void ImageShouldBeFloodFilledWithVertical() { - Test("Vertical", Color.Blue, Brushes.Vertical(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen} + Test("Vertical", Color32.Blue, Brushes.Vertical(Color32.HotPink, Color32.LimeGreen), + new Color32[,] { + { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithVertical_transparent() { - Test("Vertical_Transparent", Color.Blue, Brushes.Vertical(Color.HotPink), - new Color[,] { - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue} + Test("Vertical_Transparent", Color32.Blue, Brushes.Vertical(Color32.HotPink), + new Color32[,] { + { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal() { - Test("ForwardDiagonal", Color.Blue, Brushes.ForwardDiagonal(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} + Test("ForwardDiagonal", Color32.Blue, Brushes.ForwardDiagonal(Color32.HotPink, Color32.LimeGreen), + new Color32[,] { + { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent() { - Test("ForwardDiagonal_Transparent", Color.Blue, Brushes.ForwardDiagonal(Color.HotPink), - new Color[,] { - { Color.Blue, Color.Blue, Color.Blue, Color.HotPink}, - { Color.Blue, Color.Blue, Color.HotPink, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.HotPink, Color.Blue, Color.Blue, Color.Blue} + Test("ForwardDiagonal_Transparent", Color32.Blue, Brushes.ForwardDiagonal(Color32.HotPink), + new Color32[,] { + { Color32.Blue, Color32.Blue, Color32.Blue, Color32.HotPink}, + { Color32.Blue, Color32.Blue, Color32.HotPink, Color32.Blue}, + { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, + { Color32.HotPink, Color32.Blue, Color32.Blue, Color32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal() { - Test("BackwardDiagonal", Color.Blue, Brushes.BackwardDiagonal(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink} + Test("BackwardDiagonal", Color32.Blue, Brushes.BackwardDiagonal(Color32.HotPink, Color32.LimeGreen), + new Color32[,] { + { Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen}, + { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink} }); } [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal_transparent() { - Test("BackwardDiagonal_Transparent", Color.Blue, Brushes.BackwardDiagonal(Color.HotPink), - new Color[,] { - { Color.HotPink, Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue, Color.HotPink} + Test("BackwardDiagonal_Transparent", Color32.Blue, Brushes.BackwardDiagonal(Color32.HotPink), + new Color32[,] { + { Color32.HotPink, Color32.Blue, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.HotPink, Color32.Blue}, + { Color32.Blue, Color32.Blue, Color32.Blue, Color32.HotPink} }); } } diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 03994bc94..26a9a86ab 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -29,14 +29,14 @@ namespace ImageSharp.Tests.Drawing { ImageSharp.Rectangle bounds = new ImageSharp.Rectangle(0, 0, 1, 1); - Mock> brush = new Mock>(); + Mock> brush = new Mock>(); Mock region = new Mock(); region.Setup(x => x.Bounds).Returns(bounds); GraphicsOptions options = new GraphicsOptions(antialias) { AntialiasSubpixelDepth = 1 }; - FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); + FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); Image img = new Image(1, 1); processor.Apply(img, bounds); diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index bafc84b69..c3ba9e56b 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -24,15 +24,15 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DefaultBack.png")) { image - .Fill(Color.HotPink) + .Fill(Color32.HotPink) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); } } } @@ -46,16 +46,16 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); } } } @@ -66,20 +66,20 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .Fill(color) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index d7a4bde95..4aa199da4 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -36,33 +36,33 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Color32.Blue) + .Draw(Color32.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[10, 10]); + Assert.Equal(Color32.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color32.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 300]); + Assert.Equal(Color32.HotPink, sourcePixels[50, 300]); - Assert.Equal(Color.HotPink, sourcePixels[37, 85]); + Assert.Equal(Color32.HotPink, sourcePixels[37, 85]); - Assert.Equal(Color.HotPink, sourcePixels[93, 85]); + Assert.Equal(Color32.HotPink, sourcePixels[93, 85]); - Assert.Equal(Color.HotPink, sourcePixels[65, 137]); + Assert.Equal(Color32.HotPink, sourcePixels[65, 137]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Color32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Color32.Blue, sourcePixels[100, 192]); } } } @@ -86,18 +86,18 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Color32.Blue) + .Draw(Color32.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[10, 10]); + Assert.Equal(Color32.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color32.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 300]); + Assert.Equal(Color32.HotPink, sourcePixels[50, 300]); //Assert.Equal(Color.HotPink, sourcePixels[37, 85]); @@ -106,13 +106,13 @@ namespace ImageSharp.Tests.Drawing //Assert.Equal(Color.HotPink, sourcePixels[65, 137]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Color32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Color32.Blue, sourcePixels[100, 192]); } } } @@ -137,28 +137,28 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Color32.Blue) + .Draw(Color32.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[10, 10]); + Assert.Equal(Color32.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color32.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 300]); + Assert.Equal(Color32.HotPink, sourcePixels[50, 300]); - Assert.Equal(Color.Blue, sourcePixels[130, 41]); + Assert.Equal(Color32.Blue, sourcePixels[130, 41]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Color32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Color32.Blue, sourcePixels[100, 192]); } } } @@ -183,8 +183,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1)) + .BackgroundColor(Color32.Blue) + .Draw(Pens.Dash(Color32.HotPink, 5), simplePath.Clip(hole1)) .Save(output); } } @@ -204,22 +204,22 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .Draw(color, 5, simplePath.Clip(hole1)) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[10, 10]); @@ -234,14 +234,14 @@ namespace ImageSharp.Tests.Drawing Assert.Equal(mergedColor, sourcePixels[65, 137]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Color32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Color32.Blue, sourcePixels[100, 192]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 81efd933b..9ddd1d88d 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -23,8 +23,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Color.HotPink, 5, + .BackgroundColor(Color32.Blue) + .DrawLines(Color32.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -33,13 +33,13 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); } } } @@ -53,8 +53,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Color.HotPink, 5, + .BackgroundColor(Color32.Blue) + .DrawLines(Color32.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -64,13 +64,13 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); } } } @@ -84,8 +84,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.Dash(Color.HotPink, 5), + .BackgroundColor(Color32.Blue) + .DrawLines(Pens.Dash(Color32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -105,8 +105,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dot.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.Dot(Color.HotPink, 5), + .BackgroundColor(Color32.Blue) + .DrawLines(Pens.Dot(Color32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -126,8 +126,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DashDot.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.DashDot(Color.HotPink, 5), + .BackgroundColor(Color32.Blue) + .DrawLines(Pens.DashDot(Color32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -147,8 +147,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.DashDotDot(Color.HotPink, 5), new[] { + .BackgroundColor(Color32.Blue) + .DrawLines(Pens.DashDotDot(Color32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) @@ -162,7 +162,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Lines"); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); Image image = new Image(500, 500); @@ -170,7 +170,7 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .DrawLines(color, 10, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -180,15 +180,15 @@ namespace ImageSharp.Tests.Drawing } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f/255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f/255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); } } @@ -202,8 +202,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Color.HotPink, 10, new[] { + .BackgroundColor(Color32.Blue) + .DrawLines(Color32.HotPink, 10, new[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), @@ -212,15 +212,15 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[8, 8]); + Assert.Equal(Color32.HotPink, sourcePixels[8, 8]); - Assert.Equal(Color.HotPink, sourcePixels[198, 10]); + Assert.Equal(Color32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color.Blue, sourcePixels[10, 50]); + Assert.Equal(Color32.Blue, sourcePixels[10, 50]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs index 82e2f72a2..0e92c6f59 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Firebrick, 99.9f); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); + Pen pen = new Pen(Color32.Firebrick, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -56,7 +56,7 @@ namespace ImageSharp.Tests.Drawing.Paths BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -76,7 +76,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -96,10 +96,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -109,7 +109,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -118,10 +118,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -131,7 +131,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -149,7 +149,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs index cc126614f..59513a51c 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); + Pen pen = new Pen(Color32.Gray, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,7 +54,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -65,7 +65,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -85,7 +85,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -94,10 +94,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -107,7 +107,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -116,10 +116,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -129,7 +129,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -147,7 +147,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs index 6c1c06813..c7a556230 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); + Pen pen = new Pen(Color32.Gray, 99.9f); IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,14 +45,14 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -63,14 +63,14 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -81,17 +81,17 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -101,17 +101,17 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -121,7 +121,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -137,7 +137,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs index 9de052331..7e6324215 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); + Pen pen = new Pen(Color32.Gray, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,7 +54,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -65,7 +65,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -85,7 +85,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -94,10 +94,10 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -107,7 +107,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -116,10 +116,10 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -129,7 +129,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -147,7 +147,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs index 215d5a7c7..f504f7d25 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); + Pen pen = new Pen(Color32.Gray, 99.9f); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 98, 324); private ProcessorWatchingImage img; @@ -41,7 +41,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -64,7 +64,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -77,7 +77,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -88,7 +88,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -101,10 +101,10 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -114,7 +114,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -127,10 +127,10 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -140,7 +140,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -162,7 +162,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 5ba6580bd..7cd330eaa 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths public class FillPath : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -79,7 +79,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -105,7 +105,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index ad72d4c4e..45ebea248 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths public class FillPolygon : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); Vector2[] path = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(brush, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -60,7 +60,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(brush, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -77,7 +77,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(color, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -85,7 +85,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -95,7 +95,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(color, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -103,7 +103,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index f6b1c4ade..6ce57256c 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths public class FillRectangle : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + Color32 color = Color32.HotPink; + SolidBrush brush = Brushes.Solid(Color32.HotPink); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 77, 76); private ProcessorWatchingImage img; @@ -39,7 +39,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, rectangle); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -59,7 +59,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -79,7 +79,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, rectangle); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -90,7 +90,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -100,7 +100,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -111,7 +111,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs index 2d3d2cc2b..0af88d800 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs @@ -11,8 +11,8 @@ namespace ImageSharp.Tests.Drawing.Paths /// /// Watches but does not actually run the processors against the image. /// - /// - public class ProcessorWatchingImage : Image + /// + public class ProcessorWatchingImage : Image { public List ProcessorApplications { get; } = new List(); @@ -21,7 +21,7 @@ namespace ImageSharp.Tests.Drawing.Paths { } - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { this.ProcessorApplications.Add(new ProcessorDetails { @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing.Paths public struct ProcessorDetails { - public IImageProcessor processor; + public IImageProcessor processor; public Rectangle rectangle; } } diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 3e06ca918..3e2034531 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 5, + .BackgroundColor(Color32.Blue) + .DrawPolygon(Color32.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -35,15 +35,15 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); } } } @@ -58,30 +58,30 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .DrawPolygon(color, 10, simplePath) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); } } } @@ -96,22 +96,22 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 10, new Rectangle(10, 10, 190, 140)) + .BackgroundColor(Color32.Blue) + .Draw(Color32.HotPink, 10, new Rectangle(10, 10, 190, 140)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[8, 8]); + Assert.Equal(Color32.HotPink, sourcePixels[8, 8]); - Assert.Equal(Color.HotPink, sourcePixels[198, 10]); + Assert.Equal(Color32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color.HotPink, sourcePixels[10, 50]); + Assert.Equal(Color32.HotPink, sourcePixels[10, 50]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Color32.Blue, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 0b450d166..497d4ab45 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Color.Yellow, Color.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Color32.Yellow, Color32.HotPink, 0.2f); foreach (TestFile file in Files) { @@ -38,7 +38,7 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Color.Yellow, Color.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Color32.Yellow, Color32.HotPink, 0.2f); foreach (TestFile file in Files) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 1a7e98a12..124463d14 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -29,20 +29,20 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new Polygon(new BezierLineSegment(simplePath))) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, new Polygon(new BezierLineSegment(simplePath))) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[150, 300]); + Assert.Equal(Color32.HotPink, sourcePixels[150, 300]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Color32.Blue, sourcePixels[240, 30]); // inside shape should not be empty - Assert.Equal(Color.HotPink, sourcePixels[200, 250]); + Assert.Equal(Color32.HotPink, sourcePixels[200, 250]); } } } @@ -57,28 +57,28 @@ namespace ImageSharp.Tests.Drawing new Vector2(240, 30), new Vector2(300, 400) }; - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .Fill(color, new Polygon(new BezierLineSegment(simplePath))) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve Assert.Equal(mergedColor, sourcePixels[138, 116]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Color32.Blue, sourcePixels[240, 30]); // inside shape should not be empty Assert.Equal(mergedColor, sourcePixels[200, 250]); diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index 4ff250a93..be4fb743e 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -35,17 +35,17 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, clipped) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, clipped) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[20, 35]); + Assert.Equal(Color32.HotPink, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[60, 100]); + Assert.Equal(Color32.Blue, sourcePixels[60, 100]); } } } @@ -70,17 +70,17 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, simplePath.Clip(hole1)) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[20, 35]); + Assert.Equal(Color32.HotPink, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[60, 100]); + Assert.Equal(Color32.Blue, sourcePixels[60, 100]); } } } @@ -98,27 +98,27 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .Fill(color, simplePath.Clip(hole1)) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[60, 100]); + Assert.Equal(Color32.Blue, sourcePixels[60, 100]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 79363480f..0cbb6108c 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -32,13 +32,13 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .FillPolygon(Color.HotPink, simplePath, new GraphicsOptions(true)) + .FillPolygon(Color32.HotPink, simplePath, new GraphicsOptions(true)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[81, 145]); + Assert.Equal(Color32.HotPink, sourcePixels[81, 145]); } } } @@ -58,13 +58,13 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Pattern.png")) { image - .FillPolygon(Brushes.Horizontal(Color.HotPink), simplePath, new GraphicsOptions(true)) + .FillPolygon(Brushes.Horizontal(Color32.HotPink), simplePath, new GraphicsOptions(true)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[81, 145]); + Assert.Equal(Color32.HotPink, sourcePixels[81, 145]); } } } @@ -83,19 +83,19 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple_NoAntialias.png")) { image - .BackgroundColor(Color.Blue) - .FillPolygon(Color.HotPink, simplePath, new GraphicsOptions(false)) + .BackgroundColor(Color32.Blue) + .FillPolygon(Color32.HotPink, simplePath, new GraphicsOptions(false)) .Save(output); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[11, 11]); + Assert.Equal(Color32.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color.HotPink, sourcePixels[199, 150]); + Assert.Equal(Color32.HotPink, sourcePixels[199, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 50]); + Assert.Equal(Color32.HotPink, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); } } } @@ -117,7 +117,7 @@ namespace ImageSharp.Tests.Drawing ImageBrush brush = new ImageBrush(brushImage); image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .FillPolygon(brush, simplePath) .Save(output); } @@ -132,24 +132,24 @@ namespace ImageSharp.Tests.Drawing new Vector2(200, 150), new Vector2(50, 300) }; - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Color32.Blue) .FillPolygon(color, simplePath) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); } } } @@ -164,22 +164,22 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[11, 11]); + Assert.Equal(Color32.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color.HotPink, sourcePixels[198, 10]); + Assert.Equal(Color32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color.HotPink, sourcePixels[10, 50]); + Assert.Equal(Color32.HotPink, sourcePixels[10, 50]); - Assert.Equal(Color.HotPink, sourcePixels[50, 50]); + Assert.Equal(Color32.HotPink, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Color32.Blue, sourcePixels[2, 2]); } } } @@ -194,16 +194,16 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Triangle.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new RegularPolygon(50, 50, 3, 30)) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, new RegularPolygon(50, 50, 3, 30)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.Blue, sourcePixels[30, 65]); + Assert.Equal(Color32.Blue, sourcePixels[30, 65]); - Assert.Equal(Color.HotPink, sourcePixels[50, 50]); + Assert.Equal(Color32.HotPink, sourcePixels[50, 50]); } } } @@ -220,8 +220,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Septagon.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) .Save(output); } } @@ -239,8 +239,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/ellipse.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new Ellipse(50, 50, 30, 50) + .BackgroundColor(Color32.Blue) + .Fill(Color32.HotPink, new Ellipse(50, 50, 30, 50) .Rotate((float)(Math.PI / 3))) .Save(output); } @@ -259,8 +259,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/clipped-corner.png")) { image - .Fill(Color.Blue) - .FillPolygon(Color.HotPink, new[] + .Fill(Color32.Blue) + .FillPolygon(Color32.HotPink, new[] { new Vector2( 8, 8 ), new Vector2( 64, 8 ), diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 52b7fcbb6..f85a22d21 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -21,9 +21,9 @@ namespace ImageSharp.Tests.Drawing.Text public class DrawText : IDisposable { - Color color = Color.HotPink; + Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + SolidBrush brush = Brushes.Solid(Color32.HotPink); IPath path = new SixLabors.Shapes.Path( new LinearLineSegment( @@ -53,73 +53,73 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "123", this.Font, - Brushes.Solid(Color.Red), + Brushes.Solid(Color32.Red), null, Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), null, Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), null, Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Color.Red, Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Color32.Red, Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor processor = + Assert.IsType>(this.img.ProcessorApplications[0].processor); - SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(Color.Red, brush.Color); + SolidBrush brush = Assert.IsType>(processor.Brush); + Assert.Equal(Color32.Red, brush.Color); } [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Color.Red, Vector2.Zero); + this.img.DrawText("123", this.Font, Color32.Red, Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor processor = + Assert.IsType>(this.img.ProcessorApplications[0].processor); - SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(Color.Red, brush.Color); + SolidBrush brush = Assert.IsType>(processor.Brush); + Assert.Equal(Color32.Red, brush.Color); } [Fact] @@ -129,43 +129,43 @@ namespace ImageSharp.Tests.Drawing.Text "123", this.Font, null, - Pens.Dash(Color.Red, 1), + Pens.Dash(Color32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, null, Pens.Dash(Color32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Pens.Dash(Color32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, Pens.Dash(Color32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] @@ -174,8 +174,8 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "123", this.Font, - Brushes.Solid(Color.Red), - Pens.Dash(Color.Red, 1), + Brushes.Solid(Color32.Red), + Pens.Dash(Color32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); @@ -186,7 +186,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), Pens.Dash(Color32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(6, this.img.ProcessorApplications.Count); @@ -198,26 +198,26 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "1", this.Font, - Brushes.Solid(Color.Red), - Pens.Dash(Color.Red, 1), + Brushes.Solid(Color32.Red), + Pens.Dash(Color32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[1].processor); } [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("1", this.Font, Brushes.Solid(Color32.Red), Pens.Dash(Color32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[1].processor); } [Fact] @@ -225,19 +225,19 @@ namespace ImageSharp.Tests.Drawing.Text { this.img.MetaData.VerticalResolution = 1; this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true) { + this.img.DrawText("1", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero, new TextGraphicsOptions(true) { UseImageResolution = false }); - this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true) + this.img.DrawText("1", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero, new TextGraphicsOptions(true) { UseImageResolution = true }); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); + FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index 0bb3afccd..1d2af9363 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -32,8 +32,8 @@ namespace ImageSharp.Tests.Drawing.Text //draws 2 overlapping triangle glyphs twice 1 set on each line using (Image img = new Image(100, 200)) { - img.Fill(Color.DarkBlue) - .DrawText("AB\nAB", new Font(this.Font, 50), Color.Red, new Vector2(0, 0)); + img.Fill(Color32.DarkBlue) + .DrawText("AB\nAB", new Font(this.Font, 50), Color32.Red, new Vector2(0, 0)); img.Save($"{this.CreateOutputDirectory("Drawing", "Text")}/AB.png"); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index 28a64a765..121b3ca09 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -69,9 +69,9 @@ namespace ImageSharp.Tests .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }) .ToArray(); - Image[] testImages = + Image[] testImages = testFiles.Select( - tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) + tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) .ToArray(); using (MemoryStream ms = new MemoryStream()) @@ -79,7 +79,7 @@ namespace ImageSharp.Tests this.Measure(executionCount, () => { - foreach (Image img in testImages) + foreach (Image img in testImages) { JpegEncoder encoder = new JpegEncoder(); JpegEncoderOptions options = new JpegEncoderOptions { Quality = quality, Subsample = subsample }; diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 10b0cbb94..85245e102 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests { private readonly Mock fileSystem; private readonly IDecoderOptions decoderOptions; - private Image returnImage; + private Image returnImage; private Mock localDecoder; private Mock localFormat; private readonly string FilePath; @@ -44,7 +44,7 @@ namespace ImageSharp.Tests this.localFormat.Setup(x => x.IsSupportedFileFormat(It.IsAny())).Returns(true); this.localFormat.Setup(x => x.SupportedExtensions).Returns(new string[] { "png", "jpg" }); - this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny())) + this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((c, s, o) => { using (var ms = new MemoryStream()) @@ -103,10 +103,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithType() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -128,10 +128,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithTypeAndOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -147,7 +147,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); } @@ -155,13 +155,13 @@ namespace ImageSharp.Tests public void LoadFromStreamWithTypeAndConfig() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream); + Image img = Image.Load(this.LocalConfiguration, stream); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); } @@ -174,7 +174,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); } @@ -182,13 +182,13 @@ namespace ImageSharp.Tests public void LoadFromStreamWithTypeAndConfigAndOptions() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream, this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, stream, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); } @@ -201,18 +201,18 @@ namespace ImageSharp.Tests Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); } [Fact] public void LoadFromStreamWithTypeAndDecoder() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object); + Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); } [Fact] @@ -222,18 +222,18 @@ namespace ImageSharp.Tests Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); } [Fact] public void LoadFromStreamWithTypeAndDecoderAndOptions() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); } [Fact] @@ -252,10 +252,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithType() { - Image img = Image.Load(this.DataStream.ToArray()); + Image img = Image.Load(this.DataStream.ToArray()); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -277,10 +277,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndOptions() { - Image img = Image.Load(this.DataStream.ToArray(), this.decoderOptions); + Image img = Image.Load(this.DataStream.ToArray(), this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -295,7 +295,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -303,14 +303,14 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndConfig() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -323,7 +323,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -331,13 +331,13 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndConfigAndOptions() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray(), this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray(), this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -349,18 +349,18 @@ namespace ImageSharp.Tests Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } [Fact] public void LoadFromBytesWithTypeAndDecoder() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -370,18 +370,18 @@ namespace ImageSharp.Tests Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } [Fact] public void LoadFromBytesWithTypeAndDecoderAndOptions() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -401,10 +401,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithType() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -426,10 +426,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithTypeAndOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -444,20 +444,20 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); } [Fact] public void LoadFromFileWithTypeAndConfig() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath); + Image img = Image.Load(this.LocalConfiguration, this.FilePath); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); } @@ -469,20 +469,20 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); } [Fact] public void LoadFromFileWithTypeAndConfigAndOptions() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath, this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, this.FilePath, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); } @@ -493,17 +493,17 @@ namespace ImageSharp.Tests Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); } [Fact] public void LoadFromFileWithTypeAndDecoder() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object); + Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); } [Fact] @@ -512,17 +512,17 @@ namespace ImageSharp.Tests Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); } [Fact] public void LoadFromFileWithTypeAndDecoderAndOptions() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index 0d1c3e09b..f398d33d2 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -59,7 +59,7 @@ namespace ImageSharp.Tests this.fileSystem.Setup(x => x.Create("path.png")).Returns(stream); this.Image.Save("path.png"); - this.encoder.Verify(x => x.Encode(this.Image, stream, null)); + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -70,7 +70,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderOptions); - this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -81,7 +81,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -92,7 +92,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } @@ -105,7 +105,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -116,7 +116,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -125,7 +125,7 @@ namespace ImageSharp.Tests Stream stream = new MemoryStream(); this.Image.Save(stream); - this.encoder.Verify(x => x.Encode(this.Image, stream, null)); + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -135,7 +135,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderOptions); - this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -145,7 +145,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -155,7 +155,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -165,7 +165,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.formatNotRegistered.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -175,7 +175,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.formatNotRegistered.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index cd9cd04b7..b6aa8ead2 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -125,7 +125,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYX() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyFromZYX(image); } @@ -134,7 +134,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYXW() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyFromZYXW(image); } @@ -143,7 +143,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYX() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyToZYX(image); } @@ -152,7 +152,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYXW() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyToZYXW(image); } @@ -176,7 +176,7 @@ namespace ImageSharp.Tests pixels.CopyFrom(row, 0); - Color color = (Color)(object)pixels[0, 0]; + Color32 color = (Color32)(object)pixels[0, 0]; Assert.Equal(red, color.R); Assert.Equal(green, color.G); Assert.Equal(blue, color.B); @@ -204,7 +204,7 @@ namespace ImageSharp.Tests pixels.CopyFrom(row, 0); - Color color = (Color)(object)pixels[0, 0]; + Color32 color = (Color32)(object)pixels[0, 0]; Assert.Equal(red, color.R); Assert.Equal(green, color.G); Assert.Equal(blue, color.B); @@ -224,7 +224,7 @@ namespace ImageSharp.Tests using (PixelArea row = new PixelArea(1, ComponentOrder.Zyx)) { - pixels[0, 0] = (TColor)(object)new Color(red, green, blue); + pixels[0, 0] = (TColor)(object)new Color32(red, green, blue); pixels.CopyTo(row, 0); @@ -247,7 +247,7 @@ namespace ImageSharp.Tests using (PixelArea row = new PixelArea(1, ComponentOrder.Zyxw)) { - pixels[0, 0] = (TColor)(object)new Color(red, green, blue, alpha); + pixels[0, 0] = (TColor)(object)new Color32(red, green, blue, alpha); pixels.CopyTo(row, 0); diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index f380724df..554c2bc2b 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -243,7 +243,7 @@ namespace ImageSharp.Tests TestProfile(profile); - Image thumbnail = profile.CreateThumbnail(); + Image thumbnail = profile.CreateThumbnail(); Assert.NotNull(thumbnail); Assert.Equal(256, thumbnail.Width); Assert.Equal(170, thumbnail.Height); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs index fd08b87a4..90af8f0ac 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs @@ -21,7 +21,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { - image.BackgroundColor(Color.HotPink).Save(output); + image.BackgroundColor(Color32.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs index 1afb1300a..9db90b324 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.Glow(Color.HotPink).Save(output); + image.Glow(Color32.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs index da09aa85e..ec6694cb8 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs @@ -36,13 +36,13 @@ namespace ImageSharp.Tests // [Fact] public void PrintWeightsData() { - ResizeProcessor proc = new ResizeProcessor(new BicubicResampler(), 200, 200); + ResizeProcessor proc = new ResizeProcessor(new BicubicResampler(), 200, 200); - ResamplingWeightedProcessor.WeightsBuffer weights = proc.PrecomputeWeights(200, 500); + ResamplingWeightedProcessor.WeightsBuffer weights = proc.PrecomputeWeights(200, 500); StringBuilder bld = new StringBuilder(); - foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights) + foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights) { for (int i = 0; i < window.Length; i++) { diff --git a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs index 7f40ef1d2..a0b66936e 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.Vignette(Color.HotPink).Save(output); + image.Vignette(Color32.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs index 2361bc01c..8c27c2937 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs @@ -5,13 +5,13 @@ namespace ImageSharp.Tests { - public class ImageFactory : GenericFactory + public class ImageFactory : GenericFactory { - public override Image CreateImage(byte[] bytes) => Image.Load(bytes); + public override Image CreateImage(byte[] bytes) => Image.Load(bytes); - public override Image CreateImage(int width, int height) => new Image(width, height); + public override Image CreateImage(int width, int height) => new Image(width, height); - public override Image CreateImage(Image other) + public override Image CreateImage(Image other) { Image img = (Image)other; return new Image(img); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index c9312eed1..9278def26 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -147,9 +147,9 @@ namespace ImageSharp.Tests int bottom = pixels.Height; int height = (int)Math.Ceiling(pixels.Height / 6f); - Vector4 red = Color.Red.ToVector4(); // use real color so we can see har it translates in the test pattern - Vector4 green = Color.Green.ToVector4(); // use real color so we can see har it translates in the test pattern - Vector4 blue = Color.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 red = Color32.Red.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 green = Color32.Green.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 blue = Color32.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern TColor c = default(TColor); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs index 260a677d3..8614f6d7a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests { private static readonly Dictionary ClrTypes2PixelTypes = new Dictionary(); - private static readonly Assembly ImageSharpAssembly = typeof(Color).GetTypeInfo().Assembly; + private static readonly Assembly ImageSharpAssembly = typeof(Color32).GetTypeInfo().Assembly; private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary(); @@ -28,8 +28,8 @@ namespace ImageSharp.Tests static TestUtilityExtensions() { - string nameSpace = typeof(Color).FullName; - nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color).Name.Length - 1); + string nameSpace = typeof(Color32).FullName; + nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color32).Name.Length - 1); foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass)) { string typeName = $"{nameSpace}.{pt.ToString()}"; @@ -42,7 +42,7 @@ namespace ImageSharp.Tests PixelTypes2ClrTypes[pt] = t; ClrTypes2PixelTypes[t] = pt; } - PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color); + PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color32); } public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index 6760735d1..a3ea09d6e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -151,7 +151,7 @@ namespace ImageSharp.Tests public static readonly TheoryData BasicData = new TheoryData() { - TestImageProvider.Blank(10, 20), + TestImageProvider.Blank(10, 20), TestImageProvider.Blank( 10, 20), @@ -169,7 +169,7 @@ namespace ImageSharp.Tests public static readonly TheoryData FileData = new TheoryData() { - TestImageProvider.File( + TestImageProvider.File( TestImages.Bmp.Car), TestImageProvider.File( TestImages.Bmp.F) diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 63c24a157..d5abfe208 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -51,10 +51,10 @@ namespace ImageSharp.Tests [Fact] public void Baz() { - Type type = typeof(Color).GetTypeInfo().Assembly.GetType("ImageSharp.Color"); + Type type = typeof(Color32).GetTypeInfo().Assembly.GetType("ImageSharp.Color"); this.Output.WriteLine(type.ToString()); - Type fake = typeof(Color).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); + Type fake = typeof(Color32).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); Assert.Null(fake); } @@ -84,17 +84,17 @@ namespace ImageSharp.Tests } [Theory] - [InlineData(PixelTypes.Color, typeof(Color))] + [InlineData(PixelTypes.Color, typeof(Color32))] [InlineData(PixelTypes.Argb, typeof(Argb))] [InlineData(PixelTypes.HalfVector4, typeof(HalfVector4))] - [InlineData(PixelTypes.StandardImageClass, typeof(Color))] + [InlineData(PixelTypes.StandardImageClass, typeof(Color32))] public void ToType(PixelTypes pt, Type expectedType) { Assert.Equal(pt.ToType(), expectedType); } [Theory] - [InlineData(typeof(Color), PixelTypes.Color)] + [InlineData(typeof(Color32), PixelTypes.Color)] [InlineData(typeof(Argb), PixelTypes.Argb)] public void GetPixelType(Type clrType, PixelTypes expectedPixelType) { @@ -120,9 +120,9 @@ namespace ImageSharp.Tests AssertContainsPixelType(PixelTypes.Alpha8, expanded); AssertContainsPixelType(PixelTypes.Bgr565, expanded); - AssertContainsPixelType(PixelTypes.Color, expanded); + AssertContainsPixelType(PixelTypes.Color, expanded); AssertContainsPixelType(PixelTypes.HalfVector2, expanded); - AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); + AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } [Fact] @@ -131,8 +131,8 @@ namespace ImageSharp.Tests KeyValuePair[] expanded = PixelTypes.All.ExpandAllTypes().ToArray(); Assert.True(expanded.Length >= TestUtilityExtensions.GetAllPixelTypes().Length - 2); - AssertContainsPixelType(PixelTypes.Color, expanded); - AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); + AssertContainsPixelType(PixelTypes.Color, expanded); + AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } } } \ No newline at end of file From ba89468fe4b4d04088b1c8993a1bd56fc7acb0bb Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 17 Apr 2017 00:20:10 +1000 Subject: [PATCH 21/34] Begin add vector based Color --- src/ImageSharp/Colors/Color.BulkOperations.cs | 306 +--------------- src/ImageSharp/Colors/Color.cs | 335 ++++++++++++++++++ .../Colors/Color32.BulkOperations.cs | 291 +++++++++++++++ src/ImageSharp/Colors/Color32.Transforms.cs | 2 +- src/ImageSharp/Colors/Color32.cs | 2 +- src/ImageSharp/Colors/ColorspaceTransforms.cs | 2 +- .../BulkPixelOperations{TColor}.cs | 40 +-- .../ImageSharp.Benchmarks/Samplers/Resize.cs | 21 ++ 8 files changed, 676 insertions(+), 323 deletions(-) create mode 100644 src/ImageSharp/Colors/Color.cs create mode 100644 src/ImageSharp/Colors/Color32.BulkOperations.cs diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 096e85db8..671578e4c 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -1,305 +1,35 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp +namespace ImageSharp { using System; using System.Numerics; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - /// - /// Conains the definition of - /// - public partial struct Color32 + /// + /// Unpacked pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. + /// 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 partial struct Color { /// - /// implementation optimized for . + /// implementation optimized for . /// - internal class BulkOperations : BulkPixelOperations + internal class BulkOperations : BulkPixelOperations { - /// - /// SIMD optimized bulk implementation of - /// that works only with `count` divisible by . - /// - /// The to the source colors. - /// The to the dstination vectors. - /// The number of pixels to convert. - /// - /// Implementation adapted from: - /// - /// http://stackoverflow.com/a/5362789 - /// - /// TODO: We can replace this implementation in the future using new Vector API-s: - /// - /// https://github.com/dotnet/corefx/issues/15957 - /// - /// - internal static unsafe void ToVector4SimdAligned( - BufferSpan sourceColor32s, - BufferSpan destVectors, - int count) - { - if (!Vector.IsHardwareAccelerated) - { - throw new InvalidOperationException( - "Color32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); - } - - int vecSize = Vector.Count; - - DebugGuard.IsTrue( - count % vecSize == 0, - nameof(count), - "Argument 'count' should divisible by Vector.Count!"); - - Vector bVec = new Vector(256.0f / 255.0f); - Vector magicFloat = new Vector(32768.0f); - Vector magicInt = new Vector(1191182336); // reinterpreded value of 32768.0f - Vector mask = new Vector(255); - - int unpackedRawCount = count * 4; - - ref uint src = ref Unsafe.As(ref sourceColor32s.DangerousGetPinnableReference()); - - using (Buffer tempBuf = new Buffer( - unpackedRawCount + Vector.Count)) - { - uint[] temp = tempBuf.Array; - float[] fTemp = Unsafe.As(temp); - - ref UnpackedRGBA tempBase = ref Unsafe.As(ref tempBuf[0]); - - for (int i = 0; i < count; i++) - { - uint sVal = Unsafe.Add(ref src, i); - ref UnpackedRGBA dst = ref Unsafe.Add(ref tempBase, i); - - // This call is the bottleneck now: - dst.Load(sVal); - } - - for (int i = 0; i < unpackedRawCount; i += vecSize) - { - Vector vi = new Vector(temp, i); - - vi &= mask; - vi |= magicInt; - - Vector vf = Vector.AsVectorSingle(vi); - vf = (vf - magicFloat) * bVec; - vf.CopyTo(fTemp, i); - } - - BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint)); - } - } - /// - internal override void ToVector4(BufferSpan sourceColor32s, BufferSpan destVectors, int count) + internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) { - if (count < 256 || !Vector.IsHardwareAccelerated) - { - // Doesn't worth to bother with SIMD: - base.ToVector4(sourceColor32s, destVectors, count); - return; - } - - int remainder = count % Vector.Count; - - int alignedCount = count - remainder; - - if (alignedCount > 0) - { - ToVector4SimdAligned(sourceColor32s, destVectors, alignedCount); - } - - if (remainder > 0) - { - sourceColor32s = sourceColor32s.Slice(alignedCount); - destVectors = destVectors.Slice(alignedCount); - base.ToVector4(sourceColor32s, destVectors, remainder); - } - } - - /// - internal override void PackFromXyzBytes( - BufferSpan sourceBytes, - BufferSpan destColor32s, - int count) - { - ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color32 destRef = ref destColor32s.DangerousGetPinnableReference(); + ref Vector4 sourceRef = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); + ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color32 dp = ref Unsafe.Add(ref destRef, i); - - Unsafe.As(ref dp) = sp; - dp.A = 255; - } - } - - /// - internal override void ToXyzBytes(BufferSpan sourceColor32s, BufferSpan destBytes, int count) - { - ref Color32 sourceRef = ref sourceColor32s.DangerousGetPinnableReference(); - ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - - for (int i = 0; i < count; i++) - { - ref Color32 sp = ref Unsafe.Add(ref sourceRef, i); - ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - - dp = Unsafe.As(ref sp); - } - } - - /// - internal override unsafe void PackFromXyzwBytes( - BufferSpan sourceBytes, - BufferSpan destColor32s, - int count) - { - BufferSpan.Copy(sourceBytes, destColor32s.AsBytes(), count * sizeof(Color32)); - } - - /// - internal override unsafe void ToXyzwBytes(BufferSpan sourceColor32s, BufferSpan destBytes, int count) - { - BufferSpan.Copy(sourceColor32s.AsBytes(), destBytes, count * sizeof(Color32)); - } - - /// - internal override void PackFromZyxBytes( - BufferSpan sourceBytes, - BufferSpan destColor32s, - int count) - { - ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color32 destRef = ref destColor32s.DangerousGetPinnableReference(); - - for (int i = 0; i < count; i++) - { - ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color32 dp = ref Unsafe.Add(ref destRef, i); - - Unsafe.As(ref dp) = sp.ToZyx(); - dp.A = 255; - } - } - - /// - internal override void ToZyxBytes( - BufferSpan sourceColor32s, - BufferSpan destBytes, - int count) - { - ref Color32 sourceRef = ref sourceColor32s.DangerousGetPinnableReference(); - ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - - for (int i = 0; i < count; i++) - { - ref Color32 sp = ref Unsafe.Add(ref sourceRef, i); - ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - - dp = Unsafe.As(ref sp).ToZyx(); - } - } - - /// - internal override void PackFromZyxwBytes( - BufferSpan sourceBytes, - BufferSpan destColor32s, - int count) - { - ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color32 destRef = ref destColor32s.DangerousGetPinnableReference(); - - for (int i = 0; i < count; i++) - { - ref RGBA32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color32 dp = ref Unsafe.Add(ref destRef, i); - RGBA32 zyxw = sp.ToZyxw(); - dp = Unsafe.As(ref zyxw); - } - } - - /// - internal override void ToZyxwBytes( - BufferSpan sourceColor32s, - BufferSpan destBytes, - int count) - { - ref Color32 sourceRef = ref sourceColor32s.DangerousGetPinnableReference(); - ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - - for (int i = 0; i < count; i++) - { - ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); - ref RGBA32 dp = ref Unsafe.Add(ref destRef, i); - dp = sp.ToZyxw(); - } - } - - /// - /// Helper struct to manipulate 3-byte RGB data. - /// - [StructLayout(LayoutKind.Sequential)] - private struct RGB24 - { - private byte x; - - private byte y; - - private byte z; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RGB24 ToZyx() => new RGB24 { x = this.z, y = this.y, z = this.x }; - } - - /// - /// Helper struct to manipulate 4-byte RGBA data. - /// - [StructLayout(LayoutKind.Sequential)] - private struct RGBA32 - { - private byte x; - - private byte y; - - private byte z; - - private byte w; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RGBA32 ToZyxw() => new RGBA32 { x = this.z, y = this.y, z = this.x, w = this.w }; - } - - /// - /// Value type to store -s unpacked into multiple -s. - /// - [StructLayout(LayoutKind.Sequential)] - private struct UnpackedRGBA - { - private uint r; - - private uint g; - - private uint b; - - private uint a; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Load(uint p) - { - this.r = p; - this.g = p >> GreenShift; - this.b = p >> BlueShift; - this.a = p >> AlphaShift; + ref Vector4 sp = ref Unsafe.Add(ref sourceRef, i); + ref Vector4 dp = ref Unsafe.Add(ref destRef, i); + dp = sp; } } } diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs new file mode 100644 index 000000000..5c533e87b --- /dev/null +++ b/src/ImageSharp/Colors/Color.cs @@ -0,0 +1,335 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + /// + /// Unpacked pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. + /// 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 partial struct Color : IPixel + { + /// + /// 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 backing vector for SIMD support. + /// + private Vector4 backingVector; + + /// + /// Initializes a new instance of the struct. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + public Color(byte r, byte g, byte b, byte a = 255) + : this() + { + this.backingVector = new Vector4(r, g, b, a) / MaxBytes; + } + + /// + /// Initializes a new instance of the struct. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + public Color(float r, float g, float b, float a = 1) + : this() + { + this.backingVector = new Vector4(r, g, b, a); + } + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The vector containing the components for the packed vector. + /// + public Color(Vector3 vector) + : this() + { + this.backingVector = new Vector4(vector, 1); + } + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The vector containing the components for the packed vector. + /// + public Color(Vector4 vector) + : this() + { + this.backingVector = vector; + } + + /// + /// Gets or sets the red component. + /// + public float R + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.X; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.X = value; + } + } + + /// + /// Gets or sets the green component. + /// + public float G + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.Y; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.Y = value; + } + } + + /// + /// Gets or sets the blue component. + /// + public float B + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.Z; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.Z = value; + } + } + + /// + /// Gets or sets the alpha component. + /// + public float A + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.W; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.W = 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 ==(Color left, Color right) + { + return left.backingVector == right.backingVector; + } + + /// + /// 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 !=(Color left, Color right) + { + return left.backingVector != right.backingVector; + } + + /// + /// 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 Color FromHex(string hex) + { + return ColorBuilder.FromHex(hex); + } + + /// + public BulkPixelOperations CreateBulkOperations() => new Color.BulkOperations(); + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void PackFromBytes(byte x, byte y, byte z, byte w) + { + this.backingVector = new Vector4(x, y, z, w) / MaxBytes; + } + + /// + /// Converts the value of this instance to a hexadecimal string. + /// + /// A hexadecimal string representation of the value. + public string ToHex() + { + Vector4 vector = this.backingVector * MaxBytes; + vector += Half; + uint hexOrder = (uint)((byte)vector.X << RedShift | (byte)vector.Y << GreenShift | (byte)vector.Z << BlueShift | (byte)vector.W << AlphaShift); + return hexOrder.ToString("X8"); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ToXyzBytes(byte[] bytes, int startIndex) + { + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.X; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.Z; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ToXyzwBytes(byte[] bytes, int startIndex) + { + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.X; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.Z; + bytes[startIndex + 2] = (byte)vector.W; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ToZyxBytes(byte[] bytes, int startIndex) + { + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.Z; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.X; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ToZyxwBytes(byte[] bytes, int startIndex) + { + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.Z; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.X; + bytes[startIndex + 2] = (byte)vector.W; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void PackFromVector4(Vector4 vector) + { + this.backingVector = vector; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 ToVector4() + { + return this.backingVector; + } + + /// + public override bool Equals(object obj) + { + return (obj is Color) && this.Equals((Color)obj); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(Color other) + { + return this.backingVector == other.backingVector; + } + + /// + /// 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.backingVector.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color32.BulkOperations.cs b/src/ImageSharp/Colors/Color32.BulkOperations.cs new file mode 100644 index 000000000..b86994e5d --- /dev/null +++ b/src/ImageSharp/Colors/Color32.BulkOperations.cs @@ -0,0 +1,291 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + + /// + /// Unpacked 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 partial struct Color32 + { + /// + /// implementation optimized for . + /// + internal class BulkOperations : BulkPixelOperations + { + /// + /// SIMD optimized bulk implementation of + /// that works only with `count` divisible by . + /// + /// The to the source colors. + /// The to the dstination vectors. + /// The number of pixels to convert. + /// + /// Implementation adapted from: + /// + /// http://stackoverflow.com/a/5362789 + /// + /// TODO: We can replace this implementation in the future using new Vector API-s: + /// + /// https://github.com/dotnet/corefx/issues/15957 + /// + /// + internal static unsafe void ToVector4SimdAligned(BufferSpan sourceColors, BufferSpan destVectors, int count) + { + if (!Vector.IsHardwareAccelerated) + { + throw new InvalidOperationException( + "Color32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); + } + + int vecSize = Vector.Count; + + DebugGuard.IsTrue( + count % vecSize == 0, + nameof(count), + "Argument 'count' should divisible by Vector.Count!"); + + Vector bVec = new Vector(256.0f / 255.0f); + Vector magicFloat = new Vector(32768.0f); + Vector magicInt = new Vector(1191182336); // reinterpreded value of 32768.0f + Vector mask = new Vector(255); + + int unpackedRawCount = count * 4; + + ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); + + using (Buffer tempBuf = new Buffer( + unpackedRawCount + Vector.Count)) + { + uint[] temp = tempBuf.Array; + float[] fTemp = Unsafe.As(temp); + + ref UnpackedRGBA tempBase = ref Unsafe.As(ref tempBuf[0]); + + for (int i = 0; i < count; i++) + { + uint sVal = Unsafe.Add(ref src, i); + ref UnpackedRGBA dst = ref Unsafe.Add(ref tempBase, i); + + // This call is the bottleneck now: + dst.Load(sVal); + } + + for (int i = 0; i < unpackedRawCount; i += vecSize) + { + Vector vi = new Vector(temp, i); + + vi &= mask; + vi |= magicInt; + + Vector vf = Vector.AsVectorSingle(vi); + vf = (vf - magicFloat) * bVec; + vf.CopyTo(fTemp, i); + } + + BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint)); + } + } + + /// + internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + { + if (count < 256 || !Vector.IsHardwareAccelerated) + { + // Doesn't worth to bother with SIMD: + base.ToVector4(sourceColors, destVectors, count); + return; + } + + int remainder = count % Vector.Count; + + int alignedCount = count - remainder; + + if (alignedCount > 0) + { + ToVector4SimdAligned(sourceColors, destVectors, alignedCount); + } + + if (remainder > 0) + { + sourceColors = sourceColors.Slice(alignedCount); + destVectors = destVectors.Slice(alignedCount); + base.ToVector4(sourceColors, destVectors, remainder); + } + } + + /// + internal override void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color32 destRef = ref destColors.DangerousGetPinnableReference(); + + for (int i = 0; i < count; i++) + { + ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color32 dp = ref Unsafe.Add(ref destRef, i); + + Unsafe.As(ref dp) = sp; + dp.A = 255; + } + } + + /// + internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + ref Color32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); + + for (int i = 0; i < count; i++) + { + ref Color32 sp = ref Unsafe.Add(ref sourceRef, i); + ref RGB24 dp = ref Unsafe.Add(ref destRef, i); + + dp = Unsafe.As(ref sp); + } + } + + /// + internal override unsafe void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color32)); + } + + /// + internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Color32)); + } + + /// + internal override void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color32 destRef = ref destColors.DangerousGetPinnableReference(); + + for (int i = 0; i < count; i++) + { + ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color32 dp = ref Unsafe.Add(ref destRef, i); + + Unsafe.As(ref dp) = sp.ToZyx(); + dp.A = 255; + } + } + + /// + internal override void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + ref Color32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); + + for (int i = 0; i < count; i++) + { + ref Color32 sp = ref Unsafe.Add(ref sourceRef, i); + ref RGB24 dp = ref Unsafe.Add(ref destRef, i); + + dp = Unsafe.As(ref sp).ToZyx(); + } + } + + /// + internal override void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color32 destRef = ref destColors.DangerousGetPinnableReference(); + + for (int i = 0; i < count; i++) + { + ref RGBA32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color32 dp = ref Unsafe.Add(ref destRef, i); + RGBA32 zyxw = sp.ToZyxw(); + dp = Unsafe.As(ref zyxw); + } + } + + /// + internal override void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + ref Color32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); + + for (int i = 0; i < count; i++) + { + ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); + ref RGBA32 dp = ref Unsafe.Add(ref destRef, i); + dp = sp.ToZyxw(); + } + } + + /// + /// Helper struct to manipulate 3-byte RGB data. + /// + [StructLayout(LayoutKind.Sequential)] + private struct RGB24 + { + private byte x; + + private byte y; + + private byte z; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RGB24 ToZyx() => new RGB24 { x = this.z, y = this.y, z = this.x }; + } + + /// + /// Helper struct to manipulate 4-byte RGBA data. + /// + [StructLayout(LayoutKind.Sequential)] + private struct RGBA32 + { + private byte x; + + private byte y; + + private byte z; + + private byte w; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RGBA32 ToZyxw() => new RGBA32 { x = this.z, y = this.y, z = this.x, w = this.w }; + } + + /// + /// Value type to store -s unpacked into multiple -s. + /// + [StructLayout(LayoutKind.Sequential)] + private struct UnpackedRGBA + { + private uint r; + + private uint g; + + private uint b; + + private uint a; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Load(uint p) + { + this.r = p; + this.g = p >> GreenShift; + this.b = p >> BlueShift; + this.a = p >> AlphaShift; + } + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color32.Transforms.cs b/src/ImageSharp/Colors/Color32.Transforms.cs index 43c947b8b..935b04217 100644 --- a/src/ImageSharp/Colors/Color32.Transforms.cs +++ b/src/ImageSharp/Colors/Color32.Transforms.cs @@ -8,7 +8,7 @@ namespace ImageSharp using System.Numerics; /// - /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. + /// Unpacked 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/Color32.cs b/src/ImageSharp/Colors/Color32.cs index f7f1aceec..d646b9c4c 100644 --- a/src/ImageSharp/Colors/Color32.cs +++ b/src/ImageSharp/Colors/Color32.cs @@ -10,7 +10,7 @@ namespace ImageSharp using System.Runtime.InteropServices; /// - /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. + /// Unpacked 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/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index ec713f915..2c767386c 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Colors.Spaces; /// - /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. + /// Unpacked 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/BulkPixelOperations{TColor}.cs b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs index ccb1c2261..db0251703 100644 --- a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs +++ b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs @@ -27,10 +27,7 @@ namespace ImageSharp /// The to the source vectors. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromVector4( - BufferSpan sourceVectors, - BufferSpan destColors, - int count) + internal virtual void PackFromVector4(BufferSpan sourceVectors, BufferSpan destColors, int count) { ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference(); @@ -49,10 +46,7 @@ namespace ImageSharp /// The to the source colors. /// The to the destination vectors. /// The number of pixels to convert. - internal virtual void ToVector4( - BufferSpan sourceColors, - BufferSpan destVectors, - int count) + internal virtual void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) { ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); @@ -71,10 +65,7 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromXyzBytes( - BufferSpan sourceBytes, - BufferSpan destColors, - int count) + internal virtual void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference(); @@ -115,10 +106,7 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromXyzwBytes( - BufferSpan sourceBytes, - BufferSpan destColors, - int count) + internal virtual void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference(); @@ -141,10 +129,7 @@ namespace ImageSharp /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - internal virtual void ToXyzwBytes( - BufferSpan sourceColors, - BufferSpan destBytes, - int count) + internal virtual void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; @@ -162,10 +147,7 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromZyxBytes( - BufferSpan sourceBytes, - BufferSpan destColors, - int count) + internal virtual void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference(); @@ -206,10 +188,7 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromZyxwBytes( - BufferSpan sourceBytes, - BufferSpan destColors, - int count) + internal virtual void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference(); @@ -232,10 +211,7 @@ namespace ImageSharp /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - internal virtual void ToZyxwBytes( - BufferSpan sourceColors, - BufferSpan destBytes, - int count) + internal virtual void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 04570ce8f..c82990134 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreSize = ImageSharp.Size; using CoreImage = ImageSharp.Image; + using CoreVectorImage = ImageSharp.Image; public class Resize : BenchmarkBase { @@ -44,6 +45,16 @@ namespace ImageSharp.Benchmarks } } + [Benchmark(Description = "ImageSharp Vector Resize")] + public CoreSize ResizeCoreVector() + { + using (CoreVectorImage image = new CoreVectorImage(2000, 2000)) + { + image.Resize(400, 400); + return new CoreSize(image.Width, image.Height); + } + } + [Benchmark(Description = "ImageSharp Compand Resize")] public CoreSize ResizeCoreCompand() { @@ -53,5 +64,15 @@ namespace ImageSharp.Benchmarks return new CoreSize(image.Width, image.Height); } } + + [Benchmark(Description = "ImageSharp Vector Compand Resize")] + public CoreSize ResizeCoreVectorCompand() + { + using (CoreVectorImage image = new CoreVectorImage(2000, 2000)) + { + image.Resize(400, 400, true); + return new CoreSize(image.Width, image.Height); + } + } } } From fdfe5ed0b4b289439f19f6a8a4253fb2e0195210 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Mon, 17 Apr 2017 09:41:52 +0100 Subject: [PATCH 22/34] bump version number and SixLabor.* dependencies The dependencies APIs had breaking changes and bumping the package version will force devs onto all the latest packages. --- src/ImageSharp.Drawing/ImageSharp.Drawing.csproj | 6 +++--- src/ImageSharp.Drawing/Text/GlyphBuilder.cs | 3 ++- src/ImageSharp/ImageSharp.csproj | 2 +- tests/ImageSharp.Tests/Drawing/Text/GlyphBuilder.cs | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index 8ba0cbdd0..c4515db37 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -2,7 +2,7 @@ An extension to ImageSharp that allows the drawing of images, paths, and text. ImageSharp.Drawing - 1.0.0-alpha5 + 1.0.0-alpha6 James Jackson-South and contributors netstandard1.1 true @@ -39,8 +39,8 @@ All - - + + ..\..\ImageSharp.ruleset diff --git a/src/ImageSharp.Drawing/Text/GlyphBuilder.cs b/src/ImageSharp.Drawing/Text/GlyphBuilder.cs index ac5d01de7..0033a608c 100644 --- a/src/ImageSharp.Drawing/Text/GlyphBuilder.cs +++ b/src/ImageSharp.Drawing/Text/GlyphBuilder.cs @@ -48,7 +48,8 @@ namespace ImageSharp.Drawing /// /// Begins the glyph. /// - void IGlyphRenderer.BeginGlyph() + /// The offset that the glyph will be rendered at. + void IGlyphRenderer.BeginGlyph(Vector2 location) { this.builder.Clear(); } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index c51c0833a..a19bed604 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp - 1.0.0-alpha5 + 1.0.0-alpha6 James Jackson-South and contributors netstandard1.3;netstandard1.1 true diff --git a/tests/ImageSharp.Tests/Drawing/Text/GlyphBuilder.cs b/tests/ImageSharp.Tests/Drawing/Text/GlyphBuilder.cs index c7121695e..7f16f30bb 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/GlyphBuilder.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/GlyphBuilder.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Drawing.Text GlyphBuilder fullBuilder = new GlyphBuilder(new System.Numerics.Vector2(10, 99)); IGlyphRenderer builder = fullBuilder; - builder.BeginGlyph(); + builder.BeginGlyph(Vector2.Zero); builder.BeginFigure(); builder.MoveTo(new Vector2(0, 0)); builder.LineTo(new Vector2(0, 10)); // becomes 0, -10 @@ -52,7 +52,7 @@ namespace ImageSharp.Tests.Drawing.Text IGlyphRenderer builder = fullBuilder; for (int i = 0; i < 10; i++) { - builder.BeginGlyph(); + builder.BeginGlyph(Vector2.Zero); builder.BeginFigure(); builder.MoveTo(new Vector2(0, 0)); builder.LineTo(new Vector2(0, 10)); // becomes 0, -10 From 292bc4db9e8dd0006edd1a317d408a6a31764df0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 17 Apr 2017 21:08:49 +1000 Subject: [PATCH 23/34] Rename to Color and ColorVector --- src/ImageSharp.Drawing/Brushes/Brushes.cs | 60 +- src/ImageSharp.Drawing/Brushes/ImageBrush.cs | 6 +- .../Brushes/PatternBrush.cs | 8 +- .../Brushes/RecolorBrush.cs | 4 +- src/ImageSharp.Drawing/Brushes/SolidBrush.cs | 6 +- src/ImageSharp.Drawing/Pens/Pen.cs | 12 +- src/ImageSharp.Drawing/Pens/Pens.cs | 20 +- src/ImageSharp/Colors/Color.BulkOperations.cs | 268 ++++++- src/ImageSharp/Colors/Color.Definitions.cs | 728 ++++++++++++++++++ ...or32.Transforms.cs => Color.Transforms.cs} | 66 +- src/ImageSharp/Colors/Color.cs | 247 +++--- .../Colors/Color32.BulkOperations.cs | 291 ------- src/ImageSharp/Colors/Color32Constants.cs | 179 ----- src/ImageSharp/Colors/Color32Definitions.cs | 728 ------------------ src/ImageSharp/Colors/ColorConstants.cs | 179 +++++ .../Colors/ColorVector.BulkOperations.cs | 27 + .../Colors/ColorVector.Definitions.cs | 728 ++++++++++++++++++ .../Colors/{Color32.cs => ColorVector.cs} | 295 ++++--- src/ImageSharp/Colors/ColorspaceTransforms.cs | 60 +- src/ImageSharp/Colors/ComponentOrder.cs | 8 +- src/ImageSharp/Colors/NamedColors{TColor}.cs | 286 +++---- src/ImageSharp/Colors/PackedPixel/IPixel.cs | 8 +- .../PackedPixel/PackedPixelConverterHelper.cs | 2 +- src/ImageSharp/Colors/Spaces/Bgra32.cs | 6 +- src/ImageSharp/Colors/Spaces/CieLab.cs | 6 +- src/ImageSharp/Colors/Spaces/CieXyz.cs | 6 +- src/ImageSharp/Colors/Spaces/Cmyk.cs | 4 +- src/ImageSharp/Colors/Spaces/Hsl.cs | 6 +- src/ImageSharp/Colors/Spaces/Hsv.cs | 6 +- src/ImageSharp/Colors/Spaces/YCbCr.cs | 6 +- .../Common/Extensions/Vector4Extensions.cs | 2 +- src/ImageSharp/Image.Create.cs | 6 +- src/ImageSharp/Image.FromFile.cs | 2 +- src/ImageSharp/Image.FromStream.cs | 4 +- src/ImageSharp/Image.cs | 4 +- .../ColorMatrix/ColorMatrixProcessor.cs | 2 +- src/ImageSharp/Quantizers/PaletteQuantizer.cs | 2 +- .../Bulk/PackFromVector4ReferenceVsPointer.cs | 10 +- .../Color/Bulk/PackFromXyzw.cs | 4 +- .../Color/Bulk/ToVector4.cs | 2 +- .../ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 4 +- .../Color/Bulk/ToXyzw.cs | 4 +- .../Color/ColorEquality.cs | 2 +- .../Drawing/DrawBeziers.cs | 2 +- .../Drawing/DrawLines.cs | 2 +- .../Drawing/DrawPolygon.cs | 2 +- .../Drawing/FillPolygon.cs | 2 +- .../Drawing/FillRectangle.cs | 2 +- .../Drawing/FillWithPattern.cs | 2 +- .../General/ClearBuffer.cs | 6 +- .../ImageSharp.Benchmarks/Image/CopyPixels.cs | 2 +- .../Image/EncodeIndexedPng.cs | 10 +- .../ImageSharp.Benchmarks/Image/EncodePng.cs | 8 +- .../Image/GetSetPixel.cs | 2 +- .../ImageSharp.Benchmarks/Samplers/Resize.cs | 2 +- .../Colors/BulkPixelOperationsTests.cs | 12 +- .../Colors/ColorConversionTests.cs | 106 +-- .../Colors/ColorDefinitionTests.cs | 10 +- tests/ImageSharp.Tests/Colors/ColorTests.cs | 36 +- .../Colors/ColorTransformTests.cs | 58 +- .../Common/BufferSpanTests.cs | 6 +- .../Common/PixelDataPoolTests.cs | 8 +- .../ImageSharp.Tests/Drawing/BeziersTests.cs | 32 +- .../ImageSharp.Tests/Drawing/DrawPathTests.cs | 22 +- .../Drawing/FillPatternTests.cs | 176 ++--- .../Drawing/FillRegionProcessorTests.cs | 4 +- .../Drawing/FillSolidBrushTests.cs | 26 +- .../Drawing/LineComplexPolygonTests.cs | 80 +- tests/ImageSharp.Tests/Drawing/LineTests.cs | 64 +- .../Drawing/Paths/DrawBeziersTests.cs | 30 +- .../Drawing/Paths/DrawLinesTests.cs | 30 +- .../Drawing/Paths/DrawPath.cs | 30 +- .../Drawing/Paths/DrawPolygon.cs | 30 +- .../Drawing/Paths/DrawRectangle.cs | 30 +- .../Drawing/Paths/FillPath.cs | 16 +- .../Drawing/Paths/FillPolygon.cs | 16 +- .../Drawing/Paths/FillRectangle.cs | 16 +- .../Drawing/Paths/ProcessorWatchingImage.cs | 8 +- .../ImageSharp.Tests/Drawing/PolygonTests.cs | 42 +- .../Drawing/RecolorImageTest.cs | 4 +- .../Drawing/SolidBezierTests.cs | 22 +- .../Drawing/SolidComplexPolygonTests.cs | 30 +- .../Drawing/SolidPolygonTests.cs | 76 +- .../ImageSharp.Tests/Drawing/Text/DrawText.cs | 86 +-- .../Drawing/Text/OutputText.cs | 4 +- .../Formats/Jpg/JpegProfilingBenchmarks.cs | 6 +- .../ImageSharp.Tests/Image/ImageLoadTests.cs | 100 +-- .../ImageSharp.Tests/Image/ImageSaveTests.cs | 24 +- .../Image/PixelAccessorTests.cs | 16 +- .../Profiles/Exif/ExifProfileTests.cs | 2 +- .../Processors/Filters/BackgroundColorTest.cs | 2 +- .../Processors/Filters/GlowTest.cs | 2 +- .../Filters/ResizeProfilingBenchmarks.cs | 6 +- .../Processors/Filters/VignetteTest.cs | 2 +- .../TestUtilities/Factories/ImageFactory.cs | 8 +- .../ImageProviders/TestPatternProvider.cs | 6 +- .../TestUtilities/TestUtilityExtensions.cs | 8 +- .../Tests/TestImageProviderTests.cs | 4 +- .../Tests/TestUtilityExtensionsTests.cs | 18 +- 99 files changed, 3189 insertions(+), 2471 deletions(-) create mode 100644 src/ImageSharp/Colors/Color.Definitions.cs rename src/ImageSharp/Colors/{Color32.Transforms.cs => Color.Transforms.cs} (82%) delete mode 100644 src/ImageSharp/Colors/Color32.BulkOperations.cs delete mode 100644 src/ImageSharp/Colors/Color32Constants.cs delete mode 100644 src/ImageSharp/Colors/Color32Definitions.cs create mode 100644 src/ImageSharp/Colors/ColorConstants.cs create mode 100644 src/ImageSharp/Colors/ColorVector.BulkOperations.cs create mode 100644 src/ImageSharp/Colors/ColorVector.Definitions.cs rename src/ImageSharp/Colors/{Color32.cs => ColorVector.cs} (50%) diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs index 5912dbd51..e8269848c 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs @@ -6,7 +6,7 @@ namespace ImageSharp.Drawing.Brushes { /// - /// A collection of methods for creating brushes. Brushes use for painting. + /// A collection of methods for creating brushes. Brushes use for painting. /// public class Brushes { @@ -15,7 +15,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// A Brush - public static SolidBrush Solid(Color32 color) + public static SolidBrush Solid(Color color) => new SolidBrush(color); /// @@ -24,8 +24,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Percent10(Color32 foreColor) - => new PatternBrush(Brushes.Percent10(foreColor, Color32.Transparent)); + public static PatternBrush Percent10(Color foreColor) + => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Percent10 Hatch Pattern with @@ -34,8 +34,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent10(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.Percent10(foreColor, backColor)); + public static PatternBrush Percent10(Color foreColor, Color backColor) + => new PatternBrush(Brushes.Percent10(foreColor, backColor)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -43,8 +43,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Percent20(Color32 foreColor) - => new PatternBrush(Brushes.Percent20(foreColor, Color32.Transparent)); + public static PatternBrush Percent20(Color foreColor) + => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -53,8 +53,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent20(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.Percent20(foreColor, backColor)); + public static PatternBrush Percent20(Color foreColor, Color backColor) + => new PatternBrush(Brushes.Percent20(foreColor, backColor)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -62,8 +62,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Horizontal(Color32 foreColor) - => new PatternBrush(Brushes.Horizontal(foreColor, Color32.Transparent)); + public static PatternBrush Horizontal(Color foreColor) + => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -72,8 +72,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Horizontal(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); + public static PatternBrush Horizontal(Color foreColor, Color backColor) + => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -81,8 +81,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Min(Color32 foreColor) - => new PatternBrush(Brushes.Min(foreColor, Color32.Transparent)); + public static PatternBrush Min(Color foreColor) + => new PatternBrush(Brushes.Min(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -91,8 +91,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Min(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.Min(foreColor, backColor)); + public static PatternBrush Min(Color foreColor, Color backColor) + => new PatternBrush(Brushes.Min(foreColor, backColor)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -100,8 +100,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Vertical(Color32 foreColor) - => new PatternBrush(Brushes.Vertical(foreColor, Color32.Transparent)); + public static PatternBrush Vertical(Color foreColor) + => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -110,8 +110,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Vertical(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.Vertical(foreColor, backColor)); + public static PatternBrush Vertical(Color foreColor, Color backColor) + => new PatternBrush(Brushes.Vertical(foreColor, backColor)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -119,8 +119,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush ForwardDiagonal(Color32 foreColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color32.Transparent)); + public static PatternBrush ForwardDiagonal(Color foreColor) + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -129,8 +129,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush ForwardDiagonal(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); + public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -138,8 +138,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush BackwardDiagonal(Color32 foreColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color32.Transparent)); + public static PatternBrush BackwardDiagonal(Color foreColor) + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -148,7 +148,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush BackwardDiagonal(Color32 foreColor, Color32 backColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); + public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs index 9ffd7e42b..a7124bfe8 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs @@ -6,15 +6,15 @@ namespace ImageSharp.Drawing.Brushes { /// - /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. + /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. /// - public class ImageBrush : ImageBrush + public class ImageBrush : ImageBrush { /// /// Initializes a new instance of the class. /// /// The image to paint. - public ImageBrush(IImageBase image) + public ImageBrush(IImageBase image) : base(image) { } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs index 027029718..5093a7df0 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs @@ -6,9 +6,9 @@ namespace ImageSharp.Drawing.Brushes { /// - /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. + /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. /// - public class PatternBrush : PatternBrush + public class PatternBrush : PatternBrush { /// /// Initializes a new instance of the class. @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the fore. /// Color of the back. /// The pattern. - public PatternBrush(Color32 foreColor, Color32 backColor, bool[,] pattern) + public PatternBrush(Color foreColor, Color backColor, bool[,] pattern) : base(foreColor, backColor, pattern) { } @@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Brushes /// Initializes a new instance of the class. /// /// The brush. - internal PatternBrush(PatternBrush brush) + internal PatternBrush(PatternBrush brush) : base(brush) { } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs index fce052cb8..0452a3f01 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Drawing.Brushes /// /// Provides an implementation of a recolor brush for painting color changes. /// - public class RecolorBrush : RecolorBrush + public class RecolorBrush : RecolorBrush { /// /// Initializes a new instance of the class. @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the source. /// Color of the target. /// The threshold. - public RecolorBrush(Color32 sourceColor, Color32 targetColor, float threshold) + public RecolorBrush(Color sourceColor, Color targetColor, float threshold) : base(sourceColor, targetColor, threshold) { } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs index 93e2af6a4..123d8a7e3 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs @@ -6,15 +6,15 @@ namespace ImageSharp.Drawing.Brushes { /// - /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. + /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. /// - public class SolidBrush : SolidBrush + public class SolidBrush : SolidBrush { /// /// Initializes a new instance of the class. /// /// The color. - public SolidBrush(Color32 color) + public SolidBrush(Color color) : base(color) { } diff --git a/src/ImageSharp.Drawing/Pens/Pen.cs b/src/ImageSharp.Drawing/Pens/Pen.cs index 1b75c38b7..09fe89419 100644 --- a/src/ImageSharp.Drawing/Pens/Pen.cs +++ b/src/ImageSharp.Drawing/Pens/Pen.cs @@ -6,16 +6,16 @@ namespace ImageSharp.Drawing.Pens { /// - /// Represents a in the color space. + /// Represents a in the color space. /// - public class Pen : Pen + public class Pen : Pen { /// /// Initializes a new instance of the class. /// /// The color. /// The width. - public Pen(Color32 color, float width) + public Pen(Color color, float width) : base(color, width) { } @@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Pens /// /// The brush. /// The width. - public Pen(IBrush brush, float width) + public Pen(IBrush brush, float width) : base(brush, width) { } @@ -36,7 +36,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) + public Pen(IBrush brush, float width, float[] pattern) : base(brush, width, pattern) { } @@ -45,7 +45,7 @@ namespace ImageSharp.Drawing.Pens /// Initializes a new instance of the class. /// /// The pen. - internal Pen(Pen pen) + internal Pen(Pen pen) : base(pen) { } diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Pens/Pens.cs index b45695ceb..039b7113f 100644 --- a/src/ImageSharp.Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Pens/Pens.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Solid(Color32 color, float width) => new Pen(color, width); + public static Pen Solid(Color color, float width) => new Pen(color, width); /// /// Create a solid pen with out any drawing patterns @@ -24,7 +24,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); + public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); /// /// Create a pen with a 'Dash' drawing patterns @@ -32,7 +32,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dash(Color32 color, float width) => new Pen(Pens.Dash(color, width)); + public static Pen Dash(Color color, float width) => new Pen(Pens.Dash(color, width)); /// /// Create a pen with a 'Dash' drawing patterns @@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); + public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -48,7 +48,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dot(Color32 color, float width) => new Pen(Pens.Dot(color, width)); + public static Pen Dot(Color color, float width) => new Pen(Pens.Dot(color, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -56,7 +56,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); + public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -64,7 +64,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDot(Color32 color, float width) => new Pen(Pens.DashDot(color, width)); + public static Pen DashDot(Color color, float width) => new Pen(Pens.DashDot(color, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -72,7 +72,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); + public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -80,7 +80,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDotDot(Color32 color, float width) => new Pen(Pens.DashDotDot(color, width)); + public static Pen DashDotDot(Color color, float width) => new Pen(Pens.DashDotDot(color, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -88,6 +88,6 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); + public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 671578e4c..2de8222d6 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -1,11 +1,17 @@ -namespace ImageSharp +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp { using System; using System.Numerics; using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; /// - /// Unpacked pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. + /// Unpacked 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. /// /// @@ -19,17 +25,265 @@ /// internal class BulkOperations : BulkPixelOperations { + /// + /// SIMD optimized bulk implementation of + /// that works only with `count` divisible by . + /// + /// The to the source colors. + /// The to the dstination vectors. + /// The number of pixels to convert. + /// + /// Implementation adapted from: + /// + /// http://stackoverflow.com/a/5362789 + /// + /// TODO: We can replace this implementation in the future using new Vector API-s: + /// + /// https://github.com/dotnet/corefx/issues/15957 + /// + /// + internal static unsafe void ToVector4SimdAligned(BufferSpan sourceColors, BufferSpan destVectors, int count) + { + if (!Vector.IsHardwareAccelerated) + { + throw new InvalidOperationException( + "Color32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); + } + + int vecSize = Vector.Count; + + DebugGuard.IsTrue( + count % vecSize == 0, + nameof(count), + "Argument 'count' should divisible by Vector.Count!"); + + Vector bVec = new Vector(256.0f / 255.0f); + Vector magicFloat = new Vector(32768.0f); + Vector magicInt = new Vector(1191182336); // reinterpreded value of 32768.0f + Vector mask = new Vector(255); + + int unpackedRawCount = count * 4; + + ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); + + using (Buffer tempBuf = new Buffer( + unpackedRawCount + Vector.Count)) + { + uint[] temp = tempBuf.Array; + float[] fTemp = Unsafe.As(temp); + + ref UnpackedRGBA tempBase = ref Unsafe.As(ref tempBuf[0]); + + for (int i = 0; i < count; i++) + { + uint sVal = Unsafe.Add(ref src, i); + ref UnpackedRGBA dst = ref Unsafe.Add(ref tempBase, i); + + // This call is the bottleneck now: + dst.Load(sVal); + } + + for (int i = 0; i < unpackedRawCount; i += vecSize) + { + Vector vi = new Vector(temp, i); + + vi &= mask; + vi |= magicInt; + + Vector vf = Vector.AsVectorSingle(vi); + vf = (vf - magicFloat) * bVec; + vf.CopyTo(fTemp, i); + } + + BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint)); + } + } + /// internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) { - ref Vector4 sourceRef = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); - ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); + if (count < 256 || !Vector.IsHardwareAccelerated) + { + // Doesn't worth to bother with SIMD: + base.ToVector4(sourceColors, destVectors, count); + return; + } + + int remainder = count % Vector.Count; + + int alignedCount = count - remainder; + + if (alignedCount > 0) + { + ToVector4SimdAligned(sourceColors, destVectors, alignedCount); + } + + if (remainder > 0) + { + sourceColors = sourceColors.Slice(alignedCount); + destVectors = destVectors.Slice(alignedCount); + base.ToVector4(sourceColors, destVectors, remainder); + } + } + + /// + internal override void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - ref Vector4 sp = ref Unsafe.Add(ref sourceRef, i); - ref Vector4 dp = ref Unsafe.Add(ref destRef, i); - dp = sp; + ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color dp = ref Unsafe.Add(ref destRef, i); + + Unsafe.As(ref dp) = sp; + dp.A = 255; + } + } + + /// + internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); + + for (int i = 0; i < count; i++) + { + ref Color sp = ref Unsafe.Add(ref sourceRef, i); + ref RGB24 dp = ref Unsafe.Add(ref destRef, i); + + dp = Unsafe.As(ref sp); + } + } + + /// + internal override unsafe void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color)); + } + + /// + internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Color)); + } + + /// + internal override void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color destRef = ref destColors.DangerousGetPinnableReference(); + + for (int i = 0; i < count; i++) + { + ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color dp = ref Unsafe.Add(ref destRef, i); + + Unsafe.As(ref dp) = sp.ToZyx(); + dp.A = 255; + } + } + + /// + internal override void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); + + for (int i = 0; i < count; i++) + { + ref Color sp = ref Unsafe.Add(ref sourceRef, i); + ref RGB24 dp = ref Unsafe.Add(ref destRef, i); + + dp = Unsafe.As(ref sp).ToZyx(); + } + } + + /// + internal override void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + { + ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); + ref Color destRef = ref destColors.DangerousGetPinnableReference(); + + for (int i = 0; i < count; i++) + { + ref RGBA32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Color dp = ref Unsafe.Add(ref destRef, i); + RGBA32 zyxw = sp.ToZyxw(); + dp = Unsafe.As(ref zyxw); + } + } + + /// + internal override void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + { + ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); + + for (int i = 0; i < count; i++) + { + ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); + ref RGBA32 dp = ref Unsafe.Add(ref destRef, i); + dp = sp.ToZyxw(); + } + } + + /// + /// Helper struct to manipulate 3-byte RGB data. + /// + [StructLayout(LayoutKind.Sequential)] + private struct RGB24 + { + private byte x; + + private byte y; + + private byte z; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RGB24 ToZyx() => new RGB24 { x = this.z, y = this.y, z = this.x }; + } + + /// + /// Helper struct to manipulate 4-byte RGBA data. + /// + [StructLayout(LayoutKind.Sequential)] + private struct RGBA32 + { + private byte x; + + private byte y; + + private byte z; + + private byte w; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RGBA32 ToZyxw() => new RGBA32 { x = this.z, y = this.y, z = this.x, w = this.w }; + } + + /// + /// Value type to store -s unpacked into multiple -s. + /// + [StructLayout(LayoutKind.Sequential)] + private struct UnpackedRGBA + { + private uint r; + + private uint g; + + private uint b; + + private uint a; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Load(uint p) + { + this.r = p; + this.g = p >> GreenShift; + this.b = p >> BlueShift; + this.a = p >> AlphaShift; } } } diff --git a/src/ImageSharp/Colors/Color.Definitions.cs b/src/ImageSharp/Colors/Color.Definitions.cs new file mode 100644 index 000000000..4bc0d486a --- /dev/null +++ b/src/ImageSharp/Colors/Color.Definitions.cs @@ -0,0 +1,728 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + /// + /// Packed vector 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 partial struct Color + { + /// + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// + public static readonly Color AliceBlue = NamedColors.AliceBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// + public static readonly Color AntiqueWhite = NamedColors.AntiqueWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly Color Aqua = NamedColors.Aqua; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// + public static readonly Color Aquamarine = NamedColors.Aquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// + public static readonly Color Azure = NamedColors.Azure; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// + public static readonly Color Beige = NamedColors.Beige; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// + public static readonly Color Bisque = NamedColors.Bisque; + + /// + /// Represents a matching the W3C definition that has an hex value of #000000. + /// + public static readonly Color Black = NamedColors.Black; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// + public static readonly Color BlanchedAlmond = NamedColors.BlanchedAlmond; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// + public static readonly Color Blue = NamedColors.Blue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// + public static readonly Color BlueViolet = NamedColors.BlueViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// + public static readonly Color Brown = NamedColors.Brown; + + /// + /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// + public static readonly Color BurlyWood = NamedColors.BurlyWood; + + /// + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// + public static readonly Color CadetBlue = NamedColors.CadetBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// + public static readonly Color Chartreuse = NamedColors.Chartreuse; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// + public static readonly Color Chocolate = NamedColors.Chocolate; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// + public static readonly Color Coral = NamedColors.Coral; + + /// + /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// + public static readonly Color CornflowerBlue = NamedColors.CornflowerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// + public static readonly Color Cornsilk = NamedColors.Cornsilk; + + /// + /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// + public static readonly Color Crimson = NamedColors.Crimson; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly Color Cyan = NamedColors.Cyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #00008B. + /// + public static readonly Color DarkBlue = NamedColors.DarkBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// + public static readonly Color DarkCyan = NamedColors.DarkCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// + public static readonly Color DarkGoldenrod = NamedColors.DarkGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// + public static readonly Color DarkGray = NamedColors.DarkGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #006400. + /// + public static readonly Color DarkGreen = NamedColors.DarkGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// + public static readonly Color DarkKhaki = NamedColors.DarkKhaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// + public static readonly Color DarkMagenta = NamedColors.DarkMagenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// + public static readonly Color DarkOliveGreen = NamedColors.DarkOliveGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// + public static readonly Color DarkOrange = NamedColors.DarkOrange; + + /// + /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// + public static readonly Color DarkOrchid = NamedColors.DarkOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// + public static readonly Color DarkRed = NamedColors.DarkRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// + public static readonly Color DarkSalmon = NamedColors.DarkSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// + public static readonly Color DarkSeaGreen = NamedColors.DarkSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// + public static readonly Color DarkSlateBlue = NamedColors.DarkSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// + public static readonly Color DarkSlateGray = NamedColors.DarkSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// + public static readonly Color DarkTurquoise = NamedColors.DarkTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// + public static readonly Color DarkViolet = NamedColors.DarkViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// + public static readonly Color DeepPink = NamedColors.DeepPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// + public static readonly Color DeepSkyBlue = NamedColors.DeepSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #696969. + /// + public static readonly Color DimGray = NamedColors.DimGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// + public static readonly Color DodgerBlue = NamedColors.DodgerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #B22222. + /// + public static readonly Color Firebrick = NamedColors.Firebrick; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// + public static readonly Color FloralWhite = NamedColors.FloralWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #228B22. + /// + public static readonly Color ForestGreen = NamedColors.ForestGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly Color Fuchsia = NamedColors.Fuchsia; + + /// + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// + public static readonly Color Gainsboro = NamedColors.Gainsboro; + + /// + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// + public static readonly Color GhostWhite = NamedColors.GhostWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// + public static readonly Color Gold = NamedColors.Gold; + + /// + /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// + public static readonly Color Goldenrod = NamedColors.Goldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #808080. + /// + public static readonly Color Gray = NamedColors.Gray; + + /// + /// Represents a matching the W3C definition that has an hex value of #008000. + /// + public static readonly Color Green = NamedColors.Green; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// + public static readonly Color GreenYellow = NamedColors.GreenYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// + public static readonly Color Honeydew = NamedColors.Honeydew; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// + public static readonly Color HotPink = NamedColors.HotPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// + public static readonly Color IndianRed = NamedColors.IndianRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// + public static readonly Color Indigo = NamedColors.Indigo; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// + public static readonly Color Ivory = NamedColors.Ivory; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// + public static readonly Color Khaki = NamedColors.Khaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// + public static readonly Color Lavender = NamedColors.Lavender; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// + public static readonly Color LavenderBlush = NamedColors.LavenderBlush; + + /// + /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// + public static readonly Color LawnGreen = NamedColors.LawnGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// + public static readonly Color LemonChiffon = NamedColors.LemonChiffon; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// + public static readonly Color LightBlue = NamedColors.LightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F08080. + /// + public static readonly Color LightCoral = NamedColors.LightCoral; + + /// + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// + public static readonly Color LightCyan = NamedColors.LightCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// + public static readonly Color LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// + public static readonly Color LightGray = NamedColors.LightGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// + public static readonly Color LightGreen = NamedColors.LightGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// + public static readonly Color LightPink = NamedColors.LightPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// + public static readonly Color LightSalmon = NamedColors.LightSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// + public static readonly Color LightSeaGreen = NamedColors.LightSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// + public static readonly Color LightSkyBlue = NamedColors.LightSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #778899. + /// + public static readonly Color LightSlateGray = NamedColors.LightSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// + public static readonly Color LightSteelBlue = NamedColors.LightSteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// + public static readonly Color LightYellow = NamedColors.LightYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// + public static readonly Color Lime = NamedColors.Lime; + + /// + /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// + public static readonly Color LimeGreen = NamedColors.LimeGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// + public static readonly Color Linen = NamedColors.Linen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly Color Magenta = NamedColors.Magenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #800000. + /// + public static readonly Color Maroon = NamedColors.Maroon; + + /// + /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// + public static readonly Color MediumAquamarine = NamedColors.MediumAquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// + public static readonly Color MediumBlue = NamedColors.MediumBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// + public static readonly Color MediumOrchid = NamedColors.MediumOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// + public static readonly Color MediumPurple = NamedColors.MediumPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// + public static readonly Color MediumSeaGreen = NamedColors.MediumSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// + public static readonly Color MediumSlateBlue = NamedColors.MediumSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// + public static readonly Color MediumSpringGreen = NamedColors.MediumSpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// + public static readonly Color MediumTurquoise = NamedColors.MediumTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #C71585. + /// + public static readonly Color MediumVioletRed = NamedColors.MediumVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #191970. + /// + public static readonly Color MidnightBlue = NamedColors.MidnightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// + public static readonly Color MintCream = NamedColors.MintCream; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// + public static readonly Color MistyRose = NamedColors.MistyRose; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// + public static readonly Color Moccasin = NamedColors.Moccasin; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// + public static readonly Color NavajoWhite = NamedColors.NavajoWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #000080. + /// + public static readonly Color Navy = NamedColors.Navy; + + /// + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// + public static readonly Color OldLace = NamedColors.OldLace; + + /// + /// Represents a matching the W3C definition that has an hex value of #808000. + /// + public static readonly Color Olive = NamedColors.Olive; + + /// + /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// + public static readonly Color OliveDrab = NamedColors.OliveDrab; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// + public static readonly Color Orange = NamedColors.Orange; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// + public static readonly Color OrangeRed = NamedColors.OrangeRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// + public static readonly Color Orchid = NamedColors.Orchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// + public static readonly Color PaleGoldenrod = NamedColors.PaleGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// + public static readonly Color PaleGreen = NamedColors.PaleGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// + public static readonly Color PaleTurquoise = NamedColors.PaleTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// + public static readonly Color PaleVioletRed = NamedColors.PaleVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// + public static readonly Color PapayaWhip = NamedColors.PapayaWhip; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// + public static readonly Color PeachPuff = NamedColors.PeachPuff; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// + public static readonly Color Peru = NamedColors.Peru; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// + public static readonly Color Pink = NamedColors.Pink; + + /// + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// + public static readonly Color Plum = NamedColors.Plum; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// + public static readonly Color PowderBlue = NamedColors.PowderBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #800080. + /// + public static readonly Color Purple = NamedColors.Purple; + + /// + /// Represents a matching the W3C definition that has an hex value of #663399. + /// + public static readonly Color RebeccaPurple = NamedColors.RebeccaPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// + public static readonly Color Red = NamedColors.Red; + + /// + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// + public static readonly Color RosyBrown = NamedColors.RosyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// + public static readonly Color RoyalBlue = NamedColors.RoyalBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// + public static readonly Color SaddleBrown = NamedColors.SaddleBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// + public static readonly Color Salmon = NamedColors.Salmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// + public static readonly Color SandyBrown = NamedColors.SandyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// + public static readonly Color SeaGreen = NamedColors.SeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// + public static readonly Color SeaShell = NamedColors.SeaShell; + + /// + /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// + public static readonly Color Sienna = NamedColors.Sienna; + + /// + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// + public static readonly Color Silver = NamedColors.Silver; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// + public static readonly Color SkyBlue = NamedColors.SkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// + public static readonly Color SlateBlue = NamedColors.SlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #708090. + /// + public static readonly Color SlateGray = NamedColors.SlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// + public static readonly Color Snow = NamedColors.Snow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// + public static readonly Color SpringGreen = NamedColors.SpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// + public static readonly Color SteelBlue = NamedColors.SteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// + public static readonly Color Tan = NamedColors.Tan; + + /// + /// Represents a matching the W3C definition that has an hex value of #008080. + /// + public static readonly Color Teal = NamedColors.Teal; + + /// + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// + public static readonly Color Thistle = NamedColors.Thistle; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// + public static readonly Color Tomato = NamedColors.Tomato; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly Color Transparent = NamedColors.Transparent; + + /// + /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// + public static readonly Color Turquoise = NamedColors.Turquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// + public static readonly Color Violet = NamedColors.Violet; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// + public static readonly Color Wheat = NamedColors.Wheat; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly Color White = NamedColors.White; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// + public static readonly Color WhiteSmoke = NamedColors.WhiteSmoke; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// + public static readonly Color Yellow = NamedColors.Yellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// + public static readonly Color YellowGreen = NamedColors.YellowGreen; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color32.Transforms.cs b/src/ImageSharp/Colors/Color.Transforms.cs similarity index 82% rename from src/ImageSharp/Colors/Color32.Transforms.cs rename to src/ImageSharp/Colors/Color.Transforms.cs index 935b04217..31b4aa5be 100644 --- a/src/ImageSharp/Colors/Color32.Transforms.cs +++ b/src/ImageSharp/Colors/Color.Transforms.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -15,7 +15,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 partial struct Color32 + public partial struct Color { /// /// Adds the second color to the first. @@ -23,9 +23,9 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// - public static Color32 operator +(Color32 left, Color32 right) + public static Color operator +(Color left, Color right) { Vector4 add = left.ToVector4() + right.ToVector4(); return Pack(ref add); @@ -37,9 +37,9 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// - public static Color32 operator -(Color32 left, Color32 right) + public static Color operator -(Color left, Color right) { Vector4 sub = left.ToVector4() - right.ToVector4(); return Pack(ref sub); @@ -51,9 +51,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Normal(Color32 backdrop, Color32 source) + public static Color Normal(Color backdrop, Color source) { Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4()); return Pack(ref normal); @@ -71,9 +71,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Multiply(Color32 backdrop, Color32 source) + public static Color Multiply(Color backdrop, Color source) { Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4()); return Pack(ref multiply); @@ -90,9 +90,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Screen(Color32 backdrop, Color32 source) + public static Color Screen(Color backdrop, Color source) { Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4()); return Pack(ref subtract); @@ -105,9 +105,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 HardLight(Color32 backdrop, Color32 source) + public static Color HardLight(Color backdrop, Color source) { Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4()); return Pack(ref hardlight); @@ -124,9 +124,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Overlay(Color32 backdrop, Color32 source) + public static Color Overlay(Color backdrop, Color source) { Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4()); return Pack(ref overlay); @@ -139,9 +139,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Darken(Color32 backdrop, Color32 source) + public static Color Darken(Color backdrop, Color source) { Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4()); return Pack(ref darken); @@ -154,9 +154,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Lighten(Color32 backdrop, Color32 source) + public static Color Lighten(Color backdrop, Color source) { Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4()); return Pack(ref lighten); @@ -169,9 +169,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 SoftLight(Color32 backdrop, Color32 source) + public static Color SoftLight(Color backdrop, Color source) { Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4()); return Pack(ref softlight); @@ -183,9 +183,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 ColorDodge(Color32 backdrop, Color32 source) + public static Color ColorDodge(Color backdrop, Color source) { Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4()); return Pack(ref dodge); @@ -197,9 +197,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 ColorBurn(Color32 backdrop, Color32 source) + public static Color ColorBurn(Color backdrop, Color source) { Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4()); return Pack(ref burn); @@ -212,9 +212,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Difference(Color32 backdrop, Color32 source) + public static Color Difference(Color backdrop, Color source) { Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4()); return Pack(ref difference); @@ -227,9 +227,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color32 Exclusion(Color32 backdrop, Color32 source) + public static Color Exclusion(Color backdrop, Color source) { Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4()); return Pack(ref exclusion); @@ -245,11 +245,11 @@ namespace ImageSharp /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// /// - /// The + /// The /// - public static Color32 Lerp(Color32 from, Color32 to, float amount) + public static Color Lerp(Color from, Color to, float amount) { - return new Color32(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount)); + return new Color(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index 5c533e87b..fb2ce38ac 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -7,17 +7,43 @@ namespace ImageSharp { using System.Numerics; using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; /// - /// Unpacked pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. + /// Unpacked 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. /// + [StructLayout(LayoutKind.Explicit)] public partial struct Color : IPixel { + /// + /// 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; + /// /// The shift count for the red component /// @@ -48,11 +74,6 @@ namespace ImageSharp /// private static readonly Vector4 Half = new Vector4(0.5F); - /// - /// The backing vector for SIMD support. - /// - private Vector4 backingVector; - /// /// Initializes a new instance of the struct. /// @@ -63,7 +84,10 @@ namespace ImageSharp public Color(byte r, byte g, byte b, byte a = 255) : this() { - this.backingVector = new Vector4(r, g, b, a) / MaxBytes; + this.R = r; + this.G = g; + this.B = b; + this.A = a; } /// @@ -76,7 +100,7 @@ namespace ImageSharp public Color(float r, float g, float b, float a = 1) : this() { - this.backingVector = new Vector4(r, g, b, a); + this = Pack(r, g, b, a); } /// @@ -88,7 +112,7 @@ namespace ImageSharp public Color(Vector3 vector) : this() { - this.backingVector = new Vector4(vector, 1); + this = Pack(ref vector); } /// @@ -100,79 +124,7 @@ namespace ImageSharp public Color(Vector4 vector) : this() { - this.backingVector = vector; - } - - /// - /// Gets or sets the red component. - /// - public float R - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.backingVector.X; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.backingVector.X = value; - } - } - - /// - /// Gets or sets the green component. - /// - public float G - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.backingVector.Y; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.backingVector.Y = value; - } - } - - /// - /// Gets or sets the blue component. - /// - public float B - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.backingVector.Z; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.backingVector.Z = value; - } - } - - /// - /// Gets or sets the alpha component. - /// - public float A - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.backingVector.W; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.backingVector.W = value; - } + this = Pack(ref vector); } /// @@ -190,7 +142,10 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Color left, Color right) { - return left.backingVector == right.backingVector; + return left.R == right.R + && left.G == right.G + && left.B == right.B + && left.A == right.A; } /// @@ -204,7 +159,10 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Color left, Color right) { - return left.backingVector != right.backingVector; + return left.R != right.R + && left.G != right.G + && left.B != right.B + && left.A != right.A; } /// @@ -223,13 +181,16 @@ namespace ImageSharp } /// - public BulkPixelOperations CreateBulkOperations() => new Color.BulkOperations(); + public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { - this.backingVector = new Vector4(x, y, z, w) / MaxBytes; + this.R = x; + this.G = y; + this.B = z; + this.A = w; } /// @@ -238,9 +199,7 @@ namespace ImageSharp /// A hexadecimal string representation of the value. public string ToHex() { - Vector4 vector = this.backingVector * MaxBytes; - vector += Half; - uint hexOrder = (uint)((byte)vector.X << RedShift | (byte)vector.Y << GreenShift | (byte)vector.Z << BlueShift | (byte)vector.W << AlphaShift); + uint hexOrder = Pack(this.A, this.B, this.G, this.R); return hexOrder.ToString("X8"); } @@ -248,60 +207,52 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { - Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; - vector += Half; - bytes[startIndex] = (byte)vector.X; - bytes[startIndex + 1] = (byte)vector.Y; - bytes[startIndex + 2] = (byte)vector.Z; + bytes[startIndex] = this.R; + bytes[startIndex + 1] = this.G; + bytes[startIndex + 2] = this.B; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { - Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; - vector += Half; - bytes[startIndex] = (byte)vector.X; - bytes[startIndex + 1] = (byte)vector.Y; - bytes[startIndex + 2] = (byte)vector.Z; - bytes[startIndex + 2] = (byte)vector.W; + 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) { - Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; - vector += Half; - bytes[startIndex] = (byte)vector.Z; - bytes[startIndex + 1] = (byte)vector.Y; - bytes[startIndex + 2] = (byte)vector.X; + bytes[startIndex] = this.B; + bytes[startIndex + 1] = this.G; + bytes[startIndex + 2] = this.R; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { - Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; - vector += Half; - bytes[startIndex] = (byte)vector.Z; - bytes[startIndex + 1] = (byte)vector.Y; - bytes[startIndex + 2] = (byte)vector.X; - bytes[startIndex + 2] = (byte)vector.W; + 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.backingVector = vector; + this = Pack(ref vector); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { - return this.backingVector; + return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; } /// @@ -314,7 +265,10 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Color other) { - return this.backingVector == other.backingVector; + return this.R == other.R + && this.G == other.G + && this.B == other.B + && this.A == other.A; } /// @@ -329,7 +283,70 @@ namespace ImageSharp /// public override int GetHashCode() { - return this.backingVector.GetHashCode(); + unchecked + { + int hashCode = this.R.GetHashCode(); + hashCode = (hashCode * 397) ^ this.G.GetHashCode(); + hashCode = (hashCode * 397) ^ this.B.GetHashCode(); + hashCode = (hashCode * 397) ^ this.A.GetHashCode(); + return hashCode; + } + } + + /// + /// 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); + } + + /// + /// Packs a into a uint. + /// + /// The vector containing the values to pack. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Color Pack(ref Vector4 vector) + { + vector *= MaxBytes; + vector += Half; + vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); + + return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); + } + + /// + /// Packs a into a uint. + /// + /// The vector containing the values to pack. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Color 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 Color Pack(float x, float y, float z, float w) + { + Vector4 value = new Vector4(x, y, z, w); + return Pack(ref value); } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color32.BulkOperations.cs b/src/ImageSharp/Colors/Color32.BulkOperations.cs deleted file mode 100644 index b86994e5d..000000000 --- a/src/ImageSharp/Colors/Color32.BulkOperations.cs +++ /dev/null @@ -1,291 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - - /// - /// Unpacked 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 partial struct Color32 - { - /// - /// implementation optimized for . - /// - internal class BulkOperations : BulkPixelOperations - { - /// - /// SIMD optimized bulk implementation of - /// that works only with `count` divisible by . - /// - /// The to the source colors. - /// The to the dstination vectors. - /// The number of pixels to convert. - /// - /// Implementation adapted from: - /// - /// http://stackoverflow.com/a/5362789 - /// - /// TODO: We can replace this implementation in the future using new Vector API-s: - /// - /// https://github.com/dotnet/corefx/issues/15957 - /// - /// - internal static unsafe void ToVector4SimdAligned(BufferSpan sourceColors, BufferSpan destVectors, int count) - { - if (!Vector.IsHardwareAccelerated) - { - throw new InvalidOperationException( - "Color32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); - } - - int vecSize = Vector.Count; - - DebugGuard.IsTrue( - count % vecSize == 0, - nameof(count), - "Argument 'count' should divisible by Vector.Count!"); - - Vector bVec = new Vector(256.0f / 255.0f); - Vector magicFloat = new Vector(32768.0f); - Vector magicInt = new Vector(1191182336); // reinterpreded value of 32768.0f - Vector mask = new Vector(255); - - int unpackedRawCount = count * 4; - - ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); - - using (Buffer tempBuf = new Buffer( - unpackedRawCount + Vector.Count)) - { - uint[] temp = tempBuf.Array; - float[] fTemp = Unsafe.As(temp); - - ref UnpackedRGBA tempBase = ref Unsafe.As(ref tempBuf[0]); - - for (int i = 0; i < count; i++) - { - uint sVal = Unsafe.Add(ref src, i); - ref UnpackedRGBA dst = ref Unsafe.Add(ref tempBase, i); - - // This call is the bottleneck now: - dst.Load(sVal); - } - - for (int i = 0; i < unpackedRawCount; i += vecSize) - { - Vector vi = new Vector(temp, i); - - vi &= mask; - vi |= magicInt; - - Vector vf = Vector.AsVectorSingle(vi); - vf = (vf - magicFloat) * bVec; - vf.CopyTo(fTemp, i); - } - - BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint)); - } - } - - /// - internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) - { - if (count < 256 || !Vector.IsHardwareAccelerated) - { - // Doesn't worth to bother with SIMD: - base.ToVector4(sourceColors, destVectors, count); - return; - } - - int remainder = count % Vector.Count; - - int alignedCount = count - remainder; - - if (alignedCount > 0) - { - ToVector4SimdAligned(sourceColors, destVectors, alignedCount); - } - - if (remainder > 0) - { - sourceColors = sourceColors.Slice(alignedCount); - destVectors = destVectors.Slice(alignedCount); - base.ToVector4(sourceColors, destVectors, remainder); - } - } - - /// - internal override void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) - { - ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color32 destRef = ref destColors.DangerousGetPinnableReference(); - - for (int i = 0; i < count; i++) - { - ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color32 dp = ref Unsafe.Add(ref destRef, i); - - Unsafe.As(ref dp) = sp; - dp.A = 255; - } - } - - /// - internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) - { - ref Color32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); - ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - - for (int i = 0; i < count; i++) - { - ref Color32 sp = ref Unsafe.Add(ref sourceRef, i); - ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - - dp = Unsafe.As(ref sp); - } - } - - /// - internal override unsafe void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) - { - BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color32)); - } - - /// - internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) - { - BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Color32)); - } - - /// - internal override void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) - { - ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color32 destRef = ref destColors.DangerousGetPinnableReference(); - - for (int i = 0; i < count; i++) - { - ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color32 dp = ref Unsafe.Add(ref destRef, i); - - Unsafe.As(ref dp) = sp.ToZyx(); - dp.A = 255; - } - } - - /// - internal override void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) - { - ref Color32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); - ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - - for (int i = 0; i < count; i++) - { - ref Color32 sp = ref Unsafe.Add(ref sourceRef, i); - ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - - dp = Unsafe.As(ref sp).ToZyx(); - } - } - - /// - internal override void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) - { - ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color32 destRef = ref destColors.DangerousGetPinnableReference(); - - for (int i = 0; i < count; i++) - { - ref RGBA32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color32 dp = ref Unsafe.Add(ref destRef, i); - RGBA32 zyxw = sp.ToZyxw(); - dp = Unsafe.As(ref zyxw); - } - } - - /// - internal override void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) - { - ref Color32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); - ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); - - for (int i = 0; i < count; i++) - { - ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); - ref RGBA32 dp = ref Unsafe.Add(ref destRef, i); - dp = sp.ToZyxw(); - } - } - - /// - /// Helper struct to manipulate 3-byte RGB data. - /// - [StructLayout(LayoutKind.Sequential)] - private struct RGB24 - { - private byte x; - - private byte y; - - private byte z; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RGB24 ToZyx() => new RGB24 { x = this.z, y = this.y, z = this.x }; - } - - /// - /// Helper struct to manipulate 4-byte RGBA data. - /// - [StructLayout(LayoutKind.Sequential)] - private struct RGBA32 - { - private byte x; - - private byte y; - - private byte z; - - private byte w; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RGBA32 ToZyxw() => new RGBA32 { x = this.z, y = this.y, z = this.x, w = this.w }; - } - - /// - /// Value type to store -s unpacked into multiple -s. - /// - [StructLayout(LayoutKind.Sequential)] - private struct UnpackedRGBA - { - private uint r; - - private uint g; - - private uint b; - - private uint a; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Load(uint p) - { - this.r = p; - this.g = p >> GreenShift; - this.b = p >> BlueShift; - this.a = p >> AlphaShift; - } - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color32Constants.cs b/src/ImageSharp/Colors/Color32Constants.cs deleted file mode 100644 index 7c88b8117..000000000 --- a/src/ImageSharp/Colors/Color32Constants.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - - /// - /// Provides useful color definitions. - /// - public static class Color32Constants - { - /// - /// Provides a lazy, one time method of returning the colors. - /// - private static readonly Lazy SafeColors = new Lazy(GetWebSafeColors); - - /// - /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. - /// - public static Color32[] WebSafeColors => SafeColors.Value; - - /// - /// Returns an array of web safe colors. - /// - /// The - private static Color32[] GetWebSafeColors() - { - return new List - { - Color32.AliceBlue, - Color32.AntiqueWhite, - Color32.Aqua, - Color32.Aquamarine, - Color32.Azure, - Color32.Beige, - Color32.Bisque, - Color32.Black, - Color32.BlanchedAlmond, - Color32.Blue, - Color32.BlueViolet, - Color32.Brown, - Color32.BurlyWood, - Color32.CadetBlue, - Color32.Chartreuse, - Color32.Chocolate, - Color32.Coral, - Color32.CornflowerBlue, - Color32.Cornsilk, - Color32.Crimson, - Color32.Cyan, - Color32.DarkBlue, - Color32.DarkCyan, - Color32.DarkGoldenrod, - Color32.DarkGray, - Color32.DarkGreen, - Color32.DarkKhaki, - Color32.DarkMagenta, - Color32.DarkOliveGreen, - Color32.DarkOrange, - Color32.DarkOrchid, - Color32.DarkRed, - Color32.DarkSalmon, - Color32.DarkSeaGreen, - Color32.DarkSlateBlue, - Color32.DarkSlateGray, - Color32.DarkTurquoise, - Color32.DarkViolet, - Color32.DeepPink, - Color32.DeepSkyBlue, - Color32.DimGray, - Color32.DodgerBlue, - Color32.Firebrick, - Color32.FloralWhite, - Color32.ForestGreen, - Color32.Fuchsia, - Color32.Gainsboro, - Color32.GhostWhite, - Color32.Gold, - Color32.Goldenrod, - Color32.Gray, - Color32.Green, - Color32.GreenYellow, - Color32.Honeydew, - Color32.HotPink, - Color32.IndianRed, - Color32.Indigo, - Color32.Ivory, - Color32.Khaki, - Color32.Lavender, - Color32.LavenderBlush, - Color32.LawnGreen, - Color32.LemonChiffon, - Color32.LightBlue, - Color32.LightCoral, - Color32.LightCyan, - Color32.LightGoldenrodYellow, - Color32.LightGray, - Color32.LightGreen, - Color32.LightPink, - Color32.LightSalmon, - Color32.LightSeaGreen, - Color32.LightSkyBlue, - Color32.LightSlateGray, - Color32.LightSteelBlue, - Color32.LightYellow, - Color32.Lime, - Color32.LimeGreen, - Color32.Linen, - Color32.Magenta, - Color32.Maroon, - Color32.MediumAquamarine, - Color32.MediumBlue, - Color32.MediumOrchid, - Color32.MediumPurple, - Color32.MediumSeaGreen, - Color32.MediumSlateBlue, - Color32.MediumSpringGreen, - Color32.MediumTurquoise, - Color32.MediumVioletRed, - Color32.MidnightBlue, - Color32.MintCream, - Color32.MistyRose, - Color32.Moccasin, - Color32.NavajoWhite, - Color32.Navy, - Color32.OldLace, - Color32.Olive, - Color32.OliveDrab, - Color32.Orange, - Color32.OrangeRed, - Color32.Orchid, - Color32.PaleGoldenrod, - Color32.PaleGreen, - Color32.PaleTurquoise, - Color32.PaleVioletRed, - Color32.PapayaWhip, - Color32.PeachPuff, - Color32.Peru, - Color32.Pink, - Color32.Plum, - Color32.PowderBlue, - Color32.Purple, - Color32.RebeccaPurple, - Color32.Red, - Color32.RosyBrown, - Color32.RoyalBlue, - Color32.SaddleBrown, - Color32.Salmon, - Color32.SandyBrown, - Color32.SeaGreen, - Color32.SeaShell, - Color32.Sienna, - Color32.Silver, - Color32.SkyBlue, - Color32.SlateBlue, - Color32.SlateGray, - Color32.Snow, - Color32.SpringGreen, - Color32.SteelBlue, - Color32.Tan, - Color32.Teal, - Color32.Thistle, - Color32.Tomato, - Color32.Transparent, - Color32.Turquoise, - Color32.Violet, - Color32.Wheat, - Color32.White, - Color32.WhiteSmoke, - Color32.Yellow, - Color32.YellowGreen - }.ToArray(); - } - } -} diff --git a/src/ImageSharp/Colors/Color32Definitions.cs b/src/ImageSharp/Colors/Color32Definitions.cs deleted file mode 100644 index 5c361b428..000000000 --- a/src/ImageSharp/Colors/Color32Definitions.cs +++ /dev/null @@ -1,728 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - /// - /// Packed vector 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 partial struct Color32 - { - /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. - /// - public static readonly Color32 AliceBlue = NamedColors.AliceBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. - /// - public static readonly Color32 AntiqueWhite = NamedColors.AntiqueWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly Color32 Aqua = NamedColors.Aqua; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. - /// - public static readonly Color32 Aquamarine = NamedColors.Aquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. - /// - public static readonly Color32 Azure = NamedColors.Azure; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. - /// - public static readonly Color32 Beige = NamedColors.Beige; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. - /// - public static readonly Color32 Bisque = NamedColors.Bisque; - - /// - /// Represents a matching the W3C definition that has an hex value of #000000. - /// - public static readonly Color32 Black = NamedColors.Black; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. - /// - public static readonly Color32 BlanchedAlmond = NamedColors.BlanchedAlmond; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. - /// - public static readonly Color32 Blue = NamedColors.Blue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. - /// - public static readonly Color32 BlueViolet = NamedColors.BlueViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. - /// - public static readonly Color32 Brown = NamedColors.Brown; - - /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. - /// - public static readonly Color32 BurlyWood = NamedColors.BurlyWood; - - /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. - /// - public static readonly Color32 CadetBlue = NamedColors.CadetBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. - /// - public static readonly Color32 Chartreuse = NamedColors.Chartreuse; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. - /// - public static readonly Color32 Chocolate = NamedColors.Chocolate; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. - /// - public static readonly Color32 Coral = NamedColors.Coral; - - /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. - /// - public static readonly Color32 CornflowerBlue = NamedColors.CornflowerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. - /// - public static readonly Color32 Cornsilk = NamedColors.Cornsilk; - - /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. - /// - public static readonly Color32 Crimson = NamedColors.Crimson; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly Color32 Cyan = NamedColors.Cyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #00008B. - /// - public static readonly Color32 DarkBlue = NamedColors.DarkBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. - /// - public static readonly Color32 DarkCyan = NamedColors.DarkCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. - /// - public static readonly Color32 DarkGoldenrod = NamedColors.DarkGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. - /// - public static readonly Color32 DarkGray = NamedColors.DarkGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #006400. - /// - public static readonly Color32 DarkGreen = NamedColors.DarkGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. - /// - public static readonly Color32 DarkKhaki = NamedColors.DarkKhaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. - /// - public static readonly Color32 DarkMagenta = NamedColors.DarkMagenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. - /// - public static readonly Color32 DarkOliveGreen = NamedColors.DarkOliveGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. - /// - public static readonly Color32 DarkOrange = NamedColors.DarkOrange; - - /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. - /// - public static readonly Color32 DarkOrchid = NamedColors.DarkOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. - /// - public static readonly Color32 DarkRed = NamedColors.DarkRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. - /// - public static readonly Color32 DarkSalmon = NamedColors.DarkSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. - /// - public static readonly Color32 DarkSeaGreen = NamedColors.DarkSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. - /// - public static readonly Color32 DarkSlateBlue = NamedColors.DarkSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. - /// - public static readonly Color32 DarkSlateGray = NamedColors.DarkSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. - /// - public static readonly Color32 DarkTurquoise = NamedColors.DarkTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. - /// - public static readonly Color32 DarkViolet = NamedColors.DarkViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. - /// - public static readonly Color32 DeepPink = NamedColors.DeepPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. - /// - public static readonly Color32 DeepSkyBlue = NamedColors.DeepSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #696969. - /// - public static readonly Color32 DimGray = NamedColors.DimGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. - /// - public static readonly Color32 DodgerBlue = NamedColors.DodgerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #B22222. - /// - public static readonly Color32 Firebrick = NamedColors.Firebrick; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. - /// - public static readonly Color32 FloralWhite = NamedColors.FloralWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #228B22. - /// - public static readonly Color32 ForestGreen = NamedColors.ForestGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly Color32 Fuchsia = NamedColors.Fuchsia; - - /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. - /// - public static readonly Color32 Gainsboro = NamedColors.Gainsboro; - - /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. - /// - public static readonly Color32 GhostWhite = NamedColors.GhostWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. - /// - public static readonly Color32 Gold = NamedColors.Gold; - - /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. - /// - public static readonly Color32 Goldenrod = NamedColors.Goldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #808080. - /// - public static readonly Color32 Gray = NamedColors.Gray; - - /// - /// Represents a matching the W3C definition that has an hex value of #008000. - /// - public static readonly Color32 Green = NamedColors.Green; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. - /// - public static readonly Color32 GreenYellow = NamedColors.GreenYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. - /// - public static readonly Color32 Honeydew = NamedColors.Honeydew; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. - /// - public static readonly Color32 HotPink = NamedColors.HotPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. - /// - public static readonly Color32 IndianRed = NamedColors.IndianRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. - /// - public static readonly Color32 Indigo = NamedColors.Indigo; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. - /// - public static readonly Color32 Ivory = NamedColors.Ivory; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. - /// - public static readonly Color32 Khaki = NamedColors.Khaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. - /// - public static readonly Color32 Lavender = NamedColors.Lavender; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. - /// - public static readonly Color32 LavenderBlush = NamedColors.LavenderBlush; - - /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. - /// - public static readonly Color32 LawnGreen = NamedColors.LawnGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. - /// - public static readonly Color32 LemonChiffon = NamedColors.LemonChiffon; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. - /// - public static readonly Color32 LightBlue = NamedColors.LightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F08080. - /// - public static readonly Color32 LightCoral = NamedColors.LightCoral; - - /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. - /// - public static readonly Color32 LightCyan = NamedColors.LightCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. - /// - public static readonly Color32 LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. - /// - public static readonly Color32 LightGray = NamedColors.LightGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. - /// - public static readonly Color32 LightGreen = NamedColors.LightGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. - /// - public static readonly Color32 LightPink = NamedColors.LightPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. - /// - public static readonly Color32 LightSalmon = NamedColors.LightSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. - /// - public static readonly Color32 LightSeaGreen = NamedColors.LightSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. - /// - public static readonly Color32 LightSkyBlue = NamedColors.LightSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #778899. - /// - public static readonly Color32 LightSlateGray = NamedColors.LightSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. - /// - public static readonly Color32 LightSteelBlue = NamedColors.LightSteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. - /// - public static readonly Color32 LightYellow = NamedColors.LightYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. - /// - public static readonly Color32 Lime = NamedColors.Lime; - - /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. - /// - public static readonly Color32 LimeGreen = NamedColors.LimeGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. - /// - public static readonly Color32 Linen = NamedColors.Linen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly Color32 Magenta = NamedColors.Magenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #800000. - /// - public static readonly Color32 Maroon = NamedColors.Maroon; - - /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. - /// - public static readonly Color32 MediumAquamarine = NamedColors.MediumAquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. - /// - public static readonly Color32 MediumBlue = NamedColors.MediumBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. - /// - public static readonly Color32 MediumOrchid = NamedColors.MediumOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. - /// - public static readonly Color32 MediumPurple = NamedColors.MediumPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. - /// - public static readonly Color32 MediumSeaGreen = NamedColors.MediumSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. - /// - public static readonly Color32 MediumSlateBlue = NamedColors.MediumSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. - /// - public static readonly Color32 MediumSpringGreen = NamedColors.MediumSpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. - /// - public static readonly Color32 MediumTurquoise = NamedColors.MediumTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #C71585. - /// - public static readonly Color32 MediumVioletRed = NamedColors.MediumVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #191970. - /// - public static readonly Color32 MidnightBlue = NamedColors.MidnightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. - /// - public static readonly Color32 MintCream = NamedColors.MintCream; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. - /// - public static readonly Color32 MistyRose = NamedColors.MistyRose; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. - /// - public static readonly Color32 Moccasin = NamedColors.Moccasin; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. - /// - public static readonly Color32 NavajoWhite = NamedColors.NavajoWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #000080. - /// - public static readonly Color32 Navy = NamedColors.Navy; - - /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. - /// - public static readonly Color32 OldLace = NamedColors.OldLace; - - /// - /// Represents a matching the W3C definition that has an hex value of #808000. - /// - public static readonly Color32 Olive = NamedColors.Olive; - - /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. - /// - public static readonly Color32 OliveDrab = NamedColors.OliveDrab; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. - /// - public static readonly Color32 Orange = NamedColors.Orange; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. - /// - public static readonly Color32 OrangeRed = NamedColors.OrangeRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. - /// - public static readonly Color32 Orchid = NamedColors.Orchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. - /// - public static readonly Color32 PaleGoldenrod = NamedColors.PaleGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. - /// - public static readonly Color32 PaleGreen = NamedColors.PaleGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. - /// - public static readonly Color32 PaleTurquoise = NamedColors.PaleTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. - /// - public static readonly Color32 PaleVioletRed = NamedColors.PaleVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. - /// - public static readonly Color32 PapayaWhip = NamedColors.PapayaWhip; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. - /// - public static readonly Color32 PeachPuff = NamedColors.PeachPuff; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. - /// - public static readonly Color32 Peru = NamedColors.Peru; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. - /// - public static readonly Color32 Pink = NamedColors.Pink; - - /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. - /// - public static readonly Color32 Plum = NamedColors.Plum; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. - /// - public static readonly Color32 PowderBlue = NamedColors.PowderBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #800080. - /// - public static readonly Color32 Purple = NamedColors.Purple; - - /// - /// Represents a matching the W3C definition that has an hex value of #663399. - /// - public static readonly Color32 RebeccaPurple = NamedColors.RebeccaPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. - /// - public static readonly Color32 Red = NamedColors.Red; - - /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. - /// - public static readonly Color32 RosyBrown = NamedColors.RosyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. - /// - public static readonly Color32 RoyalBlue = NamedColors.RoyalBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. - /// - public static readonly Color32 SaddleBrown = NamedColors.SaddleBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. - /// - public static readonly Color32 Salmon = NamedColors.Salmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. - /// - public static readonly Color32 SandyBrown = NamedColors.SandyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. - /// - public static readonly Color32 SeaGreen = NamedColors.SeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. - /// - public static readonly Color32 SeaShell = NamedColors.SeaShell; - - /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. - /// - public static readonly Color32 Sienna = NamedColors.Sienna; - - /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. - /// - public static readonly Color32 Silver = NamedColors.Silver; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. - /// - public static readonly Color32 SkyBlue = NamedColors.SkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. - /// - public static readonly Color32 SlateBlue = NamedColors.SlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #708090. - /// - public static readonly Color32 SlateGray = NamedColors.SlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. - /// - public static readonly Color32 Snow = NamedColors.Snow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. - /// - public static readonly Color32 SpringGreen = NamedColors.SpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. - /// - public static readonly Color32 SteelBlue = NamedColors.SteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. - /// - public static readonly Color32 Tan = NamedColors.Tan; - - /// - /// Represents a matching the W3C definition that has an hex value of #008080. - /// - public static readonly Color32 Teal = NamedColors.Teal; - - /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. - /// - public static readonly Color32 Thistle = NamedColors.Thistle; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. - /// - public static readonly Color32 Tomato = NamedColors.Tomato; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly Color32 Transparent = NamedColors.Transparent; - - /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. - /// - public static readonly Color32 Turquoise = NamedColors.Turquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. - /// - public static readonly Color32 Violet = NamedColors.Violet; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. - /// - public static readonly Color32 Wheat = NamedColors.Wheat; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly Color32 White = NamedColors.White; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. - /// - public static readonly Color32 WhiteSmoke = NamedColors.WhiteSmoke; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. - /// - public static readonly Color32 Yellow = NamedColors.Yellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. - /// - public static readonly Color32 YellowGreen = NamedColors.YellowGreen; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorConstants.cs b/src/ImageSharp/Colors/ColorConstants.cs new file mode 100644 index 000000000..1397b6da6 --- /dev/null +++ b/src/ImageSharp/Colors/ColorConstants.cs @@ -0,0 +1,179 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Collections.Generic; + + /// + /// Provides useful color definitions. + /// + public static class ColorConstants + { + /// + /// Provides a lazy, one time method of returning the colors. + /// + private static readonly Lazy SafeColors = new Lazy(GetWebSafeColors); + + /// + /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. + /// + public static Color[] WebSafeColors => SafeColors.Value; + + /// + /// Returns an array of web safe colors. + /// + /// The + private static Color[] GetWebSafeColors() + { + return new List + { + Color.AliceBlue, + Color.AntiqueWhite, + Color.Aqua, + Color.Aquamarine, + Color.Azure, + Color.Beige, + Color.Bisque, + Color.Black, + Color.BlanchedAlmond, + Color.Blue, + Color.BlueViolet, + Color.Brown, + Color.BurlyWood, + Color.CadetBlue, + Color.Chartreuse, + Color.Chocolate, + Color.Coral, + Color.CornflowerBlue, + Color.Cornsilk, + Color.Crimson, + Color.Cyan, + Color.DarkBlue, + Color.DarkCyan, + Color.DarkGoldenrod, + Color.DarkGray, + Color.DarkGreen, + Color.DarkKhaki, + Color.DarkMagenta, + Color.DarkOliveGreen, + Color.DarkOrange, + Color.DarkOrchid, + Color.DarkRed, + Color.DarkSalmon, + Color.DarkSeaGreen, + Color.DarkSlateBlue, + Color.DarkSlateGray, + Color.DarkTurquoise, + Color.DarkViolet, + Color.DeepPink, + Color.DeepSkyBlue, + Color.DimGray, + Color.DodgerBlue, + Color.Firebrick, + Color.FloralWhite, + Color.ForestGreen, + Color.Fuchsia, + Color.Gainsboro, + Color.GhostWhite, + Color.Gold, + Color.Goldenrod, + Color.Gray, + Color.Green, + Color.GreenYellow, + Color.Honeydew, + Color.HotPink, + Color.IndianRed, + Color.Indigo, + Color.Ivory, + Color.Khaki, + Color.Lavender, + Color.LavenderBlush, + Color.LawnGreen, + Color.LemonChiffon, + Color.LightBlue, + Color.LightCoral, + Color.LightCyan, + Color.LightGoldenrodYellow, + Color.LightGray, + Color.LightGreen, + Color.LightPink, + Color.LightSalmon, + Color.LightSeaGreen, + Color.LightSkyBlue, + Color.LightSlateGray, + Color.LightSteelBlue, + Color.LightYellow, + Color.Lime, + Color.LimeGreen, + Color.Linen, + Color.Magenta, + Color.Maroon, + Color.MediumAquamarine, + Color.MediumBlue, + Color.MediumOrchid, + Color.MediumPurple, + Color.MediumSeaGreen, + Color.MediumSlateBlue, + Color.MediumSpringGreen, + Color.MediumTurquoise, + Color.MediumVioletRed, + Color.MidnightBlue, + Color.MintCream, + Color.MistyRose, + Color.Moccasin, + Color.NavajoWhite, + Color.Navy, + Color.OldLace, + Color.Olive, + Color.OliveDrab, + Color.Orange, + Color.OrangeRed, + Color.Orchid, + Color.PaleGoldenrod, + Color.PaleGreen, + Color.PaleTurquoise, + Color.PaleVioletRed, + Color.PapayaWhip, + Color.PeachPuff, + Color.Peru, + Color.Pink, + Color.Plum, + Color.PowderBlue, + Color.Purple, + Color.RebeccaPurple, + Color.Red, + Color.RosyBrown, + Color.RoyalBlue, + Color.SaddleBrown, + Color.Salmon, + Color.SandyBrown, + Color.SeaGreen, + Color.SeaShell, + Color.Sienna, + Color.Silver, + Color.SkyBlue, + Color.SlateBlue, + Color.SlateGray, + Color.Snow, + Color.SpringGreen, + Color.SteelBlue, + Color.Tan, + Color.Teal, + Color.Thistle, + Color.Tomato, + Color.Transparent, + Color.Turquoise, + Color.Violet, + Color.Wheat, + Color.White, + Color.WhiteSmoke, + Color.Yellow, + Color.YellowGreen + }.ToArray(); + } + } +} diff --git a/src/ImageSharp/Colors/ColorVector.BulkOperations.cs b/src/ImageSharp/Colors/ColorVector.BulkOperations.cs new file mode 100644 index 000000000..ab32313c0 --- /dev/null +++ b/src/ImageSharp/Colors/ColorVector.BulkOperations.cs @@ -0,0 +1,27 @@ +namespace ImageSharp +{ + using System.Numerics; + + /// + /// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1. + /// 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 partial struct ColorVector + { + /// + /// implementation optimized for . + /// + internal class BulkOperations : BulkPixelOperations + { + /// + internal override unsafe void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + { + BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4)); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorVector.Definitions.cs b/src/ImageSharp/Colors/ColorVector.Definitions.cs new file mode 100644 index 000000000..955c0b9db --- /dev/null +++ b/src/ImageSharp/Colors/ColorVector.Definitions.cs @@ -0,0 +1,728 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + /// + /// Unpacked 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 partial struct ColorVector + { + /// + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// + public static readonly ColorVector AliceBlue = NamedColors.AliceBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// + public static readonly ColorVector AntiqueWhite = NamedColors.AntiqueWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly ColorVector Aqua = NamedColors.Aqua; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// + public static readonly ColorVector Aquamarine = NamedColors.Aquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// + public static readonly ColorVector Azure = NamedColors.Azure; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// + public static readonly ColorVector Beige = NamedColors.Beige; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// + public static readonly ColorVector Bisque = NamedColors.Bisque; + + /// + /// Represents a matching the W3C definition that has an hex value of #000000. + /// + public static readonly ColorVector Black = NamedColors.Black; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// + public static readonly ColorVector BlanchedAlmond = NamedColors.BlanchedAlmond; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// + public static readonly ColorVector Blue = NamedColors.Blue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// + public static readonly ColorVector BlueViolet = NamedColors.BlueViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// + public static readonly ColorVector Brown = NamedColors.Brown; + + /// + /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// + public static readonly ColorVector BurlyWood = NamedColors.BurlyWood; + + /// + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// + public static readonly ColorVector CadetBlue = NamedColors.CadetBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// + public static readonly ColorVector Chartreuse = NamedColors.Chartreuse; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// + public static readonly ColorVector Chocolate = NamedColors.Chocolate; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// + public static readonly ColorVector Coral = NamedColors.Coral; + + /// + /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// + public static readonly ColorVector CornflowerBlue = NamedColors.CornflowerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// + public static readonly ColorVector Cornsilk = NamedColors.Cornsilk; + + /// + /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// + public static readonly ColorVector Crimson = NamedColors.Crimson; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly ColorVector Cyan = NamedColors.Cyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #00008B. + /// + public static readonly ColorVector DarkBlue = NamedColors.DarkBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// + public static readonly ColorVector DarkCyan = NamedColors.DarkCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// + public static readonly ColorVector DarkGoldenrod = NamedColors.DarkGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// + public static readonly ColorVector DarkGray = NamedColors.DarkGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #006400. + /// + public static readonly ColorVector DarkGreen = NamedColors.DarkGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// + public static readonly ColorVector DarkKhaki = NamedColors.DarkKhaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// + public static readonly ColorVector DarkMagenta = NamedColors.DarkMagenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// + public static readonly ColorVector DarkOliveGreen = NamedColors.DarkOliveGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// + public static readonly ColorVector DarkOrange = NamedColors.DarkOrange; + + /// + /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// + public static readonly ColorVector DarkOrchid = NamedColors.DarkOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// + public static readonly ColorVector DarkRed = NamedColors.DarkRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// + public static readonly ColorVector DarkSalmon = NamedColors.DarkSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// + public static readonly ColorVector DarkSeaGreen = NamedColors.DarkSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// + public static readonly ColorVector DarkSlateBlue = NamedColors.DarkSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// + public static readonly ColorVector DarkSlateGray = NamedColors.DarkSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// + public static readonly ColorVector DarkTurquoise = NamedColors.DarkTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// + public static readonly ColorVector DarkViolet = NamedColors.DarkViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// + public static readonly ColorVector DeepPink = NamedColors.DeepPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// + public static readonly ColorVector DeepSkyBlue = NamedColors.DeepSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #696969. + /// + public static readonly ColorVector DimGray = NamedColors.DimGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// + public static readonly ColorVector DodgerBlue = NamedColors.DodgerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #B22222. + /// + public static readonly ColorVector Firebrick = NamedColors.Firebrick; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// + public static readonly ColorVector FloralWhite = NamedColors.FloralWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #228B22. + /// + public static readonly ColorVector ForestGreen = NamedColors.ForestGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly ColorVector Fuchsia = NamedColors.Fuchsia; + + /// + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// + public static readonly ColorVector Gainsboro = NamedColors.Gainsboro; + + /// + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// + public static readonly ColorVector GhostWhite = NamedColors.GhostWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// + public static readonly ColorVector Gold = NamedColors.Gold; + + /// + /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// + public static readonly ColorVector Goldenrod = NamedColors.Goldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #808080. + /// + public static readonly ColorVector Gray = NamedColors.Gray; + + /// + /// Represents a matching the W3C definition that has an hex value of #008000. + /// + public static readonly ColorVector Green = NamedColors.Green; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// + public static readonly ColorVector GreenYellow = NamedColors.GreenYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// + public static readonly ColorVector Honeydew = NamedColors.Honeydew; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// + public static readonly ColorVector HotPink = NamedColors.HotPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// + public static readonly ColorVector IndianRed = NamedColors.IndianRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// + public static readonly ColorVector Indigo = NamedColors.Indigo; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// + public static readonly ColorVector Ivory = NamedColors.Ivory; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// + public static readonly ColorVector Khaki = NamedColors.Khaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// + public static readonly ColorVector Lavender = NamedColors.Lavender; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// + public static readonly ColorVector LavenderBlush = NamedColors.LavenderBlush; + + /// + /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// + public static readonly ColorVector LawnGreen = NamedColors.LawnGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// + public static readonly ColorVector LemonChiffon = NamedColors.LemonChiffon; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// + public static readonly ColorVector LightBlue = NamedColors.LightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F08080. + /// + public static readonly ColorVector LightCoral = NamedColors.LightCoral; + + /// + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// + public static readonly ColorVector LightCyan = NamedColors.LightCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// + public static readonly ColorVector LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// + public static readonly ColorVector LightGray = NamedColors.LightGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// + public static readonly ColorVector LightGreen = NamedColors.LightGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// + public static readonly ColorVector LightPink = NamedColors.LightPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// + public static readonly ColorVector LightSalmon = NamedColors.LightSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// + public static readonly ColorVector LightSeaGreen = NamedColors.LightSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// + public static readonly ColorVector LightSkyBlue = NamedColors.LightSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #778899. + /// + public static readonly ColorVector LightSlateGray = NamedColors.LightSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// + public static readonly ColorVector LightSteelBlue = NamedColors.LightSteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// + public static readonly ColorVector LightYellow = NamedColors.LightYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// + public static readonly ColorVector Lime = NamedColors.Lime; + + /// + /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// + public static readonly ColorVector LimeGreen = NamedColors.LimeGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// + public static readonly ColorVector Linen = NamedColors.Linen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly ColorVector Magenta = NamedColors.Magenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #800000. + /// + public static readonly ColorVector Maroon = NamedColors.Maroon; + + /// + /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// + public static readonly ColorVector MediumAquamarine = NamedColors.MediumAquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// + public static readonly ColorVector MediumBlue = NamedColors.MediumBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// + public static readonly ColorVector MediumOrchid = NamedColors.MediumOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// + public static readonly ColorVector MediumPurple = NamedColors.MediumPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// + public static readonly ColorVector MediumSeaGreen = NamedColors.MediumSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// + public static readonly ColorVector MediumSlateBlue = NamedColors.MediumSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// + public static readonly ColorVector MediumSpringGreen = NamedColors.MediumSpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// + public static readonly ColorVector MediumTurquoise = NamedColors.MediumTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #C71585. + /// + public static readonly ColorVector MediumVioletRed = NamedColors.MediumVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #191970. + /// + public static readonly ColorVector MidnightBlue = NamedColors.MidnightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// + public static readonly ColorVector MintCream = NamedColors.MintCream; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// + public static readonly ColorVector MistyRose = NamedColors.MistyRose; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// + public static readonly ColorVector Moccasin = NamedColors.Moccasin; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// + public static readonly ColorVector NavajoWhite = NamedColors.NavajoWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #000080. + /// + public static readonly ColorVector Navy = NamedColors.Navy; + + /// + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// + public static readonly ColorVector OldLace = NamedColors.OldLace; + + /// + /// Represents a matching the W3C definition that has an hex value of #808000. + /// + public static readonly ColorVector Olive = NamedColors.Olive; + + /// + /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// + public static readonly ColorVector OliveDrab = NamedColors.OliveDrab; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// + public static readonly ColorVector Orange = NamedColors.Orange; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// + public static readonly ColorVector OrangeRed = NamedColors.OrangeRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// + public static readonly ColorVector Orchid = NamedColors.Orchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// + public static readonly ColorVector PaleGoldenrod = NamedColors.PaleGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// + public static readonly ColorVector PaleGreen = NamedColors.PaleGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// + public static readonly ColorVector PaleTurquoise = NamedColors.PaleTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// + public static readonly ColorVector PaleVioletRed = NamedColors.PaleVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// + public static readonly ColorVector PapayaWhip = NamedColors.PapayaWhip; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// + public static readonly ColorVector PeachPuff = NamedColors.PeachPuff; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// + public static readonly ColorVector Peru = NamedColors.Peru; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// + public static readonly ColorVector Pink = NamedColors.Pink; + + /// + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// + public static readonly ColorVector Plum = NamedColors.Plum; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// + public static readonly ColorVector PowderBlue = NamedColors.PowderBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #800080. + /// + public static readonly ColorVector Purple = NamedColors.Purple; + + /// + /// Represents a matching the W3C definition that has an hex value of #663399. + /// + public static readonly ColorVector RebeccaPurple = NamedColors.RebeccaPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// + public static readonly ColorVector Red = NamedColors.Red; + + /// + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// + public static readonly ColorVector RosyBrown = NamedColors.RosyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// + public static readonly ColorVector RoyalBlue = NamedColors.RoyalBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// + public static readonly ColorVector SaddleBrown = NamedColors.SaddleBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// + public static readonly ColorVector Salmon = NamedColors.Salmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// + public static readonly ColorVector SandyBrown = NamedColors.SandyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// + public static readonly ColorVector SeaGreen = NamedColors.SeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// + public static readonly ColorVector SeaShell = NamedColors.SeaShell; + + /// + /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// + public static readonly ColorVector Sienna = NamedColors.Sienna; + + /// + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// + public static readonly ColorVector Silver = NamedColors.Silver; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// + public static readonly ColorVector SkyBlue = NamedColors.SkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// + public static readonly ColorVector SlateBlue = NamedColors.SlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #708090. + /// + public static readonly ColorVector SlateGray = NamedColors.SlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// + public static readonly ColorVector Snow = NamedColors.Snow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// + public static readonly ColorVector SpringGreen = NamedColors.SpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// + public static readonly ColorVector SteelBlue = NamedColors.SteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// + public static readonly ColorVector Tan = NamedColors.Tan; + + /// + /// Represents a matching the W3C definition that has an hex value of #008080. + /// + public static readonly ColorVector Teal = NamedColors.Teal; + + /// + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// + public static readonly ColorVector Thistle = NamedColors.Thistle; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// + public static readonly ColorVector Tomato = NamedColors.Tomato; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly ColorVector Transparent = NamedColors.Transparent; + + /// + /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// + public static readonly ColorVector Turquoise = NamedColors.Turquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// + public static readonly ColorVector Violet = NamedColors.Violet; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// + public static readonly ColorVector Wheat = NamedColors.Wheat; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly ColorVector White = NamedColors.White; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// + public static readonly ColorVector WhiteSmoke = NamedColors.WhiteSmoke; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// + public static readonly ColorVector Yellow = NamedColors.Yellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// + public static readonly ColorVector YellowGreen = NamedColors.YellowGreen; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color32.cs b/src/ImageSharp/Colors/ColorVector.cs similarity index 50% rename from src/ImageSharp/Colors/Color32.cs rename to src/ImageSharp/Colors/ColorVector.cs index d646b9c4c..d9eb1906d 100644 --- a/src/ImageSharp/Colors/Color32.cs +++ b/src/ImageSharp/Colors/ColorVector.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -7,43 +7,17 @@ namespace ImageSharp { using System.Numerics; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; /// - /// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. + /// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1. /// 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. /// - [StructLayout(LayoutKind.Explicit)] - public partial struct Color32 : IPixel + public partial struct ColorVector : IPixel { - /// - /// 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; - /// /// The shift count for the red component /// @@ -75,122 +49,187 @@ namespace ImageSharp private static readonly Vector4 Half = new Vector4(0.5F); /// - /// Initializes a new instance of the struct. + /// The backing vector for SIMD support. + /// + private Vector4 backingVector; + + /// + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. - public Color32(byte r, byte g, byte b, byte a = 255) + public ColorVector(byte r, byte g, byte b, byte a = 255) : this() { - this.R = r; - this.G = g; - this.B = b; - this.A = a; + this.backingVector = new Vector4(r, g, b, a) / MaxBytes; } /// - /// 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 Color32(float r, float g, float b, float a = 1) + public ColorVector(float r, float g, float b, float a = 1) : this() { - this = Pack(r, g, b, a); + this.backingVector = new Vector4(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 Color32(Vector3 vector) + public ColorVector(Vector3 vector) : this() { - this = Pack(ref vector); + this.backingVector = new Vector4(vector, 1); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// - public Color32(Vector4 vector) + public ColorVector(Vector4 vector) : this() { - this = Pack(ref vector); + this.backingVector = vector; + } + + /// + /// Gets or sets the red component. + /// + public float R + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.X; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.X = value; + } + } + + /// + /// Gets or sets the green component. + /// + public float G + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.Y; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.Y = value; + } + } + + /// + /// Gets or sets the blue component. + /// + public float B + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.Z; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.Z = value; + } + } + + /// + /// Gets or sets the alpha component. + /// + public float A + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return this.backingVector.W; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { + this.backingVector.W = value; + } } /// - /// 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 ==(Color32 left, Color32 right) + public static bool operator ==(ColorVector left, ColorVector right) { - return left.R == right.R - && left.G == right.G - && left.B == right.B - && left.A == right.A; + return left.backingVector == right.backingVector; } /// - /// 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 !=(Color32 left, Color32 right) + public static bool operator !=(ColorVector left, ColorVector right) { - return left.R != right.R - && left.G != right.G - && left.B != right.B - && left.A != right.A; + return left.backingVector != right.backingVector; } /// - /// Creates a new instance of the struct. + /// 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 . + /// The . /// - public static Color32 FromHex(string hex) + public static ColorVector FromHex(string hex) { - return ColorBuilder.FromHex(hex); + return ColorBuilder.FromHex(hex); } /// - public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); + public BulkPixelOperations CreateBulkOperations() => new ColorVector.BulkOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { - this.R = x; - this.G = y; - this.B = z; - this.A = w; + this.backingVector = new Vector4(x, y, z, w) / MaxBytes; } /// @@ -199,7 +238,9 @@ namespace ImageSharp /// A hexadecimal string representation of the value. public string ToHex() { - uint hexOrder = Pack(this.A, this.B, this.G, this.R); + Vector4 vector = this.backingVector * MaxBytes; + vector += Half; + uint hexOrder = (uint)((byte)vector.X << RedShift | (byte)vector.Y << GreenShift | (byte)vector.Z << BlueShift | (byte)vector.W << AlphaShift); return hexOrder.ToString("X8"); } @@ -207,68 +248,73 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { - bytes[startIndex] = this.R; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.B; + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.X; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.Z; } /// [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; + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.X; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.Z; + bytes[startIndex + 2] = (byte)vector.W; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { - bytes[startIndex] = this.B; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.R; + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.Z; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.X; } /// [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; + Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; + vector += Half; + bytes[startIndex] = (byte)vector.Z; + bytes[startIndex + 1] = (byte)vector.Y; + bytes[startIndex + 2] = (byte)vector.X; + bytes[startIndex + 2] = (byte)vector.W; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { - this = Pack(ref vector); + this.backingVector = vector; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { - return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; + return this.backingVector; } /// public override bool Equals(object obj) { - return (obj is Color32) && this.Equals((Color32)obj); + return (obj is ColorVector) && this.Equals((ColorVector)obj); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Color32 other) + public bool Equals(ColorVector other) { - return this.R == other.R - && this.G == other.G - && this.B == other.B - && this.A == other.A; + return this.backingVector == other.backingVector; } /// @@ -283,70 +329,7 @@ namespace ImageSharp /// public override int GetHashCode() { - unchecked - { - int hashCode = this.R.GetHashCode(); - hashCode = (hashCode * 397) ^ this.G.GetHashCode(); - hashCode = (hashCode * 397) ^ this.B.GetHashCode(); - hashCode = (hashCode * 397) ^ this.A.GetHashCode(); - return hashCode; - } - } - - /// - /// 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); - } - - /// - /// Packs a into a uint. - /// - /// The vector containing the values to pack. - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Color32 Pack(ref Vector4 vector) - { - vector *= MaxBytes; - vector += Half; - vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); - - return new Color32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); - } - - /// - /// Packs a into a uint. - /// - /// The vector containing the values to pack. - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Color32 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 Color32 Pack(float x, float y, float z, float w) - { - Vector4 value = new Vector4(x, y, z, w); - return Pack(ref value); + return this.backingVector.GetHashCode(); } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 2c767386c..cbf40724e 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -17,46 +17,46 @@ 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 partial struct Color32 + public partial struct Color { /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Color32(Bgra32 color) + public static implicit operator Color(Bgra32 color) { - return new Color32(color.R, color.G, color.B, color.A); + return new Color(color.R, color.G, color.B, color.A); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color32(Cmyk cmykColor) + public static implicit operator Color(Cmyk cmykColor) { float r = (1 - cmykColor.C) * (1 - cmykColor.K); float g = (1 - cmykColor.M) * (1 - cmykColor.K); float b = (1 - cmykColor.Y) * (1 - cmykColor.K); - return new Color32(r, g, b, 1); + return new Color(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color32(YCbCr color) + public static implicit operator Color(YCbCr color) { float y = color.Y; float cb = color.Cb - 128; @@ -66,18 +66,18 @@ namespace ImageSharp byte g = (byte)(y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); byte b = (byte)(y + (1.772F * cb)).Clamp(0, 255); - return new Color32(r, g, b); + return new Color(r, g, b); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color32(CieXyz color) + public static implicit operator Color(CieXyz color) { float x = color.X / 100F; float y = color.Y / 100F; @@ -89,25 +89,25 @@ namespace ImageSharp float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); Vector4 vector = new Vector4(r, g, b, 1).Compress(); - return new Color32(vector); + return new Color(vector); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color32(Hsv color) + public static implicit operator Color(Hsv color) { float s = color.S; float v = color.V; if (MathF.Abs(s) < Constants.Epsilon) { - return new Color32(v, v, v, 1); + return new Color(v, v, v, 1); } float h = (MathF.Abs(color.H - 360) < Constants.Epsilon) ? 0 : color.H / 60; @@ -158,18 +158,18 @@ namespace ImageSharp break; } - return new Color32(r, g, b, 1); + return new Color(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color32(Hsl color) + public static implicit operator Color(Hsl color) { float rangedH = color.H / 360F; float r = 0; @@ -195,18 +195,18 @@ namespace ImageSharp } } - return new Color32(r, g, b, 1); + return new Color(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color32(CieLab cieLabColor) + public static implicit operator Color(CieLab cieLabColor) { // First convert back to XYZ... float y = (cieLabColor.L + 16F) / 116F; @@ -229,7 +229,7 @@ namespace ImageSharp float g = (x * -0.9689F) + (y * 1.8758F) + (z * 0.0415F); float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); - return new Color32(new Vector4(r, g, b, 1F).Compress()); + return new Color(new Vector4(r, g, b, 1F).Compress()); } /// diff --git a/src/ImageSharp/Colors/ComponentOrder.cs b/src/ImageSharp/Colors/ComponentOrder.cs index 804bc49b1..03fa3bbf8 100644 --- a/src/ImageSharp/Colors/ComponentOrder.cs +++ b/src/ImageSharp/Colors/ComponentOrder.cs @@ -11,22 +11,22 @@ namespace ImageSharp public enum ComponentOrder { /// - /// Z-> Y-> X order. Equivalent to B-> G-> R in + /// Z-> Y-> X order. Equivalent to B-> G-> R in /// Zyx, /// - /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in + /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// Zyxw, /// - /// X-> Y-> Z order. Equivalent to R-> G-> B in + /// X-> Y-> Z order. Equivalent to R-> G-> B in /// Xyz, /// - /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in + /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// Xyzw, } diff --git a/src/ImageSharp/Colors/NamedColors{TColor}.cs b/src/ImageSharp/Colors/NamedColors{TColor}.cs index 4edba660a..f8080195d 100644 --- a/src/ImageSharp/Colors/NamedColors{TColor}.cs +++ b/src/ImageSharp/Colors/NamedColors{TColor}.cs @@ -8,719 +8,719 @@ namespace ImageSharp using System; /// - /// A set of named colors mapped to the provided Color space. + /// A set of named colors mapped to the provided color space. /// /// The type of the color. public static class NamedColors where TColor : struct, IPixel { /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. /// public static readonly TColor AliceBlue = ColorBuilder.FromRGBA(240, 248, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. /// public static readonly TColor AntiqueWhite = ColorBuilder.FromRGBA(250, 235, 215, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// Represents a matching the W3C definition that has an hex value of #00FFFF. /// public static readonly TColor Aqua = ColorBuilder.FromRGBA(0, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. /// public static readonly TColor Aquamarine = ColorBuilder.FromRGBA(127, 255, 212, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. /// public static readonly TColor Azure = ColorBuilder.FromRGBA(240, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. /// public static readonly TColor Beige = ColorBuilder.FromRGBA(245, 245, 220, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. /// public static readonly TColor Bisque = ColorBuilder.FromRGBA(255, 228, 196, 255); /// - /// Represents a matching the W3C definition that has an hex value of #000000. + /// Represents a matching the W3C definition that has an hex value of #000000. /// public static readonly TColor Black = ColorBuilder.FromRGBA(0, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. /// public static readonly TColor BlanchedAlmond = ColorBuilder.FromRGBA(255, 235, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// Represents a matching the W3C definition that has an hex value of #0000FF. /// public static readonly TColor Blue = ColorBuilder.FromRGBA(0, 0, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. /// public static readonly TColor BlueViolet = ColorBuilder.FromRGBA(138, 43, 226, 255); /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// Represents a matching the W3C definition that has an hex value of #A52A2A. /// public static readonly TColor Brown = ColorBuilder.FromRGBA(165, 42, 42, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// Represents a matching the W3C definition that has an hex value of #DEB887. /// public static readonly TColor BurlyWood = ColorBuilder.FromRGBA(222, 184, 135, 255); /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. /// public static readonly TColor CadetBlue = ColorBuilder.FromRGBA(95, 158, 160, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// Represents a matching the W3C definition that has an hex value of #7FFF00. /// public static readonly TColor Chartreuse = ColorBuilder.FromRGBA(127, 255, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// Represents a matching the W3C definition that has an hex value of #D2691E. /// public static readonly TColor Chocolate = ColorBuilder.FromRGBA(210, 105, 30, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// Represents a matching the W3C definition that has an hex value of #FF7F50. /// public static readonly TColor Coral = ColorBuilder.FromRGBA(255, 127, 80, 255); /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// Represents a matching the W3C definition that has an hex value of #6495ED. /// public static readonly TColor CornflowerBlue = ColorBuilder.FromRGBA(100, 149, 237, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. /// public static readonly TColor Cornsilk = ColorBuilder.FromRGBA(255, 248, 220, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// Represents a matching the W3C definition that has an hex value of #DC143C. /// public static readonly TColor Crimson = ColorBuilder.FromRGBA(220, 20, 60, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// Represents a matching the W3C definition that has an hex value of #00FFFF. /// public static readonly TColor Cyan = ColorBuilder.FromRGBA(0, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00008B. + /// Represents a matching the W3C definition that has an hex value of #00008B. /// public static readonly TColor DarkBlue = ColorBuilder.FromRGBA(0, 0, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// Represents a matching the W3C definition that has an hex value of #008B8B. /// public static readonly TColor DarkCyan = ColorBuilder.FromRGBA(0, 139, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// Represents a matching the W3C definition that has an hex value of #B8860B. /// public static readonly TColor DarkGoldenrod = ColorBuilder.FromRGBA(184, 134, 11, 255); /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. /// public static readonly TColor DarkGray = ColorBuilder.FromRGBA(169, 169, 169, 255); /// - /// Represents a matching the W3C definition that has an hex value of #006400. + /// Represents a matching the W3C definition that has an hex value of #006400. /// public static readonly TColor DarkGreen = ColorBuilder.FromRGBA(0, 100, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// Represents a matching the W3C definition that has an hex value of #BDB76B. /// public static readonly TColor DarkKhaki = ColorBuilder.FromRGBA(189, 183, 107, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// Represents a matching the W3C definition that has an hex value of #8B008B. /// public static readonly TColor DarkMagenta = ColorBuilder.FromRGBA(139, 0, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// Represents a matching the W3C definition that has an hex value of #556B2F. /// public static readonly TColor DarkOliveGreen = ColorBuilder.FromRGBA(85, 107, 47, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// Represents a matching the W3C definition that has an hex value of #FF8C00. /// public static readonly TColor DarkOrange = ColorBuilder.FromRGBA(255, 140, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// Represents a matching the W3C definition that has an hex value of #9932CC. /// public static readonly TColor DarkOrchid = ColorBuilder.FromRGBA(153, 50, 204, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// Represents a matching the W3C definition that has an hex value of #8B0000. /// public static readonly TColor DarkRed = ColorBuilder.FromRGBA(139, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// Represents a matching the W3C definition that has an hex value of #E9967A. /// public static readonly TColor DarkSalmon = ColorBuilder.FromRGBA(233, 150, 122, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. /// public static readonly TColor DarkSeaGreen = ColorBuilder.FromRGBA(143, 188, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// Represents a matching the W3C definition that has an hex value of #483D8B. /// public static readonly TColor DarkSlateBlue = ColorBuilder.FromRGBA(72, 61, 139, 255); /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. /// public static readonly TColor DarkSlateGray = ColorBuilder.FromRGBA(47, 79, 79, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// Represents a matching the W3C definition that has an hex value of #00CED1. /// public static readonly TColor DarkTurquoise = ColorBuilder.FromRGBA(0, 206, 209, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// Represents a matching the W3C definition that has an hex value of #9400D3. /// public static readonly TColor DarkViolet = ColorBuilder.FromRGBA(148, 0, 211, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// Represents a matching the W3C definition that has an hex value of #FF1493. /// public static readonly TColor DeepPink = ColorBuilder.FromRGBA(255, 20, 147, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// Represents a matching the W3C definition that has an hex value of #00BFFF. /// public static readonly TColor DeepSkyBlue = ColorBuilder.FromRGBA(0, 191, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #696969. + /// Represents a matching the W3C definition that has an hex value of #696969. /// public static readonly TColor DimGray = ColorBuilder.FromRGBA(105, 105, 105, 255); /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// Represents a matching the W3C definition that has an hex value of #1E90FF. /// public static readonly TColor DodgerBlue = ColorBuilder.FromRGBA(30, 144, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B22222. + /// Represents a matching the W3C definition that has an hex value of #B22222. /// public static readonly TColor Firebrick = ColorBuilder.FromRGBA(178, 34, 34, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. /// public static readonly TColor FloralWhite = ColorBuilder.FromRGBA(255, 250, 240, 255); /// - /// Represents a matching the W3C definition that has an hex value of #228B22. + /// Represents a matching the W3C definition that has an hex value of #228B22. /// public static readonly TColor ForestGreen = ColorBuilder.FromRGBA(34, 139, 34, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// Represents a matching the W3C definition that has an hex value of #FF00FF. /// public static readonly TColor Fuchsia = ColorBuilder.FromRGBA(255, 0, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. /// public static readonly TColor Gainsboro = ColorBuilder.FromRGBA(220, 220, 220, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. /// public static readonly TColor GhostWhite = ColorBuilder.FromRGBA(248, 248, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// Represents a matching the W3C definition that has an hex value of #FFD700. /// public static readonly TColor Gold = ColorBuilder.FromRGBA(255, 215, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// Represents a matching the W3C definition that has an hex value of #DAA520. /// public static readonly TColor Goldenrod = ColorBuilder.FromRGBA(218, 165, 32, 255); /// - /// Represents a matching the W3C definition that has an hex value of #808080. + /// Represents a matching the W3C definition that has an hex value of #808080. /// public static readonly TColor Gray = ColorBuilder.FromRGBA(128, 128, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #008000. + /// Represents a matching the W3C definition that has an hex value of #008000. /// public static readonly TColor Green = ColorBuilder.FromRGBA(0, 128, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. /// public static readonly TColor GreenYellow = ColorBuilder.FromRGBA(173, 255, 47, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. /// public static readonly TColor Honeydew = ColorBuilder.FromRGBA(240, 255, 240, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// Represents a matching the W3C definition that has an hex value of #FF69B4. /// public static readonly TColor HotPink = ColorBuilder.FromRGBA(255, 105, 180, 255); /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. /// public static readonly TColor IndianRed = ColorBuilder.FromRGBA(205, 92, 92, 255); /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// Represents a matching the W3C definition that has an hex value of #4B0082. /// public static readonly TColor Indigo = ColorBuilder.FromRGBA(75, 0, 130, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. /// public static readonly TColor Ivory = ColorBuilder.FromRGBA(255, 255, 240, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// Represents a matching the W3C definition that has an hex value of #F0E68C. /// public static readonly TColor Khaki = ColorBuilder.FromRGBA(240, 230, 140, 255); /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. /// public static readonly TColor Lavender = ColorBuilder.FromRGBA(230, 230, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. /// public static readonly TColor LavenderBlush = ColorBuilder.FromRGBA(255, 240, 245, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// Represents a matching the W3C definition that has an hex value of #7CFC00. /// public static readonly TColor LawnGreen = ColorBuilder.FromRGBA(124, 252, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// Represents a matching the W3C definition that has an hex value of #FFFACD. /// public static readonly TColor LemonChiffon = ColorBuilder.FromRGBA(255, 250, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. /// public static readonly TColor LightBlue = ColorBuilder.FromRGBA(173, 216, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F08080. + /// Represents a matching the W3C definition that has an hex value of #F08080. /// public static readonly TColor LightCoral = ColorBuilder.FromRGBA(240, 128, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. /// public static readonly TColor LightCyan = ColorBuilder.FromRGBA(224, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. /// public static readonly TColor LightGoldenrodYellow = ColorBuilder.FromRGBA(250, 250, 210, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. /// public static readonly TColor LightGray = ColorBuilder.FromRGBA(211, 211, 211, 255); /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// Represents a matching the W3C definition that has an hex value of #90EE90. /// public static readonly TColor LightGreen = ColorBuilder.FromRGBA(144, 238, 144, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. /// public static readonly TColor LightPink = ColorBuilder.FromRGBA(255, 182, 193, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// Represents a matching the W3C definition that has an hex value of #FFA07A. /// public static readonly TColor LightSalmon = ColorBuilder.FromRGBA(255, 160, 122, 255); /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// Represents a matching the W3C definition that has an hex value of #20B2AA. /// public static readonly TColor LightSeaGreen = ColorBuilder.FromRGBA(32, 178, 170, 255); /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// Represents a matching the W3C definition that has an hex value of #87CEFA. /// public static readonly TColor LightSkyBlue = ColorBuilder.FromRGBA(135, 206, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #778899. + /// Represents a matching the W3C definition that has an hex value of #778899. /// public static readonly TColor LightSlateGray = ColorBuilder.FromRGBA(119, 136, 153, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. /// public static readonly TColor LightSteelBlue = ColorBuilder.FromRGBA(176, 196, 222, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. /// public static readonly TColor LightYellow = ColorBuilder.FromRGBA(255, 255, 224, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// Represents a matching the W3C definition that has an hex value of #00FF00. /// public static readonly TColor Lime = ColorBuilder.FromRGBA(0, 255, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// Represents a matching the W3C definition that has an hex value of #32CD32. /// public static readonly TColor LimeGreen = ColorBuilder.FromRGBA(50, 205, 50, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. /// public static readonly TColor Linen = ColorBuilder.FromRGBA(250, 240, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// Represents a matching the W3C definition that has an hex value of #FF00FF. /// public static readonly TColor Magenta = ColorBuilder.FromRGBA(255, 0, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #800000. + /// Represents a matching the W3C definition that has an hex value of #800000. /// public static readonly TColor Maroon = ColorBuilder.FromRGBA(128, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// Represents a matching the W3C definition that has an hex value of #66CDAA. /// public static readonly TColor MediumAquamarine = ColorBuilder.FromRGBA(102, 205, 170, 255); /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// Represents a matching the W3C definition that has an hex value of #0000CD. /// public static readonly TColor MediumBlue = ColorBuilder.FromRGBA(0, 0, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// Represents a matching the W3C definition that has an hex value of #BA55D3. /// public static readonly TColor MediumOrchid = ColorBuilder.FromRGBA(186, 85, 211, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// Represents a matching the W3C definition that has an hex value of #9370DB. /// public static readonly TColor MediumPurple = ColorBuilder.FromRGBA(147, 112, 219, 255); /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// Represents a matching the W3C definition that has an hex value of #3CB371. /// public static readonly TColor MediumSeaGreen = ColorBuilder.FromRGBA(60, 179, 113, 255); /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// Represents a matching the W3C definition that has an hex value of #7B68EE. /// public static readonly TColor MediumSlateBlue = ColorBuilder.FromRGBA(123, 104, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// Represents a matching the W3C definition that has an hex value of #00FA9A. /// public static readonly TColor MediumSpringGreen = ColorBuilder.FromRGBA(0, 250, 154, 255); /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// Represents a matching the W3C definition that has an hex value of #48D1CC. /// public static readonly TColor MediumTurquoise = ColorBuilder.FromRGBA(72, 209, 204, 255); /// - /// Represents a matching the W3C definition that has an hex value of #C71585. + /// Represents a matching the W3C definition that has an hex value of #C71585. /// public static readonly TColor MediumVioletRed = ColorBuilder.FromRGBA(199, 21, 133, 255); /// - /// Represents a matching the W3C definition that has an hex value of #191970. + /// Represents a matching the W3C definition that has an hex value of #191970. /// public static readonly TColor MidnightBlue = ColorBuilder.FromRGBA(25, 25, 112, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. /// public static readonly TColor MintCream = ColorBuilder.FromRGBA(245, 255, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. /// public static readonly TColor MistyRose = ColorBuilder.FromRGBA(255, 228, 225, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. /// public static readonly TColor Moccasin = ColorBuilder.FromRGBA(255, 228, 181, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. /// public static readonly TColor NavajoWhite = ColorBuilder.FromRGBA(255, 222, 173, 255); /// - /// Represents a matching the W3C definition that has an hex value of #000080. + /// Represents a matching the W3C definition that has an hex value of #000080. /// public static readonly TColor Navy = ColorBuilder.FromRGBA(0, 0, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. /// public static readonly TColor OldLace = ColorBuilder.FromRGBA(253, 245, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #808000. + /// Represents a matching the W3C definition that has an hex value of #808000. /// public static readonly TColor Olive = ColorBuilder.FromRGBA(128, 128, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// Represents a matching the W3C definition that has an hex value of #6B8E23. /// public static readonly TColor OliveDrab = ColorBuilder.FromRGBA(107, 142, 35, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// Represents a matching the W3C definition that has an hex value of #FFA500. /// public static readonly TColor Orange = ColorBuilder.FromRGBA(255, 165, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// Represents a matching the W3C definition that has an hex value of #FF4500. /// public static readonly TColor OrangeRed = ColorBuilder.FromRGBA(255, 69, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// Represents a matching the W3C definition that has an hex value of #DA70D6. /// public static readonly TColor Orchid = ColorBuilder.FromRGBA(218, 112, 214, 255); /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. /// public static readonly TColor PaleGoldenrod = ColorBuilder.FromRGBA(238, 232, 170, 255); /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// Represents a matching the W3C definition that has an hex value of #98FB98. /// public static readonly TColor PaleGreen = ColorBuilder.FromRGBA(152, 251, 152, 255); /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. /// public static readonly TColor PaleTurquoise = ColorBuilder.FromRGBA(175, 238, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// Represents a matching the W3C definition that has an hex value of #DB7093. /// public static readonly TColor PaleVioletRed = ColorBuilder.FromRGBA(219, 112, 147, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. /// public static readonly TColor PapayaWhip = ColorBuilder.FromRGBA(255, 239, 213, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. /// public static readonly TColor PeachPuff = ColorBuilder.FromRGBA(255, 218, 185, 255); /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// Represents a matching the W3C definition that has an hex value of #CD853F. /// public static readonly TColor Peru = ColorBuilder.FromRGBA(205, 133, 63, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. /// public static readonly TColor Pink = ColorBuilder.FromRGBA(255, 192, 203, 255); /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. /// public static readonly TColor Plum = ColorBuilder.FromRGBA(221, 160, 221, 255); /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. /// public static readonly TColor PowderBlue = ColorBuilder.FromRGBA(176, 224, 230, 255); /// - /// Represents a matching the W3C definition that has an hex value of #800080. + /// Represents a matching the W3C definition that has an hex value of #800080. /// public static readonly TColor Purple = ColorBuilder.FromRGBA(128, 0, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #663399. + /// Represents a matching the W3C definition that has an hex value of #663399. /// public static readonly TColor RebeccaPurple = ColorBuilder.FromRGBA(102, 51, 153, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// Represents a matching the W3C definition that has an hex value of #FF0000. /// public static readonly TColor Red = ColorBuilder.FromRGBA(255, 0, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. /// public static readonly TColor RosyBrown = ColorBuilder.FromRGBA(188, 143, 143, 255); /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// Represents a matching the W3C definition that has an hex value of #4169E1. /// public static readonly TColor RoyalBlue = ColorBuilder.FromRGBA(65, 105, 225, 255); /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// Represents a matching the W3C definition that has an hex value of #8B4513. /// public static readonly TColor SaddleBrown = ColorBuilder.FromRGBA(139, 69, 19, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// Represents a matching the W3C definition that has an hex value of #FA8072. /// public static readonly TColor Salmon = ColorBuilder.FromRGBA(250, 128, 114, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// Represents a matching the W3C definition that has an hex value of #F4A460. /// public static readonly TColor SandyBrown = ColorBuilder.FromRGBA(244, 164, 96, 255); /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// Represents a matching the W3C definition that has an hex value of #2E8B57. /// public static readonly TColor SeaGreen = ColorBuilder.FromRGBA(46, 139, 87, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. /// public static readonly TColor SeaShell = ColorBuilder.FromRGBA(255, 245, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// Represents a matching the W3C definition that has an hex value of #A0522D. /// public static readonly TColor Sienna = ColorBuilder.FromRGBA(160, 82, 45, 255); /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. /// public static readonly TColor Silver = ColorBuilder.FromRGBA(192, 192, 192, 255); /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// Represents a matching the W3C definition that has an hex value of #87CEEB. /// public static readonly TColor SkyBlue = ColorBuilder.FromRGBA(135, 206, 235, 255); /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. /// public static readonly TColor SlateBlue = ColorBuilder.FromRGBA(106, 90, 205, 255); /// - /// Represents a matching the W3C definition that has an hex value of #708090. + /// Represents a matching the W3C definition that has an hex value of #708090. /// public static readonly TColor SlateGray = ColorBuilder.FromRGBA(112, 128, 144, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. /// public static readonly TColor Snow = ColorBuilder.FromRGBA(255, 250, 250, 255); /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// Represents a matching the W3C definition that has an hex value of #00FF7F. /// public static readonly TColor SpringGreen = ColorBuilder.FromRGBA(0, 255, 127, 255); /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// Represents a matching the W3C definition that has an hex value of #4682B4. /// public static readonly TColor SteelBlue = ColorBuilder.FromRGBA(70, 130, 180, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// Represents a matching the W3C definition that has an hex value of #D2B48C. /// public static readonly TColor Tan = ColorBuilder.FromRGBA(210, 180, 140, 255); /// - /// Represents a matching the W3C definition that has an hex value of #008080. + /// Represents a matching the W3C definition that has an hex value of #008080. /// public static readonly TColor Teal = ColorBuilder.FromRGBA(0, 128, 128, 255); /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. /// public static readonly TColor Thistle = ColorBuilder.FromRGBA(216, 191, 216, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// Represents a matching the W3C definition that has an hex value of #FF6347. /// public static readonly TColor Tomato = ColorBuilder.FromRGBA(255, 99, 71, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. /// public static readonly TColor Transparent = ColorBuilder.FromRGBA(255, 255, 255, 0); /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// Represents a matching the W3C definition that has an hex value of #40E0D0. /// public static readonly TColor Turquoise = ColorBuilder.FromRGBA(64, 224, 208, 255); /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// Represents a matching the W3C definition that has an hex value of #EE82EE. /// public static readonly TColor Violet = ColorBuilder.FromRGBA(238, 130, 238, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. /// public static readonly TColor Wheat = ColorBuilder.FromRGBA(245, 222, 179, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. /// public static readonly TColor White = ColorBuilder.FromRGBA(255, 255, 255, 255); /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. /// public static readonly TColor WhiteSmoke = ColorBuilder.FromRGBA(245, 245, 245, 255); /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// Represents a matching the W3C definition that has an hex value of #FFFF00. /// public static readonly TColor Yellow = ColorBuilder.FromRGBA(255, 255, 0, 255); /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// Represents a matching the W3C definition that has an hex value of #9ACD32. /// public static readonly TColor YellowGreen = ColorBuilder.FromRGBA(154, 205, 50, 255); } diff --git a/src/ImageSharp/Colors/PackedPixel/IPixel.cs b/src/ImageSharp/Colors/PackedPixel/IPixel.cs index 7fbe76bfc..67e013a42 100644 --- a/src/ImageSharp/Colors/PackedPixel/IPixel.cs +++ b/src/ImageSharp/Colors/PackedPixel/IPixel.cs @@ -52,7 +52,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in + /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in /// /// The bytes to set the color in. /// The starting index of the . @@ -60,7 +60,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in + /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// /// The bytes to set the color in. /// The starting index of the . @@ -68,7 +68,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in + /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in /// /// The bytes to set the color in. /// The starting index of the . @@ -76,7 +76,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in + /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// /// The bytes to set the color in. /// The starting index of the . diff --git a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs index 4f6b029dd..949e44cc0 100644 --- a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs +++ b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs @@ -299,7 +299,7 @@ namespace ImageSharp /// The private static bool IsStandardNormalizedType(Type type) { - return type == typeof(Color32) + return type == typeof(Color) || type == typeof(Argb) || type == typeof(Alpha8) || type == typeof(Bgr565) diff --git a/src/ImageSharp/Colors/Spaces/Bgra32.cs b/src/ImageSharp/Colors/Spaces/Bgra32.cs index 33b683d0b..cbd1d6119 100644 --- a/src/ImageSharp/Colors/Spaces/Bgra32.cs +++ b/src/ImageSharp/Colors/Spaces/Bgra32.cs @@ -79,16 +79,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator Bgra32(Color32 color) + public static implicit operator Bgra32(Color color) { return new Bgra32(color.B, color.G, color.R, color.A); } diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index 18e915f54..921158174 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -72,16 +72,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator CieLab(Color32 color) + public static implicit operator CieLab(Color color) { // First convert to CIE XYZ Vector4 vector = color.ToVector4().Expand(); diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index db8f15d58..5bd1eac63 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -63,16 +63,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator CieXyz(Color32 color) + public static implicit operator CieXyz(Color color) { Vector4 vector = color.ToVector4().Expand(); diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index cfbed9aa5..c81a55c0b 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -78,7 +78,7 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -87,7 +87,7 @@ namespace ImageSharp.Colors.Spaces /// /// An instance of . /// - public static implicit operator Cmyk(Color32 color) + public static implicit operator Cmyk(Color color) { float c = 1f - (color.R / 255F); float m = 1f - (color.G / 255F); diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index 1058330a7..1d655ec32 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -70,14 +70,14 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Hsl(Color32 color) + public static implicit operator Hsl(Color color) { float r = color.R / 255F; float g = color.G / 255F; diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index 5c360c9e6..e171c9528 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -70,14 +70,14 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Hsv(Color32 color) + public static implicit operator Hsv(Color color) { float r = color.R / 255F; float g = color.G / 255F; diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index d490375c1..ef9f4462b 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -72,16 +72,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator YCbCr(Color32 color) + public static implicit operator YCbCr(Color color) { byte r = color.R; byte g = color.G; diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index eadc629eb..9f3aa405e 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -32,7 +32,7 @@ namespace ImageSharp /// /// /// - /// The whose signal to expand. + /// The whose signal to expand. /// The . public static Vector4 Expand(this Vector4 gamma) { diff --git a/src/ImageSharp/Image.Create.cs b/src/ImageSharp/Image.Create.cs index 1b54c427a..fcecefd7b 100644 --- a/src/ImageSharp/Image.Create.cs +++ b/src/ImageSharp/Image.Create.cs @@ -29,12 +29,12 @@ namespace ImageSharp /// The configuration providing initialization code which allows extending the library. /// /// - /// A new unless is in which case it returns + /// A new unless is in which case it returns /// internal static Image Create(int width, int height, ImageMetaData metadata, Configuration configuration) where TColor : struct, IPixel { - if (typeof(TColor) == typeof(Color32)) + if (typeof(TColor) == typeof(Color)) { return new Image(width, height, metadata, configuration) as Image; } @@ -55,7 +55,7 @@ namespace ImageSharp /// The configuration providing initialization code which allows extending the library. /// /// - /// A new unless is in which case it returns + /// A new unless is in which case it returns /// internal static Image Create(int width, int height, Configuration configuration) where TColor : struct, IPixel diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 7c6062bea..40cdfe3ef 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -83,7 +83,7 @@ namespace ImageSharp /// The image public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) { - return new Image(Load(path, decoder, options)); + return new Image(Load(path, decoder, options)); } /// diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index 0f0493a5e..112b8a109 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -83,7 +83,7 @@ namespace ImageSharp /// The image public static Image Load(Configuration config, Stream stream, IDecoderOptions options) { - Image image = Load(config, stream, options); + Image image = Load(config, stream, options); return image as Image ?? new Image(image); } @@ -100,7 +100,7 @@ namespace ImageSharp /// The image public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) { - Image image = new Image(Load(stream, decoder, options)); + Image image = new Image(Load(stream, decoder, options)); return image as Image ?? new Image(image); } diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index e681bfc0e..00688afc9 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -16,7 +16,7 @@ namespace ImageSharp /// packed into a single unsigned integer value. /// [DebuggerDisplay("Image: {Width}x{Height}")] - public sealed partial class Image : Image + public sealed partial class Image : Image { /// /// Initializes a new instance of the class @@ -49,7 +49,7 @@ namespace ImageSharp /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + public Image(Image other) : base(other) { } diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs index e0e72a2a1..c75da0003 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs @@ -75,7 +75,7 @@ namespace ImageSharp.Processing.Processors /// The matrix. /// Whether to compand the color during processing. /// - /// The . + /// The . /// private TColor ApplyMatrix(TColor color, Matrix4x4 matrix, bool compand) { diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer.cs b/src/ImageSharp/Quantizers/PaletteQuantizer.cs index 30d3a9026..f039fe0c5 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer.cs +++ b/src/ImageSharp/Quantizers/PaletteQuantizer.cs @@ -44,7 +44,7 @@ namespace ImageSharp.Quantizers { if (palette == null) { - Color32[] constants = Color32Constants.WebSafeColors; + Color[] constants = ColorConstants.WebSafeColors; TColor[] safe = new TColor[constants.Length + 1]; for (int i = 0; i < constants.Length; i++) diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs index 135616a5d..befff61d5 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -14,7 +14,7 @@ /// public unsafe class PackFromVector4ReferenceVsPointer { - private Buffer destination; + private Buffer destination; private Buffer source; @@ -24,7 +24,7 @@ [Setup] public void Setup() { - this.destination = new Buffer(this.Count); + this.destination = new Buffer(this.Count); this.source = new Buffer(this.Count * 4); this.source.Pin(); this.destination.Pin(); @@ -43,12 +43,12 @@ Vector4* sp = (Vector4*)this.source.Pin(); byte* dp = (byte*)this.destination.Pin(); int count = this.Count; - int size = sizeof(ImageSharp.Color32); + int size = sizeof(ImageSharp.Color); for (int i = 0; i < count; i++) { Vector4 v = Unsafe.Read(sp); - ImageSharp.Color32 c = default(ImageSharp.Color32); + ImageSharp.Color c = default(ImageSharp.Color); c.PackFromVector4(v); Unsafe.Write(dp, c); @@ -61,7 +61,7 @@ public void PackUsingReferences() { ref Vector4 sp = ref this.source.Array[0]; - ref ImageSharp.Color32 dp = ref this.destination.Array[0]; + ref ImageSharp.Color dp = ref this.destination.Array[0]; int count = this.Count; for (int i = 0; i < count; i++) diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 15f83eb58..33969b8fb 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -3,7 +3,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color32 = ImageSharp.Color32; + using Color = ImageSharp.Color; public abstract class PackFromXyzw where TColor : struct, IPixel @@ -57,7 +57,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class PackFromXyzw_Color : PackFromXyzw + public class PackFromXyzw_Color : PackFromXyzw { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index 21bc668b7..4cabfc01f 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -55,7 +55,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToVector4_Color : ToVector4 + public class ToVector4_Color : ToVector4 { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index d398b4eaa..f6ae4256d 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -3,7 +3,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color32 = ImageSharp.Color32; + using Color = ImageSharp.Color; public abstract class ToXyz where TColor : struct, IPixel @@ -55,7 +55,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToXyz_Color : ToXyz + public class ToXyz_Color : ToXyz { } } \ 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 03103f769..05fc4094e 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color32 = ImageSharp.Color32; + using Color = ImageSharp.Color; public abstract class ToXyzw where TColor : struct, IPixel @@ -60,7 +60,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToXyzw_Color : ToXyzw + public class ToXyzw_Color : ToXyzw { } diff --git a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs index 4e75c94ac..3ee28d06b 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Benchmarks { using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using SystemColor = System.Drawing.Color; public class ColorEquality diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index 69945cf89..3e60cae4d 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index b0ea1bf7f..ee97866e2 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 99ae6d538..047cacb42 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using System.IO; using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index 7a2ced766..782306deb 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -13,7 +13,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreImage = ImageSharp.Image; public class FillPolygon : BenchmarkBase diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 2a677b5f8..691955e8e 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CoreRectangle = ImageSharp.Rectangle; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreSize = ImageSharp.Size; using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index 8667573c6..dcd22d6fb 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreImage = ImageSharp.Image; public class FillWithPattern diff --git a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs index 180067020..c7a2021de 100644 --- a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs +++ b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs @@ -7,11 +7,11 @@ namespace ImageSharp.Benchmarks.General using BenchmarkDotNet.Attributes; - using Color32 = ImageSharp.Color32; + using Color = ImageSharp.Color; public unsafe class ClearBuffer { - private Buffer buffer; + private Buffer buffer; [Params(32, 128, 512)] public int Count { get; set; } @@ -19,7 +19,7 @@ namespace ImageSharp.Benchmarks.General [Setup] public void Setup() { - this.buffer = new Buffer(this.Count); + this.buffer = new Buffer(this.Count); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index b226c2611..335d8247d 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreImage = ImageSharp.Image; public class CopyPixels : BenchmarkBase diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index c7f1040fd..1318c1674 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -51,7 +51,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new OctreeQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new OctreeQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -62,7 +62,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new OctreeQuantizer { Dither = false }, Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new OctreeQuantizer { Dither = false }, Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -73,7 +73,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -84,7 +84,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer { Dither = false }, Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer { Dither = false }, Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -95,7 +95,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new WuQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new WuQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index 5740e0561..4c1feb6c2 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -66,10 +66,10 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - Quantizer quantizer = this.UseOctreeQuantizer - ? (Quantizer) - new OctreeQuantizer() - : new PaletteQuantizer(); + Quantizer quantizer = this.UseOctreeQuantizer + ? (Quantizer) + new OctreeQuantizer() + : new PaletteQuantizer(); PngEncoderOptions options = new PngEncoderOptions() { Quantizer = quantizer }; this.bmpCore.SaveAsPng(memoryStream, options); diff --git a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs index 801acd1c7..78295e27d 100644 --- a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color32; + using CoreColor = ImageSharp.Color; using CoreImage = ImageSharp.Image; using SystemColor = System.Drawing.Color; diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index c82990134..569070af2 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreSize = ImageSharp.Size; using CoreImage = ImageSharp.Image; - using CoreVectorImage = ImageSharp.Image; + using CoreVectorImage = ImageSharp.Image; public class Resize : BenchmarkBase { diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs index d1775a893..0b1e6dc7b 100644 --- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs @@ -10,7 +10,7 @@ namespace ImageSharp.Tests.Colors public class BulkPixelOperationsTests { - public class Color32 : BulkPixelOperationsTests + public class Color32 : BulkPixelOperationsTests { public Color32(ITestOutputHelper output) : base(output) @@ -23,19 +23,19 @@ namespace ImageSharp.Tests.Colors [Fact] public void IsSpecialImplementation() { - Assert.IsType(BulkPixelOperations.Instance); + Assert.IsType(BulkPixelOperations.Instance); } [Fact] public void ToVector4SimdAligned() { - ImageSharp.Color32[] source = CreatePixelTestData(64); + ImageSharp.Color[] source = CreatePixelTestData(64); Vector4[] expected = CreateExpectedVector4Data(source); TestOperation( source, expected, - (s, d) => ImageSharp.Color32.BulkOperations.ToVector4SimdAligned(s, d, 64) + (s, d) => ImageSharp.Color.BulkOperations.ToVector4SimdAligned(s, d, 64) ); } @@ -45,14 +45,14 @@ namespace ImageSharp.Tests.Colors int times = 200000; int count = 1024; - using (Buffer source = new Buffer(count)) + using (Buffer source = new Buffer(count)) using (Buffer dest = new Buffer(count)) { this.Measure( times, () => { - BulkPixelOperations.Instance.ToVector4(source, dest, count); + BulkPixelOperations.Instance.ToVector4(source, dest, count); }); } } diff --git a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs index 74214056e..9ed1c67a7 100644 --- a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests public class ColorConversionTests { /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -28,7 +28,7 @@ namespace ImageSharp.Tests public void ColorToYCbCr() { // White - Color32 color = Color32.White; + Color color = Color.White; YCbCr yCbCr = color; Assert.Equal(255, yCbCr.Y); @@ -36,14 +36,14 @@ namespace ImageSharp.Tests Assert.Equal(128, yCbCr.Cr); // Black - Color32 color2 = Color32.Black; + Color color2 = Color.Black; YCbCr yCbCr2 = color2; Assert.Equal(0, yCbCr2.Y); Assert.Equal(128, yCbCr2.Cb); Assert.Equal(128, yCbCr2.Cr); // Gray - Color32 color3 = Color32.Gray; + Color color3 = Color.Gray; YCbCr yCbCr3 = color3; Assert.Equal(128, yCbCr3.Y); Assert.Equal(128, yCbCr3.Cb); @@ -51,7 +51,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -60,7 +60,7 @@ namespace ImageSharp.Tests { // White YCbCr yCbCr = new YCbCr(255, 128, 128); - Color32 color = yCbCr; + Color color = yCbCr; Assert.Equal(255, color.R); Assert.Equal(255, color.G); @@ -69,7 +69,7 @@ namespace ImageSharp.Tests // Black YCbCr yCbCr2 = new YCbCr(0, 128, 128); - Color32 color2 = yCbCr2; + Color color2 = yCbCr2; Assert.Equal(0, color2.R); Assert.Equal(0, color2.G); @@ -78,7 +78,7 @@ namespace ImageSharp.Tests // Gray YCbCr yCbCr3 = new YCbCr(128, 128, 128); - Color32 color3 = yCbCr3; + Color color3 = yCbCr3; Assert.Equal(128, color3.R); Assert.Equal(128, color3.G); @@ -87,7 +87,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-xyz /// @@ -95,7 +95,7 @@ namespace ImageSharp.Tests public void ColorToCieXyz() { // White - Color32 color = Color32.White; + Color color = Color.White; CieXyz ciexyz = color; Assert.Equal(95.05f, ciexyz.X, 3); @@ -103,21 +103,21 @@ namespace ImageSharp.Tests Assert.Equal(108.900f, ciexyz.Z, 3); // Black - Color32 color2 = Color32.Black; + Color color2 = Color.Black; CieXyz ciexyz2 = color2; Assert.Equal(0, ciexyz2.X, 3); Assert.Equal(0, ciexyz2.Y, 3); Assert.Equal(0, ciexyz2.Z, 3); // Gray - Color32 color3 = Color32.Gray; + Color color3 = Color.Gray; CieXyz ciexyz3 = color3; Assert.Equal(20.518, ciexyz3.X, 3); Assert.Equal(21.586, ciexyz3.Y, 3); Assert.Equal(23.507, ciexyz3.Z, 3); // Cyan - Color32 color4 = Color32.Cyan; + Color color4 = Color.Cyan; CieXyz ciexyz4 = color4; Assert.Equal(53.810f, ciexyz4.X, 3); Assert.Equal(78.740f, ciexyz4.Y, 3); @@ -125,7 +125,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-xyz /// @@ -134,7 +134,7 @@ namespace ImageSharp.Tests { // Dark moderate pink. CieXyz ciexyz = new CieXyz(13.337f, 9.297f, 14.727f); - Color32 color = ciexyz; + Color color = ciexyz; Assert.Equal(128, color.R); Assert.Equal(64, color.G); @@ -142,7 +142,7 @@ namespace ImageSharp.Tests // Ochre CieXyz ciexyz2 = new CieXyz(31.787f, 26.147f, 4.885f); - Color32 color2 = ciexyz2; + Color color2 = ciexyz2; Assert.Equal(204, color2.R); Assert.Equal(119, color2.G); @@ -150,7 +150,7 @@ namespace ImageSharp.Tests // Black CieXyz ciexyz3 = new CieXyz(0, 0, 0); - Color32 color3 = ciexyz3; + Color color3 = ciexyz3; Assert.Equal(0, color3.R); Assert.Equal(0, color3.G); @@ -167,7 +167,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -175,7 +175,7 @@ namespace ImageSharp.Tests public void ColorToHsv() { // Black - Color32 b = Color32.Black; + Color b = Color.Black; Hsv h = b; Assert.Equal(0, h.H, 1); @@ -183,7 +183,7 @@ namespace ImageSharp.Tests Assert.Equal(0, h.V, 1); // White - Color32 color = Color32.White; + Color color = Color.White; Hsv hsv = color; Assert.Equal(0f, hsv.H, 1); @@ -191,7 +191,7 @@ namespace ImageSharp.Tests Assert.Equal(1f, hsv.V, 1); // Dark moderate pink. - Color32 color2 = new Color32(128, 64, 106); + Color color2 = new Color(128, 64, 106); Hsv hsv2 = color2; Assert.Equal(320.6f, hsv2.H, 1); @@ -199,7 +199,7 @@ namespace ImageSharp.Tests Assert.Equal(0.502f, hsv2.V, 2); // Ochre. - Color32 color3 = new Color32(204, 119, 34); + Color color3 = new Color(204, 119, 34); Hsv hsv3 = color3; Assert.Equal(30f, hsv3.H, 1); @@ -208,14 +208,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void HsvToColor() { // Dark moderate pink. Hsv hsv = new Hsv(320.6f, 0.5f, 0.502f); - Color32 color = hsv; + Color color = hsv; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -223,7 +223,7 @@ namespace ImageSharp.Tests // Ochre Hsv hsv2 = new Hsv(30, 0.833f, 0.8f); - Color32 color2 = hsv2; + Color color2 = hsv2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -231,7 +231,7 @@ namespace ImageSharp.Tests // White Hsv hsv3 = new Hsv(0, 0, 1); - Color32 color3 = hsv3; + Color color3 = hsv3; Assert.Equal(color3.B, 255); Assert.Equal(color3.G, 255); @@ -248,7 +248,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -256,7 +256,7 @@ namespace ImageSharp.Tests public void ColorToHsl() { // Black - Color32 b = Color32.Black; + Color b = Color.Black; Hsl h = b; Assert.Equal(0, h.H, 1); @@ -264,7 +264,7 @@ namespace ImageSharp.Tests Assert.Equal(0, h.L, 1); // White - Color32 color = Color32.White; + Color color = Color.White; Hsl hsl = color; Assert.Equal(0f, hsl.H, 1); @@ -272,7 +272,7 @@ namespace ImageSharp.Tests Assert.Equal(1f, hsl.L, 1); // Dark moderate pink. - Color32 color2 = new Color32(128, 64, 106); + Color color2 = new Color(128, 64, 106); Hsl hsl2 = color2; Assert.Equal(320.6f, hsl2.H, 1); @@ -280,7 +280,7 @@ namespace ImageSharp.Tests Assert.Equal(0.376f, hsl2.L, 2); // Ochre. - Color32 color3 = new Color32(204, 119, 34); + Color color3 = new Color(204, 119, 34); Hsl hsl3 = color3; Assert.Equal(30f, hsl3.H, 1); @@ -289,14 +289,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void HslToColor() { // Dark moderate pink. Hsl hsl = new Hsl(320.6f, 0.33f, 0.376f); - Color32 color = hsl; + Color color = hsl; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -304,7 +304,7 @@ namespace ImageSharp.Tests // Ochre Hsl hsl2 = new Hsl(30, 0.714f, 0.467f); - Color32 color2 = hsl2; + Color color2 = hsl2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -312,7 +312,7 @@ namespace ImageSharp.Tests // White Hsl hsl3 = new Hsl(0, 0, 1); - Color32 color3 = hsl3; + Color color3 = hsl3; Assert.Equal(color3.R, 255); Assert.Equal(color3.G, 255); @@ -329,7 +329,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -337,7 +337,7 @@ namespace ImageSharp.Tests public void ColorToCmyk() { // White - Color32 color = Color32.White; + Color color = Color.White; Cmyk cmyk = color; Assert.Equal(0, cmyk.C, 1); @@ -346,7 +346,7 @@ namespace ImageSharp.Tests Assert.Equal(0, cmyk.K, 1); // Black - Color32 color2 = Color32.Black; + Color color2 = Color.Black; Cmyk cmyk2 = color2; Assert.Equal(0, cmyk2.C, 1); Assert.Equal(0, cmyk2.M, 1); @@ -354,7 +354,7 @@ namespace ImageSharp.Tests Assert.Equal(1, cmyk2.K, 1); // Gray - Color32 color3 = Color32.Gray; + Color color3 = Color.Gray; Cmyk cmyk3 = color3; Assert.Equal(0f, cmyk3.C, 1); Assert.Equal(0f, cmyk3.M, 1); @@ -362,7 +362,7 @@ namespace ImageSharp.Tests Assert.Equal(0.498, cmyk3.K, 2); // Checked with other online converters. // Cyan - Color32 color4 = Color32.Cyan; + Color color4 = Color.Cyan; Cmyk cmyk4 = color4; Assert.Equal(1, cmyk4.C, 1); Assert.Equal(0f, cmyk4.M, 1); @@ -371,14 +371,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void CmykToColor() { // Dark moderate pink. Cmyk cmyk = new Cmyk(0f, .5f, .171f, .498f); - Color32 color = cmyk; + Color color = cmyk; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -386,7 +386,7 @@ namespace ImageSharp.Tests // Ochre Cmyk cmyk2 = new Cmyk(0, .416f, .833f, .199f); - Color32 color2 = cmyk2; + Color color2 = cmyk2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -394,7 +394,7 @@ namespace ImageSharp.Tests // White Cmyk cmyk3 = new Cmyk(0, 0, 0, 0); - Color32 color3 = cmyk3; + Color color3 = cmyk3; Assert.Equal(color3.R, 255); Assert.Equal(color3.G, 255); @@ -411,7 +411,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-lab /// @@ -419,7 +419,7 @@ namespace ImageSharp.Tests public void ColorToCieLab() { // White - Color32 color = Color32.White; + Color color = Color.White; CieLab cielab = color; Assert.Equal(100, cielab.L, 3); @@ -427,21 +427,21 @@ namespace ImageSharp.Tests Assert.Equal(-0.010, cielab.B, 3); // Black - Color32 color2 = Color32.Black; + Color color2 = Color.Black; CieLab cielab2 = color2; Assert.Equal(0, cielab2.L, 3); Assert.Equal(0, cielab2.A, 3); Assert.Equal(0, cielab2.B, 3); // Gray - Color32 color3 = Color32.Gray; + Color color3 = Color.Gray; CieLab cielab3 = color3; Assert.Equal(53.585, cielab3.L, 3); Assert.Equal(0.003, cielab3.A, 3); Assert.Equal(-0.006, cielab3.B, 3); // Cyan - Color32 color4 = Color32.Cyan; + Color color4 = Color.Cyan; CieLab cielab4 = color4; Assert.Equal(91.117, cielab4.L, 3); Assert.Equal(-48.080, cielab4.A, 3); @@ -449,7 +449,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-lab @@ -458,7 +458,7 @@ namespace ImageSharp.Tests { // Dark moderate pink. CieLab cielab = new CieLab(36.5492f, 33.3173f, -12.0615f); - Color32 color = cielab; + Color color = cielab; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -466,7 +466,7 @@ namespace ImageSharp.Tests // Ochre CieLab cielab2 = new CieLab(58.1758f, 27.3399f, 56.8240f); - Color32 color2 = cielab2; + Color color2 = cielab2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -474,7 +474,7 @@ namespace ImageSharp.Tests // Black CieLab cielab3 = new CieLab(0, 0, 0); - Color32 color3 = cielab3; + Color color3 = cielab3; Assert.Equal(color3.R, 0); Assert.Equal(color3.G, 0); diff --git a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs b/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs index dc0555f1f..899ce4f77 100644 --- a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs @@ -15,14 +15,14 @@ namespace ImageSharp.Tests using Xunit; public class ColorDefinitionTests { - public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name }); + public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name }); [Theory] [MemberData(nameof(ColorNames))] public void AllColorsAreOnGenericAndBaseColor(string name) { - FieldInfo generic = typeof(NamedColors).GetTypeInfo().GetField(name); - FieldInfo specific = typeof(Color32).GetTypeInfo().GetField(name); + FieldInfo generic = typeof(NamedColors).GetTypeInfo().GetField(name); + FieldInfo specific = typeof(Color).GetTypeInfo().GetField(name); Assert.NotNull(specific); Assert.NotNull(generic); @@ -30,8 +30,8 @@ namespace ImageSharp.Tests Assert.True(specific.Attributes.HasFlag(FieldAttributes.Static), "specific must be static"); Assert.True(generic.Attributes.HasFlag(FieldAttributes.Public), "generic must be public"); Assert.True(generic.Attributes.HasFlag(FieldAttributes.Static), "generic must be static"); - Color32 expected = (Color32)generic.GetValue(null); - Color32 actual = (Color32)specific.GetValue(null); + Color expected = (Color)generic.GetValue(null); + Color actual = (Color)specific.GetValue(null); Assert.Equal(expected, actual); } } diff --git a/tests/ImageSharp.Tests/Colors/ColorTests.cs b/tests/ImageSharp.Tests/Colors/ColorTests.cs index 97f9231ba..312e66466 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorTests.cs @@ -11,7 +11,7 @@ namespace ImageSharp.Tests using Xunit; /// - /// Tests the struct. + /// Tests the struct. /// public class ColorTests { @@ -21,12 +21,12 @@ namespace ImageSharp.Tests [Fact] public void AreEqual() { - Color32 color1 = new Color32(0, 0, 0); - Color32 color2 = new Color32(0, 0, 0, 1F); - Color32 color3 = Color32.FromHex("#000"); - Color32 color4 = Color32.FromHex("#000F"); - Color32 color5 = Color32.FromHex("#000000"); - Color32 color6 = Color32.FromHex("#000000FF"); + Color color1 = new Color(0, 0, 0); + Color color2 = new Color(0, 0, 0, 1F); + Color color3 = Color.FromHex("#000"); + Color color4 = Color.FromHex("#000F"); + Color color5 = Color.FromHex("#000000"); + Color color6 = Color.FromHex("#000000FF"); Assert.Equal(color1, color2); Assert.Equal(color1, color3); @@ -41,11 +41,11 @@ namespace ImageSharp.Tests [Fact] public void AreNotEqual() { - Color32 color1 = new Color32(255, 0, 0, 255); - Color32 color2 = new Color32(0, 0, 0, 255); - Color32 color3 = Color32.FromHex("#000"); - Color32 color4 = Color32.FromHex("#000000"); - Color32 color5 = Color32.FromHex("#FF000000"); + Color color1 = new Color(255, 0, 0, 255); + Color color2 = new Color(0, 0, 0, 255); + Color color3 = Color.FromHex("#000"); + Color color4 = Color.FromHex("#000000"); + Color color5 = Color.FromHex("#FF000000"); Assert.NotEqual(color1, color2); Assert.NotEqual(color1, color3); @@ -59,25 +59,25 @@ namespace ImageSharp.Tests [Fact] public void ConstructorAssignsProperties() { - Color32 color1 = new Color32(1, .1f, .133f, .864f); + Color color1 = new Color(1, .1f, .133f, .864f); Assert.Equal(255, color1.R); Assert.Equal((byte)Math.Round(.1f * 255), color1.G); Assert.Equal((byte)Math.Round(.133f * 255), color1.B); Assert.Equal((byte)Math.Round(.864f * 255), color1.A); - Color32 color2 = new Color32(1, .1f, .133f); + Color color2 = new Color(1, .1f, .133f); Assert.Equal(255, color2.R); Assert.Equal(Math.Round(.1f * 255), color2.G); Assert.Equal(Math.Round(.133f * 255), color2.B); Assert.Equal(255, color2.A); - Color32 color4 = new Color32(new Vector3(1, .1f, .133f)); + Color color4 = new Color(new Vector3(1, .1f, .133f)); Assert.Equal(255, color4.R); Assert.Equal(Math.Round(.1f * 255), color4.G); Assert.Equal(Math.Round(.133f * 255), color4.B); Assert.Equal(255, color4.A); - Color32 color5 = new Color32(new Vector4(1, .1f, .133f, .5f)); + Color color5 = new Color(new Vector4(1, .1f, .133f, .5f)); Assert.Equal(255, color5.R); Assert.Equal(Math.Round(.1f * 255), color5.G); Assert.Equal(Math.Round(.133f * 255), color5.B); @@ -90,7 +90,7 @@ namespace ImageSharp.Tests [Fact] public void FromAndToHex() { - Color32 color = Color32.FromHex("#AABBCCDD"); + Color color = Color.FromHex("#AABBCCDD"); Assert.Equal(170, color.R); Assert.Equal(187, color.G); Assert.Equal(204, color.B); @@ -118,7 +118,7 @@ namespace ImageSharp.Tests [Fact] public unsafe void ByteLayout() { - Color32 color = new Color32(1, 2, 3, 4); + Color color = new Color(1, 2, 3, 4); byte* colorBase = (byte*)&color; Assert.Equal(1, colorBase[0]); Assert.Equal(2, colorBase[1]); diff --git a/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs b/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs index 1d655e880..064bdf2d0 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs @@ -16,101 +16,101 @@ namespace ImageSharp.Tests.Colors /// /// Orange backdrop /// - private static readonly Color32 Backdrop = new Color32(204, 102, 0); + private static readonly Color Backdrop = new Color(204, 102, 0); /// /// Blue source /// - private static readonly Color32 Source = new Color32(0, 102, 153); + private static readonly Color Source = new Color(0, 102, 153); [Fact] public void Normal() { - Color32 normal = Color32.Normal(Backdrop, Source); + Color normal = Color.Normal(Backdrop, Source); Assert.True(normal == Source); } [Fact] public void Multiply() { - Assert.True(Color32.Multiply(Backdrop, Color32.Black) == Color32.Black); - Assert.True(Color32.Multiply(Backdrop, Color32.White) == Backdrop); + Assert.True(Color.Multiply(Backdrop, Color.Black) == Color.Black); + Assert.True(Color.Multiply(Backdrop, Color.White) == Backdrop); - Color32 multiply = Color32.Multiply(Backdrop, Source); - Assert.True(multiply == new Color32(0, 41, 0)); + Color multiply = Color.Multiply(Backdrop, Source); + Assert.True(multiply == new Color(0, 41, 0)); } [Fact] public void Screen() { - Assert.True(Color32.Screen(Backdrop, Color32.Black) == Backdrop); - Assert.True(Color32.Screen(Backdrop, Color32.White) == Color32.White); + Assert.True(Color.Screen(Backdrop, Color.Black) == Backdrop); + Assert.True(Color.Screen(Backdrop, Color.White) == Color.White); - Color32 screen = Color32.Screen(Backdrop, Source); - Assert.True(screen == new Color32(204, 163, 153)); + Color screen = Color.Screen(Backdrop, Source); + Assert.True(screen == new Color(204, 163, 153)); } [Fact] public void HardLight() { - Color32 hardLight = Color32.HardLight(Backdrop, Source); - Assert.True(hardLight == new Color32(0, 82, 51)); + Color hardLight = Color.HardLight(Backdrop, Source); + Assert.True(hardLight == new Color(0, 82, 51)); } [Fact] public void Overlay() { - Color32 overlay = Color32.Overlay(Backdrop, Source); - Assert.True(overlay == new Color32(153, 82, 0)); + Color overlay = Color.Overlay(Backdrop, Source); + Assert.True(overlay == new Color(153, 82, 0)); } [Fact] public void Darken() { - Color32 darken = Color32.Darken(Backdrop, Source); - Assert.True(darken == new Color32(0, 102, 0)); + Color darken = Color.Darken(Backdrop, Source); + Assert.True(darken == new Color(0, 102, 0)); } [Fact] public void Lighten() { - Color32 lighten = Color32.Lighten(Backdrop, Source); - Assert.True(lighten == new Color32(204, 102, 153)); + Color lighten = Color.Lighten(Backdrop, Source); + Assert.True(lighten == new Color(204, 102, 153)); } [Fact] public void SoftLight() { - Color32 softLight = Color32.SoftLight(Backdrop, Source); - Assert.True(softLight == new Color32(163, 90, 0)); + Color softLight = Color.SoftLight(Backdrop, Source); + Assert.True(softLight == new Color(163, 90, 0)); } [Fact] public void ColorDodge() { - Color32 colorDodge = Color32.ColorDodge(Backdrop, Source); - Assert.True(colorDodge == new Color32(204, 170, 0)); + Color colorDodge = Color.ColorDodge(Backdrop, Source); + Assert.True(colorDodge == new Color(204, 170, 0)); } [Fact] public void ColorBurn() { - Color32 colorBurn = Color32.ColorBurn(Backdrop, Source); - Assert.True(colorBurn == new Color32(0, 0, 0)); + Color colorBurn = Color.ColorBurn(Backdrop, Source); + Assert.True(colorBurn == new Color(0, 0, 0)); } [Fact] public void Difference() { - Color32 difference = Color32.Difference(Backdrop, Source); - Assert.True(difference == new Color32(204, 0, 153)); + Color difference = Color.Difference(Backdrop, Source); + Assert.True(difference == new Color(204, 0, 153)); } [Fact] public void Exclusion() { - Color32 exclusion = Color32.Exclusion(Backdrop, Source); - Assert.True(exclusion == new Color32(204, 122, 153)); + Color exclusion = Color.Exclusion(Backdrop, Source); + Assert.True(exclusion == new Color(204, 122, 153)); } } } diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index aa3eb2797..ebf3a866a 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -412,12 +412,12 @@ namespace ImageSharp.Tests.Common [Fact] public void Color32ToBytes() { - Color32[] colors = { new Color32(0, 1, 2, 3), new Color32(4, 5, 6, 7), new Color32(8, 9, 10, 11), }; + Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), }; - using (Buffer colorBuf = new Buffer(colors)) + using (Buffer colorBuf = new Buffer(colors)) using (Buffer byteBuf = new Buffer(colors.Length * 4)) { - BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Color32)); + BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Color)); byte[] a = byteBuf.Array; diff --git a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs index 78d1ca4b0..403dffba9 100644 --- a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs +++ b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests [Fact] public void PixelDataPoolRentsMinimumSize() { - Color32[] pixels = PixelDataPool.Rent(1024); + Color[] pixels = PixelDataPool.Rent(1024); Assert.True(pixels.Length >= 1024); } @@ -26,9 +26,9 @@ namespace ImageSharp.Tests [Fact] public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() { - Color32[] pixels = new Color32[1024]; + Color[] pixels = new Color[1024]; - PixelDataPool.Return(pixels); + PixelDataPool.Return(pixels); Assert.True(pixels.Length >= 1024); } @@ -39,7 +39,7 @@ namespace ImageSharp.Tests public void CalculateMaxArrayLength(bool isRawData) { int max = isRawData ? PixelDataPool.CalculateMaxArrayLength() - : PixelDataPool.CalculateMaxArrayLength(); + : PixelDataPool.CalculateMaxArrayLength(); Assert.Equal(max < int.MaxValue, !isRawData); } diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index 3335fd070..a1d4d3fd5 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -23,8 +23,8 @@ namespace ImageSharp.Tests.Drawing { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { - image.BackgroundColor(Color32.Blue) - .DrawBeziers(Color32.HotPink, 5, + image.BackgroundColor(Color.Blue) + .DrawBeziers(Color.HotPink, 5, new[] { new Vector2(10, 400), new Vector2(30, 10), @@ -34,21 +34,21 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve - Assert.Equal(Color32.HotPink, sourcePixels[138, 115]); + Assert.Equal(Color.HotPink, sourcePixels[138, 115]); //start points - Assert.Equal(Color32.HotPink, sourcePixels[10, 400]); - Assert.Equal(Color32.HotPink, sourcePixels[300, 400]); + Assert.Equal(Color.HotPink, sourcePixels[10, 400]); + Assert.Equal(Color.HotPink, sourcePixels[300, 400]); //curve points should not be never be set - Assert.Equal(Color32.Blue, sourcePixels[30, 10]); - Assert.Equal(Color32.Blue, sourcePixels[240, 30]); + Assert.Equal(Color.Blue, sourcePixels[30, 10]); + Assert.Equal(Color.Blue, sourcePixels[240, 30]); // inside shape should be empty - Assert.Equal(Color32.Blue, sourcePixels[200, 250]); + Assert.Equal(Color.Blue, sourcePixels[200, 250]); } } } @@ -59,13 +59,13 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "BezierLine"); - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { - image.BackgroundColor(Color32.Blue) + image.BackgroundColor(Color.Blue) .DrawBeziers(color, 10, new[] { @@ -78,9 +78,9 @@ namespace ImageSharp.Tests.Drawing } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve Assert.Equal(mergedColor, sourcePixels[138, 115]); @@ -90,11 +90,11 @@ namespace ImageSharp.Tests.Drawing Assert.Equal(mergedColor, sourcePixels[300, 400]); //curve points should not be never be set - Assert.Equal(Color32.Blue, sourcePixels[30, 10]); - Assert.Equal(Color32.Blue, sourcePixels[240, 30]); + Assert.Equal(Color.Blue, sourcePixels[30, 10]); + Assert.Equal(Color.Blue, sourcePixels[240, 30]); // inside shape should be empty - Assert.Equal(Color32.Blue, sourcePixels[200, 250]); + Assert.Equal(Color.Blue, sourcePixels[200, 250]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index 9b5a10b32..fc231a89d 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -38,18 +38,18 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .Draw(Color32.HotPink, 5, p) + .BackgroundColor(Color.Blue) + .Draw(Color.HotPink, 5, p) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } } @@ -60,7 +60,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Path"); - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); LinearLineSegment linerSegemnt = new LinearLineSegment( @@ -81,21 +81,21 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .Draw(color, 10, p) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index c0c7e9c95..8162bc531 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests.Drawing public class FillPatternBrushTests : FileTestBase { - private void Test(string name, Color32 background, IBrush brush, Color32[,] expectedPattern) + private void Test(string name, Color background, IBrush brush, Color[,] expectedPattern) { string path = this.CreateOutputDirectory("Fill", "PatternBrush"); using (Image image = new Image(20, 20)) @@ -29,11 +29,11 @@ namespace ImageSharp.Tests.Drawing image.Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { // lets pick random spots to start checking Random r = new Random(); - Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); + Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); int xStride = expectedPatternFast.Width; int yStride = expectedPatternFast.Height; int offsetX = r.Next(image.Width / xStride) * xStride; @@ -44,8 +44,8 @@ namespace ImageSharp.Tests.Drawing { int actualX = x + offsetX; int actualY = y + offsetY; - Color32 expected = expectedPatternFast[y, x]; // inverted pattern - Color32 actual = sourcePixels[actualX, actualY]; + Color expected = expectedPatternFast[y, x]; // inverted pattern + Color actual = sourcePixels[actualX, actualY]; if (expected != actual) { Assert.True(false, $"Expected {expected} but found {actual} at ({actualX},{actualY})"); @@ -63,73 +63,73 @@ namespace ImageSharp.Tests.Drawing [Fact] public void ImageShouldBeFloodFilledWithPercent10() { - this.Test("Percent10", Color32.Blue, Brushes.Percent10(Color32.HotPink, Color32.LimeGreen), + this.Test("Percent10", Color.Blue, Brushes.Percent10(Color.HotPink, Color.LimeGreen), new[,] { - { Color32.HotPink , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink , Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen} + { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent10Transparent() { - Test("Percent10_Transparent", Color32.Blue, Brushes.Percent10(Color32.HotPink), - new Color32[,] { - { Color32.HotPink , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.HotPink , Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.Blue, Color32.Blue} + Test("Percent10_Transparent", Color.Blue, Brushes.Percent10(Color.HotPink), + new Color[,] { + { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.HotPink , Color.Blue}, + { Color.Blue, Color.Blue, Color.Blue, Color.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent20() { - Test("Percent20", Color32.Blue, Brushes.Percent20(Color32.HotPink, Color32.LimeGreen), - new Color32[,] { - { Color32.HotPink , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink , Color32.LimeGreen}, - { Color32.HotPink , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink , Color32.LimeGreen} + Test("Percent20", Color.Blue, Brushes.Percent20(Color.HotPink, Color.LimeGreen), + new Color[,] { + { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, + { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent20_transparent() { - Test("Percent20_Transparent", Color32.Blue, Brushes.Percent20(Color32.HotPink), - new Color32[,] { - { Color32.HotPink , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.HotPink , Color32.Blue}, - { Color32.HotPink , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.HotPink , Color32.Blue} + Test("Percent20_Transparent", Color.Blue, Brushes.Percent20(Color.HotPink), + new Color[,] { + { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.HotPink , Color.Blue}, + { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.HotPink , Color.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithHorizontal() { - Test("Horizontal", Color32.Blue, Brushes.Horizontal(Color32.HotPink, Color32.LimeGreen), - new Color32[,] { - { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink}, - { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen , Color32.LimeGreen} + Test("Horizontal", Color.Blue, Brushes.Horizontal(Color.HotPink, Color.LimeGreen), + new Color[,] { + { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, + { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen , Color.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithHorizontal_transparent() { - Test("Horizontal_Transparent", Color32.Blue, Brushes.Horizontal(Color32.HotPink), - new Color32[,] { - { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink}, - { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.Blue , Color32.Blue} + Test("Horizontal_Transparent", Color.Blue, Brushes.Horizontal(Color.HotPink), + new Color[,] { + { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, + { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, + { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.Blue , Color.Blue} }); } @@ -138,96 +138,96 @@ namespace ImageSharp.Tests.Drawing [Fact] public void ImageShouldBeFloodFilledWithMin() { - Test("Min", Color32.Blue, Brushes.Min(Color32.HotPink, Color32.LimeGreen), - new Color32[,] { - { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen , Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen , Color32.LimeGreen}, - { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink} + Test("Min", Color.Blue, Brushes.Min(Color.HotPink, Color.LimeGreen), + new Color[,] { + { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen , Color.LimeGreen}, + { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink} }); } [Fact] public void ImageShouldBeFloodFilledWithMin_transparent() { - Test("Min_Transparent", Color32.Blue, Brushes.Min(Color32.HotPink), - new Color32[,] { - { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue , Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.Blue , Color32.Blue}, - { Color32.HotPink, Color32.HotPink, Color32.HotPink , Color32.HotPink}, + Test("Min_Transparent", Color.Blue, Brushes.Min(Color.HotPink), + new Color[,] { + { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.Blue , Color.Blue}, + { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, }); } [Fact] public void ImageShouldBeFloodFilledWithVertical() { - Test("Vertical", Color32.Blue, Brushes.Vertical(Color32.HotPink, Color32.LimeGreen), - new Color32[,] { - { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen} + Test("Vertical", Color.Blue, Brushes.Vertical(Color.HotPink, Color.LimeGreen), + new Color[,] { + { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithVertical_transparent() { - Test("Vertical_Transparent", Color32.Blue, Brushes.Vertical(Color32.HotPink), - new Color32[,] { - { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue} + Test("Vertical_Transparent", Color.Blue, Brushes.Vertical(Color.HotPink), + new Color[,] { + { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, + { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, + { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, + { Color.Blue, Color.HotPink, Color.Blue, Color.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal() { - Test("ForwardDiagonal", Color32.Blue, Brushes.ForwardDiagonal(Color32.HotPink, Color32.LimeGreen), - new Color32[,] { - { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen} + Test("ForwardDiagonal", Color.Blue, Brushes.ForwardDiagonal(Color.HotPink, Color.LimeGreen), + new Color[,] { + { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink}, + { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen}, + { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, + { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent() { - Test("ForwardDiagonal_Transparent", Color32.Blue, Brushes.ForwardDiagonal(Color32.HotPink), - new Color32[,] { - { Color32.Blue, Color32.Blue, Color32.Blue, Color32.HotPink}, - { Color32.Blue, Color32.Blue, Color32.HotPink, Color32.Blue}, - { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, - { Color32.HotPink, Color32.Blue, Color32.Blue, Color32.Blue} + Test("ForwardDiagonal_Transparent", Color.Blue, Brushes.ForwardDiagonal(Color.HotPink), + new Color[,] { + { Color.Blue, Color.Blue, Color.Blue, Color.HotPink}, + { Color.Blue, Color.Blue, Color.HotPink, Color.Blue}, + { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, + { Color.HotPink, Color.Blue, Color.Blue, Color.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal() { - Test("BackwardDiagonal", Color32.Blue, Brushes.BackwardDiagonal(Color32.HotPink, Color32.LimeGreen), - new Color32[,] { - { Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink, Color32.LimeGreen}, - { Color32.LimeGreen, Color32.LimeGreen, Color32.LimeGreen, Color32.HotPink} + Test("BackwardDiagonal", Color.Blue, Brushes.BackwardDiagonal(Color.HotPink, Color.LimeGreen), + new Color[,] { + { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen}, + { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink} }); } [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal_transparent() { - Test("BackwardDiagonal_Transparent", Color32.Blue, Brushes.BackwardDiagonal(Color32.HotPink), - new Color32[,] { - { Color32.HotPink, Color32.Blue, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.HotPink, Color32.Blue, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.HotPink, Color32.Blue}, - { Color32.Blue, Color32.Blue, Color32.Blue, Color32.HotPink} + Test("BackwardDiagonal_Transparent", Color.Blue, Brushes.BackwardDiagonal(Color.HotPink), + new Color[,] { + { Color.HotPink, Color.Blue, Color.Blue, Color.Blue}, + { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, + { Color.Blue, Color.Blue, Color.HotPink, Color.Blue}, + { Color.Blue, Color.Blue, Color.Blue, Color.HotPink} }); } } diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 26a9a86ab..03994bc94 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -29,14 +29,14 @@ namespace ImageSharp.Tests.Drawing { ImageSharp.Rectangle bounds = new ImageSharp.Rectangle(0, 0, 1, 1); - Mock> brush = new Mock>(); + Mock> brush = new Mock>(); Mock region = new Mock(); region.Setup(x => x.Bounds).Returns(bounds); GraphicsOptions options = new GraphicsOptions(antialias) { AntialiasSubpixelDepth = 1 }; - FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); + FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); Image img = new Image(1, 1); processor.Apply(img, bounds); diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index c3ba9e56b..bafc84b69 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -24,15 +24,15 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DefaultBack.png")) { image - .Fill(Color32.HotPink) + .Fill(Color.HotPink) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color.HotPink, sourcePixels[199, 149]); } } } @@ -46,16 +46,16 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color.HotPink, sourcePixels[199, 149]); } } } @@ -66,20 +66,20 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .Fill(color) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index 4aa199da4..d7a4bde95 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -36,33 +36,33 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .Draw(Color32.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Color.Blue) + .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[10, 10]); + Assert.Equal(Color.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color32.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color32.HotPink, sourcePixels[50, 300]); + Assert.Equal(Color.HotPink, sourcePixels[50, 300]); - Assert.Equal(Color32.HotPink, sourcePixels[37, 85]); + Assert.Equal(Color.HotPink, sourcePixels[37, 85]); - Assert.Equal(Color32.HotPink, sourcePixels[93, 85]); + Assert.Equal(Color.HotPink, sourcePixels[93, 85]); - Assert.Equal(Color32.HotPink, sourcePixels[65, 137]); + Assert.Equal(Color.HotPink, sourcePixels[65, 137]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[57, 99]); + Assert.Equal(Color.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color32.Blue, sourcePixels[100, 192]); + Assert.Equal(Color.Blue, sourcePixels[100, 192]); } } } @@ -86,18 +86,18 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png")) { image - .BackgroundColor(Color32.Blue) - .Draw(Color32.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Color.Blue) + .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[10, 10]); + Assert.Equal(Color.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color32.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color32.HotPink, sourcePixels[50, 300]); + Assert.Equal(Color.HotPink, sourcePixels[50, 300]); //Assert.Equal(Color.HotPink, sourcePixels[37, 85]); @@ -106,13 +106,13 @@ namespace ImageSharp.Tests.Drawing //Assert.Equal(Color.HotPink, sourcePixels[65, 137]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[57, 99]); + Assert.Equal(Color.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color32.Blue, sourcePixels[100, 192]); + Assert.Equal(Color.Blue, sourcePixels[100, 192]); } } } @@ -137,28 +137,28 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { image - .BackgroundColor(Color32.Blue) - .Draw(Color32.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Color.Blue) + .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[10, 10]); + Assert.Equal(Color.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color32.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color32.HotPink, sourcePixels[50, 300]); + Assert.Equal(Color.HotPink, sourcePixels[50, 300]); - Assert.Equal(Color32.Blue, sourcePixels[130, 41]); + Assert.Equal(Color.Blue, sourcePixels[130, 41]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[57, 99]); + Assert.Equal(Color.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color32.Blue, sourcePixels[100, 192]); + Assert.Equal(Color.Blue, sourcePixels[100, 192]); } } } @@ -183,8 +183,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { image - .BackgroundColor(Color32.Blue) - .Draw(Pens.Dash(Color32.HotPink, 5), simplePath.Clip(hole1)) + .BackgroundColor(Color.Blue) + .Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1)) .Save(output); } } @@ -204,22 +204,22 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .Draw(color, 5, simplePath.Clip(hole1)) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[10, 10]); @@ -234,14 +234,14 @@ namespace ImageSharp.Tests.Drawing Assert.Equal(mergedColor, sourcePixels[65, 137]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[57, 99]); + Assert.Equal(Color.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color32.Blue, sourcePixels[100, 192]); + Assert.Equal(Color.Blue, sourcePixels[100, 192]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 9ddd1d88d..81efd933b 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -23,8 +23,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Color32.HotPink, 5, + .BackgroundColor(Color.Blue) + .DrawLines(Color.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -33,13 +33,13 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } } @@ -53,8 +53,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Color32.HotPink, 5, + .BackgroundColor(Color.Blue) + .DrawLines(Color.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -64,13 +64,13 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } } @@ -84,8 +84,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Pens.Dash(Color32.HotPink, 5), + .BackgroundColor(Color.Blue) + .DrawLines(Pens.Dash(Color.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -105,8 +105,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dot.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Pens.Dot(Color32.HotPink, 5), + .BackgroundColor(Color.Blue) + .DrawLines(Pens.Dot(Color.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -126,8 +126,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DashDot.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Pens.DashDot(Color32.HotPink, 5), + .BackgroundColor(Color.Blue) + .DrawLines(Pens.DashDot(Color.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -147,8 +147,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Pens.DashDotDot(Color32.HotPink, 5), new[] { + .BackgroundColor(Color.Blue) + .DrawLines(Pens.DashDotDot(Color.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) @@ -162,7 +162,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Lines"); - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); Image image = new Image(500, 500); @@ -170,7 +170,7 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .DrawLines(color, 10, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -180,15 +180,15 @@ namespace ImageSharp.Tests.Drawing } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f/255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f/255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } @@ -202,8 +202,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color32.Blue) - .DrawLines(Color32.HotPink, 10, new[] { + .BackgroundColor(Color.Blue) + .DrawLines(Color.HotPink, 10, new[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), @@ -212,15 +212,15 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[8, 8]); + Assert.Equal(Color.HotPink, sourcePixels[8, 8]); - Assert.Equal(Color32.HotPink, sourcePixels[198, 10]); + Assert.Equal(Color.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color32.Blue, sourcePixels[10, 50]); + Assert.Equal(Color.Blue, sourcePixels[10, 50]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs index 0e92c6f59..82e2f72a2 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); - Pen pen = new Pen(Color32.Firebrick, 99.9f); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Pen pen = new Pen(Color.Firebrick, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -56,7 +56,7 @@ namespace ImageSharp.Tests.Drawing.Paths BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -76,7 +76,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -96,10 +96,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -109,7 +109,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -118,10 +118,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -131,7 +131,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -149,7 +149,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs index 59513a51c..cc126614f 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); - Pen pen = new Pen(Color32.Gray, 99.9f); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Pen pen = new Pen(Color.Gray, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,7 +54,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -65,7 +65,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -85,7 +85,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -94,10 +94,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -107,7 +107,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -116,10 +116,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -129,7 +129,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -147,7 +147,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs index c7a556230..6c1c06813 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); - Pen pen = new Pen(Color32.Gray, 99.9f); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Pen pen = new Pen(Color.Gray, 99.9f); IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,14 +45,14 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -63,14 +63,14 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -81,17 +81,17 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -101,17 +101,17 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -121,7 +121,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -137,7 +137,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs index 7e6324215..9de052331 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); - Pen pen = new Pen(Color32.Gray, 99.9f); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Pen pen = new Pen(Color.Gray, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,7 +54,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -65,7 +65,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -85,7 +85,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -94,10 +94,10 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -107,7 +107,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -116,10 +116,10 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -129,7 +129,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -147,7 +147,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs index f504f7d25..215d5a7c7 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs @@ -18,9 +18,9 @@ namespace ImageSharp.Tests.Drawing.Paths { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); - Pen pen = new Pen(Color32.Gray, 99.9f); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Pen pen = new Pen(Color.Gray, 99.9f); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 98, 324); private ProcessorWatchingImage img; @@ -41,7 +41,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -64,7 +64,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -77,7 +77,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -88,7 +88,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -101,10 +101,10 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -114,7 +114,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -127,10 +127,10 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -140,7 +140,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -162,7 +162,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 7cd330eaa..5ba6580bd 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths public class FillPath : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -79,7 +79,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -105,7 +105,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index 45ebea248..ad72d4c4e 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths public class FillPolygon : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); Vector2[] path = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(brush, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -60,7 +60,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(brush, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -77,7 +77,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(color, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -85,7 +85,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -95,7 +95,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(color, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -103,7 +103,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 6ce57256c..f6b1c4ade 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths public class FillRectangle : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color32 color = Color32.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 77, 76); private ProcessorWatchingImage img; @@ -39,7 +39,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, rectangle); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -59,7 +59,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -79,7 +79,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, rectangle); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -90,7 +90,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -100,7 +100,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -111,7 +111,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs index 0af88d800..2d3d2cc2b 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs @@ -11,8 +11,8 @@ namespace ImageSharp.Tests.Drawing.Paths /// /// Watches but does not actually run the processors against the image. /// - /// - public class ProcessorWatchingImage : Image + /// + public class ProcessorWatchingImage : Image { public List ProcessorApplications { get; } = new List(); @@ -21,7 +21,7 @@ namespace ImageSharp.Tests.Drawing.Paths { } - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { this.ProcessorApplications.Add(new ProcessorDetails { @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing.Paths public struct ProcessorDetails { - public IImageProcessor processor; + public IImageProcessor processor; public Rectangle rectangle; } } diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 3e2034531..3e06ca918 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .DrawPolygon(Color32.HotPink, 5, + .BackgroundColor(Color.Blue) + .DrawPolygon(Color.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -35,15 +35,15 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[9, 9]); + Assert.Equal(Color.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 149]); + Assert.Equal(Color.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); } } } @@ -58,30 +58,30 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .DrawPolygon(color, 10, simplePath) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); } } } @@ -96,22 +96,22 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color32.Blue) - .Draw(Color32.HotPink, 10, new Rectangle(10, 10, 190, 140)) + .BackgroundColor(Color.Blue) + .Draw(Color.HotPink, 10, new Rectangle(10, 10, 190, 140)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[8, 8]); + Assert.Equal(Color.HotPink, sourcePixels[8, 8]); - Assert.Equal(Color32.HotPink, sourcePixels[198, 10]); + Assert.Equal(Color.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color32.HotPink, sourcePixels[10, 50]); + Assert.Equal(Color.HotPink, sourcePixels[10, 50]); - Assert.Equal(Color32.Blue, sourcePixels[50, 50]); + Assert.Equal(Color.Blue, sourcePixels[50, 50]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 497d4ab45..0b450d166 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Color32.Yellow, Color32.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Color.Yellow, Color.HotPink, 0.2f); foreach (TestFile file in Files) { @@ -38,7 +38,7 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Color32.Yellow, Color32.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Color.Yellow, Color.HotPink, 0.2f); foreach (TestFile file in Files) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 124463d14..1a7e98a12 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -29,20 +29,20 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, new Polygon(new BezierLineSegment(simplePath))) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, new Polygon(new BezierLineSegment(simplePath))) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[150, 300]); + Assert.Equal(Color.HotPink, sourcePixels[150, 300]); //curve points should not be never be set - Assert.Equal(Color32.Blue, sourcePixels[240, 30]); + Assert.Equal(Color.Blue, sourcePixels[240, 30]); // inside shape should not be empty - Assert.Equal(Color32.HotPink, sourcePixels[200, 250]); + Assert.Equal(Color.HotPink, sourcePixels[200, 250]); } } } @@ -57,28 +57,28 @@ namespace ImageSharp.Tests.Drawing new Vector2(240, 30), new Vector2(300, 400) }; - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .Fill(color, new Polygon(new BezierLineSegment(simplePath))) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve Assert.Equal(mergedColor, sourcePixels[138, 116]); //curve points should not be never be set - Assert.Equal(Color32.Blue, sourcePixels[240, 30]); + Assert.Equal(Color.Blue, sourcePixels[240, 30]); // inside shape should not be empty Assert.Equal(mergedColor, sourcePixels[200, 250]); diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index be4fb743e..4ff250a93 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -35,17 +35,17 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, clipped) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, clipped) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[20, 35]); + Assert.Equal(Color.HotPink, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[60, 100]); + Assert.Equal(Color.Blue, sourcePixels[60, 100]); } } } @@ -70,17 +70,17 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, simplePath.Clip(hole1)) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[20, 35]); + Assert.Equal(Color.HotPink, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[60, 100]); + Assert.Equal(Color.Blue, sourcePixels[60, 100]); } } } @@ -98,27 +98,27 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .Fill(color, simplePath.Clip(hole1)) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color32.Blue, sourcePixels[60, 100]); + Assert.Equal(Color.Blue, sourcePixels[60, 100]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 0cbb6108c..79363480f 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -32,13 +32,13 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .FillPolygon(Color32.HotPink, simplePath, new GraphicsOptions(true)) + .FillPolygon(Color.HotPink, simplePath, new GraphicsOptions(true)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[81, 145]); + Assert.Equal(Color.HotPink, sourcePixels[81, 145]); } } } @@ -58,13 +58,13 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Pattern.png")) { image - .FillPolygon(Brushes.Horizontal(Color32.HotPink), simplePath, new GraphicsOptions(true)) + .FillPolygon(Brushes.Horizontal(Color.HotPink), simplePath, new GraphicsOptions(true)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[81, 145]); + Assert.Equal(Color.HotPink, sourcePixels[81, 145]); } } } @@ -83,19 +83,19 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple_NoAntialias.png")) { image - .BackgroundColor(Color32.Blue) - .FillPolygon(Color32.HotPink, simplePath, new GraphicsOptions(false)) + .BackgroundColor(Color.Blue) + .FillPolygon(Color.HotPink, simplePath, new GraphicsOptions(false)) .Save(output); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[11, 11]); + Assert.Equal(Color.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color32.HotPink, sourcePixels[199, 150]); + Assert.Equal(Color.HotPink, sourcePixels[199, 150]); - Assert.Equal(Color32.HotPink, sourcePixels[50, 50]); + Assert.Equal(Color.HotPink, sourcePixels[50, 50]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); } } } @@ -117,7 +117,7 @@ namespace ImageSharp.Tests.Drawing ImageBrush brush = new ImageBrush(brushImage); image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .FillPolygon(brush, simplePath) .Save(output); } @@ -132,24 +132,24 @@ namespace ImageSharp.Tests.Drawing new Vector2(200, 150), new Vector2(50, 300) }; - Color32 color = new Color32(Color32.HotPink.R, Color32.HotPink.G, Color32.HotPink.B, 150); + Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color32.Blue) + .BackgroundColor(Color.Blue) .FillPolygon(color, simplePath) .Save(output); } //shift background color towards forground color by the opacity amount - Color32 mergedColor = new Color32(Vector4.Lerp(Color32.Blue.ToVector4(), Color32.HotPink.ToVector4(), 150f / 255f)); + Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); } } } @@ -164,22 +164,22 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.HotPink, sourcePixels[11, 11]); + Assert.Equal(Color.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color32.HotPink, sourcePixels[198, 10]); + Assert.Equal(Color.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color32.HotPink, sourcePixels[10, 50]); + Assert.Equal(Color.HotPink, sourcePixels[10, 50]); - Assert.Equal(Color32.HotPink, sourcePixels[50, 50]); + Assert.Equal(Color.HotPink, sourcePixels[50, 50]); - Assert.Equal(Color32.Blue, sourcePixels[2, 2]); + Assert.Equal(Color.Blue, sourcePixels[2, 2]); } } } @@ -194,16 +194,16 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Triangle.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, new RegularPolygon(50, 50, 3, 30)) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, new RegularPolygon(50, 50, 3, 30)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color32.Blue, sourcePixels[30, 65]); + Assert.Equal(Color.Blue, sourcePixels[30, 65]); - Assert.Equal(Color32.HotPink, sourcePixels[50, 50]); + Assert.Equal(Color.HotPink, sourcePixels[50, 50]); } } } @@ -220,8 +220,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Septagon.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) .Save(output); } } @@ -239,8 +239,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/ellipse.png")) { image - .BackgroundColor(Color32.Blue) - .Fill(Color32.HotPink, new Ellipse(50, 50, 30, 50) + .BackgroundColor(Color.Blue) + .Fill(Color.HotPink, new Ellipse(50, 50, 30, 50) .Rotate((float)(Math.PI / 3))) .Save(output); } @@ -259,8 +259,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/clipped-corner.png")) { image - .Fill(Color32.Blue) - .FillPolygon(Color32.HotPink, new[] + .Fill(Color.Blue) + .FillPolygon(Color.HotPink, new[] { new Vector2( 8, 8 ), new Vector2( 64, 8 ), diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index f85a22d21..52b7fcbb6 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -21,9 +21,9 @@ namespace ImageSharp.Tests.Drawing.Text public class DrawText : IDisposable { - Color32 color = Color32.HotPink; + Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color32.HotPink); + SolidBrush brush = Brushes.Solid(Color.HotPink); IPath path = new SixLabors.Shapes.Path( new LinearLineSegment( @@ -53,73 +53,73 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "123", this.Font, - Brushes.Solid(Color32.Red), + Brushes.Solid(Color.Red), null, Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), null, Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), null, Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Color32.Red, Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Color.Red, Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor processor = + Assert.IsType>(this.img.ProcessorApplications[0].processor); - SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(Color32.Red, brush.Color); + SolidBrush brush = Assert.IsType>(processor.Brush); + Assert.Equal(Color.Red, brush.Color); } [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Color32.Red, Vector2.Zero); + this.img.DrawText("123", this.Font, Color.Red, Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor processor = + Assert.IsType>(this.img.ProcessorApplications[0].processor); - SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(Color32.Red, brush.Color); + SolidBrush brush = Assert.IsType>(processor.Brush); + Assert.Equal(Color.Red, brush.Color); } [Fact] @@ -129,43 +129,43 @@ namespace ImageSharp.Tests.Drawing.Text "123", this.Font, null, - Pens.Dash(Color32.Red, 1), + Pens.Dash(Color.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Color32.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, null, Pens.Dash(Color.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Color32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Color32.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] @@ -174,8 +174,8 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "123", this.Font, - Brushes.Solid(Color32.Red), - Pens.Dash(Color32.Red, 1), + Brushes.Solid(Color.Red), + Pens.Dash(Color.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); @@ -186,7 +186,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color32.Red), Pens.Dash(Color32.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(6, this.img.ProcessorApplications.Count); @@ -198,26 +198,26 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "1", this.Font, - Brushes.Solid(Color32.Red), - Pens.Dash(Color32.Red, 1), + Brushes.Solid(Color.Red), + Pens.Dash(Color.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[1].processor); } [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Color32.Red), Pens.Dash(Color32.Red, 1), Vector2.Zero); + this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[1].processor); } [Fact] @@ -225,19 +225,19 @@ namespace ImageSharp.Tests.Drawing.Text { this.img.MetaData.VerticalResolution = 1; this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero, new TextGraphicsOptions(true) { + this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true) { UseImageResolution = false }); - this.img.DrawText("1", this.Font, Brushes.Solid(Color32.Red), Vector2.Zero, new TextGraphicsOptions(true) + this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true) { UseImageResolution = true }); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); + FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index 1d2af9363..0bb3afccd 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -32,8 +32,8 @@ namespace ImageSharp.Tests.Drawing.Text //draws 2 overlapping triangle glyphs twice 1 set on each line using (Image img = new Image(100, 200)) { - img.Fill(Color32.DarkBlue) - .DrawText("AB\nAB", new Font(this.Font, 50), Color32.Red, new Vector2(0, 0)); + img.Fill(Color.DarkBlue) + .DrawText("AB\nAB", new Font(this.Font, 50), Color.Red, new Vector2(0, 0)); img.Save($"{this.CreateOutputDirectory("Drawing", "Text")}/AB.png"); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index 121b3ca09..28a64a765 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -69,9 +69,9 @@ namespace ImageSharp.Tests .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }) .ToArray(); - Image[] testImages = + Image[] testImages = testFiles.Select( - tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) + tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) .ToArray(); using (MemoryStream ms = new MemoryStream()) @@ -79,7 +79,7 @@ namespace ImageSharp.Tests this.Measure(executionCount, () => { - foreach (Image img in testImages) + foreach (Image img in testImages) { JpegEncoder encoder = new JpegEncoder(); JpegEncoderOptions options = new JpegEncoderOptions { Quality = quality, Subsample = subsample }; diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 85245e102..10b0cbb94 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests { private readonly Mock fileSystem; private readonly IDecoderOptions decoderOptions; - private Image returnImage; + private Image returnImage; private Mock localDecoder; private Mock localFormat; private readonly string FilePath; @@ -44,7 +44,7 @@ namespace ImageSharp.Tests this.localFormat.Setup(x => x.IsSupportedFileFormat(It.IsAny())).Returns(true); this.localFormat.Setup(x => x.SupportedExtensions).Returns(new string[] { "png", "jpg" }); - this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny())) + this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((c, s, o) => { using (var ms = new MemoryStream()) @@ -103,10 +103,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithType() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -128,10 +128,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithTypeAndOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -147,7 +147,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); } @@ -155,13 +155,13 @@ namespace ImageSharp.Tests public void LoadFromStreamWithTypeAndConfig() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream); + Image img = Image.Load(this.LocalConfiguration, stream); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); } @@ -174,7 +174,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); } @@ -182,13 +182,13 @@ namespace ImageSharp.Tests public void LoadFromStreamWithTypeAndConfigAndOptions() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream, this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, stream, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); } @@ -201,18 +201,18 @@ namespace ImageSharp.Tests Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); } [Fact] public void LoadFromStreamWithTypeAndDecoder() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object); + Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); } [Fact] @@ -222,18 +222,18 @@ namespace ImageSharp.Tests Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); } [Fact] public void LoadFromStreamWithTypeAndDecoderAndOptions() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); } [Fact] @@ -252,10 +252,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithType() { - Image img = Image.Load(this.DataStream.ToArray()); + Image img = Image.Load(this.DataStream.ToArray()); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -277,10 +277,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndOptions() { - Image img = Image.Load(this.DataStream.ToArray(), this.decoderOptions); + Image img = Image.Load(this.DataStream.ToArray(), this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -295,7 +295,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -303,14 +303,14 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndConfig() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -323,7 +323,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -331,13 +331,13 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndConfigAndOptions() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray(), this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray(), this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -349,18 +349,18 @@ namespace ImageSharp.Tests Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } [Fact] public void LoadFromBytesWithTypeAndDecoder() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -370,18 +370,18 @@ namespace ImageSharp.Tests Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } [Fact] public void LoadFromBytesWithTypeAndDecoderAndOptions() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -401,10 +401,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithType() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -426,10 +426,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithTypeAndOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -444,20 +444,20 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); } [Fact] public void LoadFromFileWithTypeAndConfig() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath); + Image img = Image.Load(this.LocalConfiguration, this.FilePath); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); } @@ -469,20 +469,20 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); } [Fact] public void LoadFromFileWithTypeAndConfigAndOptions() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath, this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, this.FilePath, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); } @@ -493,17 +493,17 @@ namespace ImageSharp.Tests Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); } [Fact] public void LoadFromFileWithTypeAndDecoder() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object); + Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); } [Fact] @@ -512,17 +512,17 @@ namespace ImageSharp.Tests Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); } [Fact] public void LoadFromFileWithTypeAndDecoderAndOptions() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index f398d33d2..0d1c3e09b 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -59,7 +59,7 @@ namespace ImageSharp.Tests this.fileSystem.Setup(x => x.Create("path.png")).Returns(stream); this.Image.Save("path.png"); - this.encoder.Verify(x => x.Encode(this.Image, stream, null)); + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -70,7 +70,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderOptions); - this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -81,7 +81,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -92,7 +92,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } @@ -105,7 +105,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -116,7 +116,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -125,7 +125,7 @@ namespace ImageSharp.Tests Stream stream = new MemoryStream(); this.Image.Save(stream); - this.encoder.Verify(x => x.Encode(this.Image, stream, null)); + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -135,7 +135,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderOptions); - this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -145,7 +145,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -155,7 +155,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -165,7 +165,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.formatNotRegistered.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -175,7 +175,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.formatNotRegistered.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index b6aa8ead2..cd9cd04b7 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -125,7 +125,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYX() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyFromZYX(image); } @@ -134,7 +134,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYXW() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyFromZYXW(image); } @@ -143,7 +143,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYX() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyToZYX(image); } @@ -152,7 +152,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYXW() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyToZYXW(image); } @@ -176,7 +176,7 @@ namespace ImageSharp.Tests pixels.CopyFrom(row, 0); - Color32 color = (Color32)(object)pixels[0, 0]; + Color color = (Color)(object)pixels[0, 0]; Assert.Equal(red, color.R); Assert.Equal(green, color.G); Assert.Equal(blue, color.B); @@ -204,7 +204,7 @@ namespace ImageSharp.Tests pixels.CopyFrom(row, 0); - Color32 color = (Color32)(object)pixels[0, 0]; + Color color = (Color)(object)pixels[0, 0]; Assert.Equal(red, color.R); Assert.Equal(green, color.G); Assert.Equal(blue, color.B); @@ -224,7 +224,7 @@ namespace ImageSharp.Tests using (PixelArea row = new PixelArea(1, ComponentOrder.Zyx)) { - pixels[0, 0] = (TColor)(object)new Color32(red, green, blue); + pixels[0, 0] = (TColor)(object)new Color(red, green, blue); pixels.CopyTo(row, 0); @@ -247,7 +247,7 @@ namespace ImageSharp.Tests using (PixelArea row = new PixelArea(1, ComponentOrder.Zyxw)) { - pixels[0, 0] = (TColor)(object)new Color32(red, green, blue, alpha); + pixels[0, 0] = (TColor)(object)new Color(red, green, blue, alpha); pixels.CopyTo(row, 0); diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index 554c2bc2b..f380724df 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -243,7 +243,7 @@ namespace ImageSharp.Tests TestProfile(profile); - Image thumbnail = profile.CreateThumbnail(); + Image thumbnail = profile.CreateThumbnail(); Assert.NotNull(thumbnail); Assert.Equal(256, thumbnail.Width); Assert.Equal(170, thumbnail.Height); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs index 90af8f0ac..fd08b87a4 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs @@ -21,7 +21,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { - image.BackgroundColor(Color32.HotPink).Save(output); + image.BackgroundColor(Color.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs index 9db90b324..1afb1300a 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.Glow(Color32.HotPink).Save(output); + image.Glow(Color.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs index ec6694cb8..da09aa85e 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs @@ -36,13 +36,13 @@ namespace ImageSharp.Tests // [Fact] public void PrintWeightsData() { - ResizeProcessor proc = new ResizeProcessor(new BicubicResampler(), 200, 200); + ResizeProcessor proc = new ResizeProcessor(new BicubicResampler(), 200, 200); - ResamplingWeightedProcessor.WeightsBuffer weights = proc.PrecomputeWeights(200, 500); + ResamplingWeightedProcessor.WeightsBuffer weights = proc.PrecomputeWeights(200, 500); StringBuilder bld = new StringBuilder(); - foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights) + foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights) { for (int i = 0; i < window.Length; i++) { diff --git a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs index a0b66936e..7f40ef1d2 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.Vignette(Color32.HotPink).Save(output); + image.Vignette(Color.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs index 8c27c2937..2361bc01c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs @@ -5,13 +5,13 @@ namespace ImageSharp.Tests { - public class ImageFactory : GenericFactory + public class ImageFactory : GenericFactory { - public override Image CreateImage(byte[] bytes) => Image.Load(bytes); + public override Image CreateImage(byte[] bytes) => Image.Load(bytes); - public override Image CreateImage(int width, int height) => new Image(width, height); + public override Image CreateImage(int width, int height) => new Image(width, height); - public override Image CreateImage(Image other) + public override Image CreateImage(Image other) { Image img = (Image)other; return new Image(img); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 9278def26..c9312eed1 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -147,9 +147,9 @@ namespace ImageSharp.Tests int bottom = pixels.Height; int height = (int)Math.Ceiling(pixels.Height / 6f); - Vector4 red = Color32.Red.ToVector4(); // use real color so we can see har it translates in the test pattern - Vector4 green = Color32.Green.ToVector4(); // use real color so we can see har it translates in the test pattern - Vector4 blue = Color32.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 red = Color.Red.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 green = Color.Green.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 blue = Color.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern TColor c = default(TColor); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs index 8614f6d7a..260a677d3 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs @@ -18,7 +18,7 @@ namespace ImageSharp.Tests { private static readonly Dictionary ClrTypes2PixelTypes = new Dictionary(); - private static readonly Assembly ImageSharpAssembly = typeof(Color32).GetTypeInfo().Assembly; + private static readonly Assembly ImageSharpAssembly = typeof(Color).GetTypeInfo().Assembly; private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary(); @@ -28,8 +28,8 @@ namespace ImageSharp.Tests static TestUtilityExtensions() { - string nameSpace = typeof(Color32).FullName; - nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color32).Name.Length - 1); + string nameSpace = typeof(Color).FullName; + nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color).Name.Length - 1); foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass)) { string typeName = $"{nameSpace}.{pt.ToString()}"; @@ -42,7 +42,7 @@ namespace ImageSharp.Tests PixelTypes2ClrTypes[pt] = t; ClrTypes2PixelTypes[t] = pt; } - PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color32); + PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color); } public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index a3ea09d6e..6760735d1 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -151,7 +151,7 @@ namespace ImageSharp.Tests public static readonly TheoryData BasicData = new TheoryData() { - TestImageProvider.Blank(10, 20), + TestImageProvider.Blank(10, 20), TestImageProvider.Blank( 10, 20), @@ -169,7 +169,7 @@ namespace ImageSharp.Tests public static readonly TheoryData FileData = new TheoryData() { - TestImageProvider.File( + TestImageProvider.File( TestImages.Bmp.Car), TestImageProvider.File( TestImages.Bmp.F) diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index d5abfe208..63c24a157 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -51,10 +51,10 @@ namespace ImageSharp.Tests [Fact] public void Baz() { - Type type = typeof(Color32).GetTypeInfo().Assembly.GetType("ImageSharp.Color"); + Type type = typeof(Color).GetTypeInfo().Assembly.GetType("ImageSharp.Color"); this.Output.WriteLine(type.ToString()); - Type fake = typeof(Color32).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); + Type fake = typeof(Color).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); Assert.Null(fake); } @@ -84,17 +84,17 @@ namespace ImageSharp.Tests } [Theory] - [InlineData(PixelTypes.Color, typeof(Color32))] + [InlineData(PixelTypes.Color, typeof(Color))] [InlineData(PixelTypes.Argb, typeof(Argb))] [InlineData(PixelTypes.HalfVector4, typeof(HalfVector4))] - [InlineData(PixelTypes.StandardImageClass, typeof(Color32))] + [InlineData(PixelTypes.StandardImageClass, typeof(Color))] public void ToType(PixelTypes pt, Type expectedType) { Assert.Equal(pt.ToType(), expectedType); } [Theory] - [InlineData(typeof(Color32), PixelTypes.Color)] + [InlineData(typeof(Color), PixelTypes.Color)] [InlineData(typeof(Argb), PixelTypes.Argb)] public void GetPixelType(Type clrType, PixelTypes expectedPixelType) { @@ -120,9 +120,9 @@ namespace ImageSharp.Tests AssertContainsPixelType(PixelTypes.Alpha8, expanded); AssertContainsPixelType(PixelTypes.Bgr565, expanded); - AssertContainsPixelType(PixelTypes.Color, expanded); + AssertContainsPixelType(PixelTypes.Color, expanded); AssertContainsPixelType(PixelTypes.HalfVector2, expanded); - AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); + AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } [Fact] @@ -131,8 +131,8 @@ namespace ImageSharp.Tests KeyValuePair[] expanded = PixelTypes.All.ExpandAllTypes().ToArray(); Assert.True(expanded.Length >= TestUtilityExtensions.GetAllPixelTypes().Length - 2); - AssertContainsPixelType(PixelTypes.Color, expanded); - AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); + AssertContainsPixelType(PixelTypes.Color, expanded); + AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } } } \ No newline at end of file From 2e7b36c06f8cc2c4b58c1fbc84444a06efaa14f4 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 17 Apr 2017 21:54:15 +1000 Subject: [PATCH 24/34] Remove unneeded constants --- src/ImageSharp/Colors/ColorVector.cs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/ImageSharp/Colors/ColorVector.cs b/src/ImageSharp/Colors/ColorVector.cs index d9eb1906d..3e86e85c7 100644 --- a/src/ImageSharp/Colors/ColorVector.cs +++ b/src/ImageSharp/Colors/ColorVector.cs @@ -18,26 +18,6 @@ namespace ImageSharp /// public partial struct ColorVector : IPixel { - /// - /// 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. /// @@ -240,7 +220,7 @@ namespace ImageSharp { Vector4 vector = this.backingVector * MaxBytes; vector += Half; - uint hexOrder = (uint)((byte)vector.X << RedShift | (byte)vector.Y << GreenShift | (byte)vector.Z << BlueShift | (byte)vector.W << AlphaShift); + uint hexOrder = (uint)((byte)vector.X | (byte)vector.Y << 8 | (byte)vector.Z << 16 | (byte)vector.W << 24); return hexOrder.ToString("X8"); } From 38541af055b2e06d14ba9828f5beba070650a187 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 17 Apr 2017 22:56:28 +1000 Subject: [PATCH 25/34] Add tests, fix bugs --- src/ImageSharp/Colors/ColorVector.cs | 7 +- .../Colors/ColorEqualityTests.cs | 50 +++--- .../Colors/PackedPixelTests.cs | 45 ++++++ .../Colors/UnPackedPixelTests.cs | 148 ++++++++++++++++++ 4 files changed, 223 insertions(+), 27 deletions(-) create mode 100644 tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs diff --git a/src/ImageSharp/Colors/ColorVector.cs b/src/ImageSharp/Colors/ColorVector.cs index 3e86e85c7..354553982 100644 --- a/src/ImageSharp/Colors/ColorVector.cs +++ b/src/ImageSharp/Colors/ColorVector.cs @@ -218,9 +218,10 @@ namespace ImageSharp /// A hexadecimal string representation of the value. public string ToHex() { + // Hex is RRGGBBAA Vector4 vector = this.backingVector * MaxBytes; vector += Half; - uint hexOrder = (uint)((byte)vector.X | (byte)vector.Y << 8 | (byte)vector.Z << 16 | (byte)vector.W << 24); + uint hexOrder = (uint)((byte)vector.W | (byte)vector.Z << 8 | (byte)vector.Y << 16 | (byte)vector.X << 24); return hexOrder.ToString("X8"); } @@ -244,7 +245,7 @@ namespace ImageSharp bytes[startIndex] = (byte)vector.X; bytes[startIndex + 1] = (byte)vector.Y; bytes[startIndex + 2] = (byte)vector.Z; - bytes[startIndex + 2] = (byte)vector.W; + bytes[startIndex + 3] = (byte)vector.W; } /// @@ -267,7 +268,7 @@ namespace ImageSharp bytes[startIndex] = (byte)vector.Z; bytes[startIndex + 1] = (byte)vector.Y; bytes[startIndex + 2] = (byte)vector.X; - bytes[startIndex + 2] = (byte)vector.W; + bytes[startIndex + 3] = (byte)vector.W; } /// diff --git a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs index b5b09c828..42481799f 100644 --- a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs @@ -33,6 +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 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) }, @@ -144,6 +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 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) }, @@ -289,10 +291,10 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(EqualityDataColorSpaces))] public void EqualityObject(object first, object second, Type type) { - // Arrange - // Cast to the known object types, this is so that we can hit the - // equality operator on the concrete type, otherwise it goes to the - // default "object" one :) + // Arrange + // Cast to the known object types, this is so that we can hit the + // equality operator on the concrete type, otherwise it goes to the + // default "object" one :) dynamic firstObject = Convert.ChangeType(first, type); dynamic secondObject = Convert.ChangeType(second, type); @@ -308,10 +310,10 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(NotEqualityDataColorSpaces))] public void NotEqualityObject(object first, object second, Type type) { - // Arrange - // Cast to the known object types, this is so that we can hit the - // equality operator on the concrete type, otherwise it goes to the - // default "object" one :) + // Arrange + // Cast to the known object types, this is so that we can hit the + // equality operator on the concrete type, otherwise it goes to the + // default "object" one :) dynamic firstObject = Convert.ChangeType(first, type); dynamic secondObject = Convert.ChangeType(second, type); @@ -327,10 +329,10 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(EqualityDataColorSpaces))] public void EqualityOperator(object first, object second, Type type) { - // Arrange - // Cast to the known object types, this is so that we can hit the - // equality operator on the concrete type, otherwise it goes to the - // default "object" one :) + // Arrange + // Cast to the known object types, this is so that we can hit the + // equality operator on the concrete type, otherwise it goes to the + // default "object" one :) dynamic firstObject = Convert.ChangeType(first, type); dynamic secondObject = Convert.ChangeType(second, type); @@ -346,10 +348,10 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(NotEqualityDataColorSpaces))] public void NotEqualityOperator(object first, object second, Type type) { - // Arrange - // Cast to the known object types, this is so that we can hit the - // equality operator on the concrete type, otherwise it goes to the - // default "object" one :) + // Arrange + // Cast to the known object types, this is so that we can hit the + // equality operator on the concrete type, otherwise it goes to the + // default "object" one :) dynamic firstObject = Convert.ChangeType(first, type); dynamic secondObject = Convert.ChangeType(second, type); @@ -364,10 +366,10 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(AlmostEqualsData))] public void AlmostEquals(object first, object second, Type type, float precision) { - // Arrange - // Cast to the known object types, this is so that we can hit the - // equality operator on the concrete type, otherwise it goes to the - // default "object" one :) + // Arrange + // Cast to the known object types, this is so that we can hit the + // equality operator on the concrete type, otherwise it goes to the + // default "object" one :) dynamic firstObject = Convert.ChangeType(first, type); dynamic secondObject = Convert.ChangeType(second, type); @@ -382,10 +384,10 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(AlmostNotEqualsData))] public void AlmostNotEquals(object first, object second, Type type, float precision) { - // Arrange - // Cast to the known object types, this is so that we can hit the - // equality operator on the concrete type, otherwise it goes to the - // default "object" one :) + // Arrange + // Cast to the known object types, this is so that we can hit the + // equality operator on the concrete type, otherwise it goes to the + // default "object" one :) dynamic firstObject = Convert.ChangeType(first, type); dynamic secondObject = Convert.ChangeType(second, type); diff --git a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs index 3e2b6fcd5..b5e159d9a 100644 --- a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs +++ b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs @@ -711,6 +711,51 @@ namespace ImageSharp.Tests.Colors Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 }); } + [Fact] + public void Rgba32() + { + // Test the limits. + Assert.Equal((uint)0x0, new Rgba32(Vector4.Zero).PackedValue); + Assert.Equal(0xFFFFFFFF, new Rgba32(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())); + + // 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())); + + float x = +0.1f; + float y = -0.3f; + float z = +0.5f; + float w = -0.7f; + Rgba32 rgba32 = new Rgba32(x, y, z, w); + Assert.Equal(0x80001Au, rgba32.PackedValue); + + // Test ordering + byte[] rgb = new byte[3]; + byte[] rgba = new byte[4]; + byte[] bgr = new byte[3]; + byte[] bgra = new byte[4]; + + rgba32.ToXyzBytes(rgb, 0); + Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 }); + + rgba32.ToXyzwBytes(rgba, 0); + Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 }); + + rgba32.ToZyxBytes(bgr, 0); + Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a }); + + rgba32.ToZyxwBytes(bgra, 0); + Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 }); + } + [Fact] public void Rgba64() { diff --git a/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs b/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs new file mode 100644 index 000000000..4fb189ca8 --- /dev/null +++ b/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs @@ -0,0 +1,148 @@ +namespace ImageSharp.Tests.Colors +{ + using System.Numerics; + + using Xunit; + + public class UnPackedPixelTests + { + [Fact] + public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + Assert.Equal(color.R, (byte)(colorVector.R * 255)); + Assert.Equal(color.G, (byte)(colorVector.G * 255)); + Assert.Equal(color.B, (byte)(colorVector.B * 255)); + Assert.Equal(color.A, (byte)(colorVector.A * 255)); + } + + [Fact] + public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut() + { + Color color = new Color(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); + ColorVector colorVector = new ColorVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); + + Assert.Equal(color.R, (byte)(colorVector.R * 255)); + Assert.Equal(color.G, (byte)(colorVector.G * 255)); + Assert.Equal(color.B, (byte)(colorVector.B * 255)); + Assert.Equal(color.A, (byte)(colorVector.A * 255)); + } + + [Fact] + public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut() + { + Color color = new Color(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); + ColorVector colorVector = new ColorVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); + + Assert.Equal(color.R, (byte)(colorVector.R * 255)); + Assert.Equal(color.G, (byte)(colorVector.G * 255)); + Assert.Equal(color.B, (byte)(colorVector.B * 255)); + Assert.Equal(color.A, (byte)(colorVector.A * 255)); + } + + [Fact] + public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut() + { + Color color = new Color(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); + ColorVector colorVector = new ColorVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); + + Assert.Equal(color.R, (byte)(colorVector.R * 255)); + Assert.Equal(color.G, (byte)(colorVector.G * 255)); + Assert.Equal(color.B, (byte)(colorVector.B * 255)); + Assert.Equal(color.A, (byte)(colorVector.A * 255)); + } + + [Fact] + public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut() + { + Color color = Color.FromHex("183060C0"); + ColorVector colorVector = ColorVector.FromHex("183060C0"); + + Assert.Equal(color.R, (byte)(colorVector.R * 255)); + Assert.Equal(color.G, (byte)(colorVector.G * 255)); + Assert.Equal(color.B, (byte)(colorVector.B * 255)); + Assert.Equal(color.A, (byte)(colorVector.A * 255)); + } + + [Fact] + public void Color_Types_To_Vector4_Produce_Equal_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + Assert.Equal(color.ToVector4(), colorVector.ToVector4()); + } + + [Fact] + public void Color_Types_To_RgbBytes_Produce_Equal_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + byte[] rgb = new byte[3]; + byte[] rgbVector = new byte[3]; + + color.ToXyzBytes(rgb, 0); + colorVector.ToXyzBytes(rgbVector, 0); + + Assert.Equal(rgb, rgbVector); + } + + [Fact] + public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + byte[] rgba = new byte[4]; + byte[] rgbaVector = new byte[4]; + + color.ToXyzwBytes(rgba, 0); + colorVector.ToXyzwBytes(rgbaVector, 0); + + Assert.Equal(rgba, rgbaVector); + } + + [Fact] + public void Color_Types_To_BgrBytes_Produce_Equal_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + byte[] bgr = new byte[3]; + byte[] bgrVector = new byte[3]; + + color.ToZyxBytes(bgr, 0); + colorVector.ToZyxBytes(bgrVector, 0); + + Assert.Equal(bgr, bgrVector); + } + + [Fact] + public void Color_Types_To_BgraBytes_Produce_Equal_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + byte[] bgra = new byte[4]; + byte[] bgraVector = new byte[4]; + + color.ToZyxwBytes(bgra, 0); + colorVector.ToZyxwBytes(bgraVector, 0); + + Assert.Equal(bgra, bgraVector); + } + + [Fact] + public void Color_Types_To_Hex_Produce_Equal_OutPut() + { + Color color = new Color(24, 48, 96, 192); + ColorVector colorVector = new ColorVector(24, 48, 96, 192); + + // 183060C0 + Assert.Equal(color.ToHex(), colorVector.ToHex()); + } + } +} \ No newline at end of file From e7e9f7bdd28870469f960a0fcfb72457390f6503 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 00:55:03 +1000 Subject: [PATCH 26/34] Add transforms plus additional tests --- .../Colors/ColorVector.Transforms.cs | 253 ++++++++++++++++++ .../Colors/ColorVectorTests.cs | 132 +++++++++ .../Colors/ColorVectorTransformTests.cs | 118 ++++++++ 3 files changed, 503 insertions(+) create mode 100644 src/ImageSharp/Colors/ColorVector.Transforms.cs create mode 100644 tests/ImageSharp.Tests/Colors/ColorVectorTests.cs create mode 100644 tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs diff --git a/src/ImageSharp/Colors/ColorVector.Transforms.cs b/src/ImageSharp/Colors/ColorVector.Transforms.cs new file mode 100644 index 000000000..e9666a351 --- /dev/null +++ b/src/ImageSharp/Colors/ColorVector.Transforms.cs @@ -0,0 +1,253 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System.Numerics; + + /// + /// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1. + /// 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 partial struct ColorVector + { + /// + /// Adds the second color to the first. + /// + /// The first source color. + /// The second source color. + /// + /// The . + /// + public static ColorVector operator +(ColorVector left, ColorVector right) + { + return new ColorVector(left.backingVector + right.backingVector); + } + + /// + /// Subtracts the second color from the first. + /// + /// The first source color. + /// The second source color. + /// + /// The . + /// + public static ColorVector operator -(ColorVector left, ColorVector right) + { + return new ColorVector(left.backingVector - right.backingVector); + } + + /// + /// The blending formula simply selects the source color. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Normal(ColorVector backdrop, ColorVector source) + { + Vector4 normal = Vector4BlendTransforms.Normal(backdrop.backingVector, source.backingVector); + return new ColorVector(normal); + } + + /// + /// Blends two colors by multiplication. + /// + /// The source color is multiplied by the destination color and replaces the destination. + /// The resultant color is always at least as dark as either the source or destination color. + /// Multiplying any color with black results in black. Multiplying any color with white preserves the + /// original color. + /// + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Multiply(ColorVector backdrop, ColorVector source) + { + Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.backingVector, source.backingVector); + return new ColorVector(multiply); + } + + /// + /// Multiplies the complements of the backdrop and source color values, then complements the result. + /// + /// The result color is always at least as light as either of the two constituent colors. Screening any + /// color with white produces white; screening with black leaves the original color unchanged. + /// The effect is similar to projecting multiple photographic slides simultaneously onto a single screen. + /// + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Screen(ColorVector backdrop, ColorVector source) + { + Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.backingVector, source.backingVector); + return new ColorVector(subtract); + } + + /// + /// Multiplies or screens the colors, depending on the source color value. The effect is similar to + /// shining a harsh spotlight on the backdrop. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector HardLight(ColorVector backdrop, ColorVector source) + { + Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.backingVector, source.backingVector); + return new ColorVector(hardlight); + } + + /// + /// Multiplies or screens the colors, depending on the backdrop color value. + /// + /// Source colors overlay the backdrop while preserving its highlights and shadows. + /// The backdrop color is not replaced but is mixed with the source color to reflect the lightness or darkness + /// of the backdrop. + /// + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Overlay(ColorVector backdrop, ColorVector source) + { + Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.backingVector, source.backingVector); + return new ColorVector(overlay); + } + + /// + /// Selects the darker of the backdrop and source colors. + /// The backdrop is replaced with the source where the source is darker; otherwise, it is left unchanged. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Darken(ColorVector backdrop, ColorVector source) + { + Vector4 darken = Vector4BlendTransforms.Darken(backdrop.backingVector, source.backingVector); + return new ColorVector(darken); + } + + /// + /// Selects the lighter of the backdrop and source colors. + /// The backdrop is replaced with the source where the source is lighter; otherwise, it is left unchanged. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Lighten(ColorVector backdrop, ColorVector source) + { + Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.backingVector, source.backingVector); + return new ColorVector(lighten); + } + + /// + /// Darkens or lightens the colors, depending on the source color value. The effect is similar to shining + /// a diffused spotlight on the backdrop. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector SoftLight(ColorVector backdrop, ColorVector source) + { + Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.backingVector, source.backingVector); + return new ColorVector(softlight); + } + + /// + /// Brightens the backdrop color to reflect the source color. Painting with black produces no changes. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector ColorDodge(ColorVector backdrop, ColorVector source) + { + Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.backingVector, source.backingVector); + return new ColorVector(dodge); + } + + /// + /// Darkens the backdrop color to reflect the source color. Painting with white produces no change. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector ColorBurn(ColorVector backdrop, ColorVector source) + { + Vector4 burn = Vector4BlendTransforms.Burn(backdrop.backingVector, source.backingVector); + return new ColorVector(burn); + } + + /// + /// Subtracts the darker of the two constituent colors from the lighter color. + /// Painting with white inverts the backdrop color; painting with black produces no change. + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Difference(ColorVector backdrop, ColorVector source) + { + Vector4 difference = Vector4BlendTransforms.Difference(backdrop.backingVector, source.backingVector); + return new ColorVector(difference); + } + + /// + /// Produces an effect similar to that of the mode but lower in contrast. Painting with white + /// inverts the backdrop color; painting with black produces no change + /// + /// The backdrop color. + /// The source color. + /// + /// The . + /// + public static ColorVector Exclusion(ColorVector backdrop, ColorVector source) + { + Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.backingVector, source.backingVector); + return new ColorVector(exclusion); + } + + /// + /// Linearly interpolates from one color to another based on the given weighting. + /// + /// The first color value. + /// The second color value. + /// + /// A value between 0 and 1 indicating the weight of the second source vector. + /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. + /// + /// + /// The + /// + public static ColorVector Lerp(ColorVector from, ColorVector to, float amount) + { + return new ColorVector(Vector4.Lerp(from.backingVector, to.backingVector, amount)); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs b/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs new file mode 100644 index 000000000..4300b1b38 --- /dev/null +++ b/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs @@ -0,0 +1,132 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + using Xunit; + + /// + /// Tests the struct. + /// + public class ColorVectorTests + { + /// + /// Tests the equality operators for equality. + /// + [Fact] + public void AreEqual() + { + ColorVector color1 = new ColorVector(0, 0, 0F); + ColorVector color2 = new ColorVector(0, 0, 0, 1F); + ColorVector color3 = ColorVector.FromHex("#000"); + ColorVector color4 = ColorVector.FromHex("#000F"); + ColorVector color5 = ColorVector.FromHex("#000000"); + ColorVector color6 = ColorVector.FromHex("#000000FF"); + + Assert.Equal(color1, color2); + Assert.Equal(color1, color3); + Assert.Equal(color1, color4); + Assert.Equal(color1, color5); + Assert.Equal(color1, color6); + } + + /// + /// Tests the equality operators for inequality. + /// + [Fact] + public void AreNotEqual() + { + ColorVector color1 = new ColorVector(1, 0, 0, 1); + ColorVector color2 = new ColorVector(0, 0, 0, 1); + ColorVector color3 = ColorVector.FromHex("#000"); + ColorVector color4 = ColorVector.FromHex("#000000"); + ColorVector color5 = ColorVector.FromHex("#FF000000"); + + Assert.NotEqual(color1, color2); + Assert.NotEqual(color1, color3); + Assert.NotEqual(color1, color4); + Assert.NotEqual(color1, color5); + } + + /// + /// Tests whether the color constructor correctly assign properties. + /// + [Fact] + public void ConstructorAssignsProperties() + { + ColorVector color1 = new ColorVector(1, .1F, .133F, .864F); + Assert.Equal(1F, color1.R); + Assert.Equal(.1F, color1.G); + Assert.Equal(.133F, color1.B); + Assert.Equal(.864F, color1.A); + + ColorVector color2 = new ColorVector(1, .1f, .133f); + Assert.Equal(1F, color2.R); + Assert.Equal(.1F, color2.G); + Assert.Equal(.133F, color2.B); + Assert.Equal(1F, color2.A); + + ColorVector color4 = new ColorVector(new Vector3(1, .1f, .133f)); + Assert.Equal(1F, color4.R); + Assert.Equal(.1F, color4.G); + Assert.Equal(.133F, color4.B); + Assert.Equal(1F, color4.A); + + ColorVector color5 = new ColorVector(new Vector4(1, .1f, .133f, .5f)); + Assert.Equal(1F, color5.R); + Assert.Equal(.1F, color5.G); + Assert.Equal(.133F, color5.B); + Assert.Equal(.5F, color5.A); + } + + /// + /// Tests whether FromHex and ToHex work correctly. + /// + [Fact] + public void FromAndToHex() + { + ColorVector color = ColorVector.FromHex("#AABBCCDD"); + Assert.Equal(170 / 255F, color.R); + Assert.Equal(187 / 255F, color.G); + Assert.Equal(204 / 255F, color.B); + Assert.Equal(221 / 255F, color.A); + + color.A = 170 / 255F; + color.B = 187 / 255F; + color.G = 204 / 255F; + color.R = 221 / 255F; + + Assert.Equal("DDCCBBAA", color.ToHex()); + + color.R = 0; + + Assert.Equal("00CCBBAA", color.ToHex()); + + color.A = 255 / 255F; + + Assert.Equal("00CCBBFF", color.ToHex()); + } + + /// + /// Tests that the individual float elements are layed out in RGBA order. + /// + [Fact] + public void FloatLayout() + { + ColorVector color = new ColorVector(1F, 2, 3, 4); + Vector4 colorBase = Unsafe.As(ref Unsafe.Add(ref color, 0)); + float[] ordered = new float[4]; + colorBase.CopyTo(ordered); + + Assert.Equal(1, ordered[0]); + Assert.Equal(2, ordered[1]); + Assert.Equal(3, ordered[2]); + Assert.Equal(4, ordered[3]); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs b/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs new file mode 100644 index 000000000..985e54998 --- /dev/null +++ b/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs @@ -0,0 +1,118 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Colors +{ + using Xunit; + + /// + /// Tests the color transform algorithms. Test results match the output of CSS equivalents. + /// + /// + public class ColorVectorTransformTests + { + private static readonly ApproximateFloatComparer FloatComparer = new ApproximateFloatComparer(0.01F); + + /// + /// Orange backdrop + /// + private static readonly ColorVector Backdrop = new ColorVector(204, 102, 0); + + /// + /// Blue source + /// + private static readonly ColorVector Source = new ColorVector(0, 102, 153); + + [Fact] + public void Normal() + { + ColorVector normal = ColorVector.Normal(Backdrop, Source); + Assert.True(normal == Source); + } + + [Fact] + public void Multiply() + { + Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer); + Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.White).ToVector4(), ColorVector.White.ToVector4(), FloatComparer); + + ColorVector multiply = ColorVector.Multiply(Backdrop, Source); + Assert.Equal(multiply.ToVector4(), new ColorVector(0, 41, 0).ToVector4(), FloatComparer); + } + + [Fact] + public void Screen() + { + Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer); + Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.White).ToVector4(), ColorVector.White.ToVector4(), FloatComparer); + + ColorVector screen = ColorVector.Screen(Backdrop, Source); + Assert.Equal(screen.ToVector4(), new ColorVector(204, 163, 153).ToVector4(), FloatComparer); + } + + [Fact] + public void HardLight() + { + ColorVector hardLight = ColorVector.HardLight(Backdrop, Source); + Assert.Equal(hardLight.ToVector4(), new ColorVector(0, 82, 51).ToVector4(), FloatComparer); + } + + [Fact] + public void Overlay() + { + ColorVector overlay = ColorVector.Overlay(Backdrop, Source); + Assert.Equal(overlay.ToVector4(), new ColorVector(153, 82, 0).ToVector4(), FloatComparer); + } + + [Fact] + public void Darken() + { + ColorVector darken = ColorVector.Darken(Backdrop, Source); + Assert.Equal(darken.ToVector4(), new ColorVector(0, 102, 0).ToVector4(), FloatComparer); + } + + [Fact] + public void Lighten() + { + ColorVector lighten = ColorVector.Lighten(Backdrop, Source); + Assert.Equal(lighten.ToVector4(), new ColorVector(204, 102, 153).ToVector4(), FloatComparer); + } + + [Fact] + public void SoftLight() + { + ColorVector softLight = ColorVector.SoftLight(Backdrop, Source); + Assert.Equal(softLight.ToVector4(), new ColorVector(163, 90, 0).ToVector4(), FloatComparer); + } + + [Fact] + public void ColorDodge() + { + ColorVector colorDodge = ColorVector.ColorDodge(Backdrop, Source); + Assert.Equal(colorDodge.ToVector4(), new ColorVector(204, 170, 0).ToVector4(), FloatComparer); + } + + [Fact] + public void ColorBurn() + { + ColorVector colorBurn = ColorVector.ColorBurn(Backdrop, Source); + Assert.Equal(colorBurn.ToVector4(), new ColorVector(0, 0, 0).ToVector4(), FloatComparer); + } + + [Fact] + public void Difference() + { + ColorVector difference = ColorVector.Difference(Backdrop, Source); + Assert.Equal(difference.ToVector4(), new ColorVector(204, 0, 153).ToVector4(), FloatComparer); + } + + [Fact] + public void Exclusion() + { + ColorVector exclusion = ColorVector.Exclusion(Backdrop, Source); + Assert.Equal(exclusion.ToVector4(), new ColorVector(204, 122, 153).ToVector4(), FloatComparer); + } + } +} From 3d41e1560b26426cbf26a4c2c54a559105435069 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 01:10:34 +1000 Subject: [PATCH 27/34] Fix failing test --- tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs b/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs index 985e54998..c2e27d231 100644 --- a/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs @@ -35,8 +35,8 @@ namespace ImageSharp.Tests.Colors [Fact] public void Multiply() { - Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer); - Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.White).ToVector4(), ColorVector.White.ToVector4(), FloatComparer); + Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.Black).ToVector4(), Color.Black.ToVector4(), FloatComparer); + Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.White).ToVector4(), Backdrop.ToVector4(), FloatComparer); ColorVector multiply = ColorVector.Multiply(Backdrop, Source); Assert.Equal(multiply.ToVector4(), new ColorVector(0, 41, 0).ToVector4(), FloatComparer); From 61d552345a3307f5dfafcb5029be589b857f5f55 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:16:20 +1000 Subject: [PATCH 28/34] Change xunit layout --- tests/ImageSharp.Tests/ImageSharp.Tests.csproj | 5 +++++ 1 file changed, 5 insertions(+) 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 From 86957b2f4844b40c8aa4f551e78876490e15a59e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:16:35 +1000 Subject: [PATCH 29/34] Delete Rgba32 --- src/ImageSharp/Colors/PackedPixel/Rgba32.cs | 398 -------------------- 1 file changed, 398 deletions(-) delete mode 100644 src/ImageSharp/Colors/PackedPixel/Rgba32.cs 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 From aaf5f920b62934bdaef092bef677a90fc79d2f26 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:17:26 +1000 Subject: [PATCH 30/34] Add PackedValue back to Color --- src/ImageSharp/Colors/Color.cs | 96 ++++++++++++------- .../ImageProviders/TestPatternProvider.cs | 2 +- 2 files changed, 65 insertions(+), 33 deletions(-) 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/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++) From 8891ab02e4141ed00769f5ddaea0369f7fc9d2a0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:17:50 +1000 Subject: [PATCH 31/34] Add missing xunit file --- tests/ImageSharp.Tests/xunit.runner.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/ImageSharp.Tests/xunit.runner.json 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 From 6b6df21cb6dd7d7605b0c15dd3cfdeeae375e82f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:18:09 +1000 Subject: [PATCH 32/34] ColorVector perf improvements --- src/ImageSharp/Colors/ColorVector.Definitions.cs | 2 +- src/ImageSharp/Colors/ColorVector.Transforms.cs | 5 ++++- src/ImageSharp/Colors/ColorVector.cs | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) 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() { From 29cbdc4a1b2db7b332797e36e6d320dffaa84bc5 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:18:35 +1000 Subject: [PATCH 33/34] Rename Argb, Add Color to tests --- src/ImageSharp/Colors/Color.Transforms.cs | 36 ++++++++------- src/ImageSharp/Colors/ColorspaceTransforms.cs | 2 +- .../Colors/PackedPixel/{Argb.cs => Argb32.cs} | 46 +++++++++---------- .../PackedPixel/PackedPixelConverterHelper.cs | 2 +- .../Color/Bulk/ToXyzw.cs | 2 +- .../Colors/BulkPixelOperationsTests.cs | 2 +- .../Colors/ColorConstructorTests.cs | 8 ++-- .../Colors/ColorEqualityTests.cs | 12 ++--- .../Colors/ColorPackingTests.cs | 4 +- tests/ImageSharp.Tests/Colors/ColorTests.cs | 2 + .../Colors/PackedPixelTests.cs | 46 +++++++++---------- .../Tests/TestUtilityExtensionsTests.cs | 4 +- 12 files changed, 86 insertions(+), 80 deletions(-) rename src/ImageSharp/Colors/PackedPixel/{Argb.cs => Argb32.cs} (87%) 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/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/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..745da3f9d 100644 --- a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs +++ b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs @@ -65,26 +65,26 @@ namespace ImageSharp.Tests.Colors public void Argb() { // 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/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 63c24a157..852ce006c 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.Argb, 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.Argb)] public void GetPixelType(Type clrType, PixelTypes expectedPixelType) { Assert.Equal(expectedPixelType, clrType.GetPixelType()); From 3b9079020dfe7c9bdcc28c49cd15165a5fe9966b Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:33:22 +1000 Subject: [PATCH 34/34] Fix Argb32 naming in typehelpers. --- tests/ImageSharp.Tests/Colors/PackedPixelTests.cs | 2 +- tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs | 4 ++-- tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs | 4 ++-- tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs | 4 ++-- tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs | 2 +- .../TestUtilities/Tests/TestImageProviderTests.cs | 6 +++--- .../TestUtilities/Tests/TestUtilityExtensionsTests.cs | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs index 745da3f9d..52ca86cae 100644 --- a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs +++ b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs @@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Colors } [Fact] - public void Argb() + public void Argb32() { // Test the limits. Assert.Equal((uint)0x0, new Argb32(Vector4.Zero).PackedValue); 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/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 852ce006c..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(Argb32))] + [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(Argb32), PixelTypes.Argb)] + [InlineData(typeof(Argb32), PixelTypes.Argb32)] public void GetPixelType(Type clrType, PixelTypes expectedPixelType) { Assert.Equal(expectedPixelType, clrType.GetPixelType());