Browse Source

Remove from tests

af/merge-core
James Jackson-South 8 years ago
parent
commit
b5d6a4b692
  1. 7
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
  2. 8
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
  3. 519
      tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs
  4. 23
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  5. 76
      tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs
  6. 10
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs
  7. 16
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  8. 20
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

7
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs

@ -35,11 +35,16 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
{ {
TPixel[] s = this.source.Array; TPixel[] s = this.source.Array;
byte[] d = this.destination.Array; byte[] d = this.destination.Array;
var rgb = default(Rgb24);
for (int i = 0; i < this.Count; i++) for (int i = 0; i < this.Count; i++)
{ {
TPixel c = s[i]; TPixel c = s[i];
c.ToXyzBytes(d, i * 4); int i3 = i * 3;
c.ToRgb24(ref rgb);
d[i3] = rgb.R;
d[i3 + 1] = rgb.G;
d[i3 + 2] = rgb.B;
} }
} }

8
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs

@ -40,11 +40,17 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
{ {
TPixel[] s = this.source.Array; TPixel[] s = this.source.Array;
byte[] d = this.destination.Array; byte[] d = this.destination.Array;
var rgba = default(Rgba32);
for (int i = 0; i < this.Count; i++) for (int i = 0; i < this.Count; i++)
{ {
TPixel c = s[i]; TPixel c = s[i];
c.ToXyzwBytes(d, i * 4); int i4 = i * 4;
c.ToRgba32(ref rgba);
d[i4] = rgba.R;
d[i4 + 1] = rgba.G;
d[i4 + 2] = rgba.B;
d[i4 + 3] = rgba.A;
} }
} }

