Plan depth export through document renderer

This commit is contained in:
2026-06-05 21:03:27 +02:00
parent 3c36be4b43
commit 3be7171010
10 changed files with 443 additions and 14 deletions

View File

@@ -37,10 +37,20 @@ struct DocumentCubeFaceExportTarget {
std::size_t face_count = 0;
};
struct DocumentDepthExportTarget {
std::string image_path;
std::string depth_path;
};
struct DocumentCubeFaceExportPayload {
std::span<const std::byte> bytes;
};
struct DocumentDepthExportPayload {
std::span<const std::byte> image_bytes;
std::span<const std::byte> depth_bytes;
};
struct DocumentExportCollectionPngPayload {
std::string path_suffix;
std::span<const std::byte> bytes;
@@ -195,6 +205,16 @@ public:
virtual void publish_exported_image(std::string_view path) = 0;
};
class DocumentDepthExportWriteServices {
public:
virtual ~DocumentDepthExportWriteServices() = default;
virtual pp::foundation::Status write_binary_file(
std::string_view path,
std::span<const std::byte> bytes) = 0;
virtual void publish_exported_image(std::string_view path) = 0;
};
class DocumentExportCollectionWriteServices {
public:
virtual ~DocumentExportCollectionWriteServices() = default;
@@ -623,6 +643,34 @@ document_cube_face_export_names() noexcept
return pp::foundation::Result<DocumentCubeFaceExportTarget>::success(std::move(target));
}
[[nodiscard]] inline pp::foundation::Result<DocumentDepthExportTarget> make_document_depth_export_target(
std::string_view work_directory,
std::string_view document_name)
{
if (work_directory.empty()) {
return pp::foundation::Result<DocumentDepthExportTarget>::failure(
pp::foundation::Status::invalid_argument("work directory must not be empty"));
}
if (document_name.empty()) {
return pp::foundation::Result<DocumentDepthExportTarget>::failure(
pp::foundation::Status::invalid_argument("document name must not be empty"));
}
DocumentDepthExportTarget target;
target.image_path.reserve(work_directory.size() + document_name.size() + 5U);
target.image_path += work_directory;
target.image_path += "/";
target.image_path += document_name;
target.image_path += ".png";
target.depth_path.reserve(work_directory.size() + document_name.size() + 11U);
target.depth_path += work_directory;
target.depth_path += "/";
target.depth_path += document_name;
target.depth_path += "_depth.png";
return pp::foundation::Result<DocumentDepthExportTarget>::success(std::move(target));
}
[[nodiscard]] inline std::string document_export_two_digit_index(std::size_t index)
{
auto value = std::to_string(index);
@@ -706,6 +754,33 @@ document_cube_face_export_names() noexcept
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_document_depth_export_write(
const DocumentDepthExportTarget& target,
DocumentDepthExportPayload payload,
DocumentDepthExportWriteServices& services)
{
if (target.image_path.empty() || target.depth_path.empty()) {
return pp::foundation::Status::invalid_argument("depth export target requires image and depth paths");
}
if (payload.image_bytes.empty() || payload.depth_bytes.empty()) {
return pp::foundation::Status::invalid_argument("depth export payload requires image and depth bytes");
}
const auto image_status = services.write_binary_file(target.image_path, payload.image_bytes);
if (!image_status.ok()) {
return image_status;
}
services.publish_exported_image(target.image_path);
const auto depth_status = services.write_binary_file(target.depth_path, payload.depth_bytes);
if (!depth_status.ok()) {
return depth_status;
}
services.publish_exported_image(target.depth_path);
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_collection_write(
const DocumentExportCollectionTarget& target,
std::span<const DocumentExportCollectionPngPayload> payloads,