show packed bboxes

This commit is contained in:
Fabien Freling 2022-02-15 13:59:17 +01:00
parent 81463d9eb0
commit 8698cf8160
3 changed files with 28 additions and 17 deletions

View file

@ -16,21 +16,21 @@ void blit(const Frame& in_frame,
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);
const int in_row_size = in_frame.width;
const int out_row_size = out_frame.width;
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;
const int in_offset = in_box.left + (i + in_box.top) * in_row_size;
const int out_offset = out_box.left + (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) {
const std::vector<BoundingBox>& bboxes,
std::vector<BoundingBox>& packed_bboxes) {
if (bboxes.size() == 0) {
std::cerr << "No bounding box, cannot pack.\n";
return {};
@ -71,9 +71,12 @@ std::optional<Frame> pack(const Frame& in_frame,
const auto& largest = sorted_bboxes[0];
BoundingBox out_largest = {0, 0, static_cast<uint32_t>(largest.width()),
static_cast<uint32_t>(largest.height())};
packed_bboxes.clear();
packed_bboxes.push_back(out_largest);
Frame packed_frame(largest.width(), largest.height());
blit(in_frame, largest, packed_frame, out_largest);
return Frame(in_frame);
return packed_frame;
}
} // namespace freling