public void Test_Bgr555()
        {
            string[] hexValues = new[] { "7C00", "3E0", "1F" };
            for (int i = 0; i < 3; i++)
            {
                int x = i == 0 ? 1 : 0;
                int y = i == 1 ? 1 : 0;
                int z = i == 2 ? 1 : 0;

                var testPixel = new Bgr555(x, y, z);

                Assert.Equal($"Bgr555({z}, {y}, {x})", testPixel.ToString());

                var destPixel = new ImageSharp.PixelFormats.Rgba32(0);
                testPixel.ToRgba32(ref destPixel);

                Assert.Equal(hexValues[i], testPixel.PackedValue.ToString("X"));

                Assert.Equal(i == 0 ? 255 : 0, destPixel.R);
                Assert.Equal(i == 1 ? 255 : 0, destPixel.G);
                Assert.Equal(i == 2 ? 255 : 0, destPixel.B);
                Assert.Equal(255, destPixel.A);

                var vector4 = testPixel.ToVector4();
                testPixel.FromVector4(vector4);
                Assert.Equal(testPixel.ToVector4(), vector4);
            }
        }
Пример #2
0
        /// <summary>
        /// Reads a compressed palette from the stream.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException">the decompressed bytes were not the correct size (32 or 512).</exception>
        public Palette ReadCompressedPalette()
        {
            var buffer = ReadCompressedBytes();

            var palette = new Palette(Bgr555.Black, buffer.Length / 2);

            for (int i = 0; i < palette.Length; i++)
            {
                palette[i] = new Bgr555((ushort)((buffer[i * 2 + 1] << 8) | buffer[i * 2]));
            }

            return(palette);
        }
Пример #3
0
 public void WriteColor(Bgr555 color)
 {
     WriteUInt16(color.ToUInt16());
 }