This commit is contained in:
Fabien Freling 2022-02-17 23:15:45 +01:00
parent 4447cd67d1
commit 5b32c517c1
12 changed files with 179 additions and 16 deletions

View file

@ -17,6 +17,7 @@
#include "bounding_box.h"
#include "frame.h"
#include "mapping.h"
#include "mask.h"
#include "pack.h"
#include "png.h"
@ -52,7 +53,7 @@ void draw_region(const freling::BoundingBox& box,
DrawRectangleRec(rect, ColorAlpha(color, 0.8));
}
Image image_from_frame(const Frame& frame) {
Image image_from_frame(const freling::Frame& frame) {
Image image = {0};
const int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
@ -84,7 +85,7 @@ int main(int argc, const char* argv[]) {
return 1;
}
const std::optional<Frame> in_frame = load_png(input);
const std::optional<freling::Frame> in_frame = freling::load_png(input);
if (!in_frame) {
std::cerr << "Cannot load file " << input << "\n";
return 1;
@ -106,6 +107,7 @@ int main(int argc, const char* argv[]) {
std::vector<freling::BoundingBox> packed_bboxes;
std::vector<freling::BoundingBox> a2_bboxes;
std::vector<freling::BoundingBox> a2_bboxes_origin;
freling::Mask in_mask(in_frame->width, in_frame->height);
Vector2 win_size = {800, 450};
const int padding = 5;
@ -205,9 +207,19 @@ int main(int argc, const char* argv[]) {
b_size.y},
"Pack Rects")) {
a2_processed = false;
std::optional<Frame> f_packed =
std::optional<freling::Frame> f_packed =
freling::pack(*in_frame, bboxes, packed_bboxes);
// Update mask
in_mask.fill(false);
for (const auto& b : bboxes) {
for (int j = b.y; j < b.y + b.height; ++j) {
for (int i = b.x; i < b.x + b.width; ++i) {
in_mask.set(i, j, true);
}
}
};
if (packed) {
UnloadTexture(pack_texture);
UnloadImage(pack_img);