Browse Source

Promote PixelTypeInfo to TPixel

Fixes #2534
pull/2601/head
Stefan Nikolei 2 years ago
parent
commit
b52ef56181
  1. 32
      src/ImageSharp/Formats/PixelTypeInfo.cs
  2. 8
      src/ImageSharp/Image{TPixel}.cs
  3. 3
      src/ImageSharp/PixelFormats/IPixel.cs
  4. 3
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  5. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
  6. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
  7. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
  8. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
  9. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
  10. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
  11. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
  12. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
  13. 3
      src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
  14. 3
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
  15. 3
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
  16. 3
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  17. 3
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  18. 3
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  19. 3
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  20. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
  21. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
  22. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
  23. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
  24. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs
  25. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs
  26. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs
  27. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs
  28. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs
  29. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs
  30. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs
  31. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs
  32. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs
  33. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs
  34. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs
  35. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs
  36. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs
  37. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs
  38. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs
  39. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs
  40. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs
  41. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs
  42. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs
  43. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs
  44. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs
  45. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs
  46. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs
  47. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs
  48. 6
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs
  49. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs
  50. 6
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs
  51. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs
  52. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs
  53. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
  54. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
  55. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
  56. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
  57. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  58. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
  59. 3
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  60. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
  61. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
  62. 3
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  63. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs
  64. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  65. 2
      tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs
  66. 263
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs
  67. 9
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude
  68. 6
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  69. 2
      tests/ImageSharp.Tests/TestFormat.cs
  70. 5
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs

32
src/ImageSharp/Formats/PixelTypeInfo.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Formats;
/// <summary>
/// Contains information about the pixels that make up an images visual data.
/// </summary>
public class PixelTypeInfo
public readonly struct PixelTypeInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> class.
@ -21,33 +21,25 @@ public class PixelTypeInfo
public PixelTypeInfo(int bitsPerPixel)
=> this.BitsPerPixel = bitsPerPixel;
/// <summary>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> class.
/// </summary>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
/// <param name="alpha">The pixel alpha transparency behavior.</param>
public PixelTypeInfo(int bitsPerPixel, PixelAlphaRepresentation alpha)
{
this.BitsPerPixel = bitsPerPixel;
this.AlphaRepresentation = alpha;
}
/// <summary>
/// Gets color depth, in number of bits per pixel.
/// </summary>
public int BitsPerPixel { get; }
public int BitsPerPixel { get; init; }
public byte ComponentCount { get; init; }
/// <summary>
/// Gets the pixel alpha transparency behavior.
/// <see langword="null"/> means unknown, unspecified.
/// </summary>
public PixelAlphaRepresentation? AlphaRepresentation { get; }
internal static PixelTypeInfo Create<TPixel>()
where TPixel : unmanaged, IPixel<TPixel>
=> new(Unsafe.SizeOf<TPixel>() * 8);
public PixelAlphaRepresentation? AlphaRepresentation { get; init; }
internal static PixelTypeInfo Create<TPixel>(PixelAlphaRepresentation alpha)
internal static PixelTypeInfo Create<TPixel>(byte componentCount, PixelAlphaRepresentation pixelAlphaRepresentation)
where TPixel : unmanaged, IPixel<TPixel>
=> new(Unsafe.SizeOf<TPixel>() * 8, alpha);
=> new()
{
BitsPerPixel = Unsafe.SizeOf<TPixel>() * 8,
ComponentCount = componentCount,
AlphaRepresentation = pixelAlphaRepresentation
};
}

8
src/ImageSharp/Image{TPixel}.cs