519
tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Diagnostics;
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
@ -34,29 +33,29 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(26, new Alpha8(0.1F).PackedValue); Assert.Equal(26, new Alpha8(0.1F).PackedValue);
// Test ordering // Test ordering
Vector4 vector = new Alpha8(.5F).ToVector4(); var vector = new Alpha8(.5F).ToVector4();
Assert.Equal(0, vector.X); Assert.Equal(0, vector.X);
Assert.Equal(0, vector.Y); Assert.Equal(0, vector.Y);
Assert.Equal(0, vector.Z); Assert.Equal(0, vector.Z);
Assert.Equal(.5F, vector.W, 2); Assert.Equal(.5F, vector.W, 2);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Alpha8(.5F).ToXyzBytes(rgb, 0); new Alpha8(.5F).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 0, 0, 0 }); Assert.Equal(rgb, new Rgb24(0, 0, 0));
new Alpha8(.5F).ToXyzwBytes(rgba, 0); new Alpha8(.5F).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 0, 0, 0, 128 }); Assert.Equal(rgba, new Rgba32(0, 0, 0, 128));
new Alpha8(.5F).ToZyxBytes(bgr, 0); new Alpha8(.5F).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 0, 0 }); Assert.Equal(bgr, new Bgr24(0, 0, 0));
new Alpha8(.5F).ToZyxwBytes(bgra, 0); new Alpha8(.5F).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 0, 0, 128 }); Assert.Equal(bgra, new Bgra32(0, 0, 0, 128));
} }
[Fact] [Fact]
@ -82,26 +81,26 @@ namespace SixLabors.ImageSharp.Tests.Colors
float y = -0.3f; float y = -0.3f;
float z = +0.5f; float z = +0.5f;
float w = -0.7f; float w = -0.7f;
Argb32 argb = new Argb32(x, y, z, w); var argb = new Argb32(x, y, z, w);
Assert.Equal(0x001a0080u, argb.PackedValue); Assert.Equal(0x001a0080u, argb.PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
argb.ToXyzBytes(rgb, 0); argb.ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 }); Assert.Equal(rgb, new Rgb24(0x1a, 0, 0x80));
argb.ToXyzwBytes(rgba, 0); argb.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 }); Assert.Equal(rgba, new Rgba32(0x1a, 0, 0x80, 0));
argb.ToZyxBytes(bgr, 0); argb.ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a }); Assert.Equal(bgr, new Bgr24(0x1a, 0, 0x80));
argb.ToZyxwBytes(bgra, 0); argb.ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 }); Assert.Equal(bgra, new Bgra32(0x1a, 0, 0x80, 0));
} }
[Fact] [Fact]
@ -133,22 +132,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(6160, new Bgr565(x, y, z).PackedValue); Assert.Equal(6160, new Bgr565(x, y, z).PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Bgr565(x, y, z).ToXyzBytes(rgb, 0); new Bgr565(x, y, z).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 25, 0, 132 }); Assert.Equal(rgb, new Rgb24(25, 0, 132));
new Bgr565(x, y, z).ToXyzwBytes(rgba, 0); new Bgr565(x, y, z).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 25, 0, 132, 255 }); Assert.Equal(rgba, new Rgba32(25, 0, 132, 255));
new Bgr565(x, y, z).ToZyxBytes(bgr, 0); new Bgr565(x, y, z).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 132, 0, 25 }); Assert.Equal(bgr, new Bgr24(25, 0, 132));
new Bgr565(x, y, z).ToZyxwBytes(bgra, 0); new Bgr565(x, y, z).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 132, 0, 25, 255 }); Assert.Equal(bgra, new Bgra32(25, 0, 132, 255));
} }
[Fact] [Fact]
@ -183,22 +182,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(520, new Bgra4444(x, y, z, w).PackedValue); Assert.Equal(520, new Bgra4444(x, y, z, w).PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Bgra4444(x, y, z, w).ToXyzBytes(rgb, 0); new Bgra4444(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 34, 0, 136 }); Assert.Equal(rgb, new Rgb24(34, 0, 136));
new Bgra4444(x, y, z, w).ToXyzwBytes(rgba, 0); new Bgra4444(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 34, 0, 136, 0 }); Assert.Equal(rgba, new Rgba32(34, 0, 136, 0));
new Bgra4444(x, y, z, w).ToZyxBytes(bgr, 0); new Bgra4444(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 136, 0, 34 }); Assert.Equal(bgr, new Bgr24(34, 0, 136));
new Bgra4444(x, y, z, w).ToZyxwBytes(bgra, 0); new Bgra4444(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 136, 0, 34, 0 }); Assert.Equal(bgra, new Bgra32(34, 0, 136, 0));
} }
[Fact] [Fact]
@ -229,22 +228,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(3088, new Bgra5551(x, y, z, w).PackedValue); Assert.Equal(3088, new Bgra5551(x, y, z, w).PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Bgra5551(x, y, z, w).ToXyzBytes(rgb, 0); new Bgra5551(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 24, 0, 131 }); Assert.Equal(rgb, new Rgb24(24, 0, 131));
new Bgra5551(x, y, z, w).ToXyzwBytes(rgba, 0); new Bgra5551(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 24, 0, 131, 0 }); Assert.Equal(rgba, new Rgba32(24, 0, 131, 0));
new Bgra5551(x, y, z, w).ToZyxBytes(bgr, 0); new Bgra5551(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 131, 0, 24 }); Assert.Equal(bgr, new Bgr24(24, 0, 131));
new Bgra5551(x, y, z, w).ToZyxwBytes(bgra, 0); new Bgra5551(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 131, 0, 24, 0 }); Assert.Equal(bgra, new Bgra32(24, 0, 131, 0));
} }
[Fact] [Fact]
@ -280,27 +279,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal((uint)128, new Byte4(x, y, z, w).PackedValue); Assert.Equal((uint)128, new Byte4(x, y, z, w).PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Byte4(x, y, z, w).ToXyzBytes(rgb, 0); new Byte4(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 128, 0, 0 }); Assert.Equal(rgb, new Rgb24(128, 0, 0));
new Byte4(x, y, z, w).ToXyzwBytes(rgba, 0); new Byte4(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 128, 0, 0, 0 }); Assert.Equal(rgba, new Rgba32(128, 0, 0, 0));
new Byte4(x, y, z, w).ToZyxBytes(bgr, 0); new Byte4(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 0, 128 }); Assert.Equal(bgr, new Bgr24(128, 0, 0));
new Byte4(x, y, z, w).ToZyxwBytes(bgra, 0); new Byte4(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 0, 128, 0 }); Assert.Equal(bgra, new Bgra32(128, 0, 0, 0));
Byte4 r = new Byte4(); var r = new Byte4();
r.PackFromRgba32(new Rgba32(20, 38, 0, 255)); r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 }); Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
} }
[Fact] [Fact]
@ -319,22 +318,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
float x = .5F; float x = .5F;
Assert.True(Equal(new Vector4(x, 0, 0, 1), new HalfSingle(x).ToVector4())); Assert.True(Equal(new Vector4(x, 0, 0, 1), new HalfSingle(x).ToVector4()));
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new HalfSingle(x).ToXyzBytes(rgb, 0); new HalfSingle(x).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 128, 0, 0 }); Assert.Equal(rgb, new Rgb24(128, 0, 0));
new HalfSingle(x).ToXyzwBytes(rgba, 0); new HalfSingle(x).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 128, 0, 0, 255 }); Assert.Equal(rgba, new Rgba32(128, 0, 0, 255));
new HalfSingle(x).ToZyxBytes(bgr, 0); new HalfSingle(x).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 0, 128 }); Assert.Equal(bgr, new Bgr24(128, 0, 0));
new HalfSingle(x).ToZyxwBytes(bgra, 0); new HalfSingle(x).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 0, 128, 255 }); Assert.Equal(bgra, new Bgra32(128, 0, 0, 255));
} }
[Fact] [Fact]
@ -356,22 +355,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
float y = .25F; float y = .25F;
Assert.True(Equal(new Vector4(x, y, 0, 1), new HalfVector2(x, y).ToVector4())); Assert.True(Equal(new Vector4(x, y, 0, 1), new HalfVector2(x, y).ToVector4()));
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new HalfVector2(x, y).ToXyzBytes(rgb, 0); new HalfVector2(x, y).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 128, 64, 0 }); Assert.Equal(rgb, new Rgb24(128, 64, 0));
new HalfVector2(x, y).ToXyzwBytes(rgba, 0); new HalfVector2(x, y).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 128, 64, 0, 255 }); Assert.Equal(rgba, new Rgba32(128, 64, 0, 255));
new HalfVector2(x, y).ToZyxBytes(bgr, 0); new HalfVector2(x, y).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 64, 128 }); Assert.Equal(bgr, new Bgr24(128, 64, 0));
new HalfVector2(x, y).ToZyxwBytes(bgra, 0); new HalfVector2(x, y).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 64, 128, 255 }); Assert.Equal(bgra, new Bgra32(128, 64, 0, 255));
} }
[Fact] [Fact]
@ -402,22 +401,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
float z = .75F; float z = .75F;
float w = 1F; float w = 1F;
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new HalfVector4(x, y, z, w).ToXyzBytes(rgb, 0); new HalfVector4(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 64, 128, 191 }); Assert.Equal(rgb, new Rgb24(64, 128, 191));
new HalfVector4(x, y, z, w).ToXyzwBytes(rgba, 0); new HalfVector4(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 64, 128, 191, 255 }); Assert.Equal(rgba, new Rgba32(64, 128, 191, 255));
new HalfVector4(x, y, z, w).ToZyxBytes(bgr, 0); new HalfVector4(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 191, 128, 64 }); Assert.Equal(bgr, new Bgr24(64, 128, 191));
new HalfVector4(x, y, z, w).ToZyxwBytes(bgra, 0); new HalfVector4(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 191, 128, 64, 255 }); Assert.Equal(bgra, new Bgra32(64, 128, 191, 255));
} }
[Fact] [Fact]
@ -443,26 +442,26 @@ namespace SixLabors.ImageSharp.Tests.Colors
float x = 0.1f; float x = 0.1f;
float y = -0.3f; float y = -0.3f;
Assert.Equal(0xda0d, new NormalizedByte2(x, y).PackedValue); Assert.Equal(0xda0d, new NormalizedByte2(x, y).PackedValue);
NormalizedByte2 n = new NormalizedByte2(); var n = new NormalizedByte2();
n.PackFromRgba32(new Rgba32(141, 90, 0, 0)); n.PackFromRgba32(new Rgba32(141, 90, 0, 0));
Assert.Equal(0xda0d, n.PackedValue); Assert.Equal(0xda0d, n.PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new NormalizedByte2(x, y).ToXyzBytes(rgb, 0); new NormalizedByte2(x, y).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 141, 90, 0 }); Assert.Equal(rgb, new Rgb24(141, 90, 0));
new NormalizedByte2(x, y).ToXyzwBytes(rgba, 0); new NormalizedByte2(x, y).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 141, 90, 0, 255 }); Assert.Equal(rgba, new Rgba32(141, 90, 0, 255));
new NormalizedByte2(x, y).ToZyxBytes(bgr, 0); new NormalizedByte2(x, y).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 90, 141 }); Assert.Equal(bgr, new Bgr24(141, 90, 0));
new NormalizedByte2(x, y).ToZyxwBytes(bgra, 0); new NormalizedByte2(x, y).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 90, 141, 255 }); Assert.Equal(bgra, new Bgra32(141, 90, 0, 255));
} }
[Fact] [Fact]
@ -486,38 +485,38 @@ namespace SixLabors.ImageSharp.Tests.Colors
float z = 0.5f; float z = 0.5f;
float w = -0.7f; float w = -0.7f;
Assert.Equal(0xA740DA0D, new NormalizedByte4(x, y, z, w).PackedValue); Assert.Equal(0xA740DA0D, new NormalizedByte4(x, y, z, w).PackedValue);
NormalizedByte4 n = new NormalizedByte4(); var n = new NormalizedByte4();
n.PackFromRgba32(new Rgba32(141, 90, 192, 39)); n.PackFromRgba32(new Rgba32(141, 90, 192, 39));
Assert.Equal(0xA740DA0D, n.PackedValue); Assert.Equal(0xA740DA0D, n.PackedValue);
Assert.Equal((uint)958796544, new NormalizedByte4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue); Assert.Equal((uint)958796544, new NormalizedByte4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new NormalizedByte4(x, y, z, w).ToXyzBytes(rgb, 0); new NormalizedByte4(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 141, 90, 192 }); Assert.Equal(rgb, new Rgb24(141, 90, 192));
new NormalizedByte4(x, y, z, w).ToXyzwBytes(rgba, 0); new NormalizedByte4(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 141, 90, 192, 39 }); Assert.Equal(rgba, new Rgba32(141, 90, 192, 39));
new NormalizedByte4(x, y, z, w).ToZyxBytes(bgr, 0); new NormalizedByte4(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 192, 90, 141 }); Assert.Equal(bgr, new Bgr24(141, 90, 192));
new NormalizedByte4(x, y, z, w).ToZyxwBytes(bgra, 0); new NormalizedByte4(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 192, 90, 141, 39 }); Assert.Equal(bgra, new Bgra32(141, 90, 192, 39));
// http://community.monogame.net/t/normalizedbyte4-texture2d-gives-different-results-from-xna/8012/8 // http://community.monogame.net/t/normalizedbyte4-texture2d-gives-different-results-from-xna/8012/8
NormalizedByte4 r = new NormalizedByte4(); var r = new NormalizedByte4();
r.PackFromRgba32(new Rgba32(9, 115, 202, 127)); r.PackFromRgba32(new Rgba32(9, 115, 202, 127));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 }); Assert.Equal(rgba, new Rgba32(9, 115, 202, 127));
r.PackedValue = 0xff4af389; r.PackedValue = 0xff4af389;
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 }); Assert.Equal(rgba, new Rgba32(9, 115, 202, 127));
} }
[Fact] [Fact]
@ -544,30 +543,30 @@ namespace SixLabors.ImageSharp.Tests.Colors
y = -0.3f; y = -0.3f;
Assert.Equal(3650751693, new NormalizedShort2(x, y).PackedValue); Assert.Equal(3650751693, new NormalizedShort2(x, y).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
NormalizedShort2 n = new NormalizedShort2(); var n = new NormalizedShort2();
n.PackFromRgba32(new Rgba32(141, 90, 0, 0)); n.PackFromRgba32(new Rgba32(141, 90, 0, 0));
n.ToXyzBytes(rgb, 0); n.ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 141, 90, 0 }); Assert.Equal(rgb, new Rgb24(141, 90, 0));
// TODO: I don't think this can ever pass since the bytes are already truncated. // TODO: I don't think this can ever pass since the bytes are already truncated.
// Assert.Equal(3650751693, n.PackedValue); // Assert.Equal(3650751693, n.PackedValue);
new NormalizedShort2(x, y).ToXyzBytes(rgb, 0); new NormalizedShort2(x, y).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 141, 90, 0 }); Assert.Equal(rgb, new Rgb24(141, 90, 0));
new NormalizedShort2(x, y).ToXyzwBytes(rgba, 0); new NormalizedShort2(x, y).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 141, 90, 0, 255 }); Assert.Equal(rgba, new Rgba32(141, 90, 0, 255));
new NormalizedShort2(x, y).ToZyxBytes(bgr, 0); new NormalizedShort2(x, y).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 90, 141 }); Assert.Equal(bgr, new Bgr24(141, 90, 0));
new NormalizedShort2(x, y).ToZyxwBytes(bgra, 0); new NormalizedShort2(x, y).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 90, 141, 255 }); Assert.Equal(bgra, new Bgra32(141, 90, 0, 255));
} }
[Fact] [Fact]
@ -593,27 +592,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(0xa6674000d99a0ccd, new NormalizedShort4(x, y, z, w).PackedValue); Assert.Equal(0xa6674000d99a0ccd, new NormalizedShort4(x, y, z, w).PackedValue);
Assert.Equal((ulong)4150390751449251866, new NormalizedShort4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue); Assert.Equal((ulong)4150390751449251866, new NormalizedShort4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new NormalizedShort4(x, y, z, w).ToXyzBytes(rgb, 0); new NormalizedShort4(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 141, 90, 192 }); Assert.Equal(rgb, new Rgb24(141, 90, 192));
new NormalizedShort4(x, y, z, w).ToXyzwBytes(rgba, 0); new NormalizedShort4(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 141, 90, 192, 39 }); Assert.Equal(rgba, new Rgba32(141, 90, 192, 39));
new NormalizedShort4(x, y, z, w).ToZyxBytes(bgr, 0); new NormalizedShort4(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 192, 90, 141 }); Assert.Equal(bgr, new Bgr24(141, 90, 192));
new NormalizedShort4(x, y, z, w).ToZyxwBytes(bgra, 0); new NormalizedShort4(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 192, 90, 141, 39 }); Assert.Equal(bgra, new Bgra32(141, 90, 192, 39));
NormalizedShort4 r = new NormalizedShort4(); var r = new NormalizedShort4();
r.PackFromRgba32(new Rgba32(9, 115, 202, 127)); r.PackFromRgba32(new Rgba32(9, 115, 202, 127));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 }); Assert.Equal(rgba, new Rgba32(9, 115, 202, 127));
} }
[Fact] [Fact]
@ -640,22 +639,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal((uint)6554, new Rg32(x, y).PackedValue); Assert.Equal((uint)6554, new Rg32(x, y).PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Rg32(x, y).ToXyzBytes(rgb, 0); new Rg32(x, y).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 25, 0, 0 }); Assert.Equal(rgb, new Rgb24(25, 0, 0));
new Rg32(x, y).ToXyzwBytes(rgba, 0); new Rg32(x, y).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 25, 0, 0, 255 }); Assert.Equal(rgba, new Rgba32(25, 0, 0, 255));
new Rg32(x, y).ToZyxBytes(bgr, 0); new Rg32(x, y).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 0, 25 }); Assert.Equal(bgr, new Bgr24(25, 0, 0));
new Rg32(x, y).ToZyxwBytes(bgra, 0); new Rg32(x, y).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 0, 25, 255 }); Assert.Equal(bgra, new Bgra32(25, 0, 0, 255));
} }
[Fact] [Fact]
@ -685,28 +684,28 @@ namespace SixLabors.ImageSharp.Tests.Colors
w = -0.7f; w = -0.7f;
Assert.Equal((uint)536871014, new Rgba1010102(x, y, z, w).PackedValue); Assert.Equal((uint)536871014, new Rgba1010102(x, y, z, w).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Rgba1010102(x, y, z, w).ToXyzBytes(rgb, 0); new Rgba1010102(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 25, 0, 128 }); Assert.Equal(rgb, new Rgb24(25, 0, 128));
new Rgba1010102(x, y, z, w).ToXyzwBytes(rgba, 0); new Rgba1010102(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 }); Assert.Equal(rgba, new Rgba32(25, 0, 128, 0));
new Rgba1010102(x, y, z, w).ToZyxBytes(bgr, 0); new Rgba1010102(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 128, 0, 25 }); Assert.Equal(bgr, new Bgr24(25, 0, 128));
new Rgba1010102(x, y, z, w).ToZyxwBytes(bgra, 0); new Rgba1010102(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 128, 0, 25, 0 }); Assert.Equal(bgra, new Bgra32(25, 0, 128, 0));
// Alpha component accuracy will be awful. // Alpha component accuracy will be awful.
Rgba1010102 r = new Rgba1010102(); var r = new Rgba1010102();
r.PackFromRgba32(new Rgba32(25, 0, 128, 0)); r.PackFromRgba32(new Rgba32(25, 0, 128, 0));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 }); Assert.Equal(rgba, new Rgba32(25, 0, 128, 0));
} }
[Fact] [Fact]
@ -732,26 +731,26 @@ namespace SixLabors.ImageSharp.Tests.Colors
float y = -0.3f; float y = -0.3f;
float z = +0.5f; float z = +0.5f;
float w = -0.7f; float w = -0.7f;
Rgba32 rgba32 = new Rgba32(x, y, z, w); var rgba32 = new Rgba32(x, y, z, w);
Assert.Equal(0x80001Au, rgba32.PackedValue); Assert.Equal(0x80001Au, rgba32.PackedValue);
// Test ordering // Test ordering
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
rgba32.ToXyzBytes(rgb, 0); rgba32.ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 }); Assert.Equal(rgb, new Rgb24(0x1a, 0, 0x80));
rgba32.ToXyzwBytes(rgba, 0); rgba32.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 }); Assert.Equal(rgba, new Rgba32(0x1a, 0, 0x80, 0));
rgba32.ToZyxBytes(bgr, 0); rgba32.ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a }); Assert.Equal(bgr, new Bgr24(0x1a, 0, 0x80));
rgba32.ToZyxwBytes(bgra, 0); rgba32.ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 }); Assert.Equal(bgra, new Bgra32(0x1a, 0, 0x80, 0));
} }
[Fact] [Fact]
@ -779,27 +778,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
float w = 0.45f; float w = 0.45f;
Assert.Equal((ulong)0x73334CCC2666147B, new Rgba64(x, y, z, w).PackedValue); Assert.Equal((ulong)0x73334CCC2666147B, new Rgba64(x, y, z, w).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Rgba64(x, y, z, w).ToXyzBytes(rgb, 0); new Rgba64(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 20, 38, 76 }); Assert.Equal(rgb, new Rgb24(20, 38, 76));
new Rgba64(x, y, z, w).ToXyzwBytes(rgba, 0); new Rgba64(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 20, 38, 76, 115 }); Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));
new Rgba64(x, y, z, w).ToZyxBytes(bgr, 0); new Rgba64(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 76, 38, 20 }); Assert.Equal(bgr, new Bgr24(20, 38, 76));
new Rgba64(x, y, z, w).ToZyxwBytes(bgra, 0); new Rgba64(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 76, 38, 20, 115 }); Assert.Equal(bgra, new Bgra32(20, 38, 76, 115));
Rgba64 r = new Rgba64(); var r = new Rgba64();
r.PackFromRgba32(new Rgba32(20, 38, 76, 115)); r.PackFromRgba32(new Rgba32(20, 38, 76, 115));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 20, 38, 76, 115 }); Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));
} }
[Fact] [Fact]
@ -834,27 +833,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
y = -5.3f; y = -5.3f;
Assert.Equal(4294639744, new Short2(x, y).PackedValue); Assert.Equal(4294639744, new Short2(x, y).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Short2(x, y).ToXyzBytes(rgb, 0); new Short2(x, y).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 128, 127, 0 }); Assert.Equal(rgb, new Rgb24(128, 127, 0));
new Short2(x, y).ToXyzwBytes(rgba, 0); new Short2(x, y).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 128, 127, 0, 255 }); Assert.Equal(rgba, new Rgba32(128, 127, 0, 255));
new Short2(x, y).ToZyxBytes(bgr, 0); new Short2(x, y).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 0, 127, 128 }); Assert.Equal(bgr, new Bgr24(128, 127, 0));
new Short2(x, y).ToZyxwBytes(bgra, 0); new Short2(x, y).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 0, 127, 128, 255 }); Assert.Equal(bgra, new Bgra32(128, 127, 0, 255));
Short2 r = new Short2(); var r = new Short2();
r.PackFromRgba32(new Rgba32(20, 38, 0, 255)); r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 }); Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
} }
[Fact] [Fact]
@ -891,27 +890,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
w = 193; w = 193;
Assert.Equal((ulong)0x00c173b7316d2d1b, new Short4(x, y, z, w).PackedValue); Assert.Equal((ulong)0x00c173b7316d2d1b, new Short4(x, y, z, w).PackedValue);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
new Short4(x, y, z, w).ToXyzBytes(rgb, 0); new Short4(x, y, z, w).ToRgb24(ref rgb);
Assert.Equal(rgb, new byte[] { 172, 177, 243 }); Assert.Equal(rgb, new Rgb24(172, 177, 243));
new Short4(x, y, z, w).ToXyzwBytes(rgba, 0); new Short4(x, y, z, w).ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 172, 177, 243, 128 }); Assert.Equal(rgba, new Rgba32(172, 177, 243, 128));
new Short4(x, y, z, w).ToZyxBytes(bgr, 0); new Short4(x, y, z, w).ToBgr24(ref bgr);
Assert.Equal(bgr, new byte[] { 243, 177, 172 }); Assert.Equal(bgr, new Bgr24(172, 177, 243));
new Short4(x, y, z, w).ToZyxwBytes(bgra, 0); new Short4(x, y, z, w).ToBgra32(ref bgra);
Assert.Equal(bgra, new byte[] { 243, 177, 172, 128 }); Assert.Equal(bgra, new Bgra32(172, 177, 243, 128));
Short4 r = new Short4(); var r = new Short4();
r.PackFromRgba32(new Rgba32(20, 38, 0, 255)); r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
r.ToXyzwBytes(rgba, 0); r.ToRgba32(ref rgba);
Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 }); Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
} }
// Comparison helpers with small tolerance to allow for floating point rounding during computations. // Comparison helpers with small tolerance to allow for floating point rounding during computations.

