diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-05 20:47:15 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-05 20:47:15 +0100 |
commit | 794787093d1d29aa67a06223ed2e0c56ec90b9ce (patch) | |
tree | 900d3e5591b1187e864a4116bf957e0d0839cb77 /anim-crop-tool | |
parent | b97413c5561a59acac86e053a1aa8bd7905456f2 (diff) |
a
Diffstat (limited to 'anim-crop-tool')
-rw-r--r-- | anim-crop-tool/atlas.cpp | 14 | ||||
-rw-r--r-- | anim-crop-tool/atlas.hpp | 8 | ||||
-rw-r--r-- | anim-crop-tool/main.cpp | 19 |
3 files changed, 22 insertions, 19 deletions
diff --git a/anim-crop-tool/atlas.cpp b/anim-crop-tool/atlas.cpp index b099435b..d088e733 100644 --- a/anim-crop-tool/atlas.cpp +++ b/anim-crop-tool/atlas.cpp @@ -10,12 +10,12 @@ void anim_atlas_row::add_entry(const anim_atlas_entry& x) auto& frame = *x.frame; const auto& mat = x.mat; frame.offset = {xpos, ypos}; - frame.size = {mat.cols, mat.rows}; + frame.size = {(unsigned)mat.cols, (unsigned)mat.rows}; fm_assert(mat.rows > 0 && mat.cols > 0); data.push_back(x); - xpos += mat.cols; - max_height = std::max(mat.rows, max_height); + xpos += (unsigned)mat.cols; + max_height = std::max((unsigned)mat.rows, max_height); } void anim_atlas::advance_row() @@ -30,13 +30,13 @@ void anim_atlas::advance_row() rows.push_back({{}, 0, 0, ypos}); } -Magnum::Vector2i anim_atlas::offset() const noexcept +Magnum::Vector2ui anim_atlas::offset() const noexcept { const auto& row = rows.back(); return {row.xpos, row.ypos}; } -Magnum::Vector2i anim_atlas::size() const noexcept +Magnum::Vector2ui anim_atlas::size() const noexcept { const anim_atlas_row& row = rows.back(); // prevent accidentally writing out of bounds by forgetting to call @@ -47,7 +47,7 @@ Magnum::Vector2i anim_atlas::size() const noexcept bool anim_atlas::dump(const std::filesystem::path& filename) const { auto sz = size(); - cv::Mat4b mat(sz[1], sz[0]); + cv::Mat4b mat((int)sz[1], (int)sz[0]); mat.setTo(0); for (const anim_atlas_row& row : rows) @@ -55,7 +55,7 @@ bool anim_atlas::dump(const std::filesystem::path& filename) const { auto offset = x.frame->offset; auto size = x.frame->size; - cv::Rect roi = {offset[0], offset[1], (int)size[0], (int)size[1]}; + cv::Rect roi = {(int)offset[0], (int)offset[1], (int)size[0], (int)size[1]}; x.mat.copyTo(mat(roi)); } diff --git a/anim-crop-tool/atlas.hpp b/anim-crop-tool/atlas.hpp index 6da8fd63..21e1eff1 100644 --- a/anim-crop-tool/atlas.hpp +++ b/anim-crop-tool/atlas.hpp @@ -18,7 +18,7 @@ struct anim_atlas_entry struct anim_atlas_row { std::vector<anim_atlas_entry> data; - int max_height = 0, xpos = 0, ypos = 0; + unsigned max_height = 0, xpos = 0, ypos = 0; void add_entry(const anim_atlas_entry& x); }; @@ -26,13 +26,13 @@ struct anim_atlas_row class anim_atlas { std::vector<anim_atlas_row> rows = {{}}; - int ypos = 0, maxx = 0; + unsigned ypos = 0, maxx = 0; public: void add_entry(const anim_atlas_entry& x) { rows.back().add_entry(x); } void advance_row(); - Magnum::Vector2i offset() const noexcept; - Magnum::Vector2i size() const noexcept; + Magnum::Vector2ui offset() const noexcept; + Magnum::Vector2ui size() const noexcept; [[nodiscard]] bool dump(const std::filesystem::path& filename) const; }; diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 215d9994..e16f830c 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -11,6 +11,7 @@ #include <algorithm> #include <utility> #include <tuple> +#include <string_view> #include <filesystem> #include <Corrade/Utility/Arguments.h> @@ -34,7 +35,7 @@ struct options { double scale = 0; path input_dir, input_file, output_dir; - int width = 0, height = 0, nframes = 0; + std::size_t width = 0, height = 0, nframes = 0; }; [[nodiscard]] @@ -117,7 +118,9 @@ static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const (int)std::round((group.ground[1] - start[1]) * opts.scale), }; - group.frames.push_back({ground, atlas.offset(), {dest_size.width, dest_size.height}}); + const Magnum::Vector2ui dest_size_ = { (unsigned)dest_size.width, (unsigned)dest_size.height }; + + group.frames.push_back({ground, atlas.offset(), dest_size_}); atlas.add_entry({&group.frames.back(), std::move(resized)}); return true; } @@ -125,7 +128,7 @@ static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const [[nodiscard]] static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) { - const auto input_dir = opts.input_dir/group.name; + const auto input_dir = opts.input_dir/std::string_view{group.name.cbegin(), group.name.cend()}; if (std::error_code ec; !std::filesystem::exists(input_dir/".", ec)) { @@ -133,7 +136,7 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) return false; } - int max; + unsigned max; for (max = 1; max <= 9999; max++) { char filename[9]; @@ -162,7 +165,7 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) // vector::reserve() is necessary to avoid use-after-free. group.frames.reserve((std::size_t)max-1); - for (int i = 1; i < max; i++) + for (unsigned i = 1; i < max; i++) { char filename[9]; sprintf(filename, "%04d.png", i); @@ -202,9 +205,9 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* .addOption('H', "height", ""); args.parse(argc, argv); options opts; - if (int w = args.value<int>("width"); w != 0) + if (auto w = args.value<unsigned>("width"); w != 0) opts.width = w; - if (int h = args.value<int>("height"); h != 0) + if (auto h = args.value<unsigned>("height"); h != 0) opts.height = h; opts.output_dir = args.value<std::string>("output"); opts.input_file = args.value<std::string>("input"); @@ -265,7 +268,7 @@ int main(int argc, char** argv) opts.height = anim_info.height; opts.nframes = anim_info.nframes; - if (!(opts.width ^ opts.height) || opts.width < 0 || opts.height < 0) + if (!(opts.width ^ opts.height)) { Error{} << "error: exactly one of --width, --height must be specified"; return usage(args); |