Extract brush package import targets
This commit is contained in:
@@ -126,4 +126,34 @@ pp::foundation::Result<PpbrExportPaths> plan_ppbr_export_paths(
|
||||
return pp::foundation::Result<PpbrExportPaths>::success(std::move(paths));
|
||||
}
|
||||
|
||||
pp::foundation::Result<BrushPackageImageTargetPaths> plan_brush_package_image_target_paths(
|
||||
std::string_view data_path,
|
||||
BrushPackageImageKind kind,
|
||||
std::string_view image_name,
|
||||
std::string_view image_extension)
|
||||
{
|
||||
if (data_path.empty()) {
|
||||
return pp::foundation::Result<BrushPackageImageTargetPaths>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush package data path must not be empty"));
|
||||
}
|
||||
if (image_name.empty()) {
|
||||
return pp::foundation::Result<BrushPackageImageTargetPaths>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush package image name must not be empty"));
|
||||
}
|
||||
if (!is_word_extension(image_extension)) {
|
||||
return pp::foundation::Result<BrushPackageImageTargetPaths>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush package image extension contains unsupported characters"));
|
||||
}
|
||||
|
||||
const auto directory = kind == BrushPackageImageKind::brush_tip ? "brushes" : "patterns";
|
||||
const std::string base_path = std::string(data_path) + "/" + directory + "/" + std::string(image_name)
|
||||
+ "." + std::string(image_extension);
|
||||
|
||||
return pp::foundation::Result<BrushPackageImageTargetPaths>::success(BrushPackageImageTargetPaths {
|
||||
.image_path = base_path,
|
||||
.thumbnail_path = std::string(data_path) + "/" + directory + "/thumbs/" + std::string(image_name)
|
||||
+ "." + std::string(image_extension),
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace pp::assets
|
||||
|
||||
@@ -19,11 +19,21 @@ enum class PpbrDataDirectoryPolicy {
|
||||
override_directory,
|
||||
};
|
||||
|
||||
enum class BrushPackageImageKind {
|
||||
brush_tip,
|
||||
pattern,
|
||||
};
|
||||
|
||||
struct PpbrHeader {
|
||||
std::uint16_t major = 0;
|
||||
std::uint16_t minor = 0;
|
||||
};
|
||||
|
||||
struct BrushPackageImageTargetPaths {
|
||||
std::string image_path;
|
||||
std::string thumbnail_path;
|
||||
};
|
||||
|
||||
struct PpbrExportPaths {
|
||||
std::string package_path;
|
||||
std::string directory;
|
||||
@@ -50,4 +60,10 @@ struct PpbrExportPaths {
|
||||
bool export_data,
|
||||
PpbrDataDirectoryPolicy data_directory_policy);
|
||||
|
||||
[[nodiscard]] pp::foundation::Result<BrushPackageImageTargetPaths> plan_brush_package_image_target_paths(
|
||||
std::string_view data_path,
|
||||
BrushPackageImageKind kind,
|
||||
std::string_view image_name,
|
||||
std::string_view image_extension);
|
||||
|
||||
} // namespace pp::assets
|
||||
|
||||
@@ -876,8 +876,17 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path)
|
||||
{
|
||||
Image img;
|
||||
sr >> img;
|
||||
std::string path = App::I->data_path + "/brushes/" + img.file_name + "." + img.file_ext;
|
||||
std::string path_thumb = App::I->data_path + "/brushes/thumbs/" + img.file_name + "." + img.file_ext;
|
||||
const auto target_paths = pp::assets::plan_brush_package_image_target_paths(
|
||||
App::I->data_path,
|
||||
pp::assets::BrushPackageImageKind::brush_tip,
|
||||
img.file_name,
|
||||
img.file_ext);
|
||||
if (!target_paths) {
|
||||
LOG("import_ppbr invalid brush image target: %s", target_paths.status().message);
|
||||
return false;
|
||||
}
|
||||
const auto& path = target_paths.value().image_path;
|
||||
const auto& path_thumb = target_paths.value().thumbnail_path;
|
||||
if (!Asset::exist(path))
|
||||
{
|
||||
img.save_png(path);
|
||||
@@ -898,8 +907,17 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path)
|
||||
{
|
||||
Image img;
|
||||
sr >> img;
|
||||
std::string path = App::I->data_path + "/patterns/" + img.file_name + "." + img.file_ext;
|
||||
std::string path_thumb = App::I->data_path + "/patterns/thumbs/" + img.file_name + "." + img.file_ext;
|
||||
const auto target_paths = pp::assets::plan_brush_package_image_target_paths(
|
||||
App::I->data_path,
|
||||
pp::assets::BrushPackageImageKind::pattern,
|
||||
img.file_name,
|
||||
img.file_ext);
|
||||
if (!target_paths) {
|
||||
LOG("import_ppbr invalid pattern image target: %s", target_paths.status().message);
|
||||
return false;
|
||||
}
|
||||
const auto& path = target_paths.value().image_path;
|
||||
const auto& path_thumb = target_paths.value().thumbnail_path;
|
||||
if (!Asset::exist(path))
|
||||
{
|
||||
img.save_png(path);
|
||||
@@ -970,8 +988,17 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
auto ii = abr.m_samples.begin();
|
||||
std::advance(ii, i);
|
||||
const auto& samp = *ii;
|
||||
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";
|
||||
const auto target_paths = pp::assets::plan_brush_package_image_target_paths(
|
||||
App::I->data_path,
|
||||
pp::assets::BrushPackageImageKind::brush_tip,
|
||||
samp.first,
|
||||
"png");
|
||||
if (!target_paths) {
|
||||
LOG("import_abr invalid brush image target: %s", target_paths.status().message);
|
||||
return;
|
||||
}
|
||||
const auto& path_high = target_paths.value().image_path;
|
||||
const auto& path_thumb = target_paths.value().thumbnail_path;
|
||||
auto padded = samp.second->resize_squared(glm::u8vec4(255));
|
||||
//auto high = padded.resize_power2();
|
||||
//high.save(path_high);
|
||||
@@ -987,8 +1014,17 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
auto ii = abr.m_patterns.begin();
|
||||
std::advance(ii, i);
|
||||
const auto& patt = *ii;
|
||||
std::string path_high = App::I->data_path + "/patterns/" + patt.first + ".png";
|
||||
std::string path_thumb = App::I->data_path + "/patterns/thumbs/" + patt.first + ".png";
|
||||
const auto target_paths = pp::assets::plan_brush_package_image_target_paths(
|
||||
App::I->data_path,
|
||||
pp::assets::BrushPackageImageKind::pattern,
|
||||
patt.first,
|
||||
"png");
|
||||
if (!target_paths) {
|
||||
LOG("import_abr invalid pattern image target: %s", target_paths.status().message);
|
||||
return;
|
||||
}
|
||||
const auto& path_high = target_paths.value().image_path;
|
||||
const auto& path_thumb = target_paths.value().thumbnail_path;
|
||||
patt.second->save_png(path_high);
|
||||
auto thumb = patt.second->resize(64, 64);
|
||||
thumb.save_png(path_thumb);
|
||||
|
||||
Reference in New Issue
Block a user