Browse Source

introducing Rgb24 & Bgr24

pull/242/head
Anton Firszov 9 years ago
parent
commit
6ef195f812
  1. 2
      src/ImageSharp/PixelFormats/Alpha8.cs
  2. 2
      src/ImageSharp/PixelFormats/Argb32.cs
  3. 94
      src/ImageSharp/PixelFormats/Bgr24.cs
  4. 2
      src/ImageSharp/PixelFormats/Bgr565.cs
  5. 2
      src/ImageSharp/PixelFormats/Bgra4444.cs
  6. 2
      src/ImageSharp/PixelFormats/Bgra5551.cs
  7. 2
      src/ImageSharp/PixelFormats/Byte4.cs
  8. 2
      src/ImageSharp/PixelFormats/HalfSingle.cs
  9. 2
      src/ImageSharp/PixelFormats/HalfVector2.cs
  10. 2
      src/ImageSharp/PixelFormats/HalfVector4.cs
  11. 2
      src/ImageSharp/PixelFormats/IPixel.cs
  12. 2
      src/ImageSharp/PixelFormats/NormalizedByte2.cs
  13. 2
      src/ImageSharp/PixelFormats/NormalizedByte4.cs
  14. 2
      src/ImageSharp/PixelFormats/NormalizedShort2.cs
  15. 2
      src/ImageSharp/PixelFormats/NormalizedShort4.cs
  16. 2
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  17. 2
      src/ImageSharp/PixelFormats/Rg32.cs
  18. 94
      src/ImageSharp/PixelFormats/Rgb24.cs
  19. 2
      src/ImageSharp/PixelFormats/Rgba1010102.cs
  20. 8
      src/ImageSharp/PixelFormats/Rgba32.cs
  21. 2
      src/ImageSharp/PixelFormats/Rgba64.cs
  22. 2
      src/ImageSharp/PixelFormats/RgbaVector.cs
  23. 2
      src/ImageSharp/PixelFormats/Short2.cs
  24. 2
      src/ImageSharp/PixelFormats/Short4.cs
  25. 6
      src/Shared/stylecop.json
  26. 4
      tests/ImageSharp.Sandbox46/Tests/PixelFormats/PixelBlenderTests.cs
  27. 2
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  28. 63
      tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
  29. 0
      tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs
  30. 0
      tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs
  31. 0
      tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs
  32. 0
      tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs
  33. 0
      tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs
  34. 50
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs
  35. 5
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  36. 65
      tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs
  37. 0
      tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
  38. 0
      tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs
  39. 0
      tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs

2
src/ImageSharp/PixelFormats/Alpha8.cs

@ -62,7 +62,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Alpha8> CreateBulkOperations() => new PixelOperations<Alpha8>();
public PixelOperations<Alpha8> CreatePixelOperations() => new PixelOperations<Alpha8>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/Argb32.cs

@ -237,7 +237,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Argb32> CreateBulkOperations() => new PixelOperations<Argb32>();
public PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations<Argb32>();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]

94
src/ImageSharp/PixelFormats/Bgr24.cs

@ -0,0 +1,94 @@
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct Bgr24 : IPixel<Bgr24>
{
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B;
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G;
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Bgr24(byte r, byte g, byte b)
{
this.R = r;
this.G = g;
this.B = b;
}
public PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations<Bgr24>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Bgr24 other)
{
return this.R == other.R && this.G == other.G && this.B == other.B;
}
public override bool Equals(object obj)
{
return obj.GetType() == typeof(Bgr24) && this.Equals((Bgr24)obj);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
unchecked
{
int hashCode = this.B;
hashCode = (hashCode * 397) ^ this.G;
hashCode = (hashCode * 397) ^ this.R;
return hashCode;
}
}
public void PackFromBytes(byte x, byte y, byte z, byte w)
{
throw new NotImplementedException();
}
public void PackFromVector4(Vector4 vector)
{
throw new NotImplementedException();
}
public Vector4 ToVector4()
{
throw new NotImplementedException();
}
public void ToXyzBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
public void ToXyzwBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
public void ToZyxBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
public void ToZyxwBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
}
}

2
src/ImageSharp/PixelFormats/Bgr565.cs

