Export document frame faces as PNGs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "assets/image_pixels.h"
|
||||
#include "paint_renderer/compositor.h"
|
||||
#include "renderer_api/recording_renderer.h"
|
||||
#include "test_harness.h"
|
||||
@@ -597,6 +598,73 @@ void records_document_frame_upload_report(pp::tests::Harness& h)
|
||||
}
|
||||
}
|
||||
|
||||
void exports_document_frame_faces_as_pngs(pp::tests::Harness& h)
|
||||
{
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
};
|
||||
const AnimationFrame layer_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = {
|
||||
LayerFacePixels {
|
||||
.face_index = 4,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.rgba8 = { 64, 128, 255, 255 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const DocumentLayerConfig layers[] {
|
||||
{
|
||||
.name = "Paint",
|
||||
.frames = std::span<const AnimationFrame>(layer_frames, 1),
|
||||
},
|
||||
};
|
||||
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.layers = std::span<const DocumentLayerConfig>(layers, 1),
|
||||
.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_frame_face_pngs(
|
||||
pp::paint_renderer::DocumentFrameCompositeRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 0,
|
||||
.clear_color = {},
|
||||
});
|
||||
|
||||
PP_EXPECT(h, exported);
|
||||
if (!exported) {
|
||||
return;
|
||||
}
|
||||
|
||||
PP_EXPECT(h, exported.value().face_count == pp::document::cube_face_count);
|
||||
PP_EXPECT(h, exported.value().encoded_bytes > 0U);
|
||||
PP_EXPECT(h, exported.value().composite.face_payload_count == 1U);
|
||||
|
||||
const auto decoded = pp::assets::decode_png_rgba8(exported.value().face_pngs[4]);
|
||||
PP_EXPECT(h, decoded);
|
||||
if (decoded) {
|
||||
PP_EXPECT(h, decoded.value().width == 1U);
|
||||
PP_EXPECT(h, decoded.value().height == 1U);
|
||||
PP_EXPECT(h, decoded.value().pixels.size() == 4U);
|
||||
PP_EXPECT(h, decoded.value().pixels[0] == 64U);
|
||||
PP_EXPECT(h, decoded.value().pixels[1] == 128U);
|
||||
PP_EXPECT(h, decoded.value().pixels[2] == 255U);
|
||||
PP_EXPECT(h, decoded.value().pixels[3] == 255U);
|
||||
}
|
||||
}
|
||||
|
||||
void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
{
|
||||
RecordingRenderDevice device;
|
||||
@@ -979,6 +1047,7 @@ int main()
|
||||
harness.run("document_frame_composite_rejects_invalid_requests", document_frame_composite_rejects_invalid_requests);
|
||||
harness.run("uploads_document_frame_faces_to_renderer_api", uploads_document_frame_faces_to_renderer_api);
|
||||
harness.run("records_document_frame_upload_report", records_document_frame_upload_report);
|
||||
harness.run("exports_document_frame_faces_as_pngs", exports_document_frame_faces_as_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