Ejemplo n.º 1
0
        public void ToRgba32_Retval()
        {
            // arrange
            var source   = new Rgba64(5140, 9766, 19532, 29555);
            var expected = new Rgba32(20, 38, 76, 115);

            // act
            var actual = source.ToRgba32();

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public void Rgba64_ToRgba32()
        {
            // arrange
            var rgba64   = new Rgba64(5140, 9766, 19532, 29555);
            var actual   = default(Rgba32);
            var expected = new Rgba32(20, 38, 76, 115);

            // act
            rgba64.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public void Rgba64_ToRgba32()
        {
            // arrange
            var rgba64   = new Rgba64(0.08f, 0.15f, 0.30f, 0.45f);
            var actual   = default(Rgba32);
            var expected = new Rgba32(20, 38, 76, 115);

            // act
            rgba64.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        public void Rgba64()
        {
            // Test the limits.
            Assert.Equal((ulong)0x0, new Rgba64(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFFFFFFFFFF, new Rgba64(Vector4.One).PackedValue);

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

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

            // Test data ordering
            Assert.Equal(0xC7AD8F5C570A1EB8, new Rgba64(((float)0x1EB8) / 0xffff, ((float)0x570A) / 0xffff, ((float)0x8F5C) / 0xffff, ((float)0xC7AD) / 0xffff).PackedValue);
            Assert.Equal(0xC7AD8F5C570A1EB8, new Rgba64(0.12f, 0.34f, 0.56f, 0.78f).PackedValue);

            float x = 0.08f;
            float y = 0.15f;
            float z = 0.30f;
            float w = 0.45f;

            Assert.Equal((ulong)0x73334CCC2666147B, new Rgba64(x, y, z, w).PackedValue);

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

            new Rgba64(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(20, 38, 76));

            new Rgba64(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));

            new Rgba64(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(20, 38, 76));

            new Rgba64(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(20, 38, 76, 115));

            var r = new Rgba64();

            r.PackFromRgba32(new Rgba32(20, 38, 76, 115));
            r.ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));
        }
Ejemplo n.º 5
0
        public void Rgba64()
        {
            if (!TestEnvironment.Is64BitProcess)
            {
                // Can't decide if these assertions are robust enough to be portable across CPU architectures.
                // Let's just skip it for 32 bits!
                // TODO: Someone should review this!
                return;
            }

            // Test the limits.
            Assert.Equal((ulong)0x0, new Rgba64(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFFFFFFFFFF, new Rgba64(Vector4.One).PackedValue);

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

            // Test ToScaledVector4.
            Vector4 scaled = new Rgba64(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(Rgba64);

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

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

            // Test data ordering
            Assert.Equal(0xC7AD8F5C570A1EB8, new Rgba64(((float)0x1EB8) / 0xffff, ((float)0x570A) / 0xffff, ((float)0x8F5C) / 0xffff, ((float)0xC7AD) / 0xffff).PackedValue);
            Assert.Equal(0xC7AD8F5C570A1EB8, new Rgba64(0.12f, 0.34f, 0.56f, 0.78f).PackedValue);

            float x = 0.08f;
            float y = 0.15f;
            float z = 0.30f;
            float w = 0.45f;

            Assert.Equal((ulong)0x73334CCC2666147B, new Rgba64(x, y, z, w).PackedValue);

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

            new Rgba64(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(20, 38, 76));

            new Rgba64(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));

            new Rgba64(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(20, 38, 76));

            new Rgba64(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(20, 38, 76, 115));

            var r = new Rgba64();

            r.PackFromRgba32(new Rgba32(20, 38, 76, 115));
            r.ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));
        }