summaryrefslogtreecommitdiffhomepage
path: root/anim-crop-tool/atlas.hpp
blob: 21e1eff1e7d77d7c3a12a74ef1c45caa43431294 (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
#pragma once
#include <vector>
#include <filesystem>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
#include <opencv2/core/mat.hpp>

namespace floormat::Serialize {

struct anim_frame;

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

struct anim_atlas_row
{
    std::vector<anim_atlas_entry> data;
    unsigned max_height = 0, xpos = 0, ypos = 0;

    void add_entry(const anim_atlas_entry& x);
};

class anim_atlas
{
    std::vector<anim_atlas_row> rows = {{}};
    unsigned ypos = 0, maxx = 0;

public:
    void add_entry(const anim_atlas_entry& x) { rows.back().add_entry(x); }
    void advance_row();
    Magnum::Vector2ui offset() const noexcept;
    Magnum::Vector2ui size() const noexcept;
    [[nodiscard]] bool dump(const std::filesystem::path& filename) const;
};

} // namespace floormat::Serialize