diff --git a/conv/CMakeLists.txt b/conv/CMakeLists.txt index 2476b40..5bbce77 100644 --- a/conv/CMakeLists.txt +++ b/conv/CMakeLists.txt @@ -1,3 +1,6 @@ +add_executable(dcode_fcode common.hh dcode_fcode.cc) +target_link_libraries(dcode_fcode PRIVATE args) + add_executable(fidx_stego common.hh fidx_stego.cc) target_link_libraries(fidx_stego PRIVATE args minimp4 openh264) @@ -6,3 +9,6 @@ target_link_libraries(stego_fprob PRIVATE args minimp4 openh264) add_executable(fcprob_fcode common.hh fcprob_fcode.cc) target_link_libraries(fcprob_fcode PRIVATE args) + +add_executable(fcode_dcode common.hh fcode_dcode.cc) +target_link_libraries(fcode_dcode PRIVATE args) diff --git a/conv/dcode_fcode.cc b/conv/dcode_fcode.cc new file mode 100644 index 0000000..a522382 --- /dev/null +++ b/conv/dcode_fcode.cc @@ -0,0 +1,70 @@ +#include +#include +#include + +#include + +#include "common.hh" + + +namespace param { +using namespace ::args; + +ArgumentParser parser { + "converter: feature code probability matrix -> feature code" +}; +HelpFlag help { + parser, "help", "display this menu", {'h', "help"}, +}; + +ValueFlag smap { + parser, "path", "step map file path", {"smap"}, +}; + +ValueFlag first { + parser, "0", "first fcode", {"first"}, 0 +}; +ValueFlag fcnum { + parser, "50", "number of fcode alphabet", {"fc-num"}, 50 +}; + +} // namespace param + + +static void Exec() { + const auto fcnum = args::get(param::fcnum); + Enforce(fcnum > 0, "fc-num must be greater than 0"); + + std::ifstream smap_st {args::get(param::smap)}; + Enforce(!!smap_st, "smap path is invalid"); + const auto smap = ReadMatrix(smap_st); + Enforce(smap.size() > 0 && smap[0].size() > 0, "empty smap"); + + const auto bn = smap[0].size(); + for (auto& br : smap) { + Enforce(br.size() == bn, "all node should have the same number of branch"); + } + + size_t fcode = args::get(param::first); + std::cout << fcode << '\n'; + + for (size_t dcode, t = 0; std::cin >> dcode; ++t) { + Enforce(dcode < bn, "dcode must be lower than number of branch"); + Enforce(fcnum*(t+1) <= smap.size(), "smap row shortage"); + fcode = smap[t*fcnum + fcode][dcode]; + std::cout << fcode << '\n'; + } +} + +int main(int argc, char** argv) +try { + param::parser.ParseCLI(argc, argv); + Exec(); + return EXIT_SUCCESS; +} catch (const args::Help&) { + std::cout << param::parser << std::endl; + return EXIT_SUCCESS; +} catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; +} diff --git a/conv/fcode_dcode.cc b/conv/fcode_dcode.cc new file mode 100644 index 0000000..fb25bb2 --- /dev/null +++ b/conv/fcode_dcode.cc @@ -0,0 +1,71 @@ +#include +#include +#include + +#include + +#include "common.hh" + + +namespace param { +using namespace ::args; + +ArgumentParser parser { + "converter: feature code probability matrix -> feature code" +}; +HelpFlag help { + parser, "help", "display this menu", {'h', "help"}, +}; + +ValueFlag smap { + parser, "path", "step map file path", {"smap"}, +}; + +ValueFlag fcnum { + parser, "50", "number of fcode alphabet", {"fc-num"}, 50 +}; + +} // namespace param + + +static void Exec() { + const auto fcnum = args::get(param::fcnum); + Enforce(fcnum > 0, "fc-num must be greater than 0"); + + std::ifstream smap_st {args::get(param::smap)}; + Enforce(!!smap_st, "smap path is invalid"); + const auto smap = ReadMatrix(smap_st); + Enforce(smap.size() > 0 && smap[0].size() > 0, "empty smap"); + + const auto bn = smap[0].size(); + for (auto& br : smap) { + Enforce(br.size() == bn, "all node should have the same number of branch"); + } + + size_t fcode_p, dcode; + std::cin >> fcode_p; + for (size_t fcode, t = 0; std::cin >> fcode; ++t) { + Enforce(fcode < fcnum, "fcode overflow"); + Enforce(fcnum*(t+1) <= smap.size(), "smap row shortage"); + + const auto& row = smap[t*fcnum + fcode_p]; + auto itr = std::find(row.begin(), row.end(), fcode); + Enforce(itr != row.end(), "invalid step detected"); + std::cout << std::distance(row.begin(), itr) << '\n'; + fcode_p = fcode; + } +} + +int main(int argc, char** argv) +try { + param::parser.ParseCLI(argc, argv); + Exec(); + return EXIT_SUCCESS; +} catch (const args::Help&) { + std::cout << param::parser << std::endl; + return EXIT_SUCCESS; +} catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; +} +