コード例 #1
0
        public void Rgba1010102_ToRgba32()
        {
            // arrange
            var rgba     = new Rgba1010102(0.1f, -0.3f, 0.5f, -0.7f);
            var actual   = default(Rgba32);
            var expected = new Rgba32(25, 0, 128, 0);

            // act
            rgba.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
コード例 #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));
        }