@ -71,7 +71,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Bgr565> CreateBulkOperations() => new PixelOperations<Bgr565>();
public PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations<Bgr565>();
/// <summary>
/// Expands the packed representation into a <see cref="Vector3"/>.

2
src/ImageSharp/PixelFormats/Bgra4444.cs

@ -70,7 +70,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Bgra4444> CreateBulkOperations() => new PixelOperations<Bgra4444>();
public PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations<Bgra4444>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/Bgra5551.cs

@ -72,7 +72,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Bgra5551> CreateBulkOperations() => new PixelOperations<Bgra5551>();
public PixelOperations<Bgra5551> CreatePixelOperations() => new PixelOperations<Bgra5551>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/Byte4.cs

@ -73,7 +73,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Byte4> CreateBulkOperations() => new PixelOperations<Byte4>();
public PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations<Byte4>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/HalfSingle.cs

@ -76,7 +76,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<HalfSingle> CreateBulkOperations() => new PixelOperations<HalfSingle>();
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations<HalfSingle>();
/// <summary>
/// Expands the packed representation into a <see cref="float"/>.

2
src/ImageSharp/PixelFormats/HalfVector2.cs

@ -86,7 +86,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<HalfVector2> CreateBulkOperations() => new PixelOperations<HalfVector2>();
public PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations<HalfVector2>();
/// <summary>
/// Expands the packed representation into a <see cref="Vector2"/>.

2
src/ImageSharp/PixelFormats/HalfVector4.cs

@ -89,7 +89,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<HalfVector4> CreateBulkOperations() => new PixelOperations<HalfVector4>();
public PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations<HalfVector4>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/IPixel.cs

@ -20,7 +20,7 @@ namespace ImageSharp.PixelFormats
/// This method is not intended to be consumed directly. Use <see cref="PixelOperations{TPixel}.Instance"/> instead.
/// </summary>
/// <returns>The <see cref="PixelOperations{TPixel}"/> instance.</returns>
PixelOperations<TSelf> CreateBulkOperations();
PixelOperations<TSelf> CreatePixelOperations();
}
/// <summary>

2
src/ImageSharp/PixelFormats/NormalizedByte2.cs

@ -91,7 +91,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<NormalizedByte2> CreateBulkOperations() => new PixelOperations<NormalizedByte2>();
public PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations<NormalizedByte2>();
/// <summary>
/// Expands the packed representation into a <see cref="Vector2"/>.

2
src/ImageSharp/PixelFormats/NormalizedByte4.cs

@ -93,7 +93,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<NormalizedByte4> CreateBulkOperations() => new PixelOperations<NormalizedByte4>();
public PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations<NormalizedByte4>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/NormalizedShort2.cs

@ -91,7 +91,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<NormalizedShort2> CreateBulkOperations() => new PixelOperations<NormalizedShort2>();
public PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations<NormalizedShort2>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/NormalizedShort4.cs

@ -93,7 +93,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<NormalizedShort4> CreateBulkOperations() => new PixelOperations<NormalizedShort4>();
public PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations<NormalizedShort4>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

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

@ -20,7 +20,7 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Gets the global <see cref="PixelOperations{TPixel}"/> instance for the pixel type <typeparamref name="TPixel"/>
/// </summary>
public static PixelOperations<TPixel> Instance { get; } = default(TPixel).CreateBulkOperations();
public static PixelOperations<TPixel> Instance { get; } = default(TPixel).CreatePixelOperations();
/// <summary>
/// Bulk version of <see cref="IPixel.PackFromVector4(Vector4)"/>

2
src/ImageSharp/PixelFormats/Rg32.cs

@ -76,7 +76,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Rg32> CreateBulkOperations() => new PixelOperations<Rg32>();
public PixelOperations<Rg32> CreatePixelOperations() => new PixelOperations<Rg32>();
/// <summary>
/// Expands the packed representation into a <see cref="Vector2"/>.

94
src/ImageSharp/PixelFormats/Rgb24.cs

