Пример #1
0
        public void EncodeFourBlocksPureBlackRGBThenDecodeIt()
        {
            // Arrange
            const int width            = 8;  // One block is 4x4, so 8x8 is 4 blocks
            const int height           = 8;
            const int channelsPerPixel = 3;

            byte[] blackRGB = new byte[] { 0, 0, 0 };
            byte[,,] pixels = new byte[width, height, channelsPerPixel] {
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
                { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
            };
            TempByteImageFormat image = new TempByteImageFormat(pixels);

            // Act
            byte[] encodedBytes = PvrtcCompress.EncodeRgb4Bpp(image);

            TempByteImageFormat decoded = PvrtcDecompress.DecodeRgb4Bpp(encodedBytes, width);

            byte[] firstPixel = decoded.GetPixelChannels(0, 0);

            // Assert
            Assert.AreEqual(32, encodedBytes.Length);

            Assert.AreEqual(width, decoded.GetWidth());
            Assert.AreEqual(height, decoded.GetHeight());
            Assert.AreEqual(channelsPerPixel, decoded.GetChannelsPerPixel());
            CollectionAssert.AreEqual(blackRGB, firstPixel);
        }
Пример #2
0
        public void EncodeOneBlockPureWhiteRGBAThenDecodeIt()
        {
            // Arrange
            const int width            = 4;  // One block is 4x4
            const int height           = 4;
            const int channelsPerPixel = 4;

            byte[] whiteRGBA = new byte[] { 255, 255, 255, 255 };
            byte[,,] pixels = new byte[width, height, channelsPerPixel] {
                { { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 } },
                { { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 } },
                { { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 } },
                { { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 } },
            };
            TempByteImageFormat image = new TempByteImageFormat(pixels);

            // Act
            byte[] encodedBytes = PvrtcCompress.EncodeRgba4Bpp(image);

            TempByteImageFormat decoded = PvrtcDecompress.DecodeRgba4Bpp(encodedBytes, width);

            byte[] firstPixel = decoded.GetPixelChannels(0, 0);

            // Assert
            Assert.AreEqual(8, encodedBytes.Length);

            Assert.AreEqual(width, decoded.GetWidth());
            Assert.AreEqual(height, decoded.GetHeight());
            Assert.AreEqual(channelsPerPixel, decoded.GetChannelsPerPixel());
            CollectionAssert.AreEqual(whiteRGBA, firstPixel);
        }
        public void IndexingTest()
        {
            // Arrange
            FileStream pngStream = new FileStream("half.png", FileMode.Open, FileAccess.Read);

            int[] indexes = new int[] { 0, 1, 12, 37, 56, 132, 200 };

            // Act
            var image = new Bitmap(pngStream);

            TempByteImageFormat test3d = new TempByteImageFormat(ReadTo3DBytes(image));
            TempByteImageFormat test1d = new TempByteImageFormat(ReadTo1DBytes(image), image.Width, image.Height, 3);

            // Assert
            for (int x = 0; x < indexes.Length; x++)
            {
                for (int y = 0; y < indexes.Length; y++)
                {
                    byte[] pixel3d = test3d.GetPixelChannels(x, y);
                    byte[] pixel1d = test1d.GetPixelChannels(x, y);

                    CollectionAssert.AreEqual(pixel3d, pixel1d, $"Pixels at {x} x {y} should be equal");
                }
            }
        }
Пример #4
0
        public void DecodeRGBTextureFromByteArray()
        {
            // Arrange
            byte[] input = new byte[8] {
                0, 0, 0, 0, 254, 255, 255, 255
            };
            int width = 4;

            byte[] whiteRGB = new byte[] { 255, 255, 255 };

            // Act
            TempByteImageFormat temp = PvrtcDecompress.DecodeRgb4Bpp(input, width);

            byte[] firstPixel = temp.GetPixelChannels(0, 0);

            // Assert
            CollectionAssert.AreEqual(whiteRGB, firstPixel);
        }
        public void LoadTest1d()
        {
            // Arrange
            FileStream pngStream = new FileStream("half.png", FileMode.Open, FileAccess.Read);

            // Act
            var   image      = new Bitmap(pngStream);
            Color firstColor = image.GetPixel(0, 0);

            TempByteImageFormat test = new TempByteImageFormat(ReadTo1DBytes(image), image.Width, image.Height, 3);

            byte[] firstPixel = test.GetPixelChannels(0, 0);

            // Assert
            Assert.AreEqual(firstColor.R, firstPixel[0]);
            Assert.AreEqual(firstColor.G, firstPixel[1]);
            Assert.AreEqual(firstColor.B, firstPixel[2]);
        }
        public void CheckThat1dCopyWorks()
        {
            // Arrange
            FileStream pngStream = new FileStream("half.png", FileMode.Open, FileAccess.Read);

            // Act
            var image = new Bitmap(pngStream);

            byte[] bytes1d = ReadTo1DBytes(image);
            TempByteImageFormat test1d_1 = new TempByteImageFormat(bytes1d, image.Width, image.Height, 3, createCopy: false);
            TempByteImageFormat test1d_2 = new TempByteImageFormat(bytes1d, image.Width, image.Height, 3, createCopy: true);

            bytes1d[0] = 0;

            byte[] firstPixel1 = test1d_1.GetPixelChannels(0, 0);
            byte[] firstPixel2 = test1d_2.GetPixelChannels(0, 0);

            // Assert
            Assert.AreEqual(0, firstPixel1[0]);
            Assert.AreNotEqual(0, firstPixel2[0]);
        }