Example #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);
        }
Example #2
0
        public void EncodeOneBlockPureWhiteRGBThenDecodeIt()
        {
            // Arrange
            const int width            = 4;  // One block is 4x4
            const int height           = 4;
            const int channelsPerPixel = 3;

            byte[] whiteRGB = new byte[] { 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 } },
            };
            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(8, encodedBytes.Length);

            Assert.AreEqual(width, decoded.GetWidth());
            Assert.AreEqual(height, decoded.GetHeight());
            Assert.AreEqual(channelsPerPixel, decoded.GetChannelsPerPixel());
            CollectionAssert.AreEqual(whiteRGB, firstPixel);
        }
Example #3
0
        public void EncodeRBGWhiteBlock()
        {
            // Arrange
            byte[] expected = new byte[8] {
                0, 0, 0, 0, 254, 255, 255, 255
            };

            const int width            = 4;  // One block is 4x4
            const int height           = 4;
            const int channelsPerPixel = 3;

            byte[] whiteRGB = new byte[] { 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 } },
            };
            TempByteImageFormat image = new TempByteImageFormat(pixels);

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

            // Assert
            Assert.AreEqual(8, encodedBytes.Length);
            CollectionAssert.AreEqual(expected, encodedBytes);
        }
Example #4
0
    private static IEnumerator _Compress24(Texture2D tex, SignalEnumerator <Texture2D> signal)
    {
        var width         = tex.width;
        var height        = tex.height;
        var resultTexture = new Texture2D(width, height, TextureFormat.PVRTC_RGB4, false, true);

        byte[]  compressed = null;
        Color[] pixels     = tex.GetPixels();

        yield return(new AsyncExecutor <object>(x =>
        {
            PvrtcCompress compressor = new PvrtcCompress();
            compressed = compressor.EncodeRgb4Bpp(pixels, width, height);
        }));

        resultTexture.LoadRawTextureData(compressed);
        resultTexture.Apply();

        signal.Notify(resultTexture);
    }