Exemple #1
0
        public void Color_Types_To_BgrBytes_Produce_Equal_OutPut()
        {
            Rgba32     color       = new Rgba32(24, 48, 96, 192);
            RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);

            byte[] bgr       = new byte[3];
            byte[] bgrVector = new byte[3];

            color.ToZyxBytes(bgr, 0);
            colorVector.ToZyxBytes(bgrVector, 0);

            Assert.Equal(bgr, bgrVector);
        }
Exemple #2
0
        public void Color()
        {
            // Test the limits.
            Assert.Equal((uint)0x0, new Rgba32(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFF, new Rgba32(Vector4.One).PackedValue);

            // Test ToVector4.
            Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One).ToVector4()));
            Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.Zero).ToVector4()));
            Assert.True(Equal(Vector4.UnitX, new Rgba32(Vector4.UnitX).ToVector4()));
            Assert.True(Equal(Vector4.UnitY, new Rgba32(Vector4.UnitY).ToVector4()));
            Assert.True(Equal(Vector4.UnitZ, new Rgba32(Vector4.UnitZ).ToVector4()));
            Assert.True(Equal(Vector4.UnitW, new Rgba32(Vector4.UnitW).ToVector4()));

            // Test clamping.
            Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.One * -1234.0f).ToVector4()));
            Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One * +1234.0f).ToVector4()));

            float  x      = +0.1f;
            float  y      = -0.3f;
            float  z      = +0.5f;
            float  w      = -0.7f;
            Rgba32 rgba32 = new Rgba32(x, y, z, w);

            Assert.Equal(0x80001Au, rgba32.PackedValue);

            // Test ordering
            byte[] rgb  = new byte[3];
            byte[] rgba = new byte[4];
            byte[] bgr  = new byte[3];
            byte[] bgra = new byte[4];

            rgba32.ToXyzBytes(rgb, 0);
            Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 });

            rgba32.ToXyzwBytes(rgba, 0);
            Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 });

            rgba32.ToZyxBytes(bgr, 0);
            Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a });

            rgba32.ToZyxwBytes(bgra, 0);
            Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 });
        }