@ -0,0 +1,94 @@
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct Rgb24 : IPixel<Rgb24>
{
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R;
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G;
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Rgb24(byte r, byte g, byte b)
{
this.R = r;
this.G = g;
this.B = b;
}
public PixelOperations<Rgb24> CreatePixelOperations() => new PixelOperations<Rgb24>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Rgb24 other)
{
return this.R == other.R && this.G == other.G && this.B == other.B;
}
public override bool Equals(object obj)
{
return obj.GetType() == typeof(Rgb24) && this.Equals((Rgb24)obj);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
unchecked
{
int hashCode = this.R;
hashCode = (hashCode * 397) ^ this.G;
hashCode = (hashCode * 397) ^ this.B;
return hashCode;
}
}
public void PackFromBytes(byte x, byte y, byte z, byte w)
{
throw new NotImplementedException();
}
public void PackFromVector4(Vector4 vector)
{
throw new NotImplementedException();
}
public Vector4 ToVector4()
{
throw new NotImplementedException();
}
public void ToXyzBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
public void ToXyzwBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
public void ToZyxBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
public void ToZyxwBytes(Span<byte> bytes, int startIndex)
{
throw new NotImplementedException();
}
}
}

2
src/ImageSharp/PixelFormats/Rgba1010102.cs

@ -79,7 +79,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Rgba1010102> CreateBulkOperations() => new PixelOperations<Rgba1010102>();
public PixelOperations<Rgba1010102> CreatePixelOperations() => new PixelOperations<Rgba1010102>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

8
src/ImageSharp/PixelFormats/Rgba32.cs

@ -23,31 +23,27 @@ namespace ImageSharp
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
[StructLayout(LayoutKind.Sequential)]
public partial struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
{
/// <summary>
/// Gets or sets the red component.
/// </summary>
[FieldOffset(0)]
public byte R;
/// <summary>
/// Gets or sets the green component.
/// </summary>
[FieldOffset(1)]
public byte G;
/// <summary>
/// Gets or sets the blue component.
/// </summary>
[FieldOffset(2)]
public byte B;
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
[FieldOffset(3)]
public byte A;
/// <summary>
@ -233,7 +229,7 @@ namespace ImageSharp
}
/// <inheritdoc />
public PixelOperations<Rgba32> CreateBulkOperations() => new PixelOperations();
public PixelOperations<Rgba32> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/Rgba64.cs

@ -78,7 +78,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Rgba64> CreateBulkOperations() => new PixelOperations<Rgba64>();
public PixelOperations<Rgba64> CreatePixelOperations() => new PixelOperations<Rgba64>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/RgbaVector.cs

@ -211,7 +211,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<RgbaVector> CreateBulkOperations() => new RgbaVector.PixelOperations();
public PixelOperations<RgbaVector> CreatePixelOperations() => new RgbaVector.PixelOperations();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/Short2.cs

@ -91,7 +91,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Short2> CreateBulkOperations() => new PixelOperations<Short2>();
public PixelOperations<Short2> CreatePixelOperations() => new PixelOperations<Short2>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/PixelFormats/Short4.cs

@ -93,7 +93,7 @@ namespace ImageSharp.PixelFormats
}
/// <inheritdoc />
public PixelOperations<Short4> CreateBulkOperations() => new PixelOperations<Short4>();
public PixelOperations<Short4> CreatePixelOperations() => new PixelOperations<Short4>();
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]

6
src/Shared/stylecop.json

@ -3,7 +3,11 @@
"settings": {
"documentationRules": {
"companyName": "James Jackson-South",
"copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0."
"copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0.",
"documentInterfaces": false,
"documentInternalElements": false,
"documentExposedElements": false
}
}
}

4
tests/ImageSharp.Tests/PixelFormats/PixelOperations.cs → tests/ImageSharp.Sandbox46/Tests/PixelFormats/PixelBlenderTests.cs

