make brushes square when imported from ABR

This commit is contained in:
2019-02-11 00:45:53 +01:00
parent 6e41263600
commit 97c3ac0d19
5 changed files with 10 additions and 8 deletions

View File

@@ -116,7 +116,7 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
b->m_tip_spacing = samp->value<UnitFloat>("Spcn") * 0.01f;
b->m_tip_flow = .25f;
b->m_tip_opacity = 1.f;
b->m_tip_angle = glm::radians(samp->value<UnitFloat>("Angl"));
b->m_tip_angle = samp->value<UnitFloat>("Angl") / 360.f + 0.5f; // [-180,180] -> [0, 1]
//b->m_tip_mix = i.m_tip_mix;
//b->m_tip_stencil = i.m_tip_stencil;
b->m_tip_wet = p->value<UnitFloat>("Wtdg");

View File

@@ -207,7 +207,7 @@ void App::initShaders()
"uniform sampler2D tex;\n"
"uniform sampler2D tex_stroke;\n"
"uniform sampler2D tex_mask;\n"
"uniform sampler2D tex_stencil;\n"
//"uniform sampler2D tex_stencil;\n"
"uniform mediump float alpha;\n"
"uniform mediump float stroke_alpha;\n"
"uniform mediump int blend_mode;\n"

View File

@@ -120,7 +120,7 @@ Image Image::resize_power2() const
return resize(w, h);
}
Image Image::resize_squared() const
Image Image::resize_squared(const glm::u8vec4& bg) const
{
Image ret;
if (width == height)
@@ -146,7 +146,7 @@ Image Image::resize_squared() const
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));
std::fill_n(ptr_dst, size * size, bg);
for (int y = 0; y < height; y++)
std::copy_n(ptr_src + y * width, width, ptr_dst + pad_x + (y + pad_y) * ret.width);
}

View File

@@ -36,5 +36,5 @@ public:
void create() { m_data = std::make_unique<uint8_t[]>(size()); }
Image resize(int w, int h) const;
Image resize_power2() const;
Image resize_squared() const;
Image resize_squared(const glm::u8vec4& bg) const;
};

View File

@@ -77,8 +77,10 @@ void NodePanelBrush::init()
{
std::string path_high = App::I.data_path + "/brushes/" + samp.first + ".png";
std::string path_thumb = App::I.data_path + "/brushes/thumbs/" + samp.first + ".png";
samp.second->save(path_high);
auto thumb = samp.second->resize(64, 64);
auto padded = samp.second->resize_squared(glm::u8vec4(255));
auto high = padded.resize_power2();
high.save(path_high);
auto thumb = padded.resize(64, 64);
thumb.save(path_thumb);
async_start();
@@ -123,7 +125,7 @@ void NodePanelBrush::init()
std::string path_high = App::I.data_path + "/brushes/" + name + ".png";
std::string path_thumb = App::I.data_path + "/brushes/thumbs/" + name + ".png";
img = img.resize_squared();
img = img.resize_squared(glm::u8vec4(255));
img.gayscale_alpha();
auto thumb = img.resize(64, 64);