Esempio n. 1
0
        public static List <Chunk> CompressIDATs(byte[] cipheredBytes)
        {
            byte[]       compressedBytes = ZlibCompression.Compress(cipheredBytes);
            List <Chunk> resultIdats     = IDATConverter.SplitToIDATs(compressedBytes).Select(idat => (Chunk)idat).ToList();

            return(resultIdats);
        }
Esempio n. 2
0
        public void ShouldSplitToOneIDAT()
        {
            byte[]      bytes  = { 1, 3, 5 };
            List <IDAT> result = IDATConverter.SplitToIDATs(bytes);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(bytes, result[0].Data);
        }
Esempio n. 3
0
        public void ShouldSplitToThreeIDATsWithOneShorter()
        {
            byte[]      bytes  = CreateByteRange(0, short.MaxValue * 2 + 1);
            List <IDAT> result = IDATConverter.SplitToIDATs(bytes);

            Assert.AreEqual(3, result.Count);
            byte[] expectedFirstChunkData  = CreateByteRange(0, short.MaxValue);
            byte[] expectedSecondChunkData = CreateByteRange(short.MaxValue, short.MaxValue);
            byte[] expectedThirdChunkData  = CreateByteRange(short.MaxValue * 2, 1);
            Assert.AreEqual(expectedFirstChunkData, result[0].Data);
            Assert.AreEqual(expectedSecondChunkData, result[1].Data);
            Assert.AreEqual(expectedThirdChunkData, result[2].Data);
        }
Esempio n. 4
0
        public void ShouldConcatAndThenSplitImage()
        {
            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);
            List <Chunk> resultIdats  = IDATConverter.SplitToIDATs(bytes).Select(idat => (Chunk)idat).ToList();
            List <Chunk> resultChunks = parsedChunks.Where(chunk => !IsIDAT(chunk)).ToList();

            resultChunks.InsertRange(firstIdatIndex, resultIdats);
            PNGFile.Write(@"../../../Data/lenaConverted.png", resultChunks);
        }