@ -78,7 +78,7 @@ public sealed class Image<TPixel> : Image
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images metadata.</param>
internal Image(Configuration configuration, int width, int height, ImageMetadata? metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata ?? new(), width, height)
: base(configuration, TPixel.GetPixelTypeInfo(), metadata ?? new(), width, height)
=> this.frames = new ImageFrameCollection<TPixel>(this, width, height, default(TPixel));
/// <summary>
@ -111,7 +111,7 @@ public sealed class Image<TPixel> : Image
int width,
int height,
ImageMetadata metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height)
: base(configuration, TPixel.GetPixelTypeInfo(), metadata, width, height)
=> this.frames = new ImageFrameCollection<TPixel>(this, width, height, memoryGroup);
/// <summary>
@ -129,7 +129,7 @@ public sealed class Image<TPixel> : Image
int height,
TPixel backgroundColor,
ImageMetadata? metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata ?? new(), width, height)
: base(configuration, TPixel.GetPixelTypeInfo(), metadata ?? new(), width, height)
=> this.frames = new ImageFrameCollection<TPixel>(this, width, height, backgroundColor);
/// <summary>
@ -140,7 +140,7 @@ public sealed class Image<TPixel> : Image
/// <param name="metadata">The images metadata.</param>
/// <param name="frames">The frames that will be owned by this image instance.</param>
internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable<ImageFrame<TPixel>> frames)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, ValidateFramesAndGetSize(frames))
: base(configuration, TPixel.GetPixelTypeInfo(), metadata, ValidateFramesAndGetSize(frames))
=> this.frames = new ImageFrameCollection<TPixel>(this, frames);
/// <inheritdoc />

3
src/ImageSharp/PixelFormats/IPixel.cs

