|
| 1 | +#include "MMVII_Image2D.h" |
| 2 | + |
| 3 | +namespace MMVII |
| 4 | +{ |
| 5 | + |
| 6 | +namespace { // private |
| 7 | + |
| 8 | +class cAppliTestAPBI : public cMMVII_Appli, |
| 9 | + public cAppliParseBoxIm<tREAL4> |
| 10 | +{ |
| 11 | +public : |
| 12 | + typedef cAppliParseBoxIm<tREAL4> tAPBI; |
| 13 | + typedef tAPBI::tIm tImAPBI; |
| 14 | + typedef tAPBI::tDataIm tDImAPBI; |
| 15 | + typedef cIm2D<tREAL4> tImPx; |
| 16 | + typedef cIm2D<tU_INT1> tImMasq; |
| 17 | + |
| 18 | + // typedef cIm2D |
| 19 | + |
| 20 | + // =========== Declaration ======== |
| 21 | + // --- Method to be a MMVII application |
| 22 | + cAppliTestAPBI(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli &); |
| 23 | + int Exe() override; |
| 24 | + // --- Method to be a cAppliParseBoxIm<tREAL4> |
| 25 | + int ExeOnParsedBox() override; ///< Action to exec for each box, When the appli parse a big file |
| 26 | + |
| 27 | + static std::string ImNameIn() { return cMMVII_Appli::CurrentAppli().TmpDirTestMMVII() + "TestAPBI.tif"; } |
| 28 | + static std::string ImNameOut() { return cMMVII_Appli::CurrentAppli().TmpDirTestMMVII() + "TestAPBI_out.tif"; } |
| 29 | + static tU_INT1 valFromBox(const cPixBox<2>& box) { return (box.P0().x() + box.P0().y()) % 255;} |
| 30 | + |
| 31 | +private: |
| 32 | + cCollecSpecArg2007 &ArgObl(cCollecSpecArg2007 &anArgObl) override; |
| 33 | + cCollecSpecArg2007 &ArgOpt(cCollecSpecArg2007 &anArgOpt) override; |
| 34 | +}; |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +cAppliTestAPBI::cAppliTestAPBI |
| 39 | + ( |
| 40 | + const std::vector<std::string> & aVArgs, |
| 41 | + const cSpecMMVII_Appli & aSpec |
| 42 | + ) : |
| 43 | + cMMVII_Appli (aVArgs,aSpec) , |
| 44 | + cAppliParseBoxIm<tREAL4> (*this,eForceGray::Yes,cPt2di(0,0),cPt2di(0,0),true) |
| 45 | +{ |
| 46 | +} |
| 47 | + |
| 48 | +cCollecSpecArg2007 & cAppliTestAPBI::ArgObl(cCollecSpecArg2007 & anArgObl) |
| 49 | +{ |
| 50 | + return anArgObl; |
| 51 | +// return APBI_ArgObl(anArgObl); <-- should be used, but for bench, it's simplier to don't |
| 52 | +} |
| 53 | + |
| 54 | +cCollecSpecArg2007 & cAppliTestAPBI::ArgOpt(cCollecSpecArg2007 & anArgOpt) |
| 55 | +{ |
| 56 | + return APBI_ArgOpt(anArgOpt); |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +int cAppliTestAPBI::ExeOnParsedBox() |
| 61 | +{ |
| 62 | + cIm2D<tU_INT1> aImTest(CurSzIn()); |
| 63 | + tU_INT1 aVal = valFromBox(CurBoxIn()); |
| 64 | + auto &imSrc = LoadI(CurBoxIn()); |
| 65 | + for (const auto & aPix : aImTest.DIm()) |
| 66 | + aImTest.DIm().SetVTrunc(aPix,(aVal + (int)imSrc.GetV(aPix)) % 255); |
| 67 | + APBI_WriteIm(ImNameOut(),aImTest); |
| 68 | + |
| 69 | + return EXIT_SUCCESS; |
| 70 | +} |
| 71 | + |
| 72 | +int cAppliTestAPBI::Exe() |
| 73 | +{ |
| 74 | + mNameIm = ImNameIn(); |
| 75 | + APBI_ExecAll(true); |
| 76 | + return EXIT_SUCCESS; |
| 77 | +} |
| 78 | + |
| 79 | + |
| 80 | +/* ============================================= */ |
| 81 | +/* ALLOCATION */ |
| 82 | +/* ============================================= */ |
| 83 | + |
| 84 | +tMMVII_UnikPApli Alloc_cAppliTestAPBI(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec) |
| 85 | +{ |
| 86 | + return tMMVII_UnikPApli(new cAppliTestAPBI(aVArgs,aSpec)); |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +} // namespace private |
| 91 | + |
| 92 | +cSpecMMVII_Appli TheSpecAppliBenchAPBI |
| 93 | + ( |
| 94 | + "TestAPBI", |
| 95 | + Alloc_cAppliTestAPBI, |
| 96 | + "Internal only !! Used by APBI bench", |
| 97 | + {eApF::Test,eApF::NoGui}, |
| 98 | + {eApDT::None}, |
| 99 | + {eApDT::Image}, |
| 100 | + __FILE__ |
| 101 | + ); |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +void BenchAPBI(cParamExeBench & aParam) |
| 106 | +{ |
| 107 | + if (! aParam.NewBench("APBI")) return; |
| 108 | + |
| 109 | + |
| 110 | + cDataFileIm2D::Create(cAppliTestAPBI::ImNameIn(),eTyNums::eTN_U_INT1, |
| 111 | + cPt2di(2000+RandUnif_M_N(-100,100),2000+RandUnif_M_N(-100,100)), |
| 112 | + 1 |
| 113 | + ); |
| 114 | + auto aIm2d = cIm2D<tU_INT1>(cPt2di(2000+RandUnif_M_N(-100,100),2000+RandUnif_M_N(-100,100))); |
| 115 | + for (const auto& aPix : aIm2d.DIm()) { |
| 116 | + aIm2d.DIm().SetV(aPix,(aPix.x()+aPix.y()) % 255); |
| 117 | + } |
| 118 | + cDataFileIm2D aDF = cDataFileIm2D::Create(cAppliTestAPBI::ImNameIn(),eTyNums::eTN_U_INT1,aIm2d.DIm().Sz(),1); |
| 119 | + aIm2d.Write(aDF,cPt2di(0,0)); |
| 120 | + auto aBoxSize = cPt2di(200+RandUnif_M_N(-10,10),200+RandUnif_M_N(-10,10)); |
| 121 | + |
| 122 | + cMMVII_Appli & anAp = cMMVII_Appli::CurrentAppli(); |
| 123 | + |
| 124 | + anAp.ExeCallMMVII |
| 125 | + ( |
| 126 | + TheSpecAppliBenchAPBI, |
| 127 | + anAp.StrObl(), |
| 128 | + anAp.StrOpt() << std::make_pair("SzTiles",cStrIO<cPt2di>::ToStr(aBoxSize)) |
| 129 | + ); |
| 130 | + |
| 131 | + |
| 132 | + auto mIm2d = cIm2D<tU_INT1>::FromFile(cAppliTestAPBI::ImNameOut()); |
| 133 | + cParseBoxInOut<2> aPBIO = cParseBoxInOut<2>::CreateFromSize(mIm2d.DIm(),aBoxSize); |
| 134 | + for (const auto & aPixI : aPBIO.BoxIndex()) { |
| 135 | + auto aBox = aPBIO.BoxOut(aPixI); |
| 136 | + tU_INT1 aVal = cAppliTestAPBI::valFromBox(aBox); |
| 137 | + for (const auto &aPix : aBox) { |
| 138 | + MMVII_INTERNAL_ASSERT_bench(mIm2d.DIm().GetV(aPix) == (aVal + (aPix.x() + aPix.y()) % 255)%255,"BenchAPBI failed"); |
| 139 | + } |
| 140 | + } |
| 141 | + aParam.EndBench(); |
| 142 | +} |
| 143 | + |
| 144 | +} // namespace MMVII |
| 145 | + |
0 commit comments