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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (!ret)
|
||||
@@ -68,7 +68,7 @@ bool Image::save_png(const std::string& path)
|
||||
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);
|
||||
if (!ret)
|
||||
|
||||
@@ -24,8 +24,8 @@ public:
|
||||
bool load_file(std::string filename);
|
||||
const uint8_t* data() const { return m_data.get(); }
|
||||
int size() const { return width * height * comp; }
|
||||
bool save_png(const std::string& path);
|
||||
bool save_jpg(const std::string& path, int quality);
|
||||
bool save_png(const std::string& path) const noexcept;
|
||||
bool save_jpg(const std::string& path, int quality) const noexcept;
|
||||
void create(int w, int h, uint8_t* data = nullptr)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
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,6 +983,7 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
});
|
||||
|
||||
auto brushes = abr.compute_brushes(App::I->data_path);
|
||||
App::I->ui_task([&]{
|
||||
for (const auto& b : brushes)
|
||||
{
|
||||
if (b->valid())
|
||||
@@ -976,6 +994,7 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
}
|
||||
pb->increment();
|
||||
}
|
||||
});
|
||||
|
||||
save();
|
||||
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)
|
||||
{
|
||||
mbstate_t st = {};
|
||||
std::wstring converted;
|
||||
converted.resize(str.size());
|
||||
const char* ptr = str.c_str();
|
||||
std::mbsrtowcs((wchar_t*)converted.data(), &ptr, converted.capacity(), &st);
|
||||
return converted;
|
||||
//mbstate_t st = {};
|
||||
//std::wstring converted;
|
||||
//converted.resize(str.size());
|
||||
//const char* ptr = str.c_str();
|
||||
//std::mbsrtowcs((wchar_t*)converted.data(), &ptr, converted.capacity(), &st);
|
||||
//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)
|
||||
{
|
||||
mbstate_t st = {};
|
||||
std::string converted;
|
||||
converted.resize(wstr.size());
|
||||
const wchar_t * wptr = wstr.c_str();
|
||||
std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st);
|
||||
return converted;
|
||||
//mbstate_t st = {};
|
||||
//std::string converted;
|
||||
//converted.resize(wstr.size());
|
||||
//const wchar_t * wptr = wstr.c_str();
|
||||
//std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st);
|
||||
//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)
|
||||
|
||||
Reference in New Issue
Block a user