Browse Source

Add PixelComponentPrecision

pull/2601/head
James Jackson-South 2 years ago
parent
commit
db705814df
  1. 2
      src/ImageSharp/Color/Color.cs
  2. 28
      src/ImageSharp/Formats/PixelTypeInfo.cs
  3. 8
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs
  4. 2
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs
  5. 2
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs
  6. 50
      src/ImageSharp/PixelFormats/PixelComponentPrecision.cs
  7. 2
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  8. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
  9. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
  10. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
  11. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
  12. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
  13. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
  14. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
  15. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
  16. 2
      src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
  17. 2
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
  18. 2
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
  19. 2
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  20. 2
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  21. 2
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  22. 2
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  23. 2
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
  24. 2
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
  25. 2
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
  26. 2
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
  27. 2
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs
  28. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
  29. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
  30. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
  31. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
  32. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  33. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
  34. 2
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  35. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
  36. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
  37. 28
      tests/ImageSharp.Tests/PixelFormats/A8Tests.cs
  38. 42
      tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs
  39. 42
      tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs
  40. 42
      tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
  41. 60
      tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs
  42. 42
      tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
  43. 58
      tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs
  44. 67
      tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs
  45. 56
      tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs
  46. 22
      tests/ImageSharp.Tests/PixelFormats/HalfSingleTests.cs
  47. 24
      tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs
  48. 18
      tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs
  49. 32
      tests/ImageSharp.Tests/PixelFormats/L16Tests.cs
  50. 50
      tests/ImageSharp.Tests/PixelFormats/L8Tests.cs
  51. 50
      tests/ImageSharp.Tests/PixelFormats/La16Tests.cs
  52. 32
      tests/ImageSharp.Tests/PixelFormats/La32Tests.cs
  53. 20
      tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs
  54. 56
      tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs
  55. 20
      tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs
  56. 56
      tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs
  57. 20
      tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs
  58. 36
      tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs
  59. 26
      tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs
  60. 58
      tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs
  61. 96
      tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
  62. 118
      tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs
  63. 59
      tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs
  64. 44
      tests/ImageSharp.Tests/PixelFormats/Short2Tests.cs
  65. 74
      tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs
  66. 32
      tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs
  67. 2
      tests/ImageSharp.Tests/TestFormat.cs
  68. 4
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs

2
src/ImageSharp/Color/Color.cs