23
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

@ -173,11 +173,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
TPixel[] source = CreatePixelTestData(count); TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 3]; byte[] expected = new byte[count * 3];
var rgb = default(Rgb24);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i3 = i * 3; int i3 = i * 3;
source[i].ToXyzBytes(expected, i3); source[i].ToRgb24(ref rgb);
expected[i3] = rgb.R;
expected[i3 + 1] = rgb.G;
expected[i3 + 2] = rgb.B;
} }
TestOperation( TestOperation(
@ -214,11 +218,16 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
TPixel[] source = CreatePixelTestData(count); TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 4]; byte[] expected = new byte[count * 4];
var rgba = default(Rgba32);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i4 = i * 4; int i4 = i * 4;
source[i].ToXyzwBytes(expected, i4); source[i].ToRgba32(ref rgba);
expected[i4] = rgba.R;
expected[i4 + 1] = rgba.G;
expected[i4 + 2] = rgba.B;
expected[i4 + 3] = rgba.A;
} }
TestOperation( TestOperation(
@ -255,11 +264,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
TPixel[] source = CreatePixelTestData(count); TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 3]; byte[] expected = new byte[count * 3];
var bgr = default(Bgr24);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i3 = i * 3; int i3 = i * 3;
source[i].ToZyxBytes(expected, i3); source[i].ToBgr24(ref bgr);
expected[i3] = bgr.B;
expected[i3 + 1] = bgr.G;
expected[i3 + 2] = bgr.R;
} }
TestOperation( TestOperation(
@ -296,11 +309,13 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
TPixel[] source = CreatePixelTestData(count); TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 4]; byte[] expected = new byte[count * 4];
var bgra = default(Bgra32);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i4 = i * 4; int i4 = i * 4;
source[i].ToZyxwBytes(expected, i4); source[i].ToBgra32(ref bgra);
expected[i4] = bgra.B;
} }
TestOperation( TestOperation(

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

@ -12,8 +12,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut() public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut() public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut()
{ {
Rgba32 color = new Rgba32(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); var color = new Rgba32(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
RgbaVector colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut() public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut()
{ {
Rgba32 color = new Rgba32(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); var color = new Rgba32(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
RgbaVector colorVector = new RgbaVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); var colorVector = new RgbaVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -48,8 +48,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut() public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut()
{ {
Rgba32 color = new Rgba32(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); var color = new Rgba32(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
RgbaVector colorVector = new RgbaVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); var colorVector = new RgbaVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -60,8 +60,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut() public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut()
{ {
Rgba32 color = Rgba32.FromHex("183060C0"); var color = Rgba32.FromHex("183060C0");
RgbaVector colorVector = RgbaVector.FromHex("183060C0"); var colorVector = RgbaVector.FromHex("183060C0");
Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255));
@ -72,8 +72,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_To_Vector4_Produce_Equal_OutPut() public void Color_Types_To_Vector4_Produce_Equal_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
Assert.Equal(color.ToVector4(), colorVector.ToVector4()); Assert.Equal(color.ToVector4(), colorVector.ToVector4());
} }
@ -81,14 +81,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_To_RgbBytes_Produce_Equal_OutPut() public void Color_Types_To_RgbBytes_Produce_Equal_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
byte[] rgb = new byte[3]; var rgb = default(Rgb24);
byte[] rgbVector = new byte[3]; var rgbVector = default(Rgb24);
color.ToXyzBytes(rgb, 0); color.ToRgb24(ref rgb);
colorVector.ToXyzBytes(rgbVector, 0); colorVector.ToRgb24(ref rgbVector);
Assert.Equal(rgb, rgbVector); Assert.Equal(rgb, rgbVector);
} }
@ -96,14 +96,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut() public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
byte[] rgba = new byte[4]; var rgba = default(Rgba32);
byte[] rgbaVector = new byte[4]; var rgbaVector = default(Rgba32);
color.ToXyzwBytes(rgba, 0); color.ToRgba32(ref rgba);
colorVector.ToXyzwBytes(rgbaVector, 0); colorVector.ToRgba32(ref rgbaVector);
Assert.Equal(rgba, rgbaVector); Assert.Equal(rgba, rgbaVector);
} }
@ -111,14 +111,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_To_BgrBytes_Produce_Equal_OutPut() public void Color_Types_To_BgrBytes_Produce_Equal_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
byte[] bgr = new byte[3]; var bgr = default(Bgr24);
byte[] bgrVector = new byte[3]; var bgrVector = default(Bgr24);
color.ToZyxBytes(bgr, 0); color.ToBgr24(ref bgr);
colorVector.ToZyxBytes(bgrVector, 0); colorVector.ToBgr24(ref bgrVector);
Assert.Equal(bgr, bgrVector); Assert.Equal(bgr, bgrVector);
} }
@ -126,14 +126,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_To_BgraBytes_Produce_Equal_OutPut() public void Color_Types_To_BgraBytes_Produce_Equal_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
byte[] bgra = new byte[4]; var bgra = default(Bgra32);
byte[] bgraVector = new byte[4]; var bgraVector = default(Bgra32);
color.ToZyxwBytes(bgra, 0); color.ToBgra32(ref bgra);
colorVector.ToZyxwBytes(bgraVector, 0); colorVector.ToBgra32(ref bgraVector);
Assert.Equal(bgra, bgraVector); Assert.Equal(bgra, bgraVector);
} }
@ -141,8 +141,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_To_Hex_Produce_Equal_OutPut() public void Color_Types_To_Hex_Produce_Equal_OutPut()
{ {
Rgba32 color = new Rgba32(24, 48, 96, 192); var color = new Rgba32(24, 48, 96, 192);
RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); var colorVector = new RgbaVector(24, 48, 96, 192);
// 183060C0 // 183060C0
Assert.Equal(color.ToHex(), colorVector.ToHex()); Assert.Equal(color.ToHex(), colorVector.ToHex());

10
tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs

@ -31,13 +31,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
image.Mutate(x => x.Grayscale(value)); image.Mutate(x => x.Grayscale(value));
byte[] data = new byte[3]; var rgb = default(Rgb24);
System.Span<TPixel> span = image.Frames.RootFrame.GetPixelSpan(); System.Span<TPixel> span = image.Frames.RootFrame.GetPixelSpan();
for (int i = 0; i < span.Length; i++) for (int i = 0; i < span.Length; i++)
{ {
span[i].ToXyzBytes(data, 0); span[i].ToRgb24(ref rgb);
Assert.Equal(data[0], data[1]); Assert.Equal(rgb.R, rgb.B);
Assert.Equal(data[1], data[2]); Assert.Equal(rgb.B, rgb.G);
} }
image.DebugSave(provider, value.ToString()); image.DebugSave(provider, value.ToString());
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> source = provider.GetImage()) using (Image<TPixel> source = provider.GetImage())
using (var image = source.Clone()) using (Image<TPixel> image = source.Clone())
{ {
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Mutate(x => x.Grayscale(value, bounds)); image.Mutate(x => x.Grayscale(value, bounds));

16
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -54,8 +54,8 @@ namespace SixLabors.ImageSharp.Tests
return false; return false;
} }
byte[] bytesA = new byte[3]; var rgb1 = default(Rgb24);
byte[] bytesB = new byte[3]; var rgb2 = default(Rgb24);
using (PixelAccessor<TPixel> pixA = a.Lock()) using (PixelAccessor<TPixel> pixA = a.Lock())
{ {
@ -77,12 +77,12 @@ namespace SixLabors.ImageSharp.Tests
} }
else else
{ {
ca.ToXyzBytes(bytesA, 0); ca.ToRgb24(ref rgb1);
cb.ToXyzBytes(bytesB, 0); cb.ToRgb24(ref rgb2);
if (bytesA[0] != bytesB[0] || if (rgb1.R != rgb2.R ||
bytesA[1] != bytesB[1] || rgb1.G != rgb2.G ||
bytesA[2] != bytesB[2]) rgb1.B != rgb2.B)
{ {
return false; return false;
} }
@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests
/// <returns></returns> /// <returns></returns>
public static PixelTypes GetPixelType(this Type colorStructClrType) => ClrTypes2PixelTypes[colorStructClrType]; public static PixelTypes GetPixelType(this Type colorStructClrType) => ClrTypes2PixelTypes[colorStructClrType];
public static IEnumerable<KeyValuePair<PixelTypes, Type>> ExpandAllTypes(this PixelTypes pixelTypes) public static IEnumerable<KeyValuePair<PixelTypes, Type>> ExpandAllTypes(this PixelTypes pixelTypes)
{ {

20
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
Assert.Equal(expected, provider.PixelType); Assert.Equal(expected, provider.PixelType);
} }
[Theory] [Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)] [WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)]
[WithFile(TestImages.Bmp.F, PixelTypes.All, 88)] [WithFile(TestImages.Bmp.F, PixelTypes.All, 88)]
@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Tests
} }
internal static int GetInvocationCount(string callerName) => invocationCounts[callerName]; internal static int GetInvocationCount(string callerName) => invocationCounts[callerName];
private static readonly object Monitor = new object(); private static readonly object Monitor = new object();
public static void DoTestThreadSafe(Action action) public static void DoTestThreadSafe(Action action)
@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Tests
} }
internal static int GetInvocationCount(string callerName) => invocationCounts[callerName]; internal static int GetInvocationCount(string callerName) => invocationCounts[callerName];
private static readonly object Monitor = new object(); private static readonly object Monitor = new object();
public static void DoTestThreadSafe(Action action) public static void DoTestThreadSafe(Action action)
@ -234,7 +234,7 @@ namespace SixLabors.ImageSharp.Tests
Image<TPixel> image = provider.GetImage(); Image<TPixel> image = provider.GetImage();
provider.Utility.SaveTestOutputFile(image, "png"); provider.Utility.SaveTestOutputFile(image, "png");
} }
[Theory] [Theory]
[WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Rgba32 | PixelTypes.Argb32)] [WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Rgba32 | PixelTypes.Argb32)]
public void Use_WithSolidFilledImagesAttribute<TPixel>(TestImageProvider<TPixel> provider) public void Use_WithSolidFilledImagesAttribute<TPixel>(TestImageProvider<TPixel> provider)
@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.Tests
Assert.Equal(10, img.Width); Assert.Equal(10, img.Width);
Assert.Equal(20, img.Height); Assert.Equal(20, img.Height);
byte[] colors = new byte[4]; var rgba = default(Rgba32);
using (PixelAccessor<TPixel> pixels = img.Lock()) using (PixelAccessor<TPixel> pixels = img.Lock())
{ {
@ -252,12 +252,12 @@ namespace SixLabors.ImageSharp.Tests
{ {
for (int x = 0; x < pixels.Width; x++) for (int x = 0; x < pixels.Width; x++)
{ {
pixels[x, y].ToXyzwBytes(colors, 0); pixels[x, y].ToRgba32(ref rgba);
Assert.Equal(255, colors[0]); Assert.Equal(255, rgba.R);
Assert.Equal(100, colors[1]); Assert.Equal(100, rgba.G);
Assert.Equal(50, colors[2]); Assert.Equal(50, rgba.B);
Assert.Equal(200, colors[3]); Assert.Equal(200, rgba.A);
} }
} }
} }

Loading…
Cancel
Save