summaryrefslogtreecommitdiffhomepage
path: root/anim-crop-tool/atlas.hpp
blob: be74b40a7fb97735eccd979fe521deaa9da01140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once

#include <vector>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
#include <opencv2/core/mat.hpp>

namespace std::filesystem { class path; }

namespace Magnum::Examples::Serialize {

struct anim_frame;

struct anim_atlas_entry
{
    anim_frame* frame;
    cv::Mat4b mat;
};

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);
};

class anim_atlas
{
    std::vector<anim_atlas_row> rows = {{}};
    int 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;
    [[nodiscard]] bool dump(const std::filesystem::path& filename) const;
};

} // namespace Magnum::Examples::Serialize