use raygui
This commit is contained in:
parent
8d91216f24
commit
81463d9eb0
9 changed files with 4589 additions and 83 deletions
40
src/pack.cpp
40
src/pack.cpp
|
@ -1,10 +1,40 @@
|
|||
#include "pack.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
Frame pack(const Frame& in_frame, const std::vector<BoundingBox>& bboxes) {
|
||||
namespace freling {
|
||||
|
||||
void blit(const Frame& in_frame,
|
||||
const BoundingBox& in_box,
|
||||
Frame& out_frame,
|
||||
const BoundingBox& out_box) {
|
||||
assert(in_box.width() == out_box.width());
|
||||
assert(in_box.height() == out_box.height());
|
||||
|
||||
const int data_width = in_box.width() * sizeof(Pixel);
|
||||
const int in_row_size = in_frame.width * sizeof(Pixel);
|
||||
const int out_row_size = out_frame.width * sizeof(Pixel);
|
||||
|
||||
for (unsigned int i = 0; i < in_box.height(); ++i) {
|
||||
const int in_offset =
|
||||
in_box.left * sizeof(Pixel) + (i + in_box.top) * in_row_size;
|
||||
const int out_offset =
|
||||
out_box.left * sizeof(Pixel) + (i + out_box.top) * out_row_size;
|
||||
memcpy(out_frame.data + out_offset, in_frame.data + in_offset,
|
||||
data_width);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Frame> pack(const Frame& in_frame,
|
||||
const std::vector<BoundingBox>& bboxes) {
|
||||
if (bboxes.size() == 0) {
|
||||
std::cerr << "No bounding box, cannot pack.\n";
|
||||
return {};
|
||||
}
|
||||
// We sort the bounding boxes by maximum area
|
||||
std::vector<BoundingBox> sorted_bboxes = bboxes;
|
||||
std::sort(sorted_bboxes.begin(), sorted_bboxes.end(),
|
||||
|
@ -38,6 +68,12 @@ Frame pack(const Frame& in_frame, const std::vector<BoundingBox>& bboxes) {
|
|||
std::cout << "maximum image dimention: " << in_min_dim << " x "
|
||||
<< in_min_dim << "\n";
|
||||
|
||||
// TODO
|
||||
const auto& largest = sorted_bboxes[0];
|
||||
BoundingBox out_largest = {0, 0, static_cast<uint32_t>(largest.width()),
|
||||
static_cast<uint32_t>(largest.height())};
|
||||
Frame packed_frame(largest.width(), largest.height());
|
||||
blit(in_frame, largest, packed_frame, out_largest);
|
||||
return Frame(in_frame);
|
||||
}
|
||||
|
||||
} // namespace freling
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue