public void TestMultipleIDATChunksAreTreatedAsASingleDeflatedBuffer() { byte[] originalData = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xA0 }; byte[] deflateOriginalData = DeflateBytes(originalData); int splitAtIndex = 4; byte[] chunk1Data = deflateOriginalData.Take(splitAtIndex).ToArray(); byte[] chunk2Data = deflateOriginalData.Skip(splitAtIndex).ToArray(); List <PNGChunk> chunks = new List <PNGChunk>() { new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.CgBI), new byte[] { }, 0), new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.IDAT), chunk1Data, 0), new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.IDAT), chunk2Data, 0) }; IEnumerable <PNGChunk> decrushedChunks = PNGDecrusher.DecrushChunks(chunks); byte[] zlibChunk1 = decrushedChunks.First().Data; byte[] zlibChunk2 = decrushedChunks.Last().Data; byte[] zlibChunksCombined = new byte[zlibChunk1.Length + zlibChunk2.Length]; zlibChunk1.CopyTo(zlibChunksCombined, 0); zlibChunk2.CopyTo(zlibChunksCombined, zlibChunk1.Length); byte[] dezlibbedData = DecompressZlibBytes(zlibChunksCombined); Assert.AreEqual(originalData.Length, dezlibbedData.Length); CollectionAssert.AreEqual(originalData, dezlibbedData); }
public void TestAppleChunkIsRemovedWhenDecrushing() { IEnumerable <PNGChunk> chunks = new List <PNGChunk>() { new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.CgBI), new byte[] { 0x01, 0x02, 0x03 }, 12345), new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.IDAT), DeflateBytes(new byte[] { 0x01, 0x02, 0x03 }), 12345), new PNGChunk("IEND", new byte[] { }, 0xFFFFFF) }; IEnumerable <PNGChunk> fixedChunks = PNGDecrusher.DecrushChunks(chunks); Assert.AreEqual(2, fixedChunks.Count()); Assert.AreEqual(PNGChunk.ChunkType.IDAT, fixedChunks.ToArray()[0].Type); Assert.AreEqual("IEND", fixedChunks.ToArray()[1].TypeString); }
public void TestDecrushedIDATDataIsSameAsOriginalAfterDecompressing() { byte[] originalData = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; byte[] deflatedOriginalData = DeflateBytes(originalData); List <PNGChunk> chunks = new List <PNGChunk>() { new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.CgBI), new byte[] { }, 0), new PNGChunk(PNGChunk.StringFromType(PNGChunk.ChunkType.IDAT), deflatedOriginalData, 0) }; IEnumerable <PNGChunk> decrushedChunks = PNGDecrusher.DecrushChunks(chunks); Assert.AreEqual(1, decrushedChunks.Count()); byte[] zlibData = decrushedChunks.First().Data; byte[] dezlibbedData = DecompressZlibBytes(zlibData); Assert.AreEqual(originalData.Length, dezlibbedData.Length); CollectionAssert.AreEqual(originalData, dezlibbedData); }
private static PNGChunk IDATChunkWithBytes(byte[] bytes) { string type = PNGChunk.StringFromType(PNGChunk.ChunkType.IDAT); return(new PNGChunk(type, bytes, CalculateCRCForChunk(type, bytes))); }