diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/Colors/Color.BulkOperations.cs index 2488c643f..3a1d66752 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/Colors/Color.BulkOperations.cs @@ -1,3 +1,8 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + namespace ImageSharp { using System; @@ -5,6 +10,9 @@ namespace ImageSharp using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + /// + /// Conains the definition of + /// public partial struct Color { /// @@ -13,27 +21,7 @@ namespace ImageSharp internal class BulkOperations : BulkPixelOperations { /// - /// Value type to store -s unpacked into multiple -s. - /// - 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; - } - } - - /// - /// SIMD optimized bulk implementation of + /// SIMD optimized bulk implementation of /// that works only with `count` divisible by . /// /// The to the source colors. @@ -55,8 +43,7 @@ namespace ImageSharp DebugGuard.IsTrue( count % vecSize == 0, nameof(count), - "Argument 'count' should divisible by Vector.Count!" - ); + "Argument 'count' should divisible by Vector.Count!"); Vector bVec = new Vector(256.0f / 255.0f); Vector magicFloat = new Vector(32768.0f); @@ -64,7 +51,7 @@ namespace ImageSharp Vector mask = new Vector(255); int unpackedRawCount = count * 4; - + uint* src = (uint*)sourceColors.PointerAtOffset; uint* srcEnd = src + count; @@ -92,7 +79,7 @@ namespace ImageSharp vf.CopyTo(fTemp, i); } - BufferPointer.Copy(tempBuf, (BufferPointer) destVectors, unpackedRawCount); + BufferPointer.Copy(tempBuf, (BufferPointer)destVectors, unpackedRawCount); } } @@ -120,7 +107,7 @@ namespace ImageSharp internal override unsafe void PackFromXyzBytes(BufferPointer sourceBytes, BufferPointer destColors, int count) { byte* source = (byte*)sourceBytes; - byte* destination = (byte*)destColors; + byte* destination = (byte*)destColors; for (int x = 0; x < count; x++) { @@ -224,6 +211,26 @@ namespace ImageSharp destination += 4; } } + + /// + /// Value type to store -s unpacked into multiple -s. + /// + 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; + } + } } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index 1375636f4..c1fa46191 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -30,7 +30,6 @@ namespace ImageSharp } } - /// /// Verifies that the specified value is less than a maximum value /// and throws an exception if it is not. @@ -117,7 +116,6 @@ namespace ImageSharp } } - /// /// Verifies, that the method parameter with specified target value is true /// and throws an exception if it is found to be so. diff --git a/src/ImageSharp/Common/Memory/BufferPointer.cs b/src/ImageSharp/Common/Memory/BufferPointer.cs index 10a5c2db2..e600f4188 100644 --- a/src/ImageSharp/Common/Memory/BufferPointer.cs +++ b/src/ImageSharp/Common/Memory/BufferPointer.cs @@ -63,7 +63,7 @@ namespace ImageSharp return; } } - + Unsafe.CopyBlock((void*)destination.PointerAtOffset, (void*)source.PointerAtOffset, byteCount); } @@ -110,13 +110,13 @@ namespace ImageSharp public static uint USizeOf(int count) where T : struct => (uint)SizeOf(count); - + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryMarshalCopy(BufferPointer source, BufferPointer destination, int count) - where TSource : struct + where TSource : struct where TDest : struct { - // Pattern Based On: + // Pattern Based On: // https://github.com/dotnet/corefx/blob/master/src/System.Numerics.Vectors/src/System/Numerics/Vector.cs#L12 // // Note: The following patterns are used throughout the code here and are described here @@ -128,7 +128,6 @@ namespace ImageSharp // At runtime, each instantiation of BufferPointer will be type-specific, and each of these typeof blocks will be eliminated, // as typeof(T) is a (JIT) compile-time constant for each instantiation. This design was chosen to eliminate any overhead from // delegates and other patterns. - if (typeof(TSource) == typeof(long)) { long[] srcArray = Unsafe.As(source.Array); diff --git a/src/ImageSharp/Common/Memory/BufferPointer{T}.cs b/src/ImageSharp/Common/Memory/BufferPointer{T}.cs index a9935c5dd..fe79e064e 100644 --- a/src/ImageSharp/Common/Memory/BufferPointer{T}.cs +++ b/src/ImageSharp/Common/Memory/BufferPointer{T}.cs @@ -89,7 +89,7 @@ namespace ImageSharp } /// - /// Converts instance to + /// Converts instance to /// setting it's and to correct values. /// /// The to convert diff --git a/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs b/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs index ea76252c5..e90238888 100644 --- a/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs +++ b/src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs @@ -95,7 +95,7 @@ namespace ImageSharp /// Gets a pointer to the pinned . /// public IntPtr Pointer { get; private set; } - + /// /// Converts to an . /// @@ -107,9 +107,8 @@ namespace ImageSharp } /// - /// Gets a to the beginning of the raw data in 'buffer'. + /// Gets a to the beginning of the raw data of the buffer. /// - /// The element type /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe BufferPointer Slice() @@ -118,9 +117,9 @@ namespace ImageSharp } /// - /// Gets a to the beginning of the raw data in 'buffer'. + /// Gets a to an offseted position inside the buffer. /// - /// The element type + /// The offset /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe BufferPointer Slice(int offset) @@ -128,7 +127,6 @@ namespace ImageSharp return new BufferPointer(this.Array, (void*)this.Pointer, offset); } - /// /// Disposes the instance by unpinning the array, and returning the pooled buffer when necessary. ///