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); } }
public sprite_data load_sprite_png(string _filename, string _name, bool _apply_palette, bool _crop_image, int _palette_slot) { PngReader png_reader = FileHelper.CreatePngReader(_filename); try { if (!png_reader.ImgInfo.Indexed) { throw new Exception(_filename + "\n\nNot indexed image!"); } if (png_reader.IsInterlaced()) { throw new Exception(_filename + "\n\nOnly non interlaced .PNG images are supported!"); } // if( ( png_reader.ImgInfo.Cols & 0x07 ) != 0 || ( png_reader.ImgInfo.Rows & 0x07 ) != 0 ) // { // png_reader.End(); // throw new Exception( _filename + "\n\nThe image size must be a multiple of 8 !" ); // } // if( ( ( png_reader.ImgInfo.Cols >> 3 ) * ( png_reader.ImgInfo.Rows >> 3 ) ) > utils.CONST_CHR_BANK_MAX_SPRITES_CNT ) // { // png_reader.End(); // throw new Exception( _filename + "\n\nThe imported image contains more than " + utils.CONST_CHR_BANK_MAX_SPRITES_CNT + " CHRs!" ); // } #if DEF_NES if (png_reader.GetMetadata().GetPLTE().MinBitDepth() != 2) { throw new Exception(_filename + "\n\nThe PNG image must have a 4 colors palette!"); } #elif DEF_SMS || DEF_PCE int img_bit_depth = png_reader.GetMetadata().GetPLTE().MinBitDepth(); if (img_bit_depth != 4 && img_bit_depth != 2) { throw new Exception(_filename + "\n\nThe PNG image must have a 4 or 2 bpp color depth!"); } if (png_reader.GetMetadata().GetPLTE().GetNentries() > 16) { throw new Exception(_filename + "\n\nThe PNG image must have a 16 or 4 colors palette!"); } #else ... #endif sprite_params spr_params = m_CHR_data_storage.create(png_reader, _apply_palette, _crop_image, _palette_slot); sprite_data spr = new sprite_data(_name); spr.setup(spr_params); spr.update_dimensions(); png_reader.End(); return(spr); }
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); }