@ -15,7 +15,7 @@ namespace ImageSharp.Tests.PixelFormats
public class PixelOperations
{
public static TheoryData<object, Type, PixelBlenderMode> blenderMappings = new TheoryData<object, Type, PixelBlenderMode>()
public static TheoryData<object, Type, PixelBlenderMode> BlenderMappings = new TheoryData<object, Type, PixelBlenderMode>()
{
{ new TestPixel<Rgba32>(), typeof(DefaultNormalPixelBlender<Rgba32>), PixelBlenderMode.Normal },
{ new TestPixel<Rgba32>(), typeof(DefaultScreenPixelBlender<Rgba32>), PixelBlenderMode.Screen },
@ -39,7 +39,7 @@ namespace ImageSharp.Tests.PixelFormats
};
[Theory]
[MemberData(nameof(blenderMappings))]
[MemberData(nameof(BlenderMappings))]
public void ReturnsCorrectBlender<TPixel>(TestPixel<TPixel> pixel, Type type, PixelBlenderMode mode)
where TPixel : struct, IPixel<TPixel>
{

2
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -7,7 +7,7 @@
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<None Include="PixelFormats\PixelOperations.cs" />
<None Include="PixelFormats\PixelOperationsTests.Blender.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />

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

@ -0,0 +1,63 @@
namespace ImageSharp.Tests
{
using ImageSharp.PixelFormats;
using Xunit;
public class Bgr24Tests
{
public static readonly TheoryData<byte, byte, byte> ColorData =
new TheoryData<byte, byte, byte>() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } };
[Theory]
[MemberData(nameof(ColorData))]
public void Constructor(byte r, byte g, byte b)
{
var p = new Rgb24(r, g, b);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
Assert.Equal(b, p.B);
}
[Fact]
public unsafe void ByteLayoutIsSequentialBgr()
{
var color = new Bgr24(1, 2, 3);
byte* ptr = (byte*)&color;
Assert.Equal(3, ptr[0]);
Assert.Equal(2, ptr[1]);
Assert.Equal(1, ptr[2]);
}
public class Equality
{
public static TheoryData<byte, byte, byte> ColorData = Rgb24Tests.ColorData;
[Theory]
[MemberData(nameof(ColorData))]
public void WhenTrue(byte r, byte g, byte b)
{
var x = new Rgb24(r, g, b);
var y = new Rgb24(r, g, b);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
Assert.Equal(x.GetHashCode(), y.GetHashCode());
}
[Theory]
[InlineData(1, 2, 3, 1, 2, 4)]
[InlineData(0, 255, 0, 0, 244, 0)]
[InlineData(1, 255, 0, 0, 255, 0)]
public void WhenFalse(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
{
var a = new Rgb24(1, 2, 3);
var b = new Rgb24(1, 2, 4);
Assert.False(a.Equals(b));
Assert.False(a.Equals((object)b));
}
}
}
}

0
tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs → tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs

0
tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs → tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs

0
tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs → tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs

0
tests/ImageSharp.Tests/Colors/ColorPackingTests.cs → tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs

0
tests/ImageSharp.Tests/Colors/PackedPixelTests.cs → tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs

50
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs

@ -0,0 +1,50 @@
// <copyright file="PixelBlenderTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.PixelFormats
{
using System;
using System.Collections.Generic;
using System.Text;
using ImageSharp.PixelFormats;
using ImageSharp.PixelFormats.PixelBlenders;
using ImageSharp.Tests.TestUtilities;
using Xunit;
public partial class PixelOperationsTests
{
public static TheoryData<object, Type, PixelBlenderMode> BlenderMappings = new TheoryData<object, Type, PixelBlenderMode>()
{
{ new TestPixel<Rgba32>(), typeof(DefaultNormalPixelBlender<Rgba32>), PixelBlenderMode.Normal },
{ new TestPixel<Rgba32>(), typeof(DefaultScreenPixelBlender<Rgba32>), PixelBlenderMode.Screen },
{ new TestPixel<Rgba32>(), typeof(DefaultHardLightPixelBlender<Rgba32>), PixelBlenderMode.HardLight },
{ new TestPixel<Rgba32>(), typeof(DefaultOverlayPixelBlender<Rgba32>), PixelBlenderMode.Overlay },
{ new TestPixel<Rgba32>(), typeof(DefaultDarkenPixelBlender<Rgba32>), PixelBlenderMode.Darken },
{ new TestPixel<Rgba32>(), typeof(DefaultLightenPixelBlender<Rgba32>), PixelBlenderMode.Lighten },
{ new TestPixel<Rgba32>(), typeof(DefaultAddPixelBlender<Rgba32>), PixelBlenderMode.Add },
{ new TestPixel<Rgba32>(), typeof(DefaultSubstractPixelBlender<Rgba32>), PixelBlenderMode.Substract },
{ new TestPixel<Rgba32>(), typeof(DefaultMultiplyPixelBlender<Rgba32>), PixelBlenderMode.Multiply },
{ new TestPixel<RgbaVector>(), typeof(DefaultNormalPixelBlender<RgbaVector>), PixelBlenderMode.Normal },
{ new TestPixel<RgbaVector>(), typeof(DefaultScreenPixelBlender<RgbaVector>), PixelBlenderMode.Screen },
{ new TestPixel<RgbaVector>(), typeof(DefaultHardLightPixelBlender<RgbaVector>), PixelBlenderMode.HardLight },
{ new TestPixel<RgbaVector>(), typeof(DefaultOverlayPixelBlender<RgbaVector>), PixelBlenderMode.Overlay },
{ new TestPixel<RgbaVector>(), typeof(DefaultDarkenPixelBlender<RgbaVector>), PixelBlenderMode.Darken },
{ new TestPixel<RgbaVector>(), typeof(DefaultLightenPixelBlender<RgbaVector>), PixelBlenderMode.Lighten },
{ new TestPixel<RgbaVector>(), typeof(DefaultAddPixelBlender<RgbaVector>), PixelBlenderMode.Add },
{ new TestPixel<RgbaVector>(), typeof(DefaultSubstractPixelBlender<RgbaVector>), PixelBlenderMode.Substract },
{ new TestPixel<RgbaVector>(), typeof(DefaultMultiplyPixelBlender<RgbaVector>), PixelBlenderMode.Multiply },
};
[Theory]
[MemberData(nameof(BlenderMappings))]
public void ReturnsCorrectBlender<TPixel>(TestPixel<TPixel> pixel, Type type, PixelBlenderMode mode)
where TPixel : struct, IPixel<TPixel>
{
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(mode);
Assert.IsType(type, blender);
}
}
}

5
tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs → tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

@ -1,6 +1,6 @@
// ReSharper disable InconsistentNaming
// ReSharper disable AccessToDisposedClosure
namespace ImageSharp.Tests.Colors
namespace ImageSharp.Tests.PixelFormats
{
using System;
using System.Numerics;
@ -11,8 +11,9 @@ namespace ImageSharp.Tests.Colors
using Xunit;
using Xunit.Abstractions;
public class PixelOperationsTests
public partial class PixelOperationsTests
{
public class Color32 : PixelOperationsTests<Rgba32>
{
public Color32(ITestOutputHelper output)

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

@ -0,0 +1,65 @@
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests
{
using ImageSharp.PixelFormats;
using Xunit;
public class Rgb24Tests
{
public static readonly TheoryData<byte, byte, byte> ColorData =
new TheoryData<byte, byte, byte>() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } };
[Theory]
[MemberData(nameof(ColorData))]
public void Constructor(byte r, byte g, byte b)
{
var p = new Rgb24(r, g, b);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
Assert.Equal(b, p.B);
}
[Fact]
public unsafe void ByteLayoutIsSequentialRgb()
{
var color = new Rgb24(1, 2, 3);
byte* ptr = (byte*)&color;
Assert.Equal(1, ptr[0]);
Assert.Equal(2, ptr[1]);
Assert.Equal(3, ptr[2]);
}
public class Equality
{
public static TheoryData<byte, byte, byte> ColorData = Rgb24Tests.ColorData;
[Theory]
[MemberData(nameof(ColorData))]
public void WhenTrue(byte r, byte g, byte b)
{
var x = new Rgb24(r, g, b);
var y = new Rgb24(r, g, b);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
Assert.Equal(x.GetHashCode(), y.GetHashCode());
}
[Theory]
[InlineData(1, 2, 3, 1, 2, 4)]
[InlineData(0, 255, 0, 0, 244, 0)]
[InlineData(1, 255, 0, 0, 255, 0)]
public void WhenFalse(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
{
var a = new Rgb24(1, 2, 3);
var b = new Rgb24(1, 2, 4);
Assert.False(a.Equals(b));
Assert.False(a.Equals((object)b));
}
}
}
}

0
tests/ImageSharp.Tests/Colors/Rgba32Tests.cs → tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs

0
tests/ImageSharp.Tests/Colors/RgbaVectorTests.cs → tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs

0
tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs → tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs

Loading…
Cancel
Save