add export layers, export png, import brush padding

This commit is contained in:
2019-02-04 00:08:31 +01:00
parent a193666f4a
commit 24a6d0bae9
10 changed files with 266 additions and 65 deletions

View File

@@ -59,6 +59,18 @@ void Image::flip()
std::swap(m_data, flipped);
}
void Image::gayscale_alpha()
{
int np = width * height;
auto ptr = reinterpret_cast<glm::u8vec4*>(m_data.get());
for (int i = 0; i < np; i++)
{
auto& c = ptr[i];
c.g = c.b = c.r = 255 - c.a;
c.a = 255;
}
}
Image Image::resize(int w, int h) const
{
Image ret;
@@ -90,3 +102,50 @@ Image Image::resize(int w, int h) const
}
return ret;
}
Image Image::resize_power2() const
{
int w = pow(2, ceil(log(width) / log(2)));
int h = pow(2, ceil(log(height) / log(2)));
if (w == width && h == height)
{
Image i;
i.create(width, height);
std::copy(m_data.get(), m_data.get() + width * height * comp, i.m_data.get());
return i;
}
return resize(w, h);
}
Image Image::resize_squared() const
{
Image ret;
if (width == height)
{
ret.create(width, height);
std::copy(m_data.get(), m_data.get() + width * height * comp, ret.m_data.get());
}
else
{
int pad_x = 0;
int pad_y = 0;
int size = 0;
if (height > width)
{
size = height;
pad_x = (size - width) / 2;
}
else
{
size = width;
pad_y = (size - height) / 2;
}
ret.create(size, size);
auto ptr_src = reinterpret_cast<glm::u8vec4*>(m_data.get());
auto ptr_dst = reinterpret_cast<glm::u8vec4*>(ret.m_data.get());
std::fill_n(ptr_dst, size * size, glm::u8vec4(0));
for (int y = 0; y < height; y++)
std::copy_n(ptr_src + y * width, width, ptr_dst + pad_x + (y + pad_y) * ret.width);
}
return ret;
}