public void NormalizedByte4() { // Test PackedValue Assert.Equal((uint)0x0, new NormalizedByte4(Vector4.Zero).PackedValue); Assert.Equal((uint)0x7F7F7F7F, new NormalizedByte4(Vector4.One).PackedValue); Assert.Equal(0x81818181, new NormalizedByte4(-Vector4.One).PackedValue); // Test ToVector4 Assert.True(Equal(Vector4.One, new NormalizedByte4(Vector4.One).ToVector4())); Assert.True(Equal(Vector4.Zero, new NormalizedByte4(Vector4.Zero).ToVector4())); Assert.True(Equal(-Vector4.One, new NormalizedByte4(-Vector4.One).ToVector4())); Assert.True(Equal(Vector4.One, new NormalizedByte4(Vector4.One * 1234.0f).ToVector4())); Assert.True(Equal(-Vector4.One, new NormalizedByte4(Vector4.One * -1234.0f).ToVector4())); // Test Ordering float x = 0.1f; float y = -0.3f; float z = 0.5f; float w = -0.7f; Assert.Equal(0xA740DA0D, new NormalizedByte4(x, y, z, w).PackedValue); NormalizedByte4 n = new NormalizedByte4(); n.PackFromRgba32(new Rgba32(141, 90, 192, 39)); Assert.Equal(0xA740DA0D, n.PackedValue); Assert.Equal((uint)958796544, new NormalizedByte4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue); byte[] rgb = new byte[3]; byte[] rgba = new byte[4]; byte[] bgr = new byte[3]; byte[] bgra = new byte[4]; new NormalizedByte4(x, y, z, w).ToXyzBytes(rgb, 0); Assert.Equal(rgb, new byte[] { 141, 90, 192 }); new NormalizedByte4(x, y, z, w).ToXyzwBytes(rgba, 0); Assert.Equal(rgba, new byte[] { 141, 90, 192, 39 }); new NormalizedByte4(x, y, z, w).ToZyxBytes(bgr, 0); Assert.Equal(bgr, new byte[] { 192, 90, 141 }); new NormalizedByte4(x, y, z, w).ToZyxwBytes(bgra, 0); Assert.Equal(bgra, new byte[] { 192, 90, 141, 39 }); // http://community.monogame.net/t/normalizedbyte4-texture2d-gives-different-results-from-xna/8012/8 NormalizedByte4 r = new NormalizedByte4(); r.PackFromRgba32(new Rgba32(9, 115, 202, 127)); r.ToXyzwBytes(rgba, 0); Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 }); r.PackedValue = 0xff4af389; r.ToXyzwBytes(rgba, 0); Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 }); }
public void NormalizedByte4() { // Test PackedValue Assert.Equal((uint)0x0, new NormalizedByte4(Vector4.Zero).PackedValue); Assert.Equal((uint)0x7F7F7F7F, new NormalizedByte4(Vector4.One).PackedValue); Assert.Equal(0x81818181, new NormalizedByte4(-Vector4.One).PackedValue); // Test ToVector4 Assert.True(Equal(Vector4.One, new NormalizedByte4(Vector4.One).ToVector4())); Assert.True(Equal(Vector4.Zero, new NormalizedByte4(Vector4.Zero).ToVector4())); Assert.True(Equal(-Vector4.One, new NormalizedByte4(-Vector4.One).ToVector4())); Assert.True(Equal(Vector4.One, new NormalizedByte4(Vector4.One * 1234.0f).ToVector4())); Assert.True(Equal(-Vector4.One, new NormalizedByte4(Vector4.One * -1234.0f).ToVector4())); // Test Ordering float x = 0.1f; float y = -0.3f; float z = 0.5f; float w = -0.7f; Assert.Equal(0xA740DA0D, new NormalizedByte4(x, y, z, w).PackedValue); var n = new NormalizedByte4(); n.PackFromRgba32(new Rgba32(141, 90, 192, 39)); Assert.Equal(0xA740DA0D, n.PackedValue); Assert.Equal((uint)958796544, new NormalizedByte4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue); var rgb = default(Rgb24); var rgba = default(Rgba32); var bgr = default(Bgr24); var bgra = default(Bgra32); new NormalizedByte4(x, y, z, w).ToRgb24(ref rgb); Assert.Equal(rgb, new Rgb24(141, 90, 192)); new NormalizedByte4(x, y, z, w).ToRgba32(ref rgba); Assert.Equal(rgba, new Rgba32(141, 90, 192, 39)); new NormalizedByte4(x, y, z, w).ToBgr24(ref bgr); Assert.Equal(bgr, new Bgr24(141, 90, 192)); new NormalizedByte4(x, y, z, w).ToBgra32(ref bgra); Assert.Equal(bgra, new Bgra32(141, 90, 192, 39)); // http://community.monogame.net/t/normalizedbyte4-texture2d-gives-different-results-from-xna/8012/8 var r = new NormalizedByte4(); r.PackFromRgba32(new Rgba32(9, 115, 202, 127)); r.ToRgba32(ref rgba); Assert.Equal(rgba, new Rgba32(9, 115, 202, 127)); r.PackedValue = 0xff4af389; r.ToRgba32(ref rgba); Assert.Equal(rgba, new Rgba32(9, 115, 202, 127)); }