From 3cdc423500b4894ce8c0f7d43073ec16d1e90a5d Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 19 Feb 2017 14:18:41 +0100 Subject: [PATCH] The return of IPackedVector --- src/ImageSharp/Colors/Color.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Alpha8.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Argb.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Bgr565.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Bgra4444.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Bgra5551.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Byte4.cs | 2 +- .../Colors/PackedPixel/HalfSingle.cs | 2 +- .../Colors/PackedPixel/HalfVector2.cs | 2 +- .../Colors/PackedPixel/HalfVector4.cs | 2 +- .../PackedPixel/IPackedVector{TPacked}.cs | 24 +++++++++++++++++++ .../Colors/PackedPixel/NormalizedByte2.cs | 2 +- .../Colors/PackedPixel/NormalizedByte4.cs | 2 +- .../Colors/PackedPixel/NormalizedShort2.cs | 2 +- .../Colors/PackedPixel/NormalizedShort4.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Rg32.cs | 2 +- .../Colors/PackedPixel/Rgba1010102.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Rgba64.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Short2.cs | 2 +- src/ImageSharp/Colors/PackedPixel/Short4.cs | 2 +- .../Common/ArrayPointerTests.cs | 18 +------------- 21 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index b82628b3b8..2c0d80e52d 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -18,7 +18,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 : IPixel + public partial struct Color : IPixel, IPackedVector { /// /// The shift count for the red component diff --git a/src/ImageSharp/Colors/PackedPixel/Alpha8.cs b/src/ImageSharp/Colors/PackedPixel/Alpha8.cs index 5141cbca43..6339b66a88 100644 --- a/src/ImageSharp/Colors/PackedPixel/Alpha8.cs +++ b/src/ImageSharp/Colors/PackedPixel/Alpha8.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing a single 8 bit normalized W values ranging from 0 to 1. /// - public struct Alpha8 : IPixel + public struct Alpha8 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Argb.cs b/src/ImageSharp/Colors/PackedPixel/Argb.cs index 57ae0898bb..da3c50917b 100644 --- a/src/ImageSharp/Colors/PackedPixel/Argb.cs +++ b/src/ImageSharp/Colors/PackedPixel/Argb.cs @@ -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 + public struct Argb : IPixel, IPackedVector { /// /// The shift count for the blue component diff --git a/src/ImageSharp/Colors/PackedPixel/Bgr565.cs b/src/ImageSharp/Colors/PackedPixel/Bgr565.cs index 042c8c0f5f..e11aa9c650 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgr565.cs +++ b/src/ImageSharp/Colors/PackedPixel/Bgr565.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits. /// - public struct Bgr565 : IPixel + public struct Bgr565 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs b/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs index 8bae542c2a..9853409eaa 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs +++ b/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w. /// - public struct Bgra4444 : IPixel + public struct Bgra4444 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs b/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs index 0ad7dbd0e3..bed6581339 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs +++ b/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x , y and z components use 5 bits, and the w component uses 1 bit. /// - public struct Bgra5551 : IPixel + public struct Bgra5551 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Byte4.cs b/src/ImageSharp/Colors/PackedPixel/Byte4.cs index b1f8d5a6ea..79a625c312 100644 --- a/src/ImageSharp/Colors/PackedPixel/Byte4.cs +++ b/src/ImageSharp/Colors/PackedPixel/Byte4.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255. /// - public struct Byte4 : IPixel + public struct Byte4 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs b/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs index bd4ba3840a..9737a99ae7 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing a single 16 bit floating point value. /// - public struct HalfSingle : IPixel + public struct HalfSingle : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs b/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs index 4d1f0a2cb4..57649dbd5e 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing two 16-bit floating-point values. /// - public struct HalfVector2 : IPixel + public struct HalfVector2 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs b/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs index e0108404d1..f4f08a25c6 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 16-bit floating-point values. /// - public struct HalfVector4 : IPixel + public struct HalfVector4 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs b/src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs new file mode 100644 index 0000000000..0450fb8fba --- /dev/null +++ b/src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs @@ -0,0 +1,24 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + + /// + /// This interface exists for ensuring signature compatibility to MonoGame and XNA packed color types. + /// + /// + /// The packed format. uint, long, float. + public interface IPackedVector : IPixel + where TPacked : struct, IEquatable + { + /// + /// Gets or sets the packed representation of the value. + /// + TPacked PackedValue { get; set; } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs index 0567b44452..1fece550fa 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1. /// - public struct NormalizedByte2 : IPixel + public struct NormalizedByte2 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs index a45f601c4c..d49ea8a654 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 8-bit signed normalized values, ranging from −1 to 1. /// - public struct NormalizedByte4 : IPixel + public struct NormalizedByte4 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs index 3642aed5b6..b9a2dc5332 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing two 16-bit signed normalized values, ranging from −1 to 1. /// - public struct NormalizedShort2 : IPixel + public struct NormalizedShort2 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs index d5a3de79e9..2cf90d2081 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 16-bit signed normalized values, ranging from −1 to 1. /// - public struct NormalizedShort4 : IPixel + public struct NormalizedShort4 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/Rg32.cs b/src/ImageSharp/Colors/PackedPixel/Rg32.cs index 9bda5f6058..0dbcf483a9 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rg32.cs +++ b/src/ImageSharp/Colors/PackedPixel/Rg32.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 1. /// - public struct Rg32 : IPixel + public struct Rg32 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs b/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs index 69c097f964..f867afb014 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs +++ b/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs @@ -13,7 +13,7 @@ namespace ImageSharp /// Packed vector type containing unsigned normalized values ranging from 0 to 1. /// The x, y and z components use 10 bits, and the w component uses 2 bits. /// - public struct Rgba1010102 : IPixel + public struct Rgba1010102 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba64.cs b/src/ImageSharp/Colors/PackedPixel/Rgba64.cs index 4705564354..a99e127f35 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rgba64.cs +++ b/src/ImageSharp/Colors/PackedPixel/Rgba64.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. /// - public struct Rgba64 : IPixel + public struct Rgba64 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/PackedPixel/Short2.cs b/src/ImageSharp/Colors/PackedPixel/Short2.cs index 3f83a4cd5d..a89005ce54 100644 --- a/src/ImageSharp/Colors/PackedPixel/Short2.cs +++ b/src/ImageSharp/Colors/PackedPixel/Short2.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing two 16-bit signed integer values. /// - public struct Short2 : IPixel + public struct Short2 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/src/ImageSharp/Colors/PackedPixel/Short4.cs b/src/ImageSharp/Colors/PackedPixel/Short4.cs index 1696cb40a4..4b6a6d00b5 100644 --- a/src/ImageSharp/Colors/PackedPixel/Short4.cs +++ b/src/ImageSharp/Colors/PackedPixel/Short4.cs @@ -12,7 +12,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 16-bit signed integer values. /// - public struct Short4 : IPixel + public struct Short4 : IPixel, IPackedVector { /// /// The maximum byte value. diff --git a/tests/ImageSharp.Tests/Common/ArrayPointerTests.cs b/tests/ImageSharp.Tests/Common/ArrayPointerTests.cs index 64cd306f3a..076e2512c8 100644 --- a/tests/ImageSharp.Tests/Common/ArrayPointerTests.cs +++ b/tests/ImageSharp.Tests/Common/ArrayPointerTests.cs @@ -26,23 +26,7 @@ namespace ImageSharp.Tests.Common return result; } } - - [Fact] - public void ConstructWithNullArray_Throws() - { - Assert.Throws( - () => - { - new ArrayPointer(null, (void*)0); - }); - - Assert.Throws( - () => - { - new ArrayPointer(null, (void*)0); - }); - } - + [Fact] public void ConstructWithoutOffset() {