diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-12 08:40:08 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-12 09:57:16 +0100 |
commit | a6af5d7b0cdb037bf8d0fd99aedfedc9789fd74c (patch) | |
tree | 6664758f61d0bee67ba64f231a6ec2e6b4dd72ac /anim-crop-tool | |
parent | 7434d29f3ce0033194b53b44ed881f749e67da75 (diff) |
add offset to anim_group rotations
Diffstat (limited to 'anim-crop-tool')
-rw-r--r-- | anim-crop-tool/atlas.cpp | 19 | ||||
-rw-r--r-- | anim-crop-tool/atlas.hpp | 4 | ||||
-rw-r--r-- | anim-crop-tool/main.cpp | 13 |
3 files changed, 19 insertions, 17 deletions
diff --git a/anim-crop-tool/atlas.cpp b/anim-crop-tool/atlas.cpp index 90dda284..392f90fc 100644 --- a/anim-crop-tool/atlas.cpp +++ b/anim-crop-tool/atlas.cpp @@ -1,15 +1,16 @@ #include "atlas.hpp" -#include "serialize/anim.hpp" +#include "src/anim.hpp" #include <opencv2/imgcodecs.hpp> #include "compat/assert.hpp" // must go below opencv headers -using namespace floormat::Serialize; + +namespace floormat::Serialize { 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 = {(unsigned)mat.cols, (unsigned)mat.rows}; + frame.offset = { xpos, ypos }; + frame.size = { (unsigned)mat.cols, (unsigned)mat.rows }; fm_assert(mat.rows > 0 && mat.cols > 0); data.push_back(x); @@ -26,13 +27,13 @@ void anim_atlas::advance_row() fm_assert(row.max_height > 0); ypos += row.max_height; maxx = std::max(row.xpos, maxx); - rows.push_back({{}, 0, 0, ypos}); + rows.push_back({ {}, 0, 0, ypos }); } Magnum::Vector2ui anim_atlas::offset() const noexcept { const auto& row = rows.back(); - return {row.xpos, row.ypos}; + return { row.xpos, row.ypos }; } Magnum::Vector2ui anim_atlas::size() const noexcept @@ -40,7 +41,7 @@ Magnum::Vector2ui anim_atlas::size() const noexcept const anim_atlas_row& row = rows.back(); // prevent accidentally writing out of bounds by forgetting to call // anim_atlas::advance_row() one last time prior to anim_atlas::size() - return {std::max(maxx, row.xpos), ypos + row.max_height}; + return { std::max(maxx, row.xpos), ypos + row.max_height }; } bool anim_atlas::dump(StringView filename) const @@ -54,9 +55,11 @@ bool anim_atlas::dump(StringView filename) const { auto offset = x.frame->offset; auto size = x.frame->size; - cv::Rect roi = {(int)offset[0], (int)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)); } return cv::imwrite(filename.data(), mat); } + +} // namespace floormat::Serialize diff --git a/anim-crop-tool/atlas.hpp b/anim-crop-tool/atlas.hpp index 6b5f7b95..41e8ecca 100644 --- a/anim-crop-tool/atlas.hpp +++ b/anim-crop-tool/atlas.hpp @@ -5,9 +5,9 @@ #include <Magnum/Math/Vector2.h> #include <opencv2/core/mat.hpp> -namespace floormat::Serialize { +namespace floormat { struct anim_frame; } -struct anim_frame; +namespace floormat::Serialize { struct anim_atlas_entry { diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 15335d84..0d20781c 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -1,7 +1,7 @@ #include "atlas.hpp" -#include "serialize/anim.hpp" #include "serialize/magnum-vector2i.hpp" #include "serialize/json-helper.hpp" +#include "serialize/anim.hpp" #include "compat/defs.hpp" #include "compat/sysexits.hpp" @@ -28,7 +28,6 @@ #include "compat/assert.hpp" using namespace floormat; -using namespace floormat::Serialize; using Corrade::Utility::Error; using Corrade::Utility::Debug; @@ -66,7 +65,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) +static bool load_file(anim_group& group, options& opts, Serialize::anim_atlas& atlas, StringView filename) { auto mat = fm_begin( cv::Mat mat = cv::imread(filename, cv::IMREAD_UNCHANGED); @@ -128,7 +127,7 @@ static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, Strin } [[nodiscard]] -static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) +static bool load_directory(anim_group& group, options& opts, Serialize::anim_atlas& atlas) { const auto input_dir = Path::join(opts.input_dir, group.name); @@ -248,7 +247,7 @@ int main(int argc, char** argv) if (!opts_ok) return usage(args); - auto anim_info = json_helper::from_json<anim>(opts.input_file); + auto anim_info = json_helper::from_json<anim_def>(opts.input_file); if (!check_atlas_name(anim_info.object_name)) { @@ -274,7 +273,7 @@ int main(int argc, char** argv) return usage(args); } - anim_atlas atlas; + Serialize::anim_atlas atlas; for (anim_group& group : anim_info.groups) if (!load_directory(group, opts, atlas)) @@ -291,7 +290,7 @@ int main(int argc, char** argv) return EX_CANTCREAT; } anim_info.pixel_size = Vector2ui(atlas.size()); - json_helper::to_json<anim>(anim_info, Path::join(opts.output_dir, (base_name + ".json"))); + json_helper::to_json<anim_def>(anim_info, Path::join(opts.output_dir, (base_name + ".json"))); return 0; } |