@ -2,6 +2,7 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -14,6 +15,8 @@ namespace SixLabors.ImageSharp.PixelFormats;
public interface IPixel<TSelf> : IPixel, IEquatable<TSelf>
where TSelf : unmanaged, IPixel<TSelf>
{
static abstract PixelTypeInfo GetPixelTypeInfo();
/// <summary>
/// Creates a <see cref="PixelOperations{TPixel}"/> instance for this pixel type.
/// This method is not intended to be consumed directly. Use <see cref="PixelOperations{TPixel}.Instance"/> instead.

3
src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -55,6 +56,8 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<A8>(1, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -183,6 +184,8 @@ public partial struct Abgr32 : IPixel<Abgr32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Abgr32>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Abgr32> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -183,6 +184,8 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Argb32>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -87,6 +88,8 @@ public partial struct Bgr24 : IPixel<Bgr24>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr24>(3, PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -59,6 +60,8 @@ public partial struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr565>(3, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -136,6 +137,8 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra32>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<Bgra32> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -57,6 +58,8 @@ public partial struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra4444>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -60,6 +61,8 @@ public partial struct Bgra5551 : IPixel<Bgra5551>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra5551 left, Bgra5551 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra5551>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra5551> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -60,6 +61,8 @@ public partial struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Byte4>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -45,6 +46,8 @@ public partial struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfSingle>(1, PixelAlphaRepresentation.None);
/// <inheritdoc />
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -52,6 +53,8 @@ public partial struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector2>(2, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -57,6 +58,8 @@ public partial struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector4>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/L16.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -47,6 +48,8 @@ public partial struct L16 : IPixel<L16>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(L16 left, L16 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L16>(1, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L16> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/L8.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -48,6 +49,8 @@ public partial struct L8 : IPixel<L8>, IPackedVector<byte>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(L8 left, L8 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L8>(1, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L8> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/La16.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -71,6 +72,8 @@ public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(La16 left, La16 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La16>(2, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La16> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/La32.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -73,6 +74,8 @@ public partial struct La32 : IPixel<La32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(La32 left, La32 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La32>(2, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La32> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -60,6 +61,8 @@ public partial struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<u
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedByte2 left, NormalizedByte2 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte2>(2, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -62,6 +63,8 @@ public partial struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<u
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedByte4 left, NormalizedByte4 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte4>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -61,6 +62,8 @@ public partial struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort2>(2, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -63,6 +64,8 @@ public partial struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort4>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations();

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct A8
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<A8>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<A8>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<A8>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Abgr32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Abgr32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Abgr32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Abgr32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Argb32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Argb32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Argb32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Argb32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgr24
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgr24>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgr24>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Bgr24>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgr565
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgr565>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgr565>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Bgr565>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgra32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Bgra32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgra4444
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra4444>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra4444>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Bgra4444>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgra5551
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra5551>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra5551>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Bgra5551>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Byte4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Byte4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Byte4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Byte4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct HalfSingle
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<HalfSingle>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<HalfSingle>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<HalfSingle>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct HalfVector2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<HalfVector2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<HalfVector2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<HalfVector2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct HalfVector4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<HalfVector4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<HalfVector4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<HalfVector4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct L16
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<L16>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<L16>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<L16>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct L8
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<L8>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<L8>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<L8>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct La16
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<La16>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<La16>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<La16>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct La32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<La32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<La32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<La32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedByte2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedByte2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedByte2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedByte2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedByte4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedByte4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedByte4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedByte4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedShort2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedShort2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedShort2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedShort2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedShort4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedShort4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedShort4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedShort4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rg32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rg32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rg32>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Rg32>;
}

5
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs

@ -15,11 +15,6 @@ public partial struct Rgb24
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgb24>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new(() => PixelTypeInfo.Create<Rgb24>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
/// <inheritdoc />
internal override void PackFromRgbPlanes(

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rgb48
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgb48>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rgb48>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Rgb48>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rgba1010102
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgba1010102>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rgba1010102>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Rgba1010102>;
}

6
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs

@ -18,12 +18,6 @@ public partial struct Rgba32
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgba32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new(() => PixelTypeInfo.Create<Rgba32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
/// <inheritdoc />
public override void ToVector4(
Configuration configuration,

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rgba64
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgba64>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rgba64>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Rgba64>;
}

6
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs

@ -19,12 +19,6 @@ public partial struct RgbaVector
/// </summary>
internal class PixelOperations : PixelOperations<RgbaVector>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new(() => PixelTypeInfo.Create<RgbaVector>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
/// <inheritdoc />
public override void From<TSourcePixel>(
Configuration configuration,

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Short2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Short2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Short2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Short2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Short4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Short4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Short4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Short4>;
}

3
src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -57,6 +58,8 @@ public partial struct Rg32 : IPixel<Rg32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rg32>(2, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rg32> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -106,6 +107,8 @@ public partial struct Rgb24 : IPixel<Rgb24>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgb24 left, Rgb24 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb24>(3, PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Rgb24> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -69,6 +70,8 @@ public partial struct Rgb48 : IPixel<Rgb48>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgb48 left, Rgb48 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb48>(3, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rgb48> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -60,6 +61,8 @@ public partial struct Rgba1010102 : IPixel<Rgba1010102>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgba1010102 left, Rgba1010102 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba1010102>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba1010102> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs

@ -6,6 +6,7 @@ using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -286,6 +287,8 @@ public partial struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
return true;
}
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba32>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba32> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs

@ -4,6 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -206,6 +207,8 @@ public partial struct Rgba64 : IPixel<Rgba64>, IPackedVector<ulong>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgba64 left, Rgba64 right) => left.PackedValue != right.PackedValue;
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba64>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba64> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs

@ -5,6 +5,7 @@ using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -96,6 +97,8 @@ public partial struct RgbaVector : IPixel<RgbaVector>
/// </returns>
public static RgbaVector FromHex(string hex) => Color.ParseHex(hex).ToPixel<RgbaVector>();
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<RgbaVector>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -64,6 +65,8 @@ public partial struct Short2 : IPixel<Short2>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Short2 left, Short2 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short2>(2, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Short2> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -66,6 +67,8 @@ public partial struct Short4 : IPixel<Short4>, IPackedVector<ulong>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Short4 left, Short4 right) => !left.Equals(right);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short4>(4, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Short4> CreatePixelOperations() => new PixelOperations();

3
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

@ -18,7 +18,6 @@ namespace SixLabors.ImageSharp.PixelFormats;
public partial class PixelOperations<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo = new(() => PixelTypeInfo.Create<TPixel>(), true);
private static readonly Lazy<PixelOperations<TPixel>> LazyInstance = new(() => default(TPixel).CreatePixelOperations(), true);
/// <summary>
@ -32,7 +31,7 @@ public partial class PixelOperations<TPixel>
/// Gets the pixel type info for the given <typeparamref name="TPixel"/>.
/// </summary>
/// <returns>The <see cref="PixelTypeInfo"/>.</returns>
public virtual PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
public static PixelTypeInfo GetPixelTypeInfo() => TPixel.GetPixelTypeInfo();
/// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -197,7 +197,7 @@ internal class ResizeProcessor<TPixel> : TransformProcessor<TPixel>, IResampling
bool compand,
bool premultiplyAlpha)
{
PixelAlphaRepresentation? alphaRepresentation = PixelOperations<TPixel>.Instance.GetPixelTypeInfo()?.AlphaRepresentation;
PixelAlphaRepresentation? alphaRepresentation = PixelOperations<TPixel>.GetPixelTypeInfo().AlphaRepresentation;
// Premultiply only if alpha representation is unknown or Unassociated:
bool needsPremultiplication = alphaRepresentation == null || alphaRepresentation.Value == PixelAlphaRepresentation.Unassociated;

2
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -477,7 +477,7 @@ public class BmpDecoderTests
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedPixelSize, imageInfo.PixelType?.BitsPerPixel);
Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel);
}
[Theory]

2
tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs

@ -65,7 +65,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo info = Image.Identify(stream);
Assert.Equal(expectedPixelSize, info.PixelType?.BitsPerPixel);
Assert.Equal(expectedPixelSize, info.PixelType.BitsPerPixel);
Assert.Equal(expectedWidth, info.Width);
Assert.Equal(expectedHeight, info.Height);
Assert.NotNull(info.Metadata);

263
tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
// <auto-generated />
@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations;
public partial class PixelOperationsTests
{
public partial class A8_OperationsTests : PixelOperationsTests<A8>
{
public A8_OperationsTests(ITestOutputHelper output)
@ -20,19 +20,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<A8> Operations => A8.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<A8.PixelOperations>(PixelOperations<A8>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = A8.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Argb32_OperationsTests : PixelOperationsTests<Argb32>
{
public Argb32_OperationsTests(ITestOutputHelper output)
@ -40,19 +35,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Argb32> Operations => Argb32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Argb32.PixelOperations>(PixelOperations<Argb32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Argb32.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Abgr32_OperationsTests : PixelOperationsTests<Abgr32>
{
public Abgr32_OperationsTests(ITestOutputHelper output)
@ -60,19 +50,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Abgr32> Operations => Abgr32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Abgr32.PixelOperations>(PixelOperations<Abgr32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Abgr32.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Bgr24_OperationsTests : PixelOperationsTests<Bgr24>
{
public Bgr24_OperationsTests(ITestOutputHelper output)
@ -80,19 +65,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Bgr24> Operations => Bgr24.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Bgr24.PixelOperations>(PixelOperations<Bgr24>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Bgr24.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Bgr565_OperationsTests : PixelOperationsTests<Bgr565>
{
public Bgr565_OperationsTests(ITestOutputHelper output)
@ -100,19 +80,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Bgr565> Operations => Bgr565.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Bgr565.PixelOperations>(PixelOperations<Bgr565>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Bgr565.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Bgra32_OperationsTests : PixelOperationsTests<Bgra32>
{
public Bgra32_OperationsTests(ITestOutputHelper output)
@ -120,19 +95,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Bgra32> Operations => Bgra32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Bgra32.PixelOperations>(PixelOperations<Bgra32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Bgra32.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Bgra4444_OperationsTests : PixelOperationsTests<Bgra4444>
{
public Bgra4444_OperationsTests(ITestOutputHelper output)
@ -140,19 +110,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Bgra4444> Operations => Bgra4444.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Bgra4444.PixelOperations>(PixelOperations<Bgra4444>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Bgra4444.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Bgra5551_OperationsTests : PixelOperationsTests<Bgra5551>
{
public Bgra5551_OperationsTests(ITestOutputHelper output)
@ -160,19 +125,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Bgra5551> Operations => Bgra5551.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Bgra5551.PixelOperations>(PixelOperations<Bgra5551>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Bgra5551.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Byte4_OperationsTests : PixelOperationsTests<Byte4>
{
public Byte4_OperationsTests(ITestOutputHelper output)
@ -180,19 +140,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Byte4> Operations => Byte4.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Byte4.PixelOperations>(PixelOperations<Byte4>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Byte4.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class HalfSingle_OperationsTests : PixelOperationsTests<HalfSingle>
{
public HalfSingle_OperationsTests(ITestOutputHelper output)
@ -200,19 +155,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<HalfSingle> Operations => HalfSingle.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<HalfSingle.PixelOperations>(PixelOperations<HalfSingle>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = HalfSingle.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class HalfVector2_OperationsTests : PixelOperationsTests<HalfVector2>
{
public HalfVector2_OperationsTests(ITestOutputHelper output)
@ -220,19 +170,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<HalfVector2> Operations => HalfVector2.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<HalfVector2.PixelOperations>(PixelOperations<HalfVector2>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = HalfVector2.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class HalfVector4_OperationsTests : PixelOperationsTests<HalfVector4>
{
public HalfVector4_OperationsTests(ITestOutputHelper output)
@ -240,19 +185,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<HalfVector4> Operations => HalfVector4.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<HalfVector4.PixelOperations>(PixelOperations<HalfVector4>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = HalfVector4.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class L16_OperationsTests : PixelOperationsTests<L16>
{
public L16_OperationsTests(ITestOutputHelper output)
@ -260,19 +200,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<L16> Operations => L16.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<L16.PixelOperations>(PixelOperations<L16>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = L16.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class L8_OperationsTests : PixelOperationsTests<L8>
{
public L8_OperationsTests(ITestOutputHelper output)
@ -280,19 +215,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<L8> Operations => L8.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<L8.PixelOperations>(PixelOperations<L8>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = L8.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class La16_OperationsTests : PixelOperationsTests<La16>
{
public La16_OperationsTests(ITestOutputHelper output)
@ -300,19 +230,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<La16> Operations => La16.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<La16.PixelOperations>(PixelOperations<La16>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = La16.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class La32_OperationsTests : PixelOperationsTests<La32>
{
public La32_OperationsTests(ITestOutputHelper output)
@ -320,19 +245,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<La32> Operations => La32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<La32.PixelOperations>(PixelOperations<La32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = La32.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class NormalizedByte2_OperationsTests : PixelOperationsTests<NormalizedByte2>
{
public NormalizedByte2_OperationsTests(ITestOutputHelper output)
@ -340,19 +260,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<NormalizedByte2> Operations => NormalizedByte2.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<NormalizedByte2.PixelOperations>(PixelOperations<NormalizedByte2>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = NormalizedByte2.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class NormalizedByte4_OperationsTests : PixelOperationsTests<NormalizedByte4>
{
public NormalizedByte4_OperationsTests(ITestOutputHelper output)
@ -360,19 +275,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<NormalizedByte4> Operations => NormalizedByte4.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<NormalizedByte4.PixelOperations>(PixelOperations<NormalizedByte4>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = NormalizedByte4.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class NormalizedShort2_OperationsTests : PixelOperationsTests<NormalizedShort2>
{
public NormalizedShort2_OperationsTests(ITestOutputHelper output)
@ -380,19 +290,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<NormalizedShort2> Operations => NormalizedShort2.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<NormalizedShort2.PixelOperations>(PixelOperations<NormalizedShort2>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = NormalizedShort2.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class NormalizedShort4_OperationsTests : PixelOperationsTests<NormalizedShort4>
{
public NormalizedShort4_OperationsTests(ITestOutputHelper output)
@ -400,19 +305,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<NormalizedShort4> Operations => NormalizedShort4.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<NormalizedShort4.PixelOperations>(PixelOperations<NormalizedShort4>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = NormalizedShort4.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Rg32_OperationsTests : PixelOperationsTests<Rg32>
{
public Rg32_OperationsTests(ITestOutputHelper output)
@ -420,19 +320,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Rg32> Operations => Rg32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Rg32.PixelOperations>(PixelOperations<Rg32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Rg32.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Rgb24_OperationsTests : PixelOperationsTests<Rgb24>
{
public Rgb24_OperationsTests(ITestOutputHelper output)
@ -440,19 +335,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Rgb24> Operations => Rgb24.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Rgb24.PixelOperations>(PixelOperations<Rgb24>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Rgb24.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Rgb48_OperationsTests : PixelOperationsTests<Rgb48>
{
public Rgb48_OperationsTests(ITestOutputHelper output)
@ -460,19 +350,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Rgb48> Operations => Rgb48.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Rgb48.PixelOperations>(PixelOperations<Rgb48>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Rgb48.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Rgba1010102_OperationsTests : PixelOperationsTests<Rgba1010102>
{
public Rgba1010102_OperationsTests(ITestOutputHelper output)
@ -480,19 +365,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Rgba1010102> Operations => Rgba1010102.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Rgba1010102.PixelOperations>(PixelOperations<Rgba1010102>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Rgba1010102.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Rgba32_OperationsTests : PixelOperationsTests<Rgba32>
{
public Rgba32_OperationsTests(ITestOutputHelper output)
@ -500,19 +380,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Rgba32> Operations => Rgba32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Rgba32.PixelOperations>(PixelOperations<Rgba32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Rgba32.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Rgba64_OperationsTests : PixelOperationsTests<Rgba64>
{
public Rgba64_OperationsTests(ITestOutputHelper output)
@ -520,19 +395,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Rgba64> Operations => Rgba64.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Rgba64.PixelOperations>(PixelOperations<Rgba64>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Rgba64.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class RgbaVector_OperationsTests : PixelOperationsTests<RgbaVector>
{
public RgbaVector_OperationsTests(ITestOutputHelper output)
@ -540,19 +410,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<RgbaVector> Operations => RgbaVector.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<RgbaVector.PixelOperations>(PixelOperations<RgbaVector>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = RgbaVector.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Short2_OperationsTests : PixelOperationsTests<Short2>
{
public Short2_OperationsTests(ITestOutputHelper output)
@ -560,19 +425,14 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Short2> Operations => Short2.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Short2.PixelOperations>(PixelOperations<Short2>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Short2.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Short4_OperationsTests : PixelOperationsTests<Short4>
{
public Short4_OperationsTests(ITestOutputHelper output)
@ -580,15 +440,10 @@ public partial class PixelOperationsTests
{
}
protected override PixelOperations<Short4> Operations => Short4.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Short4.PixelOperations>(PixelOperations<Short4>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = Short4.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}

9
tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude

@ -70,7 +70,7 @@ using Xunit.Abstractions;
void GenerateSpecializedClass(string pixelType, string alpha)
{#>
public partial class <#=pixelType#>_OperationsTests : PixelOperationsTests<<#=pixelType#>>
{
public <#=pixelType#>_OperationsTests(ITestOutputHelper output)
@ -78,15 +78,10 @@ using Xunit.Abstractions;
{
}
protected override PixelOperations<<#=pixelType#>> Operations => <#=pixelType#>.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
var alphaRepresentation = <#=pixelType#>.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(<#=alpha#>, alphaRepresentation);
}
}

6
tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs

@ -70,7 +70,7 @@ public abstract class PixelOperationsTests<TPixel> : MeasureFixture
protected virtual PixelOperations<TPixel> Operations { get; } = PixelOperations<TPixel>.Instance;
protected bool HasUnassociatedAlpha => this.Operations.GetPixelTypeInfo().AlphaRepresentation == PixelAlphaRepresentation.Unassociated;
protected bool HasUnassociatedAlpha => TPixel.GetPixelTypeInfo().AlphaRepresentation == PixelAlphaRepresentation.Unassociated;
internal static TPixel[] CreateExpectedPixelData(Vector4[] source, RefAction<Vector4> vectorModifier = null)
{
@ -105,7 +105,7 @@ public abstract class PixelOperationsTests<TPixel> : MeasureFixture
[Fact]
public void PixelTypeInfoHasCorrectBitsPerPixel()
{
int bits = this.Operations.GetPixelTypeInfo().BitsPerPixel;
int bits = TPixel.GetPixelTypeInfo().BitsPerPixel;
Assert.Equal(Unsafe.SizeOf<TPixel>() * 8, bits);
}
@ -123,7 +123,7 @@ public abstract class PixelOperationsTests<TPixel> : MeasureFixture
Rgba32 dest = default;
pixel.ToRgba32(ref dest);
bool hasAlpha = this.Operations.GetPixelTypeInfo().AlphaRepresentation != PixelAlphaRepresentation.None;
bool hasAlpha = TPixel.GetPixelTypeInfo().AlphaRepresentation != PixelAlphaRepresentation.None;
byte expectedAlpha = hasAlpha ? Alpha : NoAlpha;
Assert.Equal(expectedAlpha, dest.A);

2
tests/ImageSharp.Tests/TestFormat.cs

@ -263,6 +263,8 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat
public struct TestPixelForAgnosticDecode : IPixel<TestPixelForAgnosticDecode>
{
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<TestPixelForAgnosticDecode>(2, PixelAlphaRepresentation.None);
public PixelOperations<TestPixelForAgnosticDecode> CreatePixelOperations() => new();
public void FromScaledVector4(Vector4 vector)

5
tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs

@ -8,6 +8,11 @@ namespace SixLabors.ImageSharp.Tests;
public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
{
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public TestImageProvider()
{
}
public virtual TPixel GetExpectedBasicTestPatternPixelAt(int x, int y)
{
throw new NotSupportedException("GetExpectedBasicTestPatternPixelAt(x,y) only works with BasicTestPattern");

Loading…
Cancel
Save