Export layer collections through paint renderer
This commit is contained in:
@@ -152,7 +152,9 @@ public:
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
class FakeDocumentCubeFaceExportWriteServices final : public pp::app::DocumentCubeFaceExportWriteServices {
|
||||
class FakeDocumentCubeFaceExportWriteServices final
|
||||
: public pp::app::DocumentCubeFaceExportWriteServices
|
||||
, public pp::app::DocumentExportCollectionWriteServices {
|
||||
public:
|
||||
pp::foundation::Status write_binary_file(
|
||||
std::string_view path,
|
||||
@@ -347,6 +349,96 @@ void cube_face_export_writer_rejects_malformed_inputs(pp::tests::Harness& harnes
|
||||
PP_EXPECT(harness, services.publish_calls == 0);
|
||||
}
|
||||
|
||||
void collection_export_builds_legacy_path_suffixes(pp::tests::Harness& harness)
|
||||
{
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::make_document_layer_export_path_suffix(0, "Base") == "-layer00-Base.png");
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::make_document_layer_export_path_suffix(12, "Paint") == "-layer12-Paint.png");
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::make_document_animation_frame_export_path_suffix(0) == "-00.png");
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::make_document_animation_frame_export_path_suffix(125) == "-125.png");
|
||||
}
|
||||
|
||||
void collection_export_writer_writes_and_publishes_payloads_in_order(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_export_collection_target("D:/Paint", "demo", "_layers");
|
||||
const std::array<std::byte, 2> base_bytes {};
|
||||
const std::array<std::byte, 3> paint_bytes {};
|
||||
const pp::app::DocumentExportCollectionPngPayload payloads[] {
|
||||
{
|
||||
.path_suffix = pp::app::make_document_layer_export_path_suffix(0, "Base"),
|
||||
.bytes = std::span<const std::byte>(base_bytes),
|
||||
},
|
||||
{
|
||||
.path_suffix = pp::app::make_document_layer_export_path_suffix(1, "Paint"),
|
||||
.bytes = std::span<const std::byte>(paint_bytes),
|
||||
},
|
||||
};
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_export_collection_write(target.value(), payloads, services).ok());
|
||||
PP_EXPECT(harness, services.write_calls == 2);
|
||||
PP_EXPECT(harness, services.publish_calls == 2);
|
||||
PP_EXPECT(harness, services.total_bytes == 5U);
|
||||
PP_EXPECT(harness, services.last_path == "D:/Paint/demo_layers/demo-layer01-Paint.png");
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order
|
||||
== "write:D:/Paint/demo_layers/demo-layer00-Base.png;"
|
||||
"publish:D:/Paint/demo_layers/demo-layer00-Base.png;"
|
||||
"write:D:/Paint/demo_layers/demo-layer01-Paint.png;"
|
||||
"publish:D:/Paint/demo_layers/demo-layer01-Paint.png;");
|
||||
}
|
||||
|
||||
void collection_export_writer_rejects_malformed_inputs(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_export_collection_target("D:/Paint", "demo", "_frames");
|
||||
const std::array<std::byte, 2> bytes {};
|
||||
pp::app::DocumentExportCollectionPngPayload payloads[] {
|
||||
{
|
||||
.path_suffix = pp::app::make_document_animation_frame_export_path_suffix(0),
|
||||
.bytes = std::span<const std::byte>(bytes),
|
||||
},
|
||||
};
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
auto empty_stem = target.value();
|
||||
empty_stem.stem_path.clear();
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_collection_write(empty_stem, payloads, services).ok());
|
||||
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_collection_write(
|
||||
target.value(),
|
||||
std::span<const pp::app::DocumentExportCollectionPngPayload>(),
|
||||
services)
|
||||
.ok());
|
||||
|
||||
payloads[0].path_suffix.clear();
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_collection_write(target.value(), payloads, services).ok());
|
||||
payloads[0].path_suffix = pp::app::make_document_animation_frame_export_path_suffix(0);
|
||||
payloads[0].bytes = {};
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_collection_write(target.value(), payloads, services).ok());
|
||||
PP_EXPECT(harness, services.write_calls == 0);
|
||||
PP_EXPECT(harness, services.publish_calls == 0);
|
||||
}
|
||||
|
||||
void video_export_builds_suggested_name(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto timelapse = pp::app::make_document_export_suggested_name("demo", "-timelapse");
|
||||
@@ -891,6 +983,11 @@ int main()
|
||||
"cube face export writer stops before publish on write failure",
|
||||
cube_face_export_writer_stops_before_publish_on_write_failure);
|
||||
harness.run("cube face export writer rejects malformed inputs", cube_face_export_writer_rejects_malformed_inputs);
|
||||
harness.run("collection export builds legacy path suffixes", collection_export_builds_legacy_path_suffixes);
|
||||
harness.run(
|
||||
"collection export writer writes and publishes payloads in order",
|
||||
collection_export_writer_writes_and_publishes_payloads_in_order);
|
||||
harness.run("collection export writer rejects malformed inputs", collection_export_writer_rejects_malformed_inputs);
|
||||
harness.run("video export builds suggested name", video_export_builds_suggested_name);
|
||||
harness.run("collection export target plan selects platform destination", collection_export_target_plan_selects_platform_destination);
|
||||
harness.run("export success dialog plans image destinations", export_success_dialog_plans_image_destinations);
|
||||
|
||||
@@ -46,6 +46,60 @@ bool near(float a, float b)
|
||||
return std::fabs(a - b) < 0.0001F;
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> solid_rgba8(
|
||||
std::uint32_t width,
|
||||
std::uint32_t height,
|
||||
std::uint8_t r,
|
||||
std::uint8_t g,
|
||||
std::uint8_t b,
|
||||
std::uint8_t a)
|
||||
{
|
||||
std::vector<std::uint8_t> pixels(
|
||||
static_cast<std::size_t>(width) * height * pp::document::rgba8_components);
|
||||
for (std::size_t i = 0; i < pixels.size(); i += pp::document::rgba8_components) {
|
||||
pixels[i] = r;
|
||||
pixels[i + 1U] = g;
|
||||
pixels[i + 2U] = b;
|
||||
pixels[i + 3U] = a;
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
|
||||
LayerFacePixels solid_face_payload(
|
||||
std::uint32_t face_index,
|
||||
std::uint32_t width,
|
||||
std::uint32_t height,
|
||||
std::uint8_t r,
|
||||
std::uint8_t g,
|
||||
std::uint8_t b,
|
||||
std::uint8_t a)
|
||||
{
|
||||
return LayerFacePixels {
|
||||
.face_index = face_index,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.rgba8 = solid_rgba8(width, height, r, g, b, a),
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<LayerFacePixels> solid_cube_faces(
|
||||
std::uint32_t width,
|
||||
std::uint32_t height,
|
||||
std::uint8_t r,
|
||||
std::uint8_t g,
|
||||
std::uint8_t b,
|
||||
std::uint8_t a)
|
||||
{
|
||||
std::vector<LayerFacePixels> faces;
|
||||
faces.reserve(pp::document::cube_face_count);
|
||||
for (std::uint32_t face_index = 0; face_index < pp::document::cube_face_count; ++face_index) {
|
||||
faces.push_back(solid_face_payload(face_index, width, height, r, g, b, a));
|
||||
}
|
||||
return faces;
|
||||
}
|
||||
|
||||
void composites_visible_layer_with_opacity(pp::tests::Harness& h)
|
||||
{
|
||||
std::vector<Rgba> destination {
|
||||
@@ -848,6 +902,140 @@ void exports_document_frame_as_equirectangular_png(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, decoded.value().pixels[bottom + 2U] == 255U);
|
||||
}
|
||||
|
||||
void exports_document_layers_as_equirectangular_pngs(pp::tests::Harness& h)
|
||||
{
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
};
|
||||
const AnimationFrame base_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = solid_cube_faces(1, 4, 255, 0, 0, 255),
|
||||
},
|
||||
};
|
||||
const AnimationFrame hidden_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = solid_cube_faces(1, 4, 0, 0, 255, 255),
|
||||
},
|
||||
};
|
||||
const DocumentLayerConfig layers[] {
|
||||
{
|
||||
.name = "Base",
|
||||
.frames = std::span<const AnimationFrame>(base_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "HiddenPaint",
|
||||
.visible = false,
|
||||
.opacity = 0.0F,
|
||||
.frames = std::span<const AnimationFrame>(hidden_frames, 1),
|
||||
},
|
||||
};
|
||||
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
|
||||
.width = 1,
|
||||
.height = 4,
|
||||
.layers = std::span<const DocumentLayerConfig>(layers, 2),
|
||||
.frames = std::span<const AnimationFrame>(root_frames, 1),
|
||||
.selection_masks = {},
|
||||
});
|
||||
PP_EXPECT(h, document);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto exported = pp::paint_renderer::export_document_layers_equirectangular_pngs(
|
||||
pp::paint_renderer::DocumentLayerEquirectangularPngExportRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 0,
|
||||
});
|
||||
PP_EXPECT(h, exported);
|
||||
if (!exported) {
|
||||
return;
|
||||
}
|
||||
|
||||
PP_EXPECT(h, exported.value().layer_count == 2U);
|
||||
PP_EXPECT(h, exported.value().layers.size() == 2U);
|
||||
PP_EXPECT(h, exported.value().layers[0].layer_name == "Base");
|
||||
PP_EXPECT(h, exported.value().layers[1].layer_name == "HiddenPaint");
|
||||
PP_EXPECT(h, exported.value().layers[0].face_payload_count == pp::document::cube_face_count);
|
||||
PP_EXPECT(h, exported.value().layers[1].face_payload_count == pp::document::cube_face_count);
|
||||
PP_EXPECT(h, exported.value().encoded_bytes > 0U);
|
||||
|
||||
const auto decoded = pp::assets::decode_png_rgba8(exported.value().layers[1].png);
|
||||
PP_EXPECT(h, decoded);
|
||||
if (!decoded) {
|
||||
return;
|
||||
}
|
||||
|
||||
PP_EXPECT(h, decoded.value().width == 4U);
|
||||
PP_EXPECT(h, decoded.value().height == 8U);
|
||||
PP_EXPECT(h, decoded.value().pixels[0] == 0U);
|
||||
PP_EXPECT(h, decoded.value().pixels[1] == 0U);
|
||||
PP_EXPECT(h, decoded.value().pixels[2] == 255U);
|
||||
}
|
||||
|
||||
void exports_document_animation_frames_as_equirectangular_pngs(pp::tests::Harness& h)
|
||||
{
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
};
|
||||
const AnimationFrame layer_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = solid_cube_faces(1, 4, 255, 0, 0, 255),
|
||||
},
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = solid_cube_faces(1, 4, 0, 255, 0, 255),
|
||||
},
|
||||
};
|
||||
const DocumentLayerConfig layers[] {
|
||||
{
|
||||
.name = "Paint",
|
||||
.frames = std::span<const AnimationFrame>(layer_frames, 2),
|
||||
},
|
||||
};
|
||||
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
|
||||
.width = 1,
|
||||
.height = 4,
|
||||
.layers = std::span<const DocumentLayerConfig>(layers, 1),
|
||||
.frames = std::span<const AnimationFrame>(root_frames, 2),
|
||||
.selection_masks = {},
|
||||
});
|
||||
PP_EXPECT(h, document);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto exported = pp::paint_renderer::export_document_animation_frames_equirectangular_pngs(
|
||||
pp::paint_renderer::DocumentAnimationFrameEquirectangularPngExportRequest {
|
||||
.document = &document.value(),
|
||||
});
|
||||
PP_EXPECT(h, exported);
|
||||
if (!exported) {
|
||||
return;
|
||||
}
|
||||
|
||||
PP_EXPECT(h, exported.value().frame_count == 2U);
|
||||
PP_EXPECT(h, exported.value().frames.size() == 2U);
|
||||
PP_EXPECT(h, exported.value().frames[0].frame_index == 0U);
|
||||
PP_EXPECT(h, exported.value().frames[1].frame_index == 1U);
|
||||
PP_EXPECT(h, exported.value().encoded_bytes > 0U);
|
||||
|
||||
const auto decoded = pp::assets::decode_png_rgba8(exported.value().frames[1].png);
|
||||
PP_EXPECT(h, decoded);
|
||||
if (!decoded) {
|
||||
return;
|
||||
}
|
||||
|
||||
PP_EXPECT(h, decoded.value().width == 4U);
|
||||
PP_EXPECT(h, decoded.value().height == 8U);
|
||||
PP_EXPECT(h, decoded.value().pixels[0] == 0U);
|
||||
PP_EXPECT(h, decoded.value().pixels[1] == 255U);
|
||||
PP_EXPECT(h, decoded.value().pixels[2] == 0U);
|
||||
}
|
||||
|
||||
void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
{
|
||||
RecordingRenderDevice device;
|
||||
@@ -858,6 +1046,10 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
DocumentFrameCompositeRequest {});
|
||||
const auto no_document_equirect = pp::paint_renderer::export_document_frame_equirectangular_png(
|
||||
DocumentFrameCompositeRequest {});
|
||||
const auto no_document_layers = pp::paint_renderer::export_document_layers_equirectangular_pngs(
|
||||
pp::paint_renderer::DocumentLayerEquirectangularPngExportRequest {});
|
||||
const auto no_document_frames = pp::paint_renderer::export_document_animation_frames_equirectangular_pngs(
|
||||
pp::paint_renderer::DocumentAnimationFrameEquirectangularPngExportRequest {});
|
||||
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
@@ -892,6 +1084,10 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, no_document_readiness.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !no_document_equirect.ok());
|
||||
PP_EXPECT(h, no_document_equirect.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !no_document_layers.ok());
|
||||
PP_EXPECT(h, no_document_layers.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !no_document_frames.ok());
|
||||
PP_EXPECT(h, no_document_frames.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !bad_frame.ok());
|
||||
PP_EXPECT(h, bad_frame.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_frame_readiness.ok());
|
||||
@@ -1248,6 +1444,10 @@ int main()
|
||||
harness.run("exports_document_frame_faces_as_pngs", exports_document_frame_faces_as_pngs);
|
||||
harness.run("prepares_document_frame_export_readiness_report", prepares_document_frame_export_readiness_report);
|
||||
harness.run("exports_document_frame_as_equirectangular_png", exports_document_frame_as_equirectangular_png);
|
||||
harness.run("exports_document_layers_as_equirectangular_pngs", exports_document_layers_as_equirectangular_pngs);
|
||||
harness.run(
|
||||
"exports_document_animation_frames_as_equirectangular_pngs",
|
||||
exports_document_animation_frames_as_equirectangular_pngs);
|
||||
harness.run("document_frame_upload_rejects_invalid_requests", document_frame_upload_rejects_invalid_requests);
|
||||
harness.run("detects_feedback_requirements", detects_feedback_requirements);
|
||||
harness.run("plans_stroke_composite_paths", plans_stroke_composite_paths);
|
||||
|
||||
Reference in New Issue
Block a user