save header and brush previews in same name folder when exporting ppbr
This commit is contained in:
@@ -60,7 +60,7 @@ bool Image::load_file(std::string filename)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::save_png(const std::string& path)
|
bool Image::save_png(const std::string& path) const noexcept
|
||||||
{
|
{
|
||||||
bool ret = stbi_write_png(path.c_str(), width, height, comp, data(), 0);
|
bool ret = stbi_write_png(path.c_str(), width, height, comp, data(), 0);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
@@ -68,7 +68,7 @@ bool Image::save_png(const std::string& path)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::save_jpg(const std::string& path, int quality)
|
bool Image::save_jpg(const std::string& path, int quality) const noexcept
|
||||||
{
|
{
|
||||||
bool ret = stbi_write_jpg(path.c_str(), width, height, comp, data(), quality);
|
bool ret = stbi_write_jpg(path.c_str(), width, height, comp, data(), quality);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public:
|
|||||||
bool load_file(std::string filename);
|
bool load_file(std::string filename);
|
||||||
const uint8_t* data() const { return m_data.get(); }
|
const uint8_t* data() const { return m_data.get(); }
|
||||||
int size() const { return width * height * comp; }
|
int size() const { return width * height * comp; }
|
||||||
bool save_png(const std::string& path);
|
bool save_png(const std::string& path) const noexcept;
|
||||||
bool save_jpg(const std::string& path, int quality);
|
bool save_jpg(const std::string& path, int quality) const noexcept;
|
||||||
void create(int w, int h, uint8_t* data = nullptr)
|
void create(int w, int h, uint8_t* data = nullptr)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
|
|||||||
@@ -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)
|
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);
|
std::ofstream f(path, std::ios::binary);
|
||||||
if (f.good())
|
if (f.good())
|
||||||
{
|
{
|
||||||
@@ -727,7 +738,10 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const Image& hea
|
|||||||
|
|
||||||
// header image
|
// header image
|
||||||
if (has_header_image)
|
if (has_header_image)
|
||||||
|
{
|
||||||
sw << header_image;
|
sw << header_image;
|
||||||
|
header_image.save_jpg(out_path + "/header.jpg", 75);
|
||||||
|
}
|
||||||
|
|
||||||
pb->increment();
|
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());
|
sw.wu32((int)m_container->m_children.size());
|
||||||
auto pr = std::make_unique<NodeStrokePreview>();
|
auto pr = std::make_unique<NodeStrokePreview>();
|
||||||
pr->m_preview_size = pr->m_size = { 256, 128 };
|
pr->m_preview_size = pr->m_size = { 256, 128 };
|
||||||
|
int thumb_counter = 0;
|
||||||
for (auto& c : m_container->m_children)
|
for (auto& c : m_container->m_children)
|
||||||
{
|
{
|
||||||
auto bpi = std::static_pointer_cast<NodeBrushPresetItem>(c);
|
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();
|
Image img = pr->render_to_image();
|
||||||
img.file_name = pr->m_brush->m_name;
|
img.file_name = pr->m_brush->m_name;
|
||||||
sw << img;
|
sw << img;
|
||||||
|
img.save_jpg(fmt::format(out_path + "/thumb-{:04d}.jpg", thumb_counter), 75);
|
||||||
|
thumb_counter++;
|
||||||
pb->increment();
|
pb->increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -966,16 +983,18 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto brushes = abr.compute_brushes(App::I->data_path);
|
auto brushes = abr.compute_brushes(App::I->data_path);
|
||||||
for (const auto& b : brushes)
|
App::I->ui_task([&]{
|
||||||
{
|
for (const auto& b : brushes)
|
||||||
if (b->valid())
|
|
||||||
{
|
{
|
||||||
LOG("add preset %s", b->m_name.c_str());
|
if (b->valid())
|
||||||
for (auto p : s_panels)
|
{
|
||||||
p->add_brush(b);
|
LOG("add preset %s", b->m_name.c_str());
|
||||||
|
for (auto p : s_panels)
|
||||||
|
p->add_brush(b);
|
||||||
|
}
|
||||||
|
pb->increment();
|
||||||
}
|
}
|
||||||
pb->increment();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
save();
|
save();
|
||||||
pb->destroy();
|
pb->destroy();
|
||||||
|
|||||||
30
src/util.cpp
30
src/util.cpp
@@ -571,22 +571,28 @@ std::string unescape(const std::string& s)
|
|||||||
|
|
||||||
std::wstring str2wstr(const std::string& str)
|
std::wstring str2wstr(const std::string& str)
|
||||||
{
|
{
|
||||||
mbstate_t st = {};
|
//mbstate_t st = {};
|
||||||
std::wstring converted;
|
//std::wstring converted;
|
||||||
converted.resize(str.size());
|
//converted.resize(str.size());
|
||||||
const char* ptr = str.c_str();
|
//const char* ptr = str.c_str();
|
||||||
std::mbsrtowcs((wchar_t*)converted.data(), &ptr, converted.capacity(), &st);
|
//std::mbsrtowcs((wchar_t*)converted.data(), &ptr, converted.capacity(), &st);
|
||||||
return converted;
|
//return converted;
|
||||||
|
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||||
|
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||||
|
return converterX.from_bytes(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string wstr2str(const std::wstring & wstr)
|
std::string wstr2str(const std::wstring & wstr)
|
||||||
{
|
{
|
||||||
mbstate_t st = {};
|
//mbstate_t st = {};
|
||||||
std::string converted;
|
//std::string converted;
|
||||||
converted.resize(wstr.size());
|
//converted.resize(wstr.size());
|
||||||
const wchar_t * wptr = wstr.c_str();
|
//const wchar_t * wptr = wstr.c_str();
|
||||||
std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st);
|
//std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st);
|
||||||
return converted;
|
//return converted;
|
||||||
|
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||||
|
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||||
|
return converterX.to_bytes(wstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool str_iequals(const std::string& a, const std::string& b)
|
bool str_iequals(const std::string& a, const std::string& b)
|
||||||
|
|||||||
Reference in New Issue
Block a user