From bad2670f873a9b4e4e300d664fcbc491c93911d7 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 2 Jun 2026 11:11:01 +0200 Subject: [PATCH] Add document PPI export boundary --- CMakeLists.txt | 1 + docs/modernization/build-inventory.md | 8 +- docs/modernization/debt.md | 4 +- docs/modernization/roadmap.md | 12 +- scripts/automation/platform-build.ps1 | 2 +- scripts/automation/platform-build.sh | 2 +- src/document/ppi_export.cpp | 107 +++++++++++++++ src/document/ppi_export.h | 14 ++ tests/CMakeLists.txt | 10 ++ tests/document/ppi_export_tests.cpp | 180 ++++++++++++++++++++++++++ 10 files changed, 333 insertions(+), 7 deletions(-) create mode 100644 src/document/ppi_export.cpp create mode 100644 src/document/ppi_export.h create mode 100644 tests/document/ppi_export_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e84c3f9..07275aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ target_link_libraries(pp_paint add_library(pp_document STATIC src/document/document.cpp + src/document/ppi_export.cpp src/document/ppi_import.cpp) target_include_directories(pp_document PUBLIC diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 5cff398..b25f2c8 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -93,7 +93,7 @@ Known local toolchain state: `pp_ui_core`, `pano_cli`, and their current headless test binaries, including foundation event/logging/task queue coverage, PNG metadata and decode, PPI header/layout, settings document, document - snapshot/per-layer-frame/move/duration/face-pixel coverage, paint + snapshot/per-layer-frame/move/duration/face-pixel/PPI export coverage, paint brush/stroke/stroke-script coverage, renderer shader descriptor and OpenGL capability coverage, UI color parsing, and layout XML parse coverage. - `pano_cli inspect-image` reports PNG IHDR metadata as JSON and is covered by @@ -116,6 +116,9 @@ Known local toolchain state: - `pp_document_ppi_import_tests` attaches decoded PPI dirty-face payloads to `pp_document` layer/frame storage and rejects payloads outside document layers. +- `pp_document_ppi_export_tests` exports pure `pp_document` metadata, + per-layer frame durations, and RGBA8 face payloads to PPI bytes through + `pp_assets`, then decodes and reimports them for round-trip coverage. - `pano_cli load-project` creates a `pp_document` projection with per-layer frame counts, durations, and decoded face-pixel payloads when present; the metadata-only minimal fixture remains covered by @@ -294,6 +297,9 @@ Known local toolchain state: through JSON automation and is covered by metadata-only and dirty-face-payload round-trip smoke tests; full legacy canvas save parity remains tracked by DEBT-0013. +- `pp_document::export_ppi_project_document` exposes pure document-to-PPI byte + export through CTest coverage; legacy Canvas save integration remains a + future DEBT-0010/DEBT-0013 task. - `pp_ui_core` consumes vcpkg tinyxml2 only when `PP_USE_VCPKG_TINYXML2=ON` through the vcpkg preset; default and Android validation still use the retained vendored fallback tracked by DEBT-0012. diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index e59bb3e..e659279 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -28,10 +28,10 @@ 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, snapshot construction, per-layer frame metadata, renderer-free RGBA8 face payload storage, and renderer-free alpha8 selection-mask storage, but it is not yet wired to legacy `Canvas`, save, 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`; `pp_document_ppi_import_tests`; `pano_cli_simulate_document_edits_smoke` | 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, per-layer frame metadata, renderer-free RGBA8 face payload storage, renderer-free alpha8 selection-mask storage, and PPI import/export helpers, but it is not yet wired to legacy `Canvas`, legacy save, 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`; `pp_document_ppi_import_tests`; `pp_document_ppi_export_tests`; `pano_cli_simulate_document_edits_smoke` | 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`, `pano_cli load-project`, and `pano_cli save-project` validate the fixed PPI header, thumbnail/body byte layout, generated multi-layer/multi-frame PPI writing with explicit layer opacity/blend/alpha-lock/visibility metadata, per-layer frame durations, metadata-only and targeted dirty-face-payload save/load round-trips, layer/frame index, dirty-face descriptors, dirty-face PNG payload metadata, asset-level RGBA PNG payload decoding, and decoded pixel attachment to `pp_document`, but full legacy PPI round-trip parity is not yet extracted | Full PPI save parity requires staged extraction of legacy `Canvas` serialization and image/layer payload handling | `ctest --preset desktop-fast --build-config Debug`; `pp_assets_image_pixels_tests`; `pp_assets_ppi_header_tests`; `pp_document_ppi_import_tests`; `pano_cli_inspect_project_layout_smoke`; `pano_cli_load_project_metadata_smoke`; `pano_cli_save_project_roundtrip_smoke`; `pano_cli_save_project_payload_roundtrip_smoke` | Full PPI load/save fixtures cover thumbnails, decoded layer face payloads attached to documents, frames, corrupt payloads, dirty-face payload saving, arbitrary legacy canvas payload/layout combinations, and legacy app round-trip compatibility | +| DEBT-0013 | Open | Modernization | `pp_assets`, `pp_document`, `pano_cli inspect-project`, `pano_cli load-project`, and `pano_cli save-project` validate the fixed PPI header, thumbnail/body byte layout, generated multi-layer/multi-frame PPI writing with explicit layer opacity/blend/alpha-lock/visibility metadata, per-layer frame durations, metadata-only and targeted dirty-face-payload save/load round-trips, layer/frame index, dirty-face descriptors, dirty-face PNG payload metadata, asset-level RGBA PNG payload decoding, pure document-to-PPI export, and decoded pixel attachment to `pp_document`, but full legacy PPI round-trip parity is not yet extracted | Full PPI save parity requires staged extraction of legacy `Canvas` serialization and image/layer payload handling | `ctest --preset desktop-fast --build-config Debug`; `pp_assets_image_pixels_tests`; `pp_assets_ppi_header_tests`; `pp_document_ppi_import_tests`; `pp_document_ppi_export_tests`; `pano_cli_inspect_project_layout_smoke`; `pano_cli_load_project_metadata_smoke`; `pano_cli_save_project_roundtrip_smoke`; `pano_cli_save_project_payload_roundtrip_smoke` | Full PPI load/save fixtures cover thumbnails, decoded layer face payloads attached to documents, frames, corrupt payloads, dirty-face payload saving, arbitrary legacy canvas payload/layout combinations, and legacy app round-trip compatibility | | DEBT-0014 | Open | Modernization | `windows-clangcl-asan` now configures as a headless Ninja/clang-cl preset and uses the release MSVC runtime required by ASan, but local builds still fail because installed clang-cl 18.1.8 is paired with VS 2026-preview STL headers that require Clang 20 or newer | Sanitizer validation should be local and repeatable, but this machine's compiler/header pairing is incompatible | `cmake --fresh --preset windows-clangcl-asan`; `cmake --build --preset windows-clangcl-asan --target pp_foundation` | Install/use Clang 20+ with the VS 2026 STL, or point the preset at a compatible VS 2022 toolchain, then make `platform-build.ps1 -Presets windows-clangcl-asan` pass for the headless matrix | ## Closed Debt diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 1b6d20e..31280f6 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -324,7 +324,7 @@ stroke spacing/interpolation plus a pure text stroke-script parser. started with a pure canvas/layer/frame model, alpha-lock metadata, snapshot construction, per-layer frame metadata, layer metadata operations, frame move/duration queries, renderer-free RGBA8 cube-face payload storage, -renderer-free alpha8 selection-mask storage, PPI image import, and +renderer-free alpha8 selection-mask storage, PPI image import/export, 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 @@ -349,6 +349,8 @@ visibility, opacity, blend mode, alpha lock, per-layer frame durations, and dirty-face payloads targeted to layer/frame/face slots. `pano_cli save-project` exposes the generated writer for metadata-only and test dirty-face-payload round-trips through `load-project`. +`pp_document::export_ppi_project_document` converts pure documents into PPI +bytes using that writer, including PNG-encoded layer/frame face payloads. `pano_cli create-document` can create simple animation documents with explicit frame count/duration. `pano_cli simulate-document-edits` exercises pure layer metadata, frame reordering, active-index preservation, tiny face-payload @@ -651,7 +653,7 @@ Last verified on 2026-06-02: ```powershell cmake --preset windows-msvc-default -cmake --build --preset windows-msvc-default --config Debug --target pp_foundation_binary_stream_tests pp_foundation_event_tests pp_foundation_log_tests pp_foundation_parse_tests pp_foundation_task_queue_tests pp_foundation_trace_tests pp_assets_image_format_tests pp_assets_image_metadata_tests pp_assets_image_pixels_tests pp_assets_ppi_header_tests pp_assets_settings_document_tests pp_paint_brush_tests pp_paint_blend_tests pp_paint_stroke_tests pp_document_tests pp_document_ppi_import_tests pp_renderer_api_tests pp_paint_renderer_compositor_tests pp_ui_core_color_tests pp_ui_core_layout_value_tests pp_ui_core_layout_xml_tests pano_cli PanoPainter +cmake --build --preset windows-msvc-default --config Debug --target pp_foundation_binary_stream_tests pp_foundation_event_tests pp_foundation_log_tests pp_foundation_parse_tests pp_foundation_task_queue_tests pp_foundation_trace_tests pp_assets_image_format_tests pp_assets_image_metadata_tests pp_assets_image_pixels_tests pp_assets_ppi_header_tests pp_assets_settings_document_tests pp_paint_brush_tests pp_paint_blend_tests pp_paint_stroke_tests pp_document_tests pp_document_ppi_import_tests pp_document_ppi_export_tests pp_renderer_api_tests pp_paint_renderer_compositor_tests pp_ui_core_color_tests pp_ui_core_layout_value_tests pp_ui_core_layout_xml_tests pano_cli PanoPainter ctest --preset desktop-fast --build-config Debug powershell -ExecutionPolicy Bypass -File scripts\automation\test.ps1 -Preset desktop-fast -Configuration Debug powershell -ExecutionPolicy Bypass -File scripts\automation\build.ps1 -Preset windows-msvc-default -Configuration Debug -Target pano_cli @@ -695,6 +697,9 @@ Results: - `pp_document_ppi_import_tests` passed, including decoded PPI dirty-face payload attachment to `pp_document` layer/frame storage and out-of-range payload rejection. +- `pp_document_ppi_export_tests` passed, including pure document metadata, + per-layer frame duration, and PNG-encoded face-payload export to PPI bytes, + plus malformed payload rejection at the export boundary. - `pp_renderer_api_tests` passed, including shader descriptor validation, PanoPainter shader catalog validation, and invalid catalog rejection. - `pp_paint_renderer_compositor_tests` passed. @@ -804,6 +809,9 @@ Results: parity remains tracked by DEBT-0013. - `pp_assets::create_ppi_project` exposes the underlying generated PPI writer for non-uniform layer metadata and frame-duration extraction work. +- `pp_document::export_ppi_project_document` exposes pure document-to-PPI byte + export through CTest coverage; legacy Canvas save integration remains tracked + by DEBT-0010/DEBT-0013. - PowerShell package-smoke wrapper validates the Windows CMake app executable and runtime `data/` copy. - Android arm64 configured with NDK 29.0.14206865 through the platform-build diff --git a/scripts/automation/platform-build.ps1 b/scripts/automation/platform-build.ps1 index 705e0bc..ed70df2 100644 --- a/scripts/automation/platform-build.ps1 +++ b/scripts/automation/platform-build.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [string[]]$Presets = @("android-arm64"), - [string[]]$Targets = @("pp_foundation", "pp_assets", "pp_paint", "pp_document", "pp_renderer_api", "pp_renderer_gl", "pp_paint_renderer", "pp_ui_core", "pano_cli", "pp_foundation_binary_stream_tests", "pp_foundation_event_tests", "pp_foundation_log_tests", "pp_foundation_parse_tests", "pp_foundation_task_queue_tests", "pp_foundation_trace_tests", "pp_assets_image_format_tests", "pp_assets_image_metadata_tests", "pp_assets_image_pixels_tests", "pp_assets_ppi_header_tests", "pp_assets_settings_document_tests", "pp_paint_brush_tests", "pp_paint_blend_tests", "pp_paint_stroke_tests", "pp_paint_stroke_script_tests", "pp_document_tests", "pp_document_ppi_import_tests", "pp_renderer_api_tests", "pp_renderer_gl_capabilities_tests", "pp_paint_renderer_compositor_tests", "pp_ui_core_color_tests", "pp_ui_core_layout_value_tests", "pp_ui_core_layout_xml_tests") + [string[]]$Targets = @("pp_foundation", "pp_assets", "pp_paint", "pp_document", "pp_renderer_api", "pp_renderer_gl", "pp_paint_renderer", "pp_ui_core", "pano_cli", "pp_foundation_binary_stream_tests", "pp_foundation_event_tests", "pp_foundation_log_tests", "pp_foundation_parse_tests", "pp_foundation_task_queue_tests", "pp_foundation_trace_tests", "pp_assets_image_format_tests", "pp_assets_image_metadata_tests", "pp_assets_image_pixels_tests", "pp_assets_ppi_header_tests", "pp_assets_settings_document_tests", "pp_paint_brush_tests", "pp_paint_blend_tests", "pp_paint_stroke_tests", "pp_paint_stroke_script_tests", "pp_document_tests", "pp_document_ppi_import_tests", "pp_document_ppi_export_tests", "pp_renderer_api_tests", "pp_renderer_gl_capabilities_tests", "pp_paint_renderer_compositor_tests", "pp_ui_core_color_tests", "pp_ui_core_layout_value_tests", "pp_ui_core_layout_xml_tests") ) $ErrorActionPreference = "Stop" diff --git a/scripts/automation/platform-build.sh b/scripts/automation/platform-build.sh index f87f5fc..7e353fd 100644 --- a/scripts/automation/platform-build.sh +++ b/scripts/automation/platform-build.sh @@ -3,7 +3,7 @@ set -u preset="${1:-android-arm64}" shift || true -targets="${*:-pp_foundation pp_assets pp_paint pp_document pp_renderer_api pp_renderer_gl pp_paint_renderer pp_ui_core pano_cli pp_foundation_binary_stream_tests pp_foundation_event_tests pp_foundation_log_tests pp_foundation_parse_tests pp_foundation_task_queue_tests pp_foundation_trace_tests pp_assets_image_format_tests pp_assets_image_metadata_tests pp_assets_image_pixels_tests pp_assets_ppi_header_tests pp_assets_settings_document_tests pp_paint_brush_tests pp_paint_blend_tests pp_paint_stroke_tests pp_paint_stroke_script_tests pp_document_tests pp_document_ppi_import_tests pp_renderer_api_tests pp_renderer_gl_capabilities_tests pp_paint_renderer_compositor_tests pp_ui_core_color_tests pp_ui_core_layout_value_tests pp_ui_core_layout_xml_tests}" +targets="${*:-pp_foundation pp_assets pp_paint pp_document pp_renderer_api pp_renderer_gl pp_paint_renderer pp_ui_core pano_cli pp_foundation_binary_stream_tests pp_foundation_event_tests pp_foundation_log_tests pp_foundation_parse_tests pp_foundation_task_queue_tests pp_foundation_trace_tests pp_assets_image_format_tests pp_assets_image_metadata_tests pp_assets_image_pixels_tests pp_assets_ppi_header_tests pp_assets_settings_document_tests pp_paint_brush_tests pp_paint_blend_tests pp_paint_stroke_tests pp_paint_stroke_script_tests pp_document_tests pp_document_ppi_import_tests pp_document_ppi_export_tests pp_renderer_api_tests pp_renderer_gl_capabilities_tests pp_paint_renderer_compositor_tests pp_ui_core_color_tests pp_ui_core_layout_value_tests pp_ui_core_layout_xml_tests}" start="$(date +%s)" cmake --preset "$preset" diff --git a/src/document/ppi_export.cpp b/src/document/ppi_export.cpp new file mode 100644 index 0000000..2311bb9 --- /dev/null +++ b/src/document/ppi_export.cpp @@ -0,0 +1,107 @@ +#include "document/ppi_export.h" + +#include "assets/image_pixels.h" +#include "assets/ppi_header.h" + +#include +#include +#include + +namespace pp::document { + +namespace { + +[[nodiscard]] pp::foundation::Result ppi_blend_mode( + pp::paint::BlendMode blend_mode) noexcept +{ + switch (blend_mode) { + case pp::paint::BlendMode::normal: + return pp::foundation::Result::success(0); + case pp::paint::BlendMode::multiply: + return pp::foundation::Result::success(1); + case pp::paint::BlendMode::screen: + return pp::foundation::Result::success(2); + case pp::paint::BlendMode::color_dodge: + return pp::foundation::Result::success(3); + case pp::paint::BlendMode::overlay: + return pp::foundation::Result::success(4); + } + + return pp::foundation::Result::failure( + pp::foundation::Status::invalid_argument("document layer blend mode cannot be exported to PPI")); +} + +} + +pp::foundation::Result> export_ppi_project_document( + const CanvasDocument& document) +{ + std::vector> frame_configs; + frame_configs.reserve(document.layers().size()); + std::vector layer_configs; + layer_configs.reserve(document.layers().size()); + std::vector> payloads; + payloads.reserve(document.face_pixel_payload_count()); + std::vector dirty_faces; + dirty_faces.reserve(document.face_pixel_payload_count()); + + for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) { + const auto& layer = document.layers()[layer_index]; + const auto blend_mode = ppi_blend_mode(layer.blend_mode); + if (!blend_mode) { + return pp::foundation::Result>::failure(blend_mode.status()); + } + + auto& frames = frame_configs.emplace_back(); + frames.reserve(layer.frames.size()); + for (std::size_t frame_index = 0; frame_index < layer.frames.size(); ++frame_index) { + const auto& frame = layer.frames[frame_index]; + frames.push_back(pp::assets::PpiFrameConfig { + .duration_ms = frame.duration_ms, + }); + + for (const auto& face : frame.face_pixels) { + const auto encoded = pp::assets::encode_png_rgba8( + face.width, + face.height, + face.rgba8); + if (!encoded) { + return pp::foundation::Result>::failure(encoded.status()); + } + + payloads.push_back(encoded.value()); + const auto& payload = payloads.back(); + dirty_faces.push_back(pp::assets::PpiDirtyFacePayloadConfig { + .layer_index = static_cast(layer_index), + .frame_index = static_cast(frame_index), + .face_index = face.face_index, + .x = face.x, + .y = face.y, + .width = face.width, + .height = face.height, + .png_rgba8 = std::span(payload.data(), payload.size()), + }); + } + } + + layer_configs.push_back(pp::assets::PpiLayerConfig { + .name = layer.name, + .metadata = pp::assets::PpiLayerMetadataConfig { + .opacity = layer.opacity, + .blend_mode = blend_mode.value(), + .alpha_locked = layer.alpha_locked, + .visible = layer.visible, + }, + .frames = std::span(frames.data(), frames.size()), + }); + } + + return pp::assets::create_ppi_project(pp::assets::PpiProjectConfig { + .width = document.width(), + .height = document.height(), + .layers = std::span(layer_configs.data(), layer_configs.size()), + .dirty_faces = std::span(dirty_faces.data(), dirty_faces.size()), + }); +} + +} diff --git a/src/document/ppi_export.h b/src/document/ppi_export.h new file mode 100644 index 0000000..e02811b --- /dev/null +++ b/src/document/ppi_export.h @@ -0,0 +1,14 @@ +#pragma once + +#include "document/document.h" +#include "foundation/result.h" + +#include +#include + +namespace pp::document { + +[[nodiscard]] pp::foundation::Result> export_ppi_project_document( + const CanvasDocument& document); + +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9004609..13261f3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -176,6 +176,16 @@ add_test(NAME pp_document_ppi_import_tests COMMAND pp_document_ppi_import_tests) set_tests_properties(pp_document_ppi_import_tests PROPERTIES LABELS "assets;document;integration;desktop-fast") +add_executable(pp_document_ppi_export_tests + document/ppi_export_tests.cpp) +target_link_libraries(pp_document_ppi_export_tests PRIVATE + pp_document + pp_test_harness) + +add_test(NAME pp_document_ppi_export_tests COMMAND pp_document_ppi_export_tests) +set_tests_properties(pp_document_ppi_export_tests PROPERTIES + LABELS "assets;document;integration;desktop-fast") + add_executable(pp_renderer_api_tests renderer_api/renderer_api_tests.cpp) target_link_libraries(pp_renderer_api_tests PRIVATE diff --git a/tests/document/ppi_export_tests.cpp b/tests/document/ppi_export_tests.cpp new file mode 100644 index 0000000..32eb877 --- /dev/null +++ b/tests/document/ppi_export_tests.cpp @@ -0,0 +1,180 @@ +#include "assets/ppi_header.h" +#include "document/document.h" +#include "document/ppi_export.h" +#include "document/ppi_import.h" +#include "test_harness.h" + +#include +#include +#include + +using pp::document::AnimationFrame; +using pp::document::CanvasDocument; +using pp::document::DocumentLayerConfig; +using pp::document::DocumentSnapshotConfig; +using pp::document::LayerFacePixels; +using pp::document::export_ppi_project_document; +using pp::foundation::StatusCode; + +namespace { + +void exports_document_metadata_and_face_payloads(pp::tests::Harness& h) +{ + std::vector red_pixel { 255, 0, 0, 255 }; + std::vector blue_pixel { 0, 0, 255, 128 }; + const AnimationFrame root_frames[] { + { .duration_ms = 100, .face_pixels = {} }, + { .duration_ms = 250, .face_pixels = {} }, + }; + const AnimationFrame base_frames[] { + { + .duration_ms = 100, + .face_pixels = { + LayerFacePixels { + .face_index = 0, + .x = 2, + .y = 3, + .width = 1, + .height = 1, + .rgba8 = red_pixel, + }, + }, + }, + { .duration_ms = 250, .face_pixels = {} }, + }; + const AnimationFrame paint_frames[] { + { + .duration_ms = 333, + .face_pixels = { + LayerFacePixels { + .face_index = 5, + .x = 4, + .y = 5, + .width = 1, + .height = 1, + .rgba8 = blue_pixel, + }, + }, + }, + }; + const DocumentLayerConfig layers[] { + { + .name = "Base", + .visible = true, + .alpha_locked = false, + .opacity = 1.0F, + .blend_mode = pp::paint::BlendMode::normal, + .frames = std::span(base_frames, 2), + }, + { + .name = "Paint", + .visible = false, + .alpha_locked = true, + .opacity = 0.5F, + .blend_mode = pp::paint::BlendMode::overlay, + .frames = std::span(paint_frames, 1), + }, + }; + const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { + .width = 64, + .height = 32, + .layers = std::span(layers, 2), + .frames = std::span(root_frames, 2), + .selection_masks = {}, + }); + PP_EXPECT(h, document.ok()); + + const auto exported = export_ppi_project_document(document.value()); + + PP_EXPECT(h, exported.ok()); + const auto decoded = pp::assets::decode_ppi_project_images(exported.value()); + PP_EXPECT(h, decoded.ok()); + PP_EXPECT(h, decoded.value().project.body.summary.width == 64U); + PP_EXPECT(h, decoded.value().project.body.summary.height == 32U); + PP_EXPECT(h, decoded.value().project.body.summary.layer_count == 2U); + PP_EXPECT(h, decoded.value().project.body.summary.declared_frame_count == 3U); + PP_EXPECT(h, decoded.value().project.body.summary.dirty_face_count == 2U); + PP_EXPECT(h, decoded.value().project.body.layers[0].name == "Base"); + PP_EXPECT(h, decoded.value().project.body.layers[0].frames.size() == 2U); + PP_EXPECT(h, decoded.value().project.body.layers[0].frames[1].duration_ms == 250U); + PP_EXPECT(h, decoded.value().project.body.layers[1].name == "Paint"); + PP_EXPECT(h, decoded.value().project.body.layers[1].opacity == 0.5F); + PP_EXPECT(h, decoded.value().project.body.layers[1].blend_mode == 4U); + PP_EXPECT(h, decoded.value().project.body.layers[1].alpha_locked); + PP_EXPECT(h, !decoded.value().project.body.layers[1].visible); + PP_EXPECT(h, decoded.value().faces.size() == 2U); + PP_EXPECT(h, decoded.value().faces[0].layer_index == 0U); + PP_EXPECT(h, decoded.value().faces[0].frame_index == 0U); + PP_EXPECT(h, decoded.value().faces[0].face_index == 0U); + PP_EXPECT(h, decoded.value().faces[0].descriptor.x0 == 2U); + PP_EXPECT(h, decoded.value().faces[0].image.pixels[0] == 255U); + PP_EXPECT(h, decoded.value().faces[1].layer_index == 1U); + PP_EXPECT(h, decoded.value().faces[1].frame_index == 0U); + PP_EXPECT(h, decoded.value().faces[1].face_index == 5U); + PP_EXPECT(h, decoded.value().faces[1].descriptor.y0 == 5U); + PP_EXPECT(h, decoded.value().faces[1].image.pixels[2] == 255U); + PP_EXPECT(h, decoded.value().faces[1].image.pixels[3] == 128U); + + const auto imported = pp::document::import_ppi_project_document(decoded.value()); + PP_EXPECT(h, imported.ok()); + PP_EXPECT(h, imported.value().layers().size() == 2U); + PP_EXPECT(h, imported.value().layers()[1].alpha_locked); + PP_EXPECT(h, imported.value().face_pixel_payload_count() == 2U); +} + +void rejects_export_when_document_payload_cannot_encode(pp::tests::Harness& h) +{ + const AnimationFrame root_frames[] { + { .duration_ms = 100, .face_pixels = {} }, + }; + const AnimationFrame bad_frames[] { + { + .duration_ms = 100, + .face_pixels = { + LayerFacePixels { + .face_index = 0, + .x = 0, + .y = 0, + .width = 1, + .height = 1, + .rgba8 = {}, + }, + }, + }, + }; + const DocumentLayerConfig layers[] { + { + .name = "Bad", + .visible = true, + .alpha_locked = false, + .opacity = 1.0F, + .blend_mode = pp::paint::BlendMode::normal, + .frames = std::span(bad_frames, 1), + }, + }; + + const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { + .width = 64, + .height = 32, + .layers = std::span(layers, 1), + .frames = std::span(root_frames, 1), + .selection_masks = {}, + }); + + PP_EXPECT(h, document.ok()); + + const auto exported = export_ppi_project_document(document.value()); + + PP_EXPECT(h, !exported.ok()); + PP_EXPECT(h, exported.status().code == StatusCode::invalid_argument); +} + +} + +int main() +{ + pp::tests::Harness harness; + harness.run("exports_document_metadata_and_face_payloads", exports_document_metadata_and_face_payloads); + harness.run("rejects_export_when_document_payload_cannot_encode", rejects_export_when_document_payload_cannot_encode); + return harness.finish(); +}