public void TestWritingChunksProducesIdenticalBytesAsInput() { byte[] input = Simple10x10WhitePNG; using (MemoryStream stream = new MemoryStream(Simple10x10WhitePNG)) { PNGChunk[] chunks = PNGChunkParser.ChunksFromStream(stream).ToArray(); MemoryStream output = new MemoryStream(); PNGChunkParser.WriteChunksAsPNG(chunks, output); byte[] outputBytes = output.ToArray(); CollectionAssert.AreEqual(input, outputBytes); } }
public void TestWritingChunksAfterRecalculatingCRCProducesIdenticalBytesAsInput() { byte[] input = Simple10x10WhitePNG; using (MemoryStream stream = new MemoryStream(Simple10x10WhitePNG)) { PNGChunk[] chunks = PNGChunkParser.ChunksFromStream(stream).ToArray(); chunks = chunks.Select(c => { return(new PNGChunk(c.TypeString, c.Data, PNGDecrusher.CalculateCRCForChunk(c.TypeString, c.Data))); }).ToArray(); MemoryStream output = new MemoryStream(); PNGChunkParser.WriteChunksAsPNG(chunks, output); byte[] outputBytes = output.ToArray(); CollectionAssert.AreEqual(input, outputBytes); } }
private static void DecrushAtChunkLevel(Stream input, Stream output) { IEnumerable <PNGChunk> fixedChunks = DecrushChunks(PNGChunkParser.ChunksFromStream(input)); PNGChunkParser.WriteChunksAsPNG(fixedChunks, output); }