예제 #1
0
        public void Rgba32()
        {
            // 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 ToScaledVector4.
            Vector4 scaled = new Rgba32(Vector4.One).ToScaledVector4();

            Assert.Equal(1, scaled.X);
            Assert.Equal(1, scaled.Y);
            Assert.Equal(1, scaled.Z);
            Assert.Equal(1, scaled.W);

            // Test PackFromScaledVector4.
            var pixel = default(Rgba32);

            pixel.PackFromScaledVector4(scaled);
            Assert.Equal(0xFFFFFFFF, pixel.PackedValue);

            // 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;
            var   rgba32 = new Rgba32(x, y, z, w);

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

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

            rgba32.ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(0x1a, 0, 0x80));

            rgba32.ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(0x1a, 0, 0x80, 0));

            rgba32.ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(0x1a, 0, 0x80));

            rgba32.ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(0x1a, 0, 0x80, 0));
        }
예제 #2
0
        public void Color_Types_To_BgraBytes_Produce_Equal_OutPut()
        {
            var color       = new Rgba32(24, 48, 96, 192);
            var colorVector = new RgbaVector(24, 48, 96, 192);

            var bgra       = default(Bgra32);
            var bgraVector = default(Bgra32);

            color.ToBgra32(ref bgra);
            colorVector.ToBgra32(ref bgraVector);

            Assert.Equal(bgra, bgraVector);
        }
예제 #3
0
        public void Rgba32_ToBgra32()
        {
            // arrange
            var rgba     = new Rgba32(+0.1f, -0.3f, +0.5f, -0.7f);
            var actual   = default(Bgra32);
            var expected = new Bgra32(0x1a, 0, 0x80, 0);

            // act
            rgba.ToBgra32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }