public void ShouldConcatEmptyList() { List <IDAT> idats = new List <IDAT>(); byte[] result = IDATConverter.ConcatToBytes(idats); Assert.AreEqual(new byte[] { }, result); }
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); }
public void ShouldConcatOneIDAT() { IDAT idat = new IDAT(new byte[] { 1, 5, 7 }, 0); List <IDAT> idats = new List <IDAT> { idat }; byte[] result = IDATConverter.ConcatToBytes(idats); Assert.AreEqual(new byte[] { 1, 5, 7 }, result); }
public void ShouldConcatFourIDATs() { List <IDAT> idats = new List <IDAT> { new IDAT(new byte[] { 1, 5, 7 }, 0), new IDAT(new byte[] { 4 }, 0), new IDAT(new byte[] { }, 0), new IDAT(new byte[] { 2, 5 }, 0) }; byte[] result = IDATConverter.ConcatToBytes(idats); Assert.AreEqual(new byte[] { 1, 5, 7, 4, 2, 5 }, result); }
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); }