diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-05 06:41:59 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-05 06:41:59 +0200 |
commit | cbfe7450f67eb9e0f7c9ef49d593f88527230a88 (patch) | |
tree | b1b6908bc932e1833e5f9fa7f5b7699b6055ecf4 | |
parent | d2b9714c5ab557de69a985bdb7e4a0ab0fd95864 (diff) |
a
-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 | 12 | ||||
-rw-r--r-- | main.cpp | 55 | ||||
-rw-r--r-- | tile-atlas.cpp | 1 |
5 files changed, 16 insertions, 74 deletions
diff --git a/anim-crop-tool/atlas.cpp b/anim-crop-tool/atlas.cpp index a588ff3c..8c43d64f 100644 --- a/anim-crop-tool/atlas.cpp +++ b/anim-crop-tool/atlas.cpp @@ -1,31 +1,29 @@ -#undef NDEBUG - #include "atlas.hpp" #include "anim/serialize.hpp" +#include "compat/assert.hpp" -#include <cassert> #include <filesystem> #include <opencv2/imgcodecs.hpp> -void anim_atlas_row::add_entry(const anim_atlas_entry& x) noexcept +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}; - assert(mat.rows > 0 && mat.cols > 0); + ASSERT(mat.rows > 0 && mat.cols > 0); data.push_back(x); xpos += mat.cols; max_height = std::max(mat.rows, max_height); } -void anim_atlas::advance_row() noexcept +void anim_atlas::advance_row() { auto& row = rows.back(); if (row.data.empty()) return; - assert(row.xpos); assert(row.max_height); + ASSERT(row.xpos > 0); ASSERT(row.max_height > 0); ypos += row.max_height; maxx = std::max(row.xpos, maxx); rows.push_back({{}, 0, 0, ypos}); @@ -45,7 +43,7 @@ Magnum::Vector2i anim_atlas::size() const noexcept return {std::max(maxx, row.xpos), ypos + row.max_height}; } -bool anim_atlas::dump(const std::filesystem::path& filename) const noexcept +bool anim_atlas::dump(const std::filesystem::path& filename) const { auto sz = size(); cv::Mat4b mat(sz[1], sz[0]); diff --git a/anim-crop-tool/atlas.hpp b/anim-crop-tool/atlas.hpp index 5c5e918f..66bddb5d 100644 --- a/anim-crop-tool/atlas.hpp +++ b/anim-crop-tool/atlas.hpp @@ -20,7 +20,7 @@ struct anim_atlas_row std::vector<anim_atlas_entry> data; int max_height = 0, xpos = 0, ypos = 0; - void add_entry(const anim_atlas_entry& x) noexcept; + void add_entry(const anim_atlas_entry& x); }; class anim_atlas @@ -29,9 +29,9 @@ class anim_atlas int ypos = 0, maxx = 0; public: - void add_entry(const anim_atlas_entry& x) noexcept { rows.back().add_entry(x); } - void advance_row() noexcept; + 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; - [[nodiscard]] bool dump(const std::filesystem::path& filename) 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 ff4c9e72..600688c1 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -1,11 +1,9 @@ -#undef NDEBUG - #include "atlas.hpp" #include "anim/serialize.hpp" #include "compat/defs.hpp" #include "compat/sysexits.hpp" +#include "compat/assert.hpp" -#include <cassert> #include <cmath> #include <cstring> @@ -61,7 +59,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, const path& filename) noexcept +static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const path& filename) { auto mat = progn( cv::Mat mat = cv::imread(filename.string(), cv::IMREAD_UNCHANGED); @@ -88,12 +86,12 @@ static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const if (opts.scale == 0.0) { - assert(opts.width || opts.height); + ASSERT(opts.width || opts.height); if (opts.width) opts.scale = (double)opts.width / size.width; else opts.scale = (double)opts.height / size.height; - assert(opts.scale > 1e-6); + ASSERT(opts.scale > 1e-6); } const cv::Size dest_size = { @@ -121,7 +119,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) noexcept +static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) { const auto input_dir = opts.input_dir/group.name; @@ -109,46 +109,6 @@ app::app(const Arguments& arguments): } { reset_camera_offset(); -#if 0 - std::vector<QuadVertex> vertices; vertices.reserve(1024); - std::vector<UnsignedShort> indices; indices.reserve(1024); - - //float ratio = projection_size_ratio(); - const float X = TILE_SIZE[0], Y = TILE_SIZE[1], Z = TILE_SIZE[2]; - - reset_camera_offset(); - - { - constexpr auto N = TILE_MAX_DIM; - Vector3 center{N/2.f*TILE_SIZE[0], N/2.f*TILE_SIZE[1], 0}; - tile_atlas::quad walls[] = { - wall1->wall_quad_W(center, Vector3(X, Y, Z)), - wall1->wall_quad_N(center, Vector3(X, Y, Z)), - wall1->wall_quad_E(center, Vector3(X, Y, Z)), - wall1->wall_quad_S(center, Vector3(X, Y, Z)), - }; - - int k = 0; - for (const auto& positions : walls) - { - auto texcoords = wall1->texcoords_for_id(k % wall1->size()); - auto indices_ = wall1->indices(k); - for (unsigned x = 0; x < 4; x++) - vertices.push_back({ positions[x], texcoords[x] }); - for (auto x : indices_) - indices.push_back(x); - k++; - } - - //auto positions = anim_atlas->floor_quad({(float)(sz[0]*0), (float)(sz[1]*0), sz[1]*2}, sz); - } - - _mesh2.setCount((int)indices.size()) - .addVertexBuffer(GL::Buffer{vertices}, 0, - tile_shader::Position{}, tile_shader::TextureCoordinates{}) - .setIndexBuffer(GL::Buffer{indices}, 0, GL::MeshIndexType::UnsignedShort); -#endif - timeline.start(); } @@ -169,22 +129,7 @@ void app::drawEvent() { update(dt); } -#if 0 - { - //auto ratio = projection_size_ratio(); - auto sz = windowSize(); - _shader.set_scale({ (float)sz[0], (float)sz[1] }); - static bool once = true; - if (once) { - once = false; - Debug{} << _shader.project({16*50, 0, 0}); - } - } -#endif - -#if 1 draw_chunk(_chunk); -#endif swapBuffers(); redraw(); diff --git a/tile-atlas.cpp b/tile-atlas.cpp index 1c263dec..6b7a203e 100644 --- a/tile-atlas.cpp +++ b/tile-atlas.cpp @@ -1,4 +1,5 @@ #include "tile-atlas.hpp" +#include <Corrade/Containers/StringView.h> #include <Magnum/ImageView.h> #include <Magnum/GL/TextureFormat.h> |