public static void testEqual(String image1, String image2) { PngReader png1 = FileHelper.CreatePngReader(image1); PngHelperInternal.InitCrcForTests(png1); PngReader png2 = FileHelper.CreatePngReader(image2); PngHelperInternal.InitCrcForTests(png2); if (png1.IsInterlaced() != png2.IsInterlaced()) { fatalError("Cannot compare, one is interlaced, the other not:" + png1 + " " + png2, png1, png2); } if (!png1.ImgInfo.Equals(png2.ImgInfo)) { fatalError("Image are of different type", png1, png2); } png1.ReadRow(png1.ImgInfo.Rows - 1); png2.ReadRow(png2.ImgInfo.Rows - 1); png1.End(); png2.End(); long crc1 = PngHelperInternal.GetCrctestVal(png1); long crc2 = PngHelperInternal.GetCrctestVal(png2); if (crc1 != crc2) { fatalError("different crcs " + image1 + "=" + crc1 + " " + image2 + "=" + crc2, png1, png2); } }
static void testmirror(string orig, string origni, string truecolor) { string mirror = TestsHelper.addSuffixToName(orig, "_mirror"); string recov = TestsHelper.addSuffixToName(orig, "_recov"); long crc0 = 0; bool interlaced; bool palete; { PngReader pngr = FileHelper.CreatePngReader(orig); palete = pngr.ImgInfo.Indexed; PngHelperInternal.InitCrcForTests(pngr); pngr.SetUnpackedMode(true); interlaced = pngr.IsInterlaced(); PngWriter pngw = FileHelper.CreatePngWriter(mirror, pngr.ImgInfo, true); pngw.SetFilterType(FilterType.FILTER_CYCLIC); // just to test all filters pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL); pngw.SetUseUnPackedMode(true); for (int row = 0; row < pngr.ImgInfo.Rows; row++) { ImageLine line = pngr.ReadRowInt(row); mirrorLine(line); pngw.WriteRow(line, row); } pngr.End(); crc0 = PngHelperInternal.GetCrctestVal(pngr); pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL); pngw.End(); } // mirror again, now with BYTE (if depth<16) and loading all rows { PngReader pngr2 = FileHelper.CreatePngReader(mirror); pngr2.SetUnpackedMode(true); PngWriter pngw = FileHelper.CreatePngWriter(recov, pngr2.ImgInfo, true); pngw.SetFilterType(FilterType.FILTER_AGGRESSIVE); pngw.CopyChunksFirst(pngr2, ChunkCopyBehaviour.COPY_ALL); pngw.SetUseUnPackedMode(true); ImageLines lines = pngr2.ImgInfo.BitDepth < 16 ? pngr2.ReadRowsByte() : pngr2 .ReadRowsInt(); for (int row = 0; row < pngr2.ImgInfo.Rows; row++) { ImageLine line = lines.GetImageLineAtMatrixRow(row); mirrorLine(line); pngw.WriteRow(line, row); } pngr2.End(); pngw.End(); } // now check if (orig[11] != 'i') { TestsHelper.testCrcEquals(recov, crc0); } //if (interlaced) // additionalTestInterlaced(orig, origni); //if (palete && System.IO.File.Exists(truecolor)) // additionalTestPalette(orig, truecolor); }
public static void testCrcEquals(string image1, long crc) { PngReader png1 = FileHelper.CreatePngReader(image1); PngHelperInternal.InitCrcForTests(png1); png1.ReadRow(png1.ImgInfo.Rows - 1); png1.End(); long crc1 = PngHelperInternal.GetCrctestVal(png1); if (crc1 != crc) { fatalError("different crcs", png1); } }