From 7c4d05c06e802aadbb392d3036ae873fbb0e453a Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 18 Feb 2017 15:09:16 +0100 Subject: [PATCH] IPixel --- src/ImageSharp/Colors/PackedPixel/IPixel.cs | 68 +++++++++++++++++++ .../Common/Memory/ArrayPointer{T}.cs | 4 +- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/ImageSharp/Colors/PackedPixel/IPixel.cs diff --git a/src/ImageSharp/Colors/PackedPixel/IPixel.cs b/src/ImageSharp/Colors/PackedPixel/IPixel.cs new file mode 100644 index 000000000..a222edd9a --- /dev/null +++ b/src/ImageSharp/Colors/PackedPixel/IPixel.cs @@ -0,0 +1,68 @@ +namespace ImageSharp +{ + using System; + using System.Numerics; + + public interface IPixel + { + /// + /// Sets the packed representation from a . + /// + /// The vector to create the packed representation from. + void PackFromVector4(Vector4 vector); + + /// + /// Expands the packed representation into a . + /// The vector components are typically expanded in least to greatest significance order. + /// + /// The . + Vector4 ToVector4(); + + /// + /// Sets the packed representation from the given byte array. + /// + /// The x-component. + /// The y-component. + /// The z-component. + /// The w-component. + void PackFromBytes(byte x, byte y, byte z, byte w); + + /// + /// Expands the packed representation into a given byte array. + /// 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 . + void ToXyzBytes(byte[] bytes, int startIndex); + + /// + /// 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 + /// + /// The bytes to set the color in. + /// The starting index of the . + void ToXyzwBytes(byte[] bytes, int startIndex); + + /// + /// Expands the packed representation into a given byte array. + /// 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 . + void ToZyxBytes(byte[] bytes, int startIndex); + + /// + /// 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 + /// + /// The bytes to set the color in. + /// The starting index of the . + void ToZyxwBytes(byte[] bytes, int startIndex); + } + + public interface IPixel : IPixel, IEquatable + where TSelf : struct, IPixel + { + + } +} \ No newline at end of file diff --git a/src/ImageSharp/Common/Memory/ArrayPointer{T}.cs b/src/ImageSharp/Common/Memory/ArrayPointer{T}.cs index c3fc32234..06de06107 100644 --- a/src/ImageSharp/Common/Memory/ArrayPointer{T}.cs +++ b/src/ImageSharp/Common/Memory/ArrayPointer{T}.cs @@ -16,7 +16,7 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArrayPointer(T[] array, void* pointerToArray, int offset) { - // TODO: Use Guard.NotNull() here after optimizing it with ThrowHelper! + // TODO: Use Guard.NotNull() here after optimizing it by eliminating the default argument case and applying ThrowHelper! if (array == null) { ThrowHelper.ThrowArgumentNullException(nameof(array)); @@ -29,7 +29,7 @@ namespace ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArrayPointer(T[] array, void* pointerToArray) { - // TODO: Use Guard.NotNull() here after optimizing it with ThrowHelper! + // TODO: Use Guard.NotNull() here after optimizing it by eliminating the default argument case and applying ThrowHelper! if (array == null) { ThrowHelper.ThrowArgumentNullException(nameof(array));