summaryrefslogtreecommitdiffhomepage
path: root/anim-crop-tool/main.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-11-22 12:36:16 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-11-22 12:36:16 +0100
commitefe599cbaf5d4f43d98ab19718fddd78865d1513 (patch)
treed54ccaf72aeda5b8590994558a9be70615ae9a19 /anim-crop-tool/main.cpp
parentbaf99d32bc58074f10cf194e43963f47fae34c08 (diff)
fix crop-tool
Diffstat (limited to 'anim-crop-tool/main.cpp')
-rw-r--r--anim-crop-tool/main.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp
index 33011be5..9e8fb2a1 100644
--- a/anim-crop-tool/main.cpp
+++ b/anim-crop-tool/main.cpp
@@ -33,6 +33,8 @@ using Corrade::Utility::Error;
using Corrade::Utility::Debug;
using floormat::Serialize::anim_atlas_;
+namespace {
+
struct options
{
String input_dir, input_file, output_dir;
@@ -41,7 +43,7 @@ struct options
};
[[nodiscard]]
-static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b& mat) noexcept
+std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b& mat) noexcept
{
cv::Vec2i start{mat.cols, mat.rows}, end{0, 0};
for (int y = 0; y < mat.rows; y++)
@@ -66,7 +68,7 @@ static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b&
}
[[nodiscard]]
-static bool load_file(anim_group& group, options& opts, anim_atlas_& atlas, StringView filename)
+bool load_file(anim_group& group, options& opts, anim_atlas_& atlas, StringView filename)
{
auto mat = fm_begin(
cv::Mat mat = cv::imread(filename, cv::IMREAD_UNCHANGED);
@@ -126,7 +128,7 @@ static bool load_file(anim_group& group, options& opts, anim_atlas_& atlas, Stri
}
[[nodiscard]]
-static bool load_directory(anim_group& group, options& opts, anim_atlas_& atlas)
+bool load_directory(anim_group& group, options& opts, anim_atlas_& atlas)
{
if (!group.mirror_from.isEmpty())
return true;
@@ -181,9 +183,19 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas_& atlas)
return true;
}
+inline String fixsep(String str)
+{
+#ifdef _WIN32
+ for (char& c : str)
+ if (c == '\\')
+ c = '/';
+#endif
+ return str;
+}
+
using Corrade::Utility::Arguments;
-static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* const* argv) noexcept
+std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* const* argv) noexcept
{
Corrade::Utility::Arguments args{};
args.addOption('o', "output").setHelp("output", "", "DIR")
@@ -202,8 +214,8 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char*
else if (!args.value<StringView>("scale").isEmpty())
opts.scale = anim_scale::ratio{args.value<float>("scale")};
- opts.output_dir = Path::join(loader.startup_directory(), args.value<StringView>("output"));
- opts.input_file = Path::join(loader.startup_directory(), args.value<StringView>("input.json"));
+ opts.output_dir = Path::join(loader.startup_directory(), fixsep(args.value<StringView>("output")));
+ opts.input_file = Path::join(loader.startup_directory(), fixsep(args.value<StringView>("input.json")));
opts.input_dir = Path::split(opts.input_file).first();
if (opts.output_dir.isEmpty())
@@ -212,12 +224,14 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char*
return { Utility::move(opts), Utility::move(args), true };
}
-[[nodiscard]] static int usage(const Arguments& args) noexcept
+[[nodiscard]] int usage(const Arguments& args) noexcept
{
Error{Error::Flag::NoNewlineAtTheEnd} << args.usage();
return EX_USAGE;
}
+} // namespace
+
int main(int argc, char** argv)
{
argv[0] = fix_argv0(argv[0]);