From 10e5d5b5aecb3bb8b8514e4f45a45cca83d32d20 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 1 Jun 2026 13:05:14 +0200 Subject: [PATCH] Preserve per-layer document timelines --- docs/modernization/build-inventory.md | 8 +-- docs/modernization/debt.md | 2 +- docs/modernization/roadmap.md | 14 +++-- src/document/document.cpp | 80 +++++++++++++++++++++++++-- src/document/document.h | 11 ++-- tests/CMakeLists.txt | 2 +- tests/document/document_tests.cpp | 64 ++++++++++++++++++++- tools/pano_cli/main.cpp | 36 ++++++++---- 8 files changed, 182 insertions(+), 35 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index e31b917..ec391da 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -91,8 +91,8 @@ Known local toolchain state: `pp_paint`, `pp_document`, `pp_renderer_api`, `pp_paint_renderer`, `pp_ui_core`, `pano_cli`, and their current headless test binaries, including foundation event/logging/task queue coverage, PNG metadata, PPI - header/layout, settings document, document snapshot/frame move/duration coverage, - paint brush/stroke/stroke-script coverage, renderer shader descriptor + header/layout, settings document, document snapshot/per-layer-frame/move/duration + coverage, paint brush/stroke/stroke-script coverage, renderer shader descriptor coverage, UI color parsing, and layout XML parse coverage. - `pano_cli inspect-image` reports PNG IHDR metadata as JSON and is covered by `pano_cli_inspect_png_metadata_smoke` with a tiny IHDR fixture. @@ -100,8 +100,8 @@ Known local toolchain state: body summary fields, layer/frame descriptors, and dirty-face PNG payload metadata, and is covered by `pano_cli_inspect_project_layout_smoke` with a minimal PPI fixture. -- `pano_cli load-project` creates a metadata-only `pp_document` projection for - representable PPI timelines and is covered by +- `pano_cli load-project` creates a metadata-only `pp_document` projection with + per-layer frame counts and durations, and is covered by `pano_cli_load_project_metadata_smoke`. - `pano_cli create-document` supports `--frames` and `--frame-duration-ms` and is covered by `pano_cli_create_animation_document_smoke`. diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 9272b81..011a57a 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -28,7 +28,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0007 | Open | Modernization | `vcpkg.json` and `windows-msvc-vcpkg-headless` are validated for the headless Windows component matrix, but app targets still use vendored libraries and Android/Apple triplets are not proven | Dependency migration must stay incremental while SDK/patched/vendor dependencies remain in use | `$env:VCPKG_ROOT="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg"; cmake --preset windows-msvc-vcpkg-headless`; `ctest --preset desktop-fast-vcpkg --build-config Debug` | Component targets consume vcpkg packages where reliable and desktop app, Android, and Apple triplets are validated or explicitly documented as permanent vendor exceptions | | DEBT-0008 | Open | Modernization | `windows-msvc-default` preset is used for local validation because the VS 2026 generator is not installed here | The target VS 2026 preset must remain, but this machine configures with Visual Studio 17 2022 | `cmake --preset windows-msvc-default`; `ctest --preset desktop-fast --build-config Debug` | Validate `windows-vs2026-x64` on a machine with Visual Studio 2026 installed and make it the default Windows validation preset | | DEBT-0009 | Open | Modernization | Android root CMake validation currently builds headless targets only, not APK/package variants | Platform app entrypoints still live in legacy Gradle/CMake projects and need Phase 6 alignment | `powershell -ExecutionPolicy Bypass -File scripts\automation\platform-build.ps1 -Presets android-arm64` | Android standard, Quest, and Focus/Wave package targets consume shared component targets and have package smoke commands | -| DEBT-0010 | Open | Modernization | `pp_document` is a pure layer/frame/document/undo-history model with alpha-lock metadata and snapshot construction, but it is not yet wired to legacy `Canvas`, PPI pixel load/save, selection masks, or legacy action commands | Keep extraction incremental while preserving app behavior | `ctest --preset desktop-fast --build-config Debug`; `pano_cli create-document --width 64 --height 32 --layers 2`; `pano_cli load-project --path tests\data\projects\minimal-project.ppi` | Legacy document behavior is represented by `pp_document` tests and the app consumes it through a boundary/facade | +| DEBT-0010 | Open | Modernization | `pp_document` is a pure layer/frame/document/undo-history model with alpha-lock metadata, snapshot construction, and per-layer frame metadata, but it is not yet wired to legacy `Canvas`, PPI pixel load/save, selection masks, or legacy action commands | Keep extraction incremental while preserving app behavior | `ctest --preset desktop-fast --build-config Debug`; `pano_cli create-document --width 64 --height 32 --layers 2`; `pano_cli load-project --path tests\data\projects\minimal-project.ppi` | Legacy document behavior is represented by `pp_document` tests and the app consumes it through a boundary/facade | | DEBT-0011 | Open | Modernization | `package-smoke` validates the Windows CMake app artifact only, not AppX/APK/Apple/WebGL package outputs | Platform package targets are not migrated to root CMake yet | `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug` | Package-smoke covers Windows AppX, Android APK variants, Apple bundles, and WebGL output where local toolchains are present | | DEBT-0012 | Open | Modernization | `pp_ui_core` uses vcpkg tinyxml2 on `windows-msvc-vcpkg-headless`, but retains `pp_vendor_tinyxml2` for default and unproven platform presets | Mobile/AppX/Apple triplets and app packaging still need validation before removing the vendored fallback | `ctest --preset desktop-fast-vcpkg --build-config Debug`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\platform-build.ps1 -Presets android-arm64` | All supported presets consume vcpkg tinyxml2 or document a permanent vendored exception | | DEBT-0013 | Open | Modernization | `pp_assets`, `pano_cli inspect-project`, and metadata-only `pano_cli load-project` validate the fixed PPI header, thumbnail/body byte layout, layer/frame index, dirty-face descriptors, and dirty-face PNG payload metadata, but do not yet deserialize layer face PNG pixels into document/layer/frame data | Full PPI parsing requires staged extraction of legacy `Canvas` serialization and image/layer payload handling | `ctest --preset desktop-fast --build-config Debug`; `pp_assets_ppi_header_tests`; `pano_cli_inspect_project_layout_smoke`; `pano_cli_load_project_metadata_smoke` | Full PPI load/save fixtures cover thumbnail, decoded layer face payloads, frames, metadata, corrupt payloads, and round-trip compatibility | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 8e41f17..eaa9cc1 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -321,8 +321,8 @@ CPU reference math for the five current shader blend modes, and deterministic stroke spacing/interpolation plus a pure text stroke-script parser. `pp_document` has started with a pure canvas/layer/frame model, alpha-lock metadata, snapshot -construction, layer metadata operations, frame move/duration queries, and -layer/frame/undo-redo history invariant tests. +construction, per-layer frame metadata, layer metadata operations, frame +move/duration queries, and layer/frame/undo-redo history invariant tests. `pp_renderer_api` has started with renderer-neutral texture/readback descriptors and validation tests. `pp_paint_renderer` has started with deterministic CPU layer compositing over renderer extents using @@ -332,8 +332,8 @@ input tests. `pano_cli inspect-image` exposes PNG IHDR metadata as JSON, `pano_cli inspect-project` reports validated PPI thumbnail/body byte layout, body summary, layer/frame descriptors, and dirty-face PNG payload metadata, and -`pano_cli load-project` creates a metadata-only `pp_document` projection for -representable PPI timelines. +`pano_cli load-project` creates a metadata-only `pp_document` projection with +per-layer frame counts and durations. `pano_cli create-document` can create simple animation documents with explicit frame count/duration, and `pano_cli simulate-stroke` exercises the pure stroke sampler for scripted-stroke automation. `pano_cli simulate-stroke-script` @@ -581,7 +581,8 @@ Results: - `pp_paint_stroke_tests` passed. - `pp_paint_stroke_script_tests` passed. - `pp_document_tests` passed, including snapshot construction, alpha-lock - metadata, frame move, duration, and history invariants. + metadata, per-layer frame metadata, frame move, duration, and history + invariants. - `pp_renderer_api_tests` passed, including shader descriptor validation. - `pp_paint_renderer_compositor_tests` passed. - `pp_ui_core_color_tests` passed. @@ -598,7 +599,8 @@ Results: thumbnail/body byte layout, body summary, layer/frame descriptors, and dirty-face PNG payload metadata JSON. - `pano_cli_load_project_metadata_smoke` passed and reports a metadata-only - `pp_document` projection for the minimal PPI fixture. + `pp_document` projection with per-layer frame counts and durations for the + minimal PPI fixture. - `pano_cli_parse_layout_smoke` passed. - `pano_cli_simulate_stroke_smoke` passed and reports deterministic stroke sample counts/distances. diff --git a/src/document/document.cpp b/src/document/document.cpp index eebe474..143bd35 100644 --- a/src/document/document.cpp +++ b/src/document/document.cpp @@ -33,6 +33,15 @@ namespace { return "Layer " + std::to_string(index + 1U); } +[[nodiscard]] std::uint64_t frame_duration_sum(std::span frames) noexcept +{ + std::uint64_t duration = 0; + for (const auto& frame : frames) { + duration += frame.duration_ms; + } + return duration; +} + [[nodiscard]] pp::foundation::Status validate_layer_name(std::string_view name) noexcept { if (name.empty()) { @@ -108,11 +117,14 @@ pp::foundation::Result CanvasDocument::create(DocumentConfig con CanvasDocument document; document.width_ = config.width; document.height_ = config.height; + document.frames_.push_back(AnimationFrame {}); document.layers_.reserve(config.layer_count); for (std::uint32_t i = 0; i < config.layer_count; ++i) { - document.layers_.push_back(Layer { .name = default_layer_name(i) }); + document.layers_.push_back(Layer { + .name = default_layer_name(i), + .frames = document.frames_, + }); } - document.frames_.push_back(AnimationFrame {}); return pp::foundation::Result::success(document); } @@ -158,13 +170,33 @@ pp::foundation::Result CanvasDocument::create_from_snapshot(Docu return pp::foundation::Result::failure(blend_status); } + const auto layer_frames = layer_config.frames.empty() ? config.frames : layer_config.frames; + if (layer_frames.empty()) { + return pp::foundation::Result::failure( + pp::foundation::Status::invalid_argument("document layer must contain at least one frame")); + } + + if (layer_frames.size() > max_frame_count) { + return pp::foundation::Result::failure( + pp::foundation::Status::out_of_range("document layer frame count exceeds the configured limit")); + } + + for (const auto& frame_config : layer_frames) { + const auto duration_status = validate_frame_duration(frame_config.duration_ms); + if (!duration_status.ok()) { + return pp::foundation::Result::failure(duration_status); + } + } + document.layers_.push_back(Layer { .name = std::string(layer_config.name), .visible = layer_config.visible, .alpha_locked = layer_config.alpha_locked, .opacity = layer_config.opacity, .blend_mode = layer_config.blend_mode, + .frames = {}, }); + document.layers_.back().frames.assign(layer_frames.begin(), layer_frames.end()); } document.frames_.reserve(config.frames.size()); @@ -202,13 +234,23 @@ std::size_t CanvasDocument::active_frame_index() const noexcept std::uint64_t CanvasDocument::animation_duration_ms() const noexcept { - std::uint64_t duration = 0; - for (const auto& frame : frames_) { - duration += frame.duration_ms; + std::uint64_t duration = frame_duration_sum(frames_); + for (const auto& layer : layers_) { + duration = std::max(duration, frame_duration_sum(layer.frames)); } return duration; } +pp::foundation::Result CanvasDocument::layer_animation_duration_ms(std::size_t index) const noexcept +{ + const auto index_status = validate_layer_index(index, layers_.size()); + if (!index_status.ok()) { + return pp::foundation::Result::failure(index_status); + } + + return pp::foundation::Result::success(frame_duration_sum(layers_[index].frames)); +} + std::span CanvasDocument::layers() const noexcept { return layers_; @@ -236,6 +278,7 @@ pp::foundation::Result CanvasDocument::add_layer(std::string_view n } layer.name = std::string(name); } + layer.frames = frames_; layers_.push_back(layer); active_layer_index_ = layers_.size() - 1U; return pp::foundation::Result::success(active_layer_index_); @@ -381,6 +424,9 @@ pp::foundation::Result CanvasDocument::add_frame(std::uint32_t dura } frames_.push_back(AnimationFrame { .duration_ms = duration_ms }); + for (auto& layer : layers_) { + layer.frames.push_back(AnimationFrame { .duration_ms = duration_ms }); + } active_frame_index_ = frames_.size() - 1U; return pp::foundation::Result::success(active_frame_index_); } @@ -400,6 +446,13 @@ pp::foundation::Result CanvasDocument::duplicate_frame(std::size_t const auto insert_at = index + 1U; frames_.insert(frames_.begin() + static_cast(insert_at), frames_[index]); + for (auto& layer : layers_) { + if (index < layer.frames.size()) { + layer.frames.insert( + layer.frames.begin() + static_cast(insert_at), + layer.frames[index]); + } + } active_frame_index_ = insert_at; return pp::foundation::Result::success(active_frame_index_); } @@ -416,6 +469,11 @@ pp::foundation::Status CanvasDocument::remove_frame(std::size_t index) } frames_.erase(frames_.begin() + static_cast(index)); + for (auto& layer : layers_) { + if (index < layer.frames.size() && layer.frames.size() > 1U) { + layer.frames.erase(layer.frames.begin() + static_cast(index)); + } + } if (active_frame_index_ >= frames_.size()) { active_frame_index_ = frames_.size() - 1U; } else if (active_frame_index_ > index) { @@ -438,6 +496,13 @@ pp::foundation::Status CanvasDocument::move_frame(std::size_t from, std::size_t const auto frame = frames_[from]; frames_.erase(frames_.begin() + static_cast(from)); frames_.insert(frames_.begin() + static_cast(to), frame); + for (auto& layer : layers_) { + if (from < layer.frames.size() && to < layer.frames.size()) { + const auto layer_frame = layer.frames[from]; + layer.frames.erase(layer.frames.begin() + static_cast(from)); + layer.frames.insert(layer.frames.begin() + static_cast(to), layer_frame); + } + } if (active_frame_index_ == from) { active_frame_index_ = to; @@ -463,6 +528,11 @@ pp::foundation::Status CanvasDocument::set_frame_duration(std::size_t index, std } frames_[index].duration_ms = duration_ms; + for (auto& layer : layers_) { + if (index < layer.frames.size()) { + layer.frames[index].duration_ms = duration_ms; + } + } return pp::foundation::Status::success(); } diff --git a/src/document/document.h b/src/document/document.h index 49434dd..62c9680 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -25,16 +25,17 @@ struct DocumentConfig { std::uint32_t layer_count = 1; }; +struct AnimationFrame { + std::uint32_t duration_ms = 100; +}; + struct Layer { std::string name; bool visible = true; bool alpha_locked = false; float opacity = 1.0F; pp::paint::BlendMode blend_mode = pp::paint::BlendMode::normal; -}; - -struct AnimationFrame { - std::uint32_t duration_ms = 100; + std::vector frames; }; struct DocumentLayerConfig { @@ -43,6 +44,7 @@ struct DocumentLayerConfig { bool alpha_locked = false; float opacity = 1.0F; pp::paint::BlendMode blend_mode = pp::paint::BlendMode::normal; + std::span frames; }; struct DocumentSnapshotConfig { @@ -62,6 +64,7 @@ public: [[nodiscard]] std::size_t active_layer_index() const noexcept; [[nodiscard]] std::size_t active_frame_index() const noexcept; [[nodiscard]] std::uint64_t animation_duration_ms() const noexcept; + [[nodiscard]] pp::foundation::Result layer_animation_duration_ms(std::size_t index) const noexcept; [[nodiscard]] std::span layers() const noexcept; [[nodiscard]] std::span frames() const noexcept; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 41f76a1..9f28755 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -240,7 +240,7 @@ if(TARGET pano_cli) COMMAND pano_cli load-project --path "${CMAKE_CURRENT_SOURCE_DIR}/data/projects/minimal-project.ppi") set_tests_properties(pano_cli_load_project_metadata_smoke PROPERTIES LABELS "assets;document;integration;desktop-fast" - PASS_REGULAR_EXPRESSION "\"command\":\"load-project\".*\"pixelDataLoaded\":false.*\"document\":\\{\"width\":64,\"height\":32,\"layers\":1,\"frames\":1,\"animationDurationMs\":100,\"layerNames\":\\[\"Ink\"\\]") + PASS_REGULAR_EXPRESSION "\"command\":\"load-project\".*\"pixelDataLoaded\":false.*\"document\":\\{\"width\":64,\"height\":32,\"layers\":1,\"frames\":1,\"animationDurationMs\":100,\"layerNames\":\\[\"Ink\"\\],\"layerFrameCounts\":\\[1\\],\"layerDurationsMs\":\\[100\\]") add_test(NAME pano_cli_parse_layout_smoke COMMAND pano_cli parse-layout --path "${CMAKE_CURRENT_SOURCE_DIR}/data/layouts/simple-layout.xml") diff --git a/tests/document/document_tests.cpp b/tests/document/document_tests.cpp index a278876..4939a47 100644 --- a/tests/document/document_tests.cpp +++ b/tests/document/document_tests.cpp @@ -34,6 +34,8 @@ void creates_document_with_default_layers(pp::tests::Harness& h) PP_EXPECT(h, document.value().active_layer_index() == 0U); PP_EXPECT(h, document.value().frames().size() == 1U); PP_EXPECT(h, document.value().frames()[0].duration_ms == 100U); + PP_EXPECT(h, document.value().layers()[0].frames.size() == 1U); + PP_EXPECT(h, document.value().layers()[0].frames[0].duration_ms == 100U); PP_EXPECT(h, document.value().animation_duration_ms() == 100U); PP_EXPECT(h, document.value().active_frame_index() == 0U); } @@ -172,6 +174,7 @@ void creates_document_from_snapshot_metadata(pp::tests::Harness& h) .alpha_locked = true, .opacity = 0.5F, .blend_mode = BlendMode::screen, + .frames = {}, }, { .name = "Glaze", @@ -179,6 +182,7 @@ void creates_document_from_snapshot_metadata(pp::tests::Harness& h) .alpha_locked = false, .opacity = 0.75F, .blend_mode = BlendMode::overlay, + .frames = {}, }, }; const AnimationFrame frames[] { @@ -199,16 +203,61 @@ void creates_document_from_snapshot_metadata(pp::tests::Harness& h) PP_EXPECT(h, !document_result.value().layers()[0].visible); PP_EXPECT(h, document_result.value().layers()[0].alpha_locked); PP_EXPECT(h, document_result.value().layers()[0].blend_mode == BlendMode::screen); + PP_EXPECT(h, document_result.value().layers()[0].frames.size() == 2U); + PP_EXPECT(h, document_result.value().layers()[0].frames[1].duration_ms == 250U); PP_EXPECT(h, document_result.value().frames().size() == 2U); PP_EXPECT(h, document_result.value().animation_duration_ms() == 350U); } +void preserves_per_layer_snapshot_timelines(pp::tests::Harness& h) +{ + const AnimationFrame project_frames[] { + { .duration_ms = 100 }, + }; + const AnimationFrame short_layer_frames[] { + { .duration_ms = 100 }, + { .duration_ms = 150 }, + }; + const AnimationFrame long_layer_frames[] { + { .duration_ms = 500 }, + }; + const DocumentLayerConfig layers[] { + { + .name = "Short", + .frames = short_layer_frames, + }, + { + .name = "Long", + .frames = long_layer_frames, + }, + }; + + const auto document_result = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { + .width = 128, + .height = 64, + .layers = layers, + .frames = project_frames, + }); + + PP_EXPECT(h, document_result.ok()); + PP_EXPECT(h, document_result.value().frames().size() == 1U); + PP_EXPECT(h, document_result.value().layers()[0].frames.size() == 2U); + PP_EXPECT(h, document_result.value().layers()[1].frames.size() == 1U); + PP_EXPECT(h, document_result.value().layers()[0].frames[1].duration_ms == 150U); + PP_EXPECT(h, document_result.value().layers()[1].frames[0].duration_ms == 500U); + PP_EXPECT(h, document_result.value().animation_duration_ms() == 500U); + const auto layer_duration = document_result.value().layer_animation_duration_ms(0); + PP_EXPECT(h, layer_duration.ok()); + PP_EXPECT(h, layer_duration.value() == 250U); +} + void rejects_invalid_snapshot_metadata(pp::tests::Harness& h) { - const DocumentLayerConfig layers[] { { .name = "Ink" } }; + const DocumentLayerConfig layers[] { { .name = "Ink", .frames = {} } }; const AnimationFrame frames[] { { .duration_ms = 100 } }; const AnimationFrame bad_frames[] { { .duration_ms = 0 } }; - const DocumentLayerConfig bad_layers[] { { .name = "" } }; + const DocumentLayerConfig bad_layers[] { { .name = "", .frames = {} } }; + const DocumentLayerConfig bad_layer_frames[] { { .name = "Ink", .frames = bad_frames } }; const auto no_layers = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { .width = 64, @@ -234,6 +283,12 @@ void rejects_invalid_snapshot_metadata(pp::tests::Harness& h) .layers = bad_layers, .frames = frames, }); + const auto bad_layer_frame = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { + .width = 64, + .height = 64, + .layers = bad_layer_frames, + .frames = frames, + }); PP_EXPECT(h, !no_layers.ok()); PP_EXPECT(h, no_layers.status().code == StatusCode::invalid_argument); @@ -243,6 +298,8 @@ void rejects_invalid_snapshot_metadata(pp::tests::Harness& h) PP_EXPECT(h, bad_frame.status().code == StatusCode::invalid_argument); PP_EXPECT(h, !bad_layer.ok()); PP_EXPECT(h, bad_layer.status().code == StatusCode::invalid_argument); + PP_EXPECT(h, !bad_layer_frame.ok()); + PP_EXPECT(h, bad_layer_frame.status().code == StatusCode::invalid_argument); } void manages_animation_frames_and_duration(pp::tests::Harness& h) @@ -257,6 +314,7 @@ void manages_animation_frames_and_duration(pp::tests::Harness& h) PP_EXPECT(h, added.value() == 1U); PP_EXPECT(h, document.active_frame_index() == 1U); PP_EXPECT(h, document.frames()[1].duration_ms == 250U); + PP_EXPECT(h, document.layers()[0].frames[1].duration_ms == 250U); const auto duplicated = document.duplicate_frame(1); PP_EXPECT(h, duplicated.ok()); @@ -264,6 +322,7 @@ void manages_animation_frames_and_duration(pp::tests::Harness& h) PP_EXPECT(h, document.frames()[2].duration_ms == 250U); PP_EXPECT(h, document.set_frame_duration(2, 333).ok()); PP_EXPECT(h, document.frames()[2].duration_ms == 333U); + PP_EXPECT(h, document.layers()[0].frames[2].duration_ms == 333U); PP_EXPECT(h, document.animation_duration_ms() == 683U); PP_EXPECT(h, document.remove_frame(1).ok()); @@ -457,6 +516,7 @@ int main() harness.run("updates_layer_metadata", updates_layer_metadata); harness.run("rejects_invalid_layer_metadata", rejects_invalid_layer_metadata); harness.run("creates_document_from_snapshot_metadata", creates_document_from_snapshot_metadata); + harness.run("preserves_per_layer_snapshot_timelines", preserves_per_layer_snapshot_timelines); harness.run("rejects_invalid_snapshot_metadata", rejects_invalid_snapshot_metadata); harness.run("manages_animation_frames_and_duration", manages_animation_frames_and_duration); harness.run("moves_frames_and_preserves_active_frame_identity", moves_frames_and_preserves_active_frame_identity); diff --git a/tools/pano_cli/main.cpp b/tools/pano_cli/main.cpp index 1e1420c..ed45e37 100644 --- a/tools/pano_cli/main.cpp +++ b/tools/pano_cli/main.cpp @@ -444,32 +444,29 @@ pp::foundation::Result document_from_ppi_index( frames.push_back(pp::document::AnimationFrame { .duration_ms = frame.duration_ms }); } + std::vector> layer_frames; + layer_frames.reserve(project.body.layers.size()); std::vector layers; layers.reserve(project.body.layers.size()); for (const auto& layer : project.body.layers) { - if (layer.frames.size() != reference_frames.size()) { - return pp::foundation::Result::failure( - pp::foundation::Status::invalid_argument("PPI per-layer frame counts are not representable yet")); - } - - for (std::size_t frame_index = 0; frame_index < layer.frames.size(); ++frame_index) { - if (layer.frames[frame_index].duration_ms != reference_frames[frame_index].duration_ms) { - return pp::foundation::Result::failure( - pp::foundation::Status::invalid_argument("PPI per-layer frame durations are not representable yet")); - } - } - const auto blend_mode = ppi_layer_blend_mode(layer.blend_mode); if (!blend_mode) { return pp::foundation::Result::failure(blend_mode.status()); } + auto& frame_list = layer_frames.emplace_back(); + frame_list.reserve(layer.frames.size()); + for (const auto& frame : layer.frames) { + frame_list.push_back(pp::document::AnimationFrame { .duration_ms = frame.duration_ms }); + } + layers.push_back(pp::document::DocumentLayerConfig { .name = layer.name, .visible = layer.visible, .alpha_locked = layer.alpha_locked, .opacity = layer.opacity, .blend_mode = blend_mode.value(), + .frames = std::span(frame_list.data(), frame_list.size()), }); } @@ -529,6 +526,21 @@ int load_project(int argc, char** argv) } std::cout << "\"" << json_escape(document.layers()[layer_index].name) << "\""; } + std::cout << "],\"layerFrameCounts\":["; + for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) { + if (layer_index != 0U) { + std::cout << ","; + } + std::cout << document.layers()[layer_index].frames.size(); + } + std::cout << "],\"layerDurationsMs\":["; + for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) { + if (layer_index != 0U) { + std::cout << ","; + } + const auto duration = document.layer_animation_duration_ms(layer_index); + std::cout << (duration ? duration.value() : 0U); + } std::cout << "]}}\n"; return 0; }