@ -107,7 +107,7 @@ public readonly partial struct Color : IEquatable<Color>
public static Color FromPixel<TPixel>(TPixel pixel)
where TPixel : unmanaged, IPixel<TPixel>
{
// Avoid boxing in case we can convert to Rgba64 safely and efficently
// Avoid boxing in case we can convert to Rgba64 safely and efficiently
if (typeof(TPixel) == typeof(Rgba64))
{
return new((Rgba64)(object)pixel);

28
src/ImageSharp/Formats/PixelTypeInfo.cs

@ -4,7 +4,7 @@
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
// TODO: Review this class as it's used to represent 2 different things.
// TODO: Review this type as it's used to represent 2 different things.
// 1.The encoded image pixel format.
// 2. The pixel format of the decoded image.
namespace SixLabors.ImageSharp.Formats;
@ -12,37 +12,43 @@ namespace SixLabors.ImageSharp.Formats;
/// <summary>
/// Contains information about the pixels that make up an images visual data.
/// </summary>
public readonly struct PixelTypeInfo
/// <remarks>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> struct.
/// </remarks>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
public readonly struct PixelTypeInfo(int bitsPerPixel)
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> struct.
/// </summary>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
public PixelTypeInfo(int bitsPerPixel)
=> this.BitsPerPixel = bitsPerPixel;
/// <summary>
/// Gets color depth, in number of bits per pixel.
/// </summary>
public int BitsPerPixel { get; init; }
public int BitsPerPixel { get; init; } = bitsPerPixel;
/// <summary>
/// Gets the count of the color components
/// </summary>
public byte ComponentCount { get; init; }
/// <summary>
/// Gets the pixel component precision.
/// </summary>
public PixelComponentPrecision? ComponentPrecision { get; init; }
/// <summary>
/// Gets the pixel alpha transparency behavior.
/// <see langword="null"/> means unknown, unspecified.
/// </summary>
public PixelAlphaRepresentation? AlphaRepresentation { get; init; }
internal static PixelTypeInfo Create<TPixel>(byte componentCount, PixelAlphaRepresentation pixelAlphaRepresentation)
internal static PixelTypeInfo Create<TPixel>(
byte componentCount,
PixelComponentPrecision componentPrecision,
PixelAlphaRepresentation pixelAlphaRepresentation)
where TPixel : unmanaged, IPixel<TPixel>
=> new()
{
BitsPerPixel = Unsafe.SizeOf<TPixel>() * 8,
ComponentCount = componentCount,
ComponentPrecision = componentPrecision,
AlphaRepresentation = pixelAlphaRepresentation
};
}

8
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs

@ -27,17 +27,17 @@ internal class CieLabPlanarTiffColor<TPixel> : TiffBasePlanarColorDecoder<TPixel
Span<byte> a = data[1].GetSpan();
Span<byte> b = data[2].GetSpan();
var color = default(TPixel);
TPixel color = default;
int offset = 0;
for (int y = top; y < top + height; y++)
{
Span<TPixel> pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width);
for (int x = 0; x < pixelRow.Length; x++)
{
var lab = new CieLab((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]);
var rgb = ColorSpaceConverter.ToRgb(lab);
CieLab lab = new((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]);
Rgb rgb = ColorSpaceConverter.ToRgb(lab);
color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset++;

2
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs

@ -34,7 +34,7 @@ internal class CieLabTiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
CieLab lab = new(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]);
Rgb rgb = ColorSpaceConverter.ToRgb(lab);
color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset += 3;

2
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs

@ -27,7 +27,7 @@ internal class CmykTiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
Cmyk cmyk = new(data[offset] * Inv255, data[offset + 1] * Inv255, data[offset + 2] * Inv255, data[offset + 3] * Inv255);
Rgb rgb = ColorSpaceConverter.ToRgb(in cmyk);
color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset += 4;

50
src/ImageSharp/PixelFormats/PixelComponentPrecision.cs

@ -0,0 +1,50 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Provides enumeration of the maximum precision of individual components within a pixel format.
/// </summary>
public enum PixelComponentPrecision
{
/// <summary>
/// 8-bit signed integer.
/// </summary>
SByte,
/// <summary>
/// 8-bit unsigned integer.
/// </summary>
Byte,
/// <summary>
/// 16-bit signed integer.
/// </summary>
Short,
/// <summary>
/// 16-bit unsigned integer.
/// </summary>
UShort,
/// <summary>
/// 32-bit signed integer.
/// </summary>
Int,
/// <summary>
/// 32-bit unsigned integer.
/// </summary>
UInt,
/// <summary>
/// 16-bit floating point.
/// </summary>
Half,
/// <summary>
/// 32-bit floating point.
/// </summary>
Float
}

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

@ -57,7 +57,7 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
/// <inheritdoc/>
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<A8>(1, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<A8>(1, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations();

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

@ -185,7 +185,7 @@ public partial struct Abgr32 : IPixel<Abgr32>, IPackedVector<uint>
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Abgr32>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Abgr32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Abgr32> CreatePixelOperations() => new PixelOperations();

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

@ -185,7 +185,7 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Argb32>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Argb32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations();

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

@ -89,7 +89,7 @@ public partial struct Bgr24 : IPixel<Bgr24>
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr24>(3, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr24>(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations();

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

@ -61,7 +61,7 @@ public partial struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr565>(3, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr565>(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations();

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

@ -138,7 +138,7 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra32>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<Bgra32> CreatePixelOperations() => new PixelOperations();

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

@ -59,7 +59,7 @@ public partial struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra4444>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra4444>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations();

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

@ -62,7 +62,7 @@ public partial struct Bgra5551 : IPixel<Bgra5551>, IPackedVector<ushort>
public static bool operator !=(Bgra5551 left, Bgra5551 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra5551>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra5551>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra5551> CreatePixelOperations() => new PixelOperations();

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

@ -62,7 +62,7 @@ public partial struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Byte4>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Byte4>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations();

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

@ -47,7 +47,7 @@ public partial struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfSingle>(1, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfSingle>(1, PixelComponentPrecision.Half, PixelAlphaRepresentation.None);
/// <inheritdoc />
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations();

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

@ -54,7 +54,7 @@ public partial struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector2>(2, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector2>(2, PixelComponentPrecision.Half, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations();

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

@ -59,7 +59,7 @@ public partial struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector4>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector4>(4, PixelComponentPrecision.Half, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations();

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

@ -49,7 +49,7 @@ public partial struct L16 : IPixel<L16>, IPackedVector<ushort>
public static bool operator !=(L16 left, L16 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L16>(1, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L16>(1, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L16> CreatePixelOperations() => new PixelOperations();

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

@ -50,7 +50,7 @@ public partial struct L8 : IPixel<L8>, IPackedVector<byte>
public static bool operator !=(L8 left, L8 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L8>(1, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L8>(1, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L8> CreatePixelOperations() => new PixelOperations();

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

@ -73,7 +73,7 @@ public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
public static bool operator !=(La16 left, La16 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La16>(2, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La16>(2, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La16> CreatePixelOperations() => new PixelOperations();

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

@ -75,7 +75,7 @@ public partial struct La32 : IPixel<La32>, IPackedVector<uint>
public static bool operator !=(La32 left, La32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La32>(2, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La32>(2, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La32> CreatePixelOperations() => new PixelOperations();

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

@ -62,7 +62,7 @@ public partial struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<u
public static bool operator !=(NormalizedByte2 left, NormalizedByte2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte2>(2, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte2>(2, PixelComponentPrecision.SByte, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations();

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

@ -64,7 +64,7 @@ public partial struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<u
public static bool operator !=(NormalizedByte4 left, NormalizedByte4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte4>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte4>(4, PixelComponentPrecision.SByte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations();

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

@ -63,7 +63,7 @@ public partial struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector
public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort2>(2, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort2>(2, PixelComponentPrecision.Short, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations();

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

@ -65,7 +65,7 @@ public partial struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector
public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort4>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort4>(4, PixelComponentPrecision.Short, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations();

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

@ -1,8 +1,6 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
/// <content>

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

@ -59,7 +59,7 @@ public partial struct Rg32 : IPixel<Rg32>, IPackedVector<uint>
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rg32>(2, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rg32>(2, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rg32> CreatePixelOperations() => new PixelOperations();

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

@ -108,7 +108,7 @@ public partial struct Rgb24 : IPixel<Rgb24>
public static bool operator !=(Rgb24 left, Rgb24 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb24>(3, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb24>(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Rgb24> CreatePixelOperations() => new PixelOperations();

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

@ -71,7 +71,7 @@ public partial struct Rgb48 : IPixel<Rgb48>
public static bool operator !=(Rgb48 left, Rgb48 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb48>(3, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb48>(3, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rgb48> CreatePixelOperations() => new PixelOperations();

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

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Packed vector type containing unsigned normalized values ranging from 0 to 1.
/// Packed vector type containing 4 unsigned normalized values ranging from 0 to 1.
/// The x, y and z components use 10 bits, and the w component uses 2 bits.
/// <para>
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
@ -62,7 +62,7 @@ public partial struct Rgba1010102 : IPixel<Rgba1010102>, IPackedVector<uint>
public static bool operator !=(Rgba1010102 left, Rgba1010102 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba1010102>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba1010102>(4, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba1010102> CreatePixelOperations() => new PixelOperations();

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

@ -288,7 +288,7 @@ public partial struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
}
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba32>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba32> CreatePixelOperations() => new PixelOperations();

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

@ -208,7 +208,7 @@ public partial struct Rgba64 : IPixel<Rgba64>, IPackedVector<ulong>
public static bool operator !=(Rgba64 left, Rgba64 right) => left.PackedValue != right.PackedValue;
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba64>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba64>(4, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba64> CreatePixelOperations() => new PixelOperations();

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

@ -98,7 +98,7 @@ public partial struct RgbaVector : IPixel<RgbaVector>
public static RgbaVector FromHex(string hex) => Color.ParseHex(hex).ToPixel<RgbaVector>();
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<RgbaVector>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<RgbaVector>(4, PixelComponentPrecision.Float, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations();

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

@ -66,7 +66,7 @@ public partial struct Short2 : IPixel<Short2>, IPackedVector<uint>
public static bool operator !=(Short2 left, Short2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short2>(2, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short2>(2, PixelComponentPrecision.Short, PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Short2> CreatePixelOperations() => new PixelOperations();

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

@ -68,7 +68,7 @@ public partial struct Short4 : IPixel<Short4>, IPackedVector<ulong>
public static bool operator !=(Short4 left, Short4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short4>(4, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short4>(4, PixelComponentPrecision.Short, PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Short4> CreatePixelOperations() => new PixelOperations();

28
tests/ImageSharp.Tests/PixelFormats/A8Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -28,8 +30,8 @@ public class A8Tests
[Fact]
public void A8_Equality()
{
var left = new A8(16);
var right = new A8(32);
A8 left = new(16);
A8 right = new(32);
Assert.True(left == new A8(16));
Assert.True(left != right);
@ -56,7 +58,7 @@ public class A8Tests
public void A8_ToScaledVector4()
{
// Arrange
var alpha = new A8(.5F);
A8 alpha = new(.5F);
// Act
Vector4 actual = alpha.ToScaledVector4();
@ -72,10 +74,10 @@ public class A8Tests
public void A8_ToVector4()
{
// Arrange
var alpha = new A8(.5F);
A8 alpha = new(.5F);
// Act
var actual = alpha.ToVector4();
Vector4 actual = alpha.ToVector4();
// Assert
Assert.Equal(0, actual.X);
@ -87,8 +89,8 @@ public class A8Tests
[Fact]
public void A8_ToRgba32()
{
var input = new A8(128);
var expected = new Rgba32(0, 0, 0, 128);
A8 input = new(128);
Rgba32 expected = new(0, 0, 0, 128);
Rgba32 actual = default;
input.ToRgba32(ref actual);
@ -99,7 +101,7 @@ public class A8Tests
public void A8_FromBgra5551()
{
// arrange
var alpha = default(A8);
A8 alpha = default;
byte expected = byte.MaxValue;
// act
@ -108,4 +110,14 @@ public class A8Tests
// assert
Assert.Equal(expected, alpha.PackedValue);
}
[Fact]
public void A8_PixelInformation()
{
PixelTypeInfo info = A8.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<A8>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

42
tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,8 +17,8 @@ public class Abgr32Tests
[Fact]
public void AreEqual()
{
var color1 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var color2 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Abgr32 color1 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
Abgr32 color2 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Assert.Equal(color1, color2);
}
@ -27,8 +29,8 @@ public class Abgr32Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Abgr32(0, 0, byte.MaxValue, byte.MaxValue);
var color2 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Abgr32 color1 = new(0, 0, byte.MaxValue, byte.MaxValue);
Abgr32 color2 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Assert.NotEqual(color1, color2);
}
@ -46,7 +48,7 @@ public class Abgr32Tests
[MemberData(nameof(ColorData))]
public void Constructor(byte b, byte g, byte r, byte a)
{
var p = new Abgr32(r, g, b, a);
Abgr32 p = new(r, g, b, a);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
@ -57,7 +59,7 @@ public class Abgr32Tests
[Fact]
public unsafe void ByteLayoutIsSequentialBgra()
{
var color = new Abgr32(1, 2, 3, 4);
Abgr32 color = new(1, 2, 3, 4);
byte* ptr = (byte*)&color;
Assert.Equal(4, ptr[0]);
@ -70,8 +72,8 @@ public class Abgr32Tests
[MemberData(nameof(ColorData))]
public void Equality_WhenTrue(byte r, byte g, byte b, byte a)
{
var x = new Abgr32(r, g, b, a);
var y = new Abgr32(r, g, b, a);
Abgr32 x = new(r, g, b, a);
Abgr32 y = new(r, g, b, a);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
@ -85,8 +87,8 @@ public class Abgr32Tests
[InlineData(1, 255, 0, 0, 0, 255, 0, 0)]
public void Equality_WhenFalse(byte b1, byte g1, byte r1, byte a1, byte b2, byte g2, byte r2, byte a2)
{
var x = new Abgr32(r1, g1, b1, a1);
var y = new Abgr32(r2, g2, b2, a2);
Abgr32 x = new(r1, g1, b1, a1);
Abgr32 y = new(r2, g2, b2, a2);
Assert.False(x.Equals(y));
Assert.False(x.Equals((object)y));
@ -95,7 +97,7 @@ public class Abgr32Tests
[Fact]
public void FromRgba32()
{
var abgr = default(Abgr32);
Abgr32 abgr = default;
abgr.FromRgba32(new Rgba32(1, 2, 3, 4));
Assert.Equal(1, abgr.R);
@ -104,7 +106,7 @@ public class Abgr32Tests
Assert.Equal(4, abgr.A);
}
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4(
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new(
r / 255f,
g / 255f,
b / 255f,
@ -113,7 +115,7 @@ public class Abgr32Tests
[Fact]
public void FromVector4()
{
var c = default(Abgr32);
Abgr32 c = default;
c.FromVector4(Vec(1, 2, 3, 4));
Assert.Equal(1, c.R);
@ -125,7 +127,7 @@ public class Abgr32Tests
[Fact]
public void ToVector4()
{
var abgr = new Abgr32(1, 2, 3, 4);
Abgr32 abgr = new(1, 2, 3, 4);
Assert.Equal(Vec(1, 2, 3, 4), abgr.ToVector4());
}
@ -134,7 +136,7 @@ public class Abgr32Tests
public void Abgr32_FromBgra5551()
{
// arrange
var abgr = default(Abgr32);
Abgr32 abgr = default;
uint expected = uint.MaxValue;
// act
@ -143,4 +145,14 @@ public class Abgr32Tests
// assert
Assert.Equal(expected, abgr.PackedValue);
}
[Fact]
public void Abgr32_PixelInformation()
{
PixelTypeInfo info = Abgr32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Abgr32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

42
tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class Argb32Tests
[Fact]
public void AreEqual()
{
var color1 = new Argb32(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Argb32(new Vector4(0.0f));
var color3 = new Argb32(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new Argb32(1.0f, 0.0f, 1.0f, 1.0f);
Argb32 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Argb32 color2 = new(new Vector4(0.0f));
Argb32 color3 = new(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
Argb32 color4 = new(1.0f, 0.0f, 1.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class Argb32Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Argb32(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Argb32(new Vector4(1.0f));
var color3 = new Argb32(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Argb32(1.0f, 1.0f, 0.0f, 1.0f);
Argb32 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Argb32 color2 = new(new Vector4(1.0f));
Argb32 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
Argb32 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -45,25 +47,25 @@ public class Argb32Tests
[Fact]
public void ConstructorAssignsProperties()
{
var color1 = new Argb32(1, .1f, .133f, .864f);
Argb32 color1 = new(1, .1f, .133f, .864f);
Assert.Equal(255, color1.R);
Assert.Equal((byte)Math.Round(.1f * 255), color1.G);
Assert.Equal((byte)Math.Round(.133f * 255), color1.B);
Assert.Equal((byte)Math.Round(.864f * 255), color1.A);
var color2 = new Argb32(1, .1f, .133f);
Argb32 color2 = new(1, .1f, .133f);
Assert.Equal(255, color2.R);
Assert.Equal(Math.Round(.1f * 255), color2.G);
Assert.Equal(Math.Round(.133f * 255), color2.B);
Assert.Equal(255, color2.A);
var color4 = new Argb32(new Vector3(1, .1f, .133f));
Argb32 color4 = new(new Vector3(1, .1f, .133f));
Assert.Equal(255, color4.R);
Assert.Equal(Math.Round(.1f * 255), color4.G);
Assert.Equal(Math.Round(.133f * 255), color4.B);
Assert.Equal(255, color4.A);
var color5 = new Argb32(new Vector4(1, .1f, .133f, .5f));
Argb32 color5 = new(new Vector4(1, .1f, .133f, .5f));
Assert.Equal(255, color5.R);
Assert.Equal(Math.Round(.1f * 255), color5.G);
Assert.Equal(Math.Round(.133f * 255), color5.B);
@ -93,7 +95,7 @@ public class Argb32Tests
public void Argb32_ToScaledVector4()
{
// arrange
var argb = new Argb32(Vector4.One);
Argb32 argb = new(Vector4.One);
// act
Vector4 actual = argb.ToScaledVector4();
@ -110,7 +112,7 @@ public class Argb32Tests
{
// arrange
Vector4 scaled = new Argb32(Vector4.One).ToScaledVector4();
var pixel = default(Argb32);
Argb32 pixel = default;
uint expected = 0xFFFFFFFF;
// act
@ -125,7 +127,7 @@ public class Argb32Tests
public void Argb32_FromBgra5551()
{
// arrange
var argb = default(Argb32);
Argb32 argb = default;
uint expected = uint.MaxValue;
// act
@ -141,4 +143,14 @@ public class Argb32Tests
Assert.Equal(Vector4.Zero, new Argb32(Vector4.One * -1234.0f).ToVector4());
Assert.Equal(Vector4.One, new Argb32(Vector4.One * +1234.0f).ToVector4());
}
[Fact]
public void Argb32_PixelInformation()
{
PixelTypeInfo info = Argb32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Argb32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

42
tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -12,8 +14,8 @@ public class Bgr24Tests
[Fact]
public void AreEqual()
{
var color1 = new Bgr24(byte.MaxValue, 0, byte.MaxValue);
var color2 = new Bgr24(byte.MaxValue, 0, byte.MaxValue);
Bgr24 color1 = new(byte.MaxValue, 0, byte.MaxValue);
Bgr24 color2 = new(byte.MaxValue, 0, byte.MaxValue);
Assert.Equal(color1, color2);
}
@ -21,8 +23,8 @@ public class Bgr24Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Bgr24(byte.MaxValue, 0, 0);
var color2 = new Bgr24(byte.MaxValue, 0, byte.MaxValue);
Bgr24 color1 = new(byte.MaxValue, 0, 0);
Bgr24 color2 = new(byte.MaxValue, 0, byte.MaxValue);
Assert.NotEqual(color1, color2);
}
@ -33,7 +35,7 @@ public class Bgr24Tests
[MemberData(nameof(ColorData))]
public void Constructor(byte r, byte g, byte b)
{
var p = new Rgb24(r, g, b);
Rgb24 p = new(r, g, b);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
@ -43,7 +45,7 @@ public class Bgr24Tests
[Fact]
public unsafe void ByteLayoutIsSequentialBgr()
{
var color = new Bgr24(1, 2, 3);
Bgr24 color = new(1, 2, 3);
byte* ptr = (byte*)&color;
Assert.Equal(3, ptr[0]);
@ -55,8 +57,8 @@ public class Bgr24Tests
[MemberData(nameof(ColorData))]
public void Equals_WhenTrue(byte r, byte g, byte b)
{
var x = new Bgr24(r, g, b);
var y = new Bgr24(r, g, b);
Bgr24 x = new(r, g, b);
Bgr24 y = new(r, g, b);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
@ -69,8 +71,8 @@ public class Bgr24Tests
[InlineData(1, 255, 0, 0, 255, 0)]
public void Equals_WhenFalse(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
{
var a = new Bgr24(r1, g1, b1);
var b = new Bgr24(r2, g2, b2);
Bgr24 a = new(r1, g1, b1);
Bgr24 b = new(r2, g2, b2);
Assert.False(a.Equals(b));
Assert.False(a.Equals((object)b));
@ -79,7 +81,7 @@ public class Bgr24Tests
[Fact]
public void FromRgba32()
{
var rgb = default(Bgr24);
Bgr24 rgb = default;
rgb.FromRgba32(new Rgba32(1, 2, 3, 4));
Assert.Equal(1, rgb.R);
@ -87,7 +89,7 @@ public class Bgr24Tests
Assert.Equal(3, rgb.B);
}
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4(
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new(
r / 255f,
g / 255f,
b / 255f,
@ -96,7 +98,7 @@ public class Bgr24Tests
[Fact]
public void FromVector4()
{
var rgb = default(Bgr24);
Bgr24 rgb = default;
rgb.FromVector4(Vec(1, 2, 3, 4));
Assert.Equal(1, rgb.R);
@ -107,7 +109,7 @@ public class Bgr24Tests
[Fact]
public void ToVector4()
{
var rgb = new Bgr24(1, 2, 3);
Bgr24 rgb = new(1, 2, 3);
Assert.Equal(Vec(1, 2, 3), rgb.ToVector4());
}
@ -116,7 +118,7 @@ public class Bgr24Tests
public void Bgr24_FromBgra5551()
{
// arrange
var bgr = default(Bgr24);
Bgr24 bgr = default;
// act
bgr.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
@ -126,4 +128,14 @@ public class Bgr24Tests
Assert.Equal(255, bgr.G);
Assert.Equal(255, bgr.B);
}
[Fact]
public void Bgr24_PixelInformation()
{
PixelTypeInfo info = Bgr24.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgr24>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

60
tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class Bgr565Tests
[Fact]
public void AreEqual()
{
var color1 = new Bgr565(0.0f, 0.0f, 0.0f);
var color2 = new Bgr565(new Vector3(0.0f));
var color3 = new Bgr565(new Vector3(1.0f, 0.0f, 1.0f));
var color4 = new Bgr565(1.0f, 0.0f, 1.0f);
Bgr565 color1 = new(0.0f, 0.0f, 0.0f);
Bgr565 color2 = new(new Vector3(0.0f));
Bgr565 color3 = new(new Vector3(1.0f, 0.0f, 1.0f));
Bgr565 color4 = new(1.0f, 0.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class Bgr565Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Bgr565(0.0f, 0.0f, 0.0f);
var color2 = new Bgr565(new Vector3(1.0f));
var color3 = new Bgr565(new Vector3(1.0f, 0.0f, 0.0f));
var color4 = new Bgr565(1.0f, 1.0f, 0.0f);
Bgr565 color1 = new(0.0f, 0.0f, 0.0f);
Bgr565 color2 = new(new Vector3(1.0f));
Bgr565 color3 = new(new Vector3(1.0f, 0.0f, 0.0f));
Bgr565 color4 = new(1.0f, 1.0f, 0.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -66,7 +68,7 @@ public class Bgr565Tests
public void Bgr565_ToScaledVector4()
{
// arrange
var bgr = new Bgr565(Vector3.One);
Bgr565 bgr = new(Vector3.One);
// act
Vector4 actual = bgr.ToScaledVector4();
@ -84,7 +86,7 @@ public class Bgr565Tests
// arrange
Vector4 scaled = new Bgr565(Vector3.One).ToScaledVector4();
int expected = 0xFFFF;
var pixel = default(Bgr565);
Bgr565 pixel = default;
// act
pixel.FromScaledVector4(scaled);
@ -98,7 +100,7 @@ public class Bgr565Tests
public void Bgr565_FromBgra5551()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expected = ushort.MaxValue;
// act
@ -112,8 +114,8 @@ public class Bgr565Tests
public void Bgr565_FromArgb32()
{
// arrange
var bgr1 = default(Bgr565);
var bgr2 = default(Bgr565);
Bgr565 bgr1 = default;
Bgr565 bgr2 = default;
ushort expected1 = ushort.MaxValue;
ushort expected2 = ushort.MaxValue;
@ -130,8 +132,8 @@ public class Bgr565Tests
public void Bgr565_FromRgba32()
{
// arrange
var bgr1 = default(Bgr565);
var bgr2 = default(Bgr565);
Bgr565 bgr1 = default;
Bgr565 bgr2 = default;
ushort expected1 = ushort.MaxValue;
ushort expected2 = ushort.MaxValue;
@ -148,9 +150,9 @@ public class Bgr565Tests
public void Bgr565_ToRgba32()
{
// arrange
var bgra = new Bgr565(Vector3.One);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);
Bgr565 bgra = new(Vector3.One);
Rgba32 expected = new(Vector4.One);
Rgba32 actual = default;
// act
bgra.ToRgba32(ref actual);
@ -162,7 +164,7 @@ public class Bgr565Tests
public void Bgra565_FromRgb48()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -176,7 +178,7 @@ public class Bgr565Tests
public void Bgra565_FromRgba64()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -190,7 +192,7 @@ public class Bgr565Tests
public void Bgr565_FromBgr24()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expected = ushort.MaxValue;
// act
@ -204,7 +206,7 @@ public class Bgr565Tests
public void Bgr565_FromRgb24()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expected = ushort.MaxValue;
// act
@ -218,7 +220,7 @@ public class Bgr565Tests
public void Bgr565_FromGrey8()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expected = ushort.MaxValue;
// act
@ -232,7 +234,7 @@ public class Bgr565Tests
public void Bgr565_FromGrey16()
{
// arrange
var bgr = default(Bgr565);
Bgr565 bgr = default;
ushort expected = ushort.MaxValue;
// act
@ -248,4 +250,14 @@ public class Bgr565Tests
Assert.Equal(Vector3.Zero, new Bgr565(Vector3.One * -1234F).ToVector3());
Assert.Equal(Vector3.One, new Bgr565(Vector3.One * 1234F).ToVector3());
}
[Fact]
public void Bgr565_PixelInformation()
{
PixelTypeInfo info = Bgr565.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgr565>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

42
tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,8 +17,8 @@ public class Bgra32Tests
[Fact]
public void AreEqual()
{
var color1 = new Bgra32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var color2 = new Bgra32(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Bgra32 color1 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
Bgra32 color2 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Assert.Equal(color1, color2);
}
@ -27,8 +29,8 @@ public class Bgra32Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Bgra32(0, 0, byte.MaxValue, byte.MaxValue);
var color2 = new Bgra32(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Bgra32 color1 = new(0, 0, byte.MaxValue, byte.MaxValue);
Bgra32 color2 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Assert.NotEqual(color1, color2);
}
@ -46,7 +48,7 @@ public class Bgra32Tests
[MemberData(nameof(ColorData))]
public void Constructor(byte b, byte g, byte r, byte a)
{
var p = new Bgra32(r, g, b, a);
Bgra32 p = new(r, g, b, a);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
@ -57,7 +59,7 @@ public class Bgra32Tests
[Fact]
public unsafe void ByteLayoutIsSequentialBgra()
{
var color = new Bgra32(1, 2, 3, 4);
Bgra32 color = new(1, 2, 3, 4);
byte* ptr = (byte*)&color;
Assert.Equal(3, ptr[0]);
@ -70,8 +72,8 @@ public class Bgra32Tests
[MemberData(nameof(ColorData))]
public void Equality_WhenTrue(byte b, byte g, byte r, byte a)
{
var x = new Bgra32(r, g, b, a);
var y = new Bgra32(r, g, b, a);
Bgra32 x = new(r, g, b, a);
Bgra32 y = new(r, g, b, a);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
@ -85,8 +87,8 @@ public class Bgra32Tests
[InlineData(1, 255, 0, 0, 0, 255, 0, 0)]
public void Equality_WhenFalse(byte b1, byte g1, byte r1, byte a1, byte b2, byte g2, byte r2, byte a2)
{
var x = new Bgra32(r1, g1, b1, a1);
var y = new Bgra32(r2, g2, b2, a2);
Bgra32 x = new(r1, g1, b1, a1);
Bgra32 y = new(r2, g2, b2, a2);
Assert.False(x.Equals(y));
Assert.False(x.Equals((object)y));
@ -95,7 +97,7 @@ public class Bgra32Tests
[Fact]
public void FromRgba32()
{
var bgra = default(Bgra32);
Bgra32 bgra = default;
bgra.FromRgba32(new Rgba32(1, 2, 3, 4));
Assert.Equal(1, bgra.R);
@ -104,7 +106,7 @@ public class Bgra32Tests
Assert.Equal(4, bgra.A);
}
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4(
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new(
r / 255f,
g / 255f,
b / 255f,
@ -113,7 +115,7 @@ public class Bgra32Tests
[Fact]
public void FromVector4()
{
var c = default(Bgra32);
Bgra32 c = default;
c.FromVector4(Vec(1, 2, 3, 4));
Assert.Equal(1, c.R);
@ -125,7 +127,7 @@ public class Bgra32Tests
[Fact]
public void ToVector4()
{
var rgb = new Bgra32(1, 2, 3, 4);
Bgra32 rgb = new(1, 2, 3, 4);
Assert.Equal(Vec(1, 2, 3, 4), rgb.ToVector4());
}
@ -134,7 +136,7 @@ public class Bgra32Tests
public void Bgra32_FromBgra5551()
{
// arrange
var bgra = default(Bgra32);
Bgra32 bgra = default;
uint expected = uint.MaxValue;
// act
@ -143,4 +145,14 @@ public class Bgra32Tests
// assert
Assert.Equal(expected, bgra.PackedValue);
}
[Fact]
public void Bgra32_PixelInformation()
{
PixelTypeInfo info = Bgra32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgra32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

58
tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class Bgra4444Tests
[Fact]
public void AreEqual()
{
var color1 = new Bgra4444(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Bgra4444(new Vector4(0.0f));
var color3 = new Bgra4444(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new Bgra4444(1.0f, 0.0f, 1.0f, 1.0f);
Bgra4444 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Bgra4444 color2 = new(new Vector4(0.0f));
Bgra4444 color3 = new(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
Bgra4444 color4 = new(1.0f, 0.0f, 1.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class Bgra4444Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Bgra4444(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Bgra4444(new Vector4(1.0f));
var color3 = new Bgra4444(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Bgra4444(1.0f, 1.0f, 0.0f, 1.0f);
Bgra4444 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Bgra4444 color2 = new(new Vector4(1.0f));
Bgra4444 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
Bgra4444 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -66,7 +68,7 @@ public class Bgra4444Tests
public void Bgra4444_ToScaledVector4()
{
// arrange
var bgra = new Bgra4444(Vector4.One);
Bgra4444 bgra = new(Vector4.One);
// act
Vector4 actual = bgra.ToScaledVector4();
@ -82,9 +84,9 @@ public class Bgra4444Tests
public void Bgra4444_ToRgba32()
{
// arrange
var bgra = new Bgra4444(Vector4.One);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);
Bgra4444 bgra = new(Vector4.One);
Rgba32 expected = new(Vector4.One);
Rgba32 actual = default;
// act
bgra.ToRgba32(ref actual);
@ -98,7 +100,7 @@ public class Bgra4444Tests
// arrange
Vector4 scaled = new Bgra4444(Vector4.One).ToScaledVector4();
int expected = 0xFFFF;
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
// act
bgra.FromScaledVector4(scaled);
@ -112,7 +114,7 @@ public class Bgra4444Tests
public void Bgra4444_FromBgra5551()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expected = ushort.MaxValue;
// act
@ -126,7 +128,7 @@ public class Bgra4444Tests
public void Bgra4444_FromArgb32()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -140,8 +142,8 @@ public class Bgra4444Tests
public void Bgra4444_FromRgba32()
{
// arrange
var bgra1 = default(Bgra4444);
var bgra2 = default(Bgra4444);
Bgra4444 bgra1 = default;
Bgra4444 bgra2 = default;
ushort expectedPackedValue1 = ushort.MaxValue;
ushort expectedPackedValue2 = 0xFF0F;
@ -158,7 +160,7 @@ public class Bgra4444Tests
public void Bgra4444_FromRgb48()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -172,7 +174,7 @@ public class Bgra4444Tests
public void Bgra4444_FromRgba64()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -186,7 +188,7 @@ public class Bgra4444Tests
public void Bgra4444_FromGrey16()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -200,7 +202,7 @@ public class Bgra4444Tests
public void Bgra4444_FromGrey8()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -214,7 +216,7 @@ public class Bgra4444Tests
public void Bgra4444_FromBgr24()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -228,7 +230,7 @@ public class Bgra4444Tests
public void Bgra4444_FromRgb24()
{
// arrange
var bgra = default(Bgra4444);
Bgra4444 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -244,4 +246,14 @@ public class Bgra4444Tests
Assert.Equal(Vector4.Zero, new Bgra4444(Vector4.One * -1234.0f).ToVector4());
Assert.Equal(Vector4.One, new Bgra4444(Vector4.One * 1234.0f).ToVector4());
}
[Fact]
public void Bgra4444_PixelInformation()
{
PixelTypeInfo info = Bgra4444.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgra4444>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

67
tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class Bgra5551Tests
[Fact]
public void AreEqual()
{
var color1 = new Bgra5551(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Bgra5551(new Vector4(0.0f));
var color3 = new Bgra5551(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Bgra5551(1.0f, 0.0f, 0.0f, 1.0f);
Bgra5551 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Bgra5551 color2 = new(new Vector4(0.0f));
Bgra5551 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
Bgra5551 color4 = new(1.0f, 0.0f, 0.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class Bgra5551Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Bgra5551(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Bgra5551(new Vector4(1.0f));
var color3 = new Bgra5551(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Bgra5551(1.0f, 1.0f, 0.0f, 1.0f);
Bgra5551 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Bgra5551 color2 = new(new Vector4(1.0f));
Bgra5551 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
Bgra5551 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -71,7 +73,7 @@ public class Bgra5551Tests
public void Bgra5551_ToScaledVector4()
{
// arrange
var bgra = new Bgra5551(Vector4.One);
Bgra5551 bgra = new(Vector4.One);
// act
Vector4 actual = bgra.ToScaledVector4();
@ -87,9 +89,9 @@ public class Bgra5551Tests
public void Bgra5551_ToRgba32()
{
// arrange
var bgra = new Bgra5551(Vector4.One);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);
Bgra5551 bgra = new(Vector4.One);
Rgba32 expected = new(Vector4.One);
Rgba32 actual = default;
// act
bgra.ToRgba32(ref actual);
@ -103,7 +105,7 @@ public class Bgra5551Tests
// arrange
Vector4 scaled = new Bgra5551(Vector4.One).ToScaledVector4();
int expected = 0xFFFF;
var pixel = default(Bgra5551);
Bgra5551 pixel = default;
// act
pixel.FromScaledVector4(scaled);
@ -117,9 +119,9 @@ public class Bgra5551Tests
public void Bgra5551_FromBgra5551()
{
// arrange
var bgra = default(Bgra5551);
var actual = default(Bgra5551);
var expected = new Bgra5551(1.0f, 0.0f, 1.0f, 1.0f);
Bgra5551 bgra = default;
Bgra5551 actual = default;
Bgra5551 expected = new(1.0f, 0.0f, 1.0f, 1.0f);
// act
bgra.FromBgra5551(expected);
@ -133,8 +135,8 @@ public class Bgra5551Tests
public void Bgra5551_FromRgba32()
{
// arrange
var bgra1 = default(Bgra5551);
var bgra2 = default(Bgra5551);
Bgra5551 bgra1 = default;
Bgra5551 bgra2 = default;
ushort expectedPackedValue1 = ushort.MaxValue;
ushort expectedPackedValue2 = 0xFC1F;
@ -151,8 +153,8 @@ public class Bgra5551Tests
public void Bgra5551_FromBgra32()
{
// arrange
var bgra1 = default(Bgra5551);
var bgra2 = default(Bgra5551);
Bgra5551 bgra1 = default;
Bgra5551 bgra2 = default;
ushort expectedPackedValue1 = ushort.MaxValue;
ushort expectedPackedValue2 = 0xFC1F;
@ -169,7 +171,7 @@ public class Bgra5551Tests
public void Bgra5551_FromArgb32()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -183,7 +185,7 @@ public class Bgra5551Tests
public void Bgra5551_FromRgb48()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -197,7 +199,7 @@ public class Bgra5551Tests
public void Bgra5551_FromRgba64()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -211,7 +213,7 @@ public class Bgra5551Tests
public void Bgra5551_FromGrey16()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -225,7 +227,7 @@ public class Bgra5551Tests
public void Bgra5551_FromGrey8()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -239,7 +241,7 @@ public class Bgra5551Tests
public void Bgra5551_FromBgr24()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551 bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -253,7 +255,8 @@ public class Bgra5551Tests
public void Bgra5551_FromRgb24()
{
// arrange
var bgra = default(Bgra5551);
Bgra5551
bgra = default;
ushort expectedPackedValue = ushort.MaxValue;
// act
@ -269,4 +272,14 @@ public class Bgra5551Tests
Assert.Equal(Vector4.Zero, new Bgra5551(Vector4.One * -1234.0f).ToVector4());
Assert.Equal(Vector4.One, new Bgra5551(Vector4.One * 1234.0f).ToVector4());
}
[Fact]
public void Bgra5551_PixelInformation()
{
PixelTypeInfo info = Bgra5551.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgra5551>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

56
tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class Byte4Tests
[Fact]
public void AreEqual()
{
var color1 = new Byte4(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Byte4(new Vector4(0.0f));
var color3 = new Byte4(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new Byte4(1.0f, 0.0f, 1.0f, 1.0f);
Byte4 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Byte4 color2 = new(new Vector4(0.0f));
Byte4 color3 = new(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
Byte4 color4 = new(1.0f, 0.0f, 1.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class Byte4Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Byte4(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Byte4(new Vector4(1.0f));
var color3 = new Byte4(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Byte4(1.0f, 1.0f, 0.0f, 1.0f);
Byte4 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Byte4 color2 = new(new Vector4(1.0f));
Byte4 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
Byte4 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -63,7 +65,7 @@ public class Byte4Tests
public void Byte4_ToScaledVector4()
{
// arrange
var byte4 = new Byte4(Vector4.One * 255);
Byte4 byte4 = new(Vector4.One * 255);
// act
Vector4 actual = byte4.ToScaledVector4();
@ -79,9 +81,9 @@ public class Byte4Tests
public void Byte4_ToRgba32()
{
// arrange
var byte4 = new Byte4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);
Byte4 byte4 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
Rgba32 expected = new(Vector4.One);
Rgba32 actual = default;
// act
byte4.ToRgba32(ref actual);
@ -94,7 +96,7 @@ public class Byte4Tests
{
// arrange
Vector4 scaled = new Byte4(Vector4.One * 255).ToScaledVector4();
var pixel = default(Byte4);
Byte4 pixel = default;
uint expected = 0xFFFFFFFF;
// act
@ -109,7 +111,7 @@ public class Byte4Tests
public void Byte4_FromArgb32()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -123,7 +125,7 @@ public class Byte4Tests
public void Byte4_FromBgr24()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -137,7 +139,7 @@ public class Byte4Tests
public void Byte4_FromGrey8()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -151,7 +153,7 @@ public class Byte4Tests
public void Byte4_FromGrey16()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -165,7 +167,7 @@ public class Byte4Tests
public void Byte4_FromRgb24()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -179,7 +181,7 @@ public class Byte4Tests
public void Byte4_FromBgra5551()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expected = 0xFFFFFFFF;
// act
@ -193,7 +195,7 @@ public class Byte4Tests
public void Byte4_FromRgba32()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue1 = uint.MaxValue;
// act
@ -207,7 +209,7 @@ public class Byte4Tests
public void Byte4_FromRgb48()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -221,7 +223,7 @@ public class Byte4Tests
public void Byte4_FromRgba64()
{
// arrange
var byte4 = default(Byte4);
Byte4 byte4 = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -237,4 +239,14 @@ public class Byte4Tests
Assert.Equal(Vector4.Zero, new Byte4(Vector4.One * -1234.0f).ToVector4());
Assert.Equal(Vector4.One * 255, new Byte4(Vector4.One * 1234.0f).ToVector4());
}
[Fact]
public void Byte4_PixelInformation()
{
PixelTypeInfo info = Byte4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Byte4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

22
tests/ImageSharp.Tests/PixelFormats/HalfSingleTests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -25,11 +27,11 @@ public class HalfSingleTests
public void HalfSingle_ToVector4()
{
// arrange
var halfSingle = new HalfSingle(0.5f);
var expected = new Vector4(0.5f, 0, 0, 1);
HalfSingle halfSingle = new(0.5f);
Vector4 expected = new(0.5f, 0, 0, 1);
// act
var actual = halfSingle.ToVector4();
Vector4 actual = halfSingle.ToVector4();
// assert
Assert.Equal(expected, actual);
@ -39,7 +41,7 @@ public class HalfSingleTests
public void HalfSingle_ToScaledVector4()
{
// arrange
var halfSingle = new HalfSingle(-1F);
HalfSingle halfSingle = new(-1F);
// act
Vector4 actual = halfSingle.ToScaledVector4();
@ -57,7 +59,7 @@ public class HalfSingleTests
// arrange
Vector4 scaled = new HalfSingle(-1F).ToScaledVector4();
int expected = 48128;
var halfSingle = default(HalfSingle);
HalfSingle halfSingle = default;
// act
halfSingle.FromScaledVector4(scaled);
@ -66,4 +68,14 @@ public class HalfSingleTests
// assert
Assert.Equal(expected, actual);
}
[Fact]
public void HalfSingle_PixelInformation()
{
PixelTypeInfo info = HalfSingle.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<HalfSingle>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Half, info.ComponentPrecision);
}
}

24
tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -30,7 +32,7 @@ public class HalfVector2Tests
public void HalfVector2_ToScaledVector4()
{
// arrange
var halfVector = new HalfVector2(Vector2.One);
HalfVector2 halfVector = new(Vector2.One);
// act
Vector4 actual = halfVector.ToScaledVector4();
@ -48,7 +50,7 @@ public class HalfVector2Tests
// arrange
Vector4 scaled = new HalfVector2(Vector2.One).ToScaledVector4();
uint expected = 1006648320u;
var halfVector = default(HalfVector2);
HalfVector2 halfVector = default;
// act
halfVector.FromScaledVector4(scaled);
@ -62,11 +64,11 @@ public class HalfVector2Tests
public void HalfVector2_ToVector4()
{
// arrange
var halfVector = new HalfVector2(.5F, .25F);
var expected = new Vector4(0.5f, .25F, 0, 1);
HalfVector2 halfVector = new(.5F, .25F);
Vector4 expected = new(0.5f, .25F, 0, 1);
// act
var actual = halfVector.ToVector4();
Vector4 actual = halfVector.ToVector4();
// assert
Assert.Equal(expected, actual);
@ -76,7 +78,7 @@ public class HalfVector2Tests
public void HalfVector2_FromBgra5551()
{
// arrange
var halfVector2 = default(HalfVector2);
HalfVector2 halfVector2 = default;
// act
halfVector2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
@ -88,4 +90,14 @@ public class HalfVector2Tests
Assert.Equal(0, actual.Z);
Assert.Equal(1, actual.W);
}
[Fact]
public void HalfVector2_PixelInformation()
{
PixelTypeInfo info = HalfVector2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<HalfVector2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Half, info.ComponentPrecision);
}
}

18
tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -38,7 +40,7 @@ public class HalfVector4Tests
public void HalfVector4_ToScaledVector4()
{
// arrange
var halfVector4 = new HalfVector4(-Vector4.One);
HalfVector4 halfVector4 = new(-Vector4.One);
// act
Vector4 actual = halfVector4.ToScaledVector4();
@ -54,7 +56,7 @@ public class HalfVector4Tests
public void HalfVector4_FromScaledVector4()
{
// arrange
var halfVector4 = default(HalfVector4);
HalfVector4 halfVector4 = default;
Vector4 scaled = new HalfVector4(-Vector4.One).ToScaledVector4();
ulong expected = 13547034390470638592uL;
@ -70,7 +72,7 @@ public class HalfVector4Tests
public void HalfVector4_FromBgra5551()
{
// arrange
var halfVector4 = default(HalfVector4);
HalfVector4 halfVector4 = default;
Vector4 expected = Vector4.One;
// act
@ -79,4 +81,14 @@ public class HalfVector4Tests
// assert
Assert.Equal(expected, halfVector4.ToScaledVector4());
}
[Fact]
public void HalfVector4_PixelInformation()
{
PixelTypeInfo info = HalfVector4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<HalfVector4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Half, info.ComponentPrecision);
}
}

32
tests/ImageSharp.Tests/PixelFormats/L16Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -12,8 +14,8 @@ public class L16Tests
[Fact]
public void AreEqual()
{
var color1 = new L16(3000);
var color2 = new L16(3000);
L16 color1 = new(3000);
L16 color2 = new(3000);
Assert.Equal(color1, color2);
}
@ -21,8 +23,8 @@ public class L16Tests
[Fact]
public void AreNotEqual()
{
var color1 = new L16(12345);
var color2 = new L16(54321);
L16 color1 = new(12345);
L16 color2 = new(54321);
Assert.NotEqual(color1, color2);
}
@ -58,7 +60,7 @@ public class L16Tests
public void L16_ToScaledVector4(ushort input)
{
// Arrange
var gray = new L16(input);
L16 gray = new(input);
// Act
Vector4 actual = gray.ToScaledVector4();
@ -77,7 +79,7 @@ public class L16Tests
// Arrange
L16 gray = default;
const ushort expected = 32767;
var vector = new L16(expected).ToVector4();
Vector4 vector = new L16(expected).ToVector4();
// Act
gray.FromVector4(vector);
@ -94,10 +96,10 @@ public class L16Tests
public void L16_ToVector4(ushort input)
{
// Arrange
var gray = new L16(input);
L16 gray = new(input);
// Act
var actual = gray.ToVector4();
Vector4 actual = gray.ToVector4();
// Assert
float vectorInput = input / 65535F;
@ -132,7 +134,7 @@ public class L16Tests
{
// Arrange
ushort expected = ColorNumerics.DownScaleFrom16BitTo8Bit(input);
var gray = new L16(input);
L16 gray = new(input);
// Act
Rgba32 actual = default;
@ -149,7 +151,7 @@ public class L16Tests
public void L16_FromBgra5551()
{
// arrange
var gray = default(L16);
L16 gray = default;
ushort expected = ushort.MaxValue;
// act
@ -158,4 +160,14 @@ public class L16Tests
// assert
Assert.Equal(expected, gray.PackedValue);
}
[Fact]
public void L16_PixelInformation()
{
PixelTypeInfo info = L16.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<L16>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.ComponentPrecision);
}
}

50
tests/ImageSharp.Tests/PixelFormats/L8Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
// ReSharper disable InconsistentNaming
@ -24,8 +26,8 @@ public class L8Tests
[Fact]
public void AreEqual()
{
var color1 = new L8(100);
var color2 = new L8(100);
L8 color1 = new(100);
L8 color2 = new(100);
Assert.Equal(color1, color2);
}
@ -33,8 +35,8 @@ public class L8Tests
[Fact]
public void AreNotEqual()
{
var color1 = new L8(100);
var color2 = new L8(200);
L8 color1 = new(100);
L8 color2 = new(200);
Assert.NotEqual(color1, color2);
}
@ -60,7 +62,7 @@ public class L8Tests
public void L8_ToScaledVector4(byte input)
{
// Arrange
var gray = new L8(input);
L8 gray = new(input);
// Act
Vector4 actual = gray.ToScaledVector4();
@ -79,7 +81,7 @@ public class L8Tests
{
// Arrange
L8 gray = default;
var vector = new L8(luminance).ToVector4();
Vector4 vector = new L8(luminance).ToVector4();
// Act
gray.FromVector4(vector);
@ -94,10 +96,10 @@ public class L8Tests
public void L8_ToVector4(byte input)
{
// Arrange
var gray = new L8(input);
L8 gray = new(input);
// Act
var actual = gray.ToVector4();
Vector4 actual = gray.ToVector4();
// Assert
float scaledInput = input / 255F;
@ -128,7 +130,7 @@ public class L8Tests
public void L8_ToRgba32(byte luminance)
{
// Arrange
var gray = new L8(luminance);
L8 gray = new(luminance);
// Act
Rgba32 actual = default;
@ -145,7 +147,7 @@ public class L8Tests
public void L8_FromBgra5551()
{
// arrange
var grey = default(L8);
L8 grey = default;
byte expected = byte.MaxValue;
// act
@ -164,7 +166,7 @@ public class L8Tests
[MemberData(nameof(LuminanceData))]
public void L8_FromRgba32_IsInverseOf_ToRgba32(byte luminance)
{
var original = new L8(luminance);
L8 original = new(luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -179,7 +181,7 @@ public class L8Tests
[MemberData(nameof(LuminanceData))]
public void Rgba32_ToL8_IsInverseOf_L8_ToRgba32(byte luminance)
{
var original = new L8(luminance);
L8 original = new(luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -194,13 +196,13 @@ public class L8Tests
[MemberData(nameof(LuminanceData))]
public void ToVector4_IsRgba32Compatible(byte luminance)
{
var original = new L8(luminance);
L8 original = new(luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
var l8Vector = original.ToVector4();
var rgbaVector = original.ToVector4();
Vector4 l8Vector = original.ToVector4();
Vector4 rgbaVector = original.ToVector4();
Assert.Equal(l8Vector, rgbaVector, new ApproximateFloatComparer(1e-5f));
}
@ -209,12 +211,12 @@ public class L8Tests
[MemberData(nameof(LuminanceData))]
public void FromVector4_IsRgba32Compatible(byte luminance)
{
var original = new L8(luminance);
L8 original = new(luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
var rgbaVector = original.ToVector4();
Vector4 rgbaVector = original.ToVector4();
L8 mirror = default;
mirror.FromVector4(rgbaVector);
@ -226,7 +228,7 @@ public class L8Tests
[MemberData(nameof(LuminanceData))]
public void ToScaledVector4_IsRgba32Compatible(byte luminance)
{
var original = new L8(luminance);
L8 original = new(luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -241,7 +243,7 @@ public class L8Tests
[MemberData(nameof(LuminanceData))]
public void FromScaledVector4_IsRgba32Compatible(byte luminance)
{
var original = new L8(luminance);
L8 original = new(luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -253,5 +255,15 @@ public class L8Tests
Assert.Equal(original, mirror);
}
[Fact]
public void L8_PixelInformation()
{
PixelTypeInfo info = L8.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<L8>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}
}

50
tests/ImageSharp.Tests/PixelFormats/La16Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
// ReSharper disable InconsistentNaming
@ -24,8 +26,8 @@ public class La16Tests
[Fact]
public void AreEqual()
{
var color1 = new La16(100, 50);
var color2 = new La16(100, 50);
La16 color1 = new(100, 50);
La16 color2 = new(100, 50);
Assert.Equal(color1, color2);
}
@ -33,8 +35,8 @@ public class La16Tests
[Fact]
public void AreNotEqual()
{
var color1 = new La16(100, 50);
var color2 = new La16(200, 50);
La16 color1 = new(100, 50);
La16 color2 = new(200, 50);
Assert.NotEqual(color1, color2);
}
@ -60,7 +62,7 @@ public class La16Tests
public void La16_ToScaledVector4(byte input)
{
// Arrange
var gray = new La16(input, input);
La16 gray = new(input, input);
// Act
Vector4 actual = gray.ToScaledVector4();
@ -79,7 +81,7 @@ public class La16Tests
{
// Arrange
La16 gray = default;
var vector = new La16(luminance, luminance).ToVector4();
Vector4 vector = new La16(luminance, luminance).ToVector4();
// Act
gray.FromVector4(vector);
@ -96,10 +98,10 @@ public class La16Tests
public void La16_ToVector4(byte input)
{
// Arrange
var gray = new La16(input, input);
La16 gray = new(input, input);
// Act
var actual = gray.ToVector4();
Vector4 actual = gray.ToVector4();
// Assert
float scaledInput = input / 255F;
@ -131,7 +133,7 @@ public class La16Tests
public void La16_ToRgba32(byte luminance)
{
// Arrange
var gray = new La16(luminance, luminance);
La16 gray = new(luminance, luminance);
// Act
Rgba32 actual = default;
@ -148,7 +150,7 @@ public class La16Tests
public void La16_FromBgra5551()
{
// arrange
var grey = default(La16);
La16 grey = default;
byte expected = byte.MaxValue;
// act
@ -168,7 +170,7 @@ public class La16Tests
[MemberData(nameof(LuminanceData))]
public void La16_FromRgba32_IsInverseOf_ToRgba32(byte luminance)
{
var original = new La16(luminance, luminance);
La16 original = new(luminance, luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -183,7 +185,7 @@ public class La16Tests
[MemberData(nameof(LuminanceData))]
public void Rgba32_ToLa16_IsInverseOf_La16_ToRgba32(byte luminance)
{
var original = new La16(luminance, luminance);
La16 original = new(luminance, luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -198,13 +200,13 @@ public class La16Tests
[MemberData(nameof(LuminanceData))]
public void ToVector4_IsRgba32Compatible(byte luminance)
{
var original = new La16(luminance, luminance);
La16 original = new(luminance, luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
var la16Vector = original.ToVector4();
var rgbaVector = original.ToVector4();
Vector4 la16Vector = original.ToVector4();
Vector4 rgbaVector = original.ToVector4();
Assert.Equal(la16Vector, rgbaVector, new ApproximateFloatComparer(1e-5f));
}
@ -213,12 +215,12 @@ public class La16Tests
[MemberData(nameof(LuminanceData))]
public void FromVector4_IsRgba32Compatible(byte luminance)
{
var original = new La16(luminance, luminance);
La16 original = new(luminance, luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
var rgbaVector = original.ToVector4();
Vector4 rgbaVector = original.ToVector4();
La16 mirror = default;
mirror.FromVector4(rgbaVector);
@ -230,7 +232,7 @@ public class La16Tests
[MemberData(nameof(LuminanceData))]
public void ToScaledVector4_IsRgba32Compatible(byte luminance)
{
var original = new La16(luminance, luminance);
La16 original = new(luminance, luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -245,7 +247,7 @@ public class La16Tests
[MemberData(nameof(LuminanceData))]
public void FromScaledVector4_IsRgba32Compatible(byte luminance)
{
var original = new La16(luminance, luminance);
La16 original = new(luminance, luminance);
Rgba32 rgba = default;
original.ToRgba32(ref rgba);
@ -257,5 +259,15 @@ public class La16Tests
Assert.Equal(original, mirror);
}
[Fact]
public void La16_PixelInformation()
{
PixelTypeInfo info = La16.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<La16>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}
}

32
tests/ImageSharp.Tests/PixelFormats/La32Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -12,8 +14,8 @@ public class La32Tests
[Fact]
public void AreEqual()
{
var color1 = new La32(3000, 100);
var color2 = new La32(3000, 100);
La32 color1 = new(3000, 100);
La32 color2 = new(3000, 100);
Assert.Equal(color1, color2);
}
@ -21,8 +23,8 @@ public class La32Tests
[Fact]
public void AreNotEqual()
{
var color1 = new La32(12345, 100);
var color2 = new La32(54321, 100);
La32 color1 = new(12345, 100);
La32 color2 = new(54321, 100);
Assert.NotEqual(color1, color2);
}
@ -60,7 +62,7 @@ public class La32Tests
public void La32_ToScaledVector4(ushort input)
{
// Arrange
var gray = new La32(input, input);
La32 gray = new(input, input);
// Act
Vector4 actual = gray.ToScaledVector4();
@ -79,7 +81,7 @@ public class La32Tests
// Arrange
La32 gray = default;
const ushort expected = 32767;
var vector = new La32(expected, expected).ToVector4();
Vector4 vector = new La32(expected, expected).ToVector4();
// Act
gray.FromVector4(vector);
@ -98,10 +100,10 @@ public class La32Tests
public void La32_ToVector4(ushort input)
{
// Arrange
var gray = new La32(input, input);
La32 gray = new(input, input);
// Act
var actual = gray.ToVector4();
Vector4 actual = gray.ToVector4();
// Assert
float vectorInput = input / 65535F;
@ -137,7 +139,7 @@ public class La32Tests
{
// Arrange
ushort expected = ColorNumerics.DownScaleFrom16BitTo8Bit(input);
var gray = new La32(input, ushort.MaxValue);
La32 gray = new(input, ushort.MaxValue);
// Act
Rgba32 actual = default;
@ -154,7 +156,7 @@ public class La32Tests
public void La32_FromBgra5551()
{
// arrange
var gray = default(La32);
La32 gray = default;
ushort expected = ushort.MaxValue;
// act
@ -164,4 +166,14 @@ public class La32Tests
Assert.Equal(expected, gray.L);
Assert.Equal(expected, gray.A);
}
[Fact]
public void La32_PixelInformation()
{
PixelTypeInfo info = La32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<La32>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.ComponentPrecision);
}
}

20
tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -39,7 +41,7 @@ public class NormalizedByte2Tests
public void NormalizedByte2_ToScaledVector4()
{
// arrange
var byte2 = new NormalizedByte2(-Vector2.One);
NormalizedByte2 byte2 = new(-Vector2.One);
// act
Vector4 actual = byte2.ToScaledVector4();
@ -56,7 +58,7 @@ public class NormalizedByte2Tests
{
// arrange
Vector4 scaled = new NormalizedByte2(-Vector2.One).ToScaledVector4();
var byte2 = default(NormalizedByte2);
NormalizedByte2 byte2 = default;
uint expected = 0x8181;
// act
@ -71,8 +73,8 @@ public class NormalizedByte2Tests
public void NormalizedByte2_FromBgra5551()
{
// arrange
var normalizedByte2 = default(NormalizedByte2);
var expected = new Vector4(1, 1, 0, 1);
NormalizedByte2 normalizedByte2 = default;
Vector4 expected = new(1, 1, 0, 1);
// act
normalizedByte2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
@ -80,4 +82,14 @@ public class NormalizedByte2Tests
// assert
Assert.Equal(expected, normalizedByte2.ToVector4());
}
[Fact]
public void NormalizedByte2_PixelInformation()
{
PixelTypeInfo info = NormalizedByte2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedByte2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.SByte, info.ComponentPrecision);
}
}

56
tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class NormalizedByte4Tests
[Fact]
public void AreEqual()
{
var color1 = new NormalizedByte4(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new NormalizedByte4(new Vector4(0.0f));
var color3 = new NormalizedByte4(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new NormalizedByte4(1.0f, 0.0f, 1.0f, 1.0f);
NormalizedByte4 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
NormalizedByte4 color2 = new(new Vector4(0.0f));
NormalizedByte4 color3 = new(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
NormalizedByte4 color4 = new(1.0f, 0.0f, 1.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class NormalizedByte4Tests
[Fact]
public void AreNotEqual()
{
var color1 = new NormalizedByte4(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new NormalizedByte4(new Vector4(1.0f));
var color3 = new NormalizedByte4(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new NormalizedByte4(1.0f, 1.0f, 0.0f, 1.0f);
NormalizedByte4 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
NormalizedByte4 color2 = new(new Vector4(1.0f));
NormalizedByte4 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
NormalizedByte4 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -63,7 +65,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_ToScaledVector4()
{
// arrange
var short4 = new NormalizedByte4(-Vector4.One);
NormalizedByte4 short4 = new(-Vector4.One);
// act
Vector4 actual = short4.ToScaledVector4();
@ -79,7 +81,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromScaledVector4()
{
// arrange
var pixel = default(NormalizedByte4);
NormalizedByte4 pixel = default;
Vector4 scaled = new NormalizedByte4(-Vector4.One).ToScaledVector4();
uint expected = 0x81818181;
@ -95,7 +97,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromArgb32()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -109,7 +111,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromBgr24()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -123,7 +125,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromGrey8()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -137,7 +139,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromGrey16()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -151,7 +153,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromRgb24()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -165,7 +167,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromRgba32()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -179,7 +181,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromBgra5551()
{
// arrange
var normalizedByte4 = default(NormalizedByte4);
NormalizedByte4 normalizedByte4 = default;
Vector4 expected = Vector4.One;
// act
@ -193,7 +195,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromRgb48()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -207,7 +209,7 @@ public class NormalizedByte4Tests
public void NormalizedByte4_FromRgba64()
{
// arrange
var byte4 = default(NormalizedByte4);
NormalizedByte4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -221,13 +223,23 @@ public class NormalizedByte4Tests
public void NormalizedByte4_ToRgba32()
{
// arrange
var byte4 = new NormalizedByte4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);
NormalizedByte4 byte4 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
Rgba32 expected = new(Vector4.One);
Rgba32 actual = default;
// act
byte4.ToRgba32(ref actual);
Assert.Equal(expected, actual);
}
[Fact]
public void NormalizedByte4_PixelInformation()
{
PixelTypeInfo info = NormalizedByte4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedByte4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.SByte, info.ComponentPrecision);
}
}

20
tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -43,7 +45,7 @@ public class NormalizedShort2Tests
public void NormalizedShort2_ToScaledVector4()
{
// arrange
var short2 = new NormalizedShort2(-Vector2.One);
NormalizedShort2 short2 = new(-Vector2.One);
// act
Vector4 actual = short2.ToScaledVector4();
@ -60,7 +62,7 @@ public class NormalizedShort2Tests
{
// arrange
Vector4 scaled = new NormalizedShort2(-Vector2.One).ToScaledVector4();
var short2 = default(NormalizedShort2);
NormalizedShort2 short2 = default;
uint expected = 0x80018001;
// act
@ -75,8 +77,8 @@ public class NormalizedShort2Tests
public void NormalizedShort2_FromBgra5551()
{
// arrange
var normalizedShort2 = default(NormalizedShort2);
var expected = new Vector4(1, 1, 0, 1);
NormalizedShort2 normalizedShort2 = default;
Vector4 expected = new(1, 1, 0, 1);
// act
normalizedShort2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
@ -84,4 +86,14 @@ public class NormalizedShort2Tests
// assert
Assert.Equal(expected, normalizedShort2.ToVector4());
}
[Fact]
public void NormalizedShort2_PixelInformation()
{
PixelTypeInfo info = NormalizedShort2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedShort2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Short, info.ComponentPrecision);
}
}

56
tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class NormalizedShort4Tests
[Fact]
public void AreEqual()
{
var color1 = new NormalizedShort4(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new NormalizedShort4(new Vector4(0.0f));
var color3 = new NormalizedShort4(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new NormalizedShort4(1.0f, 0.0f, 1.0f, 1.0f);
NormalizedShort4 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
NormalizedShort4 color2 = new(new Vector4(0.0f));
NormalizedShort4 color3 = new(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
NormalizedShort4 color4 = new(1.0f, 0.0f, 1.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class NormalizedShort4Tests
[Fact]
public void AreNotEqual()
{
var color1 = new NormalizedShort4(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new NormalizedShort4(new Vector4(1.0f));
var color3 = new NormalizedShort4(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new NormalizedShort4(1.0f, 1.0f, 0.0f, 1.0f);
NormalizedShort4 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
NormalizedShort4 color2 = new(new Vector4(1.0f));
NormalizedShort4 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
NormalizedShort4 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -64,7 +66,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_ToScaledVector4()
{
// arrange
var short4 = new NormalizedShort4(Vector4.One);
NormalizedShort4 short4 = new(Vector4.One);
// act
Vector4 actual = short4.ToScaledVector4();
@ -80,7 +82,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromScaledVector4()
{
// arrange
var pixel = default(NormalizedShort4);
NormalizedShort4 pixel = default;
Vector4 scaled = new NormalizedShort4(Vector4.One).ToScaledVector4();
ulong expected = 0x7FFF7FFF7FFF7FFF;
@ -96,7 +98,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromArgb32()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -110,7 +112,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromBgr24()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -124,7 +126,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromGrey8()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -138,7 +140,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromGrey16()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -152,7 +154,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromRgb24()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -166,7 +168,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromRgba32()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -180,7 +182,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromRgb48()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -194,7 +196,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromRgba64()
{
// arrange
var byte4 = default(NormalizedShort4);
NormalizedShort4 byte4 = default;
Vector4 expected = Vector4.One;
// act
@ -208,9 +210,9 @@ public class NormalizedShort4Tests
public void NormalizedShort4_ToRgba32()
{
// arrange
var byte4 = new NormalizedShort4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);
NormalizedShort4 byte4 = new(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
Rgba32 expected = new(Vector4.One);
Rgba32 actual = default;
// act
byte4.ToRgba32(ref actual);
@ -222,7 +224,7 @@ public class NormalizedShort4Tests
public void NormalizedShort4_FromBgra5551()
{
// arrange
var normalizedShort4 = default(NormalizedShort4);
NormalizedShort4 normalizedShort4 = default;
Vector4 expected = Vector4.One;
// act
@ -231,4 +233,14 @@ public class NormalizedShort4Tests
// assert
Assert.Equal(expected, normalizedShort4.ToVector4());
}
[Fact]
public void NormalizedShort4_PixelInformation()
{
PixelTypeInfo info = NormalizedShort4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedShort4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Short, info.ComponentPrecision);
}
}

20
tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -33,7 +35,7 @@ public class Rg32Tests
public void Rg32_ToScaledVector4()
{
// arrange
var rg32 = new Rg32(Vector2.One);
Rg32 rg32 = new(Vector2.One);
// act
Vector4 actual = rg32.ToScaledVector4();
@ -49,8 +51,8 @@ public class Rg32Tests
public void Rg32_FromScaledVector4()
{
// arrange
var rg32 = new Rg32(Vector2.One);
var pixel = default(Rg32);
Rg32 rg32 = new(Vector2.One);
Rg32 pixel = default;
uint expected = 0xFFFFFFFF;
// act
@ -66,7 +68,7 @@ public class Rg32Tests
public void Rg32_FromBgra5551()
{
// arrange
var rg32 = new Rg32(Vector2.One);
Rg32 rg32 = new(Vector2.One);
uint expected = 0xFFFFFFFF;
// act
@ -82,4 +84,14 @@ public class Rg32Tests
Assert.Equal(Vector2.Zero, new Rg32(Vector2.One * -1234.0f).ToVector2());
Assert.Equal(Vector2.One, new Rg32(Vector2.One * 1234.0f).ToVector2());
}
[Fact]
public void Rg32_PixelInformation()
{
PixelTypeInfo info = Rg32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rg32>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.ComponentPrecision);
}
}

36
tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -21,7 +23,7 @@ public class Rgb24Tests
[MemberData(nameof(ColorData))]
public void Constructor(byte r, byte g, byte b)
{
var p = new Rgb24(r, g, b);
Rgb24 p = new(r, g, b);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
@ -31,7 +33,7 @@ public class Rgb24Tests
[Fact]
public unsafe void ByteLayoutIsSequentialRgb()
{
var color = new Rgb24(1, 2, 3);
Rgb24 color = new(1, 2, 3);
byte* ptr = (byte*)&color;
Assert.Equal(1, ptr[0]);
@ -43,8 +45,8 @@ public class Rgb24Tests
[MemberData(nameof(ColorData))]
public void Equals_WhenTrue(byte r, byte g, byte b)
{
var x = new Rgb24(r, g, b);
var y = new Rgb24(r, g, b);
Rgb24 x = new(r, g, b);
Rgb24 y = new(r, g, b);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
@ -57,8 +59,8 @@ public class Rgb24Tests
[InlineData(1, 255, 0, 0, 255, 0)]
public void Equals_WhenFalse(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
{
var a = new Rgb24(r1, g1, b1);
var b = new Rgb24(r2, g2, b2);
Rgb24 a = new(r1, g1, b1);
Rgb24 b = new(r2, g2, b2);
Assert.False(a.Equals(b));
Assert.False(a.Equals((object)b));
@ -67,7 +69,7 @@ public class Rgb24Tests
[Fact]
public void FromRgba32()
{
var rgb = default(Rgb24);
Rgb24 rgb = default;
rgb.FromRgba32(new Rgba32(1, 2, 3, 4));
Assert.Equal(1, rgb.R);
@ -84,7 +86,7 @@ public class Rgb24Tests
[Fact]
public void FromVector4()
{
var rgb = default(Rgb24);
Rgb24 rgb = default;
rgb.FromVector4(Vec(1, 2, 3, 4));
Assert.Equal(1, rgb.R);
@ -95,7 +97,7 @@ public class Rgb24Tests
[Fact]
public void ToVector4()
{
var rgb = new Rgb24(1, 2, 3);
Rgb24 rgb = new(1, 2, 3);
Assert.Equal(Vec(1, 2, 3), rgb.ToVector4());
}
@ -104,9 +106,9 @@ public class Rgb24Tests
public void ToRgba32()
{
// arrange
var rgb = new Rgb24(1, 2, 3);
Rgb24 rgb = new(1, 2, 3);
Rgba32 rgba = default;
var expected = new Rgba32(1, 2, 3, 255);
Rgba32 expected = new(1, 2, 3, 255);
// act
rgb.ToRgba32(ref rgba);
@ -119,7 +121,7 @@ public class Rgb24Tests
public void Rgb24_FromBgra5551()
{
// arrange
var rgb = new Rgb24(255, 255, 255);
Rgb24 rgb = new(255, 255, 255);
// act
rgb.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
@ -129,4 +131,14 @@ public class Rgb24Tests
Assert.Equal(255, rgb.G);
Assert.Equal(255, rgb.B);
}
[Fact]
public void Rgb24_PixelInformation()
{
PixelTypeInfo info = Rgb24.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgb24>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

26
tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -12,7 +14,7 @@ public class Rgb48Tests
[Fact]
public void Rgb48_Values()
{
var rgb = new Rgba64(5243, 9830, 19660, 29491);
Rgba64 rgb = new(5243, 9830, 19660, 29491);
Assert.Equal(5243, rgb.R);
Assert.Equal(9830, rgb.G);
@ -32,9 +34,9 @@ public class Rgb48Tests
public void Rgb48_FromScaledVector4()
{
// arrange
var pixel = default(Rgb48);
var short3 = new Rgb48(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
var expected = new Rgb48(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
Rgb48 pixel = default;
Rgb48 short3 = new(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
Rgb48 expected = new(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
// act
Vector4 scaled = short3.ToScaledVector4();
@ -48,8 +50,8 @@ public class Rgb48Tests
public void Rgb48_ToRgba32()
{
// arrange
var rgba48 = new Rgb48(5140, 9766, 19532);
var expected = new Rgba32(20, 38, 76, 255);
Rgb48 rgba48 = new(5140, 9766, 19532);
Rgba32 expected = new(20, 38, 76, 255);
// act
Rgba32 actual = default;
@ -63,7 +65,7 @@ public class Rgb48Tests
public void Rgb48_FromBgra5551()
{
// arrange
var rgb = default(Rgb48);
Rgb48 rgb = default;
ushort expected = ushort.MaxValue;
// act
@ -74,4 +76,14 @@ public class Rgb48Tests
Assert.Equal(expected, rgb.G);
Assert.Equal(expected, rgb.B);
}
[Fact]
public void Rgb48_PixelInformation()
{
PixelTypeInfo info = Rgb48.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgb48>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.ComponentPrecision);
}
}

58
tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -15,10 +17,10 @@ public class Rgba1010102Tests
[Fact]
public void AreEqual()
{
var color1 = new Rgba1010102(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Rgba1010102(new Vector4(0.0f));
var color3 = new Rgba1010102(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new Rgba1010102(1.0f, 0.0f, 1.0f, 1.0f);
Rgba1010102 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Rgba1010102 color2 = new(new Vector4(0.0f));
Rgba1010102 color3 = new(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
Rgba1010102 color4 = new(1.0f, 0.0f, 1.0f, 1.0f);
Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
@ -30,10 +32,10 @@ public class Rgba1010102Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Rgba1010102(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Rgba1010102(new Vector4(1.0f));
var color3 = new Rgba1010102(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Rgba1010102(1.0f, 1.0f, 0.0f, 1.0f);
Rgba1010102 color1 = new(0.0f, 0.0f, 0.0f, 0.0f);
Rgba1010102 color2 = new(new Vector4(1.0f));
Rgba1010102 color3 = new(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
Rgba1010102 color4 = new(1.0f, 1.0f, 0.0f, 1.0f);
Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
@ -66,7 +68,7 @@ public class Rgba1010102Tests
public void Rgba1010102_ToScaledVector4()
{
// arrange
var rgba = new Rgba1010102(Vector4.One);
Rgba1010102 rgba = new(Vector4.One);
// act
Vector4 actual = rgba.ToScaledVector4();
@ -82,8 +84,8 @@ public class Rgba1010102Tests
public void Rgba1010102_FromScaledVector4()
{
// arrange
var rgba = new Rgba1010102(Vector4.One);
var actual = default(Rgba1010102);
Rgba1010102 rgba = new(Vector4.One);
Rgba1010102 actual = default;
uint expected = 0xFFFFFFFF;
// act
@ -98,7 +100,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromBgra5551()
{
// arrange
var rgba = new Rgba1010102(Vector4.One);
Rgba1010102 rgba = new(Vector4.One);
uint expected = 0xFFFFFFFF;
// act
@ -112,7 +114,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromArgb32()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -126,8 +128,8 @@ public class Rgba1010102Tests
public void Rgba1010102_FromRgba32()
{
// arrange
var rgba1 = default(Rgba1010102);
var rgba2 = default(Rgba1010102);
Rgba1010102 rgba1 = default;
Rgba1010102 rgba2 = default;
uint expectedPackedValue1 = uint.MaxValue;
uint expectedPackedValue2 = 0xFFF003FF;
@ -144,7 +146,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromBgr24()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -158,7 +160,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromGrey8()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -172,7 +174,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromGrey16()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -186,7 +188,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromRgb24()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -200,7 +202,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromRgb48()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -214,7 +216,7 @@ public class Rgba1010102Tests
public void Rgba1010102_FromRgba64()
{
// arrange
var rgba = default(Rgba1010102);
Rgba1010102 rgba = default;
uint expectedPackedValue = uint.MaxValue;
// act
@ -235,8 +237,8 @@ public class Rgba1010102Tests
public void Rgba1010102_ToRgba32()
{
// arrange
var rgba = new Rgba1010102(0.1f, -0.3f, 0.5f, -0.7f);
var expected = new Rgba32(25, 0, 128, 0);
Rgba1010102 rgba = new(0.1f, -0.3f, 0.5f, -0.7f);
Rgba32 expected = new(25, 0, 128, 0);
// act
Rgba32 actual = default;
@ -245,4 +247,14 @@ public class Rgba1010102Tests
// assert
Assert.Equal(expected, actual);
}
[Fact]
public void Rgba1010102_PixelInformation()
{
PixelTypeInfo info = Rgba1010102.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgba1010102>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.ComponentPrecision);
}
}

96
tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -18,12 +20,12 @@ public class Rgba32Tests
[Fact]
public void AreEqual()
{
var color1 = new Rgba32(0, 0, 0);
var color2 = new Rgba32(0, 0, 0, 1F);
var color3 = Rgba32.ParseHex("#000");
var color4 = Rgba32.ParseHex("#000F");
var color5 = Rgba32.ParseHex("#000000");
var color6 = Rgba32.ParseHex("#000000FF");
Rgba32 color1 = new(0, 0, 0);
Rgba32 color2 = new(0, 0, 0, 1F);
Rgba32 color3 = Rgba32.ParseHex("#000");
Rgba32 color4 = Rgba32.ParseHex("#000F");
Rgba32 color5 = Rgba32.ParseHex("#000000");
Rgba32 color6 = Rgba32.ParseHex("#000000FF");
Assert.Equal(color1, color2);
Assert.Equal(color1, color3);
@ -38,11 +40,11 @@ public class Rgba32Tests
[Fact]
public void AreNotEqual()
{
var color1 = new Rgba32(255, 0, 0, 255);
var color2 = new Rgba32(0, 0, 0, 255);
var color3 = Rgba32.ParseHex("#000");
var color4 = Rgba32.ParseHex("#000000");
var color5 = Rgba32.ParseHex("#FF000000");
Rgba32 color1 = new(255, 0, 0, 255);
Rgba32 color2 = new(0, 0, 0, 255);
Rgba32 color3 = Rgba32.ParseHex("#000");
Rgba32 color4 = Rgba32.ParseHex("#000000");
Rgba32 color5 = Rgba32.ParseHex("#FF000000");
Assert.NotEqual(color1, color2);
Assert.NotEqual(color1, color3);
@ -56,25 +58,25 @@ public class Rgba32Tests
[Fact]
public void ConstructorAssignsProperties()
{
var color1 = new Rgba32(1, .1f, .133f, .864f);
Rgba32 color1 = new(1, .1f, .133f, .864f);
Assert.Equal(255, color1.R);
Assert.Equal((byte)Math.Round(.1f * 255), color1.G);
Assert.Equal((byte)Math.Round(.133f * 255), color1.B);
Assert.Equal((byte)Math.Round(.864f * 255), color1.A);
var color2 = new Rgba32(1, .1f, .133f);
Rgba32 color2 = new(1, .1f, .133f);
Assert.Equal(255, color2.R);
Assert.Equal(Math.Round(.1f * 255), color2.G);
Assert.Equal(Math.Round(.133f * 255), color2.B);
Assert.Equal(255, color2.A);
var color4 = new Rgba32(new Vector3(1, .1f, .133f));
Rgba32 color4 = new(new Vector3(1, .1f, .133f));
Assert.Equal(255, color4.R);
Assert.Equal(Math.Round(.1f * 255), color4.G);
Assert.Equal(Math.Round(.133f * 255), color4.B);
Assert.Equal(255, color4.A);
var color5 = new Rgba32(new Vector4(1, .1f, .133f, .5f));
Rgba32 color5 = new(new Vector4(1, .1f, .133f, .5f));
Assert.Equal(255, color5.R);
Assert.Equal(Math.Round(.1f * 255), color5.G);
Assert.Equal(Math.Round(.133f * 255), color5.B);
@ -88,7 +90,7 @@ public class Rgba32Tests
public void FromAndToHex()
{
// 8 digit hex matches css4 spec. RRGGBBAA
var color = Rgba32.ParseHex("#AABBCCDD"); // 170, 187, 204, 221
Rgba32 color = Rgba32.ParseHex("#AABBCCDD"); // 170, 187, 204, 221
Assert.Equal(170, color.R);
Assert.Equal(187, color.G);
Assert.Equal(204, color.B);
@ -111,7 +113,7 @@ public class Rgba32Tests
[Fact]
public unsafe void ByteLayout()
{
var color = new Rgba32(1, 2, 3, 4);
Rgba32 color = new(1, 2, 3, 4);
byte* colorBase = (byte*)&color;
Assert.Equal(1, colorBase[0]);
Assert.Equal(2, colorBase[1]);
@ -146,7 +148,7 @@ public class Rgba32Tests
public void Rgba32_ToScaledVector4()
{
// arrange
var rgba = new Rgba32(Vector4.One);
Rgba32 rgba = new(Vector4.One);
// act
Vector4 actual = rgba.ToScaledVector4();
@ -162,8 +164,8 @@ public class Rgba32Tests
public void Rgba32_FromScaledVector4()
{
// arrange
var rgba = new Rgba32(Vector4.One);
var actual = default(Rgba32);
Rgba32 rgba = new(Vector4.One);
Rgba32 actual = default;
uint expected = 0xFFFFFFFF;
// act
@ -185,9 +187,9 @@ public class Rgba32Tests
public void Rgba32_ToRgba32()
{
// arrange
var rgba = new Rgba32(+0.1f, -0.3f, +0.5f, -0.7f);
var actual = default(Rgba32);
var expected = new Rgba32(0x1a, 0, 0x80, 0);
Rgba32 rgba = new(+0.1f, -0.3f, +0.5f, -0.7f);
Rgba32 actual = default;
Rgba32 expected = new(0x1a, 0, 0x80, 0);
// act
actual.FromRgba32(rgba);
@ -200,9 +202,9 @@ public class Rgba32Tests
public void Rgba32_FromRgba32_ToRgba32()
{
// arrange
var rgba = default(Rgba32);
var actual = default(Rgba32);
var expected = new Rgba32(0x1a, 0, 0x80, 0);
Rgba32 rgba = default;
Rgba32 actual = default;
Rgba32 expected = new(0x1a, 0, 0x80, 0);
// act
rgba.FromRgba32(expected);
@ -216,9 +218,9 @@ public class Rgba32Tests
public void Rgba32_FromBgra32_ToRgba32()
{
// arrange
var rgba = default(Rgba32);
var actual = default(Bgra32);
var expected = new Bgra32(0x1a, 0, 0x80, 0);
Rgba32 rgba = default;
Bgra32 actual = default;
Bgra32 expected = new(0x1a, 0, 0x80, 0);
// act
rgba.FromBgra32(expected);
@ -232,9 +234,9 @@ public class Rgba32Tests
public void Rgba32_FromAbgr32_ToRgba32()
{
// arrange
var rgba = default(Rgba32);
var actual = default(Abgr32);
var expected = new Abgr32(0x1a, 0, 0x80, 0);
Rgba32 rgba = default;
Abgr32 actual = default;
Abgr32 expected = new(0x1a, 0, 0x80, 0);
// act
rgba.FromAbgr32(expected);
@ -248,9 +250,9 @@ public class Rgba32Tests
public void Rgba32_FromArgb32_ToArgb32()
{
// arrange
var rgba = default(Rgba32);
var actual = default(Argb32);
var expected = new Argb32(0x1a, 0, 0x80, 0);
Rgba32 rgba = default;
Argb32 actual = default;
Argb32 expected = new(0x1a, 0, 0x80, 0);
// act
rgba.FromArgb32(expected);
@ -264,9 +266,9 @@ public class Rgba32Tests
public void Rgba32_FromRgb48()
{
// arrange
var input = default(Rgba32);
var actual = default(Rgb48);
var expected = new Rgb48(65535, 0, 65535);
Rgba32 input = default;
Rgb48 actual = default;
Rgb48 expected = new(65535, 0, 65535);
// act
input.FromRgb48(expected);
@ -280,9 +282,9 @@ public class Rgba32Tests
public void Rgba32_FromRgba64()
{
// arrange
var input = default(Rgba32);
var actual = default(Rgba64);
var expected = new Rgba64(65535, 0, 65535, 0);
Rgba32 input = default;
Rgba64 actual = default;
Rgba64 expected = new(65535, 0, 65535, 0);
// act
input.FromRgba64(expected);
@ -296,7 +298,7 @@ public class Rgba32Tests
public void Rgba32_FromBgra5551()
{
// arrange
var rgb = default(Rgba32);
Rgba32 rgb = default;
uint expected = 0xFFFFFFFF;
// act
@ -305,4 +307,14 @@ public class Rgba32Tests
// assert
Assert.Equal(expected, rgb.PackedValue);
}
[Fact]
public void Rgba32_PixelInformation()
{
PixelTypeInfo info = Rgba32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgba32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.ComponentPrecision);
}
}

118
tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -38,7 +40,7 @@ public class Rgba64Tests
public void Rgba64_ToScaledVector4(ushort r, ushort g, ushort b, ushort a)
{
// arrange
var short2 = new Rgba64(r, g, b, a);
Rgba64 short2 = new(r, g, b, a);
float max = ushort.MaxValue;
float rr = r / max;
@ -63,7 +65,7 @@ public class Rgba64Tests
public void Rgba64_FromScaledVector4(ushort r, ushort g, ushort b, ushort a)
{
// arrange
var source = new Rgba64(r, g, b, a);
Rgba64 source = new(r, g, b, a);
// act
Vector4 scaled = source.ToScaledVector4();
@ -78,8 +80,8 @@ public class Rgba64Tests
[Fact]
public void Rgba64_Clamping()
{
var zero = default(Rgba64);
var one = default(Rgba64);
Rgba64 zero = default;
Rgba64 one = default;
zero.FromVector4(Vector4.One * -1234.0f);
one.FromVector4(Vector4.One * 1234.0f);
Assert.Equal(Vector4.Zero, zero.ToVector4());
@ -90,9 +92,9 @@ public class Rgba64Tests
public void Rgba64_ToRgba32()
{
// arrange
var rgba64 = new Rgba64(5140, 9766, 19532, 29555);
var actual = default(Rgba32);
var expected = new Rgba32(20, 38, 76, 115);
Rgba64 rgba64 = new(5140, 9766, 19532, 29555);
Rgba32 actual = default;
Rgba32 expected = new(20, 38, 76, 115);
// act
rgba64.ToRgba32(ref actual);
@ -105,7 +107,7 @@ public class Rgba64Tests
public void Rgba64_FromBgra5551()
{
// arrange
var rgba = default(Rgba64);
Rgba64 rgba = default;
ushort expected = ushort.MaxValue;
// act
@ -121,8 +123,8 @@ public class Rgba64Tests
[Fact]
public void Equality_WhenTrue()
{
var c1 = new Rgba64(100, 2000, 3000, 40000);
var c2 = new Rgba64(100, 2000, 3000, 40000);
Rgba64 c1 = new(100, 2000, 3000, 40000);
Rgba64 c2 = new(100, 2000, 3000, 40000);
Assert.True(c1.Equals(c2));
Assert.True(c1.GetHashCode() == c2.GetHashCode());
@ -131,9 +133,9 @@ public class Rgba64Tests
[Fact]
public void Equality_WhenFalse()
{
var c1 = new Rgba64(100, 2000, 3000, 40000);
var c2 = new Rgba64(101, 2000, 3000, 40000);
var c3 = new Rgba64(100, 2000, 3000, 40001);
Rgba64 c1 = new(100, 2000, 3000, 40000);
Rgba64 c2 = new(101, 2000, 3000, 40000);
Rgba64 c3 = new(100, 2000, 3000, 40001);
Assert.False(c1.Equals(c2));
Assert.False(c2.Equals(c3));
@ -143,8 +145,8 @@ public class Rgba64Tests
[Fact]
public void Rgba64_FromRgba32()
{
var source = new Rgba32(20, 38, 76, 115);
var expected = new Rgba64(5140, 9766, 19532, 29555);
Rgba32 source = new(20, 38, 76, 115);
Rgba64 expected = new(5140, 9766, 19532, 29555);
Rgba64 actual = default;
actual.FromRgba32(source);
@ -155,9 +157,9 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Rgba32()
{
var expected = new Rgba64(5140, 9766, 19532, 29555);
var source = new Rgba32(20, 38, 76, 115);
var actual = new Rgba64(source);
Rgba64 expected = new(5140, 9766, 19532, 29555);
Rgba32 source = new(20, 38, 76, 115);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -165,9 +167,9 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Bgra32()
{
var expected = new Rgba64(5140, 9766, 19532, 29555);
var source = new Bgra32(20, 38, 76, 115);
var actual = new Rgba64(source);
Rgba64 expected = new(5140, 9766, 19532, 29555);
Bgra32 source = new(20, 38, 76, 115);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -175,9 +177,9 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Argb32()
{
var expected = new Rgba64(5140, 9766, 19532, 29555);
var source = new Argb32(20, 38, 76, 115);
var actual = new Rgba64(source);
Rgba64 expected = new(5140, 9766, 19532, 29555);
Argb32 source = new(20, 38, 76, 115);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -185,9 +187,9 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Abgr32()
{
var expected = new Rgba64(5140, 9766, 19532, 29555);
var source = new Abgr32(20, 38, 76, 115);
var actual = new Rgba64(source);
Rgba64 expected = new(5140, 9766, 19532, 29555);
Abgr32 source = new(20, 38, 76, 115);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -195,9 +197,9 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Rgb24()
{
var expected = new Rgba64(5140, 9766, 19532, ushort.MaxValue);
var source = new Rgb24(20, 38, 76);
var actual = new Rgba64(source);
Rgba64 expected = new(5140, 9766, 19532, ushort.MaxValue);
Rgb24 source = new(20, 38, 76);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -205,9 +207,9 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Bgr24()
{
var expected = new Rgba64(5140, 9766, 19532, ushort.MaxValue);
var source = new Bgr24(20, 38, 76);
var actual = new Rgba64(source);
Rgba64 expected = new(5140, 9766, 19532, ushort.MaxValue);
Bgr24 source = new(20, 38, 76);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -215,11 +217,11 @@ public class Rgba64Tests
[Fact]
public void ConstructFrom_Vector4()
{
var source = new Vector4(0f, 0.2f, 0.5f, 1f);
Vector4 source = new(0f, 0.2f, 0.5f, 1f);
Rgba64 expected = default;
expected.FromScaledVector4(source);
var actual = new Rgba64(source);
Rgba64 actual = new(source);
Assert.Equal(expected, actual);
}
@ -228,11 +230,11 @@ public class Rgba64Tests
public void ToRgba32_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Rgba32(20, 38, 76, 115);
Rgba64 source = new(5140, 9766, 19532, 29555);
Rgba32 expected = new(20, 38, 76, 115);
// act
var actual = source.ToRgba32();
Rgba32 actual = source.ToRgba32();
// assert
Assert.Equal(expected, actual);
@ -242,11 +244,11 @@ public class Rgba64Tests
public void ToBgra32_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Bgra32(20, 38, 76, 115);
Rgba64 source = new(5140, 9766, 19532, 29555);
Bgra32 expected = new(20, 38, 76, 115);
// act
var actual = source.ToBgra32();
Bgra32 actual = source.ToBgra32();
// assert
Assert.Equal(expected, actual);
@ -256,11 +258,11 @@ public class Rgba64Tests
public void ToArgb32_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Argb32(20, 38, 76, 115);
Rgba64 source = new(5140, 9766, 19532, 29555);
Argb32 expected = new(20, 38, 76, 115);
// act
var actual = source.ToArgb32();
Argb32 actual = source.ToArgb32();
// assert
Assert.Equal(expected, actual);
@ -270,11 +272,11 @@ public class Rgba64Tests
public void ToAbgr32_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Abgr32(20, 38, 76, 115);
Rgba64 source = new(5140, 9766, 19532, 29555);
Abgr32 expected = new(20, 38, 76, 115);
// act
var actual = source.ToAbgr32();
Abgr32 actual = source.ToAbgr32();
// assert
Assert.Equal(expected, actual);
@ -284,11 +286,11 @@ public class Rgba64Tests
public void ToRgb24_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Rgb24(20, 38, 76);
Rgba64 source = new(5140, 9766, 19532, 29555);
Rgb24 expected = new(20, 38, 76);
// act
var actual = source.ToRgb24();
Rgb24 actual = source.ToRgb24();
// assert
Assert.Equal(expected, actual);
@ -298,13 +300,23 @@ public class Rgba64Tests
public void ToBgr24_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Bgr24(20, 38, 76);
Rgba64 source = new(5140, 9766, 19532, 29555);
Bgr24 expected = new(20, 38, 76);
// act
var actual = source.ToBgr24();
Bgr24 actual = source.ToBgr24();
// assert
Assert.Equal(expected, actual);
}
[Fact]
public void Rgba64_PixelInformation()
{
PixelTypeInfo info = Rgba64.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgba64>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.ComponentPrecision);
}
}

59
tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs

@ -3,6 +3,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -19,12 +20,12 @@ public class RgbaVectorTests
[Fact]
public void AreEqual()
{
var color1 = new RgbaVector(0, 0, 0F);
var color2 = new RgbaVector(0, 0, 0, 1F);
var color3 = RgbaVector.FromHex("#000");
var color4 = RgbaVector.FromHex("#000F");
var color5 = RgbaVector.FromHex("#000000");
var color6 = RgbaVector.FromHex("#000000FF");
RgbaVector color1 = new(0, 0, 0F);
RgbaVector color2 = new(0, 0, 0, 1F);
RgbaVector color3 = RgbaVector.FromHex("#000");
RgbaVector color4 = RgbaVector.FromHex("#000F");
RgbaVector color5 = RgbaVector.FromHex("#000000");
RgbaVector color6 = RgbaVector.FromHex("#000000FF");
Assert.Equal(color1, color2);
Assert.Equal(color1, color3);
@ -39,11 +40,11 @@ public class RgbaVectorTests
[Fact]
public void AreNotEqual()
{
var color1 = new RgbaVector(1, 0, 0, 1);
var color2 = new RgbaVector(0, 0, 0, 1);
var color3 = RgbaVector.FromHex("#000");
var color4 = RgbaVector.FromHex("#000000");
var color5 = RgbaVector.FromHex("#FF000000");
RgbaVector color1 = new(1, 0, 0, 1);
RgbaVector color2 = new(0, 0, 0, 1);
RgbaVector color3 = RgbaVector.FromHex("#000");
RgbaVector color4 = RgbaVector.FromHex("#000000");
RgbaVector color5 = RgbaVector.FromHex("#FF000000");
Assert.NotEqual(color1, color2);
Assert.NotEqual(color1, color3);
@ -57,13 +58,13 @@ public class RgbaVectorTests
[Fact]
public void ConstructorAssignsProperties()
{
var color1 = new RgbaVector(1, .1F, .133F, .864F);
RgbaVector color1 = new(1, .1F, .133F, .864F);
Assert.Equal(1F, color1.R);
Assert.Equal(.1F, color1.G);
Assert.Equal(.133F, color1.B);
Assert.Equal(.864F, color1.A);
var color2 = new RgbaVector(1, .1f, .133f);
RgbaVector color2 = new(1, .1f, .133f);
Assert.Equal(1F, color2.R);
Assert.Equal(.1F, color2.G);
Assert.Equal(.133F, color2.B);
@ -76,7 +77,7 @@ public class RgbaVectorTests
[Fact]
public void FromAndToHex()
{
var color = RgbaVector.FromHex("#AABBCCDD");
RgbaVector color = RgbaVector.FromHex("#AABBCCDD");
Assert.Equal(170 / 255F, color.R);
Assert.Equal(187 / 255F, color.G);
Assert.Equal(204 / 255F, color.B);
@ -104,7 +105,7 @@ public class RgbaVectorTests
[Fact]
public void FloatLayout()
{
var color = new RgbaVector(1F, 2, 3, 4);
RgbaVector color = new(1F, 2, 3, 4);
Vector4 colorBase = Unsafe.As<RgbaVector, Vector4>(ref Unsafe.Add(ref color, 0));
float[] ordered = new float[4];
colorBase.CopyTo(ordered);
@ -119,9 +120,9 @@ public class RgbaVectorTests
public void RgbaVector_FromRgb48()
{
// arrange
var input = default(RgbaVector);
var actual = default(Rgb48);
var expected = new Rgb48(65535, 0, 65535);
RgbaVector input = default;
Rgb48 actual = default;
Rgb48 expected = new(65535, 0, 65535);
// act
input.FromRgb48(expected);
@ -135,9 +136,9 @@ public class RgbaVectorTests
public void RgbaVector_FromRgba64()
{
// arrange
var input = default(RgbaVector);
var actual = default(Rgba64);
var expected = new Rgba64(65535, 0, 65535, 0);
RgbaVector input = default;
Rgba64 actual = default;
Rgba64 expected = new(65535, 0, 65535, 0);
// act
input.FromRgba64(expected);
@ -151,7 +152,7 @@ public class RgbaVectorTests
public void RgbaVector_FromBgra5551()
{
// arrange
var rgb = default(RgbaVector);
RgbaVector rgb = default;
Vector4 expected = Vector4.One;
// act
@ -165,7 +166,7 @@ public class RgbaVectorTests
public void RgbaVector_FromGrey16()
{
// arrange
var rgba = default(RgbaVector);
RgbaVector rgba = default;
Vector4 expected = Vector4.One;
// act
@ -179,7 +180,7 @@ public class RgbaVectorTests
public void RgbaVector_FromGrey8()
{
// arrange
var rgba = default(RgbaVector);
RgbaVector rgba = default;
Vector4 expected = Vector4.One;
// act
@ -204,4 +205,14 @@ public class RgbaVectorTests
Assert.Equal(srcColor, cloneColor);
}
[Fact]
public void RgbaVector_PixelInformation()
{
PixelTypeInfo info = RgbaVector.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<RgbaVector>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Float, info.ComponentPrecision);
}
}

44
tests/ImageSharp.Tests/PixelFormats/Short2Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -51,7 +53,7 @@ public class Short2Tests
public void Short2_ToScaledVector4()
{
// arrange
var short2 = new Short2(Vector2.One * 0x7FFF);
Short2 short2 = new(Vector2.One * 0x7FFF);
// act
Vector4 actual = short2.ToScaledVector4();
@ -67,8 +69,8 @@ public class Short2Tests
public void Short2_FromScaledVector4()
{
// arrange
var pixel = default(Short2);
var short2 = new Short2(Vector2.One * 0x7FFF);
Short2 pixel = default;
Short2 short2 = new(Vector2.One * 0x7FFF);
const ulong expected = 0x7FFF7FFF;
// act
@ -84,9 +86,9 @@ public class Short2Tests
public void Short2_ToRgba32()
{
// arrange
var short2 = new Short2(127.5f, -5.3f);
var actual = default(Rgba32);
var expected = new Rgba32(128, 127, 0, 255);
Short2 short2 = new(127.5f, -5.3f);
Rgba32 actual = default;
Rgba32 expected = new(128, 127, 0, 255);
// act
short2.ToRgba32(ref actual);
@ -99,9 +101,9 @@ public class Short2Tests
public void Short2_FromRgba32_ToRgba32()
{
// arrange
var short2 = default(Short2);
var actual = default(Rgba32);
var expected = new Rgba32(20, 38, 0, 255);
Short2 short2 = default;
Rgba32 actual = default;
Rgba32 expected = new(20, 38, 0, 255);
// act
short2.FromRgba32(expected);
@ -115,9 +117,9 @@ public class Short2Tests
public void Short2_FromRgb48()
{
// arrange
var input = default(Short2);
var actual = default(Rgb48);
var expected = new Rgb48(65535, 65535, 0);
Short2 input = default;
Rgb48 actual = default;
Rgb48 expected = new(65535, 65535, 0);
// act
input.FromRgb48(expected);
@ -131,9 +133,9 @@ public class Short2Tests
public void Short2_FromRgba64()
{
// arrange
var input = default(Short2);
var actual = default(Rgba64);
var expected = new Rgba64(65535, 65535, 0, 65535);
Short2 input = default;
Rgba64 actual = default;
Rgba64 expected = new(65535, 65535, 0, 65535);
// act
input.FromRgba64(expected);
@ -147,7 +149,7 @@ public class Short2Tests
public void Short2_FromBgra5551()
{
// arrange
var short2 = default(Short2);
Short2 short2 = default;
// act
short2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
@ -159,4 +161,14 @@ public class Short2Tests
Assert.Equal(0, actual.Z);
Assert.Equal(1, actual.W);
}
[Fact]
public void Short2_PixelInformation()
{
PixelTypeInfo info = Short2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Short2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Short, info.ComponentPrecision);
}
}

74
tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs

@ -2,6 +2,8 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -12,8 +14,8 @@ public class Short4Tests
[Fact]
public void Short4_PackedValues()
{
var shortValue1 = new Short4(11547, 12653, 29623, 193);
var shortValue2 = new Short4(0.1f, -0.3f, 0.5f, -0.7f);
Short4 shortValue1 = new(11547, 12653, 29623, 193);
Short4 shortValue2 = new(0.1f, -0.3f, 0.5f, -0.7f);
Assert.Equal(0x00c173b7316d2d1bUL, shortValue1.PackedValue);
Assert.Equal(18446462598732840960, shortValue2.PackedValue);
@ -38,7 +40,7 @@ public class Short4Tests
public void Short4_ToScaledVector4()
{
// arrange
var short4 = new Short4(Vector4.One * 0x7FFF);
Short4 short4 = new(Vector4.One * 0x7FFF);
// act
Vector4 actual = short4.ToScaledVector4();
@ -54,12 +56,12 @@ public class Short4Tests
public void Short4_FromScaledVector4()
{
// arrange
var short4 = new Short4(Vector4.One * 0x7FFF);
Short4 short4 = new(Vector4.One * 0x7FFF);
Vector4 scaled = short4.ToScaledVector4();
const long expected = 0x7FFF7FFF7FFF7FFF;
// act
var pixel = default(Short4);
Short4 pixel = default;
pixel.FromScaledVector4(scaled);
// assert
@ -70,12 +72,12 @@ public class Short4Tests
public void Short4_Clamping()
{
// arrange
var short1 = new Short4(Vector4.One * 1234567.0f);
var short2 = new Short4(Vector4.One * -1234567.0f);
Short4 short1 = new(Vector4.One * 1234567.0f);
Short4 short2 = new(Vector4.One * -1234567.0f);
// act
var vector1 = short1.ToVector4();
var vector2 = short2.ToVector4();
Vector4 vector1 = short1.ToVector4();
Vector4 vector2 = short2.ToVector4();
// assert
Assert.Equal(Vector4.One * 0x7FFF, vector1);
@ -86,9 +88,9 @@ public class Short4Tests
public void Short4_ToRgba32()
{
// arrange
var shortValue = new Short4(11547, 12653, 29623, 193);
var actual = default(Rgba32);
var expected = new Rgba32(172, 177, 243, 128);
Short4 shortValue = new(11547, 12653, 29623, 193);
Rgba32 actual = default;
Rgba32 expected = new(172, 177, 243, 128);
// act
shortValue.ToRgba32(ref actual);
@ -101,9 +103,9 @@ public class Short4Tests
public void Short4_FromRgba32_ToRgba32()
{
// arrange
var short4 = default(Short4);
var actual = default(Rgba32);
var expected = new Rgba32(20, 38, 0, 255);
Short4 short4 = default;
Rgba32 actual = default;
Rgba32 expected = new(20, 38, 0, 255);
// act
short4.FromRgba32(expected);
@ -117,9 +119,9 @@ public class Short4Tests
public void Short4_FromBgra32_ToRgba32()
{
// arrange
var short4 = default(Short4);
var actual = default(Bgra32);
var expected = new Bgra32(20, 38, 0, 255);
Short4 short4 = default;
Bgra32 actual = default;
Bgra32 expected = new(20, 38, 0, 255);
// act
short4.FromBgra32(expected);
@ -135,9 +137,9 @@ public class Short4Tests
public void Short4_FromArgb32_ToRgba32()
{
// arrange
var short4 = default(Short4);
var actual = default(Argb32);
var expected = new Argb32(20, 38, 0, 255);
Short4 short4 = default;
Argb32 actual = default;
Argb32 expected = new(20, 38, 0, 255);
// act
short4.FromArgb32(expected);
@ -153,9 +155,9 @@ public class Short4Tests
public void Short4_FromAbgrb32_ToRgba32()
{
// arrange
var short4 = default(Short4);
var actual = default(Abgr32);
var expected = new Abgr32(20, 38, 0, 255);
Short4 short4 = default;
Abgr32 actual = default;
Abgr32 expected = new(20, 38, 0, 255);
// act
short4.FromAbgr32(expected);
@ -171,9 +173,9 @@ public class Short4Tests
public void Short4_FromRgb48_ToRgb48()
{
// arrange
var input = default(Short4);
var actual = default(Rgb48);
var expected = new Rgb48(65535, 0, 65535);
Short4 input = default;
Rgb48 actual = default;
Rgb48 expected = new(65535, 0, 65535);
// act
input.FromRgb48(expected);
@ -187,9 +189,9 @@ public class Short4Tests
public void Short4_FromRgba64_ToRgba64()
{
// arrange
var input = default(Short4);
var actual = default(Rgba64);
var expected = new Rgba64(65535, 0, 65535, 0);
Short4 input = default;
Rgba64 actual = default;
Rgba64 expected = new(65535, 0, 65535, 0);
// act
input.FromRgba64(expected);
@ -203,7 +205,7 @@ public class Short4Tests
public void Short4_FromBgra5551()
{
// arrange
var short4 = default(Short4);
Short4 short4 = default;
Vector4 expected = Vector4.One;
// act
@ -212,4 +214,14 @@ public class Short4Tests
// assert
Assert.Equal(expected, short4.ToScaledVector4());
}
[Fact]
public void Short4_PixelInformation()
{
PixelTypeInfo info = Short4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Short4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Short, info.ComponentPrecision);
}
}

32
tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs

@ -12,8 +12,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut()
{
var color = new Rgba32(24, 48, 96, 192);
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 color = new(24, 48, 96, 192);
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -24,8 +24,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut()
{
var color = new Rgba32(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 color = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -36,8 +36,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut()
{
var color = new Rgba32(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 color = new(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -48,8 +48,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut()
{
var color = new Rgba32(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F);
Rgba32 color = new(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -60,8 +60,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut()
{
var color = Rgba32.ParseHex("183060C0");
var colorVector = RgbaVector.FromHex("183060C0");
Rgba32 color = Rgba32.ParseHex("183060C0");
RgbaVector colorVector = RgbaVector.FromHex("183060C0");
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -72,8 +72,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_To_Vector4_Produce_Equal_OutPut()
{
var color = new Rgba32(24, 48, 96, 192);
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 color = new(24, 48, 96, 192);
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.ToVector4(), colorVector.ToVector4());
}
@ -81,8 +81,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut()
{
var color = new Rgba32(24, 48, 96, 192);
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 color = new(24, 48, 96, 192);
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 rgba = default;
Rgba32 rgbaVector = default;
@ -95,8 +95,8 @@ public class UnPackedPixelTests
[Fact]
public void Color_Types_To_Hex_Produce_Equal_OutPut()
{
var color = new Rgba32(24, 48, 96, 192);
var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Rgba32 color = new(24, 48, 96, 192);
RgbaVector colorVector = new(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
// 183060C0
Assert.Equal(color.ToHex(), colorVector.ToHex());

2
tests/ImageSharp.Tests/TestFormat.cs

@ -263,7 +263,7 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat
public struct TestPixelForAgnosticDecode : IPixel<TestPixelForAgnosticDecode>
{
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<TestPixelForAgnosticDecode>(2, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<TestPixelForAgnosticDecode>(2, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
public PixelOperations<TestPixelForAgnosticDecode> CreatePixelOperations() => new();

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

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
@ -85,7 +85,7 @@ public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
private static TPixel GetBottomRightColor()
{
TPixel bottomRightColor = default;
bottomRightColor.FromVector4(new Vector4(1f, 0f, 1f, 0.5f));
bottomRightColor.FromScaledVector4(new Vector4(1f, 0f, 1f, 0.5f));
return bottomRightColor;
}
}

Loading…
Cancel
Save