Beispiel #1
0
        public void Rgba1010102()
        {
            // Test the limits.
            Assert.Equal((uint)0x0, new Rgba1010102(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFF, new Rgba1010102(Vector4.One).PackedValue);

            // Test ToVector4
            Assert.True(Equal(Vector4.Zero, new Rgba1010102(Vector4.Zero).ToVector4()));
            Assert.True(Equal(Vector4.One, new Rgba1010102(Vector4.One).ToVector4()));

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

            // Test Ordering
            float x = 0x2db;
            float y = 0x36d;
            float z = 0x3b7;
            float w = 0x1;

            Assert.Equal((uint)0x7B7DB6DB, new Rgba1010102(x / 0x3ff, y / 0x3ff, z / 0x3ff, w / 3).PackedValue);
            x = 0.1f;
            y = -0.3f;
            z = 0.5f;
            w = -0.7f;
            Assert.Equal((uint)536871014, new Rgba1010102(x, y, z, w).PackedValue);

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

            new Rgba1010102(x, y, z, w).ToXyzBytes(rgb, 0);
            Assert.Equal(rgb, new byte[] { 25, 0, 128 });

            new Rgba1010102(x, y, z, w).ToXyzwBytes(rgba, 0);
            Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 });

            new Rgba1010102(x, y, z, w).ToZyxBytes(bgr, 0);
            Assert.Equal(bgr, new byte[] { 128, 0, 25 });

            new Rgba1010102(x, y, z, w).ToZyxwBytes(bgra, 0);
            Assert.Equal(bgra, new byte[] { 128, 0, 25, 0 });

            // Alpha component accuracy will be awful.
            Rgba1010102 r = new Rgba1010102();

            r.PackFromRgba32(new Rgba32(25, 0, 128, 0));
            r.ToXyzwBytes(rgba, 0);
            Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 });
        }
Beispiel #2
0
        public void Rgba1010102()
        {
            // Test the limits.
            Assert.Equal((uint)0x0, new Rgba1010102(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFF, new Rgba1010102(Vector4.One).PackedValue);

            // Test ToVector4
            Assert.True(Equal(Vector4.Zero, new Rgba1010102(Vector4.Zero).ToVector4()));
            Assert.True(Equal(Vector4.One, new Rgba1010102(Vector4.One).ToVector4()));

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

            // Test Ordering
            float x = 0x2db;
            float y = 0x36d;
            float z = 0x3b7;
            float w = 0x1;

            Assert.Equal((uint)0x7B7DB6DB, new Rgba1010102(x / 0x3ff, y / 0x3ff, z / 0x3ff, w / 3).PackedValue);
            x = 0.1f;
            y = -0.3f;
            z = 0.5f;
            w = -0.7f;
            Assert.Equal((uint)536871014, new Rgba1010102(x, y, z, w).PackedValue);

            var rgb  = default(Rgb24);
            var rgba = default(Rgba32);
            var bgr  = default(Bgr24);
            var bgra = default(Bgra32);

            new Rgba1010102(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(25, 0, 128));

            new Rgba1010102(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(25, 0, 128, 0));

            new Rgba1010102(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(25, 0, 128));

            new Rgba1010102(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(25, 0, 128, 0));

            // Alpha component accuracy will be awful.
            var r = new Rgba1010102();

            r.PackFromRgba32(new Rgba32(25, 0, 128, 0));
            r.ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(25, 0, 128, 0));
        }