예제 #1
0
        public static byte[] DecompressIDATs(List <Chunk> chunks)
        {
            List <IDAT> idats = chunks.Where(IsIDAT).Select(chunk => (IDAT)chunk).ToList();

            byte[] bytes             = IDATConverter.ConcatToBytes(idats);
            byte[] decompressedBytes = ZlibCompression.Decompress(bytes);
            return(decompressedBytes);
        }
예제 #2
0
        public void ShouldConcatDecompressCompressAndThenSplitImage()
        {
            string       filePath       = @"../../../Data/lena.png";
            List <Chunk> chunks         = PNGFile.Read(filePath);
            List <Chunk> parsedChunks   = ChunkParser.Parse(chunks);
            int          firstIdatIndex = parsedChunks.TakeWhile(chunk => !IsIDAT(chunk)).Count();
            List <IDAT>  idats          = parsedChunks.Where(IsIDAT).Select(chunk => (IDAT)chunk).ToList();

            byte[]       bytes             = IDATConverter.ConcatToBytes(idats);
            byte[]       decompressedBytes = ZlibCompression.Decompress(bytes);
            byte[]       compressedBytes   = ZlibCompression.Compress(decompressedBytes);
            List <Chunk> resultIdats       = IDATConverter.SplitToIDATs(compressedBytes).Select(idat => (Chunk)idat).ToList();
            List <Chunk> resultChunks      = parsedChunks.Where(chunk => !IsIDAT(chunk)).ToList();

            resultChunks.InsertRange(firstIdatIndex, resultIdats);
            PNGFile.Write(@"../../../Data/lenaCompressed.png", resultChunks);
        }
예제 #3
0
 private static void CompressAndDecompress(byte[] bytes)
 {
     byte[] compressed   = ZlibCompression.Compress(bytes);
     byte[] decompressed = ZlibCompression.Decompress(compressed);
     Assert.AreEqual(bytes, decompressed);
 }