save header and brush previews in same name folder when exporting ppbr
This commit is contained in:
@@ -686,6 +686,17 @@ void NodePanelBrushPreset::add_brush(std::shared_ptr<Brush> brush)
|
||||
|
||||
bool NodePanelBrushPreset::export_ppbr(const std::string& path, const Image& header_image)
|
||||
{
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
if (!std::regex_search(path, m, r))
|
||||
return false;
|
||||
auto base = m[1].str();
|
||||
auto name = m[2].str();
|
||||
auto ext = m[3].str();
|
||||
std::string out_path = base + "/" + name;
|
||||
|
||||
Asset::create_dir(out_path);
|
||||
|
||||
std::ofstream f(path, std::ios::binary);
|
||||
if (f.good())
|
||||
{
|
||||
@@ -727,7 +738,10 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const Image& hea
|
||||
|
||||
// header image
|
||||
if (has_header_image)
|
||||
sw << header_image;
|
||||
{
|
||||
sw << header_image;
|
||||
header_image.save_jpg(out_path + "/header.jpg", 75);
|
||||
}
|
||||
|
||||
pb->increment();
|
||||
|
||||
@@ -735,6 +749,7 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const Image& hea
|
||||
sw.wu32((int)m_container->m_children.size());
|
||||
auto pr = std::make_unique<NodeStrokePreview>();
|
||||
pr->m_preview_size = pr->m_size = { 256, 128 };
|
||||
int thumb_counter = 0;
|
||||
for (auto& c : m_container->m_children)
|
||||
{
|
||||
auto bpi = std::static_pointer_cast<NodeBrushPresetItem>(c);
|
||||
@@ -743,6 +758,8 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const Image& hea
|
||||
Image img = pr->render_to_image();
|
||||
img.file_name = pr->m_brush->m_name;
|
||||
sw << img;
|
||||
img.save_jpg(fmt::format(out_path + "/thumb-{:04d}.jpg", thumb_counter), 75);
|
||||
thumb_counter++;
|
||||
pb->increment();
|
||||
}
|
||||
|
||||
@@ -966,16 +983,18 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
});
|
||||
|
||||
auto brushes = abr.compute_brushes(App::I->data_path);
|
||||
for (const auto& b : brushes)
|
||||
{
|
||||
if (b->valid())
|
||||
App::I->ui_task([&]{
|
||||
for (const auto& b : brushes)
|
||||
{
|
||||
LOG("add preset %s", b->m_name.c_str());
|
||||
for (auto p : s_panels)
|
||||
p->add_brush(b);
|
||||
if (b->valid())
|
||||
{
|
||||
LOG("add preset %s", b->m_name.c_str());
|
||||
for (auto p : s_panels)
|
||||
p->add_brush(b);
|
||||
}
|
||||
pb->increment();
|
||||
}
|
||||
pb->increment();
|
||||
}
|
||||
});
|
||||
|
||||
save();
|
||||
pb->destroy();
|
||||
|
||||
Reference in New Issue
Block a user