Export equirectangular PNGs through paint renderer

This commit is contained in:
2026-06-05 20:31:35 +02:00
parent ebc84373e6
commit 77268a28fb
8 changed files with 378 additions and 19 deletions

View File

@@ -734,6 +734,120 @@ void prepares_document_frame_export_readiness_report(pp::tests::Harness& h)
}
}
void exports_document_frame_as_equirectangular_png(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 = 0,
.x = 0,
.y = 0,
.width = 1,
.height = 4,
.rgba8 = { 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255 },
},
LayerFacePixels {
.face_index = 1,
.x = 0,
.y = 0,
.width = 1,
.height = 4,
.rgba8 = { 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255 },
},
LayerFacePixels {
.face_index = 2,
.x = 0,
.y = 0,
.width = 1,
.height = 4,
.rgba8 = { 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255 },
},
LayerFacePixels {
.face_index = 3,
.x = 0,
.y = 0,
.width = 1,
.height = 4,
.rgba8 = { 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255 },
},
LayerFacePixels {
.face_index = 4,
.x = 0,
.y = 0,
.width = 1,
.height = 4,
.rgba8 = { 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255 },
},
LayerFacePixels {
.face_index = 5,
.x = 0,
.y = 0,
.width = 1,
.height = 4,
.rgba8 = { 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 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 = 4,
.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_equirectangular_png(
DocumentFrameCompositeRequest {
.document = &document.value(),
.frame_index = 0,
});
PP_EXPECT(h, exported);
if (!exported) {
return;
}
PP_EXPECT(h, exported.value().face_extent.width == 1U);
PP_EXPECT(h, exported.value().face_extent.height == 4U);
PP_EXPECT(h, exported.value().equirectangular_extent.width == 4U);
PP_EXPECT(h, exported.value().equirectangular_extent.height == 8U);
PP_EXPECT(h, exported.value().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().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] == 255U);
PP_EXPECT(h, decoded.value().pixels[1] == 0U);
PP_EXPECT(h, decoded.value().pixels[2] == 255U);
const auto bottom = (static_cast<std::size_t>(decoded.value().height) - 1U)
* decoded.value().width * pp::document::rgba8_components;
PP_EXPECT(h, decoded.value().pixels[bottom] == 0U);
PP_EXPECT(h, decoded.value().pixels[bottom + 1U] == 255U);
PP_EXPECT(h, decoded.value().pixels[bottom + 2U] == 255U);
}
void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
{
RecordingRenderDevice device;
@@ -742,6 +856,8 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
pp::paint_renderer::DocumentFrameUploadRequest {});
const auto no_document_readiness = pp::paint_renderer::prepare_document_frame_export_readiness(
DocumentFrameCompositeRequest {});
const auto no_document_equirect = pp::paint_renderer::export_document_frame_equirectangular_png(
DocumentFrameCompositeRequest {});
const AnimationFrame root_frames[] {
{ .duration_ms = 100, .face_pixels = {} },
@@ -774,6 +890,8 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
PP_EXPECT(h, no_document.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !no_document_readiness.ok());
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, !bad_frame.ok());
PP_EXPECT(h, bad_frame.status().code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_frame_readiness.ok());
@@ -1129,6 +1247,7 @@ int main()
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("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("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);