improving actions history
This commit is contained in:
45
src/canvas_layer.cpp
Normal file
45
src/canvas_layer.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "pch.h"
|
||||
#include "canvas_layer.h"
|
||||
|
||||
void Layer::Snapshot::create(int w, int h)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
image[i] = std::make_unique<uint8_t[]>(w * h * 4);
|
||||
std::fill_n(image[i].get(), w * h * 4, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Layer::Snapshot::clear()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_dirty_face[i] = false;
|
||||
m_dirty_box[i] = glm::vec4(0);
|
||||
std::fill_n(image[i].get(), width * height * 4, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Layer::Snapshot::optimize()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (!m_dirty_face[i] || !image[i])
|
||||
continue;
|
||||
auto data = reinterpret_cast<glm::u8vec4*>(image[i].get());
|
||||
glm::ivec2 bbmin(width, height);
|
||||
glm::ivec2 bbmax(0);
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
if (data[x + y * width].a > 0)
|
||||
{
|
||||
bbmin = glm::min(bbmin, { x, y });
|
||||
bbmax = glm::max(bbmax, { x + 1, y + 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
//glm::vec2 bbsz = bbmax - bbmin;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user