Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
 private static void CompressAndDecompress(byte[] bytes)
 {
     byte[] compressed   = ZlibCompression.Compress(bytes);
     byte[] decompressed = ZlibCompression.Decompress(compressed);
     Assert.AreEqual(bytes, decompressed);
 }