Export layer collections through paint renderer
This commit is contained in:
@@ -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