mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-27 03:35:02 +00:00
Merge latest main into GPU test scheduling fix
This commit is contained in:
@@ -28,6 +28,10 @@ jobs:
|
||||
name: Windows installation policy (no app build)
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
# A nightly dry run on main: every release build except macOS, nothing signed or released
|
||||
# (craft-common-actions release.yml `dry-run`). Finds release-only breakage before release day.
|
||||
schedule:
|
||||
- cron: "32 1 * * *"
|
||||
push:
|
||||
branches: [release]
|
||||
workflow_dispatch:
|
||||
@@ -29,6 +33,7 @@ jobs:
|
||||
# Intentionally tracked at @main (not SHA-pinned) so org-wide CI improvements, security fixes, and build optimizations propagate without PR churn across all craftapp repos.
|
||||
uses: storytold/craft-common-actions/.github/workflows/release.yml@main
|
||||
with:
|
||||
dry-run: ${{ github.event_name == 'schedule' }}
|
||||
app-name: effectcraft
|
||||
app-title: EffectCraft
|
||||
version: ${{ inputs.version }}
|
||||
|
||||
+10
-2
@@ -64,7 +64,7 @@ and licence texts are in [`NOTICE`](NOTICE).
|
||||
| `crates/model/tests/fixtures/cube.obj` | EffectCraft contributors | Original work: Wavefront OBJ test fixture (unit cube, two materials) | MIT OR Apache-2.0 |
|
||||
| `crates/model/tests/fixtures/cube.mtl` | EffectCraft contributors | Original work: MTL test fixture (materials of cube.obj) | MIT OR Apache-2.0 |
|
||||
|
||||
One small After Effects test project of `crates/aep` is in this repository: `crates/aep/tests/fixtures/synthetic.aep` (original work, made with After Effects 2026 from own data, working space None, the embedded colour profile removed; MIT OR Apache-2.0, with its `.attribution` sidecar). The other After Effects test projects of `crates/aep` are not in this repository. They are original work of an EffectCraft contributor, generated with After Effects 2026 as own test data (MIT OR Apache-2.0, each file with its `.attribution` sidecar); they are in [storytold/effectcraft-corpus](https://github.com/storytold/effectcraft-corpus) with their sidecars, fetched by `cargo xtask aep-corpus` (commit-pinned, SHA-256-verified), and the tests read them only from the folder named by `EFFECTCRAFT_AEP_FIXTURES` (opt-in). Their embedded colour profiles are replaced by stubs made with `crates/aep/examples/stubicc.rs` (a header and a description, no colour data), so no vendor profile data is in them.
|
||||
Three small After Effects test projects of `crates/aep` are in this repository: `crates/aep/tests/fixtures/synthetic.aep` (original work, made with After Effects 2026 from own data, working space None, the embedded colour profile removed; MIT OR Apache-2.0, with its `.attribution` sidecar), `crates/aep/tests/fixtures/ai-mask-3099.aep` (original work, made with After Effects 2026 from four hand-written one-page PDFs named `.ai`, footage paths and host name neutralised, the embedded colour profiles replaced by stubs made with `crates/aep/examples/stubicc.rs`; MIT OR Apache-2.0, with its `.attribution` sidecar) and `crates/aep/tests/fixtures/text-synthetic.aep` (original work, made with After Effects 2026 by script from own data, working space None, no colour profile embedded, nothing changed after the save; MIT OR Apache-2.0, with its `.attribution` sidecar). The other After Effects test projects of `crates/aep` are not in this repository. They are original work of an EffectCraft contributor, generated with After Effects 2026 as own test data (MIT OR Apache-2.0, each file with its `.attribution` sidecar); they are in [storytold/effectcraft-corpus](https://github.com/storytold/effectcraft-corpus) with their sidecars, fetched by `cargo xtask aep-corpus` (commit-pinned, SHA-256-verified), and the tests read them only from the folder named by `EFFECTCRAFT_AEP_FIXTURES` (opt-in). Their embedded colour profiles are replaced by stubs made with `crates/aep/examples/stubicc.rs` (a header and a description, no colour data), so no vendor profile data is in them.
|
||||
|
||||
## Screenshots
|
||||
|
||||
@@ -99,7 +99,7 @@ Screenshots of EffectCraft itself, rendered headlessly, showing only procedurall
|
||||
(sidecars `.attribution`).
|
||||
- Bundled extension (ScriptUI panel) with its twelve built-in ease presets:
|
||||
`extensions/scriptui-panels/Ease Presets.jsx` (sidecar `.attribution`).
|
||||
- Example effect plug-in: `examples/plugins/posterize-bands` (plug-in API v1, WebAssembly).
|
||||
- Example effect plug-in: `examples/plugins/posterize-bands` (WebAssembly ABI 1).
|
||||
|
||||
## Trained models (optional downloads, not bundled)
|
||||
|
||||
@@ -129,6 +129,14 @@ configuration from these Apache-2.0 projects:
|
||||
- `crates/segment/src/mobilesam.rs` follows the MobileSAM, TinyViT and Segment Anything
|
||||
architectures and their Apache-2.0 reference code.
|
||||
|
||||
## Frozen matte regression fixture
|
||||
|
||||
| Asset | Author | Source | Licence |
|
||||
|---|---|---|---|
|
||||
| `crates/engine/src/tests/fixtures/analysed-0.24.ecproj` | arnav-hiwarkar | Original work, synthetic project keyed by EffectCraft 0.24.1 | MIT OR Apache-2.0 |
|
||||
| `crates/engine/src/tests/fixtures/object-matte-0.22.ecproj` | lisn0 | Original work, synthetic project saved by EffectCraft 0.22.0 | MIT OR Apache-2.0 |
|
||||
| `crates/engine/src/tests/fixtures/tracked-0.22.ecproj` | arnav-hiwarkar | Original work, synthetic project saved by EffectCraft 0.22.0 | MIT OR Apache-2.0 |
|
||||
|
||||
## First-party brand marks
|
||||
|
||||
The ArtCraft name, wordmark and logos are trademarks of the ArtCraft Team. They are not open source and are not
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ that variable set.
|
||||
```sh
|
||||
cargo run -p effectcraft -- --demo # the desktop app, with the demo project
|
||||
cargo test --workspace
|
||||
cargo xtask ci # what every commit must pass
|
||||
cargo xtask ci # what every commit must pass (dev-profile checks and tests)
|
||||
```
|
||||
|
||||
The default `dev` profile keeps debug info to line tables: builds are fast and panics/backtraces
|
||||
|
||||
Generated
+231
-135
@@ -1089,15 +1089,24 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-audio"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4)",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
|
||||
[[package]]
|
||||
name = "craft-ecproj-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ca1b5e2edb8568335c6c14f390307bd5beae8238#ca1b5e2edb8568335c6c14f390307bd5beae8238"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1107,12 +1116,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"fixed_decimal",
|
||||
"icu_decimal",
|
||||
@@ -1132,6 +1141,14 @@ dependencies = [
|
||||
"writeable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-media"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-media"
|
||||
version = "0.1.0"
|
||||
@@ -1143,7 +1160,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"hayro-syntax",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1152,7 +1169,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -1163,7 +1180,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"craft-fonts-build",
|
||||
"craft-i18n",
|
||||
@@ -1184,7 +1201,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dunce",
|
||||
@@ -1194,6 +1211,7 @@ dependencies = [
|
||||
"image",
|
||||
"log",
|
||||
"plist",
|
||||
"rustix 1.1.5",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1207,6 +1225,16 @@ dependencies = [
|
||||
"zip 9.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-video"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4)",
|
||||
"rayon",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.2"
|
||||
@@ -1420,8 +1448,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"cpal",
|
||||
"craft-update",
|
||||
"effectcraft-engine",
|
||||
@@ -1439,6 +1468,7 @@ dependencies = [
|
||||
"rfd",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sysinfo",
|
||||
"winit",
|
||||
"winresource",
|
||||
"zbus",
|
||||
@@ -1446,13 +1476,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-aep"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-color",
|
||||
"effectcraft-effects",
|
||||
"effectcraft-keyframe",
|
||||
"effectcraft-project",
|
||||
"effectcraft-time",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1460,7 +1491,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-automation"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-engine",
|
||||
"effectcraft-host",
|
||||
@@ -1472,16 +1503,9 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-av1enc"
|
||||
version = "0.21.0"
|
||||
dependencies = [
|
||||
"filmcraft-av1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-cli"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"cpu-time",
|
||||
"effectcraft-automation",
|
||||
@@ -1500,7 +1524,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-color"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"proptest",
|
||||
"serde",
|
||||
@@ -1508,7 +1532,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-effects"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"effectcraft-color",
|
||||
@@ -1526,7 +1550,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-engine"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-docpath",
|
||||
@@ -1565,12 +1589,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-export"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-av1enc",
|
||||
"craft-audio",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4)",
|
||||
"craft-video",
|
||||
"effectcraft-color",
|
||||
"effectcraft-effects",
|
||||
"effectcraft-hevcenc",
|
||||
"effectcraft-keyframe",
|
||||
"effectcraft-media",
|
||||
"effectcraft-opusenc",
|
||||
@@ -1578,25 +1603,22 @@ dependencies = [
|
||||
"effectcraft-raster",
|
||||
"effectcraft-render",
|
||||
"effectcraft-time",
|
||||
"effectcraft-vp9enc",
|
||||
"exr",
|
||||
"filmcraft-aac",
|
||||
"filmcraft-h264enc",
|
||||
"filmcraft-isobmff",
|
||||
"filmcraft-opus",
|
||||
"filmcraft-prores",
|
||||
"filmcraft-av1",
|
||||
"filmcraft-hevc",
|
||||
"filmcraft-vp9",
|
||||
"gif",
|
||||
"image",
|
||||
"log",
|
||||
"rayon",
|
||||
"tempfile",
|
||||
"thiserror 2.0.21",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-expr"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"boa_engine",
|
||||
"effectcraft-color",
|
||||
@@ -1613,7 +1635,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-geom"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"proptest",
|
||||
"serde",
|
||||
@@ -1621,7 +1643,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-gpu"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"effectcraft-color",
|
||||
@@ -1644,7 +1666,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-helper-host"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"effectcraft-effects",
|
||||
@@ -1653,16 +1675,9 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-hevcenc"
|
||||
version = "0.21.0"
|
||||
dependencies = [
|
||||
"filmcraft-hevc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-host"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-engine",
|
||||
"effectcraft-export",
|
||||
@@ -1689,7 +1704,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-interchange"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-color",
|
||||
"effectcraft-keyframe",
|
||||
@@ -1708,7 +1723,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-keyframe"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-color",
|
||||
"effectcraft-geom",
|
||||
@@ -1720,7 +1735,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-lottie"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"craft-docpath",
|
||||
"effectcraft-color",
|
||||
@@ -1738,9 +1753,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-media"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"craft-audio",
|
||||
"craft-docpath",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4)",
|
||||
"effectcraft-color",
|
||||
"effectcraft-effects",
|
||||
"effectcraft-model",
|
||||
@@ -1752,12 +1769,9 @@ dependencies = [
|
||||
"effectcraft-svg",
|
||||
"effectcraft-time",
|
||||
"exr",
|
||||
"filmcraft-aac",
|
||||
"filmcraft-codecs",
|
||||
"filmcraft-color",
|
||||
"filmcraft-frame",
|
||||
"filmcraft-isobmff",
|
||||
"filmcraft-matroska",
|
||||
"filmcraft-media",
|
||||
"filmcraft-mpegts",
|
||||
"filmcraft-time",
|
||||
@@ -1766,12 +1780,13 @@ dependencies = [
|
||||
"log",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-model"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-geom",
|
||||
"image",
|
||||
@@ -1784,14 +1799,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-opusenc"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"filmcraft-opus",
|
||||
"craft-audio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-path"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-geom",
|
||||
"effectcraft-keyframe",
|
||||
@@ -1803,7 +1818,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-pdf"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"craft-pdf",
|
||||
"effectcraft-raster",
|
||||
@@ -1819,7 +1834,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-plugin"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-effects",
|
||||
"effectcraft-keyframe",
|
||||
@@ -1831,7 +1846,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-project"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"craft-ecproj-format",
|
||||
"effectcraft-color",
|
||||
@@ -1845,14 +1860,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-psd"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"miniz_oxide 0.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-raster"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-color",
|
||||
"effectcraft-geom",
|
||||
@@ -1862,7 +1877,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-render"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-color",
|
||||
"effectcraft-effects",
|
||||
@@ -1885,7 +1900,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-sam2"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"candle-core",
|
||||
@@ -1900,7 +1915,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-script"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"boa_engine",
|
||||
"effectcraft-engine",
|
||||
@@ -1918,7 +1933,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-segment"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"miniz_oxide 0.9.1",
|
||||
"ndarray",
|
||||
@@ -1927,19 +1942,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-svg"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-geom",
|
||||
"effectcraft-path",
|
||||
"effectcraft-raster",
|
||||
"kurbo",
|
||||
"log",
|
||||
"rayon",
|
||||
"roxmltree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-text"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-keyframe",
|
||||
"harfrust",
|
||||
@@ -1951,7 +1967,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-time"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"proptest",
|
||||
"serde",
|
||||
@@ -1959,7 +1975,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-track"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-raster",
|
||||
"effectcraft-segment",
|
||||
@@ -1971,7 +1987,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-ui-egui"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
@@ -2010,13 +2026,9 @@ dependencies = [
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-vp9enc"
|
||||
version = "0.21.0"
|
||||
|
||||
[[package]]
|
||||
name = "effectcraft-web"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"effectcraft-engine",
|
||||
"effectcraft-export",
|
||||
@@ -2481,7 +2493,7 @@ name = "filmcraft-bitstream"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5"
|
||||
dependencies = [
|
||||
"craft-media",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2582,16 +2594,6 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "filmcraft-h264enc"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5"
|
||||
dependencies = [
|
||||
"filmcraft-bitstream",
|
||||
"rayon",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "filmcraft-hevc"
|
||||
version = "0.12.0"
|
||||
@@ -2624,7 +2626,7 @@ name = "filmcraft-isobmff"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5"
|
||||
dependencies = [
|
||||
"craft-media",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2632,7 +2634,7 @@ name = "filmcraft-matroska"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5"
|
||||
dependencies = [
|
||||
"craft-media",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3068,7 +3070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
|
||||
dependencies = [
|
||||
"rustix 1.1.5",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3321,7 +3323,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a"
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"hayro-ccitt",
|
||||
]
|
||||
@@ -3335,7 +3337,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1"
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4#e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4"
|
||||
dependencies = [
|
||||
"hayro-jbig2",
|
||||
"hayro-jpeg2000",
|
||||
@@ -3668,7 +3670,7 @@ dependencies = [
|
||||
"simd_cesu8",
|
||||
"thiserror 2.0.21",
|
||||
"walkdir",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3814,7 +3816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4120,6 +4122,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.50.3"
|
||||
@@ -4434,6 +4445,16 @@ dependencies = [
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-io-kit"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-io-surface"
|
||||
version = "0.3.2"
|
||||
@@ -4664,7 +4685,7 @@ dependencies = [
|
||||
"libc",
|
||||
"redox_syscall 0.5.18",
|
||||
"smallvec",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6071,6 +6092,20 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.37.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16607d5caffd1c07ce073528f9ed972d88db15dd44023fa57142963be3feb11f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"memchr",
|
||||
"ntapi",
|
||||
"objc2-core-foundation",
|
||||
"objc2-io-kit",
|
||||
"windows 0.61.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tag_ptr"
|
||||
version = "0.1.0"
|
||||
@@ -7224,16 +7259,38 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.61.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
|
||||
dependencies = [
|
||||
"windows-collections 0.2.0",
|
||||
"windows-core 0.61.2",
|
||||
"windows-future 0.2.1",
|
||||
"windows-link 0.1.3",
|
||||
"windows-numerics 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
|
||||
dependencies = [
|
||||
"windows-collections",
|
||||
"windows-collections 0.3.2",
|
||||
"windows-core 0.62.2",
|
||||
"windows-future",
|
||||
"windows-numerics",
|
||||
"windows-future 0.3.2",
|
||||
"windows-numerics 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-collections"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8"
|
||||
dependencies = [
|
||||
"windows-core 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7255,6 +7312,19 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link 0.1.3",
|
||||
"windows-result 0.3.4",
|
||||
"windows-strings 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.62.2"
|
||||
@@ -7263,9 +7333,20 @@ checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
"windows-result 0.4.1",
|
||||
"windows-strings",
|
||||
"windows-strings 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-future"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
|
||||
dependencies = [
|
||||
"windows-core 0.61.2",
|
||||
"windows-link 0.1.3",
|
||||
"windows-threading 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7275,8 +7356,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
|
||||
dependencies = [
|
||||
"windows-core 0.62.2",
|
||||
"windows-link",
|
||||
"windows-threading",
|
||||
"windows-link 0.2.1",
|
||||
"windows-threading 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7301,12 +7382,28 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-numerics"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
|
||||
dependencies = [
|
||||
"windows-core 0.61.2",
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-numerics"
|
||||
version = "0.3.1"
|
||||
@@ -7314,7 +7411,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
|
||||
dependencies = [
|
||||
"windows-core 0.62.2",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7323,9 +7420,9 @@ version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
"windows-result 0.4.1",
|
||||
"windows-strings",
|
||||
"windows-strings 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7337,13 +7434,31 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
||||
dependencies = [
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
||||
dependencies = [
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7352,7 +7467,7 @@ version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7388,7 +7503,7 @@ version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7422,13 +7537,22 @@ dependencies = [
|
||||
"windows_x86_64_msvc 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-threading"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
|
||||
dependencies = [
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-threading"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7711,7 +7835,7 @@ checksum = "e450f9b2ed1dff33c94c12589a87338689467b9c4f5d8a5710bd09a847d2c8a7"
|
||||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"pkg-config",
|
||||
@@ -7959,7 +8083,6 @@ dependencies = [
|
||||
"nix",
|
||||
"typed-path 0.13.0",
|
||||
"windows-sys 0.61.2",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7974,18 +8097,6 @@ version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"crc32fast",
|
||||
"log",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.5.3"
|
||||
@@ -8050,18 +8161,3 @@ dependencies = [
|
||||
"syn 3.0.6",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a"
|
||||
|
||||
+24
-46
@@ -4,19 +4,19 @@ members = ["crates/*", "apps/*", "xtask"]
|
||||
default-members = ["crates/*", "apps/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.21.0"
|
||||
version = "0.24.1"
|
||||
edition = "2024"
|
||||
license = "MIT OR Apache-2.0"
|
||||
rust-version = "1.95"
|
||||
repository = "https://github.com/storytold/effectcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0", default-features = false, features = ["read"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" }
|
||||
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ca1b5e2edb8568335c6c14f390307bd5beae8238" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", version = "=0.1.0", default-features = false, features = ["read"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4" }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4" }
|
||||
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", features = ["egui"] }
|
||||
# internal
|
||||
effectcraft-time = { path = "crates/time" }
|
||||
effectcraft-geom = { path = "crates/geom" }
|
||||
@@ -41,7 +41,6 @@ effectcraft-interchange = { path = "crates/interchange" }
|
||||
effectcraft-pdf = { path = "crates/pdf" }
|
||||
effectcraft-psd = { path = "crates/psd" }
|
||||
effectcraft-aep = { path = "crates/aep" }
|
||||
effectcraft-vp9enc = { path = "crates/vp9enc" }
|
||||
effectcraft-svg = { path = "crates/svg" }
|
||||
effectcraft-engine = { path = "crates/engine" }
|
||||
effectcraft-host = { path = "crates/host" }
|
||||
@@ -49,8 +48,6 @@ effectcraft-ui-egui = { path = "crates/ui-egui" }
|
||||
effectcraft-automation = { path = "crates/automation" }
|
||||
effectcraft-opusenc = { path = "crates/opusenc" }
|
||||
effectcraft-script = { path = "crates/script" }
|
||||
effectcraft-hevcenc = { path = "crates/hevcenc" }
|
||||
effectcraft-av1enc = { path = "crates/av1enc" }
|
||||
effectcraft-plugin = { path = "crates/plugin" }
|
||||
effectcraft-helper-host = { path = "crates/helper-host" }
|
||||
|
||||
@@ -82,25 +79,23 @@ image = { version = "0.25", default-features = false, features = ["png", "jpeg"]
|
||||
same-file = "1.0"
|
||||
tempfile = "3.27"
|
||||
|
||||
# media codecs + containers: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001).
|
||||
# codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev.
|
||||
craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", default-features = false, features = ["isobmff", "matroska"] }
|
||||
craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] }
|
||||
craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] }
|
||||
|
||||
# footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001).
|
||||
# Only `crates/media`, `crates/export` and `crates/interchange` may depend on these.
|
||||
filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# encoders + muxer (crates/export)
|
||||
filmcraft-h264enc = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-prores = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-aac = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-isobmff = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# container headers read for AAC channel layouts (crates/media)
|
||||
filmcraft-matroska = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# MPEG TS / PS headers read for AAC channel layouts (crates/media); craft-media has no MPEG TS reader
|
||||
filmcraft-mpegts = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# decoder used as the round-trip oracle of effectcraft-opusenc (crates/export dev-dependency)
|
||||
filmcraft-opus = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# decoders used as the round-trip oracles of craft-video's VP9, HEVC and AV1 encoders (crates/export
|
||||
# dev-dependencies only); craft-video has no decoder for them
|
||||
filmcraft-vp9 = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# decoders used as the round-trip oracles of effectcraft-hevcenc / effectcraft-av1enc (dev-dependencies only)
|
||||
filmcraft-hevc = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
filmcraft-av1 = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" }
|
||||
# timeline interchange (EDL, FCP7 XML, FCPXML, OTIO) for Premiere Pro interop (crates/interchange only)
|
||||
@@ -117,7 +112,7 @@ half = "2.7"
|
||||
# ui
|
||||
# Shared frontend components; keep this dependency above the engine boundary.
|
||||
# Shared UI and the complete egui family select reviewed immutable commits below.
|
||||
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", features = ["serde"] }
|
||||
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", features = ["serde"] }
|
||||
# `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()`
|
||||
# and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate.
|
||||
egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] }
|
||||
@@ -137,11 +132,6 @@ sys-locale = "0.3"
|
||||
# filmcraft-frame = { path = "../filmcraft/crates/frame" }
|
||||
# filmcraft-color = { path = "../filmcraft/crates/color" }
|
||||
# filmcraft-time = { path = "../filmcraft/crates/time" }
|
||||
# filmcraft-h264enc = { path = "../filmcraft/crates/h264enc" }
|
||||
# filmcraft-prores = { path = "../filmcraft/crates/prores" }
|
||||
# filmcraft-aac = { path = "../filmcraft/crates/aac" }
|
||||
# filmcraft-isobmff = { path = "../filmcraft/crates/isobmff" }
|
||||
# filmcraft-matroska = { path = "../filmcraft/crates/matroska" }
|
||||
# filmcraft-mpegts = { path = "../filmcraft/crates/mpegts" }
|
||||
|
||||
[workspace.lints.rust]
|
||||
@@ -200,50 +190,39 @@ opt-level = 3
|
||||
[profile.dev.package.effectcraft-export]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.effectcraft-vp9enc]
|
||||
# craft-libs codec hot loops.
|
||||
[profile.dev.package.craft-video]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.effectcraft-hevcenc]
|
||||
[profile.dev.package.craft-audio]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.effectcraft-av1enc]
|
||||
[profile.dev.package.craft-media]
|
||||
opt-level = 3
|
||||
|
||||
# FilmCraft codec hot loops (same settings as FilmCraft's own workspace).
|
||||
[profile.dev.package.filmcraft-h264]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-h264enc]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-hevc]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-vp9]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-prores]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-dnx]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-av1]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-aac]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.filmcraft-opus]
|
||||
opt-level = 3
|
||||
|
||||
[profile.release]
|
||||
lto = "thin"
|
||||
codegen-units = 1
|
||||
|
||||
[patch.crates-io]
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.7.2" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.3.0" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", version = "=0.7.2" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "e7c3dda7f3e339dd2c8d40fc4eb405472be1a1e4", version = "=0.3.0" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
@@ -254,8 +233,7 @@ egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "6d518fc79968
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
# Patch a crate only together with the dependency that needs it: an unused patch makes the Nix
|
||||
# build, which uses vendored sources, fail (`cargo xtask lock-patches`).
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
|
||||
@@ -129,18 +129,14 @@ or into the Timeline, between layers and at the time you point to.
|
||||
|
||||
308 built-in effects across its categories, each with its parameter names, order and
|
||||
defaults: blur and sharpen, channel, color correction (Curves, Levels, Hue/Saturation, a full
|
||||
color-grading panel…), distort (Warp, Bulge, Turbulent Displace, CC Power Pin…), generate (Fractal Noise,
|
||||
color-grading panel…), distort (Warp, Bulge, Turbulent Displace, Perspective Pin…), generate (Fractal Noise,
|
||||
Gradient Ramp, Stroke, Write-on, Audio Spectrum…), keying, matte, noise and grain, perspective,
|
||||
**simulation** (CC Particle World, CC Rainfall, Shatter, Card Dance, Caustics, Wave World…),
|
||||
stylize (Glow, CC Glass…), **time** (Echo, Posterize Time, Timewarp, Time Displacement…),
|
||||
**simulation** (Particle Emitter 3D, Rainfall, Shatter, Card Dance, Caustics, Wave World…),
|
||||
stylize (Glow, Glass Relief…), **time** (Echo, Posterize Time, Timewarp, Time Displacement…),
|
||||
**audio** (Reverb, Parametric EQ, Delay, Stereo Mixer…), text, transitions, utility and expression
|
||||
controls. All nine **Layer Styles** (Drop Shadow, Inner/Outer Glow, Bevel and Emboss, Satin,
|
||||
overlays, Stroke) with Global Light. Preview plays audio in sync, with meters and waveforms.
|
||||
|
||||
<p align="center">
|
||||
<img src="docs/images/effectcraft-effects.png" alt="A CC Particle World burst with Glow, and the Effect Controls panel listing the particle system's parameters" width="100%">
|
||||
</p>
|
||||
|
||||
## 3D
|
||||
|
||||
Classic 3D compositing: 3D layers with orientation and material options,
|
||||
@@ -160,7 +156,7 @@ MP4, **WebM** (VP9 with inter frames and alpha, or AV1; Opus audio), PNG, JPEG,
|
||||
rendering with 3:2 pulldown, effect/solo/guide/depth overrides, crop, region of interest and
|
||||
resize, Render Settings and Output Module templates with defaults, post-render actions, storage
|
||||
overflow and render logs. The same queue runs from the command line. Every encoder is pure
|
||||
Rust (FilmCraft's H.264, ProRes and AAC; EffectCraft's own VP9, AV1, HEVC and Opus); there is no
|
||||
Rust (craft-libs' H.264, ProRes, HEVC, VP9, AV1 and AAC; EffectCraft's own Opus); there is no
|
||||
FFmpeg inside.
|
||||
|
||||
**Lottie** goes both ways: File ▸ Export ▸ Lottie JSON… writes a composition (precomps, shape,
|
||||
|
||||
@@ -31,12 +31,13 @@
|
||||
//! effectcraft-cli bench --roto [--frames N] [--sam2 model.safetensors] [--mobilesam mobile_sam.pt] [--fixes] [--clip FRAMES --truth MASKS] [--json] Roto Brush trackers on synthetic clips with known mattes
|
||||
//! (classical engine, MobileSAM and SAM 2.1 (any installed size) when installed; IoU, flicker, re-appearance, seconds per frame)
|
||||
//! effectcraft-cli script FILE.jsx [F.ecproj] | --eval CODE run an After Effects-style script
|
||||
//! effectcraft-cli replay SCRIPT.jsonl [--keep-going] replay a repro script (docs/agents.md)
|
||||
//! effectcraft-cli mcp [--autosave | --bridge PORT] MCP server on stdio
|
||||
//!
|
||||
//! Project: --project F.ecproj (or a positional *.ecproj) | --demo | --empty (default: demo; mcp: empty)
|
||||
//! Saving: --save (back to --project) | --save-as F.ecproj
|
||||
//! GPU: --gpu renders on the GPU compositor (Mercury GPU Acceleration) when an adapter exists;
|
||||
//! the default is the CPU (Mercury Software Only)
|
||||
//! GPU: --gpu renders on the GPU compositor (GPU Acceleration) when an adapter exists;
|
||||
//! the default is the CPU (Software Rendering)
|
||||
//! Bridge: --bridge PORT drives a running `effectcraft --control PORT` instead of a headless session
|
||||
//! Output: --json for one compact JSON document on stdout (errors: {"error": …}, exit 1)
|
||||
//! ```
|
||||
@@ -97,7 +98,7 @@ fn stdout_broken() -> bool {
|
||||
STDOUT_FAILED.get().is_some_and(|k| *k != std::io::ErrorKind::BrokenPipe)
|
||||
}
|
||||
|
||||
const USAGE: &str = "usage: effectcraft-cli <info|commands|exec|run|props|get|set|render-frame|render|script|mcp> [args] [--json]
|
||||
const USAGE: &str = "usage: effectcraft-cli <info|commands|exec|run|props|get|set|render-frame|render|script|replay|mcp> [args] [--json]
|
||||
info project + engine summary
|
||||
commands [--filter TEXT] [--enabled] list engine commands
|
||||
exec <command-id> [--params JSON] run one engine command (exec --list: list them, as `commands`)
|
||||
@@ -138,6 +139,9 @@ const USAGE: &str = "usage: effectcraft-cli <info|commands|exec|run|props|get|se
|
||||
script FILE.jsx [F.ecproj] | --eval CODE run JavaScript with the After Effects-style object model
|
||||
(app.project, comps, layers, properties…); prints writeLn
|
||||
output and the result; errors exit 1 with file:line:col
|
||||
replay SCRIPT.jsonl [--keep-going] replay a repro script headless (journal.export, crash repros):
|
||||
per-step ok/error and the first failure; exits 1 when a step
|
||||
fails, an expectation is not met or a command panics
|
||||
mcp [--autosave | --bridge PORT] MCP server (JSON-RPC over stdio); --autosave preserves unsaved headless work
|
||||
[--automation-read-root DIR] [--automation-write-root DIR]
|
||||
confine the agent's file access: reads under a read or write root,
|
||||
@@ -222,6 +226,7 @@ const FLAGS: &[&str] = &[
|
||||
"--small",
|
||||
"--adv3d",
|
||||
"--autosave",
|
||||
"--keep-going",
|
||||
"--progress",
|
||||
];
|
||||
|
||||
@@ -466,7 +471,7 @@ fn backend(args: &Args, default_demo: bool) -> Result<Backend, Failure> {
|
||||
}
|
||||
|
||||
/// A wired session; `--gpu` attaches the GPU compositor (renders then follow the project's
|
||||
/// renderer setting, Mercury GPU Acceleration by default).
|
||||
/// renderer setting, GPU Acceleration by default).
|
||||
fn session(args: &Args) -> Result<effectcraft_engine::Session, Failure> {
|
||||
let mut s = effectcraft_host::session();
|
||||
if args.flag("--autosave") {
|
||||
@@ -552,6 +557,59 @@ fn script_cmd(args: &Args, json_out: bool) -> Result<(), Failure> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `replay SCRIPT.jsonl`: run a repro script against a headless session (its start line picks
|
||||
/// the project) and report every step. Exits 1 when the replay fails.
|
||||
fn replay_cmd(args: &Args, json_out: bool) -> Result<(), Failure> {
|
||||
use effectcraft_engine::replay;
|
||||
let Some(file) = args.pos.first() else { return usage_err("replay needs a .jsonl script") };
|
||||
if args.opt("--bridge").is_some() || args.project.is_some() || args.flag("--demo") || args.flag("--empty") {
|
||||
return usage_err("replay runs headless from the script's start line ({\"start\": \"new\" | \"demo\" | {\"project\": path}})");
|
||||
}
|
||||
use std::io::Read;
|
||||
let path = std::path::Path::new(file);
|
||||
let input = std::fs::File::open(path).map_err(|e| Failure::Error(format!("cannot read {file}: {e}")))?;
|
||||
// Bound the read itself: metadata can be stale or describe a pipe rather than its contents.
|
||||
let mut script = String::new();
|
||||
input.take(replay::MAX_SCRIPT_BYTES as u64 + 1).read_to_string(&mut script).map_err(|e| Failure::Error(format!("cannot read {file}: {e}")))?;
|
||||
if script.len() > replay::MAX_SCRIPT_BYTES {
|
||||
return Err(Failure::Error(format!("{file} is larger than {} MB", replay::MAX_SCRIPT_BYTES >> 20)));
|
||||
}
|
||||
let mut s = session(args)?;
|
||||
let opts = replay::Options { keep_going: args.flag("--keep-going"), base_dir: path.parent().map(std::path::Path::to_path_buf) };
|
||||
let report = replay::run(&mut s, &script, &opts);
|
||||
if json_out {
|
||||
emit(&serde_json::to_value(&report).unwrap_or_else(|e| json!({"error": e.to_string()})), true);
|
||||
} else {
|
||||
for st in &report.steps {
|
||||
let what = st.command.as_deref().unwrap_or(st.kind);
|
||||
match (&st.error, st.ok) {
|
||||
(None, _) => say!("line {:>4} ok {what}", st.line),
|
||||
(Some(e), true) => say!("line {:>4} ok {what} (tolerated error: {e})", st.line),
|
||||
(Some(e), false) => say!("line {:>4} FAIL {what}: {e}", st.line),
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(first) = &report.first_failure else {
|
||||
if !json_out {
|
||||
say!("replay ok: {} steps", report.steps.len());
|
||||
}
|
||||
return Ok(());
|
||||
};
|
||||
let msg = format!(
|
||||
"failed at line {} ({}){}: {}{}",
|
||||
first.line,
|
||||
first.command.as_deref().unwrap_or(first.kind),
|
||||
if report.panicked { ", a command panicked" } else { "" },
|
||||
first.error.as_deref().unwrap_or(""),
|
||||
if report.skipped > 0 { format!(" ({} later steps not run)", report.skipped) } else { String::new() }
|
||||
);
|
||||
if json_out {
|
||||
note!("effectcraft-cli replay: {msg}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
Err(Failure::Error(msg))
|
||||
}
|
||||
|
||||
/// Print a result: compact JSON with `--json`, else pretty JSON.
|
||||
fn emit(v: &Value, json_out: bool) {
|
||||
if json_out {
|
||||
@@ -614,6 +672,7 @@ fn run(cmd: &str, args: &Args, json_out: bool) -> Result<(), Failure> {
|
||||
"commands" => list_commands_cmd(args, json_out)?,
|
||||
"exec" if args.flag("--list") => list_commands_cmd(args, json_out)?,
|
||||
"script" => script_cmd(args, json_out)?,
|
||||
"replay" => replay_cmd(args, json_out)?,
|
||||
"exec" => {
|
||||
let Some(id) = args.pos.first().cloned() else { return usage_err("exec needs a command id") };
|
||||
let params = match (args.opt("--params"), args.pos.get(1).map(String::as_str)) {
|
||||
@@ -1443,7 +1502,7 @@ fn adv3d_bench_comp(p: &mut effectcraft_engine::project::Project) -> Option<Item
|
||||
/// `bench --gpu`: CPU vs GPU ms/frame for every comp (or `--comp`) at Full and Half. "cold"
|
||||
/// renders everything (no layer cache); "warm" reuses the layer cache (playback / scrubbing of
|
||||
/// unchanged layers: compositing cost); "viewer" is the GPU display path without readback;
|
||||
/// "auto" is Backend::Auto (Mercury GPU Acceleration) choosing per comp from measured times,
|
||||
/// "auto" is Backend::Auto (GPU Acceleration) choosing per comp from measured times,
|
||||
/// warm; "up/dn MB" are the GPU's uploads / readbacks per warm GPU frame.
|
||||
fn bench_gpu(s: &Session, args: &Args) -> Result<(), Failure> {
|
||||
use effectcraft_render::Backend;
|
||||
|
||||
@@ -1223,3 +1223,39 @@ fn render_exr_compression_and_depth() {
|
||||
assert!(reply["error"].as_str().unwrap().contains("exrBitDepth: half|float"), "{reply}");
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replay_reports_steps_and_the_first_failure() {
|
||||
let repro = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/repros/comp-zero-frame-rate.jsonl");
|
||||
let v = ok_json(&["replay", repro.to_str().unwrap()]);
|
||||
assert_eq!(v["ok"], true, "{v}");
|
||||
assert!(v["steps"].as_array().unwrap().len() > 5);
|
||||
let bad = tmp("bad-repro.jsonl");
|
||||
std::fs::write(
|
||||
&bad,
|
||||
"{\"start\": \"new\"}\n{\"command\": \"comp.new\"}\n{\"expect\": {\"query\": \"comp.info\", \"pointer\": \"/width\", \"equals\": 1}}\nnot json\n",
|
||||
)
|
||||
.unwrap();
|
||||
let (code, v) = run_json(&["replay", bad.to_str().unwrap()]);
|
||||
assert_eq!(code, 1);
|
||||
assert_eq!(v["ok"], false);
|
||||
assert_eq!(v["first_failure"]["line"], 3, "{v}");
|
||||
assert_eq!(v["skipped"], 1);
|
||||
let out = bin().args(["replay", bad.to_str().unwrap(), "--keep-going"]).output().unwrap();
|
||||
assert_eq!(out.status.code(), Some(1));
|
||||
let text = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(text.contains("line 2 ok comp.new") && text.contains("line 4 FAIL invalid: not JSON"), "{text}");
|
||||
assert!(String::from_utf8_lossy(&out.stderr).contains("failed at line 3 (comp.info)"));
|
||||
// The start line picks the project.
|
||||
assert_eq!(bin().args(["replay", bad.to_str().unwrap(), "--demo"]).output().unwrap().status.code(), Some(2));
|
||||
}
|
||||
|
||||
/// Text editors can prefix an exported JSON-lines repro with a UTF-8 BOM.
|
||||
#[test]
|
||||
fn replay_accepts_a_utf8_bom() {
|
||||
let path = tmp("bom-repro.jsonl");
|
||||
std::fs::write(&path, "\u{feff}{\"command\":\"comp.new\"}\n").unwrap();
|
||||
let (code, report) = run_json(&["replay", path.to_str().unwrap()]);
|
||||
assert_eq!(code, 0, "{report}");
|
||||
assert_eq!(report["ok"], true);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ rfd = { workspace = true }
|
||||
pollster = { workspace = true }
|
||||
cpal = { workspace = true }
|
||||
log = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
# MIT; safe process handles and target-only memory observation for the crash helper.
|
||||
sysinfo = { version = "=0.37.2", default-features = false, features = ["system"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
# Native GNOME/Wayland controls without a bundled title font.
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
//! Bounded observations made outside the failed GUI. Measurements are evidence, not a cause.
|
||||
use std::io::{self, Write};
|
||||
use std::sync::mpsc::{self, Receiver};
|
||||
use std::time::{Duration, Instant, SystemTime};
|
||||
|
||||
use sysinfo::{MemoryRefreshKind, Pid, ProcessRefreshKind, ProcessesToUpdate, System};
|
||||
|
||||
pub fn utc() -> String {
|
||||
chrono::DateTime::<chrono::Utc>::from(SystemTime::now()).to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Memory {
|
||||
samples: u64,
|
||||
resident_peak: u64,
|
||||
virtual_peak: u64,
|
||||
available_min: Option<u64>,
|
||||
total: u64,
|
||||
last_at: Option<String>,
|
||||
last_uptime_secs: Option<u64>,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
fn sample(&mut self, resident: u64, virtual_bytes: u64, available: u64, total: u64) {
|
||||
self.samples = self.samples.saturating_add(1);
|
||||
self.resident_peak = self.resident_peak.max(resident);
|
||||
self.virtual_peak = self.virtual_peak.max(virtual_bytes);
|
||||
// Zero total means the platform could not supply physical-memory information.
|
||||
if total != 0 {
|
||||
self.available_min = Some(self.available_min.map_or(available, |old| old.min(available)));
|
||||
self.total = total;
|
||||
}
|
||||
self.last_at = Some(utc());
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Observation {
|
||||
pid: Pid,
|
||||
system: System,
|
||||
birth: Option<u64>,
|
||||
started: Instant,
|
||||
started_at: String,
|
||||
detected_at: Option<String>,
|
||||
last_sample: Instant,
|
||||
memory: Memory,
|
||||
// Only Windows can retrieve an unrelated process's ExitStatus through a retained handle.
|
||||
exit: Receiver<Option<std::process::ExitStatus>>,
|
||||
status: Option<std::process::ExitStatus>,
|
||||
alive: Option<bool>,
|
||||
}
|
||||
|
||||
fn target_system(pid: Pid) -> System {
|
||||
let mut system = System::new();
|
||||
system.refresh_processes_specifics(ProcessesToUpdate::Some(&[pid]), false, ProcessRefreshKind::nothing().with_memory());
|
||||
system
|
||||
}
|
||||
|
||||
impl Observation {
|
||||
/// Acquire the Windows handle before acknowledging reporter readiness, so even an immediate
|
||||
/// GUI abort leaves an observable process object. Never enumerate commands or environments.
|
||||
pub fn start(pid: u32) -> Self {
|
||||
let pid = Pid::from_u32(pid);
|
||||
let system = target_system(pid);
|
||||
let birth = system.process(pid).map(|p| p.start_time());
|
||||
let (send, exit) = mpsc::sync_channel(1);
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let waiting = target_system(pid);
|
||||
let _ = std::thread::Builder::new().name("ec-exit-status".into()).spawn(move || {
|
||||
let status = waiting.process(pid).and_then(|p| p.wait());
|
||||
let _ = send.send(status);
|
||||
});
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
drop(send);
|
||||
let now = Instant::now();
|
||||
let mut result = Self {
|
||||
pid,
|
||||
system,
|
||||
birth,
|
||||
started: now,
|
||||
started_at: utc(),
|
||||
detected_at: None,
|
||||
last_sample: now,
|
||||
memory: Memory::default(),
|
||||
exit,
|
||||
status: None,
|
||||
alive: None,
|
||||
};
|
||||
result.sample();
|
||||
result
|
||||
}
|
||||
|
||||
fn sample(&mut self) {
|
||||
self.system.refresh_processes_specifics(ProcessesToUpdate::Some(&[self.pid]), false, ProcessRefreshKind::nothing().with_memory());
|
||||
self.system.refresh_memory_specifics(MemoryRefreshKind::nothing().with_ram());
|
||||
let process = self.system.process(self.pid).filter(|p| Some(p.start_time()) == self.birth && p.exists());
|
||||
self.alive = self.birth.map(|_| process.is_some());
|
||||
if let Some(process) = process {
|
||||
self.memory.last_uptime_secs = Some(process.run_time());
|
||||
self.memory.sample(process.memory(), process.virtual_memory(), self.system.available_memory(), self.system.total_memory());
|
||||
}
|
||||
if let Ok(status) = self.exit.try_recv() {
|
||||
self.status = status;
|
||||
}
|
||||
self.last_sample = Instant::now();
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
if self.last_sample.elapsed() >= Duration::from_secs(1) {
|
||||
self.sample();
|
||||
}
|
||||
}
|
||||
|
||||
/// Pipe closure can precede the OS signalling process termination. Bound that grace period;
|
||||
/// a broken pipe or early reporter drop must never be called a confirmed process exit.
|
||||
pub fn finish(&mut self) {
|
||||
self.detected_at = Some(utc());
|
||||
if self.status.is_none()
|
||||
&& let Ok(status) = self.exit.recv_timeout(Duration::from_millis(750))
|
||||
{
|
||||
self.status = status;
|
||||
}
|
||||
self.sample();
|
||||
}
|
||||
|
||||
pub fn confirmed_exit(&self) -> bool {
|
||||
self.status.is_some()
|
||||
}
|
||||
|
||||
pub fn write(&self, report: &mut impl Write) -> io::Result<()> {
|
||||
writeln!(
|
||||
report,
|
||||
"Detection UTC: {}\nObserver started UTC: {}\nObserved duration: {} ms",
|
||||
self.detected_at.as_deref().unwrap_or("not captured"),
|
||||
self.started_at,
|
||||
self.started.elapsed().as_millis()
|
||||
)?;
|
||||
writeln!(
|
||||
report,
|
||||
"Process observation: {}",
|
||||
if self.confirmed_exit() {
|
||||
"process termination observed"
|
||||
} else if self.alive == Some(true) {
|
||||
"GUI still present when the control channel ended"
|
||||
} else {
|
||||
"target absent from refresh or process identity/status unavailable (not proof of termination)"
|
||||
}
|
||||
)?;
|
||||
match &self.status {
|
||||
Some(status) => {
|
||||
writeln!(report, "OS exit status: {status}")?;
|
||||
#[cfg(windows)]
|
||||
if let Some(code) = status.code() {
|
||||
write_windows_status(report, code as u32)?;
|
||||
}
|
||||
}
|
||||
None => writeln!(report, "OS exit status: unavailable (not inferred from the control pipe)")?,
|
||||
}
|
||||
let memory = &self.memory;
|
||||
writeln!(report, "\nMemory evidence (1 s sampling; sampled maxima, not OS peaks):\nTarget-present sampling attempts: {}", memory.samples)?;
|
||||
if let Some(uptime) = memory.last_uptime_secs {
|
||||
writeln!(report, "GUI uptime at last target-present observation: {uptime} s")?;
|
||||
}
|
||||
#[cfg(windows)]
|
||||
let virtual_label = "Peak sampled private committed bytes";
|
||||
#[cfg(not(windows))]
|
||||
let virtual_label = "Peak sampled virtual bytes";
|
||||
if memory.samples != 0 {
|
||||
writeln!(
|
||||
report,
|
||||
"Last target sampling attempt UTC: {}\nPeak sampled resident bytes: {}\n{virtual_label}: {}",
|
||||
memory.last_at.as_deref().unwrap_or("unavailable"),
|
||||
memory.resident_peak,
|
||||
memory.virtual_peak
|
||||
)?;
|
||||
}
|
||||
if let Some(available) = memory.available_min {
|
||||
writeln!(report, "Minimum sampled system available RAM bytes: {available}\nSystem total RAM bytes at last sample: {}", memory.total)?;
|
||||
}
|
||||
writeln!(
|
||||
report,
|
||||
"Samples can miss short spikes or retain stale/zero readings when an OS query fails; per-field success is not exposed by sysinfo. Windows private commit is not GPU VRAM; on other platforms virtual memory is not physical RAM. System commit limit/usage and GPU memory budgets were not collected. No memory-pressure threshold establishes the cause of this incident.\nThe memory observer does not collect process command lines, environments, documents, native dumps or system event logs. The existing session-log tail below may contain paths or other logged details; review it before sharing."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(windows, test))]
|
||||
fn write_windows_status(report: &mut impl Write, code: u32) -> io::Result<()> {
|
||||
let meaning = match code {
|
||||
0xc0000005 => "STATUS_ACCESS_VIOLATION",
|
||||
0xc0000017 => "STATUS_NO_MEMORY",
|
||||
0xc000012d => "STATUS_COMMITMENT_LIMIT",
|
||||
0xc0000374 => "STATUS_HEAP_CORRUPTION",
|
||||
0xc0000409 => "STATUS_STACK_BUFFER_OVERRUN / fast fail",
|
||||
0x40000015 => "STATUS_FATAL_APP_EXIT",
|
||||
_ => "unclassified",
|
||||
};
|
||||
writeln!(
|
||||
report,
|
||||
"Windows status bits: 0x{code:08X} ({meaning})\nThese are process exit bits, not a verified exception record. Software can set an exit code explicitly; an access violation does not identify the faulting module or prove a driver crash."
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn missing_target_without_exit_status_does_not_confirm_termination() {
|
||||
let (send, exit) = mpsc::sync_channel(1);
|
||||
drop(send);
|
||||
let now = Instant::now();
|
||||
let observation = Observation {
|
||||
pid: Pid::from_u32(1),
|
||||
system: System::new(),
|
||||
birth: Some(1),
|
||||
started: now,
|
||||
started_at: utc(),
|
||||
detected_at: Some(utc()),
|
||||
last_sample: now,
|
||||
memory: Memory::default(),
|
||||
exit,
|
||||
status: None,
|
||||
alive: Some(false),
|
||||
};
|
||||
assert!(!observation.confirmed_exit());
|
||||
let mut report = Vec::new();
|
||||
observation.write(&mut report).unwrap();
|
||||
let report = String::from_utf8(report).unwrap();
|
||||
assert!(report.contains("not proof of termination"));
|
||||
assert!(!report.contains("process termination observed"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_high_water_marks_are_bounded_and_not_a_causal_diagnosis() {
|
||||
let mut memory = Memory::default();
|
||||
memory.sample(40, 80, 30, 100);
|
||||
memory.sample(20, 90, 50, 100);
|
||||
assert_eq!((memory.samples, memory.resident_peak, memory.virtual_peak, memory.available_min), (2, 40, 90, Some(30)));
|
||||
memory.sample(0, 0, 0, 0);
|
||||
assert_eq!(memory.available_min, Some(30));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_status_bits_preserve_unsigned_codes_without_claiming_a_driver_crash() {
|
||||
for (code, name) in
|
||||
[(0xc0000005, "STATUS_ACCESS_VIOLATION"), (0xc0000017, "STATUS_NO_MEMORY"), (0xc000012d, "STATUS_COMMITMENT_LIMIT"), (42, "unclassified")]
|
||||
{
|
||||
let mut text = Vec::new();
|
||||
write_windows_status(&mut text, code).unwrap();
|
||||
let text = String::from_utf8(text).unwrap();
|
||||
assert!(text.contains(name));
|
||||
assert!(text.contains(&format!("0x{code:08X}")));
|
||||
assert!(text.contains("not a verified exception record"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn utc_timestamps_are_parseable_and_zero_offset() {
|
||||
let time = chrono::DateTime::parse_from_rfc3339(&utc()).unwrap();
|
||||
assert_eq!(time.offset().local_minus_utc(), 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,797 @@
|
||||
//! A small, separate process reports an unexpected desktop exit (#3357).
|
||||
//!
|
||||
//! Allocation failure can abort without a panic hook. The GUI therefore owns a pipe to a
|
||||
//! helper which never loads a project, font database or GPU. Only an explicit marker after
|
||||
//! normal teardown suppresses the report. EOF alone identifies a lost control channel, not
|
||||
//! a process exit or its cause. System-wide exhaustion can still prevent the helper or its native dialog working.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||
use std::sync::mpsc::{self, RecvTimeoutError};
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[path = "crash_observation.rs"]
|
||||
mod observation;
|
||||
|
||||
const FLAG: &str = "--internal-crash-reporter";
|
||||
const CLEAN: &[u8] = b"EFFECTCRAFT_CLEAN_EXIT_V1\n";
|
||||
const LOG_BYTES: usize = 64 * 1024;
|
||||
const HEADER_BYTES: usize = 128;
|
||||
const READY: &[u8] = b"READY\n";
|
||||
const EVENT_BYTES: usize = 128;
|
||||
const EVENT_COUNT: usize = 32;
|
||||
|
||||
/// Owned only by the GUI, never handed to another child. Dropping it without `finish` closes
|
||||
/// the pipe and reports the incident; there is intentionally no clean-exit Drop hook.
|
||||
pub struct Reporter {
|
||||
pipe: ChildStdin,
|
||||
child: Child,
|
||||
}
|
||||
|
||||
impl Reporter {
|
||||
/// Call only after application teardown, including handled startup/device-loss errors.
|
||||
pub fn finish(mut self) -> io::Result<()> {
|
||||
let sent = self.pipe.write_all(CLEAN).and_then(|()| self.pipe.flush());
|
||||
drop(self.pipe);
|
||||
// Do not let a suspended/broken helper hang shutdown. Reap it before the GUI
|
||||
// exits where possible, so Windows updates do not race an old executable.
|
||||
let cleanup = finish_child(&mut self.child, Duration::from_secs(2));
|
||||
match (sent, cleanup) {
|
||||
(Err(sent), Err(cleanup)) => Err(io::Error::other(format!("clean marker failed: {sent}; cleanup failed: {cleanup}"))),
|
||||
(Err(error), _) | (_, Err(error)) => Err(error),
|
||||
(Ok(()), Ok(())) => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_child(child: &mut Child, grace: Duration) -> io::Result<()> {
|
||||
let start = Instant::now();
|
||||
while start.elapsed() < grace {
|
||||
if let Some(status) = child.try_wait()? {
|
||||
return if status.success() { Ok(()) } else { Err(io::Error::other(format!("crash reporter exited with {status}"))) };
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
child.kill()?;
|
||||
// Even after termination, do not introduce an unbounded wait on a stuck OS process.
|
||||
let start = Instant::now();
|
||||
while start.elapsed() < Duration::from_secs(1) {
|
||||
if child.try_wait()?.is_some() {
|
||||
return Err(io::Error::other("crash reporter did not finish promptly and was terminated"));
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
Err(io::Error::other("crash reporter termination could not be confirmed"))
|
||||
}
|
||||
|
||||
/// Shared ownership lets macOS finish in on_exit, while main retains the startup-error path.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Shutdown(std::sync::Arc<std::sync::Mutex<Option<Reporter>>>);
|
||||
|
||||
impl Shutdown {
|
||||
/// Install the one reporter created for this desktop launch.
|
||||
pub fn install(&self, reporter: Reporter) -> io::Result<()> {
|
||||
let mut slot = self.0.lock().map_err(|_| io::Error::other("crash reporter ownership was poisoned"))?;
|
||||
*slot = Some(reporter);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Keep only fixed-vocabulary, bounded lifecycle facts outside the GUI. Callers emit each
|
||||
/// category once; their combined payload fits well below the smallest OS pipe buffer.
|
||||
pub fn record(&self, event: &'static str) -> io::Result<()> {
|
||||
if event.len() > 100 || event.contains(['\n', '\r']) {
|
||||
return Err(io::Error::other("invalid diagnostic observation"));
|
||||
}
|
||||
let mut slot = self.0.lock().map_err(|_| io::Error::other("crash reporter ownership was poisoned"))?;
|
||||
if let Some(reporter) = slot.as_mut() {
|
||||
writeln!(reporter.pipe, "EVENT {event}")?;
|
||||
reporter.pipe.flush()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Consume the reporter exactly once, after the applicable platform teardown boundary.
|
||||
pub fn finish(&self) -> io::Result<()> {
|
||||
let reporter = self.0.lock().map_err(|_| io::Error::other("crash reporter ownership was poisoned"))?.take();
|
||||
reporter.map_or(Ok(()), Reporter::finish)
|
||||
}
|
||||
}
|
||||
|
||||
/// A panic during teardown must leave the reporter armed. macOS terminates after this hook
|
||||
/// without returning to main; other platforms pass None and finish after run_native returns.
|
||||
pub fn after_teardown(reporter: Option<&Shutdown>, teardown: impl FnOnce()) -> io::Result<()> {
|
||||
teardown();
|
||||
reporter.map_or(Ok(()), Shutdown::finish)
|
||||
}
|
||||
|
||||
/// Each process/run has its own report, including simultaneous launches.
|
||||
pub fn run_id() -> String {
|
||||
let nanos = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_nanos();
|
||||
format!("{}-{nanos}", std::process::id())
|
||||
}
|
||||
|
||||
pub fn session_marker(id: &str) -> String {
|
||||
format!("crash-report session {id}")
|
||||
}
|
||||
|
||||
/// Start before heavy work. A missing helper is a warning, never a reason to refuse the app.
|
||||
pub fn start(id: &str, log: Option<&Path>, reports: &Path, interactive: bool) -> io::Result<Reporter> {
|
||||
let exe = std::env::current_exe()?;
|
||||
let args = [
|
||||
OsString::from(FLAG),
|
||||
OsString::from(id),
|
||||
log.map_or_else(OsString::new, |p| p.as_os_str().to_owned()),
|
||||
reports.as_os_str().to_owned(),
|
||||
OsString::from(if interactive { "1" } else { "0" }),
|
||||
OsString::from(std::process::id().to_string()),
|
||||
];
|
||||
spawn(&exe, &args)
|
||||
}
|
||||
|
||||
fn spawn(exe: &Path, args: &[OsString]) -> io::Result<Reporter> {
|
||||
let mut child = Command::new(exe).args(args).stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?;
|
||||
if let Err(error) = ready(&mut child) {
|
||||
let _ = child.kill();
|
||||
let _ = finish_child(&mut child, Duration::from_millis(100));
|
||||
return Err(error);
|
||||
}
|
||||
match child.stdin.take() {
|
||||
Some(pipe) => Ok(Reporter { pipe, child }),
|
||||
None => {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
Err(io::Error::other("crash reporter has no control pipe"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A fixed acknowledgement means the helper holds the process observation before heavy GUI
|
||||
/// work begins. A suspended helper cannot hold startup indefinitely.
|
||||
fn ready(child: &mut Child) -> io::Result<()> {
|
||||
let mut output = child.stdout.take().ok_or_else(|| io::Error::other("crash reporter has no readiness pipe"))?;
|
||||
let (send, receive) = mpsc::sync_channel(1);
|
||||
std::thread::Builder::new().name("ec-reporter-ready".into()).spawn(move || {
|
||||
let mut bytes = [0; READY.len()];
|
||||
#[cfg(not(test))]
|
||||
let result =
|
||||
output.read_exact(&mut bytes).and_then(|()| if bytes == READY { Ok(()) } else { Err(io::Error::other("invalid reporter acknowledgement")) });
|
||||
// libtest prints its bounded banner before invoking the helper role.
|
||||
#[cfg(test)]
|
||||
let result = (|| {
|
||||
for _ in 0..1024 {
|
||||
bytes.rotate_left(1);
|
||||
output.read_exact(&mut bytes[READY.len() - 1..])?;
|
||||
if bytes == READY {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(io::Error::other("reporter acknowledgement missing"))
|
||||
})();
|
||||
let _ = send.send(result);
|
||||
// Keep the pipe open for libtest's trailing result (and future helper output), without
|
||||
// storing it. Dropping it at READY would turn a clean helper exit into BrokenPipe.
|
||||
let _ = io::copy(&mut output, &mut io::sink());
|
||||
})?;
|
||||
receive.recv_timeout(Duration::from_secs(3)).map_err(|_| io::Error::other("crash reporter readiness timed out"))?
|
||||
}
|
||||
|
||||
/// Handle the internal mode before logging, argument parsing, updates or GUI initialization.
|
||||
/// The callback is a native dialog on this helper's main thread, not on the failed GUI's.
|
||||
pub fn maybe_run(args: &[OsString], show: impl FnOnce(&str)) -> bool {
|
||||
if args.first().map(OsString::as_os_str) != Some(OsStr::new(FLAG)) {
|
||||
return false;
|
||||
}
|
||||
let parsed = match args {
|
||||
[_, id, log, reports, interactive, pid] => id
|
||||
.to_str()
|
||||
.filter(|id| valid_id(id))
|
||||
.zip(match interactive.to_str() {
|
||||
Some("0") => Some(false),
|
||||
Some("1") => Some(true),
|
||||
_ => None,
|
||||
})
|
||||
.zip(pid.to_str().and_then(|p| p.parse::<u32>().ok()).filter(|pid| *pid != 0))
|
||||
.map(|((id, interactive), pid)| (id, (!log.is_empty()).then(|| Path::new(log)), Path::new(reports), interactive, pid)),
|
||||
_ => None,
|
||||
};
|
||||
let Some((id, log, reports, interactive, pid)) = parsed else {
|
||||
eprintln!("EffectCraft crash reporter: invalid internal arguments");
|
||||
return true;
|
||||
};
|
||||
// Keep the exact file open while the GUI is alive: a later rotation must not substitute
|
||||
// another instance's log. If rotation won the startup race, the session marker rejects it.
|
||||
let mut log = SessionLog::open(log, id);
|
||||
let mut observation = observation::Observation::start(pid);
|
||||
// A GUI that dies during helper startup can already have closed this read end. Keep
|
||||
// watching its control pipe and save the report rather than losing that early failure.
|
||||
let _ = io::stdout().write_all(READY).and_then(|()| io::stdout().flush());
|
||||
// The reader has one bounded queue; the monitor never waits on a live pipe, so it can
|
||||
// sample the target even when no log or lifecycle message is emitted.
|
||||
let (send, receive) = mpsc::sync_channel(1);
|
||||
let reader = std::thread::Builder::new().name("ec-reporter-pipe".into()).spawn(move || {
|
||||
let mut input = io::stdin().lock();
|
||||
loop {
|
||||
let message = read_message(&mut input);
|
||||
let terminal = !matches!(message, Ok(Message::Event(_)));
|
||||
if send.send(message).is_err() || terminal {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
let mut events = VecDeque::with_capacity(EVENT_COUNT);
|
||||
let failure = if reader.is_err() {
|
||||
Some("control reader could not start".to_owned())
|
||||
} else {
|
||||
loop {
|
||||
observation.tick();
|
||||
match receive.recv_timeout(Duration::from_millis(250)) {
|
||||
Ok(Ok(Message::Clean)) => return true,
|
||||
Ok(Ok(Message::Event(event))) => {
|
||||
if events.len() == EVENT_COUNT {
|
||||
events.pop_front();
|
||||
}
|
||||
events.push_back(format!("{} {event}", observation::utc()));
|
||||
}
|
||||
Ok(Ok(Message::Ended)) => break None,
|
||||
Ok(Err(error)) => break Some(error.to_string()),
|
||||
Err(RecvTimeoutError::Timeout) => continue,
|
||||
Err(RecvTimeoutError::Disconnected) => break Some("control reader disconnected".to_owned()),
|
||||
}
|
||||
}
|
||||
};
|
||||
observation.finish();
|
||||
let saved = write_report(reports, id, &mut log, failure.as_deref(), &observation, &events);
|
||||
let description = description(&saved, observation.confirmed_exit());
|
||||
eprintln!("{description}");
|
||||
if interactive {
|
||||
show(&description);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn valid_id(id: &str) -> bool {
|
||||
!id.is_empty() && id.len() <= 80 && id.bytes().all(|c| c.is_ascii_digit() || c == b'-')
|
||||
}
|
||||
|
||||
enum Message {
|
||||
Clean,
|
||||
Event(String),
|
||||
Ended,
|
||||
}
|
||||
|
||||
/// Every line and the retained event ring are bounded, including malformed control input.
|
||||
fn read_message(input: &mut impl Read) -> io::Result<Message> {
|
||||
let mut line = [0u8; EVENT_BYTES];
|
||||
for i in 0..line.len() {
|
||||
let byte = line.get_mut(i).ok_or_else(|| io::Error::other("invalid control offset"))?;
|
||||
loop {
|
||||
match input.read(std::slice::from_mut(byte)) {
|
||||
Ok(0) => return Ok(Message::Ended),
|
||||
Ok(_) => break,
|
||||
Err(error) if error.kind() == io::ErrorKind::Interrupted => continue,
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
if *byte == b'\n' {
|
||||
let text = line.get(..=i).ok_or_else(|| io::Error::other("invalid control line"))?;
|
||||
if text == CLEAN {
|
||||
return Ok(Message::Clean);
|
||||
}
|
||||
if let Some(event) = text.strip_prefix(b"EVENT ") {
|
||||
let event = std::str::from_utf8(event).map_err(|_| io::Error::other("non-UTF8 diagnostic observation"))?;
|
||||
return Ok(Message::Event(event.trim_end().to_owned()));
|
||||
}
|
||||
return Ok(Message::Ended);
|
||||
}
|
||||
}
|
||||
Err(io::Error::other("control line exceeded its fixed limit"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn clean_exit(input: &mut impl Read) -> io::Result<bool> {
|
||||
Ok(matches!(read_message(input)?, Message::Clean))
|
||||
}
|
||||
|
||||
enum SessionLog {
|
||||
Captured { file: File, marker: String },
|
||||
Unavailable(String),
|
||||
}
|
||||
|
||||
impl SessionLog {
|
||||
fn open(path: Option<&Path>, id: &str) -> Self {
|
||||
let opened = (|| {
|
||||
let path = path.ok_or_else(|| io::Error::other("no session log was opened"))?;
|
||||
let mut file = File::open(path)?;
|
||||
let mut header = [0u8; HEADER_BYTES];
|
||||
let marker = format!("{}\n", session_marker(id));
|
||||
let prefix = header.get_mut(..marker.len()).ok_or_else(|| io::Error::other("session marker too long"))?;
|
||||
file.read_exact(prefix)?;
|
||||
if prefix != marker.as_bytes() {
|
||||
return Err(io::Error::other("matching session marker unavailable; the log may have rotated"));
|
||||
}
|
||||
Ok(file)
|
||||
})();
|
||||
match opened {
|
||||
Ok(file) => Self::Captured { file, marker: format!("{}\n", session_marker(id)) },
|
||||
Err(e) => Self::Unavailable(e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn write_tail(&mut self, report: &mut File) -> io::Result<()> {
|
||||
match self {
|
||||
Self::Unavailable(reason) => writeln!(report, "Recent log unavailable: {reason}"),
|
||||
Self::Captured { file, marker } => {
|
||||
// An older concurrent launcher may have truncated the captured file.
|
||||
// Recheck its identity before copying any content into this report.
|
||||
file.seek(SeekFrom::Start(0))?;
|
||||
let mut header = [0u8; HEADER_BYTES];
|
||||
let prefix = header.get_mut(..marker.len()).ok_or_else(|| io::Error::other("session marker too long"))?;
|
||||
if file.read_exact(prefix).is_err() || prefix != marker.as_bytes() {
|
||||
return writeln!(report, "Recent log unavailable: session identity changed");
|
||||
}
|
||||
let size = file.metadata()?.len();
|
||||
file.seek(SeekFrom::Start(size.saturating_sub(LOG_BYTES as u64)))?;
|
||||
writeln!(report, "\nRecorded session log tail (last {LOG_BYTES} bytes at most; logging filters/size caps may omit later events):")?;
|
||||
io::copy(&mut file.take(LOG_BYTES as u64), report)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_report(
|
||||
reports: &Path,
|
||||
id: &str,
|
||||
log: &mut SessionLog,
|
||||
pipe_error: Option<&str>,
|
||||
observation: &observation::Observation,
|
||||
events: &VecDeque<String>,
|
||||
) -> io::Result<PathBuf> {
|
||||
if !valid_id(id) {
|
||||
return Err(io::Error::other("invalid report identity"));
|
||||
}
|
||||
std::fs::create_dir_all(reports)?;
|
||||
let path = reports.join(format!("crash-{id}.txt"));
|
||||
let mut report = OpenOptions::new().write(true).create_new(true).open(&path)?;
|
||||
writeln!(
|
||||
report,
|
||||
"EffectCraft unexpected-exit diagnostic\nVersion: {}\nPlatform: {} / {}\nSession: {id}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
std::env::consts::OS,
|
||||
std::env::consts::ARCH
|
||||
)?;
|
||||
writeln!(
|
||||
report,
|
||||
"The GUI control channel ended without its clean-exit marker.\nThe exact cause is not established. GPU fallback, memory pressure and process exit are separate observations, not a proven causal chain.\nThis report was saved locally; it was not sent anywhere."
|
||||
)?;
|
||||
observation.write(&mut report)?;
|
||||
writeln!(report, "\nRetained lifecycle observations (last {EVENT_COUNT}; UTC is helper receipt time):")?;
|
||||
for event in events {
|
||||
writeln!(report, "{event}")?;
|
||||
}
|
||||
if let Some(error) = pipe_error {
|
||||
writeln!(report, "Control pipe error: {error}")?;
|
||||
}
|
||||
if let Err(error) = log.write_tail(&mut report) {
|
||||
writeln!(report, "\nCould not read the recent session log: {error}")?;
|
||||
}
|
||||
report.flush()?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn description(saved: &io::Result<PathBuf>, confirmed_exit: bool) -> String {
|
||||
let diagnostic = match saved {
|
||||
Ok(path) => format!("A diagnostic report was saved to:\n{}", path.display()),
|
||||
Err(error) => format!("A diagnostic report could not be saved: {error}"),
|
||||
};
|
||||
let incident =
|
||||
if confirmed_exit { "EffectCraft stopped unexpectedly." } else { "EffectCraft lost its diagnostic control channel; process exit is not confirmed." };
|
||||
format!(
|
||||
"{incident}\n\n{diagnostic}\n\nThe exact cause is unknown. If EffectCraft has closed, reopen it to check for an existing auto-save. Changes since the last auto-save may be lost.\n\nNo report has been sent anywhere."
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
static NEXT: AtomicUsize = AtomicUsize::new(0);
|
||||
const ROLE: &str = "EFFECTCRAFT_CRASH_REPORT_TEST_ROLE";
|
||||
|
||||
fn test_report(dir: &Path, id: &str, log: &mut SessionLog) -> io::Result<PathBuf> {
|
||||
write_report(dir, id, log, None, &observation::Observation::start(std::process::id()), &VecDeque::new())
|
||||
}
|
||||
|
||||
fn folder() -> PathBuf {
|
||||
let p = std::env::temp_dir().join(format!("ec-crash-report-{}-{}", run_id(), NEXT.fetch_add(1, Ordering::Relaxed)));
|
||||
std::fs::create_dir_all(&p).unwrap();
|
||||
p
|
||||
}
|
||||
|
||||
fn test_name(name: &str) -> String {
|
||||
// Also usable from an isolated harness with the reporter dependencies.
|
||||
let prefix = module_path!().split_once("::").map_or("", |(_, rest)| rest);
|
||||
format!("{prefix}::{name}")
|
||||
}
|
||||
|
||||
fn helper(dir: &Path, id: &str) -> Reporter {
|
||||
helper_mode(dir, id, false)
|
||||
}
|
||||
|
||||
fn helper_mode(dir: &Path, id: &str, interactive: bool) -> Reporter {
|
||||
let mut child = Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", &test_name("reporter_process"), "--ignored", "--nocapture"])
|
||||
.env(ROLE, "reporter")
|
||||
.env("EC_REPORT_DIR", dir)
|
||||
.env("EC_REPORT_ID", id)
|
||||
.env("EC_REPORT_INTERACTIVE", if interactive { "1" } else { "0" })
|
||||
.env("EC_REPORT_PID", std::process::id().to_string())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
ready(&mut child).unwrap();
|
||||
Reporter { pipe: child.stdin.take().unwrap(), child }
|
||||
}
|
||||
|
||||
fn wait_file(path: &Path) {
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
while !path.is_file() && Instant::now() < until {
|
||||
thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
assert!(path.is_file(), "report did not arrive: {}", path.display());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounded_protocol_rejects_eof_and_partial_or_wrong_markers() {
|
||||
let mut clean = CLEAN;
|
||||
assert!(clean_exit(&mut clean).unwrap());
|
||||
for mut input in [b"".as_slice(), &CLEAN[..CLEAN.len() - 1], b"clean", b"EFFECTCRAFT_CLEAN_EXIT_V0\n"] {
|
||||
assert!(!clean_exit(&mut input).unwrap());
|
||||
}
|
||||
assert!(clean_exit(&mut &vec![b'x'; 100_000][..]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn report_is_bounded_and_keeps_its_session_after_log_rotation() {
|
||||
let dir = folder();
|
||||
let original = dir.join("effectcraft.log");
|
||||
let id = "123-456";
|
||||
std::fs::write(&original, format!("{}\n", session_marker(id))).unwrap();
|
||||
let mut log = SessionLog::open(Some(&original), id);
|
||||
std::fs::rename(&original, dir.join("effectcraft.1.log")).unwrap();
|
||||
std::fs::write(&original, "OTHER SESSION MUST NOT APPEAR").unwrap();
|
||||
let mut old = OpenOptions::new().append(true).open(dir.join("effectcraft.1.log")).unwrap();
|
||||
old.write_all(&vec![b'a'; LOG_BYTES * 2]).unwrap();
|
||||
old.write_all(b"\nGPU context retired\n").unwrap();
|
||||
let report = test_report(&dir, id, &mut log).unwrap();
|
||||
let text = std::fs::read_to_string(report).unwrap();
|
||||
assert!(text.len() < LOG_BYTES + 4096);
|
||||
assert!(text.contains("GPU context retired"));
|
||||
assert!(!text.contains("OTHER SESSION"));
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_session_and_missing_logs_are_reported_without_reading_other_content() {
|
||||
let dir = folder();
|
||||
let path = dir.join("log");
|
||||
std::fs::write(&path, "private other session").unwrap();
|
||||
for (id, source) in [("1-1", Some(path.as_path())), ("1-2", None)] {
|
||||
let report = test_report(&dir, id, &mut SessionLog::open(source, id)).unwrap();
|
||||
let text = std::fs::read_to_string(report).unwrap();
|
||||
assert!(text.contains("Recent log unavailable"));
|
||||
assert!(!text.contains("private other session"));
|
||||
}
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn captured_log_rejects_a_session_overwritten_after_open() {
|
||||
let dir = folder();
|
||||
let path = dir.join("log");
|
||||
std::fs::write(&path, "crash-report session 1-2\noriginal session\n").unwrap();
|
||||
let mut log = SessionLog::open(Some(&path), "1-2");
|
||||
std::fs::write(&path, "crash-report session 3-4\nprivate other session\n").unwrap();
|
||||
let report = test_report(&dir, "1-2", &mut log).unwrap();
|
||||
let text = std::fs::read_to_string(report).unwrap();
|
||||
assert!(text.contains("Recent log unavailable"));
|
||||
assert!(!text.contains("private other session"));
|
||||
assert!(!text.contains("session 3-4"));
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_identity_requires_the_exact_first_line() {
|
||||
let dir = folder();
|
||||
let path = dir.join("log");
|
||||
for header in ["crash-report session 1-20\n", "unrelated\ncrash-report session 1-2\n"] {
|
||||
std::fs::write(&path, header).unwrap();
|
||||
assert!(matches!(SessionLog::open(Some(&path), "1-2"), SessionLog::Unavailable(_)));
|
||||
}
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn report_write_failure_is_described_and_existing_report_is_not_overwritten() {
|
||||
let dir = folder();
|
||||
let mut log = SessionLog::Unavailable("no log".into());
|
||||
let first = test_report(&dir, "2-1", &mut log).unwrap();
|
||||
let before = std::fs::read(&first).unwrap();
|
||||
let result = test_report(&dir, "2-1", &mut log);
|
||||
assert!(result.is_err());
|
||||
assert!(description(&result, false).contains("could not be saved"));
|
||||
assert_eq!(std::fs::read(first).unwrap(), before);
|
||||
assert!(test_report(&dir, "../escape", &mut log).is_err());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normal_and_handled_shutdown_send_clean_marker_without_a_report() {
|
||||
for id in ["3-1", "3-2"] {
|
||||
let dir = folder();
|
||||
let r = helper(&dir, id);
|
||||
r.finish().unwrap();
|
||||
// A completion file proves the helper consumed the marker, not merely that it
|
||||
// hadn't yet produced a report.
|
||||
wait_file(&dir.join(format!("ready-{id}")));
|
||||
assert!(!dir.join(format!("crash-{id}.txt")).exists());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepted_native_close_finishes_before_process_termination() {
|
||||
let dir = folder();
|
||||
let status = Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", &test_name("aborting_parent"), "--ignored", "--nocapture"])
|
||||
.env(ROLE, "native-close")
|
||||
.env("EC_REPORT_DIR", &dir)
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success());
|
||||
wait_file(&dir.join("ready-8-1"));
|
||||
assert!(!dir.join("crash-8-1.txt").exists());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_teardown_panic_does_not_mark_the_reporter_clean() {
|
||||
let dir = folder();
|
||||
let reporter = Shutdown::default();
|
||||
reporter.install(helper(&dir, "8-2")).unwrap();
|
||||
let result = std::panic::catch_unwind(|| {
|
||||
let _ = after_teardown(Some(&reporter), || panic!("simulated teardown failure"));
|
||||
});
|
||||
assert!(result.is_err());
|
||||
drop(reporter);
|
||||
wait_file(&dir.join("ready-8-2"));
|
||||
assert!(dir.join("crash-8-2.txt").exists());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn platforms_returning_to_main_keep_the_reporter_armed_until_then() {
|
||||
let dir = folder();
|
||||
let reporter = Shutdown::default();
|
||||
reporter.install(helper(&dir, "8-3")).unwrap();
|
||||
after_teardown(None, || {}).unwrap();
|
||||
assert!(reporter.0.lock().unwrap().is_some());
|
||||
reporter.clone().finish().unwrap();
|
||||
reporter.finish().unwrap();
|
||||
wait_file(&dir.join("ready-8-3"));
|
||||
assert!(!dir.join("crash-8-3.txt").exists());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_aborting_parent_leaves_one_diagnostic_report() {
|
||||
let dir = folder();
|
||||
let status = Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", &test_name("aborting_parent"), "--ignored", "--nocapture"])
|
||||
.env(ROLE, "abort")
|
||||
.env("EC_REPORT_DIR", &dir)
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(!status.success());
|
||||
wait_file(&dir.join("ready-4-1"));
|
||||
let text = std::fs::read_to_string(dir.join("crash-4-1.txt")).unwrap();
|
||||
assert!(text.contains("exact cause is not established"));
|
||||
assert!(text.contains("Detection UTC:"));
|
||||
#[cfg(windows)]
|
||||
assert!(text.contains("Windows status bits:"));
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unrelated_child_does_not_keep_the_control_pipe_open() {
|
||||
let dir = folder();
|
||||
let r = helper(&dir, "5-1");
|
||||
let mut unrelated = Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", &test_name("lingering_child"), "--ignored", "--nocapture"])
|
||||
.env(ROLE, "linger")
|
||||
.stdout(Stdio::null())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
drop(r);
|
||||
wait_file(&dir.join("ready-5-1"));
|
||||
assert!(unrelated.try_wait().unwrap().is_none());
|
||||
unrelated.kill().unwrap();
|
||||
unrelated.wait().unwrap();
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unresponsive_helper_cannot_hang_clean_shutdown() {
|
||||
let mut child = Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", &test_name("lingering_child"), "--ignored", "--nocapture"])
|
||||
.env(ROLE, "linger")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::null())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let pipe = child.stdin.take().unwrap();
|
||||
let started = Instant::now();
|
||||
let result = Reporter { pipe, child }.finish();
|
||||
assert!(result.unwrap_err().to_string().contains("was terminated"));
|
||||
assert!(started.elapsed() < Duration::from_secs(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simultaneous_sessions_write_separate_reports() {
|
||||
let dir = folder();
|
||||
let a = helper(&dir, "6-1");
|
||||
let b = helper(&dir, "6-2");
|
||||
drop(a);
|
||||
drop(b);
|
||||
wait_file(&dir.join("ready-6-1"));
|
||||
wait_file(&dir.join("ready-6-2"));
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interactive_failure_calls_dialog_once_after_saving_the_report() {
|
||||
let dir = folder();
|
||||
drop(helper_mode(&dir, "7-1", true));
|
||||
wait_file(&dir.join("ready-7-1"));
|
||||
let text = std::fs::read_to_string(dir.join("dialog-7-1")).unwrap();
|
||||
assert!(text.contains("crash-7-1.txt"));
|
||||
assert!(text.contains("No report has been sent"));
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lost_pipe_keeps_bounded_lifecycle_evidence_without_claiming_process_exit() {
|
||||
let dir = folder();
|
||||
let reporter = Shutdown::default();
|
||||
reporter.install(helper(&dir, "9-1")).unwrap();
|
||||
for _ in 0..40 {
|
||||
reporter.record("GPU observation: wgpu validation error").unwrap();
|
||||
}
|
||||
drop(reporter);
|
||||
wait_file(&dir.join("ready-9-1"));
|
||||
let text = std::fs::read_to_string(dir.join("crash-9-1.txt")).unwrap();
|
||||
assert!(text.contains("GUI still present"));
|
||||
assert!(!text.contains("process termination observed"));
|
||||
assert_eq!(text.matches("GPU observation: wgpu validation error").count(), EVENT_COUNT);
|
||||
assert!(text.contains("Target-present sampling attempts:"));
|
||||
assert!(text.len() < 8192);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clean_exit_after_lifecycle_events_does_not_write_a_report() {
|
||||
let dir = folder();
|
||||
let reporter = Shutdown::default();
|
||||
reporter.install(helper(&dir, "9-2")).unwrap();
|
||||
reporter.record("Backend selection source: default").unwrap();
|
||||
reporter.finish().unwrap();
|
||||
wait_file(&dir.join("ready-9-2"));
|
||||
assert!(!dir.join("crash-9-2.txt").exists());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn windows_report_preserves_real_unsigned_exit_bits() {
|
||||
let dir = folder();
|
||||
let status = Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", &test_name("aborting_parent"), "--ignored", "--nocapture"])
|
||||
.env(ROLE, "windows-status")
|
||||
.env("EC_REPORT_DIR", &dir)
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.unwrap();
|
||||
assert_eq!(status.code().map(|code| code as u32), Some(0xc0000017));
|
||||
wait_file(&dir.join("ready-9-3"));
|
||||
let text = std::fs::read_to_string(dir.join("crash-9-3.txt")).unwrap();
|
||||
assert!(text.contains("Windows status bits: 0xC0000017 (STATUS_NO_MEMORY)"));
|
||||
assert!(text.contains("not a verified exception record"));
|
||||
assert!(text.contains("process termination observed"));
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_mode_rejects_invalid_arguments_without_launching_the_app() {
|
||||
assert!(!maybe_run(&[], |_| panic!("no dialog")));
|
||||
assert!(!maybe_run(&[OsString::from("--version")], |_| panic!("no dialog")));
|
||||
assert!(maybe_run(&[OsString::from(FLAG)], |_| panic!("no dialog")));
|
||||
let args = [FLAG, "../escape", "", "", "1", "1"].map(OsString::from);
|
||||
assert!(maybe_run(&args, |_| panic!("no dialog")));
|
||||
let args = [FLAG, "1-1", "", "", "invalid", "1"].map(OsString::from);
|
||||
assert!(maybe_run(&args, |_| panic!("no dialog")));
|
||||
for pid in ["0", "not-a-pid", "4294967296"] {
|
||||
let args = [FLAG, "1-1", "", "", "0", pid].map(OsString::from);
|
||||
assert!(maybe_run(&args, |_| panic!("no dialog")));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_helper_is_an_error_not_a_panic() {
|
||||
assert!(spawn(Path::new("/nonexistent-effectcraft-crash-helper"), &[]).is_err());
|
||||
}
|
||||
|
||||
// Roles are ignored by ordinary test runs. Explicit subprocess invocations exercise
|
||||
// real EOF/abort behavior without allocating a huge image or killing the test runner.
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn reporter_process() {
|
||||
assert_eq!(std::env::var(ROLE).unwrap(), "reporter");
|
||||
let dir = PathBuf::from(std::env::var_os("EC_REPORT_DIR").unwrap());
|
||||
let id = std::env::var("EC_REPORT_ID").unwrap();
|
||||
let interactive = std::env::var("EC_REPORT_INTERACTIVE").unwrap();
|
||||
let args = [
|
||||
OsString::from(FLAG),
|
||||
OsString::from(&id),
|
||||
OsString::new(),
|
||||
dir.as_os_str().to_owned(),
|
||||
OsString::from(&interactive),
|
||||
std::env::var_os("EC_REPORT_PID").unwrap(),
|
||||
];
|
||||
assert!(maybe_run(&args, |description| {
|
||||
assert_eq!(interactive, "1", "non-interactive reporter must not show a dialog");
|
||||
assert!(dir.join(format!("crash-{id}.txt")).exists());
|
||||
let mut shown = OpenOptions::new().write(true).create_new(true).open(dir.join(format!("dialog-{id}"))).unwrap();
|
||||
shown.write_all(description.as_bytes()).unwrap();
|
||||
}));
|
||||
std::fs::write(dir.join(format!("ready-{id}")), b"done").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn aborting_parent() {
|
||||
let role = std::env::var(ROLE).unwrap();
|
||||
let dir = PathBuf::from(std::env::var_os("EC_REPORT_DIR").unwrap());
|
||||
if role == "native-close" {
|
||||
let reporter = Shutdown::default();
|
||||
reporter.install(helper(&dir, "8-1")).unwrap();
|
||||
after_teardown(Some(&reporter.clone()), || {}).unwrap();
|
||||
std::process::exit(0); // Models macOS not returning from its native event loop.
|
||||
}
|
||||
if role == "windows-status" {
|
||||
let _reporter = helper(&dir, "9-3");
|
||||
// The real OS status is intentionally set, not actual memory exhaustion. The
|
||||
// report must preserve this distinction rather than claiming a verified exception.
|
||||
std::process::exit(0xc0000017u32 as i32);
|
||||
}
|
||||
assert_eq!(role, "abort");
|
||||
let _reporter = helper(&dir, "4-1");
|
||||
std::process::abort();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn lingering_child() {
|
||||
assert_eq!(std::env::var(ROLE).unwrap(), "linger");
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
//! Fixed-vocabulary observations retained by the crash helper independently of the log tail.
|
||||
//! Driver messages and environment text can contain private data; never forward either here.
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
|
||||
use crate::crash_report::Shutdown;
|
||||
|
||||
pub fn record(reporter: &Shutdown, event: &'static str) {
|
||||
log::info!("diagnostic observation: {event}");
|
||||
if let Err(error) = reporter.record(event) {
|
||||
log::warn!("could not retain diagnostic observation: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Mirror only wgpu's documented names/aliases, without calling its parser: that parser
|
||||
/// logs unknown tokens verbatim. Unknown, non-Unicode and oversized values remain private.
|
||||
pub fn backend_override_events(value: &OsStr) -> Vec<&'static str> {
|
||||
let Some(value) = value.to_str().filter(|value| value.len() <= 4096) else {
|
||||
return vec!["WGPU_BACKEND: non-Unicode or oversized value omitted"];
|
||||
};
|
||||
let mut selected = [false; 6];
|
||||
let mut unknown = false;
|
||||
for token in value.split(',').map(str::trim) {
|
||||
let aliases: &[&[&str]] = &[&["vulkan", "vk"], &["dx12", "d3d12"], &["metal", "mtl"], &["opengl", "gles", "gl"], &["webgpu"], &["noop"]];
|
||||
if let Some(index) = aliases.iter().position(|names| names.iter().any(|name| token.eq_ignore_ascii_case(name))) {
|
||||
if let Some(flag) = selected.get_mut(index) {
|
||||
*flag = true;
|
||||
}
|
||||
} else {
|
||||
unknown = true;
|
||||
}
|
||||
}
|
||||
let events = [
|
||||
"WGPU_BACKEND requests: vulkan",
|
||||
"WGPU_BACKEND requests: dx12",
|
||||
"WGPU_BACKEND requests: metal",
|
||||
"WGPU_BACKEND requests: gl",
|
||||
"WGPU_BACKEND requests: webgpu",
|
||||
"WGPU_BACKEND requests: noop",
|
||||
];
|
||||
let mut result: Vec<_> = selected.into_iter().zip(events).filter_map(|(present, event)| present.then_some(event)).collect();
|
||||
if unknown {
|
||||
result.push("WGPU_BACKEND: unrecognized or empty tokens omitted");
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// At most eight events per device, even when a driver floods its callbacks. A wgpu OOM
|
||||
/// observation is not proof of system RAM exhaustion; device loss is not a driver-crash verdict.
|
||||
#[derive(Clone)]
|
||||
pub struct GpuObservations {
|
||||
seen: Arc<AtomicU8>,
|
||||
reporter: Shutdown,
|
||||
}
|
||||
|
||||
impl GpuObservations {
|
||||
pub fn new(reporter: &Shutdown) -> Self {
|
||||
Self { seen: Arc::new(AtomicU8::new(0)), reporter: reporter.clone() }
|
||||
}
|
||||
|
||||
pub fn uncaptured(&self, error: &eframe::wgpu::Error) {
|
||||
let (bit, event) = match error {
|
||||
eframe::wgpu::Error::OutOfMemory { .. } => (1, "GPU observation: wgpu out-of-memory error (not proof of system RAM exhaustion)"),
|
||||
eframe::wgpu::Error::Validation { .. } => (2, "GPU observation: wgpu validation error"),
|
||||
eframe::wgpu::Error::Internal { .. } => (4, "GPU observation: wgpu internal error"),
|
||||
};
|
||||
self.once(bit, event);
|
||||
}
|
||||
|
||||
pub fn scoped(&self, error: effectcraft_ui_egui::gpu_failure::ScopedError) {
|
||||
use effectcraft_ui_egui::gpu_failure::ScopedError;
|
||||
let (bit, event) = match error {
|
||||
ScopedError::OutOfMemory => (32, "GPU scoped observation: out-of-memory (not proof of system RAM exhaustion)"),
|
||||
ScopedError::Internal => (64, "GPU scoped observation: internal error (not confirmed out-of-memory)"),
|
||||
ScopedError::Validation => (128, "GPU scoped observation: validation error"),
|
||||
};
|
||||
self.once(bit, event);
|
||||
}
|
||||
|
||||
pub fn device_lost(&self, reason: eframe::wgpu::DeviceLostReason) {
|
||||
match reason {
|
||||
eframe::wgpu::DeviceLostReason::Unknown => self.once(8, "GPU observation: device lost, reason unknown (not proof of a driver crash)"),
|
||||
eframe::wgpu::DeviceLostReason::Destroyed => self.once(16, "GPU observation: device-lost callback, explicit device destruction"),
|
||||
};
|
||||
}
|
||||
|
||||
fn once(&self, bit: u8, event: &'static str) -> bool {
|
||||
if self.seen.fetch_or(bit, Ordering::Relaxed) & bit != 0 {
|
||||
return false;
|
||||
}
|
||||
record(&self.reporter, event);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn override_names_are_normalized_deduplicated_and_private() {
|
||||
let events = backend_override_events(OsStr::new(" Vk, VULKAN, d3d12, MTL, gles, webgpu, noop, private-token"));
|
||||
assert_eq!(events.len(), 7);
|
||||
assert_eq!(events.first(), Some(&"WGPU_BACKEND requests: vulkan"));
|
||||
assert!(!events.join(" ").contains("private-token"));
|
||||
assert!(events.iter().all(|event| event.len() <= 100));
|
||||
assert_eq!(backend_override_events(OsStr::new("")).len(), 1);
|
||||
assert_eq!(backend_override_events(OsStr::new(&"x".repeat(4097))), ["WGPU_BACKEND: non-Unicode or oversized value omitted"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gpu_categories_are_latched_independently() {
|
||||
let observations = GpuObservations::new(&Shutdown::default());
|
||||
observations.uncaptured(&eframe::wgpu::Error::OutOfMemory { source: Box::new(std::io::Error::other("private driver detail")) });
|
||||
observations.device_lost(eframe::wgpu::DeviceLostReason::Unknown);
|
||||
observations.device_lost(eframe::wgpu::DeviceLostReason::Unknown);
|
||||
assert_eq!(observations.seen.load(Ordering::Relaxed), 9);
|
||||
observations.device_lost(eframe::wgpu::DeviceLostReason::Destroyed);
|
||||
observations.uncaptured(&eframe::wgpu::Error::Validation {
|
||||
source: Box::new(std::io::Error::other("private driver detail")),
|
||||
description: "private validation detail".into(),
|
||||
});
|
||||
observations.uncaptured(&eframe::wgpu::Error::Internal {
|
||||
source: Box::new(std::io::Error::other("private driver detail")),
|
||||
description: "private internal detail".into(),
|
||||
});
|
||||
assert_eq!(observations.seen.load(Ordering::Relaxed), 31);
|
||||
use effectcraft_ui_egui::gpu_failure::ScopedError;
|
||||
observations.scoped(ScopedError::Internal);
|
||||
assert_eq!(observations.seen.load(Ordering::Relaxed), 95, "internal scope must not set scoped OOM bit");
|
||||
observations.scoped(ScopedError::OutOfMemory);
|
||||
observations.scoped(ScopedError::Validation);
|
||||
observations.scoped(ScopedError::OutOfMemory);
|
||||
assert_eq!(observations.seen.load(Ordering::Relaxed), 255);
|
||||
assert!(!observations.once(1, "GPU observation: duplicate"));
|
||||
assert!(!observations.once(8, "GPU observation: duplicate"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn non_unicode_override_is_not_copied() {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
assert_eq!(backend_override_events(OsStr::from_bytes(b"private\xff")), ["WGPU_BACKEND: non-Unicode or oversized value omitted"]);
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@
|
||||
//! until its window has kept drawing for [`SETTLE`] (or the app quits normally before then). A
|
||||
//! launch that finds the previous one's marker switches Window Graphics to OpenGL, which those
|
||||
//! drivers run, and says so once the window is up. `WGPU_BACKEND` (wgpu's own override) still
|
||||
//! wins over both. The marker is locked while its launch runs, so a second copy opened meanwhile
|
||||
//! isn't taken for a crash; and a window OpenGL can't open either puts Window Graphics back to
|
||||
//! Automatic ([`opengl_failed`]) rather than failing every launch.
|
||||
//! wins over both. A separate guard file is locked while its launch runs, so a second copy opened
|
||||
//! meanwhile isn't taken for a crash; and a window OpenGL can't open either puts Window Graphics
|
||||
//! back to Automatic ([`opengl_failed`]) rather than failing every launch.
|
||||
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -21,6 +21,46 @@ use eframe::wgpu::Backends;
|
||||
|
||||
/// Left in the settings folder from a launch until its window has settled.
|
||||
const MARKER: &str = "launch-pending";
|
||||
const LOCK: &str = "launch.lock";
|
||||
|
||||
/// Keep this file in place: unlinking a locked file lets a second inode acquire a new lock.
|
||||
fn acquire_guard(dir: &Path) -> Option<File> {
|
||||
let file = match std::fs::create_dir_all(dir)
|
||||
.and_then(|()| std::fs::OpenOptions::new().read(true).write(true).create(true).truncate(false).open(dir.join(LOCK)))
|
||||
{
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
log::warn!("launch guard unavailable: {e}");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
match file.try_lock() {
|
||||
Ok(()) => {}
|
||||
Err(std::fs::TryLockError::WouldBlock) => return None,
|
||||
Err(e) => {
|
||||
log::warn!("launch guard lock unavailable: {e}");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
// Older versions lock the marker itself. Probe only the lock: Windows also prevents
|
||||
// reads through another handle while it is held. An unreadable marker is not a stale one.
|
||||
match File::open(dir.join(MARKER)) {
|
||||
Ok(marker) => match marker.try_lock() {
|
||||
Ok(()) => {}
|
||||
Err(std::fs::TryLockError::WouldBlock) => return None,
|
||||
Err(e) => {
|
||||
log::warn!("launch marker lock unavailable: {e}");
|
||||
return None;
|
||||
}
|
||||
},
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
||||
Err(e) => {
|
||||
log::warn!("launch marker unavailable: {e}");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(file)
|
||||
}
|
||||
|
||||
/// How long the window keeps drawing after its first frame before the launch counts as made.
|
||||
/// A driver that fails as the window is shown and its surface re-created does so within the
|
||||
@@ -28,16 +68,39 @@ const MARKER: &str = "launch-pending";
|
||||
/// switch back in Settings.
|
||||
pub const SETTLE: Duration = Duration::from_secs(3);
|
||||
|
||||
/// Why this launch requested its window graphics APIs. An interrupted startup is an
|
||||
/// observation, not proof that a driver caused the previous exit.
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BackendSource {
|
||||
#[default]
|
||||
Default,
|
||||
SavedPreference,
|
||||
InterruptedStartup,
|
||||
EnvironmentOverride,
|
||||
}
|
||||
|
||||
impl BackendSource {
|
||||
pub fn event(self) -> &'static str {
|
||||
match self {
|
||||
Self::Default => "backend source: default",
|
||||
Self::SavedPreference => "backend source: saved OpenGL preference",
|
||||
Self::InterruptedStartup => "backend source: previous interrupted startup; OpenGL fallback",
|
||||
Self::EnvironmentOverride => "backend source: WGPU_BACKEND present",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This launch's window graphics.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Launch {
|
||||
/// The graphics APIs the window may use (`None`: eframe's default).
|
||||
pub backends: Option<Backends>,
|
||||
pub source: BackendSource,
|
||||
/// Switched to OpenGL because the previous launch stopped as its window opened: the message
|
||||
/// to show.
|
||||
pub notice: Option<String>,
|
||||
marker: Option<PathBuf>,
|
||||
/// Holds the marker's lock until the launch settles (or the process ends).
|
||||
/// Holds the separate guard file's lock until the launch settles (or the process ends).
|
||||
lock: Option<File>,
|
||||
/// When the window drew its first frame, until the launch settles.
|
||||
first_frame: Option<Instant>,
|
||||
@@ -48,14 +111,22 @@ impl Launch {
|
||||
/// launch stopped as its window opened (where OpenGL exists: not macOS), and leave this
|
||||
/// launch's marker. `env_override`: `WGPU_BACKEND` is set.
|
||||
pub fn begin(dir: Option<&Path>, env_override: bool) -> Launch {
|
||||
let Some(dir) = dir.filter(|_| !env_override) else { return Launch::default() };
|
||||
if env_override {
|
||||
return Launch { source: BackendSource::EnvironmentOverride, ..Launch::default() };
|
||||
}
|
||||
let Some(dir) = dir else { return Launch::default() };
|
||||
let prefs_path = dir.join(PREFS_FILE);
|
||||
let mut prefs = std::fs::read_to_string(&prefs_path).map(|t| Prefs::from_json(&t)).unwrap_or_default();
|
||||
let marker = dir.join(MARKER);
|
||||
// Locked by another launch that is still opening its window: not a crash.
|
||||
let held = File::open(&marker).is_ok_and(|f| matches!(f.try_lock(), Err(std::fs::TryLockError::WouldBlock)));
|
||||
let Some(lock) = acquire_guard(dir) else {
|
||||
let backends = (prefs.startup.window_graphics == "gl").then_some(Backends::GL);
|
||||
let source = if backends.is_some() { BackendSource::SavedPreference } else { BackendSource::Default };
|
||||
return Launch { backends, source, ..Launch::default() };
|
||||
};
|
||||
// Read again while owning the guard: another launch may have just changed preferences.
|
||||
prefs = std::fs::read_to_string(&prefs_path).map(|t| Prefs::from_json(&t)).unwrap_or_default();
|
||||
let mut notice = None;
|
||||
if marker.exists() && !held && prefs.startup.window_graphics == "auto" && cfg!(not(target_os = "macos")) {
|
||||
if marker.exists() && prefs.startup.window_graphics == "auto" && cfg!(not(target_os = "macos")) {
|
||||
prefs.startup.window_graphics = "gl".into();
|
||||
match std::fs::create_dir_all(dir).and_then(|()| std::fs::write(&prefs_path, prefs.to_json())) {
|
||||
Ok(()) => log::warn!("the last launch stopped as its window opened: switching Window Graphics to OpenGL"),
|
||||
@@ -69,15 +140,21 @@ impl Launch {
|
||||
);
|
||||
}
|
||||
let backends = (prefs.startup.window_graphics == "gl").then_some(Backends::GL);
|
||||
let (marker, lock) = match std::fs::create_dir_all(dir).and_then(|()| File::create(&marker)) {
|
||||
// Where locks aren't available the guard works as before.
|
||||
Ok(f) => (Some(marker), f.try_lock().is_ok().then_some(f)),
|
||||
let source = if notice.is_some() {
|
||||
BackendSource::InterruptedStartup
|
||||
} else if backends.is_some() {
|
||||
BackendSource::SavedPreference
|
||||
} else {
|
||||
BackendSource::Default
|
||||
};
|
||||
let marker = match File::create(&marker) {
|
||||
Ok(_) => Some(marker),
|
||||
Err(e) => {
|
||||
log::warn!("launch marker: {e}");
|
||||
(None, None)
|
||||
None
|
||||
}
|
||||
};
|
||||
Launch { backends, notice, marker, lock, first_frame: None }
|
||||
Launch { backends, source, notice, marker, lock: Some(lock), first_frame: None }
|
||||
}
|
||||
|
||||
/// The window drew a frame. Until the launch has settled, returns how long that still takes
|
||||
@@ -104,18 +181,19 @@ impl Launch {
|
||||
|
||||
/// The launch made it: release and remove its marker.
|
||||
fn settled(&mut self) {
|
||||
self.lock = None;
|
||||
if let Some(m) = self.marker.take()
|
||||
&& let Err(e) = std::fs::remove_file(&m)
|
||||
{
|
||||
log::warn!("launch marker: {e}");
|
||||
}
|
||||
self.lock = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// The window couldn't open with OpenGL (an error, not a crash): back to Automatic, and no marker.
|
||||
pub fn opengl_failed(dir: Option<&Path>) {
|
||||
let Some(dir) = dir else { return };
|
||||
let Some(_lock) = acquire_guard(dir) else { return };
|
||||
let prefs_path = dir.join(PREFS_FILE);
|
||||
let mut prefs = std::fs::read_to_string(&prefs_path).map(|t| Prefs::from_json(&t)).unwrap_or_default();
|
||||
prefs.startup.window_graphics = "auto".into();
|
||||
@@ -142,6 +220,7 @@ mod tests {
|
||||
// may still crash as the window is shown); frames for `SETTLE` do.
|
||||
let mut l = Launch::begin(Some(&dir), false);
|
||||
assert_eq!((l.backends, l.notice.is_some()), (None, false));
|
||||
assert_eq!(l.source, BackendSource::Default);
|
||||
assert!(dir.join(MARKER).exists());
|
||||
let t0 = Instant::now();
|
||||
assert_eq!(l.frame_drawn_at(t0), Some(SETTLE));
|
||||
@@ -159,14 +238,18 @@ mod tests {
|
||||
} else {
|
||||
assert_eq!(l.backends, Some(Backends::GL));
|
||||
assert!(l.notice.is_some());
|
||||
assert_eq!(l.source, BackendSource::InterruptedStartup);
|
||||
assert_eq!(window_graphics(&dir), "gl", "saved in Settings");
|
||||
l.exited();
|
||||
let l = Launch::begin(Some(&dir), false);
|
||||
assert_eq!((l.backends, l.notice.is_some()), (Some(Backends::GL), false), "it stays, without the notice");
|
||||
assert_eq!(l.source, BackendSource::SavedPreference);
|
||||
}
|
||||
// `WGPU_BACKEND` wins, and leaves no marker.
|
||||
let _ = std::fs::remove_file(dir.join(MARKER));
|
||||
assert_eq!(Launch::begin(Some(&dir), true).backends, None);
|
||||
let overridden = Launch::begin(Some(&dir), true);
|
||||
assert_eq!(overridden.backends, None);
|
||||
assert_eq!(overridden.source, BackendSource::EnvironmentOverride);
|
||||
assert!(!dir.join(MARKER).exists());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
@@ -217,4 +300,232 @@ mod tests {
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A fresh settings folder for one test.
|
||||
fn fresh_dir(case: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("ec-launch-guard-{case}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
/// Window Graphics saved as OpenGL.
|
||||
fn save_opengl(dir: &Path) {
|
||||
let mut prefs = Prefs::default();
|
||||
prefs.startup.window_graphics = "gl".into();
|
||||
std::fs::write(dir.join(PREFS_FILE), prefs.to_json()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_copy_reports_the_saved_backend_without_owning_the_guard() {
|
||||
let dir = fresh_dir("second-source");
|
||||
save_opengl(&dir);
|
||||
let mut first = Launch::begin(Some(&dir), false);
|
||||
let mut second = Launch::begin(Some(&dir), false);
|
||||
assert!(second.lock.is_none());
|
||||
assert_eq!((second.backends, second.source), (Some(Backends::GL), BackendSource::SavedPreference));
|
||||
second.exited();
|
||||
first.exited();
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// A second copy that quits normally while the first is still opening doesn't remove the first
|
||||
/// one's marker (#477).
|
||||
#[test]
|
||||
fn a_second_copy_quitting_leaves_the_running_launchs_marker() {
|
||||
let dir = fresh_dir("second-quits");
|
||||
let mut first = Launch::begin(Some(&dir), false);
|
||||
let mut second = Launch::begin(Some(&dir), false);
|
||||
second.exited();
|
||||
let kept = dir.join(MARKER).exists();
|
||||
first.exited();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
assert!(kept, "the second copy removed the running launch's marker");
|
||||
}
|
||||
|
||||
/// A second copy whose OpenGL window fails doesn't remove a running launch's marker.
|
||||
#[test]
|
||||
fn failed_opengl_in_a_second_copy_leaves_the_running_launchs_marker() {
|
||||
let dir = fresh_dir("second-gl-fails");
|
||||
let mut first = Launch::begin(Some(&dir), false);
|
||||
let second = Launch::begin(Some(&dir), false);
|
||||
opengl_failed(Some(&dir));
|
||||
let kept = dir.join(MARKER).exists();
|
||||
drop(second);
|
||||
first.exited();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
assert!(kept, "OpenGL cleanup removed another running launch's marker");
|
||||
}
|
||||
|
||||
/// With `WGPU_BACKEND` set, a stale marker and a saved OpenGL choice are left as they are.
|
||||
#[test]
|
||||
fn wgpu_backend_leaves_a_stale_marker_and_saved_opengl_alone() {
|
||||
let dir = fresh_dir("env-override");
|
||||
save_opengl(&dir);
|
||||
std::fs::write(dir.join(MARKER), b"stale-marker").unwrap();
|
||||
let before = std::fs::read(dir.join(PREFS_FILE)).unwrap();
|
||||
let mut l = Launch::begin(Some(&dir), true);
|
||||
assert_eq!(l.backends, None);
|
||||
assert!(l.notice.is_none());
|
||||
l.exited();
|
||||
assert!(dir.join(MARKER).exists());
|
||||
assert_eq!(std::fs::read(dir.join(PREFS_FILE)).unwrap(), before);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// After OpenGL fails to open a window, the next launch is back on Automatic, without a notice.
|
||||
#[test]
|
||||
fn failed_opengl_puts_the_next_launch_back_on_automatic() {
|
||||
let dir = fresh_dir("gl-recovers");
|
||||
save_opengl(&dir);
|
||||
let l = Launch::begin(Some(&dir), false);
|
||||
assert_eq!(l.backends, Some(Backends::GL));
|
||||
drop(l);
|
||||
opengl_failed(Some(&dir));
|
||||
assert!(!dir.join(MARKER).exists());
|
||||
assert_eq!(Prefs::from_json(&std::fs::read_to_string(dir.join(PREFS_FILE)).unwrap()).startup.window_graphics, "auto");
|
||||
let mut l = Launch::begin(Some(&dir), false);
|
||||
assert_eq!(l.backends, None);
|
||||
assert!(l.notice.is_none());
|
||||
l.exited();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// The guard file is never removed or replaced: unlinking a locked file would let the next
|
||||
/// launch lock a new one while the old lock is still held.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn the_guard_file_stays_the_same_file_across_launches() {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let dir = fresh_dir("guard-identity");
|
||||
let mut a = Launch::begin(Some(&dir), false);
|
||||
let before = std::fs::metadata(dir.join(LOCK)).unwrap();
|
||||
let t0 = Instant::now();
|
||||
assert_eq!(a.frame_drawn_at(t0), Some(SETTLE));
|
||||
assert_eq!(a.frame_drawn_at(t0 + SETTLE), None);
|
||||
assert!(!dir.join(MARKER).exists());
|
||||
let after = std::fs::metadata(dir.join(LOCK)).unwrap();
|
||||
assert_eq!((before.dev(), before.ino()), (after.dev(), after.ino()));
|
||||
let mut b = Launch::begin(Some(&dir), false);
|
||||
assert!(b.lock.is_some());
|
||||
let reused = std::fs::metadata(dir.join(LOCK)).unwrap();
|
||||
assert_eq!((before.dev(), before.ino()), (reused.dev(), reused.ino()));
|
||||
b.exited();
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// A second copy's frames and quit neither settle nor unlock the running launch.
|
||||
#[test]
|
||||
fn a_second_copys_frames_dont_settle_the_running_launch() {
|
||||
let dir = fresh_dir("second-frames");
|
||||
let mut a = Launch::begin(Some(&dir), false);
|
||||
std::fs::write(dir.join(MARKER), b"owner-marker").unwrap();
|
||||
let mut b = Launch::begin(Some(&dir), false);
|
||||
assert!(b.lock.is_none());
|
||||
assert!(b.marker.is_none());
|
||||
let t0 = Instant::now();
|
||||
assert_eq!(b.frame_drawn_at(t0), None);
|
||||
assert_eq!(b.frame_drawn_at(t0 + SETTLE), None);
|
||||
b.exited();
|
||||
assert_eq!(std::fs::read(dir.join(MARKER)).unwrap(), b"owner-marker");
|
||||
let probe = File::open(dir.join(LOCK)).unwrap();
|
||||
assert!(matches!(probe.try_lock(), Err(std::fs::TryLockError::WouldBlock)));
|
||||
a.exited();
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// Older versions lock the marker itself: while one runs, a new launch changes nothing, and
|
||||
/// once it has stopped without settling the next launch still switches to OpenGL.
|
||||
#[test]
|
||||
fn a_running_older_version_holding_the_marker_is_left_alone() {
|
||||
let dir = fresh_dir("older-version");
|
||||
std::fs::write(dir.join(MARKER), b"old-owner").unwrap();
|
||||
std::fs::write(dir.join(PREFS_FILE), Prefs::default().to_json()).unwrap();
|
||||
let old = File::open(dir.join(MARKER)).unwrap();
|
||||
old.try_lock().unwrap();
|
||||
let before = std::fs::read(dir.join(PREFS_FILE)).unwrap();
|
||||
let mut b = Launch::begin(Some(&dir), false);
|
||||
assert!(b.lock.is_none());
|
||||
assert!(b.marker.is_none());
|
||||
assert!(b.backends.is_none());
|
||||
assert!(b.notice.is_none());
|
||||
b.exited();
|
||||
opengl_failed(Some(&dir));
|
||||
assert_eq!(std::fs::read(dir.join(PREFS_FILE)).unwrap(), before);
|
||||
// Windows locks forbid reading through another handle. Inspect the contents only after
|
||||
// releasing the old owner's lock, but before recovery can truncate the marker.
|
||||
drop(old);
|
||||
assert_eq!(std::fs::read(dir.join(MARKER)).unwrap(), b"old-owner");
|
||||
let mut recovered = Launch::begin(Some(&dir), false);
|
||||
if cfg!(not(target_os = "macos")) {
|
||||
assert_eq!(recovered.backends, Some(Backends::GL));
|
||||
}
|
||||
recovered.exited();
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// A Windows sharing violation is not evidence that a marker is stale or absent.
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn an_unopenable_marker_leaves_settings_and_marker_alone() {
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
|
||||
let dir = fresh_dir("marker-unopenable");
|
||||
std::fs::write(dir.join(MARKER), b"old-owner").unwrap();
|
||||
std::fs::write(dir.join(PREFS_FILE), Prefs::default().to_json()).unwrap();
|
||||
let old = std::fs::OpenOptions::new().read(true).write(true).share_mode(0).open(dir.join(MARKER)).unwrap();
|
||||
let before = std::fs::read(dir.join(PREFS_FILE)).unwrap();
|
||||
let mut launch = Launch::begin(Some(&dir), false);
|
||||
assert!(launch.lock.is_none());
|
||||
assert!(launch.marker.is_none());
|
||||
assert!(launch.backends.is_none());
|
||||
assert!(launch.notice.is_none());
|
||||
launch.exited();
|
||||
opengl_failed(Some(&dir));
|
||||
assert_eq!(std::fs::read(dir.join(PREFS_FILE)).unwrap(), before);
|
||||
drop(old);
|
||||
assert_eq!(std::fs::read(dir.join(MARKER)).unwrap(), b"old-owner");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// A guard file that can't be opened leaves Window Graphics and the marker as they are.
|
||||
#[test]
|
||||
fn an_unusable_guard_file_leaves_settings_and_marker_alone() {
|
||||
let dir = fresh_dir("guard-unusable");
|
||||
std::fs::create_dir(dir.join(LOCK)).unwrap();
|
||||
std::fs::write(dir.join(MARKER), b"stale-marker").unwrap();
|
||||
std::fs::write(dir.join(PREFS_FILE), Prefs::default().to_json()).unwrap();
|
||||
let before = std::fs::read(dir.join(PREFS_FILE)).unwrap();
|
||||
let mut l = Launch::begin(Some(&dir), false);
|
||||
assert!(l.backends.is_none());
|
||||
assert!(l.notice.is_none());
|
||||
assert!(l.lock.is_none());
|
||||
assert!(l.marker.is_none());
|
||||
l.exited();
|
||||
opengl_failed(Some(&dir));
|
||||
assert_eq!(std::fs::read(dir.join(PREFS_FILE)).unwrap(), before);
|
||||
assert_eq!(std::fs::read(dir.join(MARKER)).unwrap(), b"stale-marker");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// OpenGL cleanup from elsewhere waits until the running launch has let go; then it resets
|
||||
/// Window Graphics to Automatic and removes the marker.
|
||||
#[test]
|
||||
fn failed_opengl_cleanup_waits_for_the_running_launch() {
|
||||
let dir = fresh_dir("gl-cleanup-waits");
|
||||
save_opengl(&dir);
|
||||
let launch = Launch::begin(Some(&dir), false);
|
||||
assert_eq!(launch.backends, Some(Backends::GL));
|
||||
assert!(launch.lock.is_some());
|
||||
let before = std::fs::read(dir.join(PREFS_FILE)).unwrap();
|
||||
opengl_failed(Some(&dir));
|
||||
assert_eq!(std::fs::read(dir.join(PREFS_FILE)).unwrap(), before);
|
||||
assert!(dir.join(MARKER).exists(), "cleanup elsewhere can't remove a running launch's marker");
|
||||
drop(launch);
|
||||
opengl_failed(Some(&dir));
|
||||
let after = Prefs::from_json(&std::fs::read_to_string(dir.join(PREFS_FILE)).unwrap()).startup.window_graphics;
|
||||
assert_eq!(after, "auto", "once the launch has let go, failed OpenGL resets Window Graphics");
|
||||
assert!(!dir.join(MARKER).exists());
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ mod appimage;
|
||||
mod apple_events;
|
||||
mod audio_out;
|
||||
mod control_server;
|
||||
mod crash_report;
|
||||
mod diagnostic_state;
|
||||
mod launch_guard;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod native_menu;
|
||||
@@ -180,6 +182,23 @@ fn start_helpers_if_opted_in(session: &mut effectcraft_engine::Session) {
|
||||
/// Builds the session, loads settings, plugins, the requested project/media and the optional control server, then
|
||||
/// reports startup failure through `startup_failed`. Returns the event loop's result.
|
||||
fn main() -> eframe::Result {
|
||||
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||
if crash_report::maybe_run(&args, |description| {
|
||||
rfd::MessageDialog::new().set_level(rfd::MessageLevel::Error).set_title("EffectCraft diagnostic report").set_description(description).show();
|
||||
}) {
|
||||
return Ok(());
|
||||
}
|
||||
let reporter = crash_report::Shutdown::default();
|
||||
let result = run_desktop(&reporter);
|
||||
// run_desktop has dropped the app and handled any startup error with its existing dialog.
|
||||
// An unwinding panic or abort never reaches this marker.
|
||||
if let Err(error) = reporter.finish() {
|
||||
log::warn!("could not mark crash reporter clean: {error}");
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn run_desktop(reporter: &crash_report::Shutdown) -> eframe::Result {
|
||||
// Windows: the update helper is a copy of this program started with `--finish-update`.
|
||||
#[cfg(windows)]
|
||||
if let Some(result) = craft_update::self_update::finish(&effectcraft_ui_egui::UPDATE_APP, &std::env::args_os().skip(1).collect::<Vec<_>>()) {
|
||||
@@ -205,20 +224,38 @@ fn main() -> eframe::Result {
|
||||
// The session log lives in the settings folder (`Logs/effectcraft.log`, the previous two runs
|
||||
// kept): a launch from the Dock or a menu has no terminal. Opened after the arguments, so
|
||||
// `--version` leaves no file behind; records logged until now are written to it first.
|
||||
let run_id = crash_report::run_id();
|
||||
if let Some(dir) = effectcraft_host::config_dir() {
|
||||
match effectcraft_engine::logging::attach_session_log(&effectcraft_engine::logging::log_dir(Some(&dir))) {
|
||||
let header = format!("{}\n", crash_report::session_marker(&run_id));
|
||||
match effectcraft_engine::logging::attach_session_log_with_header(&effectcraft_engine::logging::log_dir(Some(&dir)), &header) {
|
||||
Ok(path) => log::info!("effectcraft {}, log file {}", env!("CARGO_PKG_VERSION"), path.display()),
|
||||
Err(e) => log::warn!("no log file: {e}"),
|
||||
}
|
||||
}
|
||||
let logs = effectcraft_engine::logging::log_dir(effectcraft_host::config_dir().as_deref());
|
||||
match crash_report::start(&run_id, effectcraft_engine::logging::session_file().as_deref(), &logs.join("Crash Reports"), control_port.is_none()) {
|
||||
Ok(started) => {
|
||||
if let Err(error) = reporter.install(started) {
|
||||
log::warn!("crash reporter could not be retained: {error}");
|
||||
}
|
||||
}
|
||||
Err(error) => log::warn!("crash reporter could not start: {error}"),
|
||||
}
|
||||
// The font menus list the installed fonts: read their names while the window opens.
|
||||
effectcraft_engine::text::fonts::scan_system_in_background();
|
||||
// Wayland shows the window's icon from its desktop entry: an AppImage brings its own.
|
||||
#[cfg(target_os = "linux")]
|
||||
appimage::integrate_from_env(ICON_PNG);
|
||||
// Settings ▸ Startup & Repair ▸ Window Graphics, switched to OpenGL when the last launch
|
||||
// stopped as its window opened (a crashing graphics driver, #243).
|
||||
let mut launch = launch_guard::Launch::begin(effectcraft_host::config_dir().as_deref(), std::env::var_os("WGPU_BACKEND").is_some());
|
||||
// stopped as its window opened (the marker alone does not establish a cause).
|
||||
let backend_override = std::env::var_os("WGPU_BACKEND");
|
||||
let mut launch = launch_guard::Launch::begin(effectcraft_host::config_dir().as_deref(), backend_override.is_some());
|
||||
diagnostic_state::record(reporter, launch.source.event());
|
||||
if let Some(value) = backend_override {
|
||||
for event in diagnostic_state::backend_override_events(&value) {
|
||||
diagnostic_state::record(reporter, event);
|
||||
}
|
||||
}
|
||||
let on_gl = launch.backends == Some(eframe::wgpu::Backends::GL);
|
||||
let notice = launch.notice.take();
|
||||
let options = eframe::NativeOptions {
|
||||
@@ -245,22 +282,40 @@ fn main() -> eframe::Result {
|
||||
let apple_events = apple_events::AppleEvents::install();
|
||||
#[cfg(target_os = "macos")]
|
||||
let apple_events = &apple_events;
|
||||
let desktop_reporter = reporter.clone();
|
||||
let result = eframe::run_native(
|
||||
"EffectCraft",
|
||||
options,
|
||||
Box::new(move |cc| {
|
||||
EffectcraftApp::install_ime_reset_hooks(&cc.egui_ctx);
|
||||
match &cc.wgpu_render_state {
|
||||
Some(rs) => log::info!("graphics: {:?}", rs.adapter.get_info()),
|
||||
None => log::info!("graphics: no wgpu device"),
|
||||
Some(rs) => {
|
||||
let info = rs.adapter.get_info();
|
||||
log::info!("graphics: {info:?}");
|
||||
let event = match info.backend {
|
||||
eframe::wgpu::Backend::Noop => "actual GPU backend: noop",
|
||||
eframe::wgpu::Backend::Vulkan => "actual GPU backend: vulkan",
|
||||
eframe::wgpu::Backend::Metal => "actual GPU backend: metal",
|
||||
eframe::wgpu::Backend::Dx12 => "actual GPU backend: dx12",
|
||||
eframe::wgpu::Backend::Gl => "actual GPU backend: gl",
|
||||
eframe::wgpu::Backend::BrowserWebGpu => "actual GPU backend: webgpu",
|
||||
};
|
||||
diagnostic_state::record(&desktop_reporter, event);
|
||||
}
|
||||
None => diagnostic_state::record(&desktop_reporter, "actual GPU backend: no wgpu device"),
|
||||
}
|
||||
// This executable owns the shared device's handlers. Install them before
|
||||
// EffectCraft's compositor pipelines are built, without changing handlers from
|
||||
// inside Gpu::new. eframe has already constructed its presentation renderer here.
|
||||
let gpu_failures = effectcraft_ui_egui::gpu_failure::GpuFailureBridge::new(&cc.egui_ctx);
|
||||
let observations = diagnostic_state::GpuObservations::new(&desktop_reporter);
|
||||
let scoped_observed = observations.clone();
|
||||
gpu_failures.set_scoped_error_observer(move |error| scoped_observed.scoped(error));
|
||||
if let Some(rs) = &cc.wgpu_render_state {
|
||||
let errors_observed = observations.clone();
|
||||
let errors = gpu_failures.clone();
|
||||
rs.device.on_uncaptured_error(std::sync::Arc::new(move |error| {
|
||||
errors_observed.uncaptured(&error);
|
||||
let message = format!("uncaptured GPU error: {error}");
|
||||
if errors.report(&message, false) {
|
||||
log::error!("{message}");
|
||||
@@ -268,6 +323,7 @@ fn main() -> eframe::Result {
|
||||
}));
|
||||
let lost = gpu_failures.clone();
|
||||
rs.device.set_device_lost_callback(move |reason, message| {
|
||||
observations.device_lost(reason);
|
||||
lost.report(&format!("GPU device lost ({reason:?}): {message}"), true);
|
||||
});
|
||||
}
|
||||
@@ -398,6 +454,7 @@ fn main() -> eframe::Result {
|
||||
window: window::Tracker::new(opened, saved_window, control_port.is_none()),
|
||||
launch,
|
||||
drawn: false,
|
||||
reporter: desktop_reporter,
|
||||
}))
|
||||
}),
|
||||
);
|
||||
@@ -491,6 +548,7 @@ struct Desktop {
|
||||
launch: launch_guard::Launch,
|
||||
/// The first frame was drawn (logged once).
|
||||
drawn: bool,
|
||||
reporter: crash_report::Shutdown,
|
||||
}
|
||||
|
||||
impl eframe::App for Desktop {
|
||||
@@ -525,15 +583,20 @@ impl eframe::App for Desktop {
|
||||
}
|
||||
|
||||
fn on_exit(&mut self) {
|
||||
// On macOS the app quits through `-[NSApplication terminate:]`, and the process ends
|
||||
// before `eframe::run_native` returns (#341).
|
||||
log::info!("the window is closing");
|
||||
self.launch.exited();
|
||||
self.window.save(self.app.session.config.as_deref());
|
||||
self.app.on_exit();
|
||||
effectcraft_host::stop_helpers();
|
||||
// Scripts in Scripts/Shutdown run with the project closed.
|
||||
let _ = self.app.session.execute("file.runShutdownScripts", json!({}));
|
||||
// macOS terminates after this hook without returning from run_native (#341).
|
||||
// Other platforms keep the reporter armed until main sees complete event-loop teardown.
|
||||
let reporter = cfg!(target_os = "macos").then(|| self.reporter.clone());
|
||||
if let Err(error) = crash_report::after_teardown(reporter.as_ref(), || {
|
||||
log::info!("the window is closing");
|
||||
self.launch.exited();
|
||||
self.window.save(self.app.session.config.as_deref());
|
||||
self.app.on_exit();
|
||||
effectcraft_host::stop_helpers();
|
||||
// Scripts in Scripts/Shutdown run with the project closed.
|
||||
let _ = self.app.session.execute("file.runShutdownScripts", json!({}));
|
||||
}) {
|
||||
log::warn!("could not mark crash reporter clean after teardown: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) {
|
||||
|
||||
@@ -15,6 +15,7 @@ effectcraft-color = { workspace = true }
|
||||
effectcraft-keyframe = { workspace = true }
|
||||
effectcraft-project = { workspace = true }
|
||||
effectcraft-effects = { workspace = true }
|
||||
log = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
|
||||
+14
-2
@@ -21,7 +21,9 @@ tree; pad bytes, odd bodies and the bytes after the container, an XMP packet, ar
|
||||
|
||||
The XML form of a project (`.aepx`) is read into the same tree by `read_aepx` (a small bounded
|
||||
XML tokenizer, no dependency); `parse_any` picks the reader by content, so the typed view and the
|
||||
importer take either form. The mapping is in `docs/aep-format.md`, section 1.
|
||||
importer take either form. The mapping is in `docs/aep-format.md`, section 1. The importer, which
|
||||
only reads, does not build the owned tree: it reads either form through the flat index
|
||||
`TreeIndex`, an `.aep` in place and an `.aepx` decoded into one buffer first.
|
||||
|
||||
Bodies that look like lists but are not chunk sequences (for example `LIST btdk`, raw text) stay
|
||||
opaque rather than failing the parse. Input is untrusted: sizes are checked against the remaining
|
||||
@@ -69,12 +71,22 @@ tests reach them only through `tests/it/common/mod.rs`, which hands a test its c
|
||||
of its own cut from the combined file; a test whose fixture is missing (or with the variable not
|
||||
set) prints `SKIPPED: fixture <name> missing` and passes.
|
||||
|
||||
`tests/fixtures/synthetic.aep` (115 KB) is the one project in the repository: made in After Effects 2026
|
||||
`tests/fixtures/synthetic.aep` (115 KB) is one of the two projects in the repository: made in After Effects 2026
|
||||
with the working space set to None (one composition, an image sequence of three 8x8 PNGs, a
|
||||
solid, a folder, a Levels and a Glow effect with expressions). Every After Effects project embeds
|
||||
the working space's ICC profile (HP sRGB IEC61966-2.1 for the default) in a JSON settings chunk;
|
||||
the one `Utf8` chunk of this file that held a profile was replaced by `{}`, and nothing else was
|
||||
changed. The tests in `tests/it/import/synthetic.rs` damage copies of it and need no other file.
|
||||
`tests/fixtures/text-synthetic.aep` is the other: made in After Effects 2026 the same way (working
|
||||
space None, nothing changed after the save), one composition with two text layers that hold a
|
||||
text animator's Stroke Opacity (static and keyed) and Source Text expressions (enabled and
|
||||
disabled); `tests/it/import/text_synthetic.rs` reads it (#3170).
|
||||
|
||||
`tests/fixtures/ai-mask-3099.aep` (131 KB, #3099) is the second: four hand-written one-page PDFs
|
||||
named `.ai` with distinct page boxes, placed in a composition, one of them with two masks under a
|
||||
Null parented to a Null (generated by `tests/fixtures/tools/ai-mask-3099.py` and
|
||||
`ai-mask-3099.jsx`, scrubbed with `scrub.py` and `stubicc`). `tests/it/import/ai_mask.rs` checks
|
||||
the import against After Effects' read-back, and the host's `vector_import` tests render it.
|
||||
|
||||
## Tools
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ mod effects;
|
||||
mod error;
|
||||
mod footage;
|
||||
mod header;
|
||||
pub mod index;
|
||||
mod keys;
|
||||
mod masks;
|
||||
mod matte;
|
||||
@@ -36,6 +37,7 @@ mod values;
|
||||
mod version;
|
||||
mod write;
|
||||
|
||||
pub(crate) use aepx::{AepxDrafts, index_aepx};
|
||||
pub use aepx::{is_aepx, parse_any, read_aepx, read_aepx_with_limits};
|
||||
pub use arbitrary::{
|
||||
CURVE_IDENTITY, CryptomatteData, CurvesData, ExtractorChannels, HueSaturationData, LevelsData, MeshData, curve_lut, identifier_channel_type,
|
||||
@@ -44,8 +46,9 @@ pub use camera::{CameraPosition, DEFAULT_CAMERA_ZOOM};
|
||||
pub use chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS, Walk};
|
||||
pub use effects::{DefinitionSource, Effect, EffectDefinitions, EffectParam, LayerRef, ParamKind, ParamValue};
|
||||
pub use error::AepError;
|
||||
pub use footage::{Footage, SequenceInfo};
|
||||
pub use footage::{Footage, PsdLayer, SequenceInfo};
|
||||
pub use header::{BlendMode, CompHeader, LayerHeader, LayerType, LightType, Quality, Rational, Renderer};
|
||||
pub use index::{Node, NodeWalk, Nodes, TreeIndex};
|
||||
pub use keys::{ExpressionFlags, Interpolation, KeyEase, KeyframeKind, SpatialKey};
|
||||
pub use masks::{Mask, MaskAtom, MaskMode, PathVertex, ShapePath};
|
||||
pub use matte::{MatteMode, TrackMatte};
|
||||
|
||||
+664
-100
@@ -12,13 +12,23 @@
|
||||
//! instructions. A document type declaration is refused (no entity expansion). It runs without
|
||||
//! recursion; the nesting depth and the element count are bounded by [`Limits`], and everything
|
||||
//! it allocates is bounded by the size of the input.
|
||||
//!
|
||||
//! There are two readers. [`read_aepx`] builds the owned tree element by element
|
||||
//! (`aepx/tree.rs`). The importer, which only reads, uses `index_aepx`: it decodes every body
|
||||
//! (hex, text, the alias JSON, the numbers) into one buffer and records the chunks as entries of
|
||||
//! the flat index ([`Draft`]s, in depth-first order, bodies as ranges of the buffer), which
|
||||
//! [`crate::container::TreeIndex::from_drafts`] turns into an index that borrows the buffer.
|
||||
//! The tests hold both to the same tree and the same errors.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::container::chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS};
|
||||
use crate::container::chunk::{AepFile, LIST, NESTED_IDS};
|
||||
use crate::container::error::AepError;
|
||||
use crate::container::index::{Draft, Kind as EntryKind};
|
||||
use crate::container::read::{Limits, parse};
|
||||
|
||||
mod tree;
|
||||
|
||||
/// The root element of an `.aepx`.
|
||||
const ROOT: &[u8] = b"AfterEffectsProject";
|
||||
/// The element that holds the XMP packet (the trailer of an `.aep`).
|
||||
@@ -68,17 +78,59 @@ pub fn read_aepx(data: &[u8]) -> Result<AepFile<'static>, AepError> {
|
||||
/// # Errors
|
||||
/// See [`read_aepx`].
|
||||
pub fn read_aepx_with_limits(data: &[u8], limits: Limits) -> Result<AepFile<'static>, AepError> {
|
||||
tree::read(data, limits)
|
||||
}
|
||||
|
||||
/// An `.aepx` read for the flat index: every body decoded into one buffer, and the chunks as
|
||||
/// [`Draft`]s in depth-first order with their bodies as ranges of that buffer.
|
||||
/// [`crate::container::TreeIndex::from_drafts`] makes the index, which borrows the buffer.
|
||||
pub(crate) struct AepxDrafts {
|
||||
/// The decoded bodies (hex, text, alias JSON, numbers) and the XMP packet.
|
||||
pub(crate) buffer: Vec<u8>,
|
||||
pub(crate) nodes: Vec<Draft>,
|
||||
/// The XMP packet: a range of `buffer` (empty without one).
|
||||
pub(crate) trailer: (usize, usize),
|
||||
}
|
||||
|
||||
/// Reads an `.aepx` into [`AepxDrafts`]: the tree [`read_aepx_with_limits`] gives, with the same
|
||||
/// errors, without one allocation per chunk.
|
||||
///
|
||||
/// # Errors
|
||||
/// See [`read_aepx_with_limits`]. When memory runs out, two errors come up in more cases than
|
||||
/// there: [`AepError::TooLarge`] when the chunk list cannot grow (the owned-tree reader would
|
||||
/// abort), and [`AepError::Xml`] "bdata is too large to hold in memory" also when the shared body
|
||||
/// buffer cannot grow (the owned-tree reader reserves each value on its own).
|
||||
pub(crate) fn index_aepx(data: &[u8], limits: Limits) -> Result<AepxDrafts, AepError> {
|
||||
let text = match std::str::from_utf8(data) {
|
||||
Ok(t) => t.as_bytes(),
|
||||
Err(e) => return Err(xml(e.valid_up_to(), "the file is not valid UTF-8")),
|
||||
};
|
||||
Reader { data: text, pos: 0, limits, count: 0, stack: Vec::new(), top: None, trailer: None }.run()
|
||||
// Every counted element takes at least 3 bytes (`<a>` in a document cut short), so there are
|
||||
// never more chunks than this.
|
||||
let bound = (text.len() / 3).min(limits.max_chunks);
|
||||
let mut nodes = Vec::new();
|
||||
let _ = nodes.try_reserve_exact(bound.min(INITIAL_SLOTS));
|
||||
// Hex is most of an `.aepx` and decodes to half its length: one buffer of that size usually
|
||||
// holds everything. A failed reservation is not an error here; the buffer grows as it goes.
|
||||
let mut buffer = Vec::new();
|
||||
let _ = buffer.try_reserve_exact(text.len() / 2);
|
||||
let reader = Reader { data: text, pos: 0, limits, count: 0, stack: Vec::new(), root_closed: false, trailer: None, buffer, nodes, bound, attrs: Vec::new() };
|
||||
reader.run()
|
||||
}
|
||||
|
||||
/// The slots the chunk list starts with; it doubles from there (as the array of
|
||||
/// [`crate::container::TreeIndex`] does).
|
||||
const INITIAL_SLOTS: usize = 1024;
|
||||
|
||||
fn xml(offset: usize, what: &'static str) -> AepError {
|
||||
AepError::Xml { offset, what }
|
||||
}
|
||||
|
||||
/// The pad byte of a body of `len` bytes, as [`crate::container::Chunk::data`] sets it.
|
||||
fn pad_of(len: usize) -> Option<u8> {
|
||||
if len % 2 == 1 { Some(0) } else { None }
|
||||
}
|
||||
|
||||
/// What an open element becomes when it closes.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Kind {
|
||||
@@ -102,13 +154,14 @@ struct Frame {
|
||||
at: usize,
|
||||
/// The name as written, to match the end tag.
|
||||
name: (usize, usize),
|
||||
/// The decoded `bdata` attribute.
|
||||
bdata: Option<Vec<u8>>,
|
||||
/// The chunk's entry in the list (for `Chunk`, `Utf8` and `Alias`).
|
||||
entry: Option<usize>,
|
||||
/// The buffer length when the element opened: its body starts here.
|
||||
mark: usize,
|
||||
/// The end of the decoded `bdata` attribute in the buffer.
|
||||
bdata_end: Option<usize>,
|
||||
/// The attributes of a `fileReference`, in document order.
|
||||
attrs: Vec<(String, String)>,
|
||||
/// Collected text (only for `string` and the XMP packet).
|
||||
text: Vec<u8>,
|
||||
children: Vec<Chunk<'static>>,
|
||||
}
|
||||
|
||||
struct Reader<'d> {
|
||||
@@ -117,13 +170,19 @@ struct Reader<'d> {
|
||||
limits: Limits,
|
||||
count: usize,
|
||||
stack: Vec<Frame>,
|
||||
/// The top-level chunks once the root element has closed.
|
||||
top: Option<Vec<Chunk<'static>>>,
|
||||
trailer: Option<Vec<u8>>,
|
||||
/// True once the root element has closed.
|
||||
root_closed: bool,
|
||||
trailer: Option<(usize, usize)>,
|
||||
buffer: Vec<u8>,
|
||||
nodes: Vec<Draft>,
|
||||
/// The most chunks the input can hold under the limits: `nodes` never reserves past it.
|
||||
bound: usize,
|
||||
/// The attributes of the current start tag; kept to reuse its allocation.
|
||||
attrs: Vec<((usize, usize), Cow<'d, [u8]>)>,
|
||||
}
|
||||
|
||||
impl Reader<'_> {
|
||||
fn run(mut self) -> Result<AepFile<'static>, AepError> {
|
||||
impl<'d> Reader<'d> {
|
||||
fn run(mut self) -> Result<AepxDrafts, AepError> {
|
||||
if self.data.starts_with(&[0xef, 0xbb, 0xbf]) {
|
||||
self.pos = 3;
|
||||
}
|
||||
@@ -137,11 +196,13 @@ impl Reader<'_> {
|
||||
if let Some(open) = self.stack.last() {
|
||||
return Err(xml(open.at, "an element is not closed before the end of the file"));
|
||||
}
|
||||
let chunks = self.top.ok_or_else(|| xml(self.data.len(), "no AfterEffectsProject root element"))?;
|
||||
Ok(AepFile { chunks, trailer: Cow::Owned(self.trailer.unwrap_or_default()) })
|
||||
if !self.root_closed {
|
||||
return Err(xml(self.data.len(), "no AfterEffectsProject root element"));
|
||||
}
|
||||
Ok(AepxDrafts { buffer: self.buffer, nodes: self.nodes, trailer: self.trailer.unwrap_or((0, 0)) })
|
||||
}
|
||||
|
||||
fn rest(&self) -> &[u8] {
|
||||
fn rest(&self) -> &'d [u8] {
|
||||
self.data.get(self.pos..).unwrap_or(&[])
|
||||
}
|
||||
|
||||
@@ -181,14 +242,13 @@ impl Reader<'_> {
|
||||
self.pos = start;
|
||||
let end = self.skip_past(b"]]>", "a CDATA section is not closed")?;
|
||||
let content = self.data.get(start..end).unwrap_or(&[]);
|
||||
let at = start;
|
||||
match self.stack.last_mut() {
|
||||
match self.stack.last() {
|
||||
Some(frame) => {
|
||||
if matches!(frame.kind, Kind::Utf8 | Kind::Xmp) {
|
||||
frame.text.extend_from_slice(content);
|
||||
self.buffer.extend_from_slice(content);
|
||||
}
|
||||
}
|
||||
None => return Err(xml(at, "CDATA outside the root element")),
|
||||
None => return Err(xml(start, "CDATA outside the root element")),
|
||||
}
|
||||
} else if rest.starts_with(b"<!") {
|
||||
return Err(xml(self.pos, "document type declarations are not supported"));
|
||||
@@ -219,25 +279,22 @@ impl Reader<'_> {
|
||||
self.pos = self.pos.saturating_add(n);
|
||||
}
|
||||
|
||||
fn slice(&self, (a, b): (usize, usize)) -> &[u8] {
|
||||
fn slice(&self, (a, b): (usize, usize)) -> &'d [u8] {
|
||||
self.data.get(a..b).unwrap_or(&[])
|
||||
}
|
||||
|
||||
fn start_tag(&mut self) -> Result<(), AepError> {
|
||||
let at = self.pos;
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
let name = self.name()?;
|
||||
let mut attrs: Vec<((usize, usize), Vec<u8>)> = Vec::new();
|
||||
let self_closing = loop {
|
||||
/// Reads the attributes of a start tag into `attrs`; true when the tag closes itself.
|
||||
fn attributes(&mut self, at: usize, attrs: &mut Vec<((usize, usize), Cow<'d, [u8]>)>) -> Result<bool, AepError> {
|
||||
loop {
|
||||
self.skip_ws();
|
||||
let rest = self.rest();
|
||||
if rest.starts_with(b"/>") {
|
||||
self.pos = self.pos.saturating_add(2);
|
||||
break true;
|
||||
return Ok(true);
|
||||
}
|
||||
if rest.starts_with(b">") {
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
break false;
|
||||
return Ok(false);
|
||||
}
|
||||
if rest.is_empty() {
|
||||
return Err(xml(at, "a start tag is not closed"));
|
||||
@@ -259,11 +316,27 @@ impl Reader<'_> {
|
||||
if raw.contains(&b'<') {
|
||||
return Err(xml(vstart, "`<` inside an attribute value"));
|
||||
}
|
||||
let mut value = Vec::new();
|
||||
decode_entities(raw, vstart, &mut value)?;
|
||||
// A value without `&` is its own decoding (most of them, every `bdata` After Effects
|
||||
// writes): borrow it instead of copying it.
|
||||
let value = if raw.contains(&b'&') {
|
||||
let mut value = Vec::new();
|
||||
decode_entities(raw, vstart, &mut value)?;
|
||||
Cow::Owned(value)
|
||||
} else {
|
||||
Cow::Borrowed(raw)
|
||||
};
|
||||
self.pos = vend.saturating_add(1);
|
||||
attrs.push((key, value));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn start_tag(&mut self) -> Result<(), AepError> {
|
||||
let at = self.pos;
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
let name = self.name()?;
|
||||
let mut attrs = std::mem::take(&mut self.attrs);
|
||||
attrs.clear();
|
||||
let self_closing = self.attributes(at, &mut attrs)?;
|
||||
let kind = self.kind_of(name, at)?;
|
||||
if kind != Kind::Root {
|
||||
self.count = self.count.saturating_add(1);
|
||||
@@ -275,14 +348,25 @@ impl Reader<'_> {
|
||||
return Err(AepError::TooDeep);
|
||||
}
|
||||
}
|
||||
let mut frame = Frame { kind, at, name, bdata: None, attrs: Vec::new(), text: Vec::new(), children: Vec::new() };
|
||||
if matches!(kind, Kind::Chunk(_)) {
|
||||
if let Some((key, value)) = attrs.iter().find(|(k, _)| self.slice(*k) == b"bdata") {
|
||||
frame.bdata = Some(decode_hex(value, key.1)?);
|
||||
let mark = self.buffer.len();
|
||||
let mut frame = Frame { kind, at, name, entry: None, mark, bdata_end: None, attrs: Vec::new() };
|
||||
match kind {
|
||||
Kind::Chunk(id) => {
|
||||
if let Some((key, value)) = attrs.iter().find(|(k, _)| self.slice(*k) == b"bdata") {
|
||||
decode_hex_into(value, key.1, MAX_BDATA, &mut self.buffer)?;
|
||||
frame.bdata_end = Some(self.buffer.len());
|
||||
}
|
||||
frame.entry = Some(self.open_entry(id)?);
|
||||
}
|
||||
} else if kind == Kind::Alias {
|
||||
frame.attrs = attrs.iter().map(|(k, v)| (String::from_utf8_lossy(self.slice(*k)).into_owned(), String::from_utf8_lossy(v).into_owned())).collect();
|
||||
Kind::Utf8 => frame.entry = Some(self.open_entry(*b"Utf8")?),
|
||||
Kind::Alias => {
|
||||
frame.attrs =
|
||||
attrs.iter().map(|(k, v)| (String::from_utf8_lossy(self.slice(*k)).into_owned(), String::from_utf8_lossy(v).into_owned())).collect();
|
||||
frame.entry = Some(self.open_entry(*b"alas")?);
|
||||
}
|
||||
Kind::Root | Kind::Xmp | Kind::Skip => {}
|
||||
}
|
||||
self.attrs = attrs;
|
||||
self.stack.push(frame);
|
||||
if self_closing {
|
||||
self.close()?;
|
||||
@@ -290,12 +374,38 @@ impl Reader<'_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Appends the entry of a chunk whose element just opened; its body is filled in when it
|
||||
/// closes. The list grows by its length (at least 16) but never past [`Self::bound`]; an
|
||||
/// allocation the target cannot make is an error, not an abort.
|
||||
fn open_entry(&mut self, id: [u8; 4]) -> Result<usize, AepError> {
|
||||
let at = self.nodes.len();
|
||||
// This entry and the one after it must have `u32` indices.
|
||||
u32::try_from(at.checked_add(1).ok_or(AepError::TooManyChunks)?).map_err(|_| AepError::TooManyChunks)?;
|
||||
if at == self.nodes.capacity() {
|
||||
// Past the bound (which only a wrong guess could reach) it keeps doubling.
|
||||
let room = self.bound.saturating_sub(at);
|
||||
let more = if room == 0 { at.max(16) } else { at.max(16).min(room) };
|
||||
self.nodes.try_reserve_exact(more).map_err(|_| AepError::TooLarge)?;
|
||||
}
|
||||
self.nodes.push(Draft::placeholder(id));
|
||||
Ok(at)
|
||||
}
|
||||
|
||||
/// Fills in the entry at `at` once its element has closed; its subtree is what follows it.
|
||||
fn finish(&mut self, at: usize, id: [u8; 4], kind: EntryKind, list_type: [u8; 4], body: (usize, usize), pad: Option<u8>) -> Result<(), AepError> {
|
||||
let end = u32::try_from(self.nodes.len()).map_err(|_| AepError::TooManyChunks)?;
|
||||
if let Some(d) = self.nodes.get_mut(at) {
|
||||
*d = Draft { start: body.0, len: body.1.saturating_sub(body.0), id, list_type, end, kind, pad };
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Classifies an element by its name and where it is.
|
||||
fn kind_of(&self, name: (usize, usize), at: usize) -> Result<Kind, AepError> {
|
||||
let n = self.slice(name);
|
||||
let parent = match self.stack.last() {
|
||||
None => {
|
||||
if self.top.is_some() {
|
||||
if self.root_closed {
|
||||
return Err(xml(at, "a second root element"));
|
||||
}
|
||||
if n != ROOT {
|
||||
@@ -339,39 +449,102 @@ impl Reader<'_> {
|
||||
self.close()
|
||||
}
|
||||
|
||||
/// Closes the innermost element and hands its chunk to the parent.
|
||||
/// Closes the innermost element and fills in its chunk's entry.
|
||||
fn close(&mut self) -> Result<(), AepError> {
|
||||
let frame = self.stack.pop().ok_or(xml(self.pos, "an end tag without a start tag"))?;
|
||||
let chunk = match frame.kind {
|
||||
Kind::Root => {
|
||||
self.top = Some(frame.children);
|
||||
return Ok(());
|
||||
}
|
||||
Kind::Skip => return Ok(()),
|
||||
match frame.kind {
|
||||
Kind::Root => self.root_closed = true,
|
||||
Kind::Skip => {}
|
||||
Kind::Xmp => {
|
||||
// Only the first packet is kept; a later one is dropped from the buffer (its
|
||||
// children are skipped, so nothing else was written after it opened).
|
||||
if self.trailer.is_none() {
|
||||
self.trailer = Some(frame.text);
|
||||
self.trailer = Some((frame.mark, self.buffer.len()));
|
||||
} else {
|
||||
self.buffer.truncate(frame.mark);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
Kind::Utf8 => Chunk::data(*b"Utf8", frame.text),
|
||||
Kind::Alias => Chunk::data(*b"alas", alias_json(&frame.attrs).into_bytes()),
|
||||
Kind::Chunk(id) => chunk_of(id, frame)?,
|
||||
};
|
||||
if let Some(parent) = self.stack.last_mut() {
|
||||
parent.children.push(chunk);
|
||||
Kind::Utf8 => {
|
||||
let at = frame.entry.ok_or(xml(frame.at, "an element lost its chunk"))?;
|
||||
let end = self.buffer.len();
|
||||
self.finish(at, *b"Utf8", EntryKind::Data, [0; 4], (frame.mark, end), pad_of(end.saturating_sub(frame.mark)))?;
|
||||
}
|
||||
Kind::Alias => {
|
||||
let at = frame.entry.ok_or(xml(frame.at, "an element lost its chunk"))?;
|
||||
self.buffer.extend_from_slice(alias_json(&frame.attrs).as_bytes());
|
||||
let end = self.buffer.len();
|
||||
self.finish(at, *b"alas", EntryKind::Data, [0; 4], (frame.mark, end), pad_of(end.saturating_sub(frame.mark)))?;
|
||||
}
|
||||
Kind::Chunk(id) => self.close_chunk(id, &frame)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The chunk of a closed element named by a chunk id (what the owned reader's `chunk_of`
|
||||
/// built): `bdata` wins over children, `numS` / `ppSn` hold their number, a nested id holds its
|
||||
/// children (or nothing), any other name is a `LIST` of that type.
|
||||
fn close_chunk(&mut self, id: [u8; 4], frame: &Frame) -> Result<(), AepError> {
|
||||
let at = frame.entry.ok_or(xml(frame.at, "an element lost its chunk"))?;
|
||||
let after = at.checked_add(1).ok_or(AepError::TooManyChunks)?;
|
||||
if let Some(bdata_end) = frame.bdata_end {
|
||||
// The children were read (and counted, and checked) but are not part of the chunk.
|
||||
self.nodes.truncate(after);
|
||||
self.buffer.truncate(bdata_end);
|
||||
let body = (frame.mark, bdata_end);
|
||||
let pad = pad_of(bdata_end.saturating_sub(frame.mark));
|
||||
if OPAQUE_LIST_TYPES.contains(&id) {
|
||||
return self.finish(at, LIST, EntryKind::OpaqueList, id, body, pad);
|
||||
}
|
||||
return self.finish(at, id, EntryKind::Data, [0; 4], body, pad);
|
||||
}
|
||||
// Numbers written as text: `<numS><string>0</string></numS>` and `<ppSn><string>150.000000000</string></ppSn>`.
|
||||
if &id == b"numS" || &id == b"ppSn" {
|
||||
let missing = || xml(frame.at, "a numS or ppSn element without its number");
|
||||
// Exactly one child chunk, a `Utf8`: the entry after this one, whose subtree runs to the end.
|
||||
let only = self.nodes.get(after).copied().filter(|c| usize::try_from(c.end).ok() == Some(self.nodes.len())).ok_or_else(missing)?;
|
||||
if only.id != *b"Utf8" {
|
||||
return Err(missing());
|
||||
}
|
||||
let text = match only.kind {
|
||||
EntryKind::Data | EntryKind::OpaqueList => only.start.checked_add(only.len).and_then(|end| self.buffer.get(only.start..end)).unwrap_or(&[]),
|
||||
EntryKind::List | EntryKind::Nested => &[],
|
||||
};
|
||||
let text = std::str::from_utf8(text).map_err(|_| xml(frame.at, "a number is not text"))?.trim();
|
||||
let body: [u8; 8];
|
||||
let bytes: &[u8] = if &id == b"numS" {
|
||||
// Only `0` is sampled, so whether the field is signed is open: accept both readings of 4 bytes.
|
||||
let n = text.parse::<i64>().ok().filter(|n| (i64::from(i32::MIN)..=i64::from(u32::MAX)).contains(n));
|
||||
let n = n.ok_or(xml(frame.at, "numS is not a 32-bit integer"))?;
|
||||
body = u64::from(n as u32).to_be_bytes();
|
||||
body.get(4..).unwrap_or(&[])
|
||||
} else {
|
||||
body = text.parse::<f64>().map_err(|_| xml(frame.at, "ppSn is not a number"))?.to_be_bytes();
|
||||
&body
|
||||
};
|
||||
self.nodes.truncate(after);
|
||||
self.buffer.truncate(frame.mark);
|
||||
self.buffer.extend_from_slice(bytes);
|
||||
let end = self.buffer.len();
|
||||
return self.finish(at, id, EntryKind::Data, [0; 4], (frame.mark, end), pad_of(bytes.len()));
|
||||
}
|
||||
let empty = (frame.mark, frame.mark);
|
||||
if NESTED_IDS.contains(&id) {
|
||||
if self.nodes.len() == after {
|
||||
return self.finish(at, id, EntryKind::Data, [0; 4], empty, None);
|
||||
}
|
||||
return self.finish(at, id, EntryKind::Nested, [0; 4], empty, None);
|
||||
}
|
||||
self.finish(at, LIST, EntryKind::List, id, empty, None)
|
||||
}
|
||||
|
||||
fn text(&mut self) -> Result<(), AepError> {
|
||||
let start = self.pos;
|
||||
let len = self.rest().iter().position(|b| *b == b'<').unwrap_or(self.rest().len());
|
||||
let end = start.saturating_add(len);
|
||||
self.pos = end;
|
||||
let raw = self.data.get(start..end).unwrap_or(&[]);
|
||||
match self.stack.last_mut() {
|
||||
Some(frame) if matches!(frame.kind, Kind::Utf8 | Kind::Xmp) => decode_entities(raw, start, &mut frame.text),
|
||||
match self.stack.last() {
|
||||
Some(frame) if matches!(frame.kind, Kind::Utf8 | Kind::Xmp) => decode_entities(raw, start, &mut self.buffer),
|
||||
Some(_) => Ok(()),
|
||||
None if raw.iter().all(u8::is_ascii_whitespace) => Ok(()),
|
||||
None => Err(xml(start, "text outside the root element")),
|
||||
@@ -392,41 +565,6 @@ fn chunk_id(name: &[u8]) -> Option<[u8; 4]> {
|
||||
Some(id)
|
||||
}
|
||||
|
||||
/// The chunk of a closed element named by a chunk id.
|
||||
fn chunk_of(id: [u8; 4], frame: Frame) -> Result<Chunk<'static>, AepError> {
|
||||
if let Some(bytes) = frame.bdata {
|
||||
if OPAQUE_LIST_TYPES.contains(&id) {
|
||||
let pad = if bytes.len() % 2 == 1 { Some(0) } else { None };
|
||||
return Ok(Chunk { id: LIST, body: Body::OpaqueList { list_type: id, data: Cow::Owned(bytes) }, pad });
|
||||
}
|
||||
return Ok(Chunk::data(id, bytes));
|
||||
}
|
||||
// Numbers written as text: `<numS><string>0</string></numS>` and `<ppSn><string>150.000000000</string></ppSn>`.
|
||||
if &id == b"numS" || &id == b"ppSn" {
|
||||
let text = match frame.children.as_slice() {
|
||||
[only] if only.is(b"Utf8") => only.bytes().unwrap_or(&[]),
|
||||
_ => return Err(xml(frame.at, "a numS or ppSn element without its number")),
|
||||
};
|
||||
let text = std::str::from_utf8(text).map_err(|_| xml(frame.at, "a number is not text"))?.trim();
|
||||
let body = if &id == b"numS" {
|
||||
// Only `0` is sampled, so whether the field is signed is open: accept both readings of 4 bytes.
|
||||
let n = text.parse::<i64>().ok().filter(|n| (i64::from(i32::MIN)..=i64::from(u32::MAX)).contains(n));
|
||||
let n = n.ok_or(xml(frame.at, "numS is not a 32-bit integer"))?;
|
||||
(n as u32).to_be_bytes().to_vec()
|
||||
} else {
|
||||
text.parse::<f64>().map_err(|_| xml(frame.at, "ppSn is not a number"))?.to_be_bytes().to_vec()
|
||||
};
|
||||
return Ok(Chunk::data(id, body));
|
||||
}
|
||||
if NESTED_IDS.contains(&id) {
|
||||
if frame.children.is_empty() {
|
||||
return Ok(Chunk::data(id, Vec::new()));
|
||||
}
|
||||
return Ok(Chunk { id, body: Body::Chunks(frame.children), pad: None });
|
||||
}
|
||||
Ok(Chunk::list(id, frame.children))
|
||||
}
|
||||
|
||||
/// Appends `raw` with the predefined entities and character references decoded.
|
||||
fn decode_entities(raw: &[u8], offset: usize, out: &mut Vec<u8>) -> Result<(), AepError> {
|
||||
let mut i = 0;
|
||||
@@ -464,23 +602,74 @@ fn decode_entities(raw: &[u8], offset: usize, out: &mut Vec<u8>) -> Result<(), A
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Decodes a `bdata` value (hex digits, two per byte).
|
||||
/// Decodes a `bdata` value (hex digits, two per byte) into a new `Vec` of exactly its size.
|
||||
fn decode_hex(text: &[u8], offset: usize) -> Result<Vec<u8>, AepError> {
|
||||
if text.len() % 2 == 1 {
|
||||
return Err(xml(offset, "bdata has an odd number of hex digits"));
|
||||
}
|
||||
decode_hex_at_most(text, offset, MAX_BDATA)
|
||||
}
|
||||
|
||||
/// The most bytes one `bdata` may decode to: what the 32-bit size field of a chunk can hold (a
|
||||
/// larger body could not be written back as an `.aep` either).
|
||||
const MAX_BDATA: usize = u32::MAX as usize;
|
||||
|
||||
/// [`decode_hex`] with the decoded-size limit as a parameter (so tests can reach it).
|
||||
fn decode_hex_at_most(text: &[u8], offset: usize, max: usize) -> Result<Vec<u8>, AepError> {
|
||||
// Checked before anything is reserved, then sized once (collecting into `Option<Vec>` has no
|
||||
// size hint and regrows step by step), and without aborting when the memory is not there.
|
||||
let pairs = check_hex(text, offset, max)?;
|
||||
let mut out = Vec::new();
|
||||
out.try_reserve_exact(pairs).map_err(|_| xml(offset, "bdata is too large to hold in memory"))?;
|
||||
decode_checked(text, offset, &mut out)?;
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Appends the bytes of a `bdata` value (hex digits, two per byte, at most `max` bytes) to `out`.
|
||||
/// On an error `out` is unchanged.
|
||||
fn decode_hex_into(text: &[u8], offset: usize, max: usize, out: &mut Vec<u8>) -> Result<(), AepError> {
|
||||
let pairs = check_hex(text, offset, max)?;
|
||||
// Grown at most once per value (amortised over a shared buffer), and without aborting when the
|
||||
// memory is not there.
|
||||
out.try_reserve(pairs).map_err(|_| xml(offset, "bdata is too large to hold in memory"))?;
|
||||
decode_checked(text, offset, out)
|
||||
}
|
||||
|
||||
/// Appends the bytes of a `bdata` value that [`check_hex`] accepted. On an error (a digit the
|
||||
/// check let through, which it does not) `out` is unchanged.
|
||||
fn decode_checked(text: &[u8], offset: usize, out: &mut Vec<u8>) -> Result<(), AepError> {
|
||||
let digit = |b: u8| match b {
|
||||
b'0'..=b'9' => Some(b - b'0'),
|
||||
b'a'..=b'f' => Some(b - b'a' + 10),
|
||||
b'A'..=b'F' => Some(b - b'A' + 10),
|
||||
_ => None,
|
||||
};
|
||||
let (pairs, _) = text.as_chunks::<2>();
|
||||
pairs
|
||||
.iter()
|
||||
.map(|[hi, lo]| digit(*hi).zip(digit(*lo)).map(|(h, l)| (h << 4) | l))
|
||||
.collect::<Option<Vec<u8>>>()
|
||||
.ok_or(xml(offset, "bdata holds a character that is not a hex digit"))
|
||||
let mark = out.len();
|
||||
for [hi, lo] in text.as_chunks::<2>().0 {
|
||||
match (digit(*hi), digit(*lo)) {
|
||||
(Some(h), Some(l)) => out.push((h << 4) | l),
|
||||
_ => {
|
||||
out.truncate(mark);
|
||||
return Err(xml(offset, "bdata holds a character that is not a hex digit"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks a `bdata` value before anything is reserved for it: an even number of hex digits, at
|
||||
/// most `max` bytes. Returns the number of bytes it decodes to.
|
||||
fn check_hex(text: &[u8], offset: usize, max: usize) -> Result<usize, AepError> {
|
||||
if text.len() % 2 == 1 {
|
||||
return Err(xml(offset, "bdata has an odd number of hex digits"));
|
||||
}
|
||||
let pairs = text.len() / 2;
|
||||
if pairs > max {
|
||||
return Err(AepError::TooLarge);
|
||||
}
|
||||
// One cheap pass checks every digit first. Blocks without an early exit inside, so the check
|
||||
// vectorises; it stops at the first bad block.
|
||||
if !text.chunks(4096).all(|block| block.iter().fold(true, |ok, b| ok & b.is_ascii_hexdigit())) {
|
||||
return Err(xml(offset, "bdata holds a character that is not a hex digit"));
|
||||
}
|
||||
Ok(pairs)
|
||||
}
|
||||
|
||||
/// The JSON body of an `alas` chunk from the attributes of a `fileReference`, keys in document
|
||||
@@ -528,6 +717,7 @@ fn json_str(out: &mut String, s: &str) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::container::index::TreeIndex;
|
||||
|
||||
fn doc(body: &str) -> String {
|
||||
format!("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<AfterEffectsProject xmlns=\"x\">{body}</AfterEffectsProject>\n")
|
||||
@@ -628,6 +818,92 @@ mod tests {
|
||||
assert!(matches!(read_aepx(b"<AfterEffectsProject>\xff</AfterEffectsProject>"), Err(AepError::Xml { .. })));
|
||||
}
|
||||
|
||||
/// Attribute values decode entities only where they have them.
|
||||
#[test]
|
||||
fn attribute_values_decode_entities_only_where_they_have_them() {
|
||||
// An entity inside `bdata` still decodes before the hex does.
|
||||
let f = read_aepx(doc("<a bdata=\"01Ab\"/>").as_bytes()).unwrap();
|
||||
assert_eq!(f.chunks[0].bytes(), Some(&[0x01, 0xab][..]));
|
||||
// A bad entity in any attribute, even of an element that is skipped, is still an error.
|
||||
for bad in ["<a other=\" \"/>", "<Unknown x=\"&bogus;\"/>", "<a bdata=\"00\" note=\"&\"/>"] {
|
||||
assert!(matches!(read_aepx(doc(bad).as_bytes()), Err(AepError::Xml { .. })), "{bad}");
|
||||
}
|
||||
// Without `&` the value is taken as written.
|
||||
let f = read_aepx(doc("<a bdata=\"0aFf\" x=\"y\"/>").as_bytes()).unwrap();
|
||||
assert_eq!(f.chunks[0].bytes(), Some(&[0x0a, 0xff][..]));
|
||||
}
|
||||
|
||||
/// A large bdata with a bad digit is refused before it is sized.
|
||||
#[test]
|
||||
fn a_large_bdata_with_a_bad_digit_is_refused_before_it_is_sized() {
|
||||
// 10 MB of hex that is bad from the first pair (and once more at the very end).
|
||||
let mut text = b"zz".to_vec();
|
||||
text.extend(std::iter::repeat_n(*b"00", 5_000_000).flatten());
|
||||
assert_eq!(decode_hex(&text, 3), Err(xml(3, "bdata holds a character that is not a hex digit")));
|
||||
let mut late = vec![b'0'; 10_000_000];
|
||||
late.extend_from_slice(b"0g");
|
||||
assert_eq!(decode_hex(&late, 3), Err(xml(3, "bdata holds a character that is not a hex digit")));
|
||||
let x = doc(&format!("<a bdata=\"{}\"/>", std::str::from_utf8(&text).unwrap()));
|
||||
assert!(matches!(read_aepx(x.as_bytes()), Err(AepError::Xml { .. })));
|
||||
}
|
||||
|
||||
/// Bdata decodes up to the size limit and not past it.
|
||||
#[test]
|
||||
fn bdata_decodes_up_to_the_size_limit_and_not_past_it() {
|
||||
assert_eq!(decode_hex_at_most(b"00ff10", 0, 3), Ok(vec![0x00, 0xff, 0x10]));
|
||||
assert_eq!(decode_hex_at_most(b"00ff10", 0, 2), Err(AepError::TooLarge));
|
||||
assert_eq!(decode_hex_at_most(b"", 0, 0), Ok(Vec::new()));
|
||||
assert_eq!(decode_hex_at_most(b"00", 0, 0), Err(AepError::TooLarge));
|
||||
// The odd-length error still comes first.
|
||||
assert_eq!(decode_hex_at_most(b"001", 0, 0), Err(xml(0, "bdata has an odd number of hex digits")));
|
||||
// The real limit is what a chunk's 32-bit size field holds.
|
||||
assert_eq!(MAX_BDATA as u64, u64::from(u32::MAX));
|
||||
}
|
||||
|
||||
/// Decode hex matches the collecting version.
|
||||
#[test]
|
||||
fn decode_hex_matches_the_collecting_version() {
|
||||
/// The collecting decoder this one replaced, as the reference.
|
||||
fn old(text: &[u8], offset: usize) -> Result<Vec<u8>, AepError> {
|
||||
if text.len() % 2 == 1 {
|
||||
return Err(xml(offset, "bdata has an odd number of hex digits"));
|
||||
}
|
||||
let digit = |b: u8| match b {
|
||||
b'0'..=b'9' => Some(b - b'0'),
|
||||
b'a'..=b'f' => Some(b - b'a' + 10),
|
||||
b'A'..=b'F' => Some(b - b'A' + 10),
|
||||
_ => None,
|
||||
};
|
||||
let (pairs, _) = text.as_chunks::<2>();
|
||||
pairs
|
||||
.iter()
|
||||
.map(|[hi, lo]| digit(*hi).zip(digit(*lo)).map(|(h, l)| (h << 4) | l))
|
||||
.collect::<Option<Vec<u8>>>()
|
||||
.ok_or(xml(offset, "bdata holds a character that is not a hex digit"))
|
||||
}
|
||||
let alphabet = b"0123456789abcdefABCDEFgG \0";
|
||||
let mut seed = 0x2545_f491_4f6c_dd1du64;
|
||||
for len in 0..200usize {
|
||||
for _ in 0..20 {
|
||||
let text: Vec<u8> = (0..len)
|
||||
.map(|_| {
|
||||
seed ^= seed << 13;
|
||||
seed ^= seed >> 7;
|
||||
seed ^= seed << 17;
|
||||
// Mostly hex digits, now and then a byte that is not one.
|
||||
let i = (seed % 1000) as usize;
|
||||
alphabet[if i < 990 { i % 22 } else { 22 + i % 4 }]
|
||||
})
|
||||
.collect();
|
||||
let new = decode_hex(&text, 7);
|
||||
assert_eq!(new, old(&text, 7));
|
||||
if let Ok(v) = new {
|
||||
assert_eq!(v.capacity(), v.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limits_hold() {
|
||||
let deep = format!("<AfterEffectsProject>{}{}</AfterEffectsProject>", "<a>".repeat(100_000), "</a>".repeat(100_000));
|
||||
@@ -637,4 +913,292 @@ mod tests {
|
||||
let many = format!("<AfterEffectsProject>{}</AfterEffectsProject>", "<a/>".repeat(10));
|
||||
assert_eq!(read_aepx_with_limits(many.as_bytes(), Limits { max_depth: 64, max_chunks: 9 }), Err(AepError::TooManyChunks));
|
||||
}
|
||||
|
||||
/// A tiny deterministic generator (xorshift64*), so the tests need no extra crate.
|
||||
struct Rng(u64);
|
||||
|
||||
impl Rng {
|
||||
/// The next pseudo-random number.
|
||||
fn next(&mut self) -> u64 {
|
||||
let mut x = self.0;
|
||||
x ^= x >> 12;
|
||||
x ^= x << 25;
|
||||
x ^= x >> 27;
|
||||
self.0 = x;
|
||||
x.wrapping_mul(0x2545_f491_4f6c_dd1d)
|
||||
}
|
||||
|
||||
/// A number below `n` (0 for `n == 0`).
|
||||
fn below(&mut self, n: usize) -> usize {
|
||||
if n == 0 { 0 } else { usize::try_from(self.next() % n as u64).unwrap() }
|
||||
}
|
||||
|
||||
/// One of `items`.
|
||||
fn pick<'s>(&mut self, items: &[&'s str]) -> &'s str {
|
||||
items[self.below(items.len())]
|
||||
}
|
||||
}
|
||||
|
||||
/// `n` random bytes as hex, upper or lower case.
|
||||
fn hex(rng: &mut Rng, n: usize) -> String {
|
||||
let upper = rng.below(4) == 0;
|
||||
(0..n).map(|_| if upper { format!("{:02X}", rng.below(256)) } else { format!("{:02x}", rng.below(256)) }).collect()
|
||||
}
|
||||
|
||||
/// Random `.aepx` content: every element form the reader knows (data, lists, nested ids,
|
||||
/// strings, numbers, `btdk`, file references, skipped elements, XMP packets), `bdata` next to
|
||||
/// children, bodies that read as chunk sequences, entities, CDATA, comments and stray text.
|
||||
fn content(rng: &mut Rng, depth: usize, budget: &mut usize, out: &mut String) {
|
||||
for _ in 0..rng.below(6) {
|
||||
if *budget == 0 {
|
||||
return;
|
||||
}
|
||||
*budget -= 1;
|
||||
match rng.below(20) {
|
||||
0..=3 => {
|
||||
let id = rng.pick(&["cdat", "tdmn", "head", "Utf8", "idta", "LIST", "a"]);
|
||||
let n = rng.below(9);
|
||||
out.push_str(&format!("<{id} bdata=\"{}\"/>", hex(rng, n)));
|
||||
}
|
||||
4..=6 if depth < 10 => {
|
||||
let id = rng.pick(&["Fold", "tdgp", "Layr", "Pin", "LIST", "btdk", "sspc"]);
|
||||
let attr = if rng.below(5) == 0 { format!(" bdata=\"{}\"", hex(rng, 3)) } else { String::new() };
|
||||
out.push_str(&format!("<{id}{attr}>"));
|
||||
content(rng, depth + 1, budget, out);
|
||||
out.push_str(&format!("</{id}>"));
|
||||
}
|
||||
7 => {
|
||||
let id = rng.pick(&["tdsn", "pdnm", "fnam"]);
|
||||
match rng.below(4) {
|
||||
0 => out.push_str(&format!("<{id}/>")),
|
||||
1 => out.push_str(&format!("<{id}><string>name & A</string></{id}>")),
|
||||
// A body that is itself a chunk sequence (`Utf8`, 1 byte, pad): still data.
|
||||
2 => out.push_str(&format!("<{id} bdata=\"557466380000000161{}\"/>", if rng.below(2) == 0 { "00" } else { "" })),
|
||||
_ => out.push_str(&format!("<{id}><string>a</string><string>b</string></{id}>")),
|
||||
}
|
||||
}
|
||||
8 => {
|
||||
let text = rng.pick(&["plain", "A < B", "<![CDATA[x<y]]>", "a<!-- c -->b", "", "été", "x<Skip>gone</Skip>y", "\r\n"]);
|
||||
out.push_str(&format!("<string>{text}</string>"));
|
||||
}
|
||||
9 => {
|
||||
let id = rng.pick(&["numS", "ppSn"]);
|
||||
let inner = rng.pick(&[
|
||||
"<string>0</string>",
|
||||
"<string> 7 </string>",
|
||||
"<string>-2147483648</string>",
|
||||
"<string>150.000000000</string>",
|
||||
"<string>x</string>",
|
||||
"",
|
||||
"<string>1</string><string>2</string>",
|
||||
"<Utf8 bdata=\"31\"/>",
|
||||
"<cdat bdata=\"31\"/>",
|
||||
"<Comment>3</Comment><string>4</string>",
|
||||
]);
|
||||
let attr = if rng.below(6) == 0 { " bdata=\"00000002\"" } else { "" };
|
||||
out.push_str(&format!("<{id}{attr}>{inner}</{id}>"));
|
||||
}
|
||||
10 => {
|
||||
let n = rng.pick(&["", "41", "414243", "4c495354000000000000"]);
|
||||
out.push_str(&format!("<btdk bdata=\"{n}\"/>"));
|
||||
}
|
||||
11 => {
|
||||
let platform = rng.pick(&["Win", "1", "Mac"]);
|
||||
out.push_str(&format!(
|
||||
"<Als2><fileReference ascendcount_base=\"1\" fullpath=\"C:\\a\\"b	.png\" platform=\"{platform}\" target_is_folder=\"{}\"/></Als2>",
|
||||
rng.below(3)
|
||||
));
|
||||
}
|
||||
12 if depth < 10 => {
|
||||
out.push_str("<Comment note=\"&\">text<a bdata=\"00\"/>");
|
||||
content(rng, depth + 1, budget, out);
|
||||
out.push_str("</Comment>");
|
||||
}
|
||||
13 => {
|
||||
let packet = rng.pick(&["<![CDATA[<?xpacket begin?>x<?xpacket end?>]]>", "plain & text", ""]);
|
||||
out.push_str(&format!("<ProjectXMPMetadata>{packet}</ProjectXMPMetadata>"));
|
||||
}
|
||||
14 => out.push_str(rng.pick(&["<!-- comment -->", "<?pi x?>", "\n ", "stray"])),
|
||||
_ => {
|
||||
let n = rng.below(5);
|
||||
out.push_str(&format!("<tdb4 bdata=\"{}\" x='y'></tdb4>", hex(rng, n)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The default limits and six tight ones (depth 0, 1 and 3; 0, 7 and 40 chunks).
|
||||
fn limit_sets() -> [Limits; 7] {
|
||||
[
|
||||
Limits { max_depth: 0, max_chunks: 10_000_000 },
|
||||
Limits { max_depth: 64, max_chunks: 0 },
|
||||
Limits::default(),
|
||||
Limits { max_depth: 1, max_chunks: 10_000_000 },
|
||||
Limits { max_depth: 3, max_chunks: 10_000_000 },
|
||||
Limits { max_depth: 64, max_chunks: 7 },
|
||||
Limits { max_depth: 64, max_chunks: 40 },
|
||||
]
|
||||
}
|
||||
|
||||
/// The index reader and the owned-tree reader give the same `Result` (the tree, or the error),
|
||||
/// and the index walks like the index of the owned tree.
|
||||
fn same(bytes: &[u8], limits: Limits) {
|
||||
let old = read_aepx_with_limits(bytes, limits);
|
||||
let new = index_aepx(bytes, limits).map(|d| TreeIndex::from_drafts(&d.buffer, d.nodes, d.trailer).to_file().into_owned());
|
||||
assert_eq!(new, old, "{}", String::from_utf8_lossy(bytes));
|
||||
if let Ok(file) = &old {
|
||||
let AepxDrafts { buffer, nodes, trailer } = index_aepx(bytes, limits).unwrap();
|
||||
let index = TreeIndex::from_drafts(&buffer, nodes, trailer);
|
||||
let expected = TreeIndex::from_file(file).unwrap();
|
||||
assert_eq!(index.len(), expected.len());
|
||||
assert_eq!(index.trailer(), expected.trailer());
|
||||
let a: Vec<String> = index.walk().map(|(d, n)| format!("{d} {n:?}")).collect();
|
||||
let b: Vec<String> = expected.walk().map(|(d, n)| format!("{d} {n:?}")).collect();
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
/// The two readers give the same tree and errors on generated and damaged documents.
|
||||
#[test]
|
||||
fn the_two_readers_agree_on_generated_and_damaged_documents() {
|
||||
let mut rng = Rng(0x9e37_79b9_7f4a_7c15);
|
||||
let noise = b"<>/=\"'&;#x0aZ \n![]-?";
|
||||
for _ in 0..600 {
|
||||
let mut budget = 80;
|
||||
let mut body = String::new();
|
||||
content(&mut rng, 0, &mut budget, &mut body);
|
||||
let x = doc(&body);
|
||||
for l in limit_sets() {
|
||||
same(x.as_bytes(), l);
|
||||
}
|
||||
for _ in 0..4 {
|
||||
let mut bad = x.clone().into_bytes();
|
||||
for _ in 0..1 + rng.below(3) {
|
||||
let at = rng.below(bad.len());
|
||||
bad[at] = noise[rng.below(noise.len())];
|
||||
}
|
||||
for l in limit_sets() {
|
||||
same(&bad, l);
|
||||
}
|
||||
}
|
||||
let cut = rng.below(x.len());
|
||||
same(&x.as_bytes()[..cut], Limits::default());
|
||||
// Bytes that are not UTF-8, and a multi-byte character cut in half.
|
||||
let mut bad = x.clone().into_bytes();
|
||||
let at = rng.below(bad.len());
|
||||
bad.insert(at, 0xff);
|
||||
same(&bad, Limits::default());
|
||||
let open = format!("{}<string>é", x.trim_end().trim_end_matches("</AfterEffectsProject>")).into_bytes();
|
||||
same(&open[..open.len() - 1], Limits::default());
|
||||
}
|
||||
}
|
||||
|
||||
/// The flat chunk list never reserves more slots than the input or the chunk limit allows.
|
||||
#[test]
|
||||
fn the_chunk_list_is_bounded_by_the_input_and_the_limit() {
|
||||
let many = format!("<AfterEffectsProject>{}</AfterEffectsProject>", "<a/>".repeat(10_000));
|
||||
let d = index_aepx(many.as_bytes(), Limits::default()).unwrap();
|
||||
assert_eq!(d.nodes.len(), 10_000);
|
||||
assert!(d.nodes.capacity() <= 2 * 10_000, "{} slots for 10 000 chunks", d.nodes.capacity());
|
||||
// The buffer is reserved once, at half the input, and holds nothing here.
|
||||
assert!(d.buffer.is_empty() && d.buffer.capacity() <= many.len() / 2);
|
||||
// At the limit the list never holds more slots than the limit.
|
||||
let d = index_aepx(many.as_bytes(), Limits { max_depth: 64, max_chunks: 10_000 }).unwrap();
|
||||
assert!(d.nodes.capacity() <= 10_000);
|
||||
let few = format!("<AfterEffectsProject>{}</AfterEffectsProject>", "<a/>".repeat(100));
|
||||
let d = index_aepx(few.as_bytes(), Limits { max_depth: 64, max_chunks: 100 }).unwrap();
|
||||
assert!(d.nodes.capacity() <= 100, "{} slots for at most 100 chunks", d.nodes.capacity());
|
||||
assert_eq!(index_aepx(few.as_bytes(), Limits { max_depth: 64, max_chunks: 99 }).err(), Some(AepError::TooManyChunks));
|
||||
// A tiny input cannot hold more than a third of its bytes in elements.
|
||||
let tiny = doc("<a/>");
|
||||
assert!(index_aepx(tiny.as_bytes(), Limits::default()).unwrap().nodes.capacity() <= tiny.len() / 3);
|
||||
}
|
||||
|
||||
/// What a closed element drops is gone from the buffer and the chunk list, but was counted.
|
||||
#[test]
|
||||
fn dropped_content_leaves_nothing_behind_but_still_counts() {
|
||||
// `bdata` wins over the children: they are read, counted and dropped.
|
||||
let x = doc("<a bdata=\"01\"><b bdata=\"0203\"/><string>xyz</string><tdsn><string>q</string></tdsn></a>");
|
||||
let d = index_aepx(x.as_bytes(), Limits::default()).unwrap();
|
||||
assert_eq!((d.buffer.as_slice(), d.nodes.len()), (&[1u8][..], 1));
|
||||
assert_eq!(index_aepx(x.as_bytes(), Limits { max_depth: 64, max_chunks: 4 }).err(), Some(AepError::TooManyChunks));
|
||||
assert!(index_aepx(x.as_bytes(), Limits { max_depth: 64, max_chunks: 5 }).is_ok());
|
||||
// A child's error is raised although the child would be dropped.
|
||||
assert!(matches!(index_aepx(doc("<a bdata=\"01\"><numS></numS></a>").as_bytes(), Limits::default()), Err(AepError::Xml { .. })));
|
||||
// Only the first XMP packet stays in the buffer.
|
||||
let packets = doc(&"<ProjectXMPMetadata>packet</ProjectXMPMetadata>".repeat(1000));
|
||||
let d = index_aepx(packets.as_bytes(), Limits::default()).unwrap();
|
||||
assert_eq!((d.buffer.as_slice(), d.trailer), (&b"packet"[..], (0, 6)));
|
||||
// A number keeps its 4 or 8 bytes, not its text.
|
||||
let d = index_aepx(doc("<numS><string> 7 </string></numS><ppSn><string>1.5</string></ppSn>").as_bytes(), Limits::default()).unwrap();
|
||||
assert_eq!(d.buffer, [&[0, 0, 0, 7][..], &1.5f64.to_be_bytes()[..]].concat());
|
||||
assert_eq!(d.nodes.len(), 2);
|
||||
}
|
||||
|
||||
/// Bodies keep what the element says they are, even where reading the same bytes as an `.aep`
|
||||
/// would decide otherwise: a nested id whose `bdata` is a chunk sequence stays data, an empty
|
||||
/// `btdk` stays an opaque list, an empty list at the deepest level stays a list.
|
||||
#[test]
|
||||
fn bodies_keep_the_kind_the_element_gives_them() {
|
||||
let x = doc("<tdsn bdata=\"5574663800000001610000\"/><btdk bdata=\"\"/><btdk bdata=\"4c4953540000000474657374\"/>");
|
||||
let AepxDrafts { buffer, nodes, trailer } = index_aepx(x.as_bytes(), Limits::default()).unwrap();
|
||||
let index = TreeIndex::from_drafts(&buffer, nodes, trailer);
|
||||
let top: Vec<_> = index.chunks().collect();
|
||||
assert_eq!(top.len(), 3);
|
||||
assert_eq!(top[0].bytes().map(<[u8]>::len), Some(11));
|
||||
assert!(top[0].children().next().is_none());
|
||||
assert!(top[1].is_opaque_list() && top[1].bytes() == Some(&[][..]));
|
||||
assert!(top[2].is_opaque_list() && top[2].bytes().map(<[u8]>::len) == Some(12));
|
||||
// 64 levels: the innermost (empty) list is a list, not opaque.
|
||||
let deep = format!("<AfterEffectsProject>{}{}</AfterEffectsProject>", "<Fold>".repeat(64), "</Fold>".repeat(64));
|
||||
let AepxDrafts { buffer, nodes, trailer } = index_aepx(deep.as_bytes(), Limits::default()).unwrap();
|
||||
let index = TreeIndex::from_drafts(&buffer, nodes, trailer);
|
||||
assert_eq!(index.walk().map(|(d, _)| d).max(), Some(64));
|
||||
assert!(index.walk().all(|(_, n)| n.is_list(b"Fold") && !n.is_opaque_list()));
|
||||
same(x.as_bytes(), Limits::default());
|
||||
same(deep.as_bytes(), Limits::default());
|
||||
}
|
||||
|
||||
/// Hostile input is refused by both readers with the same errors.
|
||||
#[test]
|
||||
fn hostile_input_is_refused_alike_by_both_readers() {
|
||||
let hostile = [
|
||||
format!("<AfterEffectsProject>{}{}</AfterEffectsProject>", "<a>".repeat(100_000), "</a>".repeat(100_000)),
|
||||
format!("<AfterEffectsProject>{}", "<string>".repeat(1000)),
|
||||
doc(&format!("<a bdata=\"{}0\"/>", "00".repeat(100_000))),
|
||||
doc(&format!("<a bdata=\"{}zz\"/>", "00".repeat(100_000))),
|
||||
doc("<numS><string>4294967296</string></numS>"),
|
||||
doc("<ppSn><string>1e400x</string></ppSn>"),
|
||||
doc("<string>�</string>"),
|
||||
doc("<string>�</string>"),
|
||||
doc(&format!("<Fold>{}", "<b/>".repeat(1000))),
|
||||
format!("<AfterEffectsProject>{}</AfterEffectsProject><x/>", "<a/>".repeat(10)),
|
||||
"<AfterEffectsProject><a bdata=\"00".to_string(),
|
||||
"<AfterEffectsProject><![CDATA[x".to_string(),
|
||||
];
|
||||
for x in &hostile {
|
||||
assert!(read_aepx(x.as_bytes()).is_err(), "{}", &x[..x.len().min(80)]);
|
||||
for l in limit_sets() {
|
||||
same(x.as_bytes(), l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Every `.aepx` of the fixture directory gives the same tree through both readers (skipped
|
||||
/// without `EFFECTCRAFT_AEP_FIXTURES`).
|
||||
#[test]
|
||||
fn every_fixture_aepx_gives_the_same_tree_through_both_readers() {
|
||||
let Some(dir) = std::env::var_os("EFFECTCRAFT_AEP_FIXTURES").filter(|d| !d.is_empty()) else { return };
|
||||
let Ok(entries) = std::fs::read_dir(dir) else { return };
|
||||
let mut paths: Vec<std::path::PathBuf> =
|
||||
entries.filter_map(Result::ok).map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "aepx")).collect();
|
||||
paths.sort();
|
||||
for path in paths {
|
||||
let bytes = std::fs::read(&path).unwrap();
|
||||
for l in limit_sets() {
|
||||
let index = index_aepx(&bytes, l).map(|d| TreeIndex::from_drafts(&d.buffer, d.nodes, d.trailer).to_file().into_owned());
|
||||
assert_eq!(index, read_aepx_with_limits(&bytes, l), "{}", path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
//! The `.aepx` reader of the owned chunk tree ([`super::read_aepx`]): it builds the tree element by
|
||||
//! element. The importer uses the index reader in `aepx.rs` instead; the tests compare the two on
|
||||
//! generated, damaged and corpus input (the same tree and the same errors).
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::{FILE_REFERENCE, OPAQUE_LIST_TYPES, ROOT, STRING, XMP, alias_json, chunk_id, decode_entities, decode_hex, xml};
|
||||
use crate::container::chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS};
|
||||
use crate::container::error::AepError;
|
||||
use crate::container::read::Limits;
|
||||
|
||||
/// [`super::read_aepx_with_limits`].
|
||||
pub(super) fn read(data: &[u8], limits: Limits) -> Result<AepFile<'static>, AepError> {
|
||||
let text = match std::str::from_utf8(data) {
|
||||
Ok(t) => t.as_bytes(),
|
||||
Err(e) => return Err(xml(e.valid_up_to(), "the file is not valid UTF-8")),
|
||||
};
|
||||
Reader { data: text, pos: 0, limits, count: 0, stack: Vec::new(), top: None, trailer: None }.run()
|
||||
}
|
||||
|
||||
/// What an open element becomes when it closes.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Kind {
|
||||
/// The root element: its children are the top-level chunks.
|
||||
Root,
|
||||
/// A chunk with this id (or a `LIST` with this list type).
|
||||
Chunk([u8; 4]),
|
||||
/// A `Utf8` chunk.
|
||||
Utf8,
|
||||
/// An `alas` chunk built from the attributes.
|
||||
Alias,
|
||||
/// The XMP packet (only directly below the root).
|
||||
Xmp,
|
||||
/// An element without a chunk counterpart (a name that is no chunk id); skipped with its content.
|
||||
Skip,
|
||||
}
|
||||
|
||||
struct Frame {
|
||||
kind: Kind,
|
||||
/// Offset of the start tag (for errors).
|
||||
at: usize,
|
||||
/// The name as written, to match the end tag.
|
||||
name: (usize, usize),
|
||||
/// The decoded `bdata` attribute.
|
||||
bdata: Option<Vec<u8>>,
|
||||
/// The attributes of a `fileReference`, in document order.
|
||||
attrs: Vec<(String, String)>,
|
||||
/// Collected text (only for `string` and the XMP packet).
|
||||
text: Vec<u8>,
|
||||
children: Vec<Chunk<'static>>,
|
||||
}
|
||||
|
||||
struct Reader<'d> {
|
||||
data: &'d [u8],
|
||||
pos: usize,
|
||||
limits: Limits,
|
||||
count: usize,
|
||||
stack: Vec<Frame>,
|
||||
/// The top-level chunks once the root element has closed.
|
||||
top: Option<Vec<Chunk<'static>>>,
|
||||
trailer: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Reader<'_> {
|
||||
fn run(mut self) -> Result<AepFile<'static>, AepError> {
|
||||
if self.data.starts_with(&[0xef, 0xbb, 0xbf]) {
|
||||
self.pos = 3;
|
||||
}
|
||||
while self.pos < self.data.len() {
|
||||
if self.rest().starts_with(b"<") {
|
||||
self.markup()?;
|
||||
} else {
|
||||
self.text()?;
|
||||
}
|
||||
}
|
||||
if let Some(open) = self.stack.last() {
|
||||
return Err(xml(open.at, "an element is not closed before the end of the file"));
|
||||
}
|
||||
let chunks = self.top.ok_or_else(|| xml(self.data.len(), "no AfterEffectsProject root element"))?;
|
||||
Ok(AepFile { chunks, trailer: Cow::Owned(self.trailer.unwrap_or_default()) })
|
||||
}
|
||||
|
||||
fn rest(&self) -> &[u8] {
|
||||
self.data.get(self.pos..).unwrap_or(&[])
|
||||
}
|
||||
|
||||
/// The offset of `needle` at or after `from`.
|
||||
fn find(&self, from: usize, needle: &[u8]) -> Option<usize> {
|
||||
let hay = self.data.get(from..)?;
|
||||
if needle.is_empty() || hay.len() < needle.len() {
|
||||
return None;
|
||||
}
|
||||
let first = *needle.first()?;
|
||||
let mut i = 0;
|
||||
while let Some(p) = hay.get(i..)?.iter().position(|b| *b == first) {
|
||||
let at = i.checked_add(p)?;
|
||||
if hay.get(at..)?.starts_with(needle) {
|
||||
return from.checked_add(at);
|
||||
}
|
||||
i = at.checked_add(1)?;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Skips to just after `close`, which must follow.
|
||||
fn skip_past(&mut self, close: &[u8], what: &'static str) -> Result<usize, AepError> {
|
||||
let at = self.find(self.pos, close).ok_or(xml(self.pos, what))?;
|
||||
self.pos = at.saturating_add(close.len());
|
||||
Ok(at)
|
||||
}
|
||||
|
||||
fn markup(&mut self) -> Result<(), AepError> {
|
||||
let rest = self.rest();
|
||||
if rest.starts_with(b"<?") {
|
||||
self.skip_past(b"?>", "a processing instruction is not closed")?;
|
||||
} else if rest.starts_with(b"<!--") {
|
||||
self.skip_past(b"-->", "a comment is not closed")?;
|
||||
} else if rest.starts_with(b"<![CDATA[") {
|
||||
let start = self.pos.saturating_add(9);
|
||||
self.pos = start;
|
||||
let end = self.skip_past(b"]]>", "a CDATA section is not closed")?;
|
||||
let content = self.data.get(start..end).unwrap_or(&[]);
|
||||
let at = start;
|
||||
match self.stack.last_mut() {
|
||||
Some(frame) => {
|
||||
if matches!(frame.kind, Kind::Utf8 | Kind::Xmp) {
|
||||
frame.text.extend_from_slice(content);
|
||||
}
|
||||
}
|
||||
None => return Err(xml(at, "CDATA outside the root element")),
|
||||
}
|
||||
} else if rest.starts_with(b"<!") {
|
||||
return Err(xml(self.pos, "document type declarations are not supported"));
|
||||
} else if rest.starts_with(b"</") {
|
||||
self.end_tag()?;
|
||||
} else {
|
||||
self.start_tag()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_name_byte(b: u8) -> bool {
|
||||
!(b.is_ascii_whitespace() || matches!(b, b'<' | b'>' | b'/' | b'=' | b'"' | b'\'' | b'&'))
|
||||
}
|
||||
|
||||
fn name(&mut self) -> Result<(usize, usize), AepError> {
|
||||
let start = self.pos;
|
||||
let len = self.rest().iter().position(|b| !Self::is_name_byte(*b)).unwrap_or(self.rest().len());
|
||||
if len == 0 {
|
||||
return Err(xml(start, "a tag or attribute has no name"));
|
||||
}
|
||||
self.pos = start.saturating_add(len);
|
||||
Ok((start, self.pos))
|
||||
}
|
||||
|
||||
fn skip_ws(&mut self) {
|
||||
let n = self.rest().iter().position(|b| !b.is_ascii_whitespace()).unwrap_or(self.rest().len());
|
||||
self.pos = self.pos.saturating_add(n);
|
||||
}
|
||||
|
||||
fn slice(&self, (a, b): (usize, usize)) -> &[u8] {
|
||||
self.data.get(a..b).unwrap_or(&[])
|
||||
}
|
||||
|
||||
fn start_tag(&mut self) -> Result<(), AepError> {
|
||||
let at = self.pos;
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
let name = self.name()?;
|
||||
let mut attrs = Vec::new();
|
||||
let self_closing = loop {
|
||||
self.skip_ws();
|
||||
let rest = self.rest();
|
||||
if rest.starts_with(b"/>") {
|
||||
self.pos = self.pos.saturating_add(2);
|
||||
break true;
|
||||
}
|
||||
if rest.starts_with(b">") {
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
break false;
|
||||
}
|
||||
if rest.is_empty() {
|
||||
return Err(xml(at, "a start tag is not closed"));
|
||||
}
|
||||
let key = self.name()?;
|
||||
self.skip_ws();
|
||||
if !self.rest().starts_with(b"=") {
|
||||
return Err(xml(self.pos, "an attribute has no value"));
|
||||
}
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
self.skip_ws();
|
||||
let quote = *self.rest().first().ok_or(xml(self.pos, "a start tag is not closed"))?;
|
||||
if quote != b'"' && quote != b'\'' {
|
||||
return Err(xml(self.pos, "an attribute value is not quoted"));
|
||||
}
|
||||
let vstart = self.pos.saturating_add(1);
|
||||
let vend = self.find(vstart, &[quote]).ok_or(xml(vstart, "an attribute value is not closed"))?;
|
||||
let raw = self.data.get(vstart..vend).unwrap_or(&[]);
|
||||
if raw.contains(&b'<') {
|
||||
return Err(xml(vstart, "`<` inside an attribute value"));
|
||||
}
|
||||
// A value without `&` is its own decoding (most of them, every `bdata` After Effects
|
||||
// writes): borrow it instead of copying it.
|
||||
let value = if raw.contains(&b'&') {
|
||||
let mut value = Vec::new();
|
||||
decode_entities(raw, vstart, &mut value)?;
|
||||
Cow::Owned(value)
|
||||
} else {
|
||||
Cow::Borrowed(raw)
|
||||
};
|
||||
self.pos = vend.saturating_add(1);
|
||||
attrs.push((key, value));
|
||||
};
|
||||
let kind = self.kind_of(name, at)?;
|
||||
if kind != Kind::Root {
|
||||
self.count = self.count.saturating_add(1);
|
||||
if self.count > self.limits.max_chunks {
|
||||
return Err(AepError::TooManyChunks);
|
||||
}
|
||||
// The root's children are depth 1, like the top-level chunks of an `.aep`.
|
||||
if self.stack.len() > self.limits.max_depth {
|
||||
return Err(AepError::TooDeep);
|
||||
}
|
||||
}
|
||||
let mut frame = Frame { kind, at, name, bdata: None, attrs: Vec::new(), text: Vec::new(), children: Vec::new() };
|
||||
if matches!(kind, Kind::Chunk(_)) {
|
||||
if let Some((key, value)) = attrs.iter().find(|(k, _)| self.slice(*k) == b"bdata") {
|
||||
frame.bdata = Some(decode_hex(value, key.1)?);
|
||||
}
|
||||
} else if kind == Kind::Alias {
|
||||
frame.attrs = attrs.iter().map(|(k, v)| (String::from_utf8_lossy(self.slice(*k)).into_owned(), String::from_utf8_lossy(v).into_owned())).collect();
|
||||
}
|
||||
self.stack.push(frame);
|
||||
if self_closing {
|
||||
self.close()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Classifies an element by its name and where it is.
|
||||
fn kind_of(&self, name: (usize, usize), at: usize) -> Result<Kind, AepError> {
|
||||
let n = self.slice(name);
|
||||
let parent = match self.stack.last() {
|
||||
None => {
|
||||
if self.top.is_some() {
|
||||
return Err(xml(at, "a second root element"));
|
||||
}
|
||||
if n != ROOT {
|
||||
return Err(xml(at, "the root element is not AfterEffectsProject"));
|
||||
}
|
||||
return Ok(Kind::Root);
|
||||
}
|
||||
Some(p) => p.kind,
|
||||
};
|
||||
Ok(match parent {
|
||||
Kind::Skip | Kind::Utf8 | Kind::Xmp | Kind::Alias => Kind::Skip,
|
||||
Kind::Root | Kind::Chunk(_) => {
|
||||
if n == STRING {
|
||||
Kind::Utf8
|
||||
} else if n == FILE_REFERENCE {
|
||||
Kind::Alias
|
||||
} else if n == XMP && parent == Kind::Root {
|
||||
Kind::Xmp
|
||||
} else if let Some(id) = chunk_id(n) {
|
||||
Kind::Chunk(id)
|
||||
} else {
|
||||
Kind::Skip
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn end_tag(&mut self) -> Result<(), AepError> {
|
||||
let at = self.pos;
|
||||
self.pos = self.pos.saturating_add(2);
|
||||
let name = self.name()?;
|
||||
self.skip_ws();
|
||||
if !self.rest().starts_with(b">") {
|
||||
return Err(xml(at, "an end tag is not closed"));
|
||||
}
|
||||
self.pos = self.pos.saturating_add(1);
|
||||
let open = self.stack.last().ok_or(xml(at, "an end tag without a start tag"))?;
|
||||
if self.slice(open.name) != self.slice(name) {
|
||||
return Err(xml(at, "an end tag does not match its start tag"));
|
||||
}
|
||||
self.close()
|
||||
}
|
||||
|
||||
/// Closes the innermost element and hands its chunk to the parent.
|
||||
fn close(&mut self) -> Result<(), AepError> {
|
||||
let frame = self.stack.pop().ok_or(xml(self.pos, "an end tag without a start tag"))?;
|
||||
let chunk = match frame.kind {
|
||||
Kind::Root => {
|
||||
self.top = Some(frame.children);
|
||||
return Ok(());
|
||||
}
|
||||
Kind::Skip => return Ok(()),
|
||||
Kind::Xmp => {
|
||||
if self.trailer.is_none() {
|
||||
self.trailer = Some(frame.text);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
Kind::Utf8 => Chunk::data(*b"Utf8", frame.text),
|
||||
Kind::Alias => Chunk::data(*b"alas", alias_json(&frame.attrs).into_bytes()),
|
||||
Kind::Chunk(id) => chunk_of(id, frame)?,
|
||||
};
|
||||
if let Some(parent) = self.stack.last_mut() {
|
||||
parent.children.push(chunk);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn text(&mut self) -> Result<(), AepError> {
|
||||
let start = self.pos;
|
||||
let len = self.rest().iter().position(|b| *b == b'<').unwrap_or(self.rest().len());
|
||||
let end = start.saturating_add(len);
|
||||
self.pos = end;
|
||||
let raw = self.data.get(start..end).unwrap_or(&[]);
|
||||
match self.stack.last_mut() {
|
||||
Some(frame) if matches!(frame.kind, Kind::Utf8 | Kind::Xmp) => decode_entities(raw, start, &mut frame.text),
|
||||
Some(_) => Ok(()),
|
||||
None if raw.iter().all(u8::is_ascii_whitespace) => Ok(()),
|
||||
None => Err(xml(start, "text outside the root element")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The chunk of a closed element named by a chunk id.
|
||||
fn chunk_of(id: [u8; 4], frame: Frame) -> Result<Chunk<'static>, AepError> {
|
||||
if let Some(bytes) = frame.bdata {
|
||||
if OPAQUE_LIST_TYPES.contains(&id) {
|
||||
let pad = if bytes.len() % 2 == 1 { Some(0) } else { None };
|
||||
return Ok(Chunk { id: LIST, body: Body::OpaqueList { list_type: id, data: Cow::Owned(bytes) }, pad });
|
||||
}
|
||||
return Ok(Chunk::data(id, bytes));
|
||||
}
|
||||
// Numbers written as text: `<numS><string>0</string></numS>` and `<ppSn><string>150.000000000</string></ppSn>`.
|
||||
if &id == b"numS" || &id == b"ppSn" {
|
||||
let text = match frame.children.as_slice() {
|
||||
[only] if only.is(b"Utf8") => only.bytes().unwrap_or(&[]),
|
||||
_ => return Err(xml(frame.at, "a numS or ppSn element without its number")),
|
||||
};
|
||||
let text = std::str::from_utf8(text).map_err(|_| xml(frame.at, "a number is not text"))?.trim();
|
||||
let body = if &id == b"numS" {
|
||||
// Only `0` is sampled, so whether the field is signed is open: accept both readings of 4 bytes.
|
||||
let n = text.parse::<i64>().ok().filter(|n| (i64::from(i32::MIN)..=i64::from(u32::MAX)).contains(n));
|
||||
let n = n.ok_or(xml(frame.at, "numS is not a 32-bit integer"))?;
|
||||
(n as u32).to_be_bytes().to_vec()
|
||||
} else {
|
||||
text.parse::<f64>().map_err(|_| xml(frame.at, "ppSn is not a number"))?.to_be_bytes().to_vec()
|
||||
};
|
||||
return Ok(Chunk::data(id, body));
|
||||
}
|
||||
if NESTED_IDS.contains(&id) {
|
||||
if frame.children.is_empty() {
|
||||
return Ok(Chunk::data(id, Vec::new()));
|
||||
}
|
||||
return Ok(Chunk { id, body: Body::Chunks(frame.children), pad: None });
|
||||
}
|
||||
Ok(Chunk::list(id, frame.children))
|
||||
}
|
||||
@@ -7,9 +7,9 @@
|
||||
//! Hue/Saturation (444-446) or a Levels value (512-516) changes only bytes of this `aRbp` (and stale
|
||||
//! UI bytes of `pard`); the visible parameters of the same names keep no record.
|
||||
|
||||
use crate::container::Chunk;
|
||||
use crate::container::bytes::{be_f32, be_i32, be_u16, be_u32};
|
||||
use crate::container::effects::Effect;
|
||||
use crate::container::index::Node;
|
||||
|
||||
impl<'f, 'a> Effect<'f, 'a> {
|
||||
/// The arbitrary data stored for the parameter with this match name (`<effect>-NNNN`): the
|
||||
@@ -17,13 +17,13 @@ impl<'f, 'a> Effect<'f, 'a> {
|
||||
/// none.
|
||||
pub fn arbitrary_data(&self, match_name: &str) -> Option<&'f [u8]> {
|
||||
let values = self.chunk().child_list(b"tdgp")?;
|
||||
let kids = values.children();
|
||||
let at = kids.iter().position(|c| c.is(b"tdmn") && c.bytes().is_some_and(|b| name_is(b, match_name)))?;
|
||||
// The value record, then the data list (no match name of its own).
|
||||
let rest = kids.get(at.checked_add(1)?..)?;
|
||||
let mut it = rest.iter().take(3);
|
||||
let mut kids = values.children();
|
||||
// Up to the parameter's match name, then the value record, then the data list (no match
|
||||
// name of its own).
|
||||
kids.find(|c| c.is(b"tdmn") && c.bytes().is_some_and(|b| name_is(b, match_name)))?;
|
||||
let mut it = kids.take(3);
|
||||
let _record = it.next().filter(|c| c.is_list(b"tdbs"))?;
|
||||
it.find(|c| c.is_list(b"aRbs")).and_then(|l| l.child(b"aRbp")).and_then(Chunk::bytes)
|
||||
it.find(|c| c.is_list(b"aRbs")).and_then(|l| l.child(b"aRbp")).and_then(Node::bytes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
//! only when it is not the default 100.
|
||||
|
||||
use crate::container::typed::{Layer, PropNode};
|
||||
use crate::container::values::{Tracked, ValueSource, read, read_opt};
|
||||
|
||||
/// The Position of a camera or light layer as stored.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
@@ -28,16 +27,6 @@ pub struct CameraPosition {
|
||||
pub auto_state: bool,
|
||||
}
|
||||
|
||||
impl CameraPosition {
|
||||
/// The position as the batch-3 notes had After Effects report it: in the auto state of a
|
||||
/// two-node camera (`two_node`) x and y are the composition centre; otherwise the stored
|
||||
/// value. **Contradicted by 256 and 537 (session S16): After Effects reports and renders the
|
||||
/// stored value**; use `stored` for what After Effects shows.
|
||||
pub fn reported(&self, comp_width: u32, comp_height: u32, two_node: bool) -> [f64; 3] {
|
||||
if self.auto_state && two_node { [f64::from(comp_width) / 2.0, f64::from(comp_height) / 2.0, self.stored[2]] } else { self.stored }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'f, 'a> Layer<'f, 'a> {
|
||||
/// The Position record of a camera or light layer.
|
||||
pub fn camera_position(&self) -> Option<CameraPosition> {
|
||||
@@ -49,87 +38,9 @@ impl<'f, 'a> Layer<'f, 'a> {
|
||||
let derived = h.get(76) == Some(&1) && h.get(77) == Some(&1) && position.expression().is_none();
|
||||
Some(CameraPosition { stored, auto_state: derived })
|
||||
}
|
||||
|
||||
/// The point of interest of a camera in pixels (its Anchor Point record); `None` when absent.
|
||||
pub fn camera_point_of_interest(&self) -> Option<[f64; 3]> {
|
||||
let Some(PropNode::Group(transform)) = self.properties()?.get("ADBE Transform Group") else { return None };
|
||||
let tracked = read(&transform, "ADBE Anchor Point", [0.0; 3], 1.0);
|
||||
matches!(tracked.source, ValueSource::Stored | ValueSource::Keyframed).then_some(tracked.value)
|
||||
}
|
||||
|
||||
/// A light's intensity in percent; the default 100 when the property is absent.
|
||||
pub fn light_intensity(&self) -> Option<Tracked<f64>> {
|
||||
let root = self.properties()?;
|
||||
let Some(PropNode::Group(options)) = root.get("ADBE Light Options Group") else { return None };
|
||||
let t = read(&options, "ADBE Light Intensity", [100.0], 1.0);
|
||||
Some(Tracked { value: t.value[0], source: t.source })
|
||||
}
|
||||
}
|
||||
|
||||
/// The camera zoom After Effects uses when `ADBE Camera Zoom` is absent: 2666.67 px for the 50 mm
|
||||
/// default camera in the 1920 px wide corpus composition. Whether it follows other composition
|
||||
/// widths was not sampled.
|
||||
pub const DEFAULT_CAMERA_ZOOM: f64 = 2_666.666_666_666_666_5;
|
||||
|
||||
impl<'f, 'a> Layer<'f, 'a> {
|
||||
fn camera_options(&self) -> Option<crate::container::typed::PropGroup<'f, 'a>> {
|
||||
match self.properties()?.get("ADBE Camera Options Group") {
|
||||
Some(PropNode::Group(g)) => Some(g),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn light_options(&self) -> Option<crate::container::typed::PropGroup<'f, 'a>> {
|
||||
match self.properties()?.get("ADBE Light Options Group") {
|
||||
Some(PropNode::Group(g)) => Some(g),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A camera's zoom in pixels (`ADBE Camera Options Group/ADBE Camera Zoom`); absent = the
|
||||
/// default, [`DEFAULT_CAMERA_ZOOM`] (341: 2000 is stored). The auto Position keeps `-2666.67` and
|
||||
/// is not recomputed from the zoom.
|
||||
pub fn camera_zoom(&self) -> Option<Tracked<f64>> {
|
||||
let t = read(&self.camera_options()?, "ADBE Camera Zoom", [DEFAULT_CAMERA_ZOOM], 1.0);
|
||||
Some(Tracked { value: t.value[0], source: t.source })
|
||||
}
|
||||
|
||||
/// The depth of field switch (`ADBE Camera Depth of Field`, a checkbox; off by default, 342).
|
||||
pub fn camera_depth_of_field(&self) -> Option<Tracked<bool>> {
|
||||
let t = read(&self.camera_options()?, "ADBE Camera Depth of Field", [0.0], 1.0);
|
||||
Some(Tracked { value: t.value[0] != 0.0, source: t.source })
|
||||
}
|
||||
|
||||
/// A camera's focus distance in pixels (`ADBE Camera Focus Distance`); `None` while absent (its
|
||||
/// default is not known).
|
||||
pub fn camera_focus_distance(&self) -> Option<Tracked<f64>> {
|
||||
let t = read_opt::<1>(&self.camera_options()?, "ADBE Camera Focus Distance", 1.0)?;
|
||||
Some(Tracked { value: t.value[0], source: t.source })
|
||||
}
|
||||
|
||||
/// A camera's aperture (`ADBE Camera Aperture`); `None` while absent (its default is not known).
|
||||
pub fn camera_aperture(&self) -> Option<Tracked<f64>> {
|
||||
let t = read_opt::<1>(&self.camera_options()?, "ADBE Camera Aperture", 1.0)?;
|
||||
Some(Tracked { value: t.value[0], source: t.source })
|
||||
}
|
||||
|
||||
/// A light's colour as `[A, R, G, B]` fractions (`ADBE Light Options Group/ADBE Light Color`,
|
||||
/// stored as doubles 0..255); white when absent (343 stores red).
|
||||
pub fn light_color(&self) -> Option<Tracked<[f64; 4]>> {
|
||||
Some(read(&self.light_options()?, "ADBE Light Color", [1.0; 4], 1.0 / 255.0))
|
||||
}
|
||||
|
||||
/// A spot light's cone angle in degrees (`ADBE Light Cone Angle`); 90 when absent (344 stores 60).
|
||||
/// A point light stores 90 with `tdsb` 3.
|
||||
pub fn light_cone_angle(&self) -> Option<Tracked<f64>> {
|
||||
let t = read(&self.light_options()?, "ADBE Light Cone Angle", [90.0], 1.0);
|
||||
Some(Tracked { value: t.value[0], source: t.source })
|
||||
}
|
||||
|
||||
/// A spot light's cone feather in percent (`ADBE Light Cone Feather 2`); 50 when absent (345
|
||||
/// stores 30).
|
||||
pub fn light_cone_feather(&self) -> Option<Tracked<f64>> {
|
||||
let t = read(&self.light_options()?, "ADBE Light Cone Feather 2", [50.0], 1.0);
|
||||
Some(Tracked { value: t.value[0], source: t.source })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,19 @@ pub enum Conv {
|
||||
Skip,
|
||||
}
|
||||
|
||||
impl Conv {
|
||||
/// For a number (`Percent`, `Plain`, `Factor`): what a stored value is multiplied by to give
|
||||
/// the value here. `None` for every other conversion.
|
||||
pub fn number_scale(self) -> Option<f64> {
|
||||
match self {
|
||||
Conv::Percent { valid_max } => Some(100.0 / valid_max),
|
||||
Conv::Plain { .. } => Some(1.0),
|
||||
Conv::Factor { factor, .. } => Some(factor),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// After Effects' popup items as the corpus stores them (`pdnm`).
|
||||
/// 368.
|
||||
pub const RAMP_SHAPE: &[&str] = &["Linear Ramp", "Radial Ramp"];
|
||||
@@ -1142,11 +1155,37 @@ pub const GLOW_MIDPOINT_MAX: f64 = 0.990_005_493_164_062_5;
|
||||
|
||||
/// The key a popup item is matched by between the two programs: trimmed, lower case, and
|
||||
/// Set Matte's "Red Channel" ... "Alpha Channel" are EffectCraft's "Red" ... "Alpha" (904 E24).
|
||||
///
|
||||
/// Lower case is Unicode's, not only ASCII's: After Effects stores popup items in its UI
|
||||
/// language, so an item can start with a capital outside ASCII (French "Écran"), and its key must
|
||||
/// be the same as for the same word in lower case.
|
||||
pub fn popup_key(item: &str) -> String {
|
||||
let s = item.trim().to_ascii_lowercase();
|
||||
let s = item.trim().to_lowercase();
|
||||
s.strip_suffix(" channel").map(str::to_string).unwrap_or(s)
|
||||
}
|
||||
|
||||
/// The English [`popup_key`] a non-English After Effects popup item name stands for, when this
|
||||
/// table knows it; `None` otherwise. EffectCraft's own popup options are English only, so a
|
||||
/// project saved by an After Effects set to another UI language never matches them by name and
|
||||
/// the parameter falls back to its default (observed on a real "Niveaux" project, French After
|
||||
/// Effects 2026 26.0.0x67: Levels' Channel and Clip to Output Black / White). Add an entry only
|
||||
/// from a confirmed After Effects label, never a guess at a whole menu's translation.
|
||||
pub fn popup_alias(key: &str) -> Option<&'static str> {
|
||||
Some(match key {
|
||||
// French: Levels' Channel popup (`ADBE Easy Levels2-0001`). "Alpha" is the same word in
|
||||
// both languages, so it needs no entry.
|
||||
"rvb" => "rgb",
|
||||
"rouge" => "red",
|
||||
"vert" => "green",
|
||||
"bleu" => "blue",
|
||||
// French: Levels' Clip to Output Black / White popups (`-0008`, `-0009`).
|
||||
"activé" => "on",
|
||||
"désactivé" => "off",
|
||||
"désactivé pour la couleur 32 bpc" => "off for 32 bpc color",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The table row of an After Effects match name.
|
||||
pub fn by_match_name(match_name: &str) -> Option<&'static EffectMap> {
|
||||
EFFECTS.iter().find(|m| m.match_name == match_name)
|
||||
@@ -1164,3 +1203,17 @@ pub const HUE_SATURATION_MASTER: [&str; 3] = ["hue", "saturation", "lightness"];
|
||||
/// The EffectCraft parameters Levels' RGB channel values (`Extra::Levels`) go to, in the order of
|
||||
/// the data (input black, input white, gamma, output black, output white: 512-516).
|
||||
pub const LEVELS_RGB: [&str; 5] = ["inBlack", "inWhite", "gamma", "outBlack", "outWhite"];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A capital outside ASCII has the same key as its lower case; ASCII keys are unchanged.
|
||||
#[test]
|
||||
fn popup_key_lowers_non_ascii_capitals() {
|
||||
assert_eq!(popup_key("ÉCRAN"), popup_key("écran"));
|
||||
assert_eq!(popup_key(" Désactivé "), "désactivé");
|
||||
assert_eq!(popup_key("Off for 32 bpc Color"), "off for 32 bpc color");
|
||||
assert_eq!(popup_key("Red Channel"), "red");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::container::Chunk;
|
||||
use crate::container::bytes::{array, be_f32, be_f64, be_i32, be_u16, be_u32, cstr, text, until_nul};
|
||||
use crate::container::index::Node;
|
||||
use crate::container::typed::{KeyList, Layer, Project, PropGroup, PropNode, Property};
|
||||
|
||||
/// The parameter type, the `u32` at byte 12 of `pard`. The numbering matches the plug-in
|
||||
@@ -132,7 +132,7 @@ pub enum LayerRef {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Effect<'f, 'a> {
|
||||
match_name: String,
|
||||
chunk: &'f Chunk<'a>,
|
||||
chunk: Node<'f, 'a>,
|
||||
}
|
||||
|
||||
/// Where the parameter definitions of an effect instance come from.
|
||||
@@ -178,13 +178,13 @@ impl<'f, 'a> Effect<'f, 'a> {
|
||||
}
|
||||
|
||||
/// The underlying `LIST sspc` chunk.
|
||||
pub fn chunk(&self) -> &'f Chunk<'a> {
|
||||
pub fn chunk(&self) -> Node<'f, 'a> {
|
||||
self.chunk
|
||||
}
|
||||
|
||||
/// The instance name shown in the effect controls (`fnam`).
|
||||
pub fn name(&self) -> Option<String> {
|
||||
self.chunk.child(b"fnam")?.children().iter().find(|c| c.is(b"Utf8"))?.bytes().map(text)
|
||||
self.chunk.child(b"fnam")?.child(b"Utf8")?.bytes().map(text)
|
||||
}
|
||||
|
||||
/// The name the user gave the instance: the `tdsn` of the instance's value group when it is
|
||||
@@ -192,7 +192,7 @@ impl<'f, 'a> Effect<'f, 'a> {
|
||||
/// `None` while the instance shows the effect's name.
|
||||
pub fn user_name(&self) -> Option<String> {
|
||||
let values = self.chunk.child_list(b"tdgp")?;
|
||||
let name = values.child(b"tdsn")?.children().iter().find(|c| c.is(b"Utf8"))?.bytes().map(text)?;
|
||||
let name = values.child(b"tdsn")?.child(b"Utf8")?.bytes().map(text)?;
|
||||
(name != "-_0_/-" && !name.is_empty()).then_some(name)
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ impl<'f, 'a> Effect<'f, 'a> {
|
||||
}
|
||||
|
||||
/// The parameters described by `part` (a `LIST parT`) with the values of this instance.
|
||||
fn params_from(&self, part: &'f Chunk<'a>, borrowed: bool) -> Vec<EffectParam<'f, 'a>> {
|
||||
fn params_from(&self, part: Node<'f, 'a>, borrowed: bool) -> Vec<EffectParam<'f, 'a>> {
|
||||
let mut out: Vec<EffectParam<'f, 'a>> = Vec::new();
|
||||
// The stored values by match name: the first entry of a name, as `PropGroup::get` finds it
|
||||
// (a group of that name means no stored value). Indexed once: a lookup per parameter
|
||||
@@ -280,7 +280,7 @@ impl<'f, 'a> Effect<'f, 'a> {
|
||||
});
|
||||
} else if c.is(b"pdnm")
|
||||
&& let Some(last) = out.last_mut()
|
||||
&& let Some(u) = c.children().iter().find(|u| u.is(b"Utf8"))
|
||||
&& let Some(u) = c.child(b"Utf8")
|
||||
&& let Some(b) = u.bytes()
|
||||
// An empty `pdnm` names nothing (EffectCraft's exports write one: the effect
|
||||
// supplies its items).
|
||||
@@ -293,8 +293,9 @@ impl<'f, 'a> Effect<'f, 'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn has_pard(part: &Chunk<'_>) -> bool {
|
||||
part.children().iter().any(|c| c.is(b"pard"))
|
||||
/// True when a `LIST parT` holds parameter definitions (a `pard`).
|
||||
fn has_pard(part: Node<'_, '_>) -> bool {
|
||||
part.children().any(|c| c.is(b"pard"))
|
||||
}
|
||||
|
||||
impl<'f, 'a> Project<'f, 'a> {
|
||||
@@ -302,18 +303,18 @@ impl<'f, 'a> Project<'f, 'a> {
|
||||
/// name and the `LIST parT` of the copied instance, in file order (the stack order of the
|
||||
/// types, 365/366). The `EfDC` count before them is little-endian and is not needed to read
|
||||
/// them. A type whose copy has no definitions is left out.
|
||||
pub fn effect_definitions(&self) -> Vec<(String, &'f Chunk<'a>)> {
|
||||
let mut out: Vec<(String, &'f Chunk<'a>)> = Vec::new();
|
||||
pub fn effect_definitions(&self) -> Vec<(String, Node<'f, 'a>)> {
|
||||
let mut out: Vec<(String, Node<'f, 'a>)> = Vec::new();
|
||||
let Some(defs) = self.effect_defs else { return out };
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
for df in defs.children().iter().filter(|c| c.is_list(b"EfDf")) {
|
||||
for df in defs.children().filter(|c| c.is_list(b"EfDf")) {
|
||||
let mut name: Option<String> = None;
|
||||
for c in df.children() {
|
||||
if c.is(b"tdmn") {
|
||||
name = c.bytes().map(|b| text(until_nul(b)));
|
||||
} else if c.is_list(b"sspc")
|
||||
&& let Some(n) = name.take()
|
||||
&& let Some(part) = c.child_list(b"parT").filter(|p| has_pard(p))
|
||||
&& let Some(part) = c.child_list(b"parT").filter(|p| has_pard(*p))
|
||||
&& seen.insert(n.clone())
|
||||
{
|
||||
out.push((n, part));
|
||||
@@ -328,8 +329,8 @@ impl<'f, 'a> Project<'f, 'a> {
|
||||
/// For a type without a project-level copy it also keeps the own `parT` of the first instance
|
||||
/// in the file (items, layers and effects in file order) that has one.
|
||||
pub fn effect_definition_index(&self) -> EffectDefinitions<'f, 'a> {
|
||||
let by_name: HashMap<String, &'f Chunk<'a>> = self.effect_definitions().into_iter().collect();
|
||||
let mut instances: HashMap<String, &'f Chunk<'a>> = HashMap::new();
|
||||
let by_name: HashMap<String, Node<'f, 'a>> = self.effect_definitions().into_iter().collect();
|
||||
let mut instances: HashMap<String, Node<'f, 'a>> = HashMap::new();
|
||||
for item in self.all_items() {
|
||||
let Some(comp) = item.comp() else { continue };
|
||||
for layer in comp.layers() {
|
||||
@@ -337,7 +338,7 @@ impl<'f, 'a> Project<'f, 'a> {
|
||||
if by_name.contains_key(&fx.match_name) || instances.contains_key(&fx.match_name) {
|
||||
continue;
|
||||
}
|
||||
if let Some(part) = fx.chunk.child_list(b"parT").filter(|p| has_pard(p)) {
|
||||
if let Some(part) = fx.chunk.child_list(b"parT").filter(|p| has_pard(*p)) {
|
||||
instances.insert(fx.match_name, part);
|
||||
}
|
||||
}
|
||||
@@ -363,9 +364,9 @@ impl<'f, 'a> Project<'f, 'a> {
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct EffectDefinitions<'f, 'a> {
|
||||
/// The project-level copies (`EfdG`).
|
||||
by_name: HashMap<String, &'f Chunk<'a>>,
|
||||
by_name: HashMap<String, Node<'f, 'a>>,
|
||||
/// For a type without a project-level copy: the own `parT` of the first instance that has one.
|
||||
instances: HashMap<String, &'f Chunk<'a>>,
|
||||
instances: HashMap<String, Node<'f, 'a>>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> EffectDefinitions<'f, 'a> {
|
||||
@@ -392,7 +393,7 @@ impl<'f, 'a> EffectDefinitions<'f, 'a> {
|
||||
return effect.params();
|
||||
}
|
||||
match self.by_name.get(effect.match_name()).or_else(|| self.instances.get(effect.match_name())) {
|
||||
Some(part) => effect.params_from(part, true),
|
||||
Some(part) => effect.params_from(*part, true),
|
||||
None => Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -638,6 +639,7 @@ impl<'f, 'a> Layer<'f, 'a> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::container::Chunk;
|
||||
|
||||
fn tdmn(name: &str) -> Chunk<'static> {
|
||||
let mut b = name.as_bytes().to_vec();
|
||||
@@ -670,11 +672,11 @@ mod tests {
|
||||
("A".to_string(), Chunk::list(*b"tdbs", vec![Chunk::data(*b"cdat", vec![0u8; 8])])),
|
||||
];
|
||||
let chunk = instance(&names, &stored);
|
||||
let fx = Effect { match_name: "X".into(), chunk: &chunk };
|
||||
let fx = Effect { match_name: "X".into(), chunk: Node::from(&chunk) };
|
||||
let params = fx.params();
|
||||
assert_eq!(params.iter().map(|p| p.match_name.as_str()).collect::<Vec<_>>(), ["A", "B", "C"]);
|
||||
let first = params.first().and_then(|p| p.stored).expect("A stored");
|
||||
assert!(first.chunk.children().is_empty(), "the first A (the second has a cdat)");
|
||||
assert!(first.chunk.children().next().is_none(), "the first A (the second has a cdat)");
|
||||
assert!(params.get(1).is_some_and(|p| p.stored.is_none()), "a group of that name is no stored value");
|
||||
assert!(params.get(2).is_some_and(|p| p.stored.is_none()));
|
||||
}
|
||||
@@ -687,7 +689,7 @@ mod tests {
|
||||
let names: Vec<String> = (0..n).map(|i| format!("P{i}")).collect();
|
||||
let stored: Vec<(String, Chunk<'static>)> = names.iter().map(|m| (m.clone(), tdbs())).collect();
|
||||
let chunk = instance(&names, &stored);
|
||||
let fx = Effect { match_name: "X".into(), chunk: &chunk };
|
||||
let fx = Effect { match_name: "X".into(), chunk: Node::from(&chunk) };
|
||||
let params = fx.params();
|
||||
assert_eq!(params.len(), n);
|
||||
assert!(params.iter().all(|p| p.stored.is_some()));
|
||||
@@ -707,19 +709,19 @@ mod tests {
|
||||
}
|
||||
let efdg = Chunk::list(*b"EfdG", defs);
|
||||
let fold = Chunk::list(*b"Fold", Vec::new());
|
||||
let project = Project { fold: &fold, effect_defs: Some(&efdg) };
|
||||
let project = Project { fold: Node::from(&fold), effect_defs: Some(Node::from(&efdg)) };
|
||||
let all = project.effect_definitions();
|
||||
assert_eq!(all.len(), n);
|
||||
let index = project.effect_definition_index();
|
||||
let bare = Chunk::list(*b"sspc", vec![Chunk::list(*b"parT", Vec::new())]);
|
||||
for i in (0..n).step_by(50) {
|
||||
let fx = Effect { match_name: format!("FX{i}"), chunk: &bare };
|
||||
let fx = Effect { match_name: format!("FX{i}"), chunk: Node::from(&bare) };
|
||||
assert_eq!(index.source(&fx), DefinitionSource::Project);
|
||||
let params = index.params(&fx);
|
||||
assert_eq!(params.iter().map(|p| p.match_name.as_str()).collect::<Vec<_>>(), ["R0"], "the first copy's definitions");
|
||||
assert!(params.iter().all(|p| p.borrowed_definition));
|
||||
}
|
||||
let unknown = Effect { match_name: "nope".into(), chunk: &bare };
|
||||
let unknown = Effect { match_name: "nope".into(), chunk: Node::from(&bare) };
|
||||
assert_eq!(index.source(&unknown), DefinitionSource::Missing);
|
||||
assert!(index.params(&unknown).is_empty());
|
||||
assert_eq!(project.definition_source(&unknown), DefinitionSource::Missing);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Item ids and labels, footage items (solids and files), precomp linkage, and the name and size
|
||||
//! of a layer's source.
|
||||
|
||||
use crate::container::bytes::{be_f32, be_f64, be_u32, cstr, le_u32, text};
|
||||
use crate::container::chunk::Chunk;
|
||||
use crate::container::bytes::{be_f32, be_f64, be_i32, be_u32, cstr, le_u32, text, until_nul};
|
||||
use crate::container::header::Rational;
|
||||
use crate::container::index::Node;
|
||||
use crate::container::typed::{Item, ItemKind, Layer, Project};
|
||||
|
||||
/// The footage data of an item (`LIST Pin ` with `sspc`, `opti` and, for files, `Als2/alas`).
|
||||
@@ -45,24 +45,62 @@ pub struct Footage {
|
||||
/// True when the alias points at a folder (`"target_is_folder":true`): an image sequence is ONE
|
||||
/// item whose alias is its folder and whose `opti` holds the first file name.
|
||||
pub is_sequence: bool,
|
||||
/// The one layer of a Photoshop file the item shows; `None` for the merged image and for
|
||||
/// any other footage.
|
||||
pub psd_layer: Option<PsdLayer>,
|
||||
}
|
||||
|
||||
/// One layer of a Photoshop file shown by a footage item, from its `opti` (tag `8BPS`,
|
||||
/// docs/aep-format.md 3.3): the layer record's index as a big-endian `i32` at byte 14 (-1 for the
|
||||
/// merged image), the document's sides as little-endian `u32` at 32 and 36, its bounds top, left,
|
||||
/// bottom, right as little-endian `i32` at 78, 82, 86 and 90, and its name (UTF-8, NUL
|
||||
/// terminated) from byte 344.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PsdLayer {
|
||||
/// The layer record's position in the file (bottom of the stack = 0).
|
||||
pub index: u32,
|
||||
pub name: String,
|
||||
/// Top, left, bottom, right in document pixels; all 0 for a layer without pixels (an
|
||||
/// adjustment layer).
|
||||
pub bounds: [i32; 4],
|
||||
/// The document's two sides (bytes 32 and 36; which one is the width is not sampled: the one
|
||||
/// file read has a square document). 0 when not stored.
|
||||
pub document: [u32; 2],
|
||||
}
|
||||
|
||||
/// Most bytes of a Photoshop layer name read.
|
||||
const MAX_NAME: usize = 1024;
|
||||
|
||||
impl PsdLayer {
|
||||
/// The bounds' width and height; `None` when they are empty.
|
||||
pub fn size(&self) -> Option<(u32, u32)> {
|
||||
let [top, left, bottom, right] = self.bounds;
|
||||
let w = u32::try_from(i64::from(right) - i64::from(left)).ok().filter(|w| *w > 0)?;
|
||||
let h = u32::try_from(i64::from(bottom) - i64::from(top)).ok().filter(|h| *h > 0)?;
|
||||
Some((w, h))
|
||||
}
|
||||
|
||||
/// Whether the document is `size` big, its sides in either order.
|
||||
pub fn document_is(&self, size: (u32, u32)) -> bool {
|
||||
let [a, b] = self.document;
|
||||
a > 0 && b > 0 && ((a, b) == size || (b, a) == size)
|
||||
}
|
||||
|
||||
/// The layer an `opti` names; `None` for another tag, the merged image or a cut record.
|
||||
fn read(opti: &[u8]) -> Option<Self> {
|
||||
if opti.get(..4) != Some(&b"8BPS"[..]) {
|
||||
return None;
|
||||
}
|
||||
let index = u32::try_from(be_i32(opti, 14)?).ok()?;
|
||||
let le_i32 = |at| le_u32(opti, at).map(|v| i32::from_le_bytes(v.to_le_bytes()));
|
||||
// (After Effects writes 602 bytes; a longer hostile name is cut.)
|
||||
let name = opti.get(344..).map(|b| text(until_nul(b.get(..MAX_NAME).unwrap_or(b)))).unwrap_or_default();
|
||||
let document = [le_u32(opti, 32).unwrap_or(0), le_u32(opti, 36).unwrap_or(0)];
|
||||
Some(Self { index, name, bounds: [le_i32(78)?, le_i32(82)?, le_i32(86)?, le_i32(90)?], document })
|
||||
}
|
||||
}
|
||||
|
||||
impl Footage {
|
||||
/// The number of frames of an image sequence (`duration * native_frame_rate`: 3/30 s at 30 fps is
|
||||
/// 3); `None` for anything else.
|
||||
pub fn sequence_frame_count(&self) -> Option<u32> {
|
||||
if !self.is_sequence {
|
||||
return None;
|
||||
}
|
||||
let d = self.duration?;
|
||||
let frames = i128::from(d.num).checked_mul(i128::from(self.native_frame_rate))?;
|
||||
let den = i128::from(d.den);
|
||||
if den <= 0 || frames % den != 0 {
|
||||
return None;
|
||||
}
|
||||
u32::try_from(frames / den).ok()
|
||||
}
|
||||
|
||||
/// The solid's colour as fractions R, G, B.
|
||||
pub fn solid_rgb(&self) -> Option<[f32; 3]> {
|
||||
let [_, r, g, b] = self.solid_argb?;
|
||||
@@ -216,14 +254,13 @@ impl SequenceInfo {
|
||||
/// is unreadable (empty). A name that is not a plain file name (holding `/`, `\`, `:` or a control
|
||||
/// character such as NUL, or being `.` or `..`) makes the whole list unreadable (empty): the names
|
||||
/// are joined to the folder.
|
||||
fn sequence_file_list(list: &Chunk<'_>) -> Vec<String> {
|
||||
fn sequence_file_list(list: Node<'_, '_>) -> Vec<String> {
|
||||
// After Effects writes the count first (the one sample); a list without a readable count is
|
||||
// not read rather than guessed.
|
||||
let Some(count) = list.child(b"StVS").and_then(|c| c.bytes()).and_then(|b| le_u32(b, 0)).and_then(|n| usize::try_from(n).ok()) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let names: Vec<String> =
|
||||
list.children().iter().filter(|c| c.is(b"Utf8")).filter_map(|c| c.bytes()).take(count).map(text).filter(|n| !n.is_empty()).collect();
|
||||
let names: Vec<String> = list.children().filter(|c| c.is(b"Utf8")).filter_map(Node::bytes).take(count).map(text).filter(|n| !n.is_empty()).collect();
|
||||
if names.iter().any(|n| n.contains(|c: char| matches!(c, '/' | '\\' | ':') || c.is_control()) || n == "." || n == "..") {
|
||||
return Vec::new();
|
||||
}
|
||||
@@ -255,9 +292,8 @@ impl<'f, 'a> Item<'f, 'a> {
|
||||
}
|
||||
let pin = self.chunk.child_list(b"Pin ")?;
|
||||
let sspc = pin.child(b"sspc")?.bytes()?;
|
||||
let kids = pin.children();
|
||||
let after = kids.iter().position(|c| c.is_list(b"Als2"))?;
|
||||
let naming = || kids.iter().skip(after.saturating_add(1)).take_while(|c| !c.is(b"opti"));
|
||||
let after = pin.children().position(|c| c.is_list(b"Als2"))?;
|
||||
let naming = || pin.children().skip(after.saturating_add(1)).take_while(|c| !c.is(b"opti"));
|
||||
let (start, end, digits) = (be_u32(sspc, 172)?, be_u32(sspc, 176)?, be_u32(sspc, 180)?);
|
||||
// Force alphabetical order: the file list replaces the numbering.
|
||||
if let Some(list) = naming().find(|c| c.is_list(b"StVc")) {
|
||||
@@ -267,7 +303,7 @@ impl<'f, 'a> Item<'f, 'a> {
|
||||
}
|
||||
return Some(SequenceInfo { prefix: String::new(), suffix: String::new(), start, end, digits, files });
|
||||
}
|
||||
let names: Vec<String> = naming().filter(|c| c.is(b"Utf8")).filter_map(|c| c.bytes()).map(text).take(2).collect();
|
||||
let names: Vec<String> = naming().filter(|c| c.is(b"Utf8")).filter_map(Node::bytes).map(text).take(2).collect();
|
||||
let (prefix, suffix) = match names.as_slice() {
|
||||
[prefix, suffix] => (prefix.clone(), suffix.clone()),
|
||||
// An empty prefix is not stored (`0001.png` has only `.png`).
|
||||
@@ -297,12 +333,6 @@ impl<'f, 'a> Item<'f, 'a> {
|
||||
self.chunk.child(b"idta")?.bytes()?.get(58).copied()
|
||||
}
|
||||
|
||||
/// The ids of the compositions this item uses as precomp layers: the little-endian `u32` of
|
||||
/// each `idpi` chunk.
|
||||
pub fn used_item_ids(&self) -> Vec<u32> {
|
||||
self.chunk.children().iter().filter(|c| c.is(b"idpi")).filter_map(|c| le_u32(c.bytes()?, 0)).collect()
|
||||
}
|
||||
|
||||
/// The footage data of a footage item.
|
||||
pub fn footage(&self) -> Option<Footage> {
|
||||
if self.kind()? != ItemKind::Footage {
|
||||
@@ -330,6 +360,7 @@ impl<'f, 'a> Item<'f, 'a> {
|
||||
file_size: be_u32(sspc, 208).unwrap_or(0),
|
||||
audio_sample_rate: be_f64(sspc, 160).filter(|r| r.is_finite() && *r > 0.0),
|
||||
is_sequence,
|
||||
psd_layer: PsdLayer::read(opti),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -351,11 +382,6 @@ impl<'f, 'a> Project<'f, 'a> {
|
||||
self.item_by_id(layer.header()?.source_id?)
|
||||
}
|
||||
|
||||
/// The name a layer shows: its own name, or its source's name when it has none.
|
||||
pub fn layer_display_name(&self, layer: &Layer<'f, 'a>) -> Option<String> {
|
||||
layer.name().or_else(|| self.layer_source(layer)?.display_name())
|
||||
}
|
||||
|
||||
/// The pixel size of a layer's source: a footage item's width and height, or a precomp's
|
||||
/// composition size.
|
||||
pub fn layer_source_size(&self, layer: &Layer<'f, 'a>) -> Option<(u32, u32)> {
|
||||
@@ -370,7 +396,46 @@ impl<'f, 'a> Project<'f, 'a> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::json_string;
|
||||
use super::{PsdLayer, json_string};
|
||||
|
||||
/// A 602-byte Photoshop `opti` naming layer `index` with `bounds` and `name`.
|
||||
fn opti(index: i32, bounds: [i32; 4], name: &[u8]) -> Vec<u8> {
|
||||
let mut b = vec![0u8; 602];
|
||||
b[..4].copy_from_slice(b"8BPS");
|
||||
b[14..18].copy_from_slice(&index.to_be_bytes());
|
||||
for (i, v) in bounds.iter().enumerate() {
|
||||
b[78 + 4 * i..82 + 4 * i].copy_from_slice(&v.to_le_bytes());
|
||||
}
|
||||
b[344..344 + name.len()].copy_from_slice(name);
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_photoshop_layer_reads_its_index_bounds_and_name() {
|
||||
let l = PsdLayer::read(&opti(7, [749, 800, 764, 848], "tést".as_bytes())).unwrap();
|
||||
assert_eq!((l.index, l.name.as_str(), l.bounds, l.size()), (7, "tést", [749, 800, 764, 848], Some((48, 15))));
|
||||
// The merged image, another tag, a cut record: no layer.
|
||||
assert_eq!(PsdLayer::read(&opti(-1, [0; 4], b"x")), None);
|
||||
let mut other = opti(1, [0; 4], b"x");
|
||||
other[..4].copy_from_slice(b"Soli");
|
||||
assert_eq!(PsdLayer::read(&other), None);
|
||||
assert_eq!(PsdLayer::read(&opti(1, [0; 4], b"x")[..80]), None);
|
||||
// A cut name, and no name at all.
|
||||
assert_eq!(PsdLayer::read(&opti(1, [0; 4], b"x")[..345]).unwrap().name, "x");
|
||||
assert_eq!(PsdLayer::read(&opti(1, [0; 4], b"x")[..300]).unwrap().name, "");
|
||||
// A layer without pixels has no size; extreme bounds do not overflow.
|
||||
assert_eq!(PsdLayer::read(&opti(2, [0; 4], b"")).unwrap().size(), None);
|
||||
assert_eq!(PsdLayer::read(&opti(2, [i32::MIN, i32::MIN, i32::MAX, i32::MAX], b"")).unwrap().size(), Some((u32::MAX, u32::MAX)));
|
||||
assert_eq!(PsdLayer::read(&opti(2, [i32::MAX, 0, i32::MIN, 1], b"")).unwrap().size(), None);
|
||||
// The document's size, its sides in either order; none when not stored.
|
||||
let mut doc = opti(0, [0, 0, 1000, 800], b"");
|
||||
doc[32..36].copy_from_slice(&800u32.to_le_bytes());
|
||||
doc[36..40].copy_from_slice(&1000u32.to_le_bytes());
|
||||
let l = PsdLayer::read(&doc).unwrap();
|
||||
assert_eq!(l.document, [800, 1000]);
|
||||
assert!(l.document_is((800, 1000)) && l.document_is((1000, 800)) && !l.document_is((800, 800)));
|
||||
assert!(!PsdLayer::read(&opti(0, [0; 4], b"")).unwrap().document_is((0, 0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_a_string_with_escapes() {
|
||||
|
||||
@@ -237,12 +237,6 @@ impl LayerHeader {
|
||||
self.flag_bytes.get(byte).is_some_and(|b| b & mask != 0)
|
||||
}
|
||||
|
||||
/// Byte 37 bit `0x01`: the layer has a name set by the user (clear on a default-named camera or
|
||||
/// light and on a precomp layer, whose name is the source's).
|
||||
pub fn name_is_user_set(&self) -> bool {
|
||||
self.flag(0, 0x01)
|
||||
}
|
||||
|
||||
/// Byte 37 bit `0x02`: guide layer.
|
||||
pub fn is_guide(&self) -> bool {
|
||||
self.flag(0, 0x02)
|
||||
@@ -333,17 +327,6 @@ impl LayerHeader {
|
||||
Rational::new(i64::from(self.stretch), i64::from(self.stretch_den))
|
||||
}
|
||||
|
||||
/// The time stretch in percent (`stretch / stretch_den * 100`); a zero denominator reads as 1.
|
||||
pub fn stretch_percent(&self) -> f64 {
|
||||
let den = if self.stretch_den == 0 { 1.0 } else { f64::from(self.stretch_den) };
|
||||
f64::from(self.stretch) / den * 100.0
|
||||
}
|
||||
|
||||
/// The start time in seconds, `None` for a zero denominator.
|
||||
pub fn start_seconds(&self) -> Option<f64> {
|
||||
self.start.to_f64()
|
||||
}
|
||||
|
||||
/// The absolute in point, `start + in * stretch`, exact and reduced.
|
||||
pub fn in_point(&self) -> Option<Rational> {
|
||||
self.start.plus_scaled(&self.in_relative, &self.stretch_ratio()?)
|
||||
@@ -355,16 +338,6 @@ impl LayerHeader {
|
||||
pub fn out_point(&self) -> Option<Rational> {
|
||||
self.start.plus_scaled(&self.out_relative, &self.stretch_ratio()?)
|
||||
}
|
||||
|
||||
/// The absolute in point in seconds.
|
||||
pub fn in_point_seconds(&self) -> Option<f64> {
|
||||
self.in_point()?.to_f64()
|
||||
}
|
||||
|
||||
/// The absolute out point in seconds.
|
||||
pub fn out_point_seconds(&self) -> Option<f64> {
|
||||
self.out_point()?.to_f64()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'f, 'a> Layer<'f, 'a> {
|
||||
@@ -464,64 +437,10 @@ impl CompHeader {
|
||||
self.time_base.frame_rate()
|
||||
}
|
||||
|
||||
/// The frame rate from the 16.16 fixed-point field (25 is `0x0019_0000`).
|
||||
pub fn frame_rate_from_fixed(&self) -> f64 {
|
||||
f64::from(self.frame_rate_fixed) / 65536.0
|
||||
}
|
||||
|
||||
/// The duration in seconds.
|
||||
pub fn duration_seconds(&self) -> Option<f64> {
|
||||
self.time_base.seconds(i32::try_from(self.duration_units).ok()?)
|
||||
}
|
||||
|
||||
/// The work area start in seconds.
|
||||
pub fn work_area_start_seconds(&self) -> Option<f64> {
|
||||
self.time_base.seconds(i32::try_from(self.work_area_start_units).ok()?)
|
||||
}
|
||||
|
||||
/// The work area end in seconds; the composition duration when the work area is the whole
|
||||
/// composition.
|
||||
pub fn work_area_end_seconds(&self) -> Option<f64> {
|
||||
match self.work_area_end_units {
|
||||
Some(end) => self.time_base.seconds(i32::try_from(end).ok()?),
|
||||
None => self.duration_seconds(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The background colour as fractions 0..1 (`byte / 255`).
|
||||
pub fn background_rgb(&self) -> [f64; 3] {
|
||||
self.background.map(|c| f64::from(c) / 255.0)
|
||||
}
|
||||
|
||||
/// The pixel aspect ratio as a number.
|
||||
pub fn pixel_aspect_ratio(&self) -> Option<f64> {
|
||||
self.pixel_aspect.to_f64()
|
||||
}
|
||||
|
||||
/// The display start time in seconds (the start timecode), `None` when absent or the
|
||||
/// denominator is zero.
|
||||
pub fn display_start_seconds(&self) -> Option<f64> {
|
||||
self.display_start?.to_f64()
|
||||
}
|
||||
|
||||
/// The display start as a frame number (`display start * frame rate`, rounded); 100 at 25 fps
|
||||
/// for a display start of 4 s.
|
||||
pub fn display_start_frame(&self) -> Option<i64> {
|
||||
let rate = self.frame_rate()?;
|
||||
Some((self.display_start_seconds()? * rate).round() as i64)
|
||||
}
|
||||
|
||||
/// The frame rate as an exact fraction `timescale / frame_duration`, as typed: 29.97 fps is
|
||||
/// `23976 / 800` (not `30000 / 1001`), 23.976 fps is `23976 / 1000`.
|
||||
pub fn frame_rate_exact(&self) -> Option<Rational> {
|
||||
Rational::new(i64::from(self.time_base.timescale), i64::from(self.time_base.frame_duration))
|
||||
}
|
||||
|
||||
/// The duration in whole frames (`duration / frame_duration`). After Effects snaps a duration
|
||||
/// to a whole number of frames: 5 s at 29.97 fps becomes 150 frames (5.005 s).
|
||||
pub fn duration_frames(&self) -> Option<u32> {
|
||||
self.duration_units.checked_div(self.time_base.frame_duration)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'f, 'a> Comp<'f, 'a> {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -193,19 +193,10 @@ impl<'f> Keyframe<'f> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The value of a 3-component spatial keyframe (Position), x, y and z in pixels.
|
||||
pub fn spatial_value(&self) -> Option<[f64; 3]> {
|
||||
let v = self.value()?;
|
||||
if !matches!(self.kind(), KeyframeKind::Spatial { components: 3 }) {
|
||||
return None;
|
||||
}
|
||||
Some([*v.first()?, *v.get(1)?, *v.get(2)?])
|
||||
}
|
||||
|
||||
/// The ease of the key: the four slots at byte 16 of a one-component plain record or at byte 24
|
||||
/// of a spatial record or a mask path record. For linear and hold keys all four are 0 (a bezier key stores what
|
||||
/// `setTemporalEase` was given). Plain records with several components keep four slots per
|
||||
/// component, see [`Keyframe::ease_component`] and [`Keyframe::plain_ease_slots`].
|
||||
/// component, see [`Keyframe::ease_component`].
|
||||
pub fn ease(&self) -> Option<KeyEase> {
|
||||
match self.kind() {
|
||||
KeyframeKind::Plain { components: 1 } => ease_at(self.record, 16),
|
||||
@@ -214,16 +205,6 @@ impl<'f> Keyframe<'f> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `4 n` ease `f64` of a plain record as stored (from byte `8 + 8 n`). With one component
|
||||
/// they are [`Keyframe::ease`]; with several they are type-major, see
|
||||
/// [`Keyframe::ease_component`].
|
||||
pub fn plain_ease_slots(&self) -> Option<Vec<f64>> {
|
||||
match self.kind() {
|
||||
KeyframeKind::Plain { components } => doubles(self.record, components.checked_mul(8)?.checked_add(8)?, components.checked_mul(4)?),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The ease of one value component. A plain record with `n` components stores the `4 n` ease
|
||||
/// doubles **type-major**: `[in speed x n][in influence x n][out speed x n][out influence x n]`
|
||||
/// starting at byte `8 + 8 n`, and component `i` uses slot `i` of each block (verified for the
|
||||
@@ -260,16 +241,6 @@ impl<'f> Keyframe<'f> {
|
||||
(0..n).map(|i| self.ease_component(i)).collect()
|
||||
}
|
||||
|
||||
/// The Euclidean ARGB distance to the next key that After Effects writes at byte 16 of a colour
|
||||
/// (4-component spatial) record whose interpolation is not linear: 255 sqrt(2) = 360.6245 for
|
||||
/// red to blue; 0 on the last key and on linear keys. `None` for other records.
|
||||
pub fn color_distance(&self) -> Option<f64> {
|
||||
match self.kind() {
|
||||
KeyframeKind::Spatial { components: 4 } => be_f64(self.record, 16),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The decoded spatial record (Position: 128 bytes, colour: 152 bytes).
|
||||
pub fn spatial(&self) -> Option<SpatialKey> {
|
||||
let KeyframeKind::Spatial { components: n } = self.kind() else { return None };
|
||||
@@ -300,11 +271,6 @@ pub struct ExpressionFlags {
|
||||
}
|
||||
|
||||
impl ExpressionFlags {
|
||||
/// True when bytes 76, 77 and 120 are all 1.
|
||||
pub fn all_set(&self) -> bool {
|
||||
self.byte_76 == 1 && self.byte_77 == 1 && self.byte_120 == 1
|
||||
}
|
||||
|
||||
/// True when byte 119 is 1.
|
||||
pub fn disabled(&self) -> bool {
|
||||
self.byte_119 == 1
|
||||
@@ -324,11 +290,6 @@ impl<'f, 'a> Property<'f, 'a> {
|
||||
be_u32(self.chunk.child(b"tdsb")?.bytes()?, 0)
|
||||
}
|
||||
|
||||
/// True when `tdb4` byte 5 has bit 0 set: the property is static, it has no keyframes.
|
||||
pub fn is_static_flag_set(&self) -> Option<bool> {
|
||||
Some(self.header()?.get(5)? & 1 != 0)
|
||||
}
|
||||
|
||||
/// The expression source: the raw UTF-8 text of the `Utf8` child that follows the value in the
|
||||
/// property (no length prefix, no engine tag; the engine is project-wide).
|
||||
pub fn expression(&self) -> Option<String> {
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
//! property (`tdbs`, with a key list when animated) and `omks` with one `LIST shap` per keyframe (a
|
||||
//! single one when the path is static).
|
||||
|
||||
use crate::container::Chunk;
|
||||
use crate::container::bytes::{be_f32, be_u32, until_nul};
|
||||
use crate::container::typed::{KeyList, Layer, Project, PropGroup, PropNode, Property};
|
||||
use crate::container::index::Node;
|
||||
use crate::container::typed::{KeyList, Layer, PropGroup, PropNode, Property};
|
||||
use crate::container::values::{Tracked, read};
|
||||
|
||||
/// The mask mode (`mkif` `u32` at byte 4).
|
||||
@@ -93,8 +93,10 @@ pub struct ShapePath {
|
||||
}
|
||||
|
||||
impl ShapePath {
|
||||
/// Decodes a `LIST shap`; `None` when `shph` or the point list is malformed.
|
||||
pub fn from_chunk(shap: &Chunk<'_>) -> Option<Self> {
|
||||
/// Decodes a `LIST shap` (a [`Chunk`](crate::container::Chunk) or a [`Node`]); `None` when
|
||||
/// `shph` or the point list is malformed.
|
||||
pub fn from_chunk<'f, 'a: 'f>(shap: impl Into<Node<'f, 'a>>) -> Option<Self> {
|
||||
let shap = shap.into();
|
||||
let shph = shap.child(b"shph")?.bytes()?;
|
||||
let bbox = [be_f32(shph, 4)?, be_f32(shph, 8)?, be_f32(shph, 12)?, be_f32(shph, 16)?];
|
||||
let closed_flag = *shph.get(20)?;
|
||||
@@ -187,22 +189,12 @@ fn mask_from_atom(atom: &PropGroup<'_, '_>, mkif: Option<&[u8]>) -> Mask {
|
||||
}
|
||||
}
|
||||
if let Some(omks) = oms.child_list(b"omks") {
|
||||
mask.shapes = omks.children().iter().filter(|c| c.is_list(b"shap")).filter_map(ShapePath::from_chunk).collect();
|
||||
mask.shapes = omks.children().filter(|c| c.is_list(b"shap")).filter_map(ShapePath::from_chunk).collect();
|
||||
}
|
||||
}
|
||||
mask
|
||||
}
|
||||
|
||||
impl<'f, 'a> Project<'f, 'a> {
|
||||
/// The vertices of every path shape of a mask in pixels of the layer: mask boxes are normalised
|
||||
/// to the **layer** size (the size of its source), not the composition's. `None` when the layer
|
||||
/// has no source with a size.
|
||||
pub fn mask_vertices_px(&self, layer: &Layer<'f, 'a>, mask: &Mask) -> Option<Vec<Vec<PathVertex>>> {
|
||||
let (width, height) = self.layer_source_size(layer)?;
|
||||
Some(mask.shapes.iter().map(|s| s.vertices((f64::from(width), f64::from(height)))).collect())
|
||||
}
|
||||
}
|
||||
|
||||
/// One mask with the views of its records, for readers that need more than [`Mask`]: the
|
||||
/// keyframes and expressions of the mask properties (in [`MaskAtom::atom`]: `ADBE Mask Feather`,
|
||||
/// `ADBE Mask Opacity`, `ADBE Mask Offset`) and the path keyframes paired with their shapes.
|
||||
@@ -246,7 +238,7 @@ impl<'f, 'a> Layer<'f, 'a> {
|
||||
if let Some(PropNode::Other(oms)) = atom.get("ADBE Mask Shape") {
|
||||
path = oms.child_list(b"tdbs").and_then(Property::from_chunk);
|
||||
if let Some(omks) = oms.child_list(b"omks") {
|
||||
path_shapes = omks.children().iter().filter(|c| c.is_list(b"shap")).map(ShapePath::from_chunk).collect();
|
||||
path_shapes = omks.children().filter(|c| c.is_list(b"shap")).map(ShapePath::from_chunk).collect();
|
||||
}
|
||||
}
|
||||
masks.push(MaskAtom { mask, atom, path, path_shapes });
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::container::bytes::{array, be_u32};
|
||||
use crate::container::chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS};
|
||||
use crate::container::error::AepError;
|
||||
|
||||
@@ -36,10 +37,20 @@ pub fn parse(data: &[u8]) -> Result<AepFile<'_>, AepError> {
|
||||
/// # Errors
|
||||
/// See [`parse`]; also fails with [`AepError::TooManyChunks`].
|
||||
pub fn parse_with_limits(data: &[u8], limits: Limits) -> Result<AepFile<'_>, AepError> {
|
||||
let end = container_end(data)?;
|
||||
let mut parser = Parser { data, limits, count: 0 };
|
||||
let chunks = parser.sequence(12, end, 1)?;
|
||||
let trailer = data.get(end..).unwrap_or(&[]);
|
||||
Ok(AepFile { chunks, trailer: Cow::Borrowed(trailer) })
|
||||
}
|
||||
|
||||
/// Checks the `RIFX`/`Egg!` header and returns where the container ends (its chunks fill
|
||||
/// `12..end`; the trailer follows). Shared with [`crate::container::index::TreeIndex::parse`].
|
||||
pub(super) fn container_end(data: &[u8]) -> Result<usize, AepError> {
|
||||
if id4(data, 0) != Some(*b"RIFX") {
|
||||
return Err(AepError::NotRifx);
|
||||
}
|
||||
let declared = u64::from(be32(data, 4).ok_or(AepError::NotRifx)?);
|
||||
let declared = u64::from(be_u32(data, 4).ok_or(AepError::NotRifx)?);
|
||||
let form = id4(data, 8).ok_or(AepError::NotRifx)?;
|
||||
if &form != b"Egg!" {
|
||||
return Err(AepError::BadFormType(form));
|
||||
@@ -49,20 +60,12 @@ pub fn parse_with_limits(data: &[u8], limits: Limits) -> Result<AepFile<'_>, Aep
|
||||
return Err(AepError::Truncated { declared, available });
|
||||
}
|
||||
// `declared <= available < data.len()`, so the end is inside the input.
|
||||
let end = usize::try_from(declared).map_err(|_| AepError::TooLarge)?.checked_add(8).ok_or(AepError::TooLarge)?;
|
||||
let mut parser = Parser { data, limits, count: 0 };
|
||||
let chunks = parser.sequence(12, end, 1)?;
|
||||
let trailer = data.get(end..).unwrap_or(&[]);
|
||||
Ok(AepFile { chunks, trailer: Cow::Borrowed(trailer) })
|
||||
usize::try_from(declared).map_err(|_| AepError::TooLarge)?.checked_add(8).ok_or(AepError::TooLarge)
|
||||
}
|
||||
|
||||
fn be32(data: &[u8], at: usize) -> Option<u32> {
|
||||
id4(data, at).map(u32::from_be_bytes)
|
||||
}
|
||||
|
||||
fn id4(data: &[u8], at: usize) -> Option<[u8; 4]> {
|
||||
let b = data.get(at..at.checked_add(4)?)?;
|
||||
Some([*b.first()?, *b.get(1)?, *b.get(2)?, *b.get(3)?])
|
||||
/// The 4-byte id at `at`, `None` when the input is too short.
|
||||
pub(super) fn id4(data: &[u8], at: usize) -> Option<[u8; 4]> {
|
||||
array::<4>(data, at)
|
||||
}
|
||||
|
||||
struct Parser<'a> {
|
||||
@@ -74,13 +77,16 @@ struct Parser<'a> {
|
||||
impl<'a> Parser<'a> {
|
||||
/// Parses the sibling chunks that exactly fill `start..end`.
|
||||
fn sequence(&mut self, start: usize, end: usize, depth: usize) -> Result<Vec<Chunk<'a>>, AepError> {
|
||||
// Sized once: a well-formed sequence fills exactly this many slots. `try_reserve` so a
|
||||
// limit raised past what the target can allocate fails nothing here (the Vec then grows).
|
||||
let mut out = Vec::new();
|
||||
let _ = out.try_reserve_exact(self.capacity_for(start, end));
|
||||
let mut pos = start;
|
||||
while pos < end {
|
||||
let short = AepError::Malformed { offset: pos, what: "bytes left over that are too short for a chunk header" };
|
||||
let body_start = pos.checked_add(8).filter(|b| *b <= end).ok_or(short)?;
|
||||
let id = id4(self.data, pos).ok_or(AepError::Malformed { offset: pos, what: "short read" })?;
|
||||
let size = be32(self.data, pos + 4).ok_or(AepError::Malformed { offset: pos, what: "short read" })? as usize;
|
||||
let size = be_u32(self.data, pos + 4).ok_or(AepError::Malformed { offset: pos, what: "short read" })? as usize;
|
||||
let avail = end - body_start;
|
||||
if size > avail {
|
||||
return Err(AepError::ChunkTooLarge { offset: pos, size: size as u64, available: avail as u64 });
|
||||
@@ -103,6 +109,26 @@ impl<'a> Parser<'a> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The slots to reserve for the sequence `start..end`: its header count, bounded by the input
|
||||
/// (one per 8 bytes at most) and by the chunks the limit still allows.
|
||||
fn capacity_for(&self, start: usize, end: usize) -> usize {
|
||||
self.count_siblings(start, end).min(self.limits.max_chunks.saturating_sub(self.count))
|
||||
}
|
||||
|
||||
/// The number of chunk headers that tile `start..end` the way [`Self::sequence`] walks them,
|
||||
/// stopping at the first that does not fit. Never more than `(end - start) / 8`.
|
||||
fn count_siblings(&self, start: usize, end: usize) -> usize {
|
||||
let mut n = 0usize;
|
||||
let mut pos = start;
|
||||
while let Some(body_start) = pos.checked_add(8).filter(|b| *b <= end) {
|
||||
let Some(size) = be_u32(self.data, pos.saturating_add(4)) else { break };
|
||||
let Some(next) = usize::try_from(size).ok().and_then(|s| body_start.checked_add(s)).filter(|e| *e <= end) else { break };
|
||||
n = n.saturating_add(1);
|
||||
pos = if size % 2 == 1 && next < end { next.saturating_add(1) } else { next };
|
||||
}
|
||||
n
|
||||
}
|
||||
|
||||
/// Like [`Self::sequence`] but a structural problem yields `None` (the caller keeps bytes).
|
||||
fn tentative(&mut self, start: usize, end: usize, depth: usize) -> Result<Option<Vec<Chunk<'a>>>, AepError> {
|
||||
match self.sequence(start, end, depth) {
|
||||
@@ -140,3 +166,113 @@ impl<'a> Parser<'a> {
|
||||
Ok(Body::Data(Cow::Borrowed(self.slice(start, end))))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Every children `Vec` in the tree, depth first.
|
||||
fn child_vecs<'f, 'a>(chunks: &'f [Chunk<'a>], out: &mut Vec<&'f Vec<Chunk<'a>>>) {
|
||||
for c in chunks {
|
||||
match &c.body {
|
||||
Body::List { children, .. } | Body::Chunks(children) => {
|
||||
out.push(children);
|
||||
child_vecs(children, out);
|
||||
}
|
||||
Body::Data(_) | Body::OpaqueList { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Every sibling list is allocated once at its exact length.
|
||||
#[test]
|
||||
fn every_sibling_list_is_allocated_once_at_its_exact_length() {
|
||||
let inner: Vec<Chunk<'static>> = (0..37u8).map(|i| Chunk::data(*b"cdat", vec![i; usize::from(i % 5)])).collect();
|
||||
let middle: Vec<Chunk<'static>> = (0..9).map(|_| Chunk::list(*b"tdbs", inner.clone())).collect();
|
||||
let file = AepFile { chunks: vec![Chunk::data(*b"head", vec![0; 3]), Chunk::list(*b"Fold", middle)], trailer: Cow::Borrowed(&[]) };
|
||||
let bytes = crate::container::write(&file).expect("write");
|
||||
let parsed = parse(&bytes).expect("parse");
|
||||
assert_eq!(crate::container::write(&parsed).expect("rewrite"), bytes);
|
||||
let mut vecs = vec![&parsed.chunks];
|
||||
child_vecs(&parsed.chunks, &mut vecs);
|
||||
assert_eq!(vecs.len(), 11);
|
||||
// `try_reserve_exact` gives exactly the requested capacity with std's allocator today; a
|
||||
// Vec grown push by push would have rounded up to a power of two (37 -> 64, 9 -> 16).
|
||||
for v in vecs {
|
||||
assert_eq!(v.capacity(), v.len(), "a sibling Vec grew past its length");
|
||||
}
|
||||
}
|
||||
|
||||
/// The preallocation is bounded by the input and the chunk limit.
|
||||
#[test]
|
||||
fn the_preallocation_is_bounded_by_the_input_and_the_chunk_limit() {
|
||||
// 1000 empty headers: the most chunks the bytes can hold.
|
||||
let mut data = b"RIFX\0\0\0\0Egg!".to_vec();
|
||||
data.extend(std::iter::repeat_n(*b"abcd\0\0\0\0", 1000).flatten());
|
||||
let declared = u32::try_from(data.len() - 8).expect("small");
|
||||
data[4..8].copy_from_slice(&declared.to_be_bytes());
|
||||
let parser = Parser { data: &data, limits: Limits::default(), count: 0 };
|
||||
assert_eq!(parser.count_siblings(12, data.len()), 1000);
|
||||
assert!(parser.count_siblings(12, data.len()) <= (data.len() - 12) / 8);
|
||||
// A header whose size runs past the end stops the count; a stray tail is not counted.
|
||||
assert_eq!(parser.count_siblings(12, data.len() - 3), 999);
|
||||
let mut big = data.clone();
|
||||
big[16..20].copy_from_slice(&u32::MAX.to_be_bytes());
|
||||
let parser = Parser { data: &big, limits: Limits::default(), count: 0 };
|
||||
assert_eq!(parser.count_siblings(12, big.len()), 0);
|
||||
let f = parse(&data).expect("parse");
|
||||
assert_eq!((f.chunks.len(), f.chunks.capacity()), (1000, 1000));
|
||||
// Under a tighter limit the parse fails as before, without sizing for more than allowed.
|
||||
let tight = Limits { max_depth: 64, max_chunks: 10 };
|
||||
assert_eq!(parse_with_limits(&data, tight), Err(AepError::TooManyChunks));
|
||||
// The reservation never exceeds what the chunk limit still allows.
|
||||
let mut parser = Parser { data: &data, limits: tight, count: 0 };
|
||||
assert_eq!(parser.capacity_for(12, data.len()), 10);
|
||||
parser.count = 7;
|
||||
assert_eq!(parser.capacity_for(12, data.len()), 3);
|
||||
parser.count = 11;
|
||||
assert_eq!(parser.capacity_for(12, data.len()), 0);
|
||||
let parser = Parser { data: &data, limits: Limits::default(), count: 0 };
|
||||
assert_eq!(parser.capacity_for(12, data.len()), 1000);
|
||||
}
|
||||
|
||||
/// `LIST Fold` around `inner`, followed by 6 bytes too short for a header, so the list's
|
||||
/// sequence fails and the list is kept opaque.
|
||||
fn broken_level(inner: &[u8]) -> Vec<u8> {
|
||||
let mut body = b"Fold".to_vec();
|
||||
body.extend_from_slice(inner);
|
||||
body.extend_from_slice(&[0xee; 6]);
|
||||
let mut out = b"LIST".to_vec();
|
||||
out.extend_from_slice(&u32::try_from(body.len()).expect("small").to_be_bytes());
|
||||
out.extend_from_slice(&body);
|
||||
out
|
||||
}
|
||||
|
||||
/// Nested lists with broken tails parse each header once.
|
||||
#[test]
|
||||
fn nested_lists_with_broken_tails_parse_each_header_once() {
|
||||
// A wide, well-formed list at the bottom, then 50 levels that each fail and fall back to
|
||||
// opaque: every level re-parses its child before giving up.
|
||||
let mut wide = b"Fold".to_vec();
|
||||
wide.extend(std::iter::repeat_n(*b"abcd\0\0\0\0", 1000).flatten());
|
||||
let mut level = b"LIST".to_vec();
|
||||
level.extend_from_slice(&u32::try_from(wide.len()).expect("small").to_be_bytes());
|
||||
level.extend_from_slice(&wide);
|
||||
for _ in 0..50 {
|
||||
level = broken_level(&level);
|
||||
}
|
||||
let mut data = b"RIFX\0\0\0\0Egg!".to_vec();
|
||||
data.extend_from_slice(&level);
|
||||
let declared = u32::try_from(data.len() - 8).expect("small");
|
||||
data[4..8].copy_from_slice(&declared.to_be_bytes());
|
||||
// 1 + 50 + 1000 headers in the file: the parse counts each exactly once (the count spans
|
||||
// every attempt), so the work stays linear in the input.
|
||||
let headers = 1 + 50 + 1000;
|
||||
let f = parse_with_limits(&data, Limits { max_depth: 64, max_chunks: headers }).expect("parse");
|
||||
assert_eq!(parse_with_limits(&data, Limits { max_depth: 64, max_chunks: headers - 1 }), Err(AepError::TooManyChunks));
|
||||
// The outermost list keeps its bytes, and the file writes back unchanged.
|
||||
let [top] = f.chunks.as_slice() else { panic!("one top-level chunk") };
|
||||
assert!(matches!(&top.body, Body::OpaqueList { list_type, data } if list_type == b"Fold" && data.len() + 12 == level.len()));
|
||||
assert_eq!(crate::container::write(&f).expect("write"), data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
//! linear-light switches, the time display and the frame count start. Cases 620-634: one change
|
||||
//! each against the base project 620; every field below is the only byte (or chunk) that changes.
|
||||
|
||||
use crate::container::bytes::be_u32;
|
||||
use crate::container::chunk::AepFile;
|
||||
use crate::container::footage::json_string;
|
||||
use crate::container::index::{Node, Root, TreeIndex};
|
||||
|
||||
/// The time display style (`nhed` byte 8, feet + frames byte 11, film type byte 13).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -54,7 +56,17 @@ pub struct ProjectSettings {
|
||||
impl ProjectSettings {
|
||||
/// Reads the settings from the top-level chunks.
|
||||
pub fn read(file: &AepFile<'_>) -> ProjectSettings {
|
||||
let nhed = file.chunk(b"nhed").and_then(|c| c.bytes());
|
||||
Self::of(Root::from(file))
|
||||
}
|
||||
|
||||
/// Reads the settings from the top-level chunks of an indexed file.
|
||||
pub fn read_index(index: &TreeIndex<'_>) -> ProjectSettings {
|
||||
Self::of(Root::from(index))
|
||||
}
|
||||
|
||||
/// Reads the settings from the top-level chunks of either tree.
|
||||
pub(crate) fn of(file: Root<'_, '_>) -> ProjectSettings {
|
||||
let nhed = file.chunk(b"nhed").and_then(Node::bytes);
|
||||
let byte = |i: usize| nhed.and_then(|b| b.get(i).copied());
|
||||
let bits_per_channel = byte(15).and_then(|v| match v {
|
||||
0 => Some(8),
|
||||
@@ -73,9 +85,9 @@ impl ProjectSettings {
|
||||
1 => Some(1),
|
||||
_ => None,
|
||||
});
|
||||
let flag = |id: &[u8; 4]| file.chunk(id).and_then(|c| c.bytes()).and_then(|b| b.first().copied()) == Some(1);
|
||||
let working_gamma_24 = file.chunk(b"dwga").and_then(|c| c.bytes()).and_then(|b| b.get(..4)).map(|b| b != [0, 0, 0, 0]);
|
||||
let scene_compensation = file.chunk(b"acer").and_then(|c| c.bytes()).and_then(|b| b.first().copied()).map(|v| v != 0);
|
||||
let flag = |id: &[u8; 4]| file.chunk(id).and_then(Node::bytes).and_then(|b| b.first().copied()) == Some(1);
|
||||
let working_gamma_24 = file.chunk(b"dwga").and_then(Node::bytes).and_then(|b| b.get(..4)).map(|b| b != [0, 0, 0, 0]);
|
||||
let scene_compensation = file.chunk(b"acer").and_then(Node::bytes).and_then(|b| b.first().copied()).map(|v| v != 0);
|
||||
ProjectSettings {
|
||||
bits_per_channel,
|
||||
working_space: working_space(file),
|
||||
@@ -90,9 +102,10 @@ impl ProjectSettings {
|
||||
}
|
||||
|
||||
/// The working space: the `Utf8` right after `PwCs`.
|
||||
fn working_space(file: &AepFile<'_>) -> Option<WorkingSpace> {
|
||||
let at = file.chunks.iter().position(|c| c.is(b"PwCs"))?;
|
||||
let json = file.chunks.get(at.checked_add(1)?).filter(|c| c.is(b"Utf8"))?.bytes()?;
|
||||
fn working_space(file: Root<'_, '_>) -> Option<WorkingSpace> {
|
||||
let mut chunks = file.chunks();
|
||||
chunks.find(|c| c.is(b"PwCs"))?;
|
||||
let json = chunks.next().filter(|c| c.is(b"Utf8"))?.bytes()?;
|
||||
let trimmed: Vec<u8> = json.iter().copied().filter(|b| !b.is_ascii_whitespace() && *b != 0).collect();
|
||||
if trimmed == b"{}" {
|
||||
return Some(WorkingSpace::None);
|
||||
@@ -130,7 +143,7 @@ fn base64_decode(text: &str) -> Option<Vec<u8>> {
|
||||
/// The profile description (ICC.1 tag `desc`): a v2 `desc` (ASCII) or a v4 `mluc` (its first
|
||||
/// record, UTF-16BE). `None` when the profile or the tag is cut short.
|
||||
fn icc_description(icc: &[u8]) -> Option<String> {
|
||||
let be32 = |at: usize| icc.get(at..at.checked_add(4)?).and_then(|b| b.try_into().ok()).map(u32::from_be_bytes);
|
||||
let be32 = |at: usize| be_u32(icc, at);
|
||||
let count = be32(128)?;
|
||||
let tag = (0..count.min(1024)).find_map(|i| {
|
||||
let at = 132usize.checked_add(usize::try_from(i).ok()?.checked_mul(12)?)?;
|
||||
@@ -141,13 +154,13 @@ fn icc_description(icc: &[u8]) -> Option<String> {
|
||||
let body = icc.get(off..off.checked_add(len)?)?;
|
||||
let text = match body.get(..4)? {
|
||||
b"desc" => {
|
||||
let n = usize::try_from(u32::from_be_bytes(body.get(8..12)?.try_into().ok()?)).ok()?;
|
||||
let n = usize::try_from(be_u32(body, 8)?).ok()?;
|
||||
let ascii = body.get(12..12usize.checked_add(n)?)?;
|
||||
String::from_utf8_lossy(ascii.split(|b| *b == 0).next().unwrap_or_default()).into_owned()
|
||||
}
|
||||
b"mluc" => {
|
||||
let n = usize::try_from(u32::from_be_bytes(body.get(20..24)?.try_into().ok()?)).ok()?;
|
||||
let at = usize::try_from(u32::from_be_bytes(body.get(24..28)?.try_into().ok()?)).ok()?;
|
||||
let n = usize::try_from(be_u32(body, 20)?).ok()?;
|
||||
let at = usize::try_from(be_u32(body, 24)?).ok()?;
|
||||
let units: Vec<u16> = body.get(at..at.checked_add(n)?)?.as_chunks::<2>().0.iter().map(|p| u16::from_be_bytes(*p)).collect();
|
||||
String::from_utf16_lossy(&units)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//! points are in pixels relative to the layer origin.
|
||||
|
||||
use crate::container::masks::ShapePath;
|
||||
use crate::container::typed::{Layer, PropGroup, PropNode, Property};
|
||||
use crate::container::typed::{Layer, PropGroup, PropNode};
|
||||
use crate::container::values::{Tracked, read, read_opt};
|
||||
|
||||
/// The stroke line cap (`ADBE Vector Stroke Line Cap`, stored as a double; butt is the default and
|
||||
@@ -140,7 +140,7 @@ fn number(group: &PropGroup<'_, '_>, name: &str) -> Option<Tracked<f64>> {
|
||||
fn paths_of(group: &PropGroup<'_, '_>) -> Vec<ShapePath> {
|
||||
let Some(PropNode::Other(oms)) = group.get("ADBE Vector Shape") else { return Vec::new() };
|
||||
let Some(omks) = oms.child_list(b"omks") else { return Vec::new() };
|
||||
omks.children().iter().filter(|c| c.is_list(b"shap")).filter_map(ShapePath::from_chunk).collect()
|
||||
omks.children().filter(|c| c.is_list(b"shap")).filter_map(ShapePath::from_chunk).collect()
|
||||
}
|
||||
|
||||
fn item(match_name: String, group: &PropGroup<'_, '_>) -> ShapeItem {
|
||||
@@ -262,12 +262,3 @@ impl<'f, 'a> Layer<'f, 'a> {
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'f, 'a> Property<'f, 'a> {
|
||||
/// The ARGB fractions of a static colour property (4 components stored as doubles 0..255).
|
||||
pub fn color_argb(&self) -> Option<[f64; 4]> {
|
||||
let v = self.static_value()?;
|
||||
let [a, r, g, b] = *v.as_slice().first_chunk::<4>()?;
|
||||
Some([a / 255.0, r / 255.0, g / 255.0, b / 255.0])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +73,6 @@ pub struct StyleMap {
|
||||
}
|
||||
|
||||
impl StyleMap {
|
||||
/// The switch group's match name (`dropShadow/enabled`).
|
||||
pub fn switch_name(&self) -> String {
|
||||
format!("{}/enabled", self.ae)
|
||||
}
|
||||
/// A parameter's full match name (`dropShadow/opacity`).
|
||||
pub fn param_name(&self, p: &StyleParam) -> String {
|
||||
format!("{}/{}", self.ae, p.ae)
|
||||
|
||||
+927
-143
File diff suppressed because it is too large
Load Diff
@@ -4,42 +4,57 @@
|
||||
//!
|
||||
//! Only facts that were established from our own one-change-per-file corpus and are checked by
|
||||
//! tests against it are decoded (see `docs/aep-format.md` for the evidence). Everything else
|
||||
//! stays reachable through the raw [`Chunk`] tree. Views borrow the file and never fail loudly:
|
||||
//! a chunk that does not have the expected shape yields `None` or is skipped.
|
||||
//! stays reachable through the raw chunk tree ([`Node`]). Views borrow the file and never fail
|
||||
//! loudly: a chunk that does not have the expected shape yields `None` or is skipped.
|
||||
//!
|
||||
//! A view reads either tree: the owned [`Chunk`](crate::container::Chunk) tree
|
||||
//! ([`Project::new`]) or the flat [`TreeIndex`] the importer builds ([`Project::from_index`]);
|
||||
//! both give the same answers.
|
||||
|
||||
use crate::container::bytes::{be_f64, be_u16, be_u32, text, until_nul};
|
||||
use crate::container::chunk::{AepFile, Chunk};
|
||||
use crate::container::chunk::AepFile;
|
||||
use crate::container::index::{Node, Root, TreeIndex};
|
||||
|
||||
/// The name a user gave a property or group: the `Utf8` inside its `tdsn` chunk. `None` for the
|
||||
/// sentinel `-_0_/-` ("no custom name") and for empty names.
|
||||
pub(crate) fn user_name(chunk: &Chunk<'_>) -> Option<String> {
|
||||
let name = chunk.child(b"tdsn")?.children().iter().find(|c| c.is(b"Utf8"))?.bytes().map(text)?;
|
||||
pub(crate) fn user_name(chunk: Node<'_, '_>) -> Option<String> {
|
||||
let name = chunk.child(b"tdsn")?.child(b"Utf8")?.bytes().map(text)?;
|
||||
(!name.is_empty() && name != "-_0_/-").then_some(name)
|
||||
}
|
||||
|
||||
/// The content of a `Utf8` child as text (not trimmed).
|
||||
pub(crate) fn utf8_child(chunk: &Chunk<'_>) -> Option<String> {
|
||||
chunk.child(b"Utf8").and_then(Chunk::bytes).map(text)
|
||||
pub(crate) fn utf8_child(chunk: Node<'_, '_>) -> Option<String> {
|
||||
chunk.child(b"Utf8").and_then(Node::bytes).map(text)
|
||||
}
|
||||
|
||||
/// The project: the top-level `LIST Fold`, which holds the project items.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Project<'f, 'a> {
|
||||
pub(crate) fold: &'f Chunk<'a>,
|
||||
pub(crate) fold: Node<'f, 'a>,
|
||||
/// The top-level `LIST EfdG` (project-level effect definitions), when there is one.
|
||||
pub(crate) effect_defs: Option<&'f Chunk<'a>>,
|
||||
pub(crate) effect_defs: Option<Node<'f, 'a>>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> Project<'f, 'a> {
|
||||
/// The project view of a file, or `None` when it has no `LIST Fold`.
|
||||
pub fn new(file: &'f AepFile<'a>) -> Option<Self> {
|
||||
file.list(b"Fold").map(|fold| Self { fold, effect_defs: file.list(b"EfdG") })
|
||||
Self::of(Root::from(file))
|
||||
}
|
||||
|
||||
/// The project view of an indexed file ([`TreeIndex`]), or `None` when it has no `LIST Fold`.
|
||||
pub fn from_index(index: &'f TreeIndex<'a>) -> Option<Self> {
|
||||
Self::of(Root::from(index))
|
||||
}
|
||||
|
||||
/// The project view of either tree: its `LIST Fold` and `LIST EfdG`.
|
||||
pub(crate) fn of(root: Root<'f, 'a>) -> Option<Self> {
|
||||
root.list(b"Fold").map(|fold| Self { fold, effect_defs: root.list(b"EfdG") })
|
||||
}
|
||||
|
||||
/// The top-level items (the project panel's root; folders hold their children, see
|
||||
/// [`Item::children`]).
|
||||
pub fn items(&self) -> impl Iterator<Item = Item<'f, 'a>> + 'f {
|
||||
self.fold.children().iter().filter(|c| c.is_list(b"Item")).map(|chunk| Item { chunk })
|
||||
self.fold.children().filter(|c| c.is_list(b"Item")).map(|chunk| Item { chunk })
|
||||
}
|
||||
|
||||
/// True when the `LIST Fold` could not be read as chunks (damaged): its items cannot be seen.
|
||||
@@ -78,12 +93,12 @@ pub enum ItemKind {
|
||||
/// A project item (`LIST Item`).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Item<'f, 'a> {
|
||||
pub(crate) chunk: &'f Chunk<'a>,
|
||||
pub(crate) chunk: Node<'f, 'a>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> Item<'f, 'a> {
|
||||
/// The underlying chunk.
|
||||
pub fn chunk(&self) -> &'f Chunk<'a> {
|
||||
pub fn chunk(&self) -> Node<'f, 'a> {
|
||||
self.chunk
|
||||
}
|
||||
|
||||
@@ -106,7 +121,7 @@ impl<'f, 'a> Item<'f, 'a> {
|
||||
|
||||
/// The items inside a folder (`LIST Sfdr`).
|
||||
pub fn children(&self) -> impl Iterator<Item = Item<'f, 'a>> + 'f {
|
||||
self.chunk.child_list(b"Sfdr").into_iter().flat_map(|sfdr| sfdr.children().iter()).filter(|c| c.is_list(b"Item")).map(|chunk| Item { chunk })
|
||||
self.chunk.child_list(b"Sfdr").into_iter().flat_map(Node::children).filter(|c| c.is_list(b"Item")).map(|chunk| Item { chunk })
|
||||
}
|
||||
|
||||
/// Whether the item has the `LIST Sfdr` of a folder's contents (After Effects writes an empty
|
||||
@@ -117,7 +132,7 @@ impl<'f, 'a> Item<'f, 'a> {
|
||||
|
||||
/// True when the folder's `LIST Sfdr` is there but could not be read as chunks (damaged).
|
||||
pub fn folder_contents_unreadable(&self) -> bool {
|
||||
self.chunk.child_list(b"Sfdr").is_some_and(Chunk::is_opaque_list)
|
||||
self.chunk.child_list(b"Sfdr").is_some_and(Node::is_opaque_list)
|
||||
}
|
||||
|
||||
/// The composition view when this item has composition data (`cdta`).
|
||||
@@ -135,6 +150,15 @@ pub struct TimeBase {
|
||||
}
|
||||
|
||||
impl TimeBase {
|
||||
/// The NTSC rates and the value After Effects stores for each (a float32 of exactly these
|
||||
/// decimals): the one table the importer and the exporter use.
|
||||
pub(crate) const NTSC: [(effectcraft_time::FrameRate, f32); 4] = [
|
||||
(effectcraft_time::FrameRate::FPS_23_976, 23.976),
|
||||
(effectcraft_time::FrameRate::FPS_29_97, 29.97),
|
||||
(effectcraft_time::FrameRate::FPS_59_94, 59.94),
|
||||
(effectcraft_time::FrameRate::FPS_119_88, 119.88),
|
||||
];
|
||||
|
||||
/// Frames per second (`timescale / frame_duration`), `None` for a zero duration.
|
||||
pub fn frame_rate(&self) -> Option<f64> {
|
||||
(self.frame_duration != 0).then(|| f64::from(self.timescale) / f64::from(self.frame_duration))
|
||||
@@ -149,7 +173,7 @@ impl TimeBase {
|
||||
/// A composition item (an [`Item`] with `cdta`).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Comp<'f, 'a> {
|
||||
pub(crate) item: &'f Chunk<'a>,
|
||||
pub(crate) item: Node<'f, 'a>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> Comp<'f, 'a> {
|
||||
@@ -163,19 +187,19 @@ impl<'f, 'a> Comp<'f, 'a> {
|
||||
/// The layers, top layer first (`LIST Layr`; the `DLay`/`SLay`/`CLay`/`SecL` lists next to
|
||||
/// them are not layers).
|
||||
pub fn layers(&self) -> impl Iterator<Item = Layer<'f, 'a>> + 'f {
|
||||
self.item.children().iter().filter(|c| c.is_list(b"Layr")).map(|chunk| Layer { chunk })
|
||||
self.item.children().filter(|c| c.is_list(b"Layr")).map(|chunk| Layer { chunk })
|
||||
}
|
||||
}
|
||||
|
||||
/// A layer (`LIST Layr`).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Layer<'f, 'a> {
|
||||
pub(crate) chunk: &'f Chunk<'a>,
|
||||
pub(crate) chunk: Node<'f, 'a>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> Layer<'f, 'a> {
|
||||
/// The underlying chunk.
|
||||
pub fn chunk(&self) -> &'f Chunk<'a> {
|
||||
pub fn chunk(&self) -> Node<'f, 'a> {
|
||||
self.chunk
|
||||
}
|
||||
|
||||
@@ -205,12 +229,12 @@ pub enum PropNode<'f, 'a> {
|
||||
/// A property (`LIST tdbs`).
|
||||
Property(Property<'f, 'a>),
|
||||
/// Any other list that follows a match name (observed: `otst`, the effect instance `sspc`).
|
||||
Other(&'f Chunk<'a>),
|
||||
Other(Node<'f, 'a>),
|
||||
}
|
||||
|
||||
impl<'f, 'a> PropNode<'f, 'a> {
|
||||
/// The node a `LIST` after a match name is.
|
||||
fn of(c: &'f Chunk<'a>) -> Self {
|
||||
fn of(c: Node<'f, 'a>) -> Self {
|
||||
if c.is_list(b"tdgp") {
|
||||
PropNode::Group(PropGroup { chunk: c })
|
||||
} else if c.is_list(b"tdbs") {
|
||||
@@ -233,17 +257,18 @@ pub struct PropEntry<'f, 'a> {
|
||||
/// `ADBE Group End` closes the group and names nothing.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PropGroup<'f, 'a> {
|
||||
pub(crate) chunk: &'f Chunk<'a>,
|
||||
pub(crate) chunk: Node<'f, 'a>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> PropGroup<'f, 'a> {
|
||||
/// A group view of a `LIST tdgp` chunk.
|
||||
pub fn from_chunk(chunk: &'f Chunk<'a>) -> Option<Self> {
|
||||
/// A group view of a `LIST tdgp` chunk (a [`Chunk`](crate::container::Chunk) or a [`Node`]).
|
||||
pub fn from_chunk(chunk: impl Into<Node<'f, 'a>>) -> Option<Self> {
|
||||
let chunk = chunk.into();
|
||||
chunk.is_list(b"tdgp").then_some(Self { chunk })
|
||||
}
|
||||
|
||||
/// The underlying chunk.
|
||||
pub fn chunk(&self) -> &'f Chunk<'a> {
|
||||
pub fn chunk(&self) -> Node<'f, 'a> {
|
||||
self.chunk
|
||||
}
|
||||
|
||||
@@ -264,7 +289,7 @@ impl<'f, 'a> PropGroup<'f, 'a> {
|
||||
for c in self.chunk.children() {
|
||||
if c.is(b"tdmn") {
|
||||
pending = c.bytes().map(match_name);
|
||||
} else if c.id == crate::container::chunk::LIST
|
||||
} else if c.is(&crate::container::chunk::LIST)
|
||||
&& let Some(name) = pending.take()
|
||||
{
|
||||
out.push(PropEntry { match_name: name, node: PropNode::of(c) });
|
||||
@@ -285,9 +310,9 @@ impl<'f, 'a> PropGroup<'f, 'a> {
|
||||
for c in self.chunk.children() {
|
||||
if c.is(b"tdmn") {
|
||||
pending = c.bytes();
|
||||
} else if c.id == crate::container::chunk::LIST
|
||||
} else if c.is(&crate::container::chunk::LIST)
|
||||
&& let Some(body) = pending.take()
|
||||
&& match_name(body) == name
|
||||
&& match_name_is(body, name)
|
||||
{
|
||||
return Some(PropNode::of(c));
|
||||
}
|
||||
@@ -314,21 +339,30 @@ fn match_name(body: &[u8]) -> String {
|
||||
text(until_nul(body))
|
||||
}
|
||||
|
||||
/// `match_name(body) == name` without building the `String`: equal bytes match; otherwise only
|
||||
/// a body that is not valid UTF-8 can still match (through its U+FFFD replacements), and only a
|
||||
/// name that holds U+FFFD.
|
||||
fn match_name_is(body: &[u8], name: &str) -> bool {
|
||||
let bytes = until_nul(body);
|
||||
bytes == name.as_bytes() || (name.contains('\u{FFFD}') && String::from_utf8_lossy(bytes) == name)
|
||||
}
|
||||
|
||||
/// A property (`LIST tdbs`): `tdsb`, `tdsn`, the 124-byte header `tdb4`, then either the static
|
||||
/// value `cdat` or a keyframe `LIST list`.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Property<'f, 'a> {
|
||||
pub(crate) chunk: &'f Chunk<'a>,
|
||||
pub(crate) chunk: Node<'f, 'a>,
|
||||
}
|
||||
|
||||
impl<'f, 'a> Property<'f, 'a> {
|
||||
/// A property view of a `LIST tdbs` chunk.
|
||||
pub fn from_chunk(chunk: &'f Chunk<'a>) -> Option<Self> {
|
||||
/// A property view of a `LIST tdbs` chunk (a [`Chunk`](crate::container::Chunk) or a [`Node`]).
|
||||
pub fn from_chunk(chunk: impl Into<Node<'f, 'a>>) -> Option<Self> {
|
||||
let chunk = chunk.into();
|
||||
chunk.is_list(b"tdbs").then_some(Self { chunk })
|
||||
}
|
||||
|
||||
/// The underlying chunk.
|
||||
pub fn chunk(&self) -> &'f Chunk<'a> {
|
||||
pub fn chunk(&self) -> Node<'f, 'a> {
|
||||
self.chunk
|
||||
}
|
||||
|
||||
@@ -436,12 +470,13 @@ pub struct KeyLayout {
|
||||
impl<'f> KeyList<'f> {
|
||||
/// A view of a `LIST list` chunk. `None` when `lhd3` is not 52 bytes or `ldat` is not exactly
|
||||
/// `count * record_size` bytes (a list without `ldat` must have no records).
|
||||
pub fn from_chunk<'a>(chunk: &'f Chunk<'a>) -> Option<Self> {
|
||||
pub fn from_chunk<'a: 'f>(chunk: impl Into<Node<'f, 'a>>) -> Option<Self> {
|
||||
let chunk = chunk.into();
|
||||
if !chunk.is_list(b"list") {
|
||||
return None;
|
||||
}
|
||||
let header = ListHeader::parse(chunk.child(b"lhd3")?.bytes()?)?;
|
||||
let ldat: &[u8] = chunk.child(b"ldat").and_then(Chunk::bytes).unwrap_or(&[]);
|
||||
let ldat: &[u8] = chunk.child(b"ldat").and_then(Node::bytes).unwrap_or(&[]);
|
||||
let expected = usize::try_from(header.count).ok()?.checked_mul(usize::try_from(header.record_size).ok()?)?;
|
||||
(ldat.len() == expected).then_some(Self { header, ldat, layout: None })
|
||||
}
|
||||
@@ -500,6 +535,7 @@ impl<'f> Keyframe<'f> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::container::Chunk;
|
||||
|
||||
fn key_list(count: u32, record_size: u32, ldat: &[u8]) -> Chunk<'static> {
|
||||
let mut lhd3 = vec![0u8; 52];
|
||||
@@ -536,4 +572,22 @@ mod tests {
|
||||
assert!(g.get("C").is_none());
|
||||
assert_eq!(g.names(), ["A", "B", "A"]);
|
||||
}
|
||||
|
||||
/// Match name is agrees with comparing the decoded name.
|
||||
#[test]
|
||||
fn match_name_is_agrees_with_comparing_the_decoded_name() {
|
||||
let bodies: [&[u8]; 9] =
|
||||
[b"ADBE Position\0\0\0", b"ADBE Position", b"ADBE Pos", b"", b"\0ADBE", b"ADBE \xff Bad\0", b"\xff", b"\xef\xbf\xbd", "Gr\u{fc}n\0".as_bytes()];
|
||||
let names = ["ADBE Position", "ADBE Pos", "", "ADBE \u{FFFD} Bad", "\u{FFFD}", "Gr\u{fc}n", "ADBE Position\0", "ADBE \u{FFFD}"];
|
||||
for body in bodies {
|
||||
for name in names {
|
||||
assert_eq!(match_name_is(body, name), match_name(body) == name, "{body:?} vs {name:?}");
|
||||
}
|
||||
}
|
||||
// Names read back from a group find their entries, a damaged one included.
|
||||
let group = Chunk::list(*b"tdgp", vec![Chunk::data(*b"tdmn", b"X\xffY\0".to_vec()), Chunk::list(*b"tdbs", Vec::new())]);
|
||||
let g = PropGroup::from_chunk(&group).expect("group");
|
||||
let names = g.names();
|
||||
assert!(g.get(&names[0]).is_some());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
//! 100 %. These defaults are verified for AV layers (solids); cameras and lights use other
|
||||
//! conventions (see the `camera` module).
|
||||
|
||||
use crate::container::bytes::be_f64;
|
||||
use crate::container::typed::{Layer, Project, PropGroup, PropNode};
|
||||
|
||||
/// Where a [`Tracked`] value came from.
|
||||
@@ -192,8 +193,7 @@ impl<'f, 'a> Layer<'f, 'a> {
|
||||
let otda = otst.child_list(b"otky")?.child(b"otda")?.bytes()?;
|
||||
let mut degrees = [0.0; 3];
|
||||
for (i, slot) in degrees.iter_mut().enumerate() {
|
||||
let b = otda.get(i * 8..i * 8 + 8)?;
|
||||
*slot = f64::from_be_bytes(b.try_into().ok()?);
|
||||
*slot = be_f64(otda, i * 8)?;
|
||||
}
|
||||
Some(Orientation {
|
||||
degrees,
|
||||
@@ -223,12 +223,10 @@ impl<'f, 'a> Layer<'f, 'a> {
|
||||
.child_list(b"otky")
|
||||
.map(|k| {
|
||||
k.children()
|
||||
.iter()
|
||||
.filter(|c| c.is(b"otda"))
|
||||
.map(|c| {
|
||||
let b = c.bytes()?;
|
||||
let at = |i: usize| b.get(i * 8..i * 8 + 8).and_then(|s| s.try_into().ok()).map(f64::from_be_bytes);
|
||||
Some([at(0)?, at(1)?, at(2)?])
|
||||
Some([be_f64(b, 0)?, be_f64(b, 8)?, be_f64(b, 16)?])
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::container::bytes::{be_u16, be_u32};
|
||||
use crate::container::bytes::be_u32;
|
||||
use crate::container::chunk::AepFile;
|
||||
use crate::container::index::{Root, TreeIndex};
|
||||
|
||||
/// An After Effects version as packed in `head` / `svap`: `26.2.1x2` is major 26, minor 2, bug-fix
|
||||
/// 1, build 2 (the form of the scripting API's `app.version`).
|
||||
@@ -71,21 +72,36 @@ impl AepFile<'_> {
|
||||
/// version there, and the older version for File ▸ Save a Copy As 25.x / 24.x. `None` when the
|
||||
/// chunk is missing, short or holds no version.
|
||||
pub fn file_version(&self) -> Option<AeVersion> {
|
||||
AeVersion::from_word(be_u32(self.chunk(b"head")?.bytes()?, 4)?)
|
||||
Root::from(self).file_version()
|
||||
}
|
||||
|
||||
/// The version of the After Effects that wrote the file: `svap` bytes 0 to 3 (the same word in a
|
||||
/// down-saved copy as in a normal save). `None` when the chunk is missing (After Effects opens such
|
||||
/// a file), short or holds no version.
|
||||
pub fn saved_by_version(&self) -> Option<AeVersion> {
|
||||
AeVersion::from_word(be_u32(self.chunk(b"svap")?.bytes()?, 0)?)
|
||||
Root::from(self).saved_by_version()
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeIndex<'_> {
|
||||
/// [`AepFile::file_version`] of the indexed file.
|
||||
pub fn file_version(&self) -> Option<AeVersion> {
|
||||
Root::from(self).file_version()
|
||||
}
|
||||
|
||||
/// The `u16` at `head` byte 0: 97 (`0x61`) in a 2026 file, 96 in a copy saved as 25.x, 95 as
|
||||
/// 24.x. It steps with the major version of [`AepFile::file_version`]; what it counts is not
|
||||
/// known, so nothing is derived from it.
|
||||
pub fn head_revision(&self) -> Option<u16> {
|
||||
be_u16(self.chunk(b"head")?.bytes()?, 0)
|
||||
/// [`AepFile::saved_by_version`] of the indexed file.
|
||||
pub fn saved_by_version(&self) -> Option<AeVersion> {
|
||||
Root::from(self).saved_by_version()
|
||||
}
|
||||
}
|
||||
|
||||
impl Root<'_, '_> {
|
||||
pub(crate) fn file_version(self) -> Option<AeVersion> {
|
||||
AeVersion::from_word(be_u32(self.chunk(b"head")?.bytes()?, 4)?)
|
||||
}
|
||||
|
||||
pub(crate) fn saved_by_version(self) -> Option<AeVersion> {
|
||||
AeVersion::from_word(be_u32(self.chunk(b"svap")?.bytes()?, 0)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,18 @@ const MAX_WRITE_DEPTH: usize = 256;
|
||||
/// [`AepError::TooDeep`] for an absurdly deep hand-built tree.
|
||||
pub fn write(file: &AepFile<'_>) -> Result<Vec<u8>, AepError> {
|
||||
let mut out = Vec::new();
|
||||
// Sized once to the exact output. A tree past the 32-bit container size fails at once (the
|
||||
// same error the write below would give after serialising it). `try_reserve` so a hand-built
|
||||
// tree that repeats one large borrowed body many times cannot abort on the allocation; the
|
||||
// writer then grows as it goes, as before.
|
||||
if let Some(len) = sequence_len(&file.chunks, 1) {
|
||||
if u32::try_from(len.saturating_add(4)).is_err() {
|
||||
return Err(AepError::TooLarge);
|
||||
}
|
||||
if let Some(total) = len.checked_add(12).and_then(|n| n.checked_add(file.trailer.len())) {
|
||||
let _ = out.try_reserve_exact(total);
|
||||
}
|
||||
}
|
||||
out.extend_from_slice(b"RIFX");
|
||||
out.extend_from_slice(&[0; 4]);
|
||||
out.extend_from_slice(b"Egg!");
|
||||
@@ -56,6 +68,28 @@ fn write_sequence(out: &mut Vec<u8>, chunks: &[Chunk<'_>], depth: usize) -> Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The number of bytes [`write_sequence`] produces for `chunks`; `None` past the depth limit or
|
||||
/// on overflow (both make the write fail).
|
||||
fn sequence_len(chunks: &[Chunk<'_>], depth: usize) -> Option<usize> {
|
||||
if depth > MAX_WRITE_DEPTH {
|
||||
return None;
|
||||
}
|
||||
let count = chunks.len();
|
||||
let mut total = 0usize;
|
||||
for (i, chunk) in chunks.iter().enumerate() {
|
||||
let body = match &chunk.body {
|
||||
Body::Data(d) => d.len(),
|
||||
Body::Chunks(c) => sequence_len(c, depth + 1)?,
|
||||
Body::List { children, .. } => sequence_len(children, depth + 1)?.checked_add(4)?,
|
||||
Body::OpaqueList { data, .. } => data.len().checked_add(4)?,
|
||||
};
|
||||
// The same pad rule as `write_chunk`.
|
||||
let pad = usize::from(body % 2 == 1 && (chunk.pad.is_some() || i + 1 != count));
|
||||
total = total.checked_add(8)?.checked_add(body)?.checked_add(pad)?;
|
||||
}
|
||||
Some(total)
|
||||
}
|
||||
|
||||
fn write_chunk(out: &mut Vec<u8>, chunk: &Chunk<'_>, is_last: bool, depth: usize) -> Result<(), AepError> {
|
||||
out.extend_from_slice(&chunk.id);
|
||||
let size_at = out.len();
|
||||
@@ -84,3 +118,62 @@ fn write_chunk(out: &mut Vec<u8>, chunk: &Chunk<'_>, is_last: bool, depth: usize
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The output is sized once to its exact length.
|
||||
#[test]
|
||||
fn the_output_is_sized_once_to_its_exact_length() {
|
||||
let odd = |n: u8| Chunk::data(*b"cdat", vec![n; usize::from(n)]);
|
||||
let mut padded = odd(3);
|
||||
padded.pad = Some(0x7f);
|
||||
let trees = [
|
||||
AepFile { chunks: Vec::new(), trailer: Cow::Borrowed(&[]) },
|
||||
AepFile {
|
||||
chunks: vec![
|
||||
odd(1),
|
||||
Chunk::list(*b"Fold", vec![odd(2), odd(3), Chunk::list(*b"tdgp", vec![odd(5)])]),
|
||||
Chunk { id: *b"LIST", body: Body::OpaqueList { list_type: *b"btdk", data: Cow::Owned(vec![1, 2, 3]) }, pad: None },
|
||||
Chunk { id: *b"tdmn", body: Body::Chunks(vec![odd(7), padded]), pad: None },
|
||||
odd(9),
|
||||
],
|
||||
trailer: Cow::Borrowed(b"<x:xmpmeta/>"),
|
||||
},
|
||||
];
|
||||
for file in &trees {
|
||||
let out = write(file).expect("write");
|
||||
assert_eq!(sequence_len(&file.chunks, 1).map(|n| n + 12 + file.trailer.len()), Some(out.len()));
|
||||
// Exact with std's allocator today; grown push by push it would be rounded up.
|
||||
assert_eq!(out.capacity(), out.len(), "the output grew past its size");
|
||||
}
|
||||
}
|
||||
|
||||
/// A tree past the container size fails before serialising.
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
#[test]
|
||||
fn a_tree_past_the_container_size_fails_before_serialising() {
|
||||
// 4097 chunks borrowing one 1 MiB body: over 4 GiB of output, none of it written.
|
||||
let body = vec![0u8; 1 << 20];
|
||||
let chunks: Vec<Chunk<'_>> = (0..4097).map(|_| Chunk::data(*b"cdat", &body[..])).collect();
|
||||
let file = AepFile { chunks, trailer: Cow::Borrowed(&[]) };
|
||||
assert_eq!(write(&file), Err(AepError::TooLarge));
|
||||
// Just under the limit still sizes, and fails nothing up front.
|
||||
assert!(sequence_len(&file.chunks[..4000], 1).is_some_and(|n| u32::try_from(n + 4).is_ok()));
|
||||
}
|
||||
|
||||
/// A tree past the depth limit has no size.
|
||||
#[test]
|
||||
fn a_tree_past_the_depth_limit_has_no_size() {
|
||||
let mut deep = Chunk::data(*b"cdat", vec![0]);
|
||||
for _ in 0..=MAX_WRITE_DEPTH {
|
||||
deep = Chunk::list(*b"tdgp", vec![deep]);
|
||||
}
|
||||
let file = AepFile { chunks: vec![deep], trailer: Cow::Borrowed(&[]) };
|
||||
assert_eq!(sequence_len(&file.chunks, 1), None);
|
||||
assert_eq!(write(&file), Err(AepError::TooDeep));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ mod footage;
|
||||
mod fx_defs;
|
||||
mod fxsynth;
|
||||
pub(crate) mod icc;
|
||||
mod keys;
|
||||
mod markers;
|
||||
mod masks;
|
||||
mod plan;
|
||||
|
||||
@@ -6,15 +6,20 @@
|
||||
//! (read-backs t-no<id>, t-zcdta, u-zsspc, u-noclrs, u-noftgi, u-nofrec, u-nocdrp).
|
||||
|
||||
use crate::Chunk;
|
||||
use crate::export::synth::{tdmn, tdsn};
|
||||
use crate::export::synth::{GROUP_END, tdmn, tdsn};
|
||||
use crate::export::tree::Fixed;
|
||||
|
||||
/// A zero buffer of `len` bytes with `fields` (offset, bytes) written into it.
|
||||
/// A zero buffer of `len` bytes with `fields` (offset, bytes) written into it. The layouts are
|
||||
/// fixed in code ([`Fixed`]).
|
||||
pub(crate) fn bytes(len: usize, fields: &[(usize, &[u8])]) -> Vec<u8> {
|
||||
let mut b = vec![0u8; len];
|
||||
layout(len, fields).finish(|| format!("base::bytes ({len} bytes, fields at {:?})", fields.iter().map(|(at, v)| (*at, v.len())).collect::<Vec<_>>()))
|
||||
}
|
||||
|
||||
/// The fixed layout of `len` zero bytes with `fields` written at their offsets.
|
||||
fn layout(len: usize, fields: &[(usize, &[u8])]) -> Fixed {
|
||||
let mut b = Fixed::zeroed(len);
|
||||
for (at, v) in fields {
|
||||
if let Some(dst) = b.get_mut(*at..at.saturating_add(v.len())) {
|
||||
dst.copy_from_slice(v);
|
||||
}
|
||||
b.put(*at, v);
|
||||
}
|
||||
b
|
||||
}
|
||||
@@ -52,12 +57,8 @@ pub(crate) fn project_chunks() -> Vec<Chunk<'static>> {
|
||||
// colour depth (2: 32 bits); the save noise after the code page is left zero.
|
||||
let nhed = bytes(32, &[(7, &[5]), (9, &[1]), (12, &[0x1e, 16, 2, 2]), (18, &UTF8_CODE_PAGE)]);
|
||||
let nnhd = bytes(40, &[(7, &[5]), (9, &[1]), (15, &[0x1e]), (19, &[16, 2]), (24, &[2]), (26, &UTF8_CODE_PAGE)]);
|
||||
let mut lhd3 = bytes(52, &[(0, &0x00d0_0bee_u32.to_be_bytes()), (12, &1u32.to_be_bytes()), (16, &RQ_ITEM_LEN.to_be_bytes())]);
|
||||
for at in [20, 24, 28] {
|
||||
if let Some(dst) = lhd3.get_mut(at..at + 4) {
|
||||
dst.copy_from_slice(&1u32.to_be_bytes());
|
||||
}
|
||||
}
|
||||
let one = 1u32.to_be_bytes();
|
||||
let lhd3 = bytes(52, &[(0, &0x00d0_0bee_u32.to_be_bytes()), (12, &one), (16, &RQ_ITEM_LEN.to_be_bytes()), (20, &one), (24, &one), (28, &one)]);
|
||||
let wsnm: Vec<u8> = "Default".encode_utf16().flat_map(u16::to_be_bytes).collect();
|
||||
vec![
|
||||
Chunk::data(*b"svap", VERSION.to_vec()),
|
||||
@@ -157,30 +158,17 @@ fn view_layer(ty: &[u8; 4], name: &str, label: u8, kind: u8) -> Vec<Chunk<'stati
|
||||
let markers = kind == 4;
|
||||
let mut name_copy = name.as_bytes().to_vec();
|
||||
name_copy.truncate(31);
|
||||
let mut ldta = bytes(
|
||||
164,
|
||||
&[
|
||||
(8, &1u32.to_be_bytes()),
|
||||
(16, &600u32.to_be_bytes()),
|
||||
(24, &25_600u32.to_be_bytes()),
|
||||
(28, &VIEW_OUT.to_be_bytes()),
|
||||
(32, &25_600u32.to_be_bytes()),
|
||||
(61, &[label]),
|
||||
(64, &name_copy),
|
||||
(108, &1u32.to_be_bytes()),
|
||||
(128, &u32::from(kind).to_be_bytes()),
|
||||
],
|
||||
);
|
||||
// Byte 38: 3D and auto-orient on the cameras; byte 39: the video switch (and on the markers
|
||||
// layer also effects, locked and collapse); quality Draft and blend mode Normal on the
|
||||
// markers layer.
|
||||
let flags: &[(usize, u8)] = if markers { &[(5, 2), (39, 0x87), (99, 2)] } else { &[(38, 0x44), (39, 1)] };
|
||||
for (at, v) in flags {
|
||||
if let Some(b) = ldta.get_mut(*at) {
|
||||
*b = *v;
|
||||
}
|
||||
}
|
||||
let root = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn(""), tdmn("ADBE Group End")];
|
||||
let flags: &[(usize, &[u8])] = if markers { &[(5, &[2]), (39, &[0x87]), (99, &[2])] } else { &[(38, &[0x44]), (39, &[1])] };
|
||||
let (one, scale, kind_word) = (1u32.to_be_bytes(), 25_600u32.to_be_bytes(), u32::from(kind).to_be_bytes());
|
||||
let (base, out, label) = (600u32.to_be_bytes(), VIEW_OUT.to_be_bytes(), [label]);
|
||||
let mut fields: Vec<(usize, &[u8])> =
|
||||
vec![(8, &one), (16, &base), (24, &scale), (28, &out), (32, &scale), (61, &label), (64, &name_copy), (108, &one), (128, &kind_word)];
|
||||
fields.extend_from_slice(flags);
|
||||
let ldta = bytes(164, &fields);
|
||||
let root = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn(""), tdmn(GROUP_END)];
|
||||
let layer = Chunk::list(*ty, vec![Chunk::data(*b"ldta", ldta), utf8(name), Chunk::list(*b"tdgp", root), guides()]);
|
||||
let mut out = vec![layer, Chunk::list(*b"Ewst", Vec::new())];
|
||||
out.extend(crate::export::skeleton::f_records());
|
||||
@@ -293,6 +281,16 @@ pub(crate) fn solid_item() -> Chunk<'static> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A field out of range is an error.
|
||||
#[test]
|
||||
fn a_field_out_of_range_is_an_error() {
|
||||
let ok = layout(4, &[(0, &[1]), (3, &[2])]);
|
||||
assert!(ok.error().is_none());
|
||||
assert_eq!(ok.finish(String::new), [1, 0, 0, 2]);
|
||||
assert!(layout(4, &[(3, &[1, 2])]).error().is_some());
|
||||
assert!(layout(4, &[(usize::MAX, &[1])]).error().is_some());
|
||||
}
|
||||
|
||||
/// The chunks After Effects refuses a file without, or crashes on (aep-export.md, "What After
|
||||
/// Effects needs").
|
||||
#[test]
|
||||
|
||||
@@ -13,7 +13,8 @@ use effectcraft_keyframe::Value;
|
||||
use effectcraft_project::{Layer, LightKind};
|
||||
|
||||
use crate::export::report::{Collector, LossCategory};
|
||||
use crate::export::tree::{R, child_data, kids_mut, list_mut, put_f64, tpl};
|
||||
use crate::export::synth::{GROUP_END, is_tdmn, tdmn};
|
||||
use crate::export::tree::{R, child_data, kids_mut, list_mut, put_f64, split_group, tpl};
|
||||
|
||||
/// A camera's options in the file's units (pixels, percent, a switch).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -183,50 +184,24 @@ const LIGHT_ORDER: &[&str] = &[
|
||||
"ADBE Casts Shadows",
|
||||
];
|
||||
|
||||
pub(crate) fn tdmn_chunk(name: &str) -> Chunk<'static> {
|
||||
let mut b = vec![0u8; 40];
|
||||
for (i, c) in name.bytes().take(39).enumerate() {
|
||||
b[i] = c;
|
||||
}
|
||||
Chunk::data(*b"tdmn", b)
|
||||
}
|
||||
|
||||
fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let b = c.bytes()?;
|
||||
let end = b.iter().position(|x| *x == 0).unwrap_or(b.len());
|
||||
std::str::from_utf8(b.get(..end)?).ok().map(str::to_string)
|
||||
}
|
||||
|
||||
/// Sets (or inserts) the records of an options group (`tdmn` named `group`) of a layer.
|
||||
fn put_group(layr: &mut Chunk<'static>, group: &str, order: &[&str], set: Vec<(&str, Chunk<'static>)>, remove: &[&str]) -> R<()> {
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at = kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(group)).ok_or_else(|| tpl("options group missing"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, group)).ok_or_else(|| tpl("options group missing"))?;
|
||||
let g = kids.get_mut(at + 1).ok_or_else(|| tpl("options group without a list"))?;
|
||||
let gk = kids_mut(g)?;
|
||||
let first = gk.iter().position(|c| c.is(b"tdmn")).unwrap_or(gk.len());
|
||||
let header: Vec<Chunk<'static>> = gk.drain(..first).collect();
|
||||
let mut pairs: Vec<(String, Vec<Chunk<'static>>)> = Vec::new();
|
||||
let mut it = std::mem::take(gk).into_iter();
|
||||
while let Some(m) = it.next() {
|
||||
let name = tdmn_name(&m).unwrap_or_default();
|
||||
if name == "ADBE Group End" {
|
||||
pairs.push((name, vec![m]));
|
||||
continue;
|
||||
}
|
||||
let Some(node) = it.next() else { break };
|
||||
// An atom group (Light Env Atom) carries its own Group End inside the list.
|
||||
pairs.push((name, vec![m, node]));
|
||||
}
|
||||
// An atom group (Light Env Atom) carries its own Group End inside its list.
|
||||
let (header, mut pairs) = split_group(gk)?;
|
||||
pairs.retain(|(n, _)| !remove.contains(&n.as_str()));
|
||||
for (name, rec) in set {
|
||||
let entry = vec![tdmn_chunk(name), rec];
|
||||
let entry = vec![tdmn(name), rec];
|
||||
match pairs.iter_mut().find(|(n, _)| n == name) {
|
||||
Some(slot) => slot.1 = entry,
|
||||
None => pairs.push((name.to_string(), entry)),
|
||||
}
|
||||
}
|
||||
let rank = |n: &str| if n == "ADBE Group End" { usize::MAX } else { order.iter().position(|g| *g == n).unwrap_or(order.len()) };
|
||||
let rank = |n: &str| if n == GROUP_END { usize::MAX } else { order.iter().position(|g| *g == n).unwrap_or(order.len()) };
|
||||
pairs.sort_by_key(|(n, _)| rank(n));
|
||||
gk.extend(header);
|
||||
gk.extend(pairs.into_iter().flat_map(|(_, v)| v));
|
||||
|
||||
+359
-80
@@ -6,8 +6,10 @@ use std::collections::HashMap;
|
||||
use crate::{AepFile, Chunk};
|
||||
use effectcraft_project::{ItemId, LayerId};
|
||||
|
||||
use crate::export::keys::fill_key_list;
|
||||
use crate::export::plan::{CompPlan, Entry, ItemPlan, KeyPlan, LayerPlan, LayerSrc, ProjectPlan, PropKind, PropPlan, SolidPlan, natural_key};
|
||||
use crate::export::template::Template;
|
||||
use crate::export::synth::{is_tdmn, tdmn_name};
|
||||
use crate::export::template::{self, Template};
|
||||
use crate::export::tree::{
|
||||
R, child_data, data_mut, kids_mut, list_mut, put, put_bits, put_cstr, put_f32, put_f64, put_i32, put_u8, put_u16, put_u32, set_utf8, tpl,
|
||||
};
|
||||
@@ -58,10 +60,14 @@ struct Cx<'t> {
|
||||
type Sorted = (String, u64, Vec<Chunk<'static>>);
|
||||
|
||||
pub(crate) fn emit(plan: &ProjectPlan, extra: &[u8]) -> R<Vec<u8>> {
|
||||
let t = Template::load()?;
|
||||
emit_with(template::shared()?, plan, extra)
|
||||
}
|
||||
|
||||
/// [`emit`] with the prototypes of `t`.
|
||||
fn emit_with(t: &Template, plan: &ProjectPlan, extra: &[u8]) -> R<Vec<u8>> {
|
||||
let special = plan.root.iter().find(|e| e.name == "Solids" && matches!(e.plan, ItemPlan::Folder(_))).map(|e| e.ec);
|
||||
let mut cx = Cx {
|
||||
t: &t,
|
||||
t,
|
||||
ids: Ids { next: FIRST_ID },
|
||||
solid_ids: HashMap::new(),
|
||||
comp_ids: HashMap::new(),
|
||||
@@ -77,16 +83,14 @@ pub(crate) fn emit(plan: &ProjectPlan, extra: &[u8]) -> R<Vec<u8>> {
|
||||
|
||||
let mut root: Vec<Sorted> = Vec::new();
|
||||
build_level(&plan.root, &mut cx, &ids_by_entry, &mut |name, key, chunks| root.push((name, key, chunks)))?;
|
||||
// The Solids folder: root-level solids and the hidden solids of null layers.
|
||||
let mut solids_children: Vec<Sorted> = Vec::new();
|
||||
for (name, key, chunks) in root.iter().filter(|(_, k, _)| *k & ROOT_SOLID != 0) {
|
||||
solids_children.push((name.clone(), *key, chunks.clone()));
|
||||
}
|
||||
root.retain(|(_, k, c)| *k & ROOT_SOLID == 0 && !c.is_empty());
|
||||
for (i, (name, chunk)) in cx.extra_solids.iter().enumerate() {
|
||||
let mut v = vec![chunk.clone()];
|
||||
// The Solids folder: root-level solids and the hidden solids of null layers (moved, not
|
||||
// copied: the root keeps neither).
|
||||
let (mut solids_children, mut root): (Vec<Sorted>, Vec<Sorted>) = root.into_iter().partition(|(_, k, _)| *k & ROOT_SOLID != 0);
|
||||
root.retain(|(_, _, c)| !c.is_empty());
|
||||
for (i, (name, chunk)) in std::mem::take(&mut cx.extra_solids).into_iter().enumerate() {
|
||||
let mut v = vec![chunk];
|
||||
v.extend(cx.t.fset.iter().cloned());
|
||||
solids_children.push((name.clone(), i as u64, v));
|
||||
solids_children.push((name, i as u64, v));
|
||||
}
|
||||
let mut folder = match cx.special_slot.take() {
|
||||
Some((item, inner)) => {
|
||||
@@ -125,26 +129,57 @@ pub(crate) fn emit(plan: &ProjectPlan, extra: &[u8]) -> R<Vec<u8>> {
|
||||
/// Marks a root entry that goes into the `Solids` folder.
|
||||
const ROOT_SOLID: u64 = 1 << 63;
|
||||
|
||||
/// Sorts by name in natural order, then by the tie-break key. Each name's sort key is built once,
|
||||
/// not on every comparison; the sort is stable, as `sort_by` is.
|
||||
fn sort_named(v: &mut [Sorted]) {
|
||||
v.sort_by(|a, b| natural_cmp(&a.0, &b.0).then(a.1.cmp(&b.1)));
|
||||
v.sort_by_cached_key(|(name, key, _)| (natural_bytes(name), *key));
|
||||
}
|
||||
|
||||
fn natural_cmp(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
let (ka, kb) = (natural_key(a), natural_key(b));
|
||||
for (x, y) in ka.iter().zip(kb.iter()) {
|
||||
let c = match (x.0, y.0) {
|
||||
(true, true) => x.2.cmp(&y.2).then_with(|| x.1.cmp(&y.1)),
|
||||
(false, false) => x.1.cmp(&y.1),
|
||||
(true, false) => std::cmp::Ordering::Less,
|
||||
(false, true) => std::cmp::Ordering::Greater,
|
||||
};
|
||||
if c != std::cmp::Ordering::Equal {
|
||||
return c;
|
||||
/// The [`natural_key`] of `name` as one byte string whose plain byte order is the natural order:
|
||||
/// segment by segment, a number before text, numbers by value and then by their digit strings
|
||||
/// byte by byte (`01` before `1`), text by its lowercase string, and a key that is a prefix of
|
||||
/// the other first.
|
||||
///
|
||||
/// - A number: `0x01`, the count of significant bytes of its value, those bytes big-endian, its
|
||||
/// digits, `0x00` (digits are never `0x00`, so a digit string that is a prefix of another, as
|
||||
/// `0` of `00`, sorts first).
|
||||
/// - Text: `0x02`, its lowercase UTF-8 with each `0x00` written as `0x00 0x01`, then `0x00 0x00`.
|
||||
///
|
||||
/// At most 5 bytes per byte of `name` (`NATURAL_BYTES_PER_NAME_BYTE`), so the cached keys stay
|
||||
/// within a small multiple of the names they sort (one segment as a `(bool, String, u128)` takes
|
||||
/// 48 bytes plus its string, which is why the segments themselves are not cached).
|
||||
fn natural_bytes(name: &str) -> Vec<u8> {
|
||||
let mut out = Vec::with_capacity(name.len().saturating_add(4));
|
||||
for (number, text, value) in natural_key(name) {
|
||||
if number {
|
||||
out.push(0x01);
|
||||
let be = value.to_be_bytes();
|
||||
let zeros = be.iter().take_while(|b| **b == 0).count();
|
||||
let significant = be.get(zeros..).unwrap_or_default();
|
||||
out.push(significant.len() as u8);
|
||||
out.extend_from_slice(significant);
|
||||
out.extend_from_slice(text.as_bytes());
|
||||
out.push(0x00);
|
||||
} else {
|
||||
out.push(0x02);
|
||||
for b in text.bytes() {
|
||||
out.push(b);
|
||||
if b == 0 {
|
||||
out.push(0x01);
|
||||
}
|
||||
}
|
||||
out.extend_from_slice(&[0x00, 0x00]);
|
||||
}
|
||||
}
|
||||
ka.len().cmp(&kb.len())
|
||||
out
|
||||
}
|
||||
|
||||
/// The bound on [`natural_bytes`]: a run of `d` digits takes at most `3 + 2d` bytes (its value
|
||||
/// never needs more bytes than digits), a text run of `b` bytes at most `3 + 2b` (lowercasing and
|
||||
/// the NUL escape at most double a character), and every run is at least one byte long.
|
||||
#[cfg(test)]
|
||||
const NATURAL_BYTES_PER_NAME_BYTE: usize = 5;
|
||||
|
||||
fn assign_ids(entries: &[Entry], cx: &mut Cx<'_>, map: &mut HashMap<ItemId, u32>) -> R<()> {
|
||||
// Iterative to bound the stack by the folder depth the plan already limits.
|
||||
let mut stack: Vec<&Entry> = entries.iter().rev().collect();
|
||||
@@ -404,8 +439,7 @@ fn put_used_comps(cx: &Cx<'_>, item: &mut Chunk<'static>, cp: &CompPlan) -> R<()
|
||||
fn put_time_remap_max(layr: &mut Chunk<'static>, seconds: f64) -> R<()> {
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at =
|
||||
kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Time Remapping")).ok_or_else(|| tpl("layer without Time Remapping"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Time Remapping")).ok_or_else(|| tpl("layer without Time Remapping"))?;
|
||||
let tdbs = kids.get_mut(at + 1).ok_or_else(|| tpl("Time Remapping without a record"))?;
|
||||
put_f64(child_data(tdbs, b"tduM")?, 0, seconds)
|
||||
}
|
||||
@@ -420,8 +454,7 @@ fn put_time_remap_max(layr: &mut Chunk<'static>, seconds: f64) -> R<()> {
|
||||
fn put_time_remap(cx: &Cx<'_>, layr: &mut Chunk<'static>, remap: &PropPlan) -> R<()> {
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at =
|
||||
kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Time Remapping")).ok_or_else(|| tpl("layer without Time Remapping"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Time Remapping")).ok_or_else(|| tpl("layer without Time Remapping"))?;
|
||||
let tdbs = kids.get_mut(at + 1).ok_or_else(|| tpl("Time Remapping without a record"))?;
|
||||
put_u32(child_data(tdbs, b"tdsb")?, 0, 1)?;
|
||||
{
|
||||
@@ -454,21 +487,12 @@ fn put_time_remap(cx: &Cx<'_>, layr: &mut Chunk<'static>, remap: &PropPlan) -> R
|
||||
.find(|k| matches!(&k.body, crate::Body::List { list_type, .. } if list_type == b"list"))
|
||||
.cloned()
|
||||
.ok_or_else(|| tpl("keyed prototype without a list"))?;
|
||||
let n = u32::try_from(remap.keys.len()).map_err(|_| tpl("too many keys"))?;
|
||||
let size = 48usize;
|
||||
{
|
||||
let lhd3 = child_data(&mut list, b"lhd3")?;
|
||||
crate::export::synth::put_key_counts(lhd3, n, 48)?;
|
||||
}
|
||||
let mut ldat = Vec::with_capacity(size * remap.keys.len());
|
||||
for k in &remap.keys {
|
||||
ldat.extend(plain_record(1, k, size)?);
|
||||
}
|
||||
let ld = kids_mut(&mut list)?;
|
||||
match ld.iter_mut().find(|c| c.is(b"ldat")) {
|
||||
Some(c) => *c = Chunk::data(*b"ldat", ldat),
|
||||
None => ld.push(Chunk::data(*b"ldat", ldat)),
|
||||
}
|
||||
fill_key_list(&mut list, ldat, remap.keys.len(), size)?;
|
||||
if let Some(slot) = rk.get_mut(cdat_at) {
|
||||
*slot = list;
|
||||
}
|
||||
@@ -616,10 +640,7 @@ fn put_masks(cx: &Cx<'_>, layr: &mut Chunk<'static>, lp: &LayerPlan) -> R<()> {
|
||||
let parade = crate::export::masks::build_parade(&cx.t.masks, &lp.masks, lp.source_size)?;
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at = kids
|
||||
.iter()
|
||||
.position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Transform Group"))
|
||||
.ok_or_else(|| tpl("layer without a Transform group"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Transform Group")).ok_or_else(|| tpl("layer without a Transform group"))?;
|
||||
kids.splice(at..at, parade);
|
||||
Ok(())
|
||||
}
|
||||
@@ -633,10 +654,7 @@ fn put_effects(cx: &mut Cx<'_>, layr: &mut Chunk<'static>, lp: &LayerPlan, layer
|
||||
let parade = crate::export::effects::build_parade(&cx.t.effects, &lp.fx, layer_id, layer_ids, lp.source_size, &mut cx.fx_use)?;
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at = kids
|
||||
.iter()
|
||||
.position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Transform Group"))
|
||||
.ok_or_else(|| tpl("layer without a Transform group"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Transform Group")).ok_or_else(|| tpl("layer without a Transform group"))?;
|
||||
kids.splice(at..at, parade);
|
||||
Ok(())
|
||||
}
|
||||
@@ -659,11 +677,6 @@ const GROUP_ORDER: [&str; 13] = [
|
||||
"ADBE Group End",
|
||||
];
|
||||
|
||||
fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let d = c.bytes()?;
|
||||
Some(d.iter().take_while(|b| **b != 0).map(|b| char::from(*b)).collect())
|
||||
}
|
||||
|
||||
/// Inserts the properties of `lp` into the layer's Transform group, in the order the file uses.
|
||||
fn put_properties(cx: &Cx<'_>, layr: &mut Chunk<'static>, lp: &LayerPlan, cp: &CompPlan) -> R<()> {
|
||||
if lp.props.is_empty() {
|
||||
@@ -671,20 +684,19 @@ fn put_properties(cx: &Cx<'_>, layr: &mut Chunk<'static>, lp: &LayerPlan, cp: &C
|
||||
}
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at = kids
|
||||
.iter()
|
||||
.position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Transform Group"))
|
||||
.ok_or_else(|| tpl("layer without a Transform group"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Transform Group")).ok_or_else(|| tpl("layer without a Transform group"))?;
|
||||
let group = kids.get_mut(at + 1).ok_or_else(|| tpl("Transform group without a list"))?;
|
||||
let gk = kids_mut(group)?;
|
||||
// Split the group into its header (up to the first match name) and (tdmn, node) pairs.
|
||||
let first = gk.iter().position(|c| c.is(b"tdmn")).ok_or_else(|| tpl("empty Transform group"))?;
|
||||
let header: Vec<Chunk<'static>> = gk.drain(..first).collect();
|
||||
let mut pairs: Vec<(String, Vec<Chunk<'static>>)> = Vec::new();
|
||||
let mut pairs: Vec<(Vec<u8>, Vec<Chunk<'static>>)> = Vec::new();
|
||||
let mut it = std::mem::take(gk).into_iter();
|
||||
while let Some(m) = it.next() {
|
||||
let name = tdmn_name(&m).unwrap_or_default();
|
||||
if name == "ADBE Group End" {
|
||||
// The match name as the shared decoder reads it (lossy UTF-8 up to the first NUL). Every
|
||||
// name looked up below is ASCII, so a name matches exactly when its bytes do.
|
||||
let name = tdmn_name(&m).unwrap_or_default().into_bytes();
|
||||
if name == b"ADBE Group End" {
|
||||
pairs.push((name, vec![m]));
|
||||
continue;
|
||||
}
|
||||
@@ -694,22 +706,19 @@ fn put_properties(cx: &Cx<'_>, layr: &mut Chunk<'static>, lp: &LayerPlan, cp: &C
|
||||
for p in &lp.props {
|
||||
let name = p.kind.match_name();
|
||||
let built = build_prop(cx, p, lp, cp)?;
|
||||
let tdmn = pairs.iter().find(|(n, _)| n == name).and_then(|(_, v)| v.first().cloned()).unwrap_or_else(|| {
|
||||
cx.t.stat
|
||||
.iter()
|
||||
.chain(cx.t.keyd.iter())
|
||||
.find(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(name))
|
||||
.cloned()
|
||||
.unwrap_or_else(|| Chunk::data(*b"tdmn", Vec::new()))
|
||||
let tdmn = pairs.iter().find(|(n, _)| n == name.as_bytes()).and_then(|(_, v)| v.first().cloned()).unwrap_or_else(|| {
|
||||
cx.t.stat.iter().chain(cx.t.keyd.iter()).find(|c| is_tdmn(c, name)).cloned().unwrap_or_else(|| Chunk::data(*b"tdmn", Vec::new()))
|
||||
});
|
||||
let entry = vec![tdmn, built];
|
||||
if let Some(slot) = pairs.iter_mut().find(|(n, _)| n == name) {
|
||||
if let Some(slot) = pairs.iter_mut().find(|(n, _)| n == name.as_bytes()) {
|
||||
slot.1 = entry;
|
||||
} else {
|
||||
pairs.push((name.to_string(), entry));
|
||||
pairs.push((name.as_bytes().to_vec(), entry));
|
||||
}
|
||||
}
|
||||
let rank = |n: &str| if n == "ADBE Group End" { usize::MAX } else { GROUP_ORDER.iter().position(|g| *g == n).unwrap_or(GROUP_ORDER.len()) };
|
||||
let rank = |n: &[u8]| {
|
||||
if n == b"ADBE Group End" { usize::MAX } else { GROUP_ORDER.iter().position(|g| g.as_bytes() == n).unwrap_or(GROUP_ORDER.len()) }
|
||||
};
|
||||
pairs.sort_by_key(|(n, _)| rank(n));
|
||||
gk.extend(header);
|
||||
gk.extend(pairs.into_iter().flat_map(|(_, v)| v));
|
||||
@@ -743,22 +752,12 @@ fn build_prop(cx: &Cx<'_>, p: &PropPlan, lp: &LayerPlan, cp: &CompPlan) -> R<Chu
|
||||
put_f64(cdat, i * 8, *v)?;
|
||||
}
|
||||
} else {
|
||||
let list = list_mut(&mut tdbs, b"list")?;
|
||||
let n = u32::try_from(p.keys.len()).map_err(|_| tpl("too many keys"))?;
|
||||
let size = if p.kind.spatial() { 56 + 24 * p.kind.dims() } else { 8 + 40 * p.kind.dims() };
|
||||
{
|
||||
let lhd3 = child_data(list, b"lhd3")?;
|
||||
crate::export::synth::put_key_counts(lhd3, n, u32::try_from(size).map_err(|_| tpl("record size"))?)?;
|
||||
}
|
||||
let mut ldat = Vec::with_capacity(size * p.keys.len());
|
||||
for k in &p.keys {
|
||||
ldat.extend(key_record(p.kind, k, size)?);
|
||||
}
|
||||
let ld = kids_mut(list)?;
|
||||
match ld.iter_mut().find(|c| c.is(b"ldat")) {
|
||||
Some(c) => *c = Chunk::data(*b"ldat", ldat),
|
||||
None => ld.push(Chunk::data(*b"ldat", ldat)),
|
||||
}
|
||||
fill_key_list(list_mut(&mut tdbs, b"list")?, ldat, p.keys.len(), size)?;
|
||||
}
|
||||
if let Some((text, _)) = &p.expr {
|
||||
let kids = kids_mut(&mut tdbs)?;
|
||||
@@ -818,3 +817,283 @@ pub(crate) fn plain_record(n: usize, k: &KeyPlan, size: usize) -> R<Vec<u8>> {
|
||||
}
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
use effectcraft_color::Label;
|
||||
use effectcraft_keyframe::{Keyframe, Value};
|
||||
use effectcraft_project::{Comp, Expression, ItemKind, LayerSource, Project, Property, Solid, build};
|
||||
use effectcraft_time::{FrameRate, TICKS_PER_SECOND, Tick};
|
||||
|
||||
/// Seconds as ticks.
|
||||
fn secs(s: f64) -> Tick {
|
||||
Tick((s * TICKS_PER_SECOND as f64).round() as i64)
|
||||
}
|
||||
|
||||
/// Adds a layer to `comp`, changed by `edit` first.
|
||||
fn add_layer(p: &mut Project, comp: ItemId, name: &str, source: LayerSource, edit: impl FnOnce(&mut effectcraft_project::Layer)) {
|
||||
let mut c = p.comp(comp).cloned().expect("comp");
|
||||
let mut l = build::layer(p, &c, name, source, (640, 360), None);
|
||||
l.name = name.to_string();
|
||||
edit(&mut l);
|
||||
c.layers.insert(0, l);
|
||||
if let Some(i) = p.item_mut(comp) {
|
||||
i.kind = ItemKind::Comp(Arc::new(c));
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives the property two keys (0 s and 1.5 s) holding its value.
|
||||
fn two_keys(prop: Option<&mut Property>) {
|
||||
let prop = prop.expect("property");
|
||||
let v = prop.value.clone();
|
||||
prop.keys = vec![Keyframe::new(secs(0.0), v.clone()), Keyframe::new(secs(1.5), v)];
|
||||
}
|
||||
|
||||
/// A project that reaches every part of `emit`: folders (one named `Solids`), root and nested
|
||||
/// solids with names that sort naturally, a precomposition, null layers (hidden solids), keyed
|
||||
/// Transform properties, an expression and a keyed time remap.
|
||||
fn varied(tag: &str) -> Project {
|
||||
let mut p = Project::default();
|
||||
let solid = |w| ItemKind::Solid(Solid { color: [0.2, 0.4, 0.6], width: w, height: 360, pixel_aspect: 1.0 });
|
||||
let solids = p.add_item("Solids", Label::None, None, ItemKind::Folder);
|
||||
let nested = p.add_item("Folder 10", Label::None, None, ItemKind::Folder);
|
||||
p.add_item("folder 9", Label::None, Some(nested), ItemKind::Folder);
|
||||
let mut ids = Vec::new();
|
||||
for name in ["Solid 10", "Solid 2", "solid 2", "Solid 02", "Solid", "Ölung 1", ""] {
|
||||
ids.push(p.add_item(&format!("{name}{tag}"), Label::Red, None, solid(640)));
|
||||
}
|
||||
p.add_item("In Solids 3", Label::None, Some(solids), solid(320));
|
||||
p.add_item("In folder", Label::None, Some(nested), solid(100));
|
||||
let pre = p.add_item("Pre 1", Label::None, Some(nested), ItemKind::Comp(Arc::new(Comp::new(640, 360, FrameRate::new(25, 1), secs(3.0)))));
|
||||
add_layer(&mut p, pre, "S", LayerSource::Solid { item: ids[0] }, |_| {});
|
||||
let main = p.add_item("Main", Label::None, None, ItemKind::Comp(Arc::new(Comp::new(1920, 1080, FrameRate::new(30, 1), secs(5.0)))));
|
||||
add_layer(&mut p, main, "Null A", LayerSource::Null, |_| {});
|
||||
add_layer(&mut p, main, "Null B", LayerSource::Null, |l| two_keys(l.props.prop_mut("transform/position")));
|
||||
add_layer(&mut p, main, "Solid layer", LayerSource::Solid { item: ids[1] }, |l| {
|
||||
two_keys(l.props.prop_mut("transform/opacity"));
|
||||
two_keys(l.props.prop_mut("transform/anchor"));
|
||||
if let Some(r) = l.props.prop_mut("transform/rotation") {
|
||||
r.expr = Some(Expression { text: "time * 10".into(), enabled: true });
|
||||
}
|
||||
});
|
||||
add_layer(&mut p, main, "Precomp", LayerSource::Comp { item: pre }, |l| {
|
||||
let mut r = Property::new(9_000, "timeRemap", "Time Remap", Value::Scalar(0.0));
|
||||
r.keys = vec![Keyframe::new(secs(0.0), Value::Scalar(3.0)), Keyframe::new(secs(3.0), Value::Scalar(0.0))];
|
||||
l.props.children.insert(0, r.into());
|
||||
});
|
||||
p
|
||||
}
|
||||
|
||||
/// The export plan of `p`.
|
||||
fn plan_of(p: &Project) -> ProjectPlan {
|
||||
let mut col = crate::export::report::Collector::default();
|
||||
crate::export::plan::plan(p, &mut col)
|
||||
}
|
||||
|
||||
/// The template is built once and every later export uses the same one.
|
||||
#[test]
|
||||
fn the_template_is_built_once() {
|
||||
let a = template::shared().expect("template");
|
||||
let b = template::shared().expect("template");
|
||||
assert!(std::ptr::eq(a, b));
|
||||
}
|
||||
|
||||
/// Exports with the shared template give the bytes a freshly built template gives, also after
|
||||
/// other exports have used it (nothing an export does reaches the template).
|
||||
#[test]
|
||||
fn the_shared_template_exports_what_a_fresh_one_does() {
|
||||
let (a, b) = (plan_of(&varied("")), plan_of(&varied(" x")));
|
||||
let fresh = |plan: &ProjectPlan| emit_with(&Template::load().expect("template"), plan, b"trailer").expect("emit");
|
||||
let (want_a, want_b) = (fresh(&a), fresh(&b));
|
||||
assert!(want_a != want_b);
|
||||
// The project exports without losses and the remap is written.
|
||||
let r = crate::export::export(&varied(""), &crate::export::ExportOptions { allow_losses: false }).expect("lossless");
|
||||
assert_eq!(r.report.exported.time_remaps, 1);
|
||||
// The null layers' hidden solids and the root solids went into the `Solids` folder.
|
||||
let file = crate::parse(&want_a).expect("parse");
|
||||
let folder = file.walk().map(|(_, c)| c).filter(|c| c.is_list(b"Sfdr")).map(|c| c.children().iter().filter(|k| k.is_list(b"Item")).count()).max();
|
||||
assert_eq!(folder, Some(10));
|
||||
for _ in 0..3 {
|
||||
assert!(emit(&a, b"trailer").expect("emit") == want_a);
|
||||
assert!(emit(&b, b"trailer").expect("emit") == want_b);
|
||||
}
|
||||
}
|
||||
|
||||
/// Exports running at the same time on several threads all give the single-threaded bytes.
|
||||
/// This checks concurrent exports from a template that is already built: other tests in this
|
||||
/// binary usually fill the shared template first, so the race on the first build is not
|
||||
/// reliably exercised here (the `static OnceLock` makes that race safe by construction).
|
||||
#[test]
|
||||
fn concurrent_exports_give_the_same_bytes() {
|
||||
let plans: Vec<ProjectPlan> = ["", " x", " y", " z"].iter().map(|t| plan_of(&varied(t))).collect();
|
||||
let want: Vec<Vec<u8>> = plans.iter().map(|plan| emit_with(&Template::load().expect("template"), plan, &[]).expect("emit")).collect();
|
||||
let got: Vec<Vec<Vec<u8>>> = std::thread::scope(|s| {
|
||||
let handles: Vec<_> = (0..8)
|
||||
.map(|i| {
|
||||
let plans = &plans;
|
||||
s.spawn(move || (0..4).map(|k| emit(&plans[(i + k) % plans.len()], &[]).expect("emit")).collect::<Vec<_>>())
|
||||
})
|
||||
.collect();
|
||||
handles.into_iter().map(|h| h.join().expect("thread")).collect()
|
||||
});
|
||||
for (i, bytes) in got.iter().enumerate() {
|
||||
for (k, b) in bytes.iter().enumerate() {
|
||||
assert!(b == &want[(i + k) % want.len()], "thread {i}, export {k}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The comparator `sort_named` used before its keys were cached: `natural_key` built on every
|
||||
/// comparison.
|
||||
fn old_sort_named(v: &mut [Sorted]) {
|
||||
/// The natural name order the cached sort keys replaced, as the reference.
|
||||
fn natural_cmp(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
let (ka, kb) = (natural_key(a), natural_key(b));
|
||||
for (x, y) in ka.iter().zip(kb.iter()) {
|
||||
let c = match (x.0, y.0) {
|
||||
(true, true) => x.2.cmp(&y.2).then_with(|| x.1.cmp(&y.1)),
|
||||
(false, false) => x.1.cmp(&y.1),
|
||||
(true, false) => std::cmp::Ordering::Less,
|
||||
(false, true) => std::cmp::Ordering::Greater,
|
||||
};
|
||||
if c != std::cmp::Ordering::Equal {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
ka.len().cmp(&kb.len())
|
||||
}
|
||||
v.sort_by(|a, b| natural_cmp(&a.0, &b.0).then(a.1.cmp(&b.1)));
|
||||
}
|
||||
|
||||
/// The cached-key sort orders names exactly as the comparator it replaced, and keeps entries
|
||||
/// with the same name and key in their order (each carries its position as a marker chunk).
|
||||
#[test]
|
||||
fn sort_named_orders_as_the_old_comparator() {
|
||||
let parts = [
|
||||
"",
|
||||
"0",
|
||||
"00",
|
||||
"1",
|
||||
"01",
|
||||
"2",
|
||||
"10",
|
||||
"a",
|
||||
"A",
|
||||
"b",
|
||||
" ",
|
||||
"-",
|
||||
".",
|
||||
"é",
|
||||
"É",
|
||||
"ß",
|
||||
"İ",
|
||||
"\u{0}",
|
||||
"\u{1}",
|
||||
"a\u{0}",
|
||||
"Ⱥ",
|
||||
"K",
|
||||
"ẞ",
|
||||
"Solid ",
|
||||
"solid ",
|
||||
"x9",
|
||||
"9x",
|
||||
"340282366920938463463374607431768211455",
|
||||
"340282366920938463463374607431768211456",
|
||||
"999999999999999999999999999999999999999999",
|
||||
];
|
||||
// A small deterministic generator (splitmix64).
|
||||
let mut state = 0x2545_f491_4f6c_dd1d_u64;
|
||||
let mut next = move || {
|
||||
state = state.wrapping_add(0x9e37_79b9_7f4a_7c15);
|
||||
let mut z = state;
|
||||
z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
|
||||
z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
|
||||
(z ^ (z >> 31)) as usize
|
||||
};
|
||||
for round in 0..2000 {
|
||||
let n = 1 + next() % 40;
|
||||
let v: Vec<Sorted> = (0..n)
|
||||
.map(|i| {
|
||||
let name: String = (0..next() % 4).map(|_| parts[next() % parts.len()]).collect();
|
||||
let key = (next() % 3) as u64 | if next() % 2 == 0 { ROOT_SOLID } else { 0 };
|
||||
(name, key, vec![Chunk::data(*b"mark", (i as u32).to_le_bytes().to_vec())])
|
||||
})
|
||||
.collect();
|
||||
let (mut old, mut new) = (v.clone(), v);
|
||||
old_sort_named(&mut old);
|
||||
sort_named(&mut new);
|
||||
assert_eq!(old, new, "round {round}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The cached sort keys stay within [`NATURAL_BYTES_PER_NAME_BYTE`] bytes per name byte, also
|
||||
/// for the worst name (255 bytes of alternating one-character text and digit runs: 255
|
||||
/// segments, which as `(bool, String, u128)` segments took about 14 KB), and the per-character
|
||||
/// premise of the bound holds for every character.
|
||||
#[test]
|
||||
fn sort_keys_are_bounded_by_the_name() {
|
||||
for c in (0..=0x10_ffff_u32).filter_map(char::from_u32) {
|
||||
let lower: usize = c.to_lowercase().map(char::len_utf8).sum::<usize>() + usize::from(c == '\0');
|
||||
assert!(lower <= 2 * c.len_utf8(), "{c:?}");
|
||||
}
|
||||
let worst: String = (0..255).map(|i| if i % 2 == 0 { 'a' } else { '1' }).collect();
|
||||
let others = ["", "1", "a", "\u{0}", "İ", "Ⱥ1", "99999999999999999999999999999999999999999999", &"\u{0}".repeat(255), &"Ⱥ".repeat(127)];
|
||||
for name in std::iter::once(worst.as_str()).chain(others) {
|
||||
let k = natural_bytes(name);
|
||||
assert!(k.len() <= NATURAL_BYTES_PER_NAME_BYTE * name.len(), "{name:?}: {} bytes", k.len());
|
||||
}
|
||||
assert_eq!(natural_key(&worst).len(), 255);
|
||||
assert!(natural_bytes(&worst).len() <= 1_275);
|
||||
}
|
||||
|
||||
/// The shared `is_tdmn` / `tdmn_name` the emitter uses agree with the Latin-1 decoding it used
|
||||
/// before for every name it looks up, which holds because those names are ASCII.
|
||||
#[test]
|
||||
fn match_names_compare_as_the_latin1_decoding_did() {
|
||||
/// The Latin-1 decoding the emitter used before.
|
||||
fn old_tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let d = c.bytes()?;
|
||||
Some(d.iter().take_while(|b| **b != 0).map(|b| char::from(*b)).collect())
|
||||
}
|
||||
let mut wanted: Vec<&str> = GROUP_ORDER.to_vec();
|
||||
wanted.extend(PropKind::ALL.iter().map(|k| k.match_name()));
|
||||
wanted.extend(["ADBE Time Remapping", "ADBE Transform Group", "ADBE Group End"]);
|
||||
assert!(wanted.iter().all(|n| n.is_ascii()));
|
||||
let mut chunks: Vec<Chunk<'static>> = wanted.iter().map(|n| Chunk::data(*b"tdmn", format!("{n}\0\0junk").into_bytes())).collect();
|
||||
chunks.extend([
|
||||
Chunk::data(*b"tdmn", Vec::new()),
|
||||
Chunk::data(*b"tdmn", b"ADBE Position".to_vec()),
|
||||
Chunk::data(*b"tdmn", b"ADBE Position_0\0".to_vec()),
|
||||
Chunk::data(*b"tdmn", b"ADBE Opacit\xe9\0".to_vec()),
|
||||
Chunk::data(*b"tdmn", b"\xc3\x84DBE Scale\0".to_vec()),
|
||||
Chunk::data(*b"tdmn", b"\0ADBE Scale".to_vec()),
|
||||
Chunk::list(*b"tdmn", Vec::new()),
|
||||
]);
|
||||
for c in &chunks {
|
||||
for n in &wanted {
|
||||
assert_eq!(is_tdmn(c, n), old_tdmn_name(c).as_deref() == Some(*n), "{c:?} {n}");
|
||||
let key = tdmn_name(c).unwrap_or_default().into_bytes();
|
||||
assert_eq!(key == n.as_bytes(), old_tdmn_name(c).as_deref() == Some(*n), "{c:?} {n}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `fill_key_list`, which the time remap and the Transform keys use, writes the counts and
|
||||
/// replaces the records, or adds them when the list has none.
|
||||
#[test]
|
||||
fn fill_key_list_writes_counts_and_records() {
|
||||
let lhd3 = || Chunk::data(*b"lhd3", vec![0; 52]);
|
||||
let mut want_lhd3 = vec![0; 52];
|
||||
crate::export::synth::put_key_counts(&mut want_lhd3, 3, 48).expect("counts");
|
||||
for start in [vec![lhd3(), Chunk::data(*b"ldat", vec![9; 4])], vec![lhd3()]] {
|
||||
let mut list = Chunk::list(*b"list", start);
|
||||
fill_key_list(&mut list, vec![7; 144], 3, 48).expect("set");
|
||||
assert_eq!(list.children(), &[Chunk::data(*b"lhd3", want_lhd3.clone()), Chunk::data(*b"ldat", vec![7; 144])]);
|
||||
}
|
||||
let mut no_header = Chunk::list(*b"list", Vec::new());
|
||||
assert!(fill_key_list(&mut no_header, Vec::new(), 0, 48).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,3 +707,99 @@ pub(crate) static FX_DEFS: &[FxDef] = &[
|
||||
p(BUILT_IN, 9, &[], None, None, None, 0x00000000),
|
||||
]),
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::container::effect_map::by_match_name;
|
||||
use effectcraft_project::ParamUi;
|
||||
|
||||
/// Effect parameters whose hard range (`ParamUi::Slider` min..max, which `prop.set` and the
|
||||
/// value editors clamp to) is still narrower than After Effects' recorded valid range, each
|
||||
/// with the open issue that tracks it: (effect, parameter, issue). Remove a row when its
|
||||
/// issue is fixed; the test fails on a row that is no longer needed.
|
||||
#[rustfmt::skip]
|
||||
const KNOWN_NARROWER: &[(&str, &str, u32)] = &[
|
||||
("ec.blur.gaussian", "blurriness", 3460),
|
||||
("ec.blur.fastbox", "radius", 3461),
|
||||
("ec.blur.channel", "redBlurriness", 3462),
|
||||
("ec.blur.channel", "greenBlurriness", 3462),
|
||||
("ec.blur.channel", "blueBlurriness", 3462),
|
||||
("ec.blur.channel", "alphaBlurriness", 3462),
|
||||
("ec.obsolete.gaussianlegacy", "blurriness", 3463),
|
||||
("ec.perspective.dropshadow", "softness", 3464),
|
||||
("ec.blur.compound", "maximumBlur", 3465),
|
||||
("ec.blur.sharpen", "amount", 3466),
|
||||
("ec.blur.radial", "amount", 3467),
|
||||
("ec.blur.ccradial", "amount", 3468),
|
||||
("ec.distort.turbulentdisplace", "amount", 3469),
|
||||
("ec.time.pixelmotionblur", "shutterAngle", 3481),
|
||||
("ec.time.pixelmotionblur", "shutterSamples", 3482),
|
||||
("ec.noise.fractal", "subSettings/subInfluence", 3485),
|
||||
("ec.noise.fractal", "subSettings/subScaling", 3486),
|
||||
("ec.distort.ccpowerpin", "expandTop", 3492),
|
||||
("ec.distort.ccpowerpin", "expandLeft", 3492),
|
||||
("ec.distort.ccpowerpin", "expandRight", 3492),
|
||||
("ec.distort.ccpowerpin", "expandBottom", 3492),
|
||||
];
|
||||
|
||||
/// `a` is at most `b`, allowing for the `f32` the recorded bounds were read from.
|
||||
fn at_most(a: f64, b: f64) -> bool {
|
||||
a <= b + 1e-6 * a.abs().max(b.abs()).max(1.0)
|
||||
}
|
||||
|
||||
/// Every effect parameter the .aep table maps to a recorded After Effects definition accepts
|
||||
/// at least After Effects' valid range, converted to EffectCraft's units the way the importer
|
||||
/// converts values (`Conv::number_scale`). Only `ParamUi::Slider` limits values (`prop.set`,
|
||||
/// the Effect Controls and Timeline editors); other controls take any number. A mapping with
|
||||
/// a declared narrower range (`ParamMap::limit`) must match the effect's range instead.
|
||||
#[test]
|
||||
fn effect_hard_ranges_cover_recorded_after_effects_ranges() {
|
||||
let mut problems = Vec::new();
|
||||
let mut narrower = Vec::new();
|
||||
for fx in FX_DEFS {
|
||||
let Some(map) = by_match_name(fx.match_name) else { continue };
|
||||
let Some(spec) = effectcraft_effects::find(map.effect) else {
|
||||
problems.push(format!("{}: no effect {}", fx.match_name, map.effect));
|
||||
continue;
|
||||
};
|
||||
for pm in map.params {
|
||||
let Some(scale) = pm.conv.number_scale() else { continue };
|
||||
let at = format!("{} {}", map.effect, pm.target);
|
||||
let Some(ps) = spec.params.iter().find(|p| p.id == pm.target) else {
|
||||
problems.push(format!("{at}: not a parameter of the effect"));
|
||||
continue;
|
||||
};
|
||||
// Other controls take any number.
|
||||
let ParamUi::Slider { min, max, .. } = &ps.ui else { continue };
|
||||
let Some(def) = fx.params.get(pm.index) else {
|
||||
problems.push(format!("{at}: no recorded definition at parT {}", pm.index));
|
||||
continue;
|
||||
};
|
||||
let (Some(lo), Some(hi)) = (def.valid_min, def.valid_max) else {
|
||||
problems.push(format!("{at}: no recorded valid range"));
|
||||
continue;
|
||||
};
|
||||
let (lo, hi) = (lo * scale, hi * scale);
|
||||
if let Some(limit) = pm.limit {
|
||||
if limit != (*min, *max) {
|
||||
problems.push(format!("{at}: declared limit {limit:?} is not the effect's range {min}..{max}"));
|
||||
}
|
||||
} else if !(at_most(*min, lo) && at_most(hi, *max)) {
|
||||
narrower.push((map.effect, pm.target, format!("{at}: {min}..{max} excludes After Effects' {lo}..{hi}")));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (effect, param, why) in &narrower {
|
||||
if !KNOWN_NARROWER.iter().any(|(e, p, _)| e == effect && p == param) {
|
||||
problems.push(why.clone());
|
||||
}
|
||||
}
|
||||
for (effect, param, issue) in KNOWN_NARROWER {
|
||||
if !narrower.iter().any(|(e, p, _)| e == effect && p == param) {
|
||||
problems.push(format!("{effect} {param}: covers After Effects' range now (or is not mapped); remove it from KNOWN_NARROWER (#{issue})"));
|
||||
}
|
||||
}
|
||||
assert!(problems.is_empty(), "{}", problems.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
use crate::Chunk;
|
||||
use crate::effect_map::{Conv, by_match_name};
|
||||
use crate::export::fx_defs::{BUILT_IN, FxDef, PDef};
|
||||
use crate::export::synth::{KeyTemplate, NO_NAME, RecSpec, class, tdmn, tdsn};
|
||||
use crate::export::synth::{GROUP_END, KeyTemplate, NO_NAME, RecSpec, class, tdmn, tdsn, utf8_in};
|
||||
use crate::export::tree::Fixed;
|
||||
use crate::{CURVE_IDENTITY, CurvesData, MeshData};
|
||||
|
||||
/// The layer a prototype's layer parameters name when their default is the owning layer; the
|
||||
@@ -37,12 +38,6 @@ pub(crate) fn value_spec(code: u8, range: Option<(f64, f64)>) -> Option<RecSpec>
|
||||
})
|
||||
}
|
||||
|
||||
fn put(b: &mut [u8], at: usize, bytes: &[u8]) {
|
||||
if let Some(dst) = b.get_mut(at..at + bytes.len()) {
|
||||
dst.copy_from_slice(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
fn fixed(v: f64) -> [u8; 4] {
|
||||
((v * 65536.0).round().clamp(f64::from(i32::MIN), f64::from(i32::MAX)) as i32).to_be_bytes()
|
||||
}
|
||||
@@ -53,83 +48,88 @@ fn fixed(v: f64) -> [u8; 4] {
|
||||
/// display 124; fixed and integer: 124 / 128 / 132 / 136, default 140, display 144). Every other
|
||||
/// byte is zero (the switches at 48 are not needed: s12-e2-nofl).
|
||||
pub(crate) fn pard(p: &PDef, popup_items: Option<u16>) -> Vec<u8> {
|
||||
let mut b = vec![0u8; 148];
|
||||
put(&mut b, 12, &u32::from(p.code).to_be_bytes());
|
||||
pard_layout(p, popup_items).finish(|| format!("pard (type {})", p.code))
|
||||
}
|
||||
|
||||
/// The 148-byte `pard` layout of a parameter definition: type, name and defaults.
|
||||
fn pard_layout(p: &PDef, popup_items: Option<u16>) -> Fixed {
|
||||
let mut b = Fixed::zeroed(148);
|
||||
b.put(12, &u32::from(p.code).to_be_bytes());
|
||||
let d = |i: usize| p.default.get(i).copied().unwrap_or(0.0);
|
||||
// After Effects takes the default of a parameter without a value record from here (s8-e1:
|
||||
// the copies below are the ones it reads).
|
||||
match p.code {
|
||||
10 => {
|
||||
put(&mut b, 56, &d(0).to_be_bytes());
|
||||
b.put(56, &d(0).to_be_bytes());
|
||||
// The default again as `f32` at 120, the display word (decimals) at 124.
|
||||
put(&mut b, 120, &(d(0) as f32).to_be_bytes());
|
||||
put(&mut b, 124, &p.display.to_be_bytes());
|
||||
b.put(120, &(d(0) as f32).to_be_bytes());
|
||||
b.put(124, &p.display.to_be_bytes());
|
||||
}
|
||||
2 => put(&mut b, 56, &fixed(d(0))),
|
||||
2 => b.put(56, &fixed(d(0))),
|
||||
// An angle: the default again at 60.
|
||||
3 => {
|
||||
put(&mut b, 56, &fixed(d(0)));
|
||||
put(&mut b, 60, &fixed(d(0)));
|
||||
b.put(56, &fixed(d(0)));
|
||||
b.put(60, &fixed(d(0)));
|
||||
}
|
||||
1 => put(&mut b, 56, &(d(0).round() as i32).to_be_bytes()),
|
||||
1 => b.put(56, &(d(0).round() as i32).to_be_bytes()),
|
||||
// A checkbox: the default again as a byte at 60.
|
||||
4 => {
|
||||
put(&mut b, 56, &(d(0).round().max(0.0) as u32).to_be_bytes());
|
||||
put(&mut b, 60, &[u8::from(d(0) != 0.0)]);
|
||||
b.put(56, &(d(0).round().max(0.0) as u32).to_be_bytes());
|
||||
b.put(60, &[u8::from(d(0) != 0.0)]);
|
||||
}
|
||||
// A popup: the default again as `u16` at 62 (the item count is at 60).
|
||||
7 => {
|
||||
let sel = d(0).round().clamp(0.0, f64::from(u16::MAX));
|
||||
put(&mut b, 56, &(sel as u32).to_be_bytes());
|
||||
put(&mut b, 62, &(sel as u16).to_be_bytes());
|
||||
b.put(56, &(sel as u32).to_be_bytes());
|
||||
b.put(62, &(sel as u16).to_be_bytes());
|
||||
}
|
||||
6 => {
|
||||
// Fractions of the layer at 56 / 60 and the same in percent at 68 / 72.
|
||||
put(&mut b, 56, &fixed(d(0)));
|
||||
put(&mut b, 60, &fixed(d(1)));
|
||||
put(&mut b, 68, &fixed(d(0) * 100.0));
|
||||
put(&mut b, 72, &fixed(d(1) * 100.0));
|
||||
b.put(56, &fixed(d(0)));
|
||||
b.put(60, &fixed(d(1)));
|
||||
b.put(68, &fixed(d(0) * 100.0));
|
||||
b.put(72, &fixed(d(1) * 100.0));
|
||||
}
|
||||
5 => {
|
||||
// ARGB at 56 and the same at 60.
|
||||
let c: Vec<u8> = (0..4).map(|i| d(i).round().clamp(0.0, 255.0) as u8).collect();
|
||||
put(&mut b, 56, &c);
|
||||
put(&mut b, 60, &c);
|
||||
b.put(56, &c);
|
||||
b.put(60, &c);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if p.code == 7 {
|
||||
let n = popup_items.unwrap_or_else(|| u16::try_from(p.display).unwrap_or(0));
|
||||
put(&mut b, 60, &n.to_be_bytes());
|
||||
b.put(60, &n.to_be_bytes());
|
||||
}
|
||||
match p.code {
|
||||
10 => {
|
||||
if let Some(m) = p.valid_min {
|
||||
put(&mut b, 104, &(m as f32).to_be_bytes());
|
||||
b.put(104, &(m as f32).to_be_bytes());
|
||||
}
|
||||
if let Some(m) = p.valid_max {
|
||||
put(&mut b, 108, &(m as f32).to_be_bytes());
|
||||
b.put(108, &(m as f32).to_be_bytes());
|
||||
}
|
||||
if let Some((lo, hi)) = p.range {
|
||||
put(&mut b, 112, &(lo as f32).to_be_bytes());
|
||||
put(&mut b, 116, &(hi as f32).to_be_bytes());
|
||||
b.put(112, &(lo as f32).to_be_bytes());
|
||||
b.put(116, &(hi as f32).to_be_bytes());
|
||||
}
|
||||
}
|
||||
1 | 2 => {
|
||||
let enc = |v: f64| if p.code == 2 { fixed(v) } else { (v.round() as i32).to_be_bytes() };
|
||||
if let Some(m) = p.valid_min {
|
||||
put(&mut b, 124, &enc(m));
|
||||
b.put(124, &enc(m));
|
||||
}
|
||||
if let Some(m) = p.valid_max {
|
||||
put(&mut b, 128, &enc(m));
|
||||
b.put(128, &enc(m));
|
||||
}
|
||||
if let Some((lo, hi)) = p.range {
|
||||
put(&mut b, 132, &enc(lo));
|
||||
put(&mut b, 136, &enc(hi));
|
||||
b.put(132, &enc(lo));
|
||||
b.put(136, &enc(hi));
|
||||
}
|
||||
// The default again at 140, the display word (decimals, percent) at 144.
|
||||
put(&mut b, 140, &enc(d(0)));
|
||||
put(&mut b, 144, &p.display.to_be_bytes());
|
||||
b.put(140, &enc(d(0)));
|
||||
b.put(144, &p.display.to_be_bytes());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ fn data_record(data: Vec<u8>) -> [Chunk<'static>; 2] {
|
||||
/// group (records only for layer parameters, groups, buttons and arbitrary data, the built-in
|
||||
/// group) and `pgui` (zero).
|
||||
pub(crate) fn default_sspc(fx: &FxDef) -> Chunk<'static> {
|
||||
let fnam = Chunk { id: *b"fnam", body: crate::Body::Chunks(vec![Chunk::data(*b"Utf8", fx.name.as_bytes().to_vec())]), pad: None };
|
||||
let fnam = utf8_in(*b"fnam", fx.name);
|
||||
let count = u32::try_from(fx.params.len()).unwrap_or(u32::MAX);
|
||||
let mut part = vec![Chunk::data(*b"parn", count.to_be_bytes().to_vec())];
|
||||
let mut values = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn(NO_NAME)];
|
||||
@@ -235,11 +235,11 @@ pub(crate) fn default_sspc(fx: &FxDef) -> Chunk<'static> {
|
||||
if matches!(p.code, 4 | 7 | 15) {
|
||||
// Checkboxes, popups and buttons have a `pdnm` (their label or items); its text may
|
||||
// be empty.
|
||||
part.push(Chunk { id: *b"pdnm", body: crate::Body::Chunks(vec![Chunk::data(*b"Utf8", Vec::new())]), pad: None });
|
||||
part.push(utf8_in(*b"pdnm", ""));
|
||||
}
|
||||
if p.id == BUILT_IN {
|
||||
values.push(tdmn(&record));
|
||||
values.push(Chunk::list(*b"tdgp", vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn(NO_NAME), tdmn("ADBE Group End")]));
|
||||
values.push(Chunk::list(*b"tdgp", vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn(NO_NAME), tdmn(GROUP_END)]));
|
||||
continue;
|
||||
}
|
||||
match p.code {
|
||||
@@ -265,6 +265,24 @@ pub(crate) fn default_sspc(fx: &FxDef) -> Chunk<'static> {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
values.push(tdmn("ADBE Group End"));
|
||||
values.push(tdmn(GROUP_END));
|
||||
Chunk::list(*b"sspc", vec![fnam, Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values), Chunk::data(*b"pgui", vec![0u8; 16])])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::export::fx_defs::FX_DEFS;
|
||||
|
||||
/// The `pard` of every parameter of the effect table fits its 148 bytes.
|
||||
#[test]
|
||||
fn every_parameter_definition_fits() {
|
||||
for fx in FX_DEFS {
|
||||
for (i, p) in fx.params.iter().enumerate() {
|
||||
let b = pard_layout(p, popup_items(fx, i));
|
||||
assert!(b.error().is_none(), "{} {}", fx.match_name, i);
|
||||
assert_eq!(b.finish(String::new).len(), 148);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
//! Key lists shared by the exporters: the times of a property's keys in the file's units, the
|
||||
//! spatial key record, and the rewrite of a key list (`LIST list`: `lhd3` + `ldat`, aep-format.md
|
||||
//! 3.5).
|
||||
|
||||
use effectcraft_keyframe::Keyframe;
|
||||
|
||||
use crate::Chunk;
|
||||
use crate::export::plan::KeyPlan;
|
||||
use crate::export::report::{Collector, LossCategory};
|
||||
use crate::export::timebase::TimeBase;
|
||||
use crate::export::tree::{R, child_data, kids_mut, list_mut, put, put_f64, put_u8, put_u16, put_u32, tpl};
|
||||
|
||||
/// The keys of a property at their times in the file's units, in time order. A key that does not
|
||||
/// fall on the time base is reported as moved; keys that end up at the same time are merged (the
|
||||
/// first one is kept) and reported once. `noun` names the key in the report ("key", "path key").
|
||||
pub(crate) fn timed_keys<'k>(keys: &'k [Keyframe], tb: &TimeBase, what: &str, noun: &str, col: &mut Collector) -> Vec<(i64, &'k Keyframe)> {
|
||||
let mut timed: Vec<(i64, &Keyframe)> = Vec::with_capacity(keys.len());
|
||||
for k in keys {
|
||||
let (u, inexact) = tb.units(k.time);
|
||||
if inexact {
|
||||
col.lose(LossCategory::RoundedTimes, format!("{what}: {noun} at {:.4} s moved to the time base", k.time.seconds()));
|
||||
}
|
||||
timed.push((u, k));
|
||||
}
|
||||
timed.sort_by_key(|(u, _)| *u);
|
||||
let before = timed.len();
|
||||
timed.dedup_by_key(|(u, _)| *u);
|
||||
if timed.len() != before {
|
||||
col.lose(LossCategory::ApproximatedKeyframes, format!("{what}: {noun}s at the same time were merged"));
|
||||
}
|
||||
timed
|
||||
}
|
||||
|
||||
/// A key of a point (flags `0x0007`, `u32@8` the automatic tangent switch; the spatial layout of
|
||||
/// a 2D Position, 853) or a colour (flags `0x0001`, 854): the temporal ease of a point at 24..55,
|
||||
/// then the `n` values at 56 and, for a point, the spatial in and out tangents after them.
|
||||
pub(crate) fn spatial_record(k: &KeyPlan, n: usize, point: bool, size: usize) -> R<Vec<u8>> {
|
||||
let mut r = vec![0u8; size];
|
||||
put(&mut r, 0, &k.time.to_be_bytes())?;
|
||||
put_u8(&mut r, 4, k.in_interp)?;
|
||||
put_u8(&mut r, 5, k.out_interp)?;
|
||||
let base: u16 = if point { 0x0007 } else { 0x0001 };
|
||||
put_u16(&mut r, 6, base | (u16::from(k.label) << 6))?;
|
||||
if point {
|
||||
put_u32(&mut r, 8, u32::from(k.spatial_auto))?;
|
||||
let (i, o) = (k.in_ease.first().copied().unwrap_or_default(), k.out_ease.first().copied().unwrap_or_default());
|
||||
put_f64(&mut r, 24, i.speed)?;
|
||||
put_f64(&mut r, 32, i.influence)?;
|
||||
put_f64(&mut r, 40, o.speed)?;
|
||||
put_f64(&mut r, 48, o.influence)?;
|
||||
}
|
||||
for j in 0..n {
|
||||
put_f64(&mut r, 56 + 8 * j, k.value.get(j).copied().unwrap_or(0.0))?;
|
||||
if point {
|
||||
put_f64(&mut r, 56 + 8 * n + 8 * j, k.spatial_in.get(j).copied().unwrap_or(0.0))?;
|
||||
put_f64(&mut r, 56 + 16 * n + 8 * j, k.spatial_out.get(j).copied().unwrap_or(0.0))?;
|
||||
}
|
||||
}
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
/// Fills a key list (`LIST list`) with `count` records of `size` bytes: the count words of `lhd3`
|
||||
/// and `ldat` (added when the list has none).
|
||||
pub(crate) fn fill_key_list(list: &mut Chunk<'static>, records: Vec<u8>, count: usize, size: usize) -> R<()> {
|
||||
let n = u32::try_from(count).map_err(|_| tpl("too many keys"))?;
|
||||
let size = u32::try_from(size).map_err(|_| tpl("record size"))?;
|
||||
crate::export::synth::put_key_counts(child_data(list, b"lhd3")?, n, size)?;
|
||||
let kids = kids_mut(list)?;
|
||||
match kids.iter_mut().find(|c| c.is(b"ldat")) {
|
||||
Some(c) => *c = Chunk::data(*b"ldat", records),
|
||||
None => kids.push(Chunk::data(*b"ldat", records)),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Rewrites the key list of a keyed property record (`LIST tdbs`), see [`fill_key_list`].
|
||||
pub(crate) fn set_key_list(tdbs: &mut Chunk<'static>, records: Vec<u8>, count: usize, size: usize) -> R<()> {
|
||||
fill_key_list(list_mut(tdbs, b"list")?, records, count, size)
|
||||
}
|
||||
|
||||
/// Puts the key list `list` in the place of the static value (`cdat`) of a property record.
|
||||
pub(crate) fn replace_cdat(tdbs: &mut Chunk<'static>, list: Chunk<'static>) -> R<()> {
|
||||
let slot = kids_mut(tdbs)?.iter_mut().find(|c| c.is(b"cdat")).ok_or_else(|| tpl("record without cdat"))?;
|
||||
*slot = list;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::export::synth::key_list;
|
||||
|
||||
/// Keys are timed sorted merged and reported.
|
||||
#[test]
|
||||
fn keys_are_timed_sorted_merged_and_reported() {
|
||||
use effectcraft_keyframe::Value;
|
||||
use effectcraft_time::{TICKS_PER_SECOND, Tick};
|
||||
let tb = TimeBase { frame_duration: 1024, timescale: 25600 };
|
||||
// Out of order; 1/3 s is not on the time base; two keys meet at 1 s (the first one kept).
|
||||
let keys = [
|
||||
Keyframe::new(Tick(TICKS_PER_SECOND), Value::Scalar(1.0)),
|
||||
Keyframe::new(Tick(TICKS_PER_SECOND / 3), Value::Scalar(2.0)),
|
||||
Keyframe::new(Tick(0), Value::Scalar(3.0)),
|
||||
Keyframe::new(Tick(TICKS_PER_SECOND), Value::Scalar(4.0)),
|
||||
];
|
||||
let mut col = Collector::default();
|
||||
let timed = timed_keys(&keys, &tb, "L", "path key", &mut col);
|
||||
let got: Vec<(i64, f64)> = timed.iter().map(|(u, k)| (*u, if let Value::Scalar(v) = k.value { v } else { f64::NAN })).collect();
|
||||
assert_eq!(got, [(0, 3.0), (8533, 2.0), (25600, 1.0)]);
|
||||
// The report lists its categories in a fixed order; one merge report for the pair.
|
||||
let report = col.finish();
|
||||
let lines: Vec<(LossCategory, &str)> = report.losses.iter().flat_map(|l| l.details.iter().map(move |d| (l.category, d.as_str()))).collect();
|
||||
assert_eq!(
|
||||
lines,
|
||||
[
|
||||
(LossCategory::ApproximatedKeyframes, "L: path keys at the same time were merged"),
|
||||
(LossCategory::RoundedTimes, "L: path key at 0.3333 s moved to the time base"),
|
||||
]
|
||||
);
|
||||
// No keys, no report.
|
||||
let mut col = Collector::default();
|
||||
assert!(timed_keys(&[], &tb, "L", "key", &mut col).is_empty());
|
||||
assert!(col.finish().losses.is_empty());
|
||||
}
|
||||
|
||||
/// Two keys at different times that round to the same time unit are merged too: the first
|
||||
/// one is kept, and both the rounding and the merge are reported.
|
||||
#[test]
|
||||
fn keys_that_round_to_the_same_time_are_merged() {
|
||||
use effectcraft_keyframe::Value;
|
||||
use effectcraft_time::Tick;
|
||||
let tb = TimeBase { frame_duration: 1024, timescale: 25600 };
|
||||
// One tick is far below one unit (1/25600 s): it rounds to unit 0, where the first key is.
|
||||
let keys = [Keyframe::new(Tick(0), Value::Scalar(1.0)), Keyframe::new(Tick(1), Value::Scalar(2.0))];
|
||||
let mut col = Collector::default();
|
||||
let timed = timed_keys(&keys, &tb, "L", "key", &mut col);
|
||||
let got: Vec<(i64, f64)> = timed.iter().map(|(u, k)| (*u, if let Value::Scalar(v) = k.value { v } else { f64::NAN })).collect();
|
||||
assert_eq!(got, [(0, 1.0)]);
|
||||
let report = col.finish();
|
||||
let lines: Vec<(LossCategory, &str)> = report.losses.iter().flat_map(|l| l.details.iter().map(move |d| (l.category, d.as_str()))).collect();
|
||||
assert_eq!(
|
||||
lines,
|
||||
[
|
||||
(LossCategory::ApproximatedKeyframes, "L: keys at the same time were merged"),
|
||||
(LossCategory::RoundedTimes, "L: key at 0.0000 s moved to the time base"),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// A key list is filled and replaces the value.
|
||||
#[test]
|
||||
fn a_key_list_is_filled_and_replaces_the_value() {
|
||||
let mut list = Chunk::list(*b"list", vec![Chunk::data(*b"lhd3", vec![0; 52])]);
|
||||
fill_key_list(&mut list, vec![7; 96], 2, 48).unwrap();
|
||||
let h = list.child(b"lhd3").and_then(|c| c.bytes()).unwrap();
|
||||
assert_eq!((h[11], h[19]), (2, 48));
|
||||
assert_eq!(list.child(b"ldat").and_then(|c| c.bytes()).map(<[u8]>::len), Some(96));
|
||||
// A second fill replaces the records instead of adding a second `ldat`.
|
||||
fill_key_list(&mut list, vec![1; 48], 1, 48).unwrap();
|
||||
assert_eq!(list.children().iter().filter(|c| c.is(b"ldat")).count(), 1);
|
||||
|
||||
let mut rec = Chunk::list(*b"tdbs", vec![Chunk::data(*b"tdb4", vec![0; 124]), Chunk::data(*b"cdat", vec![0; 8])]);
|
||||
replace_cdat(&mut rec, key_list(48, 0, Vec::new())).unwrap();
|
||||
assert!(rec.child(b"cdat").is_none() && rec.child_list(b"list").is_some());
|
||||
// A record without a value is an error, not a quiet no-op.
|
||||
assert!(replace_cdat(&mut rec, key_list(48, 0, Vec::new())).is_err());
|
||||
set_key_list(&mut rec, vec![0; 48], 1, 48).unwrap();
|
||||
assert!(set_key_list(&mut Chunk::list(*b"tdbs", Vec::new()), Vec::new(), 0, 48).is_err());
|
||||
}
|
||||
|
||||
/// A spatial record holds the point layout.
|
||||
#[test]
|
||||
fn a_spatial_record_holds_the_point_layout() {
|
||||
let k = KeyPlan {
|
||||
time: 5,
|
||||
value: vec![1.0, 2.0],
|
||||
in_interp: 2,
|
||||
out_interp: 1,
|
||||
in_ease: Vec::new(),
|
||||
out_ease: Vec::new(),
|
||||
spatial_in: [3.0; 3],
|
||||
spatial_out: [4.0; 3],
|
||||
spatial_auto: true,
|
||||
roving: false,
|
||||
label: 1,
|
||||
};
|
||||
let r = spatial_record(&k, 2, true, 56 + 24 * 2).unwrap();
|
||||
assert_eq!(&r[..12], &[0, 0, 0, 5, 2, 1, 0, 0x47, 0, 0, 0, 1]);
|
||||
assert_eq!(&r[64..72], &2.0f64.to_be_bytes());
|
||||
assert_eq!(&r[96..104], &4.0f64.to_be_bytes());
|
||||
// A colour has no tangents and flags 0x0001.
|
||||
let c = spatial_record(&k, 2, false, 56 + 24 * 2).unwrap();
|
||||
assert_eq!((c[7], c[11]), (0x41, 0));
|
||||
assert!(c[72..].iter().all(|b| *b == 0));
|
||||
// A record shorter than its layout is an error.
|
||||
assert!(spatial_record(&k, 2, true, 64).is_err());
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,11 @@ use crate::Chunk;
|
||||
use effectcraft_keyframe::{Ease, Interp, ShapePath, Value};
|
||||
use effectcraft_project::{FeatherFalloff, GroupKind, Layer, MaskMode, MaskMotionBlur, PropGroup};
|
||||
|
||||
use crate::export::keys::{set_key_list, timed_keys};
|
||||
use crate::export::plan::{CompPlan, EaseSlot, KeyPlan, LIMIT, cut_name};
|
||||
use crate::export::report::{Collector, LossCategory};
|
||||
use crate::export::tree::{R, child_data, child_mut, kids_mut, list_mut, put_f32, put_f64, put_i32, put_u8, put_u16, put_u32, tpl};
|
||||
use crate::export::synth::GROUP_END;
|
||||
use crate::export::tree::{Fixed, R, child_data, child_mut, kids_mut, list_mut, put_f32, put_f64, put_i32, put_u8, put_u16, put_u32, split_group, tpl};
|
||||
|
||||
/// The most vertices one mask path may have (as the importer).
|
||||
pub(crate) const MAX_VERTICES: usize = 65_536;
|
||||
@@ -179,20 +181,7 @@ fn plan_mask(g: &PropGroup, size: (u32, u32), cp: &CompPlan, what: &str, col: &m
|
||||
}
|
||||
// The path and its keys.
|
||||
let mut path_keys: Vec<PathKeyPlan> = Vec::new();
|
||||
let mut keys: Vec<(i64, &effectcraft_keyframe::Keyframe)> = Vec::new();
|
||||
for k in &path_prop.keys {
|
||||
let (u, inexact) = cp.tb.units(k.time);
|
||||
if inexact {
|
||||
col.lose(LossCategory::RoundedTimes, format!("{what}: path key at {:.4} s moved to the time base", k.time.seconds()));
|
||||
}
|
||||
keys.push((u, k));
|
||||
}
|
||||
keys.sort_by_key(|(u, _)| *u);
|
||||
let before = keys.len();
|
||||
keys.dedup_by_key(|(u, _)| *u);
|
||||
if keys.len() != before {
|
||||
col.lose(LossCategory::ApproximatedKeyframes, format!("{what}: path keys at the same time were merged"));
|
||||
}
|
||||
let keys = timed_keys(&path_prop.keys, &cp.tb, what, "path key", col);
|
||||
let side = |i: Interp| -> u8 {
|
||||
match i {
|
||||
Interp::Linear => 1,
|
||||
@@ -288,20 +277,7 @@ fn plan_mask(g: &PropGroup, size: (u32, u32), cp: &CompPlan, what: &str, col: &m
|
||||
|
||||
/// Feather keys (plain template, two components, speed in pixels per second).
|
||||
fn plan_feather_keys(src: &[effectcraft_keyframe::Keyframe], cp: &CompPlan, what: &str, col: &mut Collector) -> Vec<KeyPlan> {
|
||||
let mut keys: Vec<(i64, &effectcraft_keyframe::Keyframe)> = Vec::with_capacity(src.len());
|
||||
for k in src {
|
||||
let (u, inexact) = cp.tb.units(k.time);
|
||||
if inexact {
|
||||
col.lose(LossCategory::RoundedTimes, format!("{what}: feather key at {:.4} s moved to the time base", k.time.seconds()));
|
||||
}
|
||||
keys.push((u, k));
|
||||
}
|
||||
keys.sort_by_key(|(u, _)| *u);
|
||||
let before = keys.len();
|
||||
keys.dedup_by_key(|(u, _)| *u);
|
||||
if keys.len() != before {
|
||||
col.lose(LossCategory::ApproximatedKeyframes, format!("{what}: feather keys at the same time were merged"));
|
||||
}
|
||||
let keys = timed_keys(src, &cp.tb, what, "feather key", col);
|
||||
let mut out = Vec::with_capacity(keys.len());
|
||||
let beyond = std::cell::Cell::new(false);
|
||||
for (u, k) in &keys {
|
||||
@@ -381,11 +357,6 @@ pub(crate) struct MaskProtos {
|
||||
pub keyed_feather: Chunk<'static>,
|
||||
}
|
||||
|
||||
pub(crate) fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let d = c.bytes()?;
|
||||
Some(d.iter().take_while(|b| **b != 0).map(|b| char::from(*b)).collect())
|
||||
}
|
||||
|
||||
/// The limit of a mask's feather and expansion (`tduM` 32 000, 091).
|
||||
const MASK_LIMIT: f64 = 32_000.0;
|
||||
|
||||
@@ -394,9 +365,25 @@ const MASK_LIMIT: f64 = 32_000.0;
|
||||
/// s13-m1), byte 3 `0x01` (`0x09` once the path is open), the box at 4..19 (written per shape),
|
||||
/// byte 20 1.
|
||||
pub(crate) fn shph() -> Vec<u8> {
|
||||
let mut b = vec![0u8; 24];
|
||||
let _ = crate::export::tree::put(&mut b, 0, &[0xb3, 0xde, 0x02, 0x01]);
|
||||
let _ = put_u8(&mut b, 20, 1);
|
||||
shph_layout().finish(|| "shph".to_string())
|
||||
}
|
||||
|
||||
/// The 24-byte `shph` layout of a closed path with a unit box.
|
||||
fn shph_layout() -> Fixed {
|
||||
let mut b = Fixed::zeroed(24);
|
||||
b.put(0, &[0xb3, 0xde, 0x02, 0x01]);
|
||||
b.put(20, &[1]);
|
||||
b
|
||||
}
|
||||
|
||||
/// The two prototype records of a keyed path (093): 64 bytes each, flags `0x0001`, the `f64` at
|
||||
/// 16 1 in the first (the rest is zero: its last bytes were uninitialised).
|
||||
fn path_key_records() -> Fixed {
|
||||
let mut b = Fixed::zeroed(128);
|
||||
for at in [6, 64 + 6] {
|
||||
b.put(at, &0x0001u16.to_be_bytes());
|
||||
}
|
||||
b.put(16, &1.0f64.to_be_bytes());
|
||||
b
|
||||
}
|
||||
|
||||
@@ -413,15 +400,7 @@ impl MaskProtos {
|
||||
let path_rec = |keyed: bool| {
|
||||
let mut kids = vec![state(), tdsn(NO_NAME), Chunk::data(*b"tdb4", tdb4(&path, keyed, 25_600))];
|
||||
if keyed {
|
||||
// Path keys are 64-byte records: flags `0x0001`, the `f64` at 16 1 on the first
|
||||
// key (093; the rest of the record is zero: its last bytes were uninitialised).
|
||||
let mut first = vec![0u8; 64];
|
||||
let mut later = vec![0u8; 64];
|
||||
for r in [&mut first, &mut later] {
|
||||
let _ = put_u16(r, 6, 0x0001);
|
||||
}
|
||||
let _ = put_f64(&mut first, 16, 1.0);
|
||||
kids.push(key_list(64, 2, [first, later].concat()));
|
||||
kids.push(key_list(64, 2, path_key_records().finish(|| "the keyed path records".to_string())));
|
||||
} else {
|
||||
kids.push(Chunk::data(*b"cdat", vec![0u8; 4]));
|
||||
}
|
||||
@@ -444,7 +423,7 @@ impl MaskProtos {
|
||||
tdbs(&opacity, false, 25_600),
|
||||
tdmn("ADBE Mask Offset"),
|
||||
tdbs(&offset, false, 25_600),
|
||||
tdmn("ADBE Group End"),
|
||||
tdmn(GROUP_END),
|
||||
],
|
||||
);
|
||||
MaskProtos {
|
||||
@@ -453,7 +432,7 @@ impl MaskProtos {
|
||||
atom_name: tdmn("ADBE Mask Atom"),
|
||||
mkif: Chunk::data(*b"mkif", vec![0u8; 48]),
|
||||
atom,
|
||||
group_end: tdmn("ADBE Group End"),
|
||||
group_end: tdmn(GROUP_END),
|
||||
keyed_path: path_rec(true),
|
||||
keyed_feather: tdbs(&feather, true, 25_600),
|
||||
}
|
||||
@@ -485,27 +464,21 @@ fn build_atom(t: &MaskProtos, m: &MaskPlan, size: (u32, u32)) -> R<Chunk<'static
|
||||
let tdsn = child_mut(&mut atom, b"tdsn")?;
|
||||
crate::export::tree::set_utf8(tdsn, &m.name)?;
|
||||
}
|
||||
let kids = kids_mut(&mut atom)?;
|
||||
let first = kids.iter().position(|c| c.is(b"tdmn")).ok_or_else(|| tpl("empty mask atom"))?;
|
||||
let header: Vec<Chunk<'static>> = kids.drain(..first).collect();
|
||||
let mut pairs: Vec<(String, [Chunk<'static>; 2])> = Vec::new();
|
||||
let mut end: Option<Chunk<'static>> = None;
|
||||
let mut it = std::mem::take(kids).into_iter();
|
||||
while let Some(c) = it.next() {
|
||||
let name = tdmn_name(&c).unwrap_or_default();
|
||||
if name == "ADBE Group End" {
|
||||
end = Some(c);
|
||||
continue;
|
||||
}
|
||||
let node = it.next().ok_or_else(|| tpl("mask match name without a node"))?;
|
||||
pairs.push((name, [c, node]));
|
||||
}
|
||||
let end = end.ok_or_else(|| tpl("mask atom without its end"))?;
|
||||
let mut out = header;
|
||||
for (name, [tdmn, mut node]) in pairs {
|
||||
let (mut out, entries) = split_group(kids_mut(&mut atom)?)?;
|
||||
let mut has_shape = false;
|
||||
for (name, entry) in entries {
|
||||
// The closing Group End (no node) is kept as it is.
|
||||
let [tdmn, mut node]: [Chunk<'static>; 2] = match entry.try_into() {
|
||||
Ok(pair) => pair,
|
||||
Err(end) => {
|
||||
out.extend(end);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let keep = match name.as_str() {
|
||||
"ADBE Mask Shape" => {
|
||||
build_shape(t, &mut node, m, size)?;
|
||||
has_shape = true;
|
||||
true
|
||||
}
|
||||
"ADBE Mask Feather" => {
|
||||
@@ -540,7 +513,10 @@ fn build_atom(t: &MaskProtos, m: &MaskPlan, size: (u32, u32)) -> R<Chunk<'static
|
||||
out.push(node);
|
||||
}
|
||||
}
|
||||
out.push(end);
|
||||
// A prototype without the path would drop every mask's shape.
|
||||
if !has_shape {
|
||||
return Err(tpl("mask atom without its path"));
|
||||
}
|
||||
*kids_mut(&mut atom)? = out;
|
||||
Ok(atom)
|
||||
}
|
||||
@@ -554,22 +530,6 @@ fn set_cdat(tdbs: &mut Chunk<'static>, values: &[f64]) -> R<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Rewrites a key list (`lhd3` count words and `ldat`).
|
||||
fn set_key_list(tdbs: &mut Chunk<'static>, records: Vec<u8>, count: usize, size: usize) -> R<()> {
|
||||
let list = list_mut(tdbs, b"list")?;
|
||||
let n = u32::try_from(count).map_err(|_| tpl("too many keys"))?;
|
||||
{
|
||||
let lhd3 = child_data(list, b"lhd3")?;
|
||||
crate::export::synth::put_key_counts(lhd3, n, u32::try_from(size).map_err(|_| tpl("record size"))?)?;
|
||||
}
|
||||
let ld = kids_mut(list)?;
|
||||
match ld.iter_mut().find(|c| c.is(b"ldat")) {
|
||||
Some(c) => *c = Chunk::data(*b"ldat", records),
|
||||
None => ld.push(Chunk::data(*b"ldat", records)),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn keyed_feather(t: &MaskProtos, keys: &[KeyPlan]) -> R<Chunk<'static>> {
|
||||
let mut tdbs = t.keyed_feather.clone();
|
||||
// The plain template with two components (208): 8 + 40 * 2 bytes.
|
||||
@@ -669,3 +629,37 @@ pub(crate) fn build_shap(proto: &Chunk<'static>, s: &ShapePlan) -> R<Chunk<'stat
|
||||
}
|
||||
Ok(shap)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::export::synth::is_tdmn;
|
||||
|
||||
/// A closed three-point mask.
|
||||
fn mask() -> MaskPlan {
|
||||
let shape = ShapePlan { bbox: [0.0, 0.0, 1.0, 1.0], open: false, points: vec![[0.0, 0.0]; 3] };
|
||||
MaskPlan {
|
||||
name: "M".into(),
|
||||
mode: 1,
|
||||
inverted: false,
|
||||
shape,
|
||||
path_keys: Vec::new(),
|
||||
feather: None,
|
||||
feather_keys: Vec::new(),
|
||||
opacity: None,
|
||||
expansion: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// An atom without its path is an error.
|
||||
#[test]
|
||||
fn an_atom_without_its_path_is_an_error() {
|
||||
let mut t = MaskProtos::build();
|
||||
assert!(build_atom(&t, &mask(), (100, 100)).is_ok());
|
||||
// Without the Mask Shape pair the path of every mask would be dropped quietly.
|
||||
let kids = kids_mut(&mut t.atom).unwrap();
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Mask Shape")).unwrap();
|
||||
kids.drain(at..at + 2);
|
||||
assert!(build_atom(&t, &mask(), (100, 100)).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ fn plan_transform(layer: &Layer, src: &LayerSrc, comp: &Comp, source_size: (u32,
|
||||
let cam_light = matches!(src, LayerSrc::Camera(_) | LayerSrc::Light(_));
|
||||
let is_shape = matches!(src, LayerSrc::Shape(_));
|
||||
let mut props = Vec::new();
|
||||
let at = PropAt { comp, comp_name, layer: &layer.name, source: source_size, text: is_text || cam_light || is_shape };
|
||||
let at = PropAt { comp, comp_name, layer: &layer.name, source: source_size, text: is_text || cam_light || is_shape, null: matches!(src, LayerSrc::Null) };
|
||||
if let Some(tr) = layer.transform() {
|
||||
for kind in PropKind::ALL {
|
||||
// A camera's or light's point of interest is After Effects' Anchor Point.
|
||||
@@ -1172,16 +1172,21 @@ struct PropAt<'a> {
|
||||
source: (u32, u32),
|
||||
/// The anchor is stored in pixels (text, camera, light and shape layers).
|
||||
text: bool,
|
||||
/// A null layer: an Anchor Point that is not written is its top-left corner (#3099).
|
||||
null: bool,
|
||||
}
|
||||
|
||||
/// What is written for transform property `p` (`kind`) of a layer: its value or keys in the
|
||||
/// stored unit and its expression; `None` when it is at After Effects' default and has neither.
|
||||
fn plan_prop(kind: PropKind, label: Option<&str>, p: &Property, at: PropAt<'_>, cp: &CompPlan, col: &mut Collector) -> Option<PropPlan> {
|
||||
let PropAt { comp, comp_name, layer, source, text } = at;
|
||||
let PropAt { comp, comp_name, layer, source, text, null } = at;
|
||||
// A text layer's anchor is stored in pixels, with the origin as its default (385).
|
||||
let (sw, sh) = if text { (1.0, 1.0) } else { (f64::from(source.0.max(1)), f64::from(source.1.max(1))) };
|
||||
let what = format!("{comp_name}: '{layer}' {}", label.unwrap_or(kind.match_name()));
|
||||
let dims = kind.dims();
|
||||
let default: Vec<f64> = match kind {
|
||||
PropKind::Anchor if text => vec![0.0, 0.0, 0.0],
|
||||
// After Effects 2026 reads a null's absent Anchor Point as `[0, 0]` (#3099).
|
||||
PropKind::Anchor if text || null => vec![0.0, 0.0, 0.0],
|
||||
PropKind::Anchor => vec![0.5, 0.5, 0.0],
|
||||
PropKind::Position => vec![f64::from(comp.width) / 2.0, f64::from(comp.height) / 2.0, 0.0],
|
||||
PropKind::Scale => vec![1.0, 1.0, 1.0],
|
||||
@@ -1319,7 +1324,7 @@ fn plan_prop(kind: PropKind, label: Option<&str>, p: &Property, at: PropAt<'_>,
|
||||
/// back disabled).
|
||||
fn plan_remap(p: &Property, comp: &Comp, cp: &CompPlan, layer: &str, comp_name: &str, col: &mut Collector) -> PropPlan {
|
||||
// Rotation has the same layout (one component, stored as is, not spatial).
|
||||
let at = PropAt { comp, comp_name, layer, source: (1, 1), text: false };
|
||||
let at = PropAt { comp, comp_name, layer, source: (1, 1), text: false, null: false };
|
||||
let planned = plan_prop(PropKind::Rotation, Some("Time Remap"), p, at, cp, col);
|
||||
col.exported.time_remaps += 1;
|
||||
let mut plan = planned.unwrap_or_else(|| PropPlan { kind: PropKind::Rotation, value: vec![0.0], keys: Vec::new(), expr: None });
|
||||
|
||||
@@ -7,8 +7,9 @@ use std::collections::BTreeMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Most example lines kept per loss category (the count is always exact).
|
||||
pub const MAX_DETAILS: usize = 20;
|
||||
/// Most example lines kept per loss category (the count is always exact); the same as the import
|
||||
/// report's.
|
||||
pub const MAX_DETAILS: usize = crate::import::MAX_DETAILS;
|
||||
|
||||
/// Why a piece of the project did not arrive in the `.aep`, or arrived changed.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
@@ -130,15 +131,9 @@ impl LossCategory {
|
||||
}
|
||||
}
|
||||
|
||||
/// One category of things that were not exported.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Loss {
|
||||
pub category: LossCategory,
|
||||
/// How many occurrences (exact).
|
||||
pub count: usize,
|
||||
/// Up to [`MAX_DETAILS`] example lines.
|
||||
pub details: Vec<String>,
|
||||
}
|
||||
/// One category of things that were not exported: the import report's loss entry with the
|
||||
/// export categories.
|
||||
pub type Loss = crate::import::Loss<LossCategory>;
|
||||
|
||||
/// What was written to the file.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -222,7 +217,7 @@ pub struct ExportReport {
|
||||
impl ExportReport {
|
||||
/// The sum of all loss counts.
|
||||
pub fn total_losses(&self) -> usize {
|
||||
self.losses.iter().map(|l| l.count).sum()
|
||||
Loss::total(&self.losses)
|
||||
}
|
||||
|
||||
/// True when nothing was lost.
|
||||
@@ -232,12 +227,12 @@ impl ExportReport {
|
||||
|
||||
/// The loss count of a category.
|
||||
pub fn count(&self, category: LossCategory) -> usize {
|
||||
self.losses.iter().find(|l| l.category == category).map_or(0, |l| l.count)
|
||||
Loss::count_of(&self.losses, category)
|
||||
}
|
||||
|
||||
/// `effects: 3, masks: 1` (empty when lossless).
|
||||
pub fn summary(&self) -> String {
|
||||
self.losses.iter().map(|l| format!("{}: {}", l.category.label(), l.count)).collect::<Vec<_>>().join(", ")
|
||||
Loss::summary(&self.losses, LossCategory::label)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,11 +246,7 @@ pub(crate) struct Collector {
|
||||
impl Collector {
|
||||
/// Records one loss.
|
||||
pub fn lose(&mut self, category: LossCategory, detail: impl Into<String>) {
|
||||
let loss = self.losses.entry(category).or_insert_with(|| Loss { category, count: 0, details: Vec::new() });
|
||||
loss.count = loss.count.saturating_add(1);
|
||||
if loss.details.len() < MAX_DETAILS {
|
||||
loss.details.push(detail.into());
|
||||
}
|
||||
Loss::record(&mut self.losses, category, move || detail.into());
|
||||
}
|
||||
|
||||
pub fn finish(self) -> ExportReport {
|
||||
@@ -266,3 +257,56 @@ impl Collector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A report with losses in two categories, as the collector finishes it.
|
||||
fn collected() -> ExportReport {
|
||||
let mut col = Collector::default();
|
||||
col.exported.layers = 2;
|
||||
col.lose(LossCategory::RoundedTimes, "time 1");
|
||||
col.lose(LossCategory::Effects, String::from("fx 1"));
|
||||
col.lose(LossCategory::Effects, "fx 2");
|
||||
let mut report = col.finish();
|
||||
report.limitations.truncate(1);
|
||||
report.limitations[0] = "limit".into();
|
||||
report
|
||||
}
|
||||
|
||||
/// The JSON shape agents read: field names, category spelling, order and the loss entries.
|
||||
#[test]
|
||||
fn the_json_shape_is_pinned() {
|
||||
let json = serde_json::to_string(&collected()).unwrap();
|
||||
assert_eq!(
|
||||
json,
|
||||
r#"{"exported":{"folders":0,"compositions":0,"solids":0,"layers":2,"solidLayers":0,"nullLayers":0,"adjustmentLayers":0,"properties":0,"keyframes":0,"expressions":0,"masks":0,"precompLayers":0,"effects":0,"footage":0,"footageLayers":0,"textLayers":0,"markers":0,"cameras":0,"lights":0,"shapeLayers":0,"timeRemaps":0,"textAnimators":0,"layerStyles":0},"losses":[{"category":"effects","count":2,"details":["fx 1","fx 2"],"unlisted":0},{"category":"rounded_times","count":1,"details":["time 1"],"unlisted":0}],"limitations":["limit"]}"#
|
||||
);
|
||||
let back: ExportReport = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(back, collected());
|
||||
}
|
||||
|
||||
/// The queries read the losses.
|
||||
#[test]
|
||||
fn the_queries_read_the_losses() {
|
||||
let report = collected();
|
||||
assert_eq!((report.total_losses(), report.is_lossless()), (3, false));
|
||||
assert_eq!((report.count(LossCategory::Effects), report.count(LossCategory::Lights)), (2, 0));
|
||||
assert_eq!(report.summary(), "effects: 2, rounded times: 1");
|
||||
let empty = Collector::default().finish();
|
||||
assert_eq!((empty.total_losses(), empty.is_lossless(), empty.summary()), (0, true, String::new()));
|
||||
}
|
||||
|
||||
/// Details stop at the cap.
|
||||
#[test]
|
||||
fn details_stop_at_the_cap() {
|
||||
let mut col = Collector::default();
|
||||
for i in 0..MAX_DETAILS + 5 {
|
||||
col.lose(LossCategory::Masks, format!("mask {i}"));
|
||||
}
|
||||
let report = col.finish();
|
||||
assert_eq!(report.count(LossCategory::Masks), MAX_DETAILS + 5);
|
||||
assert_eq!(report.losses[0].details.len(), MAX_DETAILS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ use crate::Chunk;
|
||||
use effectcraft_keyframe::{Gradient, Interp, Keyframe, Value};
|
||||
use effectcraft_project::{Node, PropGroup, Property};
|
||||
|
||||
use crate::export::keys::{fill_key_list, replace_cdat, spatial_record, timed_keys};
|
||||
use crate::export::masks::ShapePlan;
|
||||
use crate::export::plan::{CompPlan, EaseSlot, KeyPlan};
|
||||
use crate::export::report::{Collector, LossCategory};
|
||||
use crate::export::tree::{R, child_data, kids_mut, list_mut, put, put_f64, put_u8, put_u16, put_u32, set_utf8, tpl};
|
||||
use crate::export::synth::{GROUP_END, is_tdmn, tdmn};
|
||||
use crate::export::tree::{R, child_data, kids_mut, list_mut, put_f64, put_u8, set_utf8, tpl};
|
||||
|
||||
/// The deepest group nesting written.
|
||||
const MAX_DEPTH: usize = 16;
|
||||
@@ -192,7 +194,7 @@ impl ShapeProtos {
|
||||
put_f64(child_data(&mut node, b"tdum")?, 0, lo)?;
|
||||
put_f64(child_data(&mut node, b"tduM")?, 0, hi)?;
|
||||
}
|
||||
Ok([crate::export::camlight::tdmn_chunk(name), node])
|
||||
Ok([tdmn(name), node])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,20 +269,7 @@ pub(crate) struct ShCx<'a> {
|
||||
|
||||
/// The keys of `p` in the file's units.
|
||||
fn plan_keys(p: &Property, conv: Conv, layout: Layout, what: &str, cx: &mut ShCx<'_>) -> Vec<KeyPlan> {
|
||||
let mut timed: Vec<(i64, &Keyframe)> = Vec::with_capacity(p.keys.len());
|
||||
for k in &p.keys {
|
||||
let (u, inexact) = cx.cp.tb.units(k.time);
|
||||
if inexact {
|
||||
cx.col.lose(LossCategory::RoundedTimes, format!("{what}: key at {:.4} s moved to the time base", k.time.seconds()));
|
||||
}
|
||||
timed.push((u, k));
|
||||
}
|
||||
timed.sort_by_key(|(u, _)| *u);
|
||||
let before = timed.len();
|
||||
timed.dedup_by_key(|(u, _)| *u);
|
||||
if timed.len() != before {
|
||||
cx.col.lose(LossCategory::ApproximatedKeyframes, format!("{what}: keys at the same time were merged"));
|
||||
}
|
||||
let timed = timed_keys(&p.keys, &cx.cp.tb, what, "key", cx.col);
|
||||
let all: Vec<Keyframe> = timed.iter().map(|(_, k)| (*k).clone()).collect();
|
||||
let mut out = Vec::with_capacity(timed.len());
|
||||
let beyond = std::cell::Cell::new(false);
|
||||
@@ -618,38 +607,6 @@ pub(crate) fn plan_contents(contents: &PropGroup, what: &str, depth: usize, cx:
|
||||
out
|
||||
}
|
||||
|
||||
fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let b = c.bytes()?;
|
||||
let end = b.iter().position(|x| *x == 0).unwrap_or(b.len());
|
||||
std::str::from_utf8(b.get(..end)?).ok().map(str::to_string)
|
||||
}
|
||||
|
||||
/// A key of a point (the spatial layout of a 2D Position, 853) or a colour (854).
|
||||
fn spatial_key(k: &KeyPlan, n: usize, point: bool, size: usize) -> R<Vec<u8>> {
|
||||
let mut r = vec![0u8; size];
|
||||
put(&mut r, 0, &k.time.to_be_bytes())?;
|
||||
put_u8(&mut r, 4, k.in_interp)?;
|
||||
put_u8(&mut r, 5, k.out_interp)?;
|
||||
let base: u16 = if point { 0x0007 } else { 0x0001 };
|
||||
put_u16(&mut r, 6, base | (u16::from(k.label) << 6))?;
|
||||
if point {
|
||||
put_u32(&mut r, 8, u32::from(k.spatial_auto))?;
|
||||
let (i, o) = (k.in_ease.first().copied().unwrap_or_default(), k.out_ease.first().copied().unwrap_or_default());
|
||||
put_f64(&mut r, 24, i.speed)?;
|
||||
put_f64(&mut r, 32, i.influence)?;
|
||||
put_f64(&mut r, 40, o.speed)?;
|
||||
put_f64(&mut r, 48, o.influence)?;
|
||||
}
|
||||
for j in 0..n {
|
||||
put_f64(&mut r, 56 + 8 * j, k.value.get(j).copied().unwrap_or(0.0))?;
|
||||
if point {
|
||||
put_f64(&mut r, 56 + 8 * n + 8 * j, k.spatial_in.get(j).copied().unwrap_or(0.0))?;
|
||||
put_f64(&mut r, 56 + 16 * n + 8 * j, k.spatial_out.get(j).copied().unwrap_or(0.0))?;
|
||||
}
|
||||
}
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
/// The value record of `name` holding `v`.
|
||||
fn value_record(t: &ShapeProtos, name: &'static str, v: &RecVal) -> R<[Chunk<'static>; 2]> {
|
||||
let [m, node] = t.record(name)?;
|
||||
@@ -681,32 +638,17 @@ pub(crate) fn build_record(m: Chunk<'static>, mut node: Chunk<'static>, layout:
|
||||
put_u8(tdb4, 79, 0)?;
|
||||
}
|
||||
}
|
||||
let mut list = key_list.clone();
|
||||
let count = u32::try_from(v.keys.len()).map_err(|_| tpl("too many keys"))?;
|
||||
{
|
||||
let lhd3 = child_data(&mut list, b"lhd3")?;
|
||||
crate::export::synth::put_key_counts(lhd3, count, u32::try_from(size).map_err(|_| tpl("record size"))?)?;
|
||||
}
|
||||
let mut ldat = Vec::with_capacity(size * v.keys.len());
|
||||
for k in &v.keys {
|
||||
ldat.extend(match layout {
|
||||
Layout::Point => spatial_key(k, n, true, size)?,
|
||||
Layout::Color => spatial_key(k, n, false, size)?,
|
||||
Layout::Point => spatial_record(k, n, true, size)?,
|
||||
Layout::Color => spatial_record(k, n, false, size)?,
|
||||
_ => crate::export::emit::plain_record(n, k, size)?,
|
||||
});
|
||||
}
|
||||
{
|
||||
let lk = kids_mut(&mut list)?;
|
||||
match lk.iter_mut().find(|c| c.is(b"ldat")) {
|
||||
Some(c) => *c = Chunk::data(*b"ldat", ldat),
|
||||
None => lk.push(Chunk::data(*b"ldat", ldat)),
|
||||
}
|
||||
}
|
||||
let kids = kids_mut(&mut node)?;
|
||||
let at = kids.iter().position(|c| c.is(b"cdat")).ok_or_else(|| tpl("shape record without cdat"))?;
|
||||
if let Some(slot) = kids.get_mut(at) {
|
||||
*slot = list;
|
||||
}
|
||||
let mut list = key_list.clone();
|
||||
fill_key_list(&mut list, ldat, v.keys.len(), size)?;
|
||||
replace_cdat(&mut node, list)?;
|
||||
}
|
||||
if let Some((text, enabled)) = &v.expr {
|
||||
// As on the Transform properties (R15; 856).
|
||||
@@ -746,7 +688,7 @@ pub(crate) fn build_items(t: &ShapeProtos, items: &[ShItem], depth: usize) -> R<
|
||||
if depth > MAX_DEPTH {
|
||||
return Ok(out);
|
||||
}
|
||||
let pos = |kids: &[Chunk<'static>], n: &str| kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(n));
|
||||
let pos = |kids: &[Chunk<'static>], n: &str| kids.iter().position(|c| is_tdmn(c, n));
|
||||
for item in items {
|
||||
match item {
|
||||
ShItem::Off(inner) => {
|
||||
@@ -766,7 +708,7 @@ pub(crate) fn build_items(t: &ShapeProtos, items: &[ShItem], depth: usize) -> R<
|
||||
let vg = pos(kids, "ADBE Vectors Group").ok_or_else(|| tpl("group prototype without contents"))?;
|
||||
let contents = kids.get_mut(vg + 1).ok_or_else(|| tpl("group prototype without contents"))?;
|
||||
let ck = kids_mut(contents)?;
|
||||
let end = ck.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Group End")).unwrap_or(ck.len());
|
||||
let end = ck.iter().position(|c| is_tdmn(c, GROUP_END)).unwrap_or(ck.len());
|
||||
ck.splice(end..end, children);
|
||||
let tg = pos(kids, "ADBE Vector Transform Group").ok_or_else(|| tpl("group prototype without transform"))?;
|
||||
let tnode = kids.get_mut(tg + 1).ok_or_else(|| tpl("group prototype without transform"))?;
|
||||
@@ -815,13 +757,10 @@ pub(crate) fn put_contents(layr: &mut Chunk<'static>, t: &ShapeProtos, items: &[
|
||||
let built = build_items(t, items, 0)?;
|
||||
let root = list_mut(layr, b"tdgp")?;
|
||||
let kids = kids_mut(root)?;
|
||||
let at = kids
|
||||
.iter()
|
||||
.position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Root Vectors Group"))
|
||||
.ok_or_else(|| tpl("shape layer without contents"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, "ADBE Root Vectors Group")).ok_or_else(|| tpl("shape layer without contents"))?;
|
||||
let rv = kids.get_mut(at + 1).ok_or_else(|| tpl("shape layer without contents"))?;
|
||||
let rk = kids_mut(rv)?;
|
||||
let end = rk.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some("ADBE Group End")).unwrap_or(rk.len());
|
||||
let end = rk.iter().position(|c| is_tdmn(c, GROUP_END)).unwrap_or(rk.len());
|
||||
rk.splice(end..end, built);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
//! e1-sparse).
|
||||
|
||||
use crate::Chunk;
|
||||
use crate::export::synth::{KeyTemplate, NO_NAME, RecSpec, class, tdbs, tdmn, tdsn};
|
||||
use crate::export::synth::{GROUP_END, KeyTemplate, NO_NAME, RecSpec, class, tdbs, tdmn, tdmn_name, tdsn};
|
||||
|
||||
/// A group: its match name and a `tdgp` with the state `state` (`tdsb`), no user name, `kids` and
|
||||
/// the closing `ADBE Group End`.
|
||||
pub(crate) fn group(name: &str, state: u32, kids: Vec<Chunk<'static>>) -> [Chunk<'static>; 2] {
|
||||
let mut body = vec![Chunk::data(*b"tdsb", state.to_be_bytes().to_vec()), tdsn(NO_NAME)];
|
||||
body.extend(kids);
|
||||
body.push(tdmn("ADBE Group End"));
|
||||
body.push(tdmn(GROUP_END));
|
||||
[tdmn(name), Chunk::list(*b"tdgp", body)]
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ pub(crate) fn av_layer() -> Vec<Chunk<'static>> {
|
||||
let mut root = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn(""), tdmn("ADBE Time Remapping"), time_remap()];
|
||||
root.extend(group("ADBE Transform Group", 1, crate::export::tree_spec::build(crate::export::tree_defs::AV_TRANSFORM)));
|
||||
root.extend(layer_styles());
|
||||
root.push(tdmn("ADBE Group End"));
|
||||
root.push(tdmn(GROUP_END));
|
||||
let layr = Chunk::list(
|
||||
*b"Layr",
|
||||
vec![Chunk::data(*b"ldta", vec![0; 164]), Chunk::data(*b"Utf8", Vec::new()), Chunk::list(*b"tdgp", root), crate::export::base::guides()],
|
||||
@@ -78,7 +78,7 @@ pub(crate) fn av_layer() -> Vec<Chunk<'static>> {
|
||||
pub(crate) fn layer_block(nodes: &[crate::export::tree_spec::Node]) -> Vec<Chunk<'static>> {
|
||||
let mut root = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), tdsn("")];
|
||||
root.extend(crate::export::tree_spec::build(nodes));
|
||||
root.push(tdmn("ADBE Group End"));
|
||||
root.push(tdmn(GROUP_END));
|
||||
let layr = Chunk::list(
|
||||
*b"Layr",
|
||||
vec![Chunk::data(*b"ldta", vec![0; 164]), Chunk::data(*b"Utf8", Vec::new()), Chunk::list(*b"tdgp", root), crate::export::base::guides()],
|
||||
@@ -125,7 +125,7 @@ pub(crate) fn text_layer(doc: &[u8]) -> Vec<Chunk<'static>> {
|
||||
root.extend(group("ADBE Text Properties", 1, props));
|
||||
root.extend(group("ADBE Transform Group", 1, crate::export::tree_spec::build(crate::export::tree_defs::AV_TRANSFORM)));
|
||||
root.extend(layer_styles());
|
||||
root.push(tdmn("ADBE Group End"));
|
||||
root.push(tdmn(GROUP_END));
|
||||
let layr = Chunk::list(
|
||||
*b"Layr",
|
||||
vec![Chunk::data(*b"ldta", vec![0; 164]), Chunk::data(*b"Utf8", Vec::new()), Chunk::list(*b"tdgp", root), crate::export::base::guides()],
|
||||
@@ -141,7 +141,7 @@ pub(crate) fn pairs(nodes: &[crate::export::tree_spec::Node]) -> Vec<(String, [C
|
||||
let mut out = Vec::new();
|
||||
let mut it = crate::export::tree_spec::build(nodes).into_iter();
|
||||
while let (Some(m), Some(n)) = (it.next(), it.next()) {
|
||||
let name = String::from_utf8_lossy(m.bytes().unwrap_or_default().split(|b| *b == 0).next().unwrap_or_default()).into_owned();
|
||||
let name = tdmn_name(&m).unwrap_or_default();
|
||||
out.push((name, [m, n]));
|
||||
}
|
||||
out
|
||||
|
||||
@@ -23,8 +23,10 @@ use effectcraft_project::build::Ids;
|
||||
use effectcraft_project::styles::{self as st, STYLE_BLEND_MODES};
|
||||
use effectcraft_project::{Comp, Layer, PropGroup, Property};
|
||||
|
||||
use crate::export::keys::{fill_key_list, replace_cdat, timed_keys};
|
||||
use crate::export::plan::{CompPlan, EaseSlot, KeyPlan};
|
||||
use crate::export::report::{Collector, LossCategory};
|
||||
use crate::export::synth::{GROUP_END, is_tdmn};
|
||||
use crate::export::tree::{R, child_data, kids_mut, put_f64, put_u8, put_u32, tpl};
|
||||
|
||||
/// A record's value.
|
||||
@@ -128,20 +130,7 @@ fn plan_record(spec: &StyleParam, full: String, prop: &Property, cp: &CompPlan,
|
||||
/// The keys of a scalar in the layer's time base: linear, hold and bezier sides with the ease in
|
||||
/// stored units per second (the plain template of 976).
|
||||
fn plan_number_keys(prop: &Property, cp: &CompPlan, what: &str, col: &mut Collector) -> Vec<KeyPlan> {
|
||||
let mut timed: Vec<(i64, &effectcraft_keyframe::Keyframe)> = Vec::with_capacity(prop.keys.len());
|
||||
for k in &prop.keys {
|
||||
let (u, inexact) = cp.tb.units(k.time);
|
||||
if inexact {
|
||||
col.lose(LossCategory::RoundedTimes, format!("{what}: key at {:.4} s moved to the time base", k.time.seconds()));
|
||||
}
|
||||
timed.push((u, k));
|
||||
}
|
||||
timed.sort_by_key(|(u, _)| *u);
|
||||
let before = timed.len();
|
||||
timed.dedup_by_key(|(u, _)| *u);
|
||||
if timed.len() != before {
|
||||
col.lose(LossCategory::ApproximatedKeyframes, format!("{what}: keys at the same time were merged"));
|
||||
}
|
||||
let timed = timed_keys(&prop.keys, &cp.tb, what, "key", col);
|
||||
let mut out = Vec::with_capacity(timed.len());
|
||||
let beyond = std::cell::Cell::new(false);
|
||||
for (u, k) in timed {
|
||||
@@ -279,11 +268,6 @@ pub(crate) struct StyleProtos {
|
||||
keyed: Chunk<'static>,
|
||||
}
|
||||
|
||||
fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let d = c.bytes()?;
|
||||
Some(d.iter().take_while(|b| **b != 0).map(|b| char::from(*b)).collect())
|
||||
}
|
||||
|
||||
impl StyleProtos {
|
||||
/// The records built in code from the style table (`style_defs`); the keyed form of a scalar
|
||||
/// takes `tdb4` bytes 5, 68 and 79 and the key list of a keyed one-component record.
|
||||
@@ -322,28 +306,13 @@ impl StyleProtos {
|
||||
}
|
||||
}
|
||||
let mut list = self.keyed.child_list(b"list").cloned().ok_or_else(|| tpl("keyed style prototype without keys"))?;
|
||||
let n = u32::try_from(keys.len()).map_err(|_| tpl("too many keys"))?;
|
||||
let size = 48usize;
|
||||
{
|
||||
let lhd3 = child_data(&mut list, b"lhd3")?;
|
||||
crate::export::synth::put_key_counts(lhd3, n, 48)?;
|
||||
}
|
||||
let mut ldat = Vec::with_capacity(size * keys.len());
|
||||
for k in keys {
|
||||
ldat.extend(crate::export::emit::plain_record(1, k, size)?);
|
||||
}
|
||||
{
|
||||
let lk = kids_mut(&mut list)?;
|
||||
match lk.iter_mut().find(|c| c.is(b"ldat")) {
|
||||
Some(c) => *c = Chunk::data(*b"ldat", ldat),
|
||||
None => lk.push(Chunk::data(*b"ldat", ldat)),
|
||||
}
|
||||
}
|
||||
let kids = kids_mut(&mut rec)?;
|
||||
let at = kids.iter().position(|c| c.is(b"cdat")).ok_or_else(|| tpl("style record without cdat"))?;
|
||||
if let Some(slot) = kids.get_mut(at) {
|
||||
*slot = list;
|
||||
}
|
||||
fill_key_list(&mut list, ldat, keys.len(), size)?;
|
||||
replace_cdat(&mut rec, list)?;
|
||||
}
|
||||
}
|
||||
if let Some((text, enabled)) = &r.expr {
|
||||
@@ -362,7 +331,7 @@ impl StyleProtos {
|
||||
|
||||
/// The node after the `tdmn` named `name` among `kids`.
|
||||
fn named_mut<'a>(kids: &'a mut [Chunk<'static>], name: &str) -> R<&'a mut Chunk<'static>> {
|
||||
let i = kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(name)).ok_or_else(|| tpl("layer styles group incomplete"))?;
|
||||
let i = kids.iter().position(|c| is_tdmn(c, name)).ok_or_else(|| tpl("layer styles group incomplete"))?;
|
||||
kids.get_mut(i + 1).ok_or_else(|| tpl("layer styles group incomplete"))
|
||||
}
|
||||
|
||||
@@ -377,7 +346,7 @@ fn insert_records(protos: &StyleProtos, g: &mut Chunk<'static>, recs: &[Record],
|
||||
built.extend(protos.build(r)?);
|
||||
}
|
||||
let kids = kids_mut(g)?;
|
||||
let at = kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(before)).ok_or_else(|| tpl("layer styles group incomplete"))?;
|
||||
let at = kids.iter().position(|c| is_tdmn(c, before)).ok_or_else(|| tpl("layer styles group incomplete"))?;
|
||||
kids.splice(at..at, built);
|
||||
Ok(())
|
||||
}
|
||||
@@ -392,12 +361,12 @@ pub(crate) fn put_styles(protos: &StyleProtos, layr: &mut Chunk<'static>, plan:
|
||||
set_flags(bo, sm::FLAGS_ON)?;
|
||||
insert_records(protos, bo, &plan.global, sm::ADV_BLEND)?;
|
||||
let adv = named_mut(kids_mut(bo)?, sm::ADV_BLEND)?;
|
||||
insert_records(protos, adv, &plan.adv, "ADBE Group End")?;
|
||||
insert_records(protos, adv, &plan.adv, GROUP_END)?;
|
||||
}
|
||||
for (prefix, recs, on) in &plan.styles {
|
||||
let g = named_mut(kids_mut(ls)?, &format!("{prefix}/enabled"))?;
|
||||
set_flags(g, if *on { sm::FLAGS_ON } else { sm::FLAGS_OFF })?;
|
||||
insert_records(protos, g, recs, "ADBE Group End")?;
|
||||
insert_records(protos, g, recs, GROUP_END)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
//! evidence, or zero where After Effects was shown to accept zero (the read-backs listed in
|
||||
//! `docs/aep-export.md`, "Built in code").
|
||||
|
||||
use crate::export::tree::{Fixed, R, put_u32};
|
||||
use crate::{Body, Chunk};
|
||||
|
||||
/// `tdmn`: a match name padded to 40 bytes.
|
||||
/// `tdmn`: a match name padded to 40 bytes (at most 39 bytes of the name, so that a NUL remains).
|
||||
pub(crate) fn tdmn(name: &str) -> Chunk<'static> {
|
||||
let mut b = vec![0u8; 40];
|
||||
for (slot, c) in b.iter_mut().zip(name.bytes().take(39)) {
|
||||
@@ -15,12 +16,34 @@ pub(crate) fn tdmn(name: &str) -> Chunk<'static> {
|
||||
Chunk::data(*b"tdmn", b)
|
||||
}
|
||||
|
||||
/// The match name that closes a property group.
|
||||
pub(crate) const GROUP_END: &str = "ADBE Group End";
|
||||
|
||||
/// The match name in a `tdmn`: the bytes up to the first NUL as UTF-8, invalid sequences
|
||||
/// replaced, as the importer reads it (`container::typed`). After Effects writes ASCII here
|
||||
/// (aep-format.md 3.4; every `tdmn` of the corpus is ASCII); `None` when `c` is not a data chunk.
|
||||
pub(crate) fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let b = c.bytes()?;
|
||||
let end = b.iter().position(|x| *x == 0).unwrap_or(b.len());
|
||||
Some(String::from_utf8_lossy(b.get(..end)?).into_owned())
|
||||
}
|
||||
|
||||
/// Whether `c` is a `tdmn` naming `name`.
|
||||
pub(crate) fn is_tdmn(c: &Chunk<'_>, name: &str) -> bool {
|
||||
c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(name)
|
||||
}
|
||||
|
||||
/// The user name of a property that has none (`-_0_/-`, aep-format.md 3.4).
|
||||
pub(crate) const NO_NAME: &str = "-_0_/-";
|
||||
|
||||
/// `tdsn`: the user name, a nested chunk holding one `Utf8`.
|
||||
pub(crate) fn tdsn(name: &str) -> Chunk<'static> {
|
||||
Chunk { id: *b"tdsn", body: Body::Chunks(vec![Chunk::data(*b"Utf8", name.as_bytes().to_vec())]), pad: None }
|
||||
utf8_in(*b"tdsn", name)
|
||||
}
|
||||
|
||||
/// A nested chunk `id` holding one `Utf8` with `text` (`tdsn`, `fnam`, `pdnm`).
|
||||
pub(crate) fn utf8_in(id: [u8; 4], text: &str) -> Chunk<'static> {
|
||||
Chunk { id, body: Body::Chunks(vec![Chunk::data(*b"Utf8", text.as_bytes().to_vec())]), pad: None }
|
||||
}
|
||||
|
||||
/// How a property's keys are stored (`tdb4` byte 7, aep-format.md 3.5).
|
||||
@@ -100,13 +123,13 @@ impl RecSpec {
|
||||
/// word and the constant doubles at 16..56 are written; After Effects reads the other bytes as
|
||||
/// zero (read-back e1-ztdb4d).
|
||||
pub(crate) fn tdb4(spec: &RecSpec, keyed: bool, time_scale: u32) -> Vec<u8> {
|
||||
let mut b = vec![0u8; 124];
|
||||
let set = |b: &mut Vec<u8>, at: usize, bytes: &[u8]| {
|
||||
if let Some(dst) = b.get_mut(at..at + bytes.len()) {
|
||||
dst.copy_from_slice(bytes);
|
||||
}
|
||||
};
|
||||
set(&mut b, 0, &[0xdb, 0x99, 0x00, spec.dims]);
|
||||
tdb4_layout(spec, keyed, time_scale).finish(|| "tdb4".to_string())
|
||||
}
|
||||
|
||||
/// The 124-byte `tdb4` property header layout for a record spec.
|
||||
fn tdb4_layout(spec: &RecSpec, keyed: bool, time_scale: u32) -> Fixed {
|
||||
let mut b = Fixed::zeroed(124);
|
||||
b.put(0, &[0xdb, 0x99, 0x00, spec.dims]);
|
||||
let spatial = match spec.template {
|
||||
KeyTemplate::Plain => 0,
|
||||
KeyTemplate::Spatial(t) => t,
|
||||
@@ -115,19 +138,19 @@ pub(crate) fn tdb4(spec: &RecSpec, keyed: bool, time_scale: u32) -> Vec<u8> {
|
||||
Some(b) => (b & !0x01) | u8::from(!keyed),
|
||||
None => (if spatial == 0 { 0 } else { spatial_byte5(spatial) }) | u8::from(!keyed),
|
||||
};
|
||||
set(&mut b, 5, &[byte5]);
|
||||
set(&mut b, 7, &[spatial]);
|
||||
set(&mut b, 8, &spec.class.to_be_bytes());
|
||||
set(&mut b, 12, &time_scale.to_be_bytes());
|
||||
b.put(5, &[byte5]);
|
||||
b.put(7, &[spatial]);
|
||||
b.put(8, &spec.class.to_be_bytes());
|
||||
b.put(12, &time_scale.to_be_bytes());
|
||||
// Every record After Effects writes carries 0.0001 and four 1.0 here; without them a roving
|
||||
// key reads back at time zero instead of its retimed place (read-back s14-re-keyframes).
|
||||
set(&mut b, 16, &1e-4f64.to_be_bytes());
|
||||
b.put(16, &1e-4f64.to_be_bytes());
|
||||
for at in [24, 32, 40, 48] {
|
||||
set(&mut b, at, &1.0f64.to_be_bytes());
|
||||
b.put(at, &1.0f64.to_be_bytes());
|
||||
}
|
||||
set(&mut b, 68, &[u8::from(keyed)]);
|
||||
b.put(68, &[u8::from(keyed)]);
|
||||
// Set on a static spatial property, cleared once it is keyed (aep-format.md 3.4, byte 79).
|
||||
set(&mut b, 79, &[u8::from(spatial != 0 && !keyed)]);
|
||||
b.put(79, &[u8::from(spatial != 0 && !keyed)]);
|
||||
b
|
||||
}
|
||||
|
||||
@@ -135,16 +158,21 @@ pub(crate) fn tdb4(spec: &RecSpec, keyed: bool, time_scale: u32) -> Vec<u8> {
|
||||
/// 3.5): word 0 `0x00d00bee`, word 2 the count, word 3 the blocks of four (at least one), word 4
|
||||
/// the size, words 5 and 7 the capacity (the count rounded up to four, at least two), word 6 one.
|
||||
pub(crate) fn key_list(size: u32, count: u32, records: Vec<u8>) -> Chunk<'static> {
|
||||
let mut lhd3 = vec![0u8; 52];
|
||||
// Cannot fail: the header is 52 bytes.
|
||||
let _ = crate::export::tree::put_u32(&mut lhd3, 0, 0x00d0_0bee);
|
||||
let _ = crate::export::tree::put_u32(&mut lhd3, 24, 1);
|
||||
let _ = put_key_counts(&mut lhd3, count, size);
|
||||
let lhd3 = key_list_header(size, count).finish(|| "lhd3".to_string());
|
||||
Chunk::list(*b"list", vec![Chunk::data(*b"lhd3", lhd3), Chunk::data(*b"ldat", records)])
|
||||
}
|
||||
|
||||
/// The 52-byte `lhd3` key list header for `count` records of `size` bytes.
|
||||
fn key_list_header(size: u32, count: u32) -> Fixed {
|
||||
let mut lhd3 = Fixed::zeroed(52);
|
||||
lhd3.put(0, &0x00d0_0bee_u32.to_be_bytes());
|
||||
lhd3.put(24, &1u32.to_be_bytes());
|
||||
lhd3.apply(|d| put_key_counts(d, count, size));
|
||||
lhd3
|
||||
}
|
||||
|
||||
/// Sets the count words of a key list header for `count` keys of `size` bytes.
|
||||
pub(crate) fn put_key_counts(lhd3: &mut [u8], count: u32, size: u32) -> crate::export::tree::R<()> {
|
||||
pub(crate) fn put_key_counts(lhd3: &mut [u8], count: u32, size: u32) -> R<()> {
|
||||
let capacity = count.div_ceil(4).saturating_mul(4).max(2);
|
||||
put_counts(lhd3, count, count.div_ceil(4).max(1), size, capacity, capacity)
|
||||
}
|
||||
@@ -153,8 +181,7 @@ pub(crate) fn put_key_counts(lhd3: &mut [u8], count: u32, size: u32) -> crate::e
|
||||
/// record size, word 5 `w5`, word 7 the capacity. A key list has `w5` = the capacity; a path
|
||||
/// list counts vertices: `blocks` = `w5` = the vertex count, the capacity four times it (090:
|
||||
/// 12 points, 4, 4 and 16; aep-format.md 3.5).
|
||||
pub(crate) fn put_counts(lhd3: &mut [u8], count: u32, blocks: u32, size: u32, w5: u32, capacity: u32) -> crate::export::tree::R<()> {
|
||||
use crate::export::tree::put_u32;
|
||||
pub(crate) fn put_counts(lhd3: &mut [u8], count: u32, blocks: u32, size: u32, w5: u32, capacity: u32) -> R<()> {
|
||||
put_u32(lhd3, 8, count)?;
|
||||
put_u32(lhd3, 12, blocks)?;
|
||||
put_u32(lhd3, 16, size)?;
|
||||
@@ -204,6 +231,38 @@ mod tests {
|
||||
assert_eq!(rec.child(b"cdat").and_then(|c| c.bytes()).map(<[u8]>::len), Some(40));
|
||||
}
|
||||
|
||||
/// Every record header fits.
|
||||
#[test]
|
||||
fn every_record_header_fits() {
|
||||
for dims in 0..=u8::MAX {
|
||||
for template in [KeyTemplate::Plain, KeyTemplate::Spatial(1), KeyTemplate::Spatial(3), KeyTemplate::Spatial(u8::MAX)] {
|
||||
for byte5 in [None, Some(0xff)] {
|
||||
let spec = RecSpec { dims, template, class: u32::MAX, limits: None, byte5 };
|
||||
assert!(tdb4_layout(&spec, false, u32::MAX).error().is_none() && tdb4_layout(&spec, true, 0).error().is_none());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size, count) in [(0, 0), (u32::MAX, u32::MAX), (48, 5)] {
|
||||
let h = key_list_header(size, count);
|
||||
assert!(h.error().is_none());
|
||||
assert_eq!(h.finish(String::new).len(), 52);
|
||||
}
|
||||
}
|
||||
|
||||
/// A match name reads as the importer reads it.
|
||||
#[test]
|
||||
fn a_match_name_reads_as_the_importer_reads_it() {
|
||||
let m = tdmn("ADBE Group End");
|
||||
assert_eq!(tdmn_name(&m).as_deref(), Some(GROUP_END));
|
||||
assert!(is_tdmn(&m, GROUP_END) && !is_tdmn(&m, "ADBE Group") && !is_tdmn(&tdsn(GROUP_END), GROUP_END));
|
||||
// At most 39 bytes, so that a NUL remains.
|
||||
let long = "x".repeat(50);
|
||||
assert_eq!(tdmn_name(&tdmn(&long)).map(|n| n.len()), Some(39));
|
||||
// Not ASCII (After Effects writes ASCII): UTF-8, invalid bytes replaced, as on import.
|
||||
let odd = Chunk::data(*b"tdmn", vec![b'A', 0xc3, 0xa9, 0xff, 0, b'B']);
|
||||
assert_eq!(tdmn_name(&odd).as_deref(), Some("A\u{e9}\u{fffd}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_key_list_header_counts_and_rounds() {
|
||||
let l = key_list(48, 5, vec![0; 240]);
|
||||
|
||||
@@ -81,6 +81,24 @@ fn transform_records(keyed: bool) -> Vec<Chunk<'static>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The template every export clones from: built by the first export of the process and kept, as
|
||||
/// [`Template::load`] always builds the same prototypes and nothing changes them afterwards (the
|
||||
/// exporter only reads them through `&Template` and clones what it edits).
|
||||
///
|
||||
/// Concurrent exports are safe: the `static` requires `Template: Send + Sync`, which the compiler
|
||||
/// checks. Exports that race on the first call each build a template; one is kept and the others
|
||||
/// are dropped, and all of them are equal. A failed build is not kept, so the next export tries
|
||||
/// again and reports the same error.
|
||||
pub(crate) fn shared() -> R<&'static Template> {
|
||||
static SHARED: std::sync::OnceLock<Template> = std::sync::OnceLock::new();
|
||||
if let Some(t) = SHARED.get() {
|
||||
return Ok(t);
|
||||
}
|
||||
// A failed build returns here, before `get_or_init`, so it is never kept.
|
||||
let t = Template::load()?;
|
||||
Ok(SHARED.get_or_init(|| t))
|
||||
}
|
||||
|
||||
impl Template {
|
||||
pub fn load() -> R<Template> {
|
||||
let file = AepFile { chunks: crate::export::base::project_chunks(), trailer: std::borrow::Cow::Borrowed(&[]) };
|
||||
|
||||
@@ -89,6 +89,8 @@ pub(crate) struct TextPlan {
|
||||
pub frame: Option<[f64; 4]>,
|
||||
/// The text animators (planned with the layer's time base, `textanim.rs`).
|
||||
pub animators: Vec<crate::export::textanim::AnimPlan>,
|
||||
/// The Source Text expression and its enable switch.
|
||||
pub expr: Option<(String, bool)>,
|
||||
}
|
||||
|
||||
/// Where a text value is written, for the loss report.
|
||||
@@ -133,16 +135,19 @@ pub(crate) fn plan_text(layer: &Layer, comp_name: &str, col: &mut Collector) ->
|
||||
if !st.keys.is_empty() {
|
||||
col.lose(LossCategory::TextLayers, format!("{what}: Source Text keyframes are not written (the first key's text is)"));
|
||||
}
|
||||
if st.has_expression() {
|
||||
col.lose(LossCategory::TextLayers, format!("{what}: the Source Text expression is not written"));
|
||||
}
|
||||
let value = st.keys.first().map(|k| &k.value).unwrap_or(&st.value);
|
||||
let Value::Text(doc) = value else {
|
||||
col.lose(LossCategory::TextLayers, format!("{what}: Source Text holds no text document"));
|
||||
return None;
|
||||
};
|
||||
report_extras(text, &what, col);
|
||||
Some(plan_doc(doc, &what, col))
|
||||
let mut plan = plan_doc(doc, &what, col);
|
||||
// Written enabled or disabled, as on any other property.
|
||||
plan.expr = st.expr.as_ref().filter(|e| !e.text.is_empty()).map(|e| (e.text.clone(), e.enabled));
|
||||
if plan.expr.is_some() {
|
||||
col.exported.expressions = col.exported.expressions.saturating_add(1);
|
||||
}
|
||||
Some(plan)
|
||||
}
|
||||
|
||||
/// Path / More Options that hold anything other than a new text layer's defaults are not
|
||||
@@ -190,6 +195,8 @@ fn differs(g: &PropGroup, def: Option<&PropGroup>, depth: usize) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// The text document `doc` in the file's terms (text, style runs, paragraphs, box); what the file
|
||||
/// cannot hold is reported for `what`.
|
||||
fn plan_doc(doc: &TextDoc, what: &str, col: &mut Collector) -> TextPlan {
|
||||
let base = doc.base_style();
|
||||
let runs = doc.runs();
|
||||
@@ -288,7 +295,7 @@ fn plan_doc(doc: &TextDoc, what: &str, col: &mut Collector) -> TextPlan {
|
||||
at.fit(h, (1.0, 1e6), 1.0, "box height"),
|
||||
]
|
||||
});
|
||||
TextPlan { text, runs: out_runs, paras, frame, animators: Vec::new() }
|
||||
TextPlan { text, runs: out_runs, paras, frame, animators: Vec::new(), expr: None }
|
||||
}
|
||||
|
||||
fn style_out(s: &effectcraft_keyframe::text_doc::CharStyle, what: &str, col: &mut Collector) -> StyleOut {
|
||||
@@ -518,11 +525,47 @@ pub(crate) fn build_doc(proto: &TNode, tp: &TextPlan) -> Option<TNode> {
|
||||
Some(doc)
|
||||
}
|
||||
|
||||
/// Rewrites the text document of a text layer block's `Layr` for `tp` and gives the document a
|
||||
/// fresh `btgu/pgui`.
|
||||
/// The Source Text expression into the `tdbs` of `btds` (`docs/aep-format.md` 3.10, read back from
|
||||
/// `tests/fixtures/text-synthetic.aep`): `tdb4` byte 120 = 1, byte 119 = 1 when disabled, and the
|
||||
/// text as a `Utf8` after the record's `cdat`.
|
||||
fn put_source_text_expression(layr: &mut crate::Chunk<'static>, text: &str, enabled: bool) -> crate::export::tree::R<()> {
|
||||
use crate::Body;
|
||||
use crate::export::tree::tpl;
|
||||
/// The `tdbs` of the first `btds` below `c`, at most 32 levels down.
|
||||
fn find<'c>(c: &'c mut crate::Chunk<'static>, depth: usize) -> Option<&'c mut crate::Chunk<'static>> {
|
||||
if depth > 32 {
|
||||
return None;
|
||||
}
|
||||
if c.is_list(b"btds") {
|
||||
return match &mut c.body {
|
||||
Body::List { children, .. } => children.iter_mut().find(|k| k.is_list(b"tdbs")),
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
match &mut c.body {
|
||||
Body::List { children, .. } | Body::Chunks(children) => children.iter_mut().find_map(|k| find(k, depth + 1)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
let tdbs = find(layr, 0).ok_or_else(|| tpl("text prototype without a Source Text record"))?;
|
||||
let Body::List { children, .. } = &mut tdbs.body else { return Err(tpl("text prototype without a Source Text record")) };
|
||||
let tdb4 = children.iter_mut().find(|k| k.is(b"tdb4")).ok_or_else(|| tpl("Source Text record without tdb4"))?;
|
||||
let Body::Data(d) = &mut tdb4.body else { return Err(tpl("Source Text record without tdb4")) };
|
||||
let d = d.to_mut();
|
||||
*d.get_mut(120).ok_or_else(|| tpl("short Source Text tdb4"))? = 1;
|
||||
*d.get_mut(119).ok_or_else(|| tpl("short Source Text tdb4"))? = u8::from(!enabled);
|
||||
children.retain(|k| !k.is(b"Utf8"));
|
||||
let at = children.iter().position(|k| k.is(b"tdum")).unwrap_or(children.len());
|
||||
children.insert(at, crate::Chunk::data(*b"Utf8", text.as_bytes().to_vec()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Rewrites the text document of a text layer block's `Layr` for `tp`, writes its Source Text
|
||||
/// expression and gives the document a fresh `btgu/pgui`.
|
||||
pub(crate) fn put_doc(layr: &mut crate::Chunk<'static>, tp: &TextPlan, guid: [u8; 16]) -> crate::export::tree::R<()> {
|
||||
use crate::Body;
|
||||
use crate::export::tree::tpl;
|
||||
/// The first `LIST btdk` below `c`, at most 32 levels down.
|
||||
fn find<'c>(c: &'c mut crate::Chunk<'static>, depth: usize) -> Option<&'c mut crate::Chunk<'static>> {
|
||||
if depth > 32 {
|
||||
return None;
|
||||
@@ -535,6 +578,7 @@ pub(crate) fn put_doc(layr: &mut crate::Chunk<'static>, tp: &TextPlan, guid: [u8
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
/// The first `pgui` of the first `btgu` below `c`, at most 32 levels down.
|
||||
fn find_pgui<'c>(c: &'c mut crate::Chunk<'static>, depth: usize) -> Option<&'c mut crate::Chunk<'static>> {
|
||||
if depth > 32 {
|
||||
return None;
|
||||
@@ -555,6 +599,9 @@ pub(crate) fn put_doc(layr: &mut crate::Chunk<'static>, tp: &TextPlan, guid: [u8
|
||||
let proto = crate::export::textdoc::parse(data.as_ref()).ok_or_else(|| tpl("the text prototype's document does not parse"))?;
|
||||
let doc = build_doc(&proto, tp).ok_or_else(|| tpl("the text prototype's document has another shape"))?;
|
||||
*data = std::borrow::Cow::Owned(crate::export::textdoc::write(&doc));
|
||||
if let Some((text, enabled)) = &tp.expr {
|
||||
put_source_text_expression(layr, text, *enabled)?;
|
||||
}
|
||||
if let Some(p) = find_pgui(layr, 0) {
|
||||
*p = crate::Chunk::data(*b"pgui", guid.to_vec());
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ use effectcraft_project::{Layer, Node, PropGroup};
|
||||
use crate::export::plan::CompPlan;
|
||||
use crate::export::report::{Collector, LossCategory};
|
||||
use crate::export::shapes::{Conv, Layout, RecVal, ShCx, build_record, c_color, c_popup, c_scalar, rec_value};
|
||||
use crate::export::synth::{GROUP_END, is_tdmn};
|
||||
use crate::export::tree::{R, kids_mut, set_utf8, tpl};
|
||||
|
||||
/// More animators or selectors than this on one layer are not written (and reported).
|
||||
@@ -88,6 +89,7 @@ const PROPS: &[(&str, &str, Conv, Layout)] = &[
|
||||
("opacity", "ADBE Text Opacity", c_scalar, Layout::One),
|
||||
("fillColor", "ADBE Text Fill Color", c_color, Layout::Color),
|
||||
("strokeColor", "ADBE Text Stroke Color", c_color, Layout::Color),
|
||||
("strokeOpacity", "ADBE Text Stroke Opacity", c_scalar, Layout::One),
|
||||
("strokeWidth", "ADBE Text Stroke Width", c_scalar, Layout::One),
|
||||
("tracking", "ADBE Text Tracking Amount", c_scalar, Layout::One),
|
||||
("lineSpacing", "ADBE Text Line Spacing", c_vec2, Layout::Size),
|
||||
@@ -219,14 +221,8 @@ fn plan_selector(s: &PropGroup, animator: &str, cx: &mut ShCx<'_>) -> SelPlan {
|
||||
SelPlan { name: crate::export::plan::cut_name(&s.name, 255, &here, cx.col), records, advanced }
|
||||
}
|
||||
|
||||
fn tdmn_name(c: &Chunk<'_>) -> Option<String> {
|
||||
let b = c.bytes()?;
|
||||
let end = b.iter().position(|x| *x == 0).unwrap_or(b.len());
|
||||
std::str::from_utf8(b.get(..end)?).ok().map(str::to_string)
|
||||
}
|
||||
|
||||
fn pos(kids: &[Chunk<'static>], n: &str) -> Option<usize> {
|
||||
kids.iter().position(|c| c.is(b"tdmn") && tdmn_name(c).as_deref() == Some(n))
|
||||
kids.iter().position(|c| is_tdmn(c, n))
|
||||
}
|
||||
|
||||
/// The item's user name (`tdsn/Utf8`).
|
||||
@@ -296,7 +292,7 @@ pub(crate) fn put_animators(layr: &mut Chunk<'static>, t: &AnimProtos, anims: &[
|
||||
}
|
||||
{
|
||||
let gk = kids_mut(&mut group)?;
|
||||
let end = pos(gk, "ADBE Group End").unwrap_or(gk.len());
|
||||
let end = pos(gk, GROUP_END).unwrap_or(gk.len());
|
||||
gk.splice(end..end, built);
|
||||
}
|
||||
// Into the layer's `ADBE Text Properties`, before its Group End.
|
||||
@@ -305,7 +301,7 @@ pub(crate) fn put_animators(layr: &mut Chunk<'static>, t: &AnimProtos, anims: &[
|
||||
let ti = pos(rk, "ADBE Text Properties").ok_or_else(|| tpl("text layer without text properties"))?;
|
||||
let tp = rk.get_mut(ti + 1).ok_or_else(|| tpl("text layer without text properties"))?;
|
||||
let tk = kids_mut(tp)?;
|
||||
let end = pos(tk, "ADBE Group End").unwrap_or(tk.len());
|
||||
let end = pos(tk, GROUP_END).unwrap_or(tk.len());
|
||||
tk.splice(end..end, [gm, group]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -9,13 +9,9 @@
|
||||
|
||||
use effectcraft_time::{FrameRate, TICKS_PER_SECOND, Tick};
|
||||
|
||||
/// Frame duration and time scale in units; one frame lasts `frame_duration` units and a second
|
||||
/// has `timescale` units.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct TimeBase {
|
||||
pub frame_duration: u32,
|
||||
pub timescale: u32,
|
||||
}
|
||||
/// The container's time base (frame duration and time scale in units; one frame lasts
|
||||
/// `frame_duration` units and a second has `timescale` units), which the importer reads.
|
||||
pub(crate) use crate::container::TimeBase;
|
||||
|
||||
/// The 16.16 fixed-point rate After Effects stores next to the time base (a float32 rate).
|
||||
pub(crate) fn fixed_rate(rate: FrameRate) -> u32 {
|
||||
@@ -26,11 +22,8 @@ pub(crate) fn fixed_rate(rate: FrameRate) -> u32 {
|
||||
|
||||
/// The typed value of an NTSC rate (23.976, 29.97, 59.94, 119.88), which After Effects stores as
|
||||
/// a float32 of exactly these decimals.
|
||||
pub(crate) fn ntsc_typed(rate: FrameRate) -> Option<f32> {
|
||||
[(FrameRate::FPS_23_976, 23.976f32), (FrameRate::FPS_29_97, 29.97), (FrameRate::FPS_59_94, 59.94), (FrameRate::FPS_119_88, 119.88)]
|
||||
.into_iter()
|
||||
.find(|(r, _)| *r == rate)
|
||||
.map(|(_, v)| v)
|
||||
fn ntsc_typed(rate: FrameRate) -> Option<f32> {
|
||||
TimeBase::NTSC.into_iter().find(|(r, _)| *r == rate).map(|(_, v)| v)
|
||||
}
|
||||
|
||||
/// The time base for `rate`, or `None` for a rate After Effects cannot hold (non-positive, or not
|
||||
@@ -67,28 +60,27 @@ pub(crate) fn time_base(rate: FrameRate) -> Option<TimeBase> {
|
||||
}
|
||||
|
||||
impl TimeBase {
|
||||
/// `tick` in time units, rounded to the nearest unit; the second value tells whether it was
|
||||
/// not exact.
|
||||
pub fn units(&self, tick: Tick) -> (i64, bool) {
|
||||
let n = i128::from(tick.0) * i128::from(self.timescale);
|
||||
let d = i128::from(TICKS_PER_SECOND);
|
||||
let q = n.div_euclid(d);
|
||||
let r = n.rem_euclid(d);
|
||||
let rounded = if r * 2 >= d { q + 1 } else { q };
|
||||
(i64::try_from(rounded).unwrap_or(if rounded < 0 { i64::MIN } else { i64::MAX }), r != 0)
|
||||
/// `tick` in time units, rounded to the nearest unit (saturated to `i64`); the second value
|
||||
/// tells whether it was not exact.
|
||||
pub(crate) fn units(&self, tick: Tick) -> (i64, bool) {
|
||||
nearest(i128::from(tick.0).saturating_mul(i128::from(self.timescale)), i128::from(TICKS_PER_SECOND))
|
||||
}
|
||||
|
||||
/// Whole frames of `tick` (nearest).
|
||||
pub fn frames(&self, tick: Tick, rate: FrameRate) -> i64 {
|
||||
let n = i128::from(tick.0) * i128::from(rate.num);
|
||||
let d = i128::from(TICKS_PER_SECOND) * i128::from(rate.den.max(1));
|
||||
let q = n.div_euclid(d);
|
||||
let r = n.rem_euclid(d);
|
||||
let f = if r * 2 >= d { q + 1 } else { q };
|
||||
i64::try_from(f).unwrap_or(0)
|
||||
/// Whole frames of `tick` (nearest, saturated to `i64` like [`TimeBase::units`]).
|
||||
pub(crate) fn frames(&self, tick: Tick, rate: FrameRate) -> i64 {
|
||||
let d = i128::from(TICKS_PER_SECOND).saturating_mul(i128::from(rate.den.max(1)));
|
||||
nearest(i128::from(tick.0).saturating_mul(i128::from(rate.num)), d).0
|
||||
}
|
||||
}
|
||||
|
||||
/// `n / d` rounded to the nearest whole number (a half rounds up), saturated to `i64`, and whether
|
||||
/// it was not exact. `d` is positive.
|
||||
fn nearest(n: i128, d: i128) -> (i64, bool) {
|
||||
let (q, r) = (n.div_euclid(d), n.rem_euclid(d));
|
||||
let rounded = if r.saturating_mul(2) >= d { q.saturating_add(1) } else { q };
|
||||
(i64::try_from(rounded).unwrap_or(if rounded < 0 { i64::MIN } else { i64::MAX }), r != 0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -131,4 +123,19 @@ mod tests {
|
||||
assert!(tb.units(Tick(TICKS_PER_SECOND / 3)).1);
|
||||
assert_eq!(tb.frames(Tick(TICKS_PER_SECOND * 2), FrameRate::new(25, 1)), 50);
|
||||
}
|
||||
|
||||
/// Frames saturate like units (they used to become 0 past `i64`). No storable rate gets
|
||||
/// there: [`time_base`] only accepts rates far below one frame per tick.
|
||||
#[test]
|
||||
fn frames_and_units_saturate_alike() {
|
||||
let tb = TimeBase { frame_duration: 1024, timescale: u32::MAX };
|
||||
let huge = FrameRate { num: i64::MAX, den: 1 };
|
||||
assert_eq!(tb.frames(Tick(i64::MAX), huge), i64::MAX);
|
||||
assert_eq!(tb.frames(Tick(i64::MIN), huge), i64::MIN);
|
||||
// A half rounds up on the signed value, in frames and in units.
|
||||
assert_eq!(tb.frames(Tick(TICKS_PER_SECOND / 2), FrameRate::new(1, 1)), 1);
|
||||
assert_eq!(tb.frames(Tick(-TICKS_PER_SECOND / 2), FrameRate::new(1, 1)), 0);
|
||||
let tb1 = TimeBase { frame_duration: 1, timescale: 1 };
|
||||
assert_eq!((tb1.units(Tick(TICKS_PER_SECOND / 2)), tb1.units(Tick(-TICKS_PER_SECOND / 2))), ((1, true), (0, true)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ pub(crate) fn child_data<'a>(c: &'a mut Chunk<'static>, id: &[u8; 4]) -> R<&'a m
|
||||
data_mut(child_mut(c, id)?)
|
||||
}
|
||||
|
||||
/// The one byte writer of the exporter: `bytes` at `at`, or an error when they do not fit.
|
||||
pub(crate) fn put(d: &mut [u8], at: usize, bytes: &[u8]) -> R<()> {
|
||||
let end = at.checked_add(bytes.len()).ok_or_else(|| tpl("offset overflow"))?;
|
||||
let dst = d.get_mut(at..end).ok_or_else(|| tpl("chunk shorter than its layout"))?;
|
||||
@@ -90,20 +91,161 @@ pub(crate) fn put_cstr(d: &mut [u8], at: usize, len: usize, text: &str) -> R<()>
|
||||
break;
|
||||
}
|
||||
let mut buf = [0u8; 4];
|
||||
let enc = ch.encode_utf8(&mut buf);
|
||||
for (i, b) in enc.as_bytes().iter().enumerate() {
|
||||
if let Some(slot) = dst.get_mut(n + i) {
|
||||
*slot = *b;
|
||||
}
|
||||
}
|
||||
put(dst, n, ch.encode_utf8(&mut buf).as_bytes())?;
|
||||
n += l;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// How many fixed layouts on this thread did not fit their buffer (see [`Fixed`]); the tests
|
||||
/// keep it at zero.
|
||||
static FIXED_LAYOUT_ERRORS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// A buffer whose layout is fixed in code (constant size and offsets, no input from a project).
|
||||
/// Every write goes through [`put`]; a write that does not fit is skipped and its error kept, the
|
||||
/// others are written. Such an error is a bug in the layout, never something a project can cause:
|
||||
/// the tests build every one of these layouts and require no error. The builders keep their
|
||||
/// infallible signatures because files outside this module call them without a `Result`; if a
|
||||
/// layout ever broke, [`Fixed::finish`] logs it once and returns what fit.
|
||||
pub(crate) struct Fixed {
|
||||
bytes: Vec<u8>,
|
||||
error: Option<AepExportError>,
|
||||
}
|
||||
|
||||
impl Fixed {
|
||||
/// `len` zero bytes.
|
||||
pub(crate) fn zeroed(len: usize) -> Fixed {
|
||||
Fixed { bytes: vec![0u8; len], error: None }
|
||||
}
|
||||
|
||||
/// Writes `bytes` at `at`, or keeps the error (the first one) when they do not fit.
|
||||
pub(crate) fn put(&mut self, at: usize, bytes: &[u8]) {
|
||||
self.apply(|d| put(d, at, bytes));
|
||||
}
|
||||
|
||||
/// Runs a writer on the buffer, keeping its error (the first one).
|
||||
pub(crate) fn apply(&mut self, write: impl FnOnce(&mut [u8]) -> R<()>) {
|
||||
if let Err(e) = write(&mut self.bytes) {
|
||||
self.error.get_or_insert(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// The error of the first write that did not fit (for the tests).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn error(&self) -> Option<&AepExportError> {
|
||||
self.error.as_ref()
|
||||
}
|
||||
|
||||
/// The bytes; a write that did not fit is logged once, with what `layout` says.
|
||||
pub(crate) fn finish(self, layout: impl FnOnce() -> String) -> Vec<u8> {
|
||||
if let Some(e) = self.error {
|
||||
FIXED_LAYOUT_ERRORS.with(|n| n.set(n.get().saturating_add(1)));
|
||||
log::error!("aep export: the fixed layout of {} does not fit: {e}", layout());
|
||||
}
|
||||
self.bytes
|
||||
}
|
||||
}
|
||||
|
||||
/// How many fixed layouts have failed on this thread (for the tests).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn fixed_layout_errors() -> usize {
|
||||
FIXED_LAYOUT_ERRORS.with(std::cell::Cell::get)
|
||||
}
|
||||
|
||||
/// The entries of a property group by match name (see [`split_group`]).
|
||||
pub(crate) type Entries = Vec<(String, Vec<Chunk<'static>>)>;
|
||||
|
||||
/// Splits the children of a property group into the header (up to the first `tdmn`) and its
|
||||
/// entries by match name: `[tdmn, node]`, or `[tdmn]` for the closing `ADBE Group End`. A match
|
||||
/// name without a node is an error.
|
||||
pub(crate) fn split_group(kids: &mut Vec<Chunk<'static>>) -> R<(Vec<Chunk<'static>>, Entries)> {
|
||||
let first = kids.iter().position(|c| c.is(b"tdmn")).unwrap_or(kids.len());
|
||||
let header: Vec<Chunk<'static>> = kids.drain(..first).collect();
|
||||
let mut entries = Entries::new();
|
||||
let mut it = std::mem::take(kids).into_iter();
|
||||
while let Some(m) = it.next() {
|
||||
let name = crate::export::synth::tdmn_name(&m).unwrap_or_default();
|
||||
if name == crate::export::synth::GROUP_END {
|
||||
entries.push((name, vec![m]));
|
||||
continue;
|
||||
}
|
||||
let node = it.next().ok_or_else(|| tpl("match name without a node"))?;
|
||||
entries.push((name, vec![m, node]));
|
||||
}
|
||||
Ok((header, entries))
|
||||
}
|
||||
|
||||
/// Replaces the `Utf8` child of an item or layer with `text`.
|
||||
pub(crate) fn set_utf8(c: &mut Chunk<'static>, text: &str) -> R<()> {
|
||||
let k = child_mut(c, b"Utf8")?;
|
||||
*k = Chunk::data(*b"Utf8", text.as_bytes().to_vec());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The writer errors instead of dropping.
|
||||
#[test]
|
||||
fn the_writer_errors_instead_of_dropping() {
|
||||
let mut d = [0u8; 4];
|
||||
assert!(put(&mut d, 2, &[1, 2]).is_ok());
|
||||
assert_eq!(d, [0, 0, 1, 2]);
|
||||
// Out of range, partly or wholly, and an offset that overflows: an error, nothing written.
|
||||
assert!(put(&mut d, 3, &[9, 9]).is_err());
|
||||
assert!(put(&mut d, 8, &[9]).is_err());
|
||||
assert!(put(&mut d, usize::MAX, &[9]).is_err());
|
||||
assert_eq!(d, [0, 0, 1, 2]);
|
||||
}
|
||||
|
||||
/// A cut string keeps a nul and whole characters.
|
||||
#[test]
|
||||
fn a_cut_string_keeps_a_nul_and_whole_characters() {
|
||||
let mut d = [0xffu8; 6];
|
||||
put_cstr(&mut d, 0, 6, "ab\u{e9}\u{e9}").unwrap();
|
||||
assert_eq!(d, [b'a', b'b', 0xc3, 0xa9, 0, 0]);
|
||||
assert!(put_cstr(&mut d, 4, 6, "x").is_err());
|
||||
}
|
||||
|
||||
/// Every layout fixed in code fits its buffer: the prototypes of every export (the project
|
||||
/// skeleton, layers, Transform, masks, effects of the whole table, footage of every kind,
|
||||
/// text, cameras, lights, shapes, styles) are built and no write went out of range.
|
||||
#[test]
|
||||
fn every_fixed_layout_fits() {
|
||||
// A delta: other tests on this thread may have counted a broken layout on purpose.
|
||||
let before = fixed_layout_errors();
|
||||
assert!(crate::export::template::Template::load().is_ok());
|
||||
assert_eq!(fixed_layout_errors(), before);
|
||||
}
|
||||
|
||||
/// A broken fixed layout writes what fits and is counted.
|
||||
#[test]
|
||||
fn a_broken_fixed_layout_writes_what_fits_and_is_counted() {
|
||||
let before = fixed_layout_errors();
|
||||
let mut b = Fixed::zeroed(4);
|
||||
b.put(0, &[1]);
|
||||
b.put(3, &[2, 2]);
|
||||
b.put(2, &[3]);
|
||||
assert!(b.error().is_some());
|
||||
assert_eq!(b.finish(|| "a test layout".to_string()), [1, 0, 3, 0]);
|
||||
assert_eq!(fixed_layout_errors(), before + 1);
|
||||
}
|
||||
|
||||
/// A group splits into header and entries.
|
||||
#[test]
|
||||
fn a_group_splits_into_header_and_entries() {
|
||||
use crate::export::synth::{tdmn, tdsn};
|
||||
let rec = || Chunk::list(*b"tdbs", Vec::new());
|
||||
let mut kids = vec![tdsn("h"), tdmn("A"), rec(), tdmn("ADBE Group End")];
|
||||
let (header, entries) = split_group(&mut kids).unwrap();
|
||||
assert_eq!(header.len(), 1);
|
||||
let names: Vec<(&str, usize)> = entries.iter().map(|(n, v)| (n.as_str(), v.len())).collect();
|
||||
assert_eq!(names, [("A", 2), ("ADBE Group End", 1)]);
|
||||
// A match name without its node is an error, not a quiet stop.
|
||||
let mut broken = vec![tdmn("A")];
|
||||
assert!(split_group(&mut broken).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,6 +264,8 @@ pub(crate) static TEXT_ANIMATOR_RECORDS: &[Node] = &[
|
||||
R("ADBE Text Opacity", Rec { state: 1, label: "-_0_/-", dims: 1, template: 0, class: 0xffffffff, byte5: 0x01, header: &[], cdat_len: 40, cdat: &[37.0], key_size: 0, limits: Some((0.0, 100.0)), tdpi: None }),
|
||||
R("ADBE Text Fill Color", Rec { state: 1, label: "-_0_/-", dims: 4, template: 0, class: 0x0002ffff, byte5: 0x07, header: &[(79, 1)], cdat_len: 96, cdat: &[255.0, 0.0, 255.0], key_size: 0, limits: None, tdpi: None }),
|
||||
R("ADBE Text Stroke Color", Rec { state: 1, label: "-_0_/-", dims: 4, template: 0, class: 0x0002ffff, byte5: 0x07, header: &[(79, 1)], cdat_len: 96, cdat: &[255.0, 0.0, 0.0, 255.0], key_size: 0, limits: None, tdpi: None }),
|
||||
// text-synthetic.aep (#3170): the record After Effects wrote for Stroke Opacity 40 %.
|
||||
R("ADBE Text Stroke Opacity", Rec { state: 1, label: "-_0_/-", dims: 1, template: 0, class: 0xffffffff, byte5: 0x01, header: &[], cdat_len: 40, cdat: &[40.0], key_size: 0, limits: Some((0.0, 100.0)), tdpi: None }),
|
||||
R("ADBE Text Stroke Width", Rec { state: 1, label: "-_0_/-", dims: 1, template: 0, class: 0xffffffff, byte5: 0x01, header: &[], cdat_len: 40, cdat: &[3.0], key_size: 0, limits: Some((-1000.0, 1000.0)), tdpi: None }),
|
||||
R("ADBE Text Tracking Amount", Rec { state: 1, label: "-_0_/-", dims: 1, template: 0, class: 0xffffffff, byte5: 0x01, header: &[], cdat_len: 40, cdat: &[20.0], key_size: 0, limits: Some((-32000.0, 32000.0)), tdpi: None }),
|
||||
R("ADBE Text Line Spacing", Rec { state: 1, label: "-_0_/-", dims: 2, template: 0, class: 0x0002ffff, byte5: 0x01, header: &[], cdat_len: 80, cdat: &[10.0, 20.0], key_size: 0, limits: Some((-32000.0, 32000.0)), tdpi: None }),
|
||||
|
||||
+152
-7
@@ -1,6 +1,6 @@
|
||||
//! After Effects project (`.aep`) import: the typed view of [`effectcraft_aep`] mapped into an
|
||||
//! EffectCraft [`Project`]. The XML form (`.aepx`) is accepted as well: it is read into the same
|
||||
//! chunk tree ([`crate::parse_any`] picks the reader by content).
|
||||
//! EffectCraft [`Project`]. The XML form (`.aepx`) is accepted as well: both are read into the same
|
||||
//! flat chunk index (an `.aep` in place, an `.aepx` decoded into one buffer first).
|
||||
//!
|
||||
//! What arrives: the project item tree (folders), project settings (depth, working space, time
|
||||
//! display), compositions (size, exact frame rate, duration, work area, background, pixel
|
||||
@@ -14,7 +14,8 @@
|
||||
//! missing-footage placeholders). `docs/aep-import.md` has the full list.
|
||||
//!
|
||||
//! What does not arrive is **reported**, never dropped silently: [`ImportReport`] counts other
|
||||
//! effects (by match name) and unimported effect parameters, unusable masks, layer style
|
||||
//! effects (by match name; they arrive as placeholders that render nothing, with their parameters
|
||||
//! for expressions) and unimported effect parameters, unusable masks, layer style
|
||||
//! features, text layer features, shape items, unsupported blend modes and transform
|
||||
//! properties, simplified keyframes and unreadable data per [`LossCategory`]. By default the import
|
||||
//! is refused when anything would be lost ([`ImportOptions::allow_losses`] lifts that); a refusal
|
||||
@@ -30,6 +31,7 @@ mod effects;
|
||||
mod lumetri;
|
||||
mod markers;
|
||||
mod masks;
|
||||
mod placeholder;
|
||||
mod props;
|
||||
mod puppet;
|
||||
mod report;
|
||||
@@ -42,6 +44,9 @@ mod time;
|
||||
|
||||
use effectcraft_project::{ItemId, Project, ProjectSettings};
|
||||
|
||||
use crate::container::index::{Root, TreeIndex};
|
||||
use crate::container::{AepxDrafts, Limits, index_aepx};
|
||||
|
||||
pub use effects::supported_effects;
|
||||
pub use report::{AeVersionInfo, ImportReport, Imported, LIMITATIONS, Loss, LossCategory, MAX_DETAILS, TESTED_MAJORS, UNKNOWN};
|
||||
|
||||
@@ -115,17 +120,30 @@ pub struct ImportResult {
|
||||
/// [`AepImportError::Refused`] when something would be lost and `allow_losses` is not set. On any
|
||||
/// error `project` is unchanged.
|
||||
pub fn import(project: &mut Project, bytes: &[u8], options: &ImportOptions<'_>) -> Result<ImportResult, AepImportError> {
|
||||
let file = crate::parse_any(bytes)?;
|
||||
let view = crate::Project::new(&file).ok_or(AepImportError::NoProject)?;
|
||||
// The importer only reads: an `.aep` is indexed in place (one flat array that borrows the
|
||||
// bytes); an `.aepx` is decoded into one buffer, which the index borrows.
|
||||
if crate::is_aepx(bytes) {
|
||||
let AepxDrafts { buffer, nodes, trailer } = index_aepx(bytes, Limits::default())?;
|
||||
let index = TreeIndex::from_drafts(&buffer, nodes, trailer);
|
||||
import_root(project, Root::from(&index), options)
|
||||
} else {
|
||||
let index = TreeIndex::parse(bytes)?;
|
||||
import_root(project, Root::from(&index), options)
|
||||
}
|
||||
}
|
||||
|
||||
/// [`import`] of a file read into either tree.
|
||||
fn import_root(project: &mut Project, file: Root<'_, '_>, options: &ImportOptions<'_>) -> Result<ImportResult, AepImportError> {
|
||||
let view = crate::Project::of(file).ok_or(AepImportError::NoProject)?;
|
||||
// Work on a copy so a refusal leaves the project untouched (compositions are shared, cheap).
|
||||
let mut work = project.clone();
|
||||
let (folder, comps, items, mut report) = build::run(&mut work, &view, options);
|
||||
report.ae_version = report::AeVersionInfo::of(&file);
|
||||
report.ae_version = report::AeVersionInfo::of_root(file);
|
||||
if let Some(line) = report.ae_version.limitation() {
|
||||
report.limitations.push(line);
|
||||
}
|
||||
let mut col = report::Collector::default();
|
||||
let settings = settings::map(&file, &work.settings, &mut col);
|
||||
let settings = settings::map(file, &work.settings, &mut col);
|
||||
for loss in col.finish().losses.into_iter().filter(|_| options.settings) {
|
||||
let at = report.losses.iter().position(|l| l.category > loss.category).unwrap_or(report.losses.len());
|
||||
report.losses.insert(at, loss);
|
||||
@@ -157,3 +175,130 @@ pub fn analyze_with(bytes: &[u8], options: &ImportOptions<'_>) -> Result<ImportR
|
||||
let options = ImportOptions { allow_losses: true, ..*options };
|
||||
Ok(import(&mut scratch, bytes, &options)?.report)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::container::{AepFile, Body, Chunk, parse, write};
|
||||
|
||||
/// Asserts the two destination projects are structurally equal and serialize identically (layers,
|
||||
/// properties and values included, which `ImportResult` does not carry). Nothing is normalized:
|
||||
/// the import is deterministic, ids and timestamps included.
|
||||
fn same_project(a: &Project, b: &Project, name: &str) {
|
||||
assert!(a == b, "{name}: the imported projects differ through the index");
|
||||
let (ja, jb) = (serde_json::to_string(a).ok(), serde_json::to_string(b).ok());
|
||||
assert!(ja.is_some() && ja == jb, "{name}: the serialized projects differ through the index");
|
||||
}
|
||||
|
||||
/// Imports `bytes` through the owned chunk tree and through the index: the same project, report
|
||||
/// and settings, or the same error.
|
||||
fn both(bytes: &[u8], name: &str) {
|
||||
let exists = |_: &str| true;
|
||||
let options = ImportOptions { allow_losses: true, ..ImportOptions::new(&exists) };
|
||||
match (parse(bytes), TreeIndex::parse(bytes)) {
|
||||
(Ok(file), Ok(index)) => {
|
||||
let (mut pa, mut pb) = (Project::default(), Project::default());
|
||||
let a = import_root(&mut pa, Root::from(&file), &options);
|
||||
let b = import_root(&mut pb, Root::from(&index), &options);
|
||||
assert!(a == b, "{name}: the import differs through the index");
|
||||
same_project(&pa, &pb, name);
|
||||
}
|
||||
(Err(a), Err(b)) => assert_eq!(a, b, "{name}"),
|
||||
(a, b) => panic!("{name}: {:?} vs {:?}", a.err(), b.err()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A 40-byte NUL-padded match name.
|
||||
fn tdmn(name: &str) -> Chunk<'static> {
|
||||
let mut b = name.as_bytes().to_vec();
|
||||
b.resize(40, 0);
|
||||
Chunk::data(*b"tdmn", b)
|
||||
}
|
||||
|
||||
/// A synthetic project imports the same through the index.
|
||||
#[test]
|
||||
fn a_synthetic_project_imports_the_same_through_the_index() {
|
||||
// A composition with a layer whose effect stores arbitrary data and a named value group.
|
||||
let utf8 = |id: [u8; 4], t: &str| Chunk { id, body: Body::Chunks(vec![Chunk::data(*b"Utf8", t.as_bytes().to_vec())]), pad: None };
|
||||
let record = Chunk::list(*b"tdbs", vec![Chunk::data(*b"tdsb", vec![0, 0, 0, 1]), Chunk::data(*b"cdat", vec![0, 0, 0, 1])]);
|
||||
let values = Chunk::list(
|
||||
*b"tdgp",
|
||||
vec![
|
||||
utf8(*b"tdsn", "Mine"),
|
||||
tdmn("ADBE Easy Levels2-0001"),
|
||||
record,
|
||||
Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", vec![0u8; 108])]),
|
||||
tdmn("ADBE Group End"),
|
||||
],
|
||||
);
|
||||
let part = Chunk::list(*b"parT", vec![Chunk::data(*b"parn", vec![0, 0, 0, 2]), tdmn("ADBE Easy Levels2-0001"), Chunk::data(*b"pard", vec![0u8; 148])]);
|
||||
let sspc = Chunk::list(*b"sspc", vec![utf8(*b"fnam", "Levels"), part, values]);
|
||||
let parade = Chunk::list(*b"tdgp", vec![tdmn("ADBE Easy Levels2"), sspc, tdmn("ADBE Group End")]);
|
||||
let root = Chunk::list(*b"tdgp", vec![tdmn("ADBE Effect Parade"), parade, tdmn("ADBE Group End")]);
|
||||
let layer = Chunk::list(*b"Layr", vec![Chunk::data(*b"ldta", vec![0u8; 160]), Chunk::data(*b"Utf8", b"Layer".to_vec()), root]);
|
||||
let mut idta = vec![0u8; 64];
|
||||
idta[..2].copy_from_slice(&4u16.to_be_bytes());
|
||||
let mut cdta = vec![0u8; 200];
|
||||
cdta[4..12].copy_from_slice(&[0, 0, 0, 1, 0, 0, 0, 30]);
|
||||
let item = Chunk::list(*b"Item", vec![Chunk::data(*b"idta", idta), Chunk::data(*b"Utf8", b"Comp".to_vec()), Chunk::data(*b"cdta", cdta), layer]);
|
||||
let file = AepFile { chunks: vec![Chunk::data(*b"head", vec![0u8; 20]), Chunk::list(*b"Fold", vec![item])], trailer: std::borrow::Cow::Borrowed(&[]) };
|
||||
both(&write(&file).expect("write"), "synthetic");
|
||||
}
|
||||
|
||||
/// Every `.aep` of the fixture directory (skipped without `EFFECTCRAFT_AEP_FIXTURES`).
|
||||
#[test]
|
||||
fn every_fixture_imports_the_same_through_the_index() {
|
||||
let Some(dir) = std::env::var_os("EFFECTCRAFT_AEP_FIXTURES").filter(|d| !d.is_empty()) else { return };
|
||||
let Ok(entries) = std::fs::read_dir(dir) else { return };
|
||||
let mut paths: Vec<std::path::PathBuf> =
|
||||
entries.filter_map(Result::ok).map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "aep")).collect();
|
||||
paths.sort();
|
||||
for path in paths {
|
||||
let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
||||
both(&bytes, &path.display().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
/// Imports an `.aepx` through the owned tree ([`crate::read_aepx`]) and through the index
|
||||
/// ([`import`]): the same project, report and settings, or the same error.
|
||||
fn both_aepx(bytes: &[u8], name: &str) -> Result<ImportResult, AepImportError> {
|
||||
let exists = |_: &str| true;
|
||||
let options = ImportOptions { allow_losses: true, ..ImportOptions::new(&exists) };
|
||||
let (mut pa, mut pb) = (Project::default(), Project::default());
|
||||
let a = crate::read_aepx(bytes).map_err(AepImportError::from).and_then(|file| import_root(&mut pa, Root::from(&file), &options));
|
||||
let b = import(&mut pb, bytes, &options);
|
||||
assert!(a == b, "{name}: the .aepx import differs through the index");
|
||||
same_project(&pa, &pb, name);
|
||||
b
|
||||
}
|
||||
|
||||
/// A synthetic `.aepx` imports the same through the index as through the owned tree.
|
||||
#[test]
|
||||
fn a_synthetic_aepx_imports_the_same_through_the_index() {
|
||||
// The comp of the owned-tree test above (`idta` type 4, `cdta` 1/30 s frame duration).
|
||||
let idta = format!("0004{}", "00".repeat(62));
|
||||
let cdta = format!("00000000000000010000001e{}", "00".repeat(188));
|
||||
let x = format!(
|
||||
"<?xml version=\"1.0\"?><AfterEffectsProject><head bdata=\"{}\"/><Fold><Item><idta bdata=\"{idta}\"/><string>Comp</string><cdta bdata=\"{cdta}\"/></Item></Fold><ProjectXMPMetadata>x</ProjectXMPMetadata></AfterEffectsProject>",
|
||||
"00".repeat(20)
|
||||
);
|
||||
let imported = both_aepx(x.as_bytes(), "synthetic").expect("the synthetic project imports");
|
||||
assert_eq!(imported.comps.len(), 1);
|
||||
assert_eq!(both_aepx(b"<AfterEffectsProject/>", "empty").err(), Some(AepImportError::NoProject));
|
||||
assert!(matches!(both_aepx(b"<AfterEffectsProject><a>", "broken"), Err(AepImportError::Container(crate::AepError::Xml { .. }))));
|
||||
}
|
||||
|
||||
/// Every `.aepx` of the fixture directory (skipped without `EFFECTCRAFT_AEP_FIXTURES`).
|
||||
#[test]
|
||||
fn every_fixture_aepx_imports_the_same_through_the_index() {
|
||||
let Some(dir) = std::env::var_os("EFFECTCRAFT_AEP_FIXTURES").filter(|d| !d.is_empty()) else { return };
|
||||
let Ok(entries) = std::fs::read_dir(dir) else { return };
|
||||
let mut paths: Vec<std::path::PathBuf> =
|
||||
entries.filter_map(Result::ok).map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "aepx")).collect();
|
||||
paths.sort();
|
||||
for path in paths {
|
||||
let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
||||
let _ = both_aepx(&bytes, &path.display().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ use effectcraft_color::{BlendMode, Label};
|
||||
use effectcraft_keyframe::Value;
|
||||
use effectcraft_project::build::{self, Ids};
|
||||
use effectcraft_project::{
|
||||
AutoOrient, Comp, Footage, FootageKind, ItemId, ItemKind, Layer, LayerId, LayerSource, LightKind, MatteKind, Project, Quality, Solid, TrackMatte,
|
||||
AutoOrient, Comp, Footage, FootageKind, ItemId, ItemKind, Layer, LayerId, LayerSource, LightKind, MatteKind, Project, Quality, Solid, SourceLayer,
|
||||
TrackMatte,
|
||||
};
|
||||
use effectcraft_time::Tick;
|
||||
|
||||
@@ -25,7 +26,7 @@ use crate::import::props::{AnchorUnit, import_transform};
|
||||
use crate::import::report::{Collector, ImportReport, LossCategory};
|
||||
use crate::import::shapes::import_shapes;
|
||||
use crate::import::styles::import_layer_styles;
|
||||
use crate::import::text::{report_text_extras, text_doc};
|
||||
use crate::import::text::{import_source_text_expression, report_text_extras, text_doc};
|
||||
use crate::import::text_anim::import_animators;
|
||||
use crate::import::time::{TimeMap, frame_rate};
|
||||
|
||||
@@ -216,7 +217,17 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_
|
||||
let aep_id = item.id();
|
||||
// An item without a stored name shows its file's name, a sequence `shot_[0101-0103].exr`
|
||||
// (126, 603-607).
|
||||
let name = if name.is_empty() { default_footage_name(item, &f).unwrap_or_else(|| "Footage".to_string()) } else { name };
|
||||
// One layer of a Photoshop file is `<layer>/<file>`, as EffectCraft's own Photoshop import
|
||||
// names it (#3087).
|
||||
let name = if name.is_empty() {
|
||||
let file = default_footage_name(item, &f).unwrap_or_else(|| "Footage".to_string());
|
||||
match &f.psd_layer {
|
||||
Some(l) if !l.name.is_empty() => format!("{}/{file}", l.name),
|
||||
_ => file,
|
||||
}
|
||||
} else {
|
||||
name
|
||||
};
|
||||
if f.is_solid {
|
||||
// A null object's placeholder solid is not an item here.
|
||||
if aep_id.is_some_and(|i| null_only.contains(&i)) {
|
||||
@@ -285,6 +296,8 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_
|
||||
cx.col.missing_footage.push(shown);
|
||||
}
|
||||
let kind = if sequence.is_empty() { footage_kind(&path, f.native_frame_rate, f.audio_sample_rate.is_some()) } else { FootageKind::Sequence };
|
||||
// A placed PDF / Illustrator file keeps After Effects' framing and size (#3099).
|
||||
let placed_page = kind == FootageKind::Still && is_placed_page_path(&path);
|
||||
let mut footage = Footage {
|
||||
path,
|
||||
kind,
|
||||
@@ -295,7 +308,9 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_
|
||||
// footage), and only then.
|
||||
has_audio: kind == FootageKind::Audio || (kind == FootageKind::Video && f.audio_sample_rate.is_some()),
|
||||
missing: !present,
|
||||
placed_page,
|
||||
sequence,
|
||||
layer: source_layer(&f, &name, &mut cx.col),
|
||||
..Footage::default()
|
||||
};
|
||||
// The native frame rate and the stored duration of sequences and clips (352, 603, 606).
|
||||
@@ -327,6 +342,42 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `path` names a file whose page is framed as After Effects places it
|
||||
/// ([`Footage::placed_page`]): an Illustrator or PDF file, by its extension. EPS files keep
|
||||
/// their bounding box at their own size: how After Effects sizes them was not measured (#3099).
|
||||
fn is_placed_page_path(path: &str) -> bool {
|
||||
let ext = path.rsplit(['/', '\\']).next().and_then(|name| name.rsplit_once('.')).map(|(_, ext)| ext.to_ascii_lowercase());
|
||||
matches!(ext.as_deref(), Some("pdf" | "ai"))
|
||||
}
|
||||
|
||||
/// The Photoshop layer a footage item shows (#3087): at its own bounds when the item is as big
|
||||
/// as they are (Retain Layer Sizes), else on the document. A layer without pixels (an adjustment
|
||||
/// layer) keeps the merged image and is reported. So is a layer as big as the document but not at
|
||||
/// its corner (the item's size fits both framings; its bounds are used), and an item as big as
|
||||
/// neither (the document is used).
|
||||
fn source_layer(f: &crate::Footage, name: &str, col: &mut Collector) -> Option<SourceLayer> {
|
||||
let l = f.psd_layer.as_ref()?;
|
||||
let Some(size) = l.size() else {
|
||||
col.lose(LossCategory::UnsupportedItems, format!("footage '{name}': a Photoshop layer without pixels (an adjustment layer), the merged image used"));
|
||||
return None;
|
||||
};
|
||||
let layer_size = size == (f.width, f.height);
|
||||
if !layer_size && l.document.iter().all(|side| *side > 0) && !l.document_is((f.width, f.height)) {
|
||||
col.lose(
|
||||
LossCategory::UnsupportedItems,
|
||||
format!("footage '{name}': {} x {} is neither the Photoshop layer's size nor the document's, shown on the document", f.width, f.height),
|
||||
);
|
||||
}
|
||||
let [top, left, ..] = l.bounds;
|
||||
if layer_size && (top, left) != (0, 0) && l.document_is(size) {
|
||||
col.lose(
|
||||
LossCategory::UnsupportedItems,
|
||||
format!("footage '{name}': a Photoshop layer as big as the document but at ({left}, {top}), shown at its own bounds (Retain Layer Sizes assumed)"),
|
||||
);
|
||||
}
|
||||
Some(SourceLayer { index: l.index, name: l.name.clone(), layer_size, ..SourceLayer::default() })
|
||||
}
|
||||
|
||||
/// The name After Effects shows for a footage item that stores none: the file's name, or for a
|
||||
/// sequence the name with the frame range (`shot_[0101-0103].exr`).
|
||||
fn default_footage_name(item: &AepItem<'_, '_>, f: &crate::Footage) -> Option<String> {
|
||||
@@ -453,11 +504,13 @@ fn camera_light_orient(auto_oriented: bool, light: Option<LightKind>) -> AutoOri
|
||||
}
|
||||
|
||||
/// The unit a layer's anchor is stored in.
|
||||
fn anchor_unit(camera_or_light: bool, text_or_shape: bool, size: (u32, u32)) -> AnchorUnit {
|
||||
fn anchor_unit(camera_or_light: bool, text_or_shape: bool, null: bool, size: (u32, u32)) -> AnchorUnit {
|
||||
if camera_or_light {
|
||||
AnchorUnit::PointOfInterest
|
||||
} else if text_or_shape {
|
||||
AnchorUnit::Pixels
|
||||
} else if null {
|
||||
AnchorUnit::Null(size.0, size.1)
|
||||
} else {
|
||||
AnchorUnit::Source(size.0, size.1)
|
||||
}
|
||||
@@ -582,7 +635,7 @@ fn build_layers(project: &mut Project, cx: &mut Ctx<'_>, defs: &EffectDefinition
|
||||
import_layer_styles(&layer, &mut l, &comp.global_light, &mut Ids(&mut project.next_id), &tm, &what, &mut cx.col);
|
||||
// Text and shape layers store their anchor in pixels (385, 462); cameras and lights their
|
||||
// point of interest.
|
||||
let anchor = anchor_unit(is_camera || light.is_some(), is_text || is_shape, size);
|
||||
let anchor = anchor_unit(is_camera || light.is_some(), is_text || is_shape, is_null, size);
|
||||
if let Some(tr) = l.props.sub_mut("transform") {
|
||||
import_transform(&layer, &name, comp_size, anchor, &tm, tr, &mut cx.col);
|
||||
}
|
||||
@@ -654,8 +707,8 @@ fn build_layers(project: &mut Project, cx: &mut Ctx<'_>, defs: &EffectDefinition
|
||||
}
|
||||
}
|
||||
|
||||
/// The Source Text of a text layer from its text document, and the reports of what is not
|
||||
/// imported.
|
||||
/// The Source Text of a text layer from its text document and its expression, and the reports
|
||||
/// of what is not imported.
|
||||
fn import_source_text(l: &mut Layer, layer: &AepLayer<'_, '_>, what: &str, cx: &mut Ctx<'_>) {
|
||||
match layer.text_document() {
|
||||
Some(doc) => {
|
||||
@@ -667,6 +720,7 @@ fn import_source_text(l: &mut Layer, layer: &AepLayer<'_, '_>, what: &str, cx: &
|
||||
}
|
||||
None => cx.col.lose(LossCategory::DamagedData, format!("{what}: the text document is unreadable, the layer is imported with empty text")),
|
||||
}
|
||||
import_source_text_expression(layer, l.props.prop_mut("text/sourceText"), what, &mut cx.col);
|
||||
report_text_extras(layer, what, &mut cx.col);
|
||||
}
|
||||
|
||||
@@ -906,6 +960,18 @@ fn resolve_parents(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// #3099: an `.ai` or `.pdf` from an `.aep` is a placed page; an EPS (not measured in After
|
||||
/// Effects) and other files are not.
|
||||
#[test]
|
||||
fn only_illustrator_and_pdf_files_are_placed_pages() {
|
||||
for path in [r"C:\fixture\x\logo.ai", "/work/Logo.AI", "art.pdf", r"C:\a.b\page.PDF"] {
|
||||
assert!(is_placed_page_path(path), "{path}");
|
||||
}
|
||||
for path in [r"C:\fixture\x\still.eps", "a.epsf", "a.epsi", "still.png", r"C:\dir.ai\file", "ai", ""] {
|
||||
assert!(!is_placed_page_path(path), "{path}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unlisted_extensions_follow_what_the_file_stores() {
|
||||
assert_eq!(footage_kind("C:/clips/a.MP4", 0, false), FootageKind::Video);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Effects: a table maps an After Effects effect (its match name) and its parameters (by their
|
||||
//! index in `parT`) to an EffectCraft effect, a parameter id and a unit conversion. Effects and
|
||||
//! parameters outside the table are reported in [`LossCategory::Effects`] by match name, never
|
||||
//! dropped silently.
|
||||
//! index in `parT`) to an EffectCraft effect, a parameter id and a unit conversion. Parameters
|
||||
//! outside the table are reported in [`LossCategory::Effects`] by match name, never dropped
|
||||
//! silently. An effect outside it arrives as a placeholder holding its parameters (`placeholder.rs`)
|
||||
//! and is reported too.
|
||||
//!
|
||||
//! Every conversion is backed by the corpus (`docs/aep-format.md` 3.7, cases 356-450, 511-516):
|
||||
//!
|
||||
@@ -34,7 +35,7 @@
|
||||
//! import. Hue/Saturation's master values and Levels' values are arbitrary data, decoded by the
|
||||
//! reader (444-446, 512-516).
|
||||
|
||||
use crate::effect_map::{CRYPTOMATTE_OUTPUT, Conv, EFFECTS, EffectMap, Extra, HUE_SATURATION_MASTER, LEVELS_RGB, ParamMap, popup_key};
|
||||
use crate::effect_map::{CRYPTOMATTE_OUTPUT, Conv, EFFECTS, EffectMap, Extra, HUE_SATURATION_MASTER, LEVELS_RGB, ParamMap, popup_alias, popup_key};
|
||||
use crate::{
|
||||
CryptomatteData, CurvesData, DefinitionSource, Effect as AepEffect, EffectDefinitions, EffectParam, ExtractorChannels, HueSaturationData,
|
||||
Layer as AepLayer, LayerRef, LevelsData, MeshData, ParamKind, ParamValue,
|
||||
@@ -82,44 +83,37 @@ pub(crate) fn import_effects<'f, 'a>(
|
||||
continue;
|
||||
}
|
||||
let shown = fx.display_name().unwrap_or_else(|| fx.match_name().to_string());
|
||||
let Some(map) = EFFECTS.iter().find(|m| m.match_name == fx.match_name()) else {
|
||||
col.lose(LossCategory::Effects, format!("{}: '{}' has the effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name()));
|
||||
continue;
|
||||
};
|
||||
let Some(spec) = effectcraft_effects::find(map.effect) else {
|
||||
col.lose(LossCategory::Effects, format!("{}: '{}' has the effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name()));
|
||||
continue;
|
||||
};
|
||||
let found = EFFECTS.iter().find(|m| m.match_name == fx.match_name()).and_then(|m| Some((m, effectcraft_effects::find(m.effect)?)));
|
||||
let lost = format!("{}: '{}' has the effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name());
|
||||
if defs.source(&fx) == DefinitionSource::Missing {
|
||||
col.lose(
|
||||
LossCategory::Effects,
|
||||
format!("{}: '{}' has the effect '{shown}' ({}) without readable parameter definitions, not imported", cx.comp, cx.layer, fx.match_name()),
|
||||
);
|
||||
match found {
|
||||
Some(_) => col.lose(LossCategory::Effects, format!("{lost} without readable parameter definitions, not imported")),
|
||||
None => col.lose_unmapped_effect(fx.match_name(), lost),
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let size = [f64::from(cx.size.0), f64::from(cx.size.1)];
|
||||
let mut group = effectcraft_effects::instantiate(spec, ids, &shown, size);
|
||||
match fx.enabled() {
|
||||
Some(on) => group.enabled = on,
|
||||
None => col.lose(LossCategory::DamagedData, format!("{}: '{}': the fx switch of '{shown}' is unreadable, imported switched on", cx.comp, cx.layer)),
|
||||
if found.is_none() && col.placeholder_cost >= crate::import::placeholder::MAX_COST {
|
||||
// The import's placeholder budget is spent: the definitions (shared by many instances)
|
||||
// are not read again. Named like any effect without a counterpart, in a group of its
|
||||
// own (with the kept instances it would read as kept).
|
||||
let key = format!("{} (not kept)", fx.match_name());
|
||||
col.lose_unmapped_effect(&key, format!("{lost}, not kept (past the import's placeholder parameters)"));
|
||||
continue;
|
||||
}
|
||||
let params = defs.params(&fx);
|
||||
// Borrowed definitions (another instance's or the project copy) may not name every value
|
||||
// record this instance has: such a record has nothing to import into, so it is reported.
|
||||
if params.first().is_some_and(|p| p.borrowed_definition) {
|
||||
let defined: std::collections::HashSet<&str> = params.iter().map(|p| p.match_name.as_str()).collect();
|
||||
for name in fx.value_record_names().iter().filter(|n| !defined.contains(n.as_str())) {
|
||||
col.lose(
|
||||
LossCategory::Effects,
|
||||
format!(
|
||||
"{}: '{}' effect '{shown}' ({}): the value record {name} has no parameter definition, not imported",
|
||||
cx.comp,
|
||||
cx.layer,
|
||||
fx.match_name()
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
report_records_without_definition(&fx, ¶ms, cx, &shown, col);
|
||||
let Some((map, spec)) = found else {
|
||||
// No counterpart: kept as a placeholder that renders nothing, for expressions (#3087).
|
||||
let mut group = crate::import::placeholder::placeholder(&fx, ¶ms, cx, &shown, ids, refs, col);
|
||||
set_enabled(&fx, &mut group, cx, &shown, col);
|
||||
col.lose_unmapped_effect(fx.match_name(), format!("{lost}, kept without rendering"));
|
||||
col.imported.placeholder_effects = col.imported.placeholder_effects.saturating_add(1);
|
||||
target.children.push(Node::Group(group));
|
||||
continue;
|
||||
};
|
||||
let size = [f64::from(cx.size.0), f64::from(cx.size.1)];
|
||||
let mut group = effectcraft_effects::instantiate(spec, ids, &shown, size);
|
||||
set_enabled(&fx, &mut group, cx, &shown, col);
|
||||
if map.extra == Extra::Lumetri {
|
||||
crate::import::lumetri::import_lumetri(&fx, ¶ms, cx, &shown, ParamOut { group: &mut group, refs: &mut *refs, col: &mut *col });
|
||||
} else if map.extra == Extra::Cryptomatte {
|
||||
@@ -134,6 +128,29 @@ pub(crate) fn import_effects<'f, 'a>(
|
||||
}
|
||||
}
|
||||
|
||||
/// The effect's fx switch.
|
||||
fn set_enabled(fx: &AepEffect<'_, '_>, group: &mut PropGroup, cx: &LayerCtx<'_>, shown: &str, col: &mut Collector) {
|
||||
match fx.enabled() {
|
||||
Some(on) => group.enabled = on,
|
||||
None => col.lose(LossCategory::DamagedData, format!("{}: '{}': the fx switch of '{shown}' is unreadable, imported switched on", cx.comp, cx.layer)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Borrowed definitions (another instance's or the project copy) may not name every value record
|
||||
/// this instance has: such a record has nothing to import into, so it is reported.
|
||||
fn report_records_without_definition(fx: &AepEffect<'_, '_>, params: &[EffectParam<'_, '_>], cx: &LayerCtx<'_>, shown: &str, col: &mut Collector) {
|
||||
if !params.first().is_some_and(|p| p.borrowed_definition) {
|
||||
return;
|
||||
}
|
||||
let defined: std::collections::HashSet<&str> = params.iter().map(|p| p.match_name.as_str()).collect();
|
||||
for name in fx.value_record_names().iter().filter(|n| !defined.contains(n.as_str())) {
|
||||
col.lose(
|
||||
LossCategory::Effects,
|
||||
format!("{}: '{}' effect '{shown}' ({}): the value record {name} has no parameter definition, not imported", cx.comp, cx.layer, fx.match_name()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Parameters that never carry a value to import.
|
||||
pub(crate) fn carries_nothing(p: &EffectParam<'_, '_>) -> bool {
|
||||
matches!(p.kind, ParamKind::Button | ParamKind::NoData | ParamKind::GroupStart | ParamKind::GroupEnd) || (p.index == 0 && p.kind == ParamKind::Layer)
|
||||
@@ -242,23 +259,12 @@ pub(crate) fn import_mapped(p: &EffectParam<'_, '_>, m: &ParamMap, cx: &LayerCtx
|
||||
Conv::Checkbox => Kind::EffectBool,
|
||||
// Handled above.
|
||||
Conv::LayerRef { .. } | Conv::Skip => return,
|
||||
Conv::Percent { valid_max } => {
|
||||
Conv::Percent { valid_max } | Conv::Plain { valid_max } | Conv::Factor { valid_max, .. } => {
|
||||
if !checked(valid_max, col) {
|
||||
return;
|
||||
}
|
||||
Kind::EffectNumber(100.0 / valid_max)
|
||||
}
|
||||
Conv::Plain { valid_max } => {
|
||||
if !checked(valid_max, col) {
|
||||
return;
|
||||
}
|
||||
Kind::EffectNumber(1.0)
|
||||
}
|
||||
Conv::Factor { valid_max, factor } => {
|
||||
if !checked(valid_max, col) {
|
||||
return;
|
||||
}
|
||||
Kind::EffectNumber(factor)
|
||||
let Some(scale) = m.conv.number_scale() else { return };
|
||||
Kind::EffectNumber(scale)
|
||||
}
|
||||
};
|
||||
// Grouped parameters are addressed by path (`master/exposure`).
|
||||
@@ -364,7 +370,7 @@ fn report_beyond_limit<'v>(limit: Option<(f64, f64)>, values: impl Iterator<Item
|
||||
/// A layer parameter: None stays unset, the owning layer is itself (`own`) or unset, another layer
|
||||
/// is resolved by [`resolve_layer_refs`] once the composition's layers exist.
|
||||
/// `names` is `(here, label)`, the effect and the parameter for the report.
|
||||
fn import_layer_ref(p: &EffectParam<'_, '_>, target: &str, own: bool, cx: &LayerCtx<'_>, names: (&str, &str), out: ParamOut<'_>) {
|
||||
pub(crate) fn import_layer_ref(p: &EffectParam<'_, '_>, target: &str, own: bool, cx: &LayerCtx<'_>, names: (&str, &str), out: ParamOut<'_>) {
|
||||
let (here, label) = names;
|
||||
let ParamOut { group, refs, col } = out;
|
||||
// After Effects hands the named layer's source to the effect, without its masks and effects
|
||||
@@ -413,8 +419,8 @@ pub(crate) fn resolve_layer_refs(
|
||||
}
|
||||
}
|
||||
|
||||
/// The EffectCraft item of each file item (by name, ignoring case and separators); `None` when
|
||||
/// the parameter here is not a popup.
|
||||
/// The EffectCraft item of each file item (by name, ignoring case and separators, and a known
|
||||
/// non-English name for it, [`popup_alias`]); `None` when the parameter here is not a popup.
|
||||
fn popup_mapping(file_items: &[String], ui: &ParamUi) -> Option<Vec<Option<u32>>> {
|
||||
let ParamUi::Popup { options } = ui else { return None };
|
||||
let norm = popup_key;
|
||||
@@ -425,7 +431,12 @@ fn popup_mapping(file_items: &[String], ui: &ParamUi) -> Option<Vec<Option<u32>>
|
||||
if item.trim() == "(-" {
|
||||
return None;
|
||||
}
|
||||
options.iter().position(|o| norm(o) == norm(item)).and_then(|i| u32::try_from(i).ok())
|
||||
let key = norm(item);
|
||||
options
|
||||
.iter()
|
||||
.position(|o| norm(o) == key)
|
||||
.or_else(|| popup_alias(&key).and_then(|a| options.iter().position(|o| norm(o) == a)))
|
||||
.and_then(|i| u32::try_from(i).ok())
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
@@ -799,7 +810,7 @@ fn px(v: f64) -> String {
|
||||
|
||||
/// A decoded value in EffectCraft's units, `None` when it does not fit the kind or is not a valid
|
||||
/// number.
|
||||
fn convert(value: ParamValue, kind: Kind) -> Option<Value> {
|
||||
pub(crate) fn convert(value: ParamValue, kind: Kind) -> Option<Value> {
|
||||
let raw = match (value, kind) {
|
||||
// The reader gives colours as ARGB fractions; `Kind` takes the stored 0..255.
|
||||
(ParamValue::Argb(c), Kind::EffectColor) => c.map(|x| x * 255.0).to_vec(),
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
//! EffectCraft's `timeRemap` property (seconds, keys in layer time) at the top of the layer's
|
||||
//! properties, where the engine's Enable Time Remapping puts it.
|
||||
|
||||
use crate::{Chunk, CueType, Layer as AepLayer, Marker as AepMarker, PropNode, Property as AepProp};
|
||||
use crate::container::index::Node as AepNode;
|
||||
use crate::{CueType, Layer as AepLayer, Marker as AepMarker, PropNode, Property as AepProp};
|
||||
use effectcraft_color::Label;
|
||||
use effectcraft_keyframe::Value;
|
||||
use effectcraft_project::build::Ids;
|
||||
@@ -23,12 +24,12 @@ use crate::import::report::{Collector, LossCategory};
|
||||
use crate::import::time::TimeMap;
|
||||
|
||||
/// The time scale of the marker list below `holder` (the layer, or the composition's `SecL`).
|
||||
fn marker_scale(holder: &Chunk<'_>) -> Option<u32> {
|
||||
holder.find_list(b"mrst")?.child_list(b"tdbs").and_then(AepProp::from_chunk)?.time_scale().filter(|s| *s != 0)
|
||||
fn marker_scale(holder: AepNode<'_, '_>) -> Option<u32> {
|
||||
holder.marker_list()?.child_list(b"tdbs").and_then(AepProp::from_chunk)?.time_scale().filter(|s| *s != 0)
|
||||
}
|
||||
|
||||
/// The markers of a layer (`holder` = the layer chunk) or a composition (`holder` = its `SecL`).
|
||||
pub(crate) fn import_markers(list: Vec<AepMarker>, holder: &Chunk<'_>, what: &str, tm: &TimeMap, col: &mut Collector) -> Vec<Marker> {
|
||||
pub(crate) fn import_markers(list: Vec<AepMarker>, holder: AepNode<'_, '_>, what: &str, tm: &TimeMap, col: &mut Collector) -> Vec<Marker> {
|
||||
let scale = marker_scale(holder).unwrap_or(tm.timescale);
|
||||
let mut out: Vec<Marker> = Vec::with_capacity(list.len());
|
||||
for m in list {
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
//! Placeholders: an effect with no EffectCraft counterpart (a third-party plug-in, a pseudo effect
|
||||
//! of expression controls) arrives as an effect group that renders nothing, as a missing plug-in
|
||||
//! does. Its effect id is the After Effects match name, so Find Missing Effects lists it. It holds
|
||||
//! the effect's parameters, flat and named as in After Effects, each with its value, keys and
|
||||
//! expression, so expressions that read them (`effect("Settings")("Speed")`) keep working. It is
|
||||
//! still reported, once per match name.
|
||||
//!
|
||||
//! The values keep After Effects' units, the ones its expressions read: sliders and angles as
|
||||
//! stored, points in layer pixels, colours RGBA 0..1, checkboxes on / off, popups as EffectCraft's
|
||||
//! 0-based items over the file's items in order (expressions read them 1-based, as After Effects
|
||||
//! does). Layer parameters name their layer (their keys and expression are reported). Paths and
|
||||
//! arbitrary data are not kept (reported when they hold something).
|
||||
//!
|
||||
//! The parameters placeholders walk, kept or not, and their popup items (by name length) are
|
||||
//! bounded per import ([`MAX_COST`]): definitions can be shared by many instances, so a small file
|
||||
//! could otherwise ask for very many properties. Once
|
||||
//! the budget is spent, later effects without a counterpart are reported without a placeholder.
|
||||
|
||||
use effectcraft_keyframe::Value;
|
||||
use effectcraft_project::build::Ids;
|
||||
use effectcraft_project::{GroupKind, Node, ParamUi, PropGroup, Property};
|
||||
|
||||
use crate::import::effects::{LayerCtx, ParamOut, PendingLayerRef, carries_nothing, convert, import_layer_ref, param_label};
|
||||
use crate::import::props::{Kind, import_expression, import_keys};
|
||||
use crate::import::report::{Collector, LossCategory};
|
||||
use crate::{Effect as AepEffect, EffectParam, ParamKind, ParamValue};
|
||||
|
||||
/// Most placeholder parameters (kept or not) and popup items one import walks.
|
||||
pub(crate) const MAX_COST: usize = 200_000;
|
||||
|
||||
/// Most items read from one placeholder popup.
|
||||
const MAX_POPUP_ITEMS: usize = 1024;
|
||||
|
||||
/// A popup item costs one more for each of these bytes in its name, so the names kept stay
|
||||
/// bounded too.
|
||||
const NAME_BYTES: usize = 16;
|
||||
|
||||
/// The placeholder of `fx`, with `params` (its parameter definitions) as properties.
|
||||
pub(crate) fn placeholder(
|
||||
fx: &AepEffect<'_, '_>,
|
||||
params: &[EffectParam<'_, '_>],
|
||||
cx: &LayerCtx<'_>,
|
||||
shown: &str,
|
||||
ids: &mut Ids<'_>,
|
||||
refs: &mut Vec<PendingLayerRef>,
|
||||
col: &mut Collector,
|
||||
) -> PropGroup {
|
||||
// The effect id is the match name; the group's match id is one segment of a property path
|
||||
// (a pseudo effect's `Pseudo/0.25` would be cut apart), so match paths find its parameters.
|
||||
let mut group = ids.group(&segment(fx.match_name()), shown);
|
||||
group.kind = GroupKind::Effect { effect: fx.match_name().to_string() };
|
||||
let here = format!("{}: '{}' effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name());
|
||||
for p in params {
|
||||
// Every parameter walked counts, kept or not: a definition shared by many instances is
|
||||
// otherwise walked again for each one.
|
||||
if carries_nothing(p) {
|
||||
col.placeholder_cost = col.placeholder_cost.saturating_add(1).min(MAX_COST);
|
||||
continue;
|
||||
}
|
||||
if col.placeholder_cost >= MAX_COST {
|
||||
col.lose(LossCategory::Effects, format!("{here}: parameters past the import's {MAX_COST} placeholder parameters not kept"));
|
||||
break;
|
||||
}
|
||||
let label = param_label(p);
|
||||
let Some((kind, ui, default)) = shape(p, cx.size) else {
|
||||
col.placeholder_cost = col.placeholder_cost.saturating_add(1);
|
||||
if p.stored().is_some() {
|
||||
col.lose(LossCategory::Effects, format!("{here}: parameter {label} not kept (type {:?})", p.kind));
|
||||
}
|
||||
continue;
|
||||
};
|
||||
let (items, names) = match &ui {
|
||||
ParamUi::Popup { options } => (options.len(), options.iter().map(|o| 1 + o.len() / NAME_BYTES).fold(0, usize::saturating_add)),
|
||||
_ => (0, 0),
|
||||
};
|
||||
if p.kind == ParamKind::Popup && popup_len(p).is_some_and(|n| n > items) {
|
||||
col.lose(LossCategory::Effects, format!("{here}: parameter {label}: the items past the first {MAX_POPUP_ITEMS} not kept"));
|
||||
}
|
||||
let cost = col.placeholder_cost.saturating_add(names).saturating_add(1);
|
||||
if cost > MAX_COST {
|
||||
// The budget is spent: nothing more is built, here or in later effects (definitions
|
||||
// shared by many instances would otherwise still be walked item by item).
|
||||
col.lose(
|
||||
LossCategory::Effects,
|
||||
format!("{here}: parameter {label} and the ones after it not kept (past the import's {MAX_COST} placeholder parameters)"),
|
||||
);
|
||||
col.placeholder_cost = MAX_COST;
|
||||
break;
|
||||
}
|
||||
col.placeholder_cost = cost;
|
||||
let mut prop = Property::new(ids.alloc(), ¶m_id(p), p.name.trim(), default).with_ui(ui);
|
||||
prop.spatial = p.kind == ParamKind::Point;
|
||||
prop.hold_only = matches!(p.kind, ParamKind::Checkbox | ParamKind::Popup | ParamKind::Layer);
|
||||
match kind {
|
||||
Some(kind) => {
|
||||
fill(p, &mut prop, kind, cx, (&here, &label), col);
|
||||
group.children.push(Node::Prop(prop));
|
||||
}
|
||||
// A layer parameter: the layer it names (set once every layer exists, by its uid).
|
||||
None => {
|
||||
let id = format!("@{}", prop.uid);
|
||||
group.children.push(Node::Prop(prop));
|
||||
import_layer_ref(p, &id, true, cx, (&here, &label), ParamOut { group: &mut group, refs: &mut *refs, col: &mut *col });
|
||||
}
|
||||
}
|
||||
}
|
||||
group
|
||||
}
|
||||
|
||||
/// How parameter `p` is held on a layer `size` big: its unit conversion (`None` for a layer
|
||||
/// parameter), its control and its value until one is read. `None` for a type that is not kept.
|
||||
fn shape(p: &EffectParam<'_, '_>, size: (u32, u32)) -> Option<(Option<Kind>, ParamUi, Value)> {
|
||||
let (kind, ui, default) = match p.kind {
|
||||
ParamKind::IntSlider | ParamKind::FixedSlider | ParamKind::FloatSlider => (Kind::EffectNumber(1.0), slider_ui(p), Value::Scalar(0.0)),
|
||||
ParamKind::Angle => (Kind::EffectNumber(1.0), ParamUi::Angle, Value::Scalar(0.0)),
|
||||
ParamKind::Checkbox => (Kind::EffectBool, ParamUi::Checkbox, Value::Bool(false)),
|
||||
ParamKind::Color => (Kind::EffectColor, ParamUi::Color, Value::Color([0.0, 0.0, 0.0, 1.0])),
|
||||
ParamKind::Point => (Kind::EffectPoint(f64::from(size.0), f64::from(size.1)), ParamUi::Point, Value::Vec2([0.0, 0.0])),
|
||||
ParamKind::Layer => return Some((None, ParamUi::Layer, Value::Layer(None))),
|
||||
ParamKind::Popup => {
|
||||
// The file's items, separators (`(-`) included: After Effects counts them.
|
||||
let options: Vec<String> = match &p.items {
|
||||
Some(items) => items.iter().take(MAX_POPUP_ITEMS).cloned().collect(),
|
||||
None => (1..=popup_len(p)?.min(MAX_POPUP_ITEMS)).map(|i| format!("Item {i}")).collect(),
|
||||
};
|
||||
let n = u32::try_from(options.len()).ok().filter(|n| *n > 0)?;
|
||||
(Kind::EffectPopup(n), ParamUi::Popup { options }, Value::Enum(0))
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
Some((Some(kind), ui, default))
|
||||
}
|
||||
|
||||
/// A slider's control: a float slider's valid range and drag range when they are ranges (only a
|
||||
/// float slider's are decoded), else a plain number.
|
||||
fn slider_ui(p: &EffectParam<'_, '_>) -> ParamUi {
|
||||
match (p.valid_min(), p.valid_max(), p.slider_range()) {
|
||||
(Some(min), Some(max), Some((smin, smax))) if [min, max, smin, smax].iter().all(|v| v.is_finite()) && min <= max && smin <= smax => {
|
||||
ParamUi::Slider { min, max, slider_min: smin.clamp(min, max), slider_max: smax.clamp(min, max), decimals: 2 }
|
||||
}
|
||||
_ => ParamUi::Number,
|
||||
}
|
||||
}
|
||||
|
||||
/// How many items a popup has: the file's names, else the count in its definition.
|
||||
fn popup_len(p: &EffectParam<'_, '_>) -> Option<usize> {
|
||||
p.items.as_ref().map(Vec::len).or_else(|| p.popup_item_count().map(usize::from))
|
||||
}
|
||||
|
||||
/// The property id of `p`: its match name when that is one segment of a property path (a
|
||||
/// third-party effect's `CC Cylinder-0003`), else `param<index>` (a pseudo effect's
|
||||
/// `Pseudo/0.25-0001`: `/` and `.` separate path segments). Expressions also find it by its name.
|
||||
fn param_id(p: &EffectParam<'_, '_>) -> String {
|
||||
if !p.match_name.is_empty() && p.match_name.chars().all(plain) { p.match_name.clone() } else { format!("param{}", p.index) }
|
||||
}
|
||||
|
||||
/// Whether `c` can stand in one segment of a property path (`/`, `.`, `#` and `@` mean more).
|
||||
fn plain(c: char) -> bool {
|
||||
c.is_alphanumeric() || matches!(c, ' ' | '-' | '_')
|
||||
}
|
||||
|
||||
/// `name` as one segment of a property path: other characters become `_` (`Pseudo/0.25` is
|
||||
/// `Pseudo_0_25`).
|
||||
fn segment(name: &str) -> String {
|
||||
name.chars().map(|c| if plain(c) { c } else { '_' }).collect()
|
||||
}
|
||||
|
||||
/// Sets `prop` from `p`: its expression, then its keys or its value (the record, else the `pard`
|
||||
/// default). `names` is `(here, label)` for the report.
|
||||
fn fill(p: &EffectParam<'_, '_>, prop: &mut Property, kind: Kind, cx: &LayerCtx<'_>, names: (&str, &str), col: &mut Collector) {
|
||||
let (here, label) = names;
|
||||
if let Some(stored) = p.stored() {
|
||||
import_expression(&stored, prop, col);
|
||||
}
|
||||
if p.is_animated() {
|
||||
let Some(stored) = p.stored() else { return };
|
||||
if kind == Kind::EffectBool {
|
||||
// Keys on a checkbox are not sampled by the corpus.
|
||||
col.lose(LossCategory::Effects, format!("{here}: the keyframes of parameter {label} are not kept (not decoded)"));
|
||||
return;
|
||||
}
|
||||
let before = prop.keys.len();
|
||||
import_keys(&stored, kind, cx.layer, &p.match_name, cx.tm, prop, col);
|
||||
if prop.keys.len() == before {
|
||||
col.lose(LossCategory::DamagedData, format!("{here}: parameter {label} has no readable keyframe"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
let value = match (p.stored(), p.recorded_value()) {
|
||||
(Some(_), Some(v)) => v,
|
||||
(Some(_), None) => {
|
||||
col.lose(LossCategory::DamagedData, format!("{here}: parameter {label} holds an unreadable value"));
|
||||
return;
|
||||
}
|
||||
// A borrowed popup's default slot holds another copy's selection (docs/aep-format.md 3.7).
|
||||
(None, _) if p.kind == ParamKind::Popup && p.borrowed_definition => {
|
||||
col.lose(LossCategory::Effects, format!("{here}: parameter {label}: the default item is not known (shared definition), the first item used"));
|
||||
return;
|
||||
}
|
||||
// A popup's default slot can hold 0, no item (After Effects' save of a project it opened).
|
||||
(None, _) => match p.pard_default() {
|
||||
Some(ParamValue::Index(0)) => {
|
||||
col.lose(LossCategory::Effects, format!("{here}: parameter {label}: the default item is not stored, the first item used"));
|
||||
return;
|
||||
}
|
||||
Some(v) => v,
|
||||
None => return,
|
||||
},
|
||||
};
|
||||
match (convert(value, kind), value) {
|
||||
(Some(v), _) => prop.value = v,
|
||||
// An item of the file that is past the ones kept (reported with the cut): the first item.
|
||||
(None, ParamValue::Index(i)) if usize::try_from(i).is_ok_and(|i| i > MAX_POPUP_ITEMS && popup_len(p).is_some_and(|n| i <= n)) => {
|
||||
col.lose(LossCategory::Effects, format!("{here}: parameter {label}: item {i} is past the items kept, the first item used"));
|
||||
}
|
||||
(None, _) => col.lose(LossCategory::DamagedData, format!("{here}: parameter {label} holds a value that is not valid ({value:?})")),
|
||||
}
|
||||
}
|
||||
@@ -136,8 +136,12 @@ const IGNORED: [&str; 4] = ["ADBE Position_0", "ADBE Position_1", "ADBE Position
|
||||
/// How the stored Anchor Point becomes pixels.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum AnchorUnit {
|
||||
/// A fraction of a source this big (pixels): AV layers.
|
||||
/// A fraction of a source this big (pixels): AV layers; the source's centre when absent.
|
||||
Source(u32, u32),
|
||||
/// A fraction of a null object's source this big (pixels); its top-left corner when absent:
|
||||
/// After Effects 2026 reads a null's absent Anchor Point as `[0, 0]` (#3099: two nulls made
|
||||
/// with `addNull`, one left at its default, read back `[0, 0, 0]` and `[10, 20, 0]`).
|
||||
Null(u32, u32),
|
||||
/// Pixels as stored, the origin when absent: text (385) and shape (462) layers, which have no
|
||||
/// source.
|
||||
Pixels,
|
||||
@@ -169,6 +173,14 @@ pub(crate) fn import_transform(
|
||||
let (sw, sh) = (f64::from(w), f64::from(h));
|
||||
(Kind::Anchor(sw, sh), tr.anchor_px(sw, sh))
|
||||
}
|
||||
AnchorUnit::Null(w, h) => {
|
||||
let (sw, sh) = (f64::from(w), f64::from(h));
|
||||
let px = match tr.anchor_fraction.source {
|
||||
ValueSource::Default | ValueSource::Unreadable => [0.0; 3],
|
||||
ValueSource::Stored | ValueSource::Keyframed => tr.anchor_px(sw, sh),
|
||||
};
|
||||
(Kind::Anchor(sw, sh), px)
|
||||
}
|
||||
AnchorUnit::Pixels | AnchorUnit::PointOfInterest => (Kind::Anchor(1.0, 1.0), tr.text_anchor_px()),
|
||||
};
|
||||
let poi = anchor == AnchorUnit::PointOfInterest;
|
||||
@@ -219,15 +231,21 @@ pub(crate) fn import_transform(
|
||||
}
|
||||
import_expression(&node, prop, col);
|
||||
}
|
||||
if let Some(PropNode::Other(_)) = group.get("ADBE Orientation") {
|
||||
if let Some(PropNode::Other(otst)) = group.get("ADBE Orientation") {
|
||||
match (layer.orientation(), target.get_mut("orientation")) {
|
||||
(Some(o), Some(prop)) if !o.animated && !o.has_expression && sane(&Value::Vec3(o.degrees)) => prop.value = Value::Vec3(o.degrees),
|
||||
(Some(o), Some(prop)) if o.animated || sane(&Value::Vec3(o.degrees)) => {
|
||||
if o.animated {
|
||||
import_orientation_keys(layer, layer_name, tm, prop, col);
|
||||
} else {
|
||||
prop.value = Value::Vec3(o.degrees);
|
||||
}
|
||||
// The expression is stored in the `otst`'s `tdbs` as on any property (#3087).
|
||||
if let Some(node) = otst.child_list(b"tdbs").and_then(AepProp::from_chunk) {
|
||||
import_expression(&node, prop, col);
|
||||
}
|
||||
}
|
||||
// A layer without an orientation (an ambient light) loses nothing with the default.
|
||||
(Some(o), None) if !o.animated && !o.has_expression && o.degrees == [0.0; 3] => {}
|
||||
(Some(o), Some(prop)) if o.animated && !o.has_expression => import_orientation_keys(layer, layer_name, tm, prop, col),
|
||||
(Some(o), Some(_)) if o.has_expression => {
|
||||
col.lose(LossCategory::TransformProperties, format!("{layer_name}: ADBE Orientation expression (not decoded)"));
|
||||
}
|
||||
_ => col.lose(LossCategory::TransformProperties, format!("{layer_name}: ADBE Orientation")),
|
||||
}
|
||||
}
|
||||
|
||||
+218
-14
@@ -8,6 +8,7 @@ use std::collections::BTreeMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::container::AepFile;
|
||||
use crate::container::index::Root;
|
||||
|
||||
/// Most example lines kept per loss category (the count is always exact).
|
||||
pub const MAX_DETAILS: usize = 20;
|
||||
@@ -56,7 +57,8 @@ pub enum LossCategory {
|
||||
/// Layers that could not be imported for another reason (unknown layer type, missing or
|
||||
/// unsupported source, precomposition loop).
|
||||
UnsupportedLayers,
|
||||
/// Project items of a kind that is not imported.
|
||||
/// Project items of a kind that is not imported, and items made from a Photoshop layer
|
||||
/// without pixels (they show the merged image).
|
||||
UnsupportedItems,
|
||||
/// Data that could not be read (damaged headers, unreadable keyframes).
|
||||
DamagedData,
|
||||
@@ -92,14 +94,47 @@ impl LossCategory {
|
||||
}
|
||||
}
|
||||
|
||||
/// One category of things that were not imported.
|
||||
/// One category of things that were not imported. The export report uses the same type with its
|
||||
/// own categories (`export::Loss`).
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Loss {
|
||||
pub category: LossCategory,
|
||||
pub struct Loss<C = LossCategory> {
|
||||
pub category: C,
|
||||
/// How many occurrences (exact).
|
||||
pub count: usize,
|
||||
/// Up to [`MAX_DETAILS`] example lines.
|
||||
/// Example lines: up to [`MAX_DETAILS`], and for effects with no counterpart one more line per
|
||||
/// effect (with its number of instances).
|
||||
pub details: Vec<String>,
|
||||
/// How many of the `count` occurrences no line of `details` describes.
|
||||
#[serde(default)]
|
||||
pub unlisted: usize,
|
||||
}
|
||||
|
||||
/// The loss bookkeeping the import and the export report share.
|
||||
impl<C: Copy + Ord> Loss<C> {
|
||||
/// Counts one loss of `category`; `detail` is only called while the category holds fewer than
|
||||
/// [`MAX_DETAILS`] lines.
|
||||
pub(crate) fn record(losses: &mut BTreeMap<C, Self>, category: C, detail: impl FnOnce() -> String) {
|
||||
let loss = losses.entry(category).or_insert_with(|| Loss { category, count: 0, details: Vec::new(), unlisted: 0 });
|
||||
loss.count = loss.count.saturating_add(1);
|
||||
if loss.details.len() < MAX_DETAILS {
|
||||
loss.details.push(detail());
|
||||
}
|
||||
}
|
||||
|
||||
/// The sum of all loss counts.
|
||||
pub(crate) fn total(losses: &[Self]) -> usize {
|
||||
losses.iter().map(|l| l.count).sum()
|
||||
}
|
||||
|
||||
/// The loss count of a category.
|
||||
pub(crate) fn count_of(losses: &[Self], category: C) -> usize {
|
||||
losses.iter().find(|l| l.category == category).map_or(0, |l| l.count)
|
||||
}
|
||||
|
||||
/// `effects: 3, masks: 1` (empty without losses).
|
||||
pub(crate) fn summary(losses: &[Self], label: impl Fn(C) -> &'static str) -> String {
|
||||
losses.iter().map(|l| format!("{}: {}", label(l.category), l.count)).collect::<Vec<_>>().join(", ")
|
||||
}
|
||||
}
|
||||
|
||||
/// What arrived in the project.
|
||||
@@ -156,6 +191,10 @@ pub struct Imported {
|
||||
/// in [`LossCategory::Effects`]).
|
||||
#[serde(default)]
|
||||
pub effects: usize,
|
||||
/// Effects with no counterpart, kept as placeholders that render nothing (their parameters,
|
||||
/// for expressions; each is also in [`LossCategory::Effects`]).
|
||||
#[serde(default)]
|
||||
pub placeholder_effects: usize,
|
||||
/// Layer styles (Drop Shadow, Stroke, ...), one per style on a layer.
|
||||
#[serde(default)]
|
||||
pub layer_styles: usize,
|
||||
@@ -218,6 +257,11 @@ pub const UNKNOWN: &str = "unknown";
|
||||
impl AeVersionInfo {
|
||||
/// Reads the versions of a parsed file.
|
||||
pub fn of(file: &AepFile<'_>) -> Self {
|
||||
Self::of_root(Root::from(file))
|
||||
}
|
||||
|
||||
/// Reads the versions from the top-level chunks of either tree.
|
||||
pub(crate) fn of_root(file: Root<'_, '_>) -> Self {
|
||||
let file_version = file.file_version();
|
||||
Self {
|
||||
file_version: file_version.map_or_else(|| UNKNOWN.to_string(), |v| v.text()),
|
||||
@@ -243,7 +287,7 @@ impl AeVersionInfo {
|
||||
impl ImportReport {
|
||||
/// The sum of all loss counts.
|
||||
pub fn total_losses(&self) -> usize {
|
||||
self.losses.iter().map(|l| l.count).sum()
|
||||
Loss::total(&self.losses)
|
||||
}
|
||||
|
||||
/// True when nothing was lost.
|
||||
@@ -253,12 +297,12 @@ impl ImportReport {
|
||||
|
||||
/// The loss count of a category.
|
||||
pub fn count(&self, category: LossCategory) -> usize {
|
||||
self.losses.iter().find(|l| l.category == category).map_or(0, |l| l.count)
|
||||
Loss::count_of(&self.losses, category)
|
||||
}
|
||||
|
||||
/// `effects: 3, masks: 1` (empty when lossless).
|
||||
pub fn summary(&self) -> String {
|
||||
self.losses.iter().map(|l| format!("{}: {}", l.category.label(), l.count)).collect::<Vec<_>>().join(", ")
|
||||
Loss::summary(&self.losses, LossCategory::label)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,19 +313,63 @@ pub(crate) struct Collector {
|
||||
losses: BTreeMap<LossCategory, Loss>,
|
||||
pub missing_footage: Vec<String>,
|
||||
pub missing_fonts: Vec<String>,
|
||||
/// The effects with no counterpart, by match name: the first instance's report line and how
|
||||
/// many instances there were. They get a line each in [`Collector::finish`], so one that
|
||||
/// comes after the example lines are used up is still named (#3365).
|
||||
unmapped_effects: BTreeMap<String, (String, usize)>,
|
||||
/// The properties and popup items the placeholders of this import hold so far (at most
|
||||
/// `placeholder::MAX_COST`).
|
||||
pub placeholder_cost: usize,
|
||||
}
|
||||
|
||||
/// How many different unmapped effects get a line of their own (a file names at most this many).
|
||||
const MAX_UNMAPPED_EFFECTS: usize = 100;
|
||||
|
||||
impl Collector {
|
||||
/// Records one loss.
|
||||
pub fn lose(&mut self, category: LossCategory, detail: impl Into<String>) {
|
||||
let loss = self.losses.entry(category).or_insert_with(|| Loss { category, count: 0, details: Vec::new() });
|
||||
loss.count = loss.count.saturating_add(1);
|
||||
if loss.details.len() < MAX_DETAILS {
|
||||
loss.details.push(detail.into());
|
||||
}
|
||||
self.lose_with(category, move || detail.into());
|
||||
}
|
||||
|
||||
pub fn finish(self) -> ImportReport {
|
||||
/// Records one loss whose detail line is built only while the category holds fewer than
|
||||
/// [`MAX_DETAILS`] lines (for a detail that needs `format!`).
|
||||
pub fn lose_with(&mut self, category: LossCategory, detail: impl FnOnce() -> String) {
|
||||
Loss::record(&mut self.losses, category, detail);
|
||||
}
|
||||
|
||||
/// Records one instance of an effect with no counterpart. The loss is counted now; its line is
|
||||
/// made in [`Collector::finish`], one per effect with the number of instances, so that many
|
||||
/// other losses cannot hide which effects were dropped.
|
||||
pub fn lose_unmapped_effect(&mut self, match_name: &str, detail: String) {
|
||||
let loss =
|
||||
self.losses.entry(LossCategory::Effects).or_insert_with(|| Loss { category: LossCategory::Effects, count: 0, details: Vec::new(), unlisted: 0 });
|
||||
loss.count = loss.count.saturating_add(1);
|
||||
if let Some(seen) = self.unmapped_effects.get_mut(match_name) {
|
||||
seen.1 = seen.1.saturating_add(1);
|
||||
} else if self.unmapped_effects.len() < MAX_UNMAPPED_EFFECTS {
|
||||
self.unmapped_effects.insert(match_name.to_string(), (detail, 1));
|
||||
}
|
||||
// (Past the limit an effect is only counted: its name is not worth a line of its own.)
|
||||
}
|
||||
|
||||
pub fn finish(mut self) -> ImportReport {
|
||||
// Every line describes one occurrence, except an unmapped effect's, which describes all
|
||||
// its instances.
|
||||
for loss in self.losses.values_mut() {
|
||||
loss.unlisted = loss.count.saturating_sub(loss.details.len());
|
||||
}
|
||||
if let Some(loss) = self.losses.get_mut(&LossCategory::Effects) {
|
||||
// The most used effects first.
|
||||
let mut named: Vec<(String, usize)> = std::mem::take(&mut self.unmapped_effects).into_values().collect();
|
||||
named.sort_by_key(|n| std::cmp::Reverse(n.1));
|
||||
let described = named.iter().fold(0usize, |sum, (_, n)| sum.saturating_add(*n));
|
||||
loss.unlisted = loss.unlisted.saturating_sub(described);
|
||||
let lines = named.into_iter().map(|(first, n)| match n {
|
||||
1 => first,
|
||||
_ => format!("{first}, and {} more like it", n - 1),
|
||||
});
|
||||
loss.details.splice(0..0, lines);
|
||||
}
|
||||
ImportReport {
|
||||
imported: self.imported,
|
||||
losses: self.losses.into_values().collect(),
|
||||
@@ -301,3 +389,119 @@ pub const LIMITATIONS: &[&str] = &[
|
||||
"Text: per-character 3D, text on a path and several style slots of unknown meaning are not decoded (stored values that differ from the default are reported as text layer features).",
|
||||
"Footage that is not a solid is linked by its stored path with its stored frame rate and duration; the importer never opens the files (use Reload Footage after the files are found).",
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A report with losses in two categories and a missing file, as the collector finishes it.
|
||||
fn collected() -> ImportReport {
|
||||
let mut col = Collector::default();
|
||||
col.imported.layers = 2;
|
||||
col.missing_footage.push("a.png".into());
|
||||
col.lose(LossCategory::Masks, "mask 1");
|
||||
col.lose(LossCategory::Effects, String::from("fx 1"));
|
||||
col.lose_with(LossCategory::Effects, || "fx 2".to_string());
|
||||
let mut report = col.finish();
|
||||
report.limitations.truncate(1);
|
||||
report
|
||||
}
|
||||
|
||||
/// The JSON shape agents read: field names, category spelling, order and the loss entries.
|
||||
#[test]
|
||||
fn the_json_shape_is_pinned() {
|
||||
let json = serde_json::to_string(&collected()).unwrap();
|
||||
assert_eq!(
|
||||
json,
|
||||
r#"{"imported":{"folders":0,"compositions":0,"solids":0,"footage":0,"layers":2,"solidLayers":0,"nullLayers":0,"adjustmentLayers":0,"footageLayers":0,"precompLayers":0,"textLayers":0,"keyframes":0,"expressions":0,"masks":0,"trackMattes":0,"markers":0,"timeRemaps":0,"shapeLayers":0,"shapeItems":0,"cameras":0,"lights":0,"textAnimators":0,"effects":0,"placeholderEffects":0,"layerStyles":0},"losses":[{"category":"effects","count":2,"details":["fx 1","fx 2"],"unlisted":0},{"category":"masks","count":1,"details":["mask 1"],"unlisted":0}],"missingFootage":["a.png"],"missingFonts":[],"limitations":["Frame blending, 3D material options, audio levels, guides are not decoded and not imported."],"aeVersion":{"fileVersion":"unknown","savedBy":"unknown","tested":false}}"#
|
||||
);
|
||||
let back: ImportReport = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(back, collected());
|
||||
}
|
||||
|
||||
/// The queries read the losses.
|
||||
#[test]
|
||||
fn the_queries_read_the_losses() {
|
||||
let report = collected();
|
||||
assert_eq!((report.total_losses(), report.is_lossless()), (3, false));
|
||||
assert_eq!((report.count(LossCategory::Effects), report.count(LossCategory::Lights)), (2, 0));
|
||||
assert_eq!(report.summary(), "effects: 2, masks: 1");
|
||||
let empty = Collector::default().finish();
|
||||
assert_eq!((empty.total_losses(), empty.is_lossless(), empty.summary()), (0, true, String::new()));
|
||||
}
|
||||
|
||||
/// The count stays exact past the detail cap, and a detail past the cap is never built.
|
||||
#[test]
|
||||
fn details_stop_at_the_cap_and_later_ones_are_not_built() {
|
||||
let mut col = Collector::default();
|
||||
let mut built = 0;
|
||||
for i in 0..MAX_DETAILS + 5 {
|
||||
col.lose_with(LossCategory::Masks, || {
|
||||
built += 1;
|
||||
format!("mask {i}")
|
||||
});
|
||||
}
|
||||
let report = col.finish();
|
||||
assert_eq!(report.count(LossCategory::Masks), MAX_DETAILS + 5);
|
||||
assert_eq!(report.losses[0].details.len(), MAX_DETAILS);
|
||||
assert_eq!(report.losses[0].details.last().map(String::as_str), Some("mask 19"));
|
||||
assert_eq!(built, MAX_DETAILS);
|
||||
}
|
||||
|
||||
/// #3365: with other losses filling the 20 example lines, an effect with no counterpart still
|
||||
/// gets its own line, with how many instances were lost. The category's count is unchanged.
|
||||
#[test]
|
||||
fn every_unmapped_effect_is_named_however_many_other_losses_there_are() {
|
||||
let mut col = Collector::default();
|
||||
for i in 0..30 {
|
||||
col.lose(LossCategory::Effects, format!("C: 'L{i}': parameter P not imported"));
|
||||
}
|
||||
for i in 0..25 {
|
||||
col.lose_unmapped_effect("CC Cylinder", format!("C: 'Cyl{i}' has the effect 'CC Cylinder' (CC Cylinder)"));
|
||||
}
|
||||
col.lose_unmapped_effect("Pseudo/", "C: 'D' has the effect 'Dropdown' (Pseudo/)".to_string());
|
||||
let report = col.finish();
|
||||
let effects = report.losses.iter().find(|l| l.category == LossCategory::Effects).unwrap();
|
||||
assert_eq!(effects.count, 56, "30 parameters, 25 cylinders and 1 dropdown");
|
||||
let named = |what: &str| effects.details.iter().filter(|d| d.contains(what)).collect::<Vec<_>>();
|
||||
assert_eq!(named("(CC Cylinder)").len(), 1, "{:?}", effects.details);
|
||||
assert!(named("(CC Cylinder)")[0].contains("24 more"), "{:?}", named("(CC Cylinder)"));
|
||||
// One instance stays the single line it was.
|
||||
assert_eq!(named("(Pseudo/)"), ["C: 'D' has the effect 'Dropdown' (Pseudo/)"]);
|
||||
assert!(effects.details.len() <= MAX_DETAILS + 2, "the examples stay bounded");
|
||||
// 20 parameter lines, the cylinders' line and the dropdown's describe 46; 10 parameters
|
||||
// have no line.
|
||||
assert_eq!(effects.unlisted, 10);
|
||||
// The most used effect comes first.
|
||||
assert!(effects.details[0].contains("(CC Cylinder)"), "{:?}", effects.details);
|
||||
}
|
||||
|
||||
/// #3365: each category says how many of its occurrences have no example line.
|
||||
#[test]
|
||||
fn a_loss_counts_the_occurrences_without_a_line() {
|
||||
let mut col = Collector::default();
|
||||
for i in 0..27 {
|
||||
col.lose(LossCategory::Masks, format!("mask {i}"));
|
||||
}
|
||||
col.lose(LossCategory::ShapeLayers, "one");
|
||||
let report = col.finish();
|
||||
let unlisted = |c| report.losses.iter().find(|l| l.category == c).map(|l| (l.details.len(), l.unlisted));
|
||||
assert_eq!(unlisted(LossCategory::Masks), Some((MAX_DETAILS, 7)));
|
||||
assert_eq!(unlisted(LossCategory::ShapeLayers), Some((1, 0)));
|
||||
}
|
||||
|
||||
/// A file with more than [`MAX_UNMAPPED_EFFECTS`] different unmapped effects names that many
|
||||
/// and counts the rest, whatever room the example lines have.
|
||||
#[test]
|
||||
fn at_most_the_limit_of_unmapped_effects_are_named() {
|
||||
let mut col = Collector::default();
|
||||
for i in 0..=MAX_UNMAPPED_EFFECTS {
|
||||
col.lose_unmapped_effect(&format!("Effect {i}"), format!("C: 'L' has the effect 'Effect {i}' (Effect {i})"));
|
||||
}
|
||||
let report = col.finish();
|
||||
let effects = report.losses.iter().find(|l| l.category == LossCategory::Effects).unwrap();
|
||||
assert_eq!(effects.count, MAX_UNMAPPED_EFFECTS + 1, "every instance is counted");
|
||||
assert_eq!(effects.details.len(), MAX_UNMAPPED_EFFECTS, "{} lines", effects.details.len());
|
||||
assert_eq!(effects.unlisted, 1, "the effect past the limit has no line");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Project settings (colour depth, working space, working gamma, linear-light switches, time
|
||||
//! display, frame count start) from [`crate::ProjectSettings`] (cases 620-634).
|
||||
|
||||
use crate::{AepFile, TimeDisplay, WorkingSpace};
|
||||
use crate::container::index::{Node, Root};
|
||||
use crate::{TimeDisplay, WorkingSpace};
|
||||
use effectcraft_color::ColorSpace;
|
||||
use effectcraft_project::{BitDepth, ProjectSettings, TimeDisplayStyle};
|
||||
|
||||
@@ -22,9 +23,9 @@ pub(crate) fn color_space(name: &str) -> Option<ColorSpace> {
|
||||
/// holds in an unknown form) keeps the current value. The two linear-light switches are always
|
||||
/// held: After Effects writes their chunk only when on (626, 627), so a file without it has them off. A working space EffectCraft does not have is
|
||||
/// reported.
|
||||
pub(crate) fn map(file: &AepFile<'_>, current: &ProjectSettings, col: &mut Collector) -> ProjectSettings {
|
||||
let s = crate::ProjectSettings::read(file);
|
||||
let nhed = file.chunk(b"nhed").and_then(|c| c.bytes());
|
||||
pub(crate) fn map(file: Root<'_, '_>, current: &ProjectSettings, col: &mut Collector) -> ProjectSettings {
|
||||
let s = crate::ProjectSettings::of(file);
|
||||
let nhed = file.chunk(b"nhed").and_then(Node::bytes);
|
||||
let mut out = current.clone();
|
||||
match s.bits_per_channel {
|
||||
Some(8) => out.bit_depth = BitDepth::Bpc8,
|
||||
|
||||
@@ -394,7 +394,7 @@ fn path(g: &AepGroup<'_, '_>, cx: &mut Cx<'_, '_>) -> Option<PropGroup> {
|
||||
return None;
|
||||
};
|
||||
let shapes: Vec<Option<AepPath>> =
|
||||
oms.child_list(b"omks").map(|k| k.children().iter().filter(|c| c.is_list(b"shap")).map(AepPath::from_chunk).collect()).unwrap_or_default();
|
||||
oms.child_list(b"omks").map(|k| k.children().filter(|c| c.is_list(b"shap")).map(AepPath::from_chunk).collect()).unwrap_or_default();
|
||||
let first = match shapes.first() {
|
||||
Some(Some(s)) => to_path(s, (1, 1)),
|
||||
Some(None) => Err("its path is unreadable"),
|
||||
@@ -457,18 +457,22 @@ fn shift_copy_offset(p: &mut effectcraft_project::Property, cx: &mut Cx<'_, '_>)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reports a property whose only sampled value is the default 1.
|
||||
/// Reports a property whose only sampled value is the default 1. A record in the default state
|
||||
/// holds After Effects' default (docs/aep-format.md 3.4, state), so it holds nothing to lose.
|
||||
fn not_default(g: &AepGroup<'_, '_>, match_name: &str, what: &str, cx: &mut Cx<'_, '_>) {
|
||||
if let Some(PropNode::Property(p)) = g.get(match_name)
|
||||
&& stored(&p)
|
||||
&& (p.is_animated() || p.expression().is_some() || p.static_value().and_then(|v| v.first().copied()).is_some_and(|v| v != 1.0))
|
||||
{
|
||||
cx.col.lose(LossCategory::ShapeLayers, format!("{}: {what} not imported", cx.what));
|
||||
}
|
||||
}
|
||||
|
||||
/// Reports a property whose only sampled value is 0.
|
||||
/// Reports a property whose only sampled value is 0 (a record in the default state, as above,
|
||||
/// holds nothing to lose).
|
||||
fn not_zero(g: &AepGroup<'_, '_>, match_name: &str, what: &str, cx: &mut Cx<'_, '_>) {
|
||||
if let Some(PropNode::Property(p)) = g.get(match_name)
|
||||
&& stored(&p)
|
||||
&& (p.is_animated() || p.expression().is_some() || p.static_value().and_then(|v| v.first().copied()).is_some_and(|v| v != 0.0))
|
||||
{
|
||||
cx.col.lose(LossCategory::ShapeLayers, format!("{}: {what} not imported", cx.what));
|
||||
@@ -490,3 +494,41 @@ fn unknown(g: &AepGroup<'_, '_>, known: &[&str], what: &str, cx: &mut Cx<'_, '_>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::Chunk;
|
||||
|
||||
/// A group holding `match_name` as a one-component property in state `tdsb` with value `v`.
|
||||
fn group_with(match_name: &str, tdsb: u32, v: f64) -> Chunk<'static> {
|
||||
let mut name = match_name.as_bytes().to_vec();
|
||||
name.resize(40, 0);
|
||||
let mut tdb4 = vec![0u8; 124];
|
||||
tdb4[3] = 1;
|
||||
let tdbs = Chunk::list(
|
||||
*b"tdbs",
|
||||
vec![Chunk::data(*b"tdsb", tdsb.to_be_bytes().to_vec()), Chunk::data(*b"tdb4", tdb4), Chunk::data(*b"cdat", v.to_be_bytes().to_vec())],
|
||||
);
|
||||
Chunk::list(*b"tdgp", vec![Chunk::data(*b"tdmn", name), tdbs])
|
||||
}
|
||||
|
||||
fn reported(match_name: &str, tdsb: u32, v: f64, check: fn(&AepGroup<'_, '_>, &str, &str, &mut Cx<'_, '_>)) -> usize {
|
||||
let chunk = group_with(match_name, tdsb, v);
|
||||
let g = AepGroup::from_chunk(&chunk).unwrap();
|
||||
let tm = TimeMap { timescale: 30, frame_duration: 1, rate: crate::import::time::frame_rate(30, 1).unwrap() };
|
||||
let (mut next, mut col) = (1, Collector::default());
|
||||
check(&g, match_name, "it", &mut Cx { what: "L", tm: &tm, ids: &mut Ids(&mut next), col: &mut col });
|
||||
col.finish().losses.iter().map(|l| l.count).sum()
|
||||
}
|
||||
|
||||
/// #3087: a guide rectangle's Shape Direction recorded in the default state (`tdsb` 3, holding
|
||||
/// 2) is After Effects' default and is no loss; written (`tdsb` 1) with 2, it is one.
|
||||
#[test]
|
||||
fn a_default_state_record_is_no_loss() {
|
||||
assert_eq!(reported("ADBE Vector Shape Direction", 3, 2.0, not_default), 0);
|
||||
assert_eq!(reported("ADBE Vector Shape Direction", 1, 2.0, not_default), 1);
|
||||
assert_eq!(reported("ADBE Vector Grad HiLite Length", 3, 5.0, not_zero), 0);
|
||||
assert_eq!(reported("ADBE Vector Grad HiLite Length", 1, 5.0, not_zero), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
use crate::{AutoKern, Caps, FontBaseline, Justification, Layer as AepLayer, ParagraphRun, PropGroup, PropNode, StyleRun as AepRun, TextDocument};
|
||||
use effectcraft_keyframe::text_doc::{BaselineOption, CharStyle, Composer, Direction, Justify, Kerning, ParaStyle, StyleRun, TextDoc};
|
||||
use effectcraft_project::Property;
|
||||
|
||||
use crate::import::props::import_expression;
|
||||
use crate::import::report::{Collector, LossCategory};
|
||||
|
||||
/// How deep the walk over the text property groups goes.
|
||||
@@ -344,15 +346,27 @@ fn has_stored(g: &PropGroup<'_, '_>, depth: usize) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// The Source Text expression into `target` (the layer's `text/sourceText`). The Source Text
|
||||
/// record keeps it like any other property: the text in its `Utf8`, the flags in its `tdb4`
|
||||
/// (`tests/fixtures/text-synthetic.aep`). An expression whose flags are unreadable, or a layer
|
||||
/// without a Source Text property, is reported.
|
||||
pub(crate) fn import_source_text_expression(layer: &AepLayer<'_, '_>, target: Option<&mut Property>, what: &str, col: &mut Collector) {
|
||||
let Some(st) = layer.source_text_property() else { return };
|
||||
if st.expression().is_none() {
|
||||
return;
|
||||
}
|
||||
match target {
|
||||
Some(p) if st.expression_enabled().is_some() => import_expression(&st, p, col),
|
||||
_ => col.lose(LossCategory::TextLayers, format!("{what}: the Source Text expression is not imported")),
|
||||
}
|
||||
}
|
||||
|
||||
/// The parts of a text layer besides its first text document that are not imported.
|
||||
pub(crate) fn report_text_extras(layer: &AepLayer<'_, '_>, what: &str, col: &mut Collector) {
|
||||
if let Some(st) = layer.source_text_property() {
|
||||
if st.is_animated() || layer.text_document_count() > 1 {
|
||||
col.lose(LossCategory::TextLayers, format!("{what}: Source Text keyframes are not imported (the first text document is)"));
|
||||
}
|
||||
if st.expression().is_some() {
|
||||
col.lose(LossCategory::TextLayers, format!("{what}: the Source Text expression is not imported"));
|
||||
}
|
||||
if let Some(st) = layer.source_text_property()
|
||||
&& (st.is_animated() || layer.text_document_count() > 1)
|
||||
{
|
||||
col.lose(LossCategory::TextLayers, format!("{what}: Source Text keyframes are not imported (the first text document is)"));
|
||||
}
|
||||
let Some(PropNode::Group(text)) = layer.properties().and_then(|p| p.get("ADBE Text Properties")) else { return };
|
||||
for e in text.entries() {
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
//!
|
||||
//! Not imported, and reported in [`LossCategory::TextLayers`]: wiggly and expression selectors,
|
||||
//! animator properties other than the ones mapped below (Character Value, Fill / Stroke
|
||||
//! Hue, Saturation, Brightness and Opacity, 3D rotations, variable font axes, ...), and a Tracking
|
||||
//! Type other than the default.
|
||||
//! Hue, Saturation and Brightness, Fill Opacity, 3D rotations, variable font axes, ...), and a
|
||||
//! Tracking Type other than the default.
|
||||
|
||||
use crate::{PropGroup as AepGroup, PropNode, Property as AepProp};
|
||||
use effectcraft_project::build::{self, Ids};
|
||||
@@ -37,6 +37,7 @@ const PROPS: &[(&str, &str, &str, Kind)] = &[
|
||||
("ADBE Text Opacity", "opacity", "opacity", Kind::Number),
|
||||
("ADBE Text Fill Color", "fillColor", "fillColor", Kind::EffectColor),
|
||||
("ADBE Text Stroke Color", "strokeColor", "strokeColor", Kind::EffectColor),
|
||||
("ADBE Text Stroke Opacity", "strokeOpacity", "strokeOpacity", Kind::Number),
|
||||
("ADBE Text Stroke Width", "strokeWidth", "strokeWidth", Kind::Number),
|
||||
("ADBE Text Tracking Amount", "tracking", "tracking", Kind::Number),
|
||||
("ADBE Text Line Spacing", "lineSpacing", "lineSpacing", Kind::Vec2),
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
use effectcraft_time::{FrameRate, TICKS_PER_SECOND, Tick};
|
||||
|
||||
use crate::container::TimeBase;
|
||||
|
||||
/// The composition's frame structure: the stored time base and the rate the project gets.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct TimeMap {
|
||||
@@ -27,12 +29,8 @@ pub(crate) fn frame_rate(timescale: u32, frame_duration: u32) -> Option<FrameRat
|
||||
}
|
||||
let exact = FrameRate::new(i64::from(timescale), i64::from(frame_duration));
|
||||
let fps = exact.as_f64();
|
||||
for ntsc in [FrameRate::FPS_23_976, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_119_88] {
|
||||
if (ntsc.as_f64() - fps).abs() < 0.0005 {
|
||||
return Some(ntsc);
|
||||
}
|
||||
}
|
||||
Some(exact)
|
||||
let ntsc = TimeBase::NTSC.into_iter().map(|(rate, _)| rate).find(|ntsc| (ntsc.as_f64() - fps).abs() < 0.0005);
|
||||
Some(ntsc.unwrap_or(exact))
|
||||
}
|
||||
|
||||
impl TimeMap {
|
||||
|
||||
@@ -20,8 +20,8 @@ pub use container::{
|
||||
GradientType, HueSaturationData, Interpolation, Item, ItemKind, Justification, KernRun, KeyEase, KeyLayout, KeyList, Keyframe, KeyframeKind, LIST, Layer,
|
||||
LayerHeader, LayerRef, LayerType, LevelsData, LightType, Limits, ListHeader, Marker, Mask, MaskAtom, MaskMode, MatteMode, MeshData, NESTED_IDS,
|
||||
Orientation, OrientationKey, ParagraphRun, ParamKind, ParamValue, PathVertex, PolystarType, Project, ProjectSettings, PropEntry, PropGroup, PropNode,
|
||||
Property, Quality, Rational, Renderer, SequenceInfo, ShapeDetail, ShapeGroup, ShapeItem, ShapePath, SpatialKey, Stroke, StrokeCap, StrokeJoin, StyleRun,
|
||||
TextBox, TextDocument, TextValue, TimeBase, TimeDisplay, TimeRemap, TimeRemapKey, TrackMatte, Tracked, Transform, ValueSource, Walk, WorkingSpace,
|
||||
curve_lut, effect_map, identifier_channel_type, is_aepx, parse, parse_any, parse_text_dict, parse_with_limits, read_aepx, read_aepx_with_limits, style_map,
|
||||
write, write_to,
|
||||
Property, PsdLayer, Quality, Rational, Renderer, SequenceInfo, ShapeDetail, ShapeGroup, ShapeItem, ShapePath, SpatialKey, Stroke, StrokeCap, StrokeJoin,
|
||||
StyleRun, TextBox, TextDocument, TextValue, TimeBase, TimeDisplay, TimeRemap, TimeRemapKey, TrackMatte, Tracked, Transform, ValueSource, Walk,
|
||||
WorkingSpace, curve_lut, effect_map, identifier_channel_type, is_aepx, parse, parse_any, parse_text_dict, parse_with_limits, read_aepx,
|
||||
read_aepx_with_limits, style_map, write, write_to,
|
||||
};
|
||||
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
asset: ai-mask-3099.aep
|
||||
title: Small After Effects test project: placed .ai files with masks under two parented Nulls (#3099)
|
||||
author: EffectCraft contributors
|
||||
source: original work (made in After Effects 2026 from own data: four hand-written one-page PDFs named .ai, generated by tools/ai-mask-3099.py, imported and laid out by tools/ai-mask-3099.jsx)
|
||||
license: MIT OR Apache-2.0
|
||||
added: 2026-11-08 by EffectCraft contributors
|
||||
notes: Scrubbed with tools/scrub.py (footage paths C:\fixture\x\<name>.ai of the same length, host name HOST000, the XMP packet of an empty project of the contributor); its four embedded colour profiles replaced by stubs (description only, no colour data) with crates/aep/examples/stubicc.rs, then checked with the corpus repository's tools/aep/inspect-embedded.py (CLEAN). No Adobe asset is in it.
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
asset: text-synthetic.aep
|
||||
title: Small After Effects test project for the .aep importer's text animator and Source Text expression tests
|
||||
author: EffectCraft contributors
|
||||
source: original work (made in After Effects 2026 by script from own data: a composition with two text layers, a text animator Stroke Opacity, static and keyed, and Source Text expressions, enabled and disabled)
|
||||
license: MIT OR Apache-2.0
|
||||
added: 2026-11-08 by EffectCraft contributors
|
||||
notes: The working space was set to None, so the file embeds no ICC profile; nothing After Effects wrote was changed. See crates/aep/README.md (Clean room).
|
||||
+1
@@ -29,6 +29,7 @@ single-case files some cases are merged from, and the contributor's own animatio
|
||||
| `scrub.py` | fixture hygiene of a saved `.aep`: footage alias paths replaced by neutral ones of the same length (`C:\fixtures\...`), host name `HOST000...`, neutral ascend counts, the XMP packet replaced by the base project's |
|
||||
| `layers-comps-scrub-aepx.py` | the same XMP swap for the `.aepx` of the pair |
|
||||
| `patch-text.py` | the byte edits of the text cases 732 and 733 (see below) |
|
||||
| `ai-mask-3099.py`, `ai-mask-3099.jsx` | the committed `../ai-mask-3099.aep` (#3099): the `.py` writes four one-page PDFs named `.ai` with distinct page boxes, the `.jsx` (ExtendScript, run once through an After Effects MCP server's script call in an empty untitled project) imports them, builds composition `ai-mask` and returns After Effects' read-back that `../../it/import/ai_mask.rs` compares against |
|
||||
|
||||
## Run order (per file)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// Issue 3099: how After Effects sizes a placed .ai (PDF) and where masks / parented layers land.
|
||||
// Generates ai-mask-3099.aep: run `python -I ai-mask-3099.py <work>` first, set `dir` to that
|
||||
// folder, then run this script (ExtendScript) in an empty, untitled project. It returns After
|
||||
// Effects' read-back (footage sizes, transforms, mask vertices, toComp points; the tests compare
|
||||
// against it) and saves <work>/i3099-ai-mask.aep, which is then scrubbed (README: steps 5 and 6).
|
||||
(function () {
|
||||
var dir = "<work>/";
|
||||
var out = {};
|
||||
if (app.project.file !== null || app.project.numItems !== 0) {
|
||||
return "ABORT: project not empty/untitled (" + app.project.numItems + " items)";
|
||||
}
|
||||
var target = new File(dir + "i3099-ai-mask.aep");
|
||||
if (target.exists) { return "ABORT: target exists"; }
|
||||
var names = ["i3099-a-boxes.ai", "i3099-b-frac.ai", "i3099-c-rot.ai", "i3099-d-trim.ai"];
|
||||
var items = {};
|
||||
out.footage = {};
|
||||
for (var i = 0; i < names.length; i++) {
|
||||
var io = new ImportOptions(new File(dir + names[i]));
|
||||
io.importAs = ImportAsType.FOOTAGE;
|
||||
var it = app.project.importFile(io);
|
||||
items[names[i]] = it;
|
||||
out.footage[names[i]] = { w: it.width, h: it.height, par: it.pixelAspect };
|
||||
}
|
||||
var comp = app.project.items.addComp("ai-mask", 1920, 1080, 1, 5, 25);
|
||||
var art = comp.layers.add(items["i3099-a-boxes.ai"]);
|
||||
art.name = "art";
|
||||
var artD = comp.layers.add(items["i3099-d-trim.ai"]);
|
||||
artD.name = "artD";
|
||||
artD.collapseTransformation = true;
|
||||
var artC = comp.layers.add(items["i3099-c-rot.ai"]);
|
||||
artC.name = "artC";
|
||||
artC.property("ADBE Transform Group").property("ADBE Position").setValue([1500, 800]);
|
||||
var n1 = comp.layers.addNull(); n1.name = "N1";
|
||||
var n2 = comp.layers.addNull(); n2.name = "N2";
|
||||
n2.setParentWithJump(n1);
|
||||
art.setParentWithJump(n2);
|
||||
artD.setParentWithJump(n2);
|
||||
var t = function (l, p, v) { l.property("ADBE Transform Group").property(p).setValue(v); };
|
||||
t(n1, "ADBE Position", [700, 400]);
|
||||
t(n1, "ADBE Rotate Z", 15);
|
||||
t(n1, "ADBE Scale", [80, 120]);
|
||||
t(n2, "ADBE Anchor Point", [10, 20]);
|
||||
t(n2, "ADBE Position", [50, -30]);
|
||||
t(n2, "ADBE Scale", [150, 150]);
|
||||
t(art, "ADBE Position", [0, 0]);
|
||||
t(artD, "ADBE Position", [300, 250]);
|
||||
// Two rectangular masks on each art layer, in layer pixels.
|
||||
var rect = function (l, nm, x0, y0, x1, y1) {
|
||||
var m = l.property("ADBE Mask Parade").addProperty("ADBE Mask Atom");
|
||||
m.name = nm;
|
||||
var s = new Shape();
|
||||
s.vertices = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]];
|
||||
s.closed = true;
|
||||
m.property("ADBE Mask Shape").setValue(s);
|
||||
};
|
||||
rect(art, "M1", 40, 30, 200, 90);
|
||||
rect(art, "M2", 220, 100, 350, 160);
|
||||
rect(artD, "M1", 40, 30, 200, 90);
|
||||
rect(artD, "M2", 220, 100, 350, 160);
|
||||
// World positions of layer points through the parent chain (toComp), read via a Point Control.
|
||||
var probe = n1.property("ADBE Effect Parade").addProperty("ADBE Point Control");
|
||||
var pt = probe.property(1);
|
||||
var toComp = function (ln, p) {
|
||||
pt.expression = "thisComp.layer('" + ln + "').toComp([" + p[0] + "," + p[1] + "])";
|
||||
var v = pt.valueAtTime(0, false);
|
||||
return [v[0], v[1]];
|
||||
};
|
||||
var rd = function (l) {
|
||||
var tg = l.property("ADBE Transform Group");
|
||||
var r = {
|
||||
w: l.width, h: l.height,
|
||||
anchor: tg.property("ADBE Anchor Point").value,
|
||||
position: tg.property("ADBE Position").value,
|
||||
scale: tg.property("ADBE Scale").value,
|
||||
rot: tg.property("ADBE Rotate Z").value,
|
||||
masks: []
|
||||
};
|
||||
var mp = l.property("ADBE Mask Parade");
|
||||
for (var k = 1; k <= mp.numProperties; k++) {
|
||||
r.masks.push(mp.property(k).property("ADBE Mask Shape").value.vertices);
|
||||
}
|
||||
return r;
|
||||
};
|
||||
out.layers = { art: rd(art), artD: rd(artD), artC: rd(artC), N1: rd(n1), N2: rd(n2) };
|
||||
out.world = {};
|
||||
var pts = { tl: [0, 0], tr: [art.width, 0], bl: [0, art.height], m1: [40, 30], m2: [350, 160] };
|
||||
for (var key in pts) { out.world["art_" + key] = toComp("art", pts[key]); }
|
||||
var ptsD = { tl: [0, 0], tr: [artD.width, 0], bl: [0, artD.height], m1: [40, 30] };
|
||||
for (var key2 in ptsD) { out.world["artD_" + key2] = toComp("artD", ptsD[key2]); }
|
||||
probe.remove();
|
||||
app.project.save(target);
|
||||
out.saved = target.fsName;
|
||||
return out;
|
||||
})();
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"""Writes hand-made one-page PDFs named .ai with distinct page boxes (issue 3099 repro)."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
out = sys.argv[1]
|
||||
os.makedirs(out, exist_ok=True)
|
||||
|
||||
|
||||
def pdf(page_extra, content):
|
||||
objs = [
|
||||
b"<< /Type /Catalog /Pages 2 0 R >>",
|
||||
b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
|
||||
b"<< /Type /Page /Parent 2 0 R " + page_extra.encode() + b" /Contents 4 0 R >>",
|
||||
b"<< /Length " + str(len(content)).encode() + b" >>\nstream\n" + content + b"\nendstream",
|
||||
]
|
||||
data = b"%PDF-1.4\n"
|
||||
offs = []
|
||||
for i, o in enumerate(objs, 1):
|
||||
offs.append(len(data))
|
||||
data += str(i).encode() + b" 0 obj\n" + o + b"\nendobj\n"
|
||||
x = len(data)
|
||||
data += b"xref\n0 " + str(len(objs) + 1).encode() + b"\n0000000000 65535 f \n"
|
||||
for o in offs:
|
||||
data += b"%010d 00000 n \n" % o
|
||||
data += b"trailer\n<< /Size " + str(len(objs) + 1).encode() + b" /Root 1 0 R >>\nstartxref\n" + str(x).encode() + b"\n%%EOF\n"
|
||||
return data
|
||||
|
||||
|
||||
def boxes_content(boxes):
|
||||
# One outline per box (different colours) plus a filled marker at the media box origin corner.
|
||||
cols = ["0 0 0", "1 0 0", "0 0.6 0", "0 0 1", "1 0.5 0"]
|
||||
s = b"0.85 0.85 0.85 rg "
|
||||
x0, y0, x1, y1 = boxes[0]
|
||||
s += b"%g %g %g %g re f\n" % (x0, y0, x1 - x0, y1 - y0)
|
||||
for c, (a, b, cc, d) in zip(cols, boxes):
|
||||
s += c.encode() + b" RG 1 w %g %g %g %g re S\n" % (a + 0.5, b + 0.5, cc - a - 1, d - b - 1)
|
||||
# A solid square in the lower-left of the last (innermost) box: shows y orientation.
|
||||
a, b, _, _ = boxes[-1]
|
||||
s += b"0.2 0.2 0.8 rg %g %g 20 10 re f" % (a + 4, b + 4)
|
||||
return s
|
||||
|
||||
|
||||
def arr(b):
|
||||
return "[%s]" % " ".join("%g" % v for v in b)
|
||||
|
||||
|
||||
# A: every box distinct, nested, non-square.
|
||||
media, crop, bleed, trim, art = [0, 0, 420, 220], [5, 5, 415, 215], [10, 10, 410, 210], [20, 20, 400, 200], [60, 50, 300.6, 170.4]
|
||||
a = pdf(
|
||||
f"/MediaBox {arr(media)} /CropBox {arr(crop)} /BleedBox {arr(bleed)} /TrimBox {arr(trim)} /ArtBox {arr(art)}",
|
||||
boxes_content([media, crop, bleed, trim, art]),
|
||||
)
|
||||
# B: only a fractional media box.
|
||||
mb = [0, 0, 300.6, 120.4]
|
||||
b = pdf(f"/MediaBox {arr(mb)}", boxes_content([mb]))
|
||||
# C: media box with an offset origin and /Rotate 90.
|
||||
mc = [100, 50, 400, 150]
|
||||
c = pdf(f"/MediaBox {arr(mc)} /Rotate 90", boxes_content([mc]))
|
||||
# D: media + trim + art, no crop box (bleed around the artboard).
|
||||
md, td, ad = [0, 0, 418, 218], [9, 9, 409, 209], [40, 30, 250, 150]
|
||||
d = pdf(f"/MediaBox {arr(md)} /TrimBox {arr(td)} /BleedBox {arr(md)} /ArtBox {arr(ad)}", boxes_content([md, td, ad]))
|
||||
|
||||
for name, data in [("i3099-a-boxes.ai", a), ("i3099-b-frac.ai", b), ("i3099-c-rot.ai", c), ("i3099-d-trim.ai", d)]:
|
||||
with open(os.path.join(out, name), "wb") as f:
|
||||
f.write(data)
|
||||
print(name, len(data))
|
||||
@@ -128,6 +128,13 @@ pub fn resolve(name: &str) -> Option<PathBuf> {
|
||||
locate(name).map(|s| s.path().clone())
|
||||
}
|
||||
|
||||
/// The ids of the compositions an item uses as precomposition layers, as the file stores them:
|
||||
/// the little-endian `u32` of each `idpi` chunk (the importer does not read them; the exporter
|
||||
/// writes them).
|
||||
pub fn used_item_ids(item: &effectcraft_aep::Item<'_, '_>) -> Vec<u32> {
|
||||
item.chunk().children().filter(|c| c.is(b"idpi")).filter_map(|c| Some(u32::from_le_bytes(c.bytes()?.get(..4)?.try_into().ok()?))).collect()
|
||||
}
|
||||
|
||||
/// The bytes of a case (see the module comment), or `None` when it is missing.
|
||||
pub fn try_fixture(name: &str) -> Option<Vec<u8>> {
|
||||
match locate(name)? {
|
||||
|
||||
@@ -25,5 +25,6 @@ mod shapes;
|
||||
mod text_fields;
|
||||
mod text_markers_footage;
|
||||
mod text_style_slots;
|
||||
mod tree_index;
|
||||
mod typed;
|
||||
mod values;
|
||||
|
||||
@@ -117,8 +117,8 @@ fn a_transform_set_to_its_default_adds_no_record() {
|
||||
assert_eq!(t.opacity_percent.source, ValueSource::Default);
|
||||
assert!(layer.properties().unwrap().find(&["ADBE Transform Group", "ADBE Position"]).is_none());
|
||||
// The two cases are layers of one file: they differ in the layer id only.
|
||||
let a = without_layer_id(layer.chunk());
|
||||
skip!(with_layer("299-save-noise.aep", L, |_, other| assert_eq!(a, without_layer_id(other.chunk()))));
|
||||
let a = without_layer_id(&layer.chunk().to_chunk());
|
||||
skip!(with_layer("299-save-noise.aep", L, |_, other| assert_eq!(a, without_layer_id(&other.chunk().to_chunk()))));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -140,16 +140,13 @@ fn scale_keys_keep_their_ease_type_major() {
|
||||
}
|
||||
assert_near(&keys[0].value().unwrap(), &[1.0, 1.0, 1.0], 1e-9);
|
||||
assert_near(&keys[1].value().unwrap(), &[2.0, 1.5, 1.0], 1e-9);
|
||||
// The raw block: [in speed x3][in influence x3][out speed x3][out influence x3].
|
||||
assert_near(&keys[0].plain_ease_slots().unwrap(), &[0.0, 0.0, 0.0, 0.33, 0.33, 0.33, 0.2, 0.2, 0.2, 0.66, 0.66, 0.66], 1e-9);
|
||||
assert_near(&keys[1].plain_ease_slots().unwrap(), &[0.1, 0.1, 0.1, 0.66, 0.66, 0.66, 0.0, 0.0, 0.0, 0.33, 0.33, 0.33], 1e-9);
|
||||
// The raw block is [in speed x3][in influence x3][out speed x3][out influence x3].
|
||||
for i in 0..3 {
|
||||
assert!(same_ease(&keys[0].ease_component(i).unwrap(), &ease(0.0, 0.33, 0.2, 0.66)), "key 1 component {i}");
|
||||
assert!(same_ease(&keys[1].ease_component(i).unwrap(), &ease(0.1, 0.66, 0.0, 0.33)), "key 2 component {i}");
|
||||
}
|
||||
assert!(keys[0].ease_component(3).is_none());
|
||||
assert_eq!(keys[0].ease_components().unwrap().len(), 3);
|
||||
assert!(keys[0].color_distance().is_none());
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -172,7 +169,6 @@ fn mask_feather_keys_keep_their_ease_type_major() {
|
||||
}
|
||||
assert_near(&keys[0].value().unwrap(), &[0.0, 0.0], 1e-9);
|
||||
assert_near(&keys[1].value().unwrap(), &[50.0, 30.0], 1e-9);
|
||||
assert_near(&keys[0].plain_ease_slots().unwrap(), &[0.0, 0.0, 0.33, 0.33, 15.0, 15.0, 0.66, 0.66], 1e-9);
|
||||
for i in 0..2 {
|
||||
assert!(same_ease(&keys[0].ease_component(i).unwrap(), &ease(0.0, 0.33, 15.0, 0.66)), "key 1 component {i}");
|
||||
assert!(same_ease(&keys[1].ease_component(i).unwrap(), &ease(8.0, 0.66, 0.0, 0.33)), "key 2 component {i}");
|
||||
@@ -213,14 +209,15 @@ fn bezier_colour_keys_carry_the_distance_to_the_next_key() {
|
||||
assert_eq!((k.interpolation_in(), k.interpolation_out()), (Some(Interpolation::Bezier), Some(Interpolation::Bezier)));
|
||||
assert!(same_ease(&k.ease_component(0).unwrap(), &ease(0.0, 0.0, 0.0, 0.0)));
|
||||
}
|
||||
assert!(near(keys[0].color_distance().unwrap(), 255.0 * 2f64.sqrt(), 1e-3), "{:?}", keys[0].color_distance());
|
||||
assert!(near(keys[0].color_distance().unwrap(), 360.6245, 1e-3));
|
||||
assert_eq!(keys[1].color_distance(), Some(0.0));
|
||||
let distance = |k: &effectcraft_aep::Keyframe<'_>| k.spatial().unwrap().segment_length;
|
||||
assert!(near(distance(&keys[0]), 255.0 * 2f64.sqrt(), 1e-3), "{}", distance(&keys[0]));
|
||||
assert!(near(distance(&keys[0]), 360.6245, 1e-3));
|
||||
assert_eq!(distance(&keys[1]), 0.0);
|
||||
}));
|
||||
skip!(with_layer("210-key-fill-color-2key-linear.aep", L, |_, layer| {
|
||||
let p = layer.effects()[0].params().into_iter().find(|p| p.name == "Color").unwrap();
|
||||
let k = p.stored().unwrap().keys().unwrap().keyframes().next().unwrap();
|
||||
assert_eq!(k.color_distance(), Some(0.0));
|
||||
assert_eq!(k.spatial().unwrap().segment_length, 0.0);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -243,21 +240,19 @@ fn time_stretch_is_an_exact_ratio() {
|
||||
let (h, in_p, out_p, scale) = skip!(stretch_facts("316-layer-stretch50.aep"));
|
||||
assert_eq!((h.stretch, h.stretch_den), (1, 2));
|
||||
assert_eq!(h.stretch_ratio(), Some(rat(1, 2)));
|
||||
assert_eq!(h.stretch_percent(), 50.0);
|
||||
assert_eq!(h.out_relative, rat(128000, 25600));
|
||||
assert_eq!((in_p, out_p, scale), (Some(rat(0, 1)), Some(rat(5, 2)), 25600));
|
||||
// 317: 150 %: 3/2, ends at 7.5 s, the property time scale is 25600 x 3/2.
|
||||
let (h, in_p, out_p, scale) = skip!(stretch_facts("317-layer-stretch150.aep"));
|
||||
assert_eq!((h.stretch, h.stretch_den), (3, 2));
|
||||
assert_eq!(h.stretch_ratio(), Some(rat(3, 2)));
|
||||
assert_eq!(h.stretch_percent(), 150.0);
|
||||
assert_eq!((in_p, out_p, scale), (Some(rat(0, 1)), Some(rat(15, 2)), 38400));
|
||||
// 018: 200 %: 2/1, ends at 10 s, time scale 51200. The base is 1/1.
|
||||
let (h, _, out_p, scale) = skip!(stretch_facts("018-layer-stretch200.aep"));
|
||||
assert_eq!((h.stretch, h.stretch_den, h.stretch_ratio()), (2, 1, Some(rat(2, 1))));
|
||||
assert_eq!((out_p, scale), (Some(rat(10, 1)), 51200));
|
||||
let (h, _, out_p, scale) = skip!(stretch_facts("000-base.aep"));
|
||||
assert_eq!((h.stretch, h.stretch_den, h.stretch_percent()), (1, 1, 100.0));
|
||||
assert_eq!((h.stretch, h.stretch_den, h.stretch_ratio()), (1, 1, Some(rat(1, 1))));
|
||||
assert_eq!((out_p, scale), (Some(rat(5, 1)), 25600));
|
||||
}
|
||||
|
||||
@@ -269,9 +264,9 @@ fn fractional_times_are_exact_multiples_of_one_over_25600() {
|
||||
assert_eq!(h.in_relative, rat(8532, 25600));
|
||||
assert_eq!(h.out_relative, rat(136532, 25600));
|
||||
assert_eq!(h.start, rat(0, 25600));
|
||||
// 0.33328125 s and 5.33328125 s.
|
||||
assert_eq!(h.in_point(), Some(rat(2133, 6400)));
|
||||
assert_eq!(h.in_point_seconds(), Some(0.33328125));
|
||||
assert_eq!(h.out_point_seconds(), Some(5.33328125));
|
||||
assert_eq!(h.out_point(), Some(rat(34133, 6400)));
|
||||
assert_eq!(h.stretch_ratio(), Some(rat(1, 1)));
|
||||
}
|
||||
|
||||
@@ -364,18 +359,17 @@ fn pixel_aspect_shutter_phase_and_display_start() {
|
||||
// 325: pixelAspect 0.9091 reads back 0.90909090909091 = the exact ratio 10/11.
|
||||
let h = skip!(comp_header("325-comp-pixelaspect-0.9091.aep"));
|
||||
assert_eq!(h.pixel_aspect.reduced(), Some(rat(10, 11)));
|
||||
assert!(near(h.pixel_aspect_ratio().unwrap(), 0.90909090909091, 1e-12));
|
||||
// 326: shutterPhase -90, the shutter angle stays 180.
|
||||
let h = skip!(comp_header("326-comp-shutterphase-m90.aep"));
|
||||
assert_eq!((h.shutter_phase, h.shutter_angle), (Some(-90), 180));
|
||||
// 327: displayStartFrame 100 at 25 fps = 4 s = 102400/25600; the shutter phase is back to 0.
|
||||
let h = skip!(comp_header("327-comp-displaystartframe-100.aep"));
|
||||
assert_eq!(h.display_start, Some(rat(102400, 25600)));
|
||||
assert_eq!((h.display_start_seconds(), h.display_start_frame(), h.shutter_phase), (Some(4.0), Some(100), Some(0)));
|
||||
assert_eq!(h.shutter_phase, Some(0));
|
||||
// The base: no phase, start 0.
|
||||
let h = skip!(comp_header("000-base.aep"));
|
||||
assert_eq!((h.shutter_phase, h.display_start_seconds(), h.display_start_frame()), (Some(0), Some(0.0), Some(0)));
|
||||
assert_eq!(h.pixel_aspect_ratio(), Some(1.0));
|
||||
assert_eq!((h.shutter_phase, h.display_start.and_then(|r| r.reduced())), (Some(0), Some(rat(0, 1))));
|
||||
assert_eq!(h.pixel_aspect.reduced(), Some(rat(1, 1)));
|
||||
// A short chunk still decodes the old fields.
|
||||
let bytes = [0u8; 176];
|
||||
let h = effectcraft_aep::CompHeader::parse(&bytes).unwrap();
|
||||
|
||||
@@ -148,19 +148,21 @@ fn a_mask_box_is_normalised_to_the_layer_size() {
|
||||
for (got, want) in m.shapes[0].bbox.iter().zip(want_box) {
|
||||
assert!(near(f64::from(*got), want, 1e-6), "{:?}", m.shapes[0].bbox);
|
||||
}
|
||||
let shapes = project.mask_vertices_px(&layer, m).unwrap();
|
||||
assert_eq!(shapes.len(), 1);
|
||||
let got: Vec<[f64; 2]> = shapes[0].iter().map(|v| v.position).collect();
|
||||
// The box scales by the size of the layer's source (the importer takes that size from the
|
||||
// source item it matched, the same item `layer_source_size` reads).
|
||||
let (w, h) = project.layer_source_size(&layer).unwrap();
|
||||
assert_eq!(m.shapes.len(), 1);
|
||||
let got: Vec<[f64; 2]> = m.shapes[0].vertices((f64::from(w), f64::from(h))).iter().map(|v| v.position).collect();
|
||||
for (g, w) in got.iter().zip([[20.0, 30.0], [80.0, 30.0], [80.0, 70.0], [20.0, 70.0]]) {
|
||||
assert_near(g, &w, 1e-3);
|
||||
}
|
||||
assert_eq!(got.len(), 4);
|
||||
// A layer without a sized source has no pixel vertices.
|
||||
// A layer without a sized source has no size to scale by.
|
||||
let bytes = fixture!("333-shape-group-two-rects.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let shape = layer_named(&first_comp(&project), "Shape");
|
||||
assert!(project.mask_vertices_px(&shape, m).is_none());
|
||||
assert!(project.layer_source_size(&shape).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -178,12 +180,14 @@ fn one_mkif_per_mask_and_the_mode_none() {
|
||||
assert_eq!((m.mode, m.inverted, m.counter), (Some(MaskMode::Add), Some(false), Some(counter)));
|
||||
assert_eq!(m.shapes.len(), 1);
|
||||
}
|
||||
let v1 = project.mask_vertices_px(&layer, &masks[0]).unwrap();
|
||||
let (w, h) = project.layer_source_size(&layer).unwrap();
|
||||
let px = |m: &effectcraft_aep::Mask| m.shapes.iter().map(|s| s.vertices((f64::from(w), f64::from(h)))).collect::<Vec<_>>();
|
||||
let v1 = px(&masks[0]);
|
||||
for (v, w) in v1[0].iter().zip(ellipse_vertices()) {
|
||||
assert_near(&v.position, &w, 1e-2);
|
||||
}
|
||||
// Mask 2 has its own box (500..900 x 350..650) normalised to the layer.
|
||||
let v2 = project.mask_vertices_px(&layer, &masks[1]).unwrap();
|
||||
let v2 = px(&masks[1]);
|
||||
for (v, w) in v2[0].iter().zip([[500.0, 350.0], [900.0, 350.0], [900.0, 650.0], [500.0, 650.0]]) {
|
||||
assert_near(&v.position, &w, 1e-2);
|
||||
}
|
||||
@@ -382,78 +386,16 @@ fn the_last_style_run_absorbs_the_final_carriage_return() {
|
||||
|
||||
// ------------------------------------------------------------------ camera and light (341-345)
|
||||
|
||||
/// Camera zoom keeps the auto position.
|
||||
#[test]
|
||||
fn camera_zoom_and_depth_of_field() {
|
||||
let camera = |name: &str| {
|
||||
Some({
|
||||
let bytes = crate::common::try_fixture(name)?;
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let layer = layer_of_type(&first_comp(&project), LayerType::Camera);
|
||||
(
|
||||
layer.camera_zoom(),
|
||||
layer.camera_depth_of_field(),
|
||||
layer.camera_focus_distance(),
|
||||
layer.camera_aperture(),
|
||||
layer.camera_position().map(|p| (p.stored, p.auto_state)),
|
||||
)
|
||||
})
|
||||
};
|
||||
// 341: Zoom 2000 is stored; the auto Position keeps [0, 0, -2666.67].
|
||||
let (zoom, dof, focus, aperture, pos) = skip!(camera("341-camera-zoom-2000.aep"));
|
||||
assert_eq!(zoom.map(|z| (z.value, z.source)), Some((2000.0, ValueSource::Stored)));
|
||||
assert_eq!((dof.map(|d| (d.value, d.source)), focus, aperture), (Some((false, ValueSource::Default)), None, None));
|
||||
let (stored, auto) = pos.unwrap();
|
||||
assert!(auto && near(stored[2], -2666.67, 0.01) && stored[0] == 0.0, "{stored:?}");
|
||||
// 342: DOF on, Focus Distance 800, Aperture 30; Zoom stays the default.
|
||||
let (zoom, dof, focus, aperture, _) = skip!(camera("342-camera-dof-800-30.aep"));
|
||||
assert_eq!(zoom.map(|z| (z.source, near(z.value, 2666.67, 0.01))), Some((ValueSource::Default, true)));
|
||||
assert_eq!(dof.map(|d| (d.value, d.source)), Some((true, ValueSource::Stored)));
|
||||
assert_eq!(focus.map(|f| (f.value, f.source)), Some((800.0, ValueSource::Stored)));
|
||||
assert_eq!(aperture.map(|f| (f.value, f.source)), Some((30.0, ValueSource::Stored)));
|
||||
// The default camera (256) has nothing but the default zoom.
|
||||
let (zoom, dof, ..) = skip!(camera("256-camera-two-node-default.aep"));
|
||||
assert_eq!((zoom.unwrap().source, dof.unwrap().value), (ValueSource::Default, false));
|
||||
assert_eq!(zoom.unwrap().value, effectcraft_aep::DEFAULT_CAMERA_ZOOM);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn light_colour_cone_angle_and_feather() {
|
||||
let light = |name: &str| {
|
||||
Some({
|
||||
let bytes = crate::common::try_fixture(name)?;
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let layer = layer_of_type(&first_comp(&project), LayerType::Light);
|
||||
assert_eq!(layer.header().unwrap().light_type(), Some(effectcraft_aep::LightType::Spot), "{name}");
|
||||
let t = |x: Option<effectcraft_aep::Tracked<f64>>| x.map(|x| (x.value, x.source));
|
||||
(layer.light_color().map(|c| (c.value, c.source)), t(layer.light_cone_angle()), t(layer.light_cone_feather()))
|
||||
})
|
||||
};
|
||||
// The default spot light: white, 90, 50, all absent.
|
||||
let (colour, angle, feather) = skip!(light("254-light-spot-intensity-50.aep"));
|
||||
assert_eq!((colour, angle, feather), (Some(([1.0; 4], ValueSource::Default)), Some((90.0, ValueSource::Default)), Some((50.0, ValueSource::Default))));
|
||||
// 343: colour [1,0,0,1] = ARGB doubles [255,255,0,0].
|
||||
let (colour, angle, feather) = skip!(light("343-light-spot-color-red.aep"));
|
||||
assert_eq!(colour, Some(([1.0, 1.0, 0.0, 0.0], ValueSource::Stored)));
|
||||
assert_eq!((angle, feather), (Some((90.0, ValueSource::Default)), Some((50.0, ValueSource::Default))));
|
||||
// 344: Cone Angle 60. 345: Cone Feather 30.
|
||||
let (colour, angle, feather) = skip!(light("344-light-spot-coneangle-60.aep"));
|
||||
assert_eq!((colour.unwrap().1, angle, feather), (ValueSource::Default, Some((60.0, ValueSource::Stored)), Some((50.0, ValueSource::Default))));
|
||||
let (_, angle, feather) = skip!(light("345-light-spot-conefeather-30.aep"));
|
||||
assert_eq!((angle, feather), (Some((90.0, ValueSource::Default)), Some((30.0, ValueSource::Stored))));
|
||||
// A point light (252) stores Cone Angle 90 / Feather 50 in their default state.
|
||||
let bytes = fixture!("252-light-point.aep");
|
||||
fn camera_zoom_keeps_the_auto_position() {
|
||||
// 341: Zoom 2000 is stored (checked on import); the auto Position keeps [0, 0, -2666.67].
|
||||
let bytes = fixture!("341-camera-zoom-2000.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let layer = layer_of_type(&first_comp(&project), LayerType::Light);
|
||||
assert_eq!(layer.light_cone_angle().map(|a| (a.value, a.source)), Some((90.0, ValueSource::Stored)));
|
||||
// Layers without light options have no light accessors.
|
||||
let bytes = fixture!("000-base.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let solid = base_layer(&first_comp(&project));
|
||||
assert!(solid.light_color().is_none() && solid.camera_zoom().is_none() && solid.camera_depth_of_field().is_none());
|
||||
let layer = layer_of_type(&first_comp(&project), LayerType::Camera);
|
||||
let pos = layer.camera_position().unwrap();
|
||||
assert!(pos.auto_state && near(pos.stored[2], -2666.67, 0.01) && pos.stored[0] == 0.0, "{:?}", pos.stored);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ marker data (347-349, 249)
|
||||
@@ -503,7 +445,7 @@ fn audio_footage_item() {
|
||||
assert_eq!((f.width, f.height, f.is_solid), (0, 0, false));
|
||||
assert_eq!(f.duration, Some(rat(48000, 48000)));
|
||||
assert_eq!((f.audio_sample_rate, f.file_size, f.bits_per_pixel, f.native_frame_rate), (Some(48000.0), 96044, 0, 0));
|
||||
assert!(!f.is_sequence && f.sequence_frame_count().is_none());
|
||||
assert!(!f.is_sequence && item.sequence_info().is_none());
|
||||
// The combined file stores no display name for the item (the single-case file had
|
||||
// "test-tone.wav"); the path names the file.
|
||||
assert_eq!(item.label(), Some(7));
|
||||
@@ -527,7 +469,7 @@ fn image_sequence_is_one_item() {
|
||||
assert_eq!(f.duration, Some(rat(3, 30)), "{name}");
|
||||
assert_eq!((f.native_frame_rate, f.bits_per_pixel, f.file_size, f.audio_sample_rate), (30, 24, 504, None), "{name}");
|
||||
assert!(f.is_sequence, "{name}");
|
||||
assert_eq!(f.sequence_frame_count(), Some(3), "{name}");
|
||||
assert_eq!(item.sequence_info().map(|s| s.frame_count()), Some(3), "{name}");
|
||||
// The first file name sits in opti; the alias points at the sequence folder.
|
||||
assert_eq!(f.name.as_deref(), Some("seq_001.png"), "{name}");
|
||||
assert!(f.path.as_deref().is_some_and(|p| p.ends_with("test-seq")), "{name}");
|
||||
|
||||
@@ -38,7 +38,7 @@ fn a_composition_counts_the_compositions_it_shows() {
|
||||
let id = |n: &str| items.iter().find(|i| i.display_name().as_deref() == Some(n)).and_then(|i| i.id()).expect(n);
|
||||
let c = items.iter().find(|i| i.display_name().as_deref() == Some("C")).expect("C");
|
||||
// The list holds each used composition once (in no particular order).
|
||||
let mut used = c.used_item_ids();
|
||||
let mut used = crate::common::used_item_ids(c);
|
||||
used.sort();
|
||||
let mut want = vec![id("P30"), id("Q")];
|
||||
want.sort();
|
||||
@@ -60,8 +60,8 @@ fn an_image_sequence_knows_its_numbering() {
|
||||
let item = project.all_items().into_iter().find(|i| i.footage().is_some_and(|f| !f.is_solid)).expect("sequence");
|
||||
let f = item.footage().expect("footage");
|
||||
assert_eq!((f.file_type.as_str(), f.width, f.height, f.native_frame_rate, f.is_sequence), ("oEXR", 64, 48, 30, true));
|
||||
assert_eq!(f.sequence_frame_count(), Some(3));
|
||||
let s = item.sequence_info().expect("numbering");
|
||||
assert_eq!(s.frame_count(), 3);
|
||||
assert_eq!((s.prefix.as_str(), s.suffix.as_str(), s.start, s.end, s.digits), ("shot_", ".exr", 101, 103, 4));
|
||||
assert_eq!(s.file_name(101), "shot_0101.exr");
|
||||
// A still has no numbering (000: the solid; the base has no other footage).
|
||||
|
||||
@@ -55,7 +55,6 @@ fn assert_plain(h: &LayerHeader) {
|
||||
assert_eq!(h.label, 1);
|
||||
// No name was set, so the copy of the name at byte 64 is empty (the layer shows its source name).
|
||||
assert_eq!(h.name_copy, "");
|
||||
assert!(!h.name_is_user_set());
|
||||
assert!(!h.is_null_object());
|
||||
assert_eq!(h.parent_id, None);
|
||||
assert_eq!(h.source_id, Some(0x1a));
|
||||
@@ -67,16 +66,13 @@ fn base_layer_header() {
|
||||
assert_plain(&h);
|
||||
assert_eq!(h.quality, Quality::Best);
|
||||
assert_eq!(h.blend_mode, BlendMode::Normal);
|
||||
assert_eq!(h.stretch, 1);
|
||||
assert_eq!(h.stretch_percent(), 100.0);
|
||||
assert_eq!((h.stretch, h.stretch_den), (1, 1));
|
||||
assert_eq!(switches(&h), NONE);
|
||||
// start 0 s, in 0 s, out 5 s; denominator = the composition timescale.
|
||||
assert_eq!(h.start, Rational { num: 0, den: 25600 });
|
||||
assert_eq!(h.in_relative, Rational { num: 0, den: 25600 });
|
||||
assert_eq!(h.out_relative, Rational { num: 128_000, den: 25600 });
|
||||
assert_eq!(h.start_seconds(), Some(0.0));
|
||||
assert_eq!(h.in_point_seconds(), Some(0.0));
|
||||
assert_eq!(h.out_point_seconds(), Some(5.0));
|
||||
assert_eq!(h.in_point(), Rational::new(0, 1));
|
||||
assert_eq!(h.out_point(), Rational::new(5, 1));
|
||||
}
|
||||
|
||||
@@ -98,7 +94,7 @@ fn one_switch_per_case() {
|
||||
assert_eq!(switches(&h), expected, "{name}");
|
||||
assert_plain(&h);
|
||||
assert_eq!((h.quality, h.blend_mode, h.stretch), (Quality::Best, BlendMode::Normal, 1), "{name}");
|
||||
assert_eq!(h.out_point_seconds(), Some(5.0), "{name}");
|
||||
assert_eq!(h.out_point(), Rational::new(5, 1), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +102,6 @@ fn one_switch_per_case() {
|
||||
fn name_blend_mode_and_quality() {
|
||||
let h = skip!(l_header("010-layer-name.aep"));
|
||||
assert_eq!(h.name_copy, "Renamed");
|
||||
assert!(h.name_is_user_set());
|
||||
let bytes = fixture!("010-layer-name.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
@@ -114,7 +109,6 @@ fn name_blend_mode_and_quality() {
|
||||
// The layer name is the user's; the source footage keeps its own name.
|
||||
assert_eq!(layer.name().as_deref(), Some("Renamed"));
|
||||
assert_eq!(project.layer_source(&layer).and_then(|i| i.display_name()).as_deref(), Some("L"));
|
||||
assert_eq!(project.layer_display_name(&layer).as_deref(), Some("Renamed"));
|
||||
|
||||
assert_eq!(skip!(l_header("016-layer-blend-multiply.aep")).blend_mode, BlendMode::Multiply);
|
||||
assert_eq!(skip!(l_header("023-layer-quality-draft.aep")).quality, Quality::Draft);
|
||||
@@ -127,7 +121,7 @@ fn display_name_falls_back_to_the_source_name() {
|
||||
let project = Project::new(&file).unwrap();
|
||||
let layer = base_layer(&first_comp(&project));
|
||||
assert_eq!(layer.name(), None);
|
||||
assert_eq!(project.layer_display_name(&layer).as_deref(), Some("L"));
|
||||
assert_eq!(project.layer_source(&layer).and_then(|i| i.display_name()).as_deref(), Some("L"));
|
||||
assert_eq!(project.layer_source_size(&layer), Some((1920, 1080)));
|
||||
let source = project.layer_source(&layer).unwrap();
|
||||
assert_eq!(source.id(), Some(0x1a));
|
||||
@@ -139,26 +133,23 @@ fn time_stretch_and_the_in_out_start_convention() {
|
||||
// 018: stretch 100 -> 200: the stored out point stays 5 s, the layer ends at 10 s.
|
||||
let h = skip!(l_header("018-layer-stretch200.aep"));
|
||||
assert_eq!(h.stretch, 2);
|
||||
assert_eq!(h.stretch_percent(), 200.0);
|
||||
assert_eq!(h.stretch_ratio(), Rational::new(2, 1));
|
||||
assert_eq!(h.out_relative, Rational { num: 128_000, den: 25600 });
|
||||
assert_eq!(h.out_point_seconds(), Some(10.0));
|
||||
assert_eq!(h.in_point_seconds(), Some(0.0));
|
||||
assert_eq!(h.out_point(), Rational::new(10, 1));
|
||||
assert_eq!(h.in_point(), Rational::new(0, 1));
|
||||
|
||||
// 019: inPoint 0 -> 1; AE moved the out point to 6 s and left the start at 0.
|
||||
let h = skip!(l_header("019-layer-inpoint1.aep"));
|
||||
assert_eq!(h.start_seconds(), Some(0.0));
|
||||
assert_eq!(h.start.num, 0);
|
||||
assert_eq!(h.in_relative, Rational { num: 25600, den: 25600 });
|
||||
assert_eq!(h.in_point(), Rational::new(1, 1));
|
||||
assert_eq!(h.out_point_seconds(), Some(6.0));
|
||||
assert_eq!(h.out_point(), Rational::new(6, 1));
|
||||
|
||||
// 021: startTime 0 -> 0.5: in 0.5 s and out 5.5 s although the stored in point stays 0.
|
||||
let h = skip!(l_header("021-layer-starttime0.5.aep"));
|
||||
assert_eq!(h.start, Rational { num: 12800, den: 25600 });
|
||||
assert_eq!(h.start_seconds(), Some(0.5));
|
||||
assert_eq!(h.in_relative.num, 0);
|
||||
assert_eq!(h.in_point(), Rational::new(1, 2));
|
||||
assert_eq!(h.in_point_seconds(), Some(0.5));
|
||||
assert_eq!(h.out_point_seconds(), Some(5.5));
|
||||
assert_eq!(h.out_point(), Rational::new(11, 2));
|
||||
}
|
||||
|
||||
@@ -175,7 +166,6 @@ fn parent_link_and_null_object() {
|
||||
let nh = null.header().unwrap();
|
||||
assert_eq!(null.name().as_deref(), Some("Null"));
|
||||
assert!(nh.is_null_object());
|
||||
assert!(nh.name_is_user_set());
|
||||
assert_eq!(nh.layer_type, LayerType::Av);
|
||||
assert_eq!(nh.parent_id, None);
|
||||
assert_eq!(project.layer_source(null).and_then(|i| i.display_name()).as_deref(), Some("Null 1"));
|
||||
@@ -225,17 +215,14 @@ fn base_comp_header() {
|
||||
assert_eq!((h.width, h.height), (1920, 1080));
|
||||
assert_eq!((h.time_base.frame_duration, h.time_base.timescale), (1024, 25600));
|
||||
assert_eq!(h.frame_rate(), Some(25.0));
|
||||
assert_eq!(h.frame_rate_from_fixed(), 25.0);
|
||||
assert_eq!(h.frame_rate_fixed, 25 << 16);
|
||||
assert_eq!(h.duration_units, 128_000);
|
||||
assert_eq!(h.duration_seconds(), Some(5.0));
|
||||
assert_eq!(h.background, [0, 0, 0]);
|
||||
assert_eq!(h.background_rgb(), [0.0, 0.0, 0.0]);
|
||||
assert_eq!(h.shutter_angle, 180);
|
||||
assert_eq!(h.work_area_start_seconds(), Some(0.0));
|
||||
assert_eq!(h.work_area_start_units, 0);
|
||||
assert_eq!(h.work_area_end_units, None);
|
||||
assert_eq!(h.work_area_end_seconds(), Some(5.0));
|
||||
assert_eq!(h.pixel_aspect, Rational { num: 1, den: 1 });
|
||||
assert_eq!(h.pixel_aspect_ratio(), Some(1.0));
|
||||
assert!(!h.motion_blur);
|
||||
// The manifest calls the classic renderer `ADBE Advanced 3d`; the file stores `ADBE Escher`
|
||||
// and the display name `Classic 3D`.
|
||||
@@ -255,7 +242,7 @@ fn one_comp_change_per_case() {
|
||||
let (h, _, _) = skip!(comp_header("031-comp-fps30.aep"));
|
||||
assert_eq!((h.time_base.frame_duration, h.time_base.timescale), (1024, 30720));
|
||||
assert_eq!(h.frame_rate(), Some(30.0));
|
||||
assert_eq!(h.frame_rate_from_fixed(), 30.0);
|
||||
assert_eq!(h.frame_rate_fixed, 30 << 16);
|
||||
assert_eq!(h.duration_units, 153_600);
|
||||
assert_eq!(h.duration_seconds(), Some(5.0));
|
||||
|
||||
@@ -263,12 +250,11 @@ fn one_comp_change_per_case() {
|
||||
let (h, _, _) = skip!(comp_header("032-comp-duration10.aep"));
|
||||
assert_eq!(h.duration_units, 256_000);
|
||||
assert_eq!(h.duration_seconds(), Some(10.0));
|
||||
assert_eq!(h.work_area_end_seconds(), Some(10.0));
|
||||
assert_eq!(h.work_area_end_units, None);
|
||||
|
||||
// 033: bgColor [0,0,0] -> [0,1,0].
|
||||
let (h, _, _) = skip!(comp_header("033-comp-bg-green.aep"));
|
||||
assert_eq!(h.background, [0, 255, 0]);
|
||||
assert_eq!(h.background_rgb(), [0.0, 1.0, 0.0]);
|
||||
|
||||
// 034: shutterAngle 180 -> 90.
|
||||
let (h, _, _) = skip!(comp_header("034-comp-shutter90.aep"));
|
||||
@@ -279,8 +265,6 @@ fn one_comp_change_per_case() {
|
||||
let (h, _, _) = skip!(comp_header("035-comp-workarea-1-2.aep"));
|
||||
assert_eq!(h.work_area_start_units, 25600);
|
||||
assert_eq!(h.work_area_end_units, Some(76_800));
|
||||
assert_eq!(h.work_area_start_seconds(), Some(1.0));
|
||||
assert_eq!(h.work_area_end_seconds(), Some(3.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -290,7 +274,6 @@ fn one_comp_change_per_case_aspect_blur_renderer() {
|
||||
// 037: pixelAspect 1 -> 2.
|
||||
let (h, _, _) = skip!(comp_header("037-comp-pixelaspect2.aep"));
|
||||
assert_eq!(h.pixel_aspect, Rational { num: 2, den: 1 });
|
||||
assert_eq!(h.pixel_aspect_ratio(), Some(2.0));
|
||||
|
||||
// 038: comp motion blur on.
|
||||
let (h, _, _) = skip!(comp_header("038-comp-motionblur.aep"));
|
||||
@@ -328,17 +311,16 @@ fn precomp_item_ids_and_labels() {
|
||||
assert_eq!(h.source_id, pre_item.id());
|
||||
assert_eq!(project.layer_source(layer).unwrap().id(), pre_item.id());
|
||||
assert_eq!(h.label, 15);
|
||||
assert!(!h.name_is_user_set());
|
||||
assert_eq!(layer.name(), None);
|
||||
assert_eq!(project.layer_display_name(layer).as_deref(), Some("Pre"));
|
||||
assert_eq!(project.layer_source(layer).and_then(|i| i.display_name()).as_deref(), Some("Pre"));
|
||||
assert_eq!(project.layer_source_size(layer), Some((1920, 1080)));
|
||||
// The precomp layer's start time has the denominator 1; the Pre comp is 1920x1080, 25 fps, 5 s.
|
||||
assert_eq!(h.start.den, 1);
|
||||
let ph = pre.header().unwrap();
|
||||
assert_eq!((ph.width, ph.height, ph.frame_rate(), ph.duration_seconds()), (1920, 1080, Some(25.0), Some(5.0)));
|
||||
// C records that it uses the comp Pre (chunk idpi, a little-endian u32).
|
||||
assert_eq!(c_item.used_item_ids(), [pre_item.id().unwrap()]);
|
||||
assert!(pre_item.used_item_ids().is_empty());
|
||||
assert_eq!(crate::common::used_item_ids(c_item), [pre_item.id().unwrap()]);
|
||||
assert!(crate::common::used_item_ids(pre_item).is_empty());
|
||||
assert_eq!(pre_item.label(), Some(15));
|
||||
// The layer inside Pre is a new layer made from the solid L (moving the layers into a precomp
|
||||
// creates new layers).
|
||||
@@ -347,7 +329,7 @@ fn precomp_item_ids_and_labels() {
|
||||
let ih = inner[0].header().unwrap();
|
||||
assert_ne!(ih.id, L);
|
||||
assert_eq!(ih.source_id, Some(0x1a));
|
||||
assert_eq!(project.layer_display_name(&inner[0]).as_deref(), Some("L"));
|
||||
assert_eq!(project.layer_source(&inner[0]).and_then(|i| i.display_name()).as_deref(), Some("L"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -356,9 +338,8 @@ fn a_negative_stretch_is_a_reversed_layer() {
|
||||
// point 0 and out point 5 s relative, so the layer runs from 5 s back to 0 s; 983: -50 % = -1/2.
|
||||
let h = skip!(l_header("981-layer-stretch-minus100-start5.aep"));
|
||||
assert_eq!((h.stretch, h.stretch_den), (-1, 1));
|
||||
assert_eq!(h.stretch_percent(), -100.0);
|
||||
assert_eq!((h.in_point_seconds(), h.out_point_seconds()), (Some(5.0), Some(0.0)));
|
||||
assert_eq!((h.in_point(), h.out_point()), (Rational::new(5, 1), Rational::new(0, 1)));
|
||||
let h = skip!(l_header("983-layer-stretch-minus50-opacity-keys.aep"));
|
||||
assert_eq!((h.stretch, h.stretch_den), (-1, 2));
|
||||
assert_eq!((h.in_point_seconds(), h.out_point_seconds()), (Some(5.0), Some(2.5)));
|
||||
assert_eq!((h.in_point(), h.out_point()), (Rational::new(5, 1), Rational::new(5, 2)));
|
||||
}
|
||||
|
||||
@@ -379,7 +379,8 @@ pub fn layer_named<'f, 'a>(comp: &Comp<'f, 'a>, name: &str) -> Layer<'f, 'a> {
|
||||
|
||||
/// The layer that shows this name: its own name, or its source's while it has none.
|
||||
pub fn layer_shown_as<'f, 'a>(project: &Project<'f, 'a>, comp: &Comp<'f, 'a>, name: &str) -> Layer<'f, 'a> {
|
||||
comp.layers().find(|l| project.layer_display_name(l).as_deref() == Some(name)).unwrap_or_else(|| panic!("no layer shown as {name}"))
|
||||
let shown = |l: &Layer<'f, 'a>| l.name().or_else(|| project.layer_source(l)?.display_name());
|
||||
comp.layers().find(|l| shown(l).as_deref() == Some(name)).unwrap_or_else(|| panic!("no layer shown as {name}"))
|
||||
}
|
||||
|
||||
/// The first layer of this type in a composition.
|
||||
|
||||
@@ -19,6 +19,9 @@ fn prop_of<R>(name: &str, path: &[&str], f: impl FnOnce(Property<'_, '_>) -> R)
|
||||
const POSITION: &[&str] = &["ADBE Transform Group", "ADBE Position"];
|
||||
const OPACITY: &[&str] = &["ADBE Transform Group", "ADBE Opacity"];
|
||||
|
||||
/// The ease of a linear key: all four slots 0.
|
||||
const NO_EASE: KeyEase = KeyEase { in_speed: 0.0, in_influence: 0.0, out_speed: 0.0, out_influence: 0.0 };
|
||||
|
||||
fn ease(in_speed: f64, in_influence: f64, out_speed: f64, out_influence: f64) -> KeyEase {
|
||||
KeyEase { in_speed, in_influence, out_speed, out_influence }
|
||||
}
|
||||
@@ -33,7 +36,7 @@ fn in_and_out_interpolation_are_separate_bytes() {
|
||||
assert_eq!((keys[0].interpolation_in(), keys[0].interpolation_out()), (Some(Interpolation::Linear), Some(Interpolation::Hold)));
|
||||
assert_eq!((keys[1].interpolation_in(), keys[1].interpolation_out()), (Some(Interpolation::Linear), Some(Interpolation::Linear)));
|
||||
assert_eq!(keys.iter().map(|k| k.seconds(25600).unwrap()).collect::<Vec<_>>(), [0.0, 1.0]);
|
||||
assert_eq!(keys[1].spatial_value(), Some([100.0, 0.0, 0.0]));
|
||||
assert_eq!(keys[1].value(), Some(vec![100.0, 0.0, 0.0]));
|
||||
}));
|
||||
// 203: key 1 inType HOLD, outType LINEAR (bytes 03 01): byte 4 is the incoming side.
|
||||
skip!(prop_of("203-key-in-hold-out-linear.aep", POSITION, |p| {
|
||||
@@ -76,7 +79,7 @@ fn opacity_ease_speed_is_in_stored_units_per_second() {
|
||||
assert_near(&[e0.in_speed, e0.in_influence, e0.out_speed, e0.out_influence], &[0.05, 0.2, 0.2, 0.8], 1e-12);
|
||||
let e1 = keys[1].ease().unwrap();
|
||||
assert_near(&[e1.in_speed, e1.in_influence, e1.out_speed, e1.out_influence], &[0.3, 0.6, 0.09, 0.4], 1e-12);
|
||||
assert_eq!(keys[0].plain_ease_slots().unwrap().len(), 4);
|
||||
assert_eq!(keys[0].ease_components(), Some(vec![e0]));
|
||||
for k in &keys {
|
||||
assert_eq!((k.interpolation_in(), k.interpolation_out()), (Some(Interpolation::Bezier), Some(Interpolation::Bezier)));
|
||||
}
|
||||
@@ -94,7 +97,7 @@ fn scale_keys_use_the_plain_template_with_three_components() {
|
||||
// A 128-byte record is not always spatial: the header's template flag decides.
|
||||
assert_eq!(k.kind(), KeyframeKind::Plain { components: 3 });
|
||||
assert_eq!(k.spatial(), None);
|
||||
assert_eq!(k.plain_ease_slots(), Some(vec![0.0; 12]));
|
||||
assert_eq!(k.ease_components(), Some(vec![NO_EASE; 3]));
|
||||
assert_eq!(k.ease(), None);
|
||||
assert_eq!((k.interpolation_in(), k.interpolation_out()), (Some(Interpolation::Linear), Some(Interpolation::Linear)));
|
||||
}
|
||||
@@ -125,7 +128,7 @@ fn two_dimensional_mask_feather_keys() {
|
||||
assert!(keys.iter().all(|k| k.raw().len() == 88 && k.kind() == KeyframeKind::Plain { components: 2 }));
|
||||
assert_eq!(keys.iter().map(|k| k.value().unwrap()).collect::<Vec<_>>(), [vec![0.0, 0.0], vec![40.0, 20.0]]);
|
||||
assert_eq!(keys.iter().map(|k| k.seconds(25600).unwrap()).collect::<Vec<_>>(), [0.0, 1.0]);
|
||||
assert_eq!(keys[0].plain_ease_slots(), Some(vec![0.0; 8]));
|
||||
assert_eq!(keys[0].ease_components(), Some(vec![NO_EASE; 2]));
|
||||
let mask = &layer.masks()[0];
|
||||
assert!(mask.feather.source == ValueSource::Keyframed && mask.feather.value == [0.0, 0.0]);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! colours, checked against the values the corpus was made with (its MANIFEST, batch 2).
|
||||
|
||||
use crate::container::helpers::{assert_near, base_layer, first_comp, layer_of_type, layer_shown_as, open};
|
||||
use effectcraft_aep::{BlendMode, CompHeader, LayerHeader, LayerType, LightType, Project, Rational, ValueSource};
|
||||
use effectcraft_aep::{BlendMode, CompHeader, LayerHeader, LayerType, LightType, Project};
|
||||
|
||||
fn l_header(name: &str) -> Option<LayerHeader> {
|
||||
Some({
|
||||
@@ -80,22 +80,24 @@ fn ntsc_frame_rates_are_exact_fractions() {
|
||||
// 229: frameRate 29.97 -> read back 29.9700012207031; the duration snaps from 5 s to 150 frames (5.005005 s).
|
||||
let h = skip!(comp_header("229-comp-fps-29.97.aep"));
|
||||
assert_eq!((h.time_base.frame_duration, h.time_base.timescale), (800, 23976));
|
||||
assert_eq!(h.frame_rate_exact(), Some(Rational { num: 2997, den: 100 }));
|
||||
assert!((h.frame_rate().unwrap() - 29.97).abs() < 1e-12);
|
||||
assert!((h.frame_rate_from_fixed() - 29.970_001_220_703_1).abs() < 1e-7);
|
||||
assert_eq!((h.duration_units, h.duration_frames()), (120_000, Some(150)));
|
||||
// The 16.16 rate holds the float32 29.97 (29.9700012207031).
|
||||
assert_eq!(h.frame_rate_fixed, 1_964_114);
|
||||
// 150 frames of 800 units.
|
||||
assert_eq!(h.duration_units, 120_000);
|
||||
assert!((h.duration_seconds().unwrap() - 5.005_005_005_005_01).abs() < 1e-9);
|
||||
// 230: frameRate 23.976 -> read back 23.9759979248047; 120 frames.
|
||||
let h = skip!(comp_header("230-comp-fps-23.976.aep"));
|
||||
assert_eq!((h.time_base.frame_duration, h.time_base.timescale), (1000, 23976));
|
||||
assert_eq!(h.frame_rate_exact(), Some(Rational { num: 2997, den: 125 }));
|
||||
assert!((h.frame_rate().unwrap() - 23.976).abs() < 1e-12);
|
||||
assert!((h.frame_rate_from_fixed() - 23.975_997_924_804_7).abs() < 1e-7);
|
||||
assert_eq!((h.duration_units, h.duration_frames()), (120_000, Some(120)));
|
||||
// The 16.16 rate holds the float32 23.976 (23.9759979248047).
|
||||
assert_eq!(h.frame_rate_fixed, 1_571_291);
|
||||
// 120 frames of 1000 units.
|
||||
assert_eq!(h.duration_units, 120_000);
|
||||
assert!((h.duration_seconds().unwrap() - 5.005_005_005_005_01).abs() < 1e-9);
|
||||
// 25 fps stays 25.
|
||||
let h = skip!(comp_header("000-base.aep"));
|
||||
assert_eq!((h.frame_rate_exact(), h.duration_frames()), (Some(Rational { num: 25, den: 1 }), Some(125)));
|
||||
assert_eq!((h.time_base.timescale, h.time_base.frame_duration, h.duration_units), (25600, 1024, 128_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -128,7 +130,6 @@ fn background_is_8_bits_per_channel() {
|
||||
// 231: bgColor [0.5, 0.5, 0.5] is stored as 128 and reads back as 128/255 = 0.50196.
|
||||
let h = skip!(comp_header("231-comp-bg-grey-0.5.aep"));
|
||||
assert_eq!(h.background, [128, 128, 128]);
|
||||
assert_near(&h.background_rgb(), &[0.501_960_784_313_73; 3], 1e-12);
|
||||
// The frame rate stays 25 even though an earlier edit of the AE session left other numbers in the cache-like fields.
|
||||
assert_eq!((h.time_base.frame_duration, h.time_base.timescale), (1024, 25600));
|
||||
}
|
||||
@@ -143,12 +144,10 @@ fn cameras_auto_orient_and_position() {
|
||||
let camera = layer_of_type(&comp, LayerType::Camera);
|
||||
let h = camera.header().unwrap();
|
||||
assert_eq!((h.flag_bytes[1], h.is_auto_oriented(), h.is_three_d(), h.source_id, h.light_type()), (0x44, true, true, None, None));
|
||||
// The default Position is an "auto state" record that stores [0, 0, -2666.67]; the two-node camera reports the comp centre.
|
||||
// The default Position is an "auto state" record that stores [0, 0, -2666.67].
|
||||
let pos = camera.camera_position().unwrap();
|
||||
assert!(pos.auto_state);
|
||||
assert_near(&pos.stored, &[0.0, 0.0, -2666.67], 0.01);
|
||||
assert_near(&pos.reported(1920, 1080, true), &[960.0, 540.0, -2666.67], 0.01);
|
||||
assert_eq!(camera.camera_point_of_interest(), Some([960.0, 540.0, 0.0]));
|
||||
|
||||
let bytes = fixture!("251-camera-one-node.aep");
|
||||
let file = open(&bytes);
|
||||
@@ -159,10 +158,9 @@ fn cameras_auto_orient_and_position() {
|
||||
// AE reports [0, 0, -2666.67] for the one-node camera: the stored value.
|
||||
let pos = camera.camera_position().unwrap();
|
||||
assert!(pos.auto_state);
|
||||
assert_near(&pos.reported(1920, 1080, h.is_auto_oriented()), &[0.0, 0.0, -2666.67], 0.01);
|
||||
assert_eq!(camera.camera_point_of_interest(), Some([960.0, 540.0, 0.0]));
|
||||
assert_near(&pos.stored, &[0.0, 0.0, -2666.67], 0.01);
|
||||
|
||||
// 253: Position set to [100, 200, -1000]: stored as given, no auto state; the point of interest stays [960, 540, 0].
|
||||
// 253: Position set to [100, 200, -1000]: stored as given, no auto state.
|
||||
let bytes = fixture!("253-camera-position-100-200-m1000.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
@@ -170,35 +168,28 @@ fn cameras_auto_orient_and_position() {
|
||||
let pos = camera.camera_position().unwrap();
|
||||
assert!(!pos.auto_state);
|
||||
assert_eq!(pos.stored, [100.0, 200.0, -1000.0]);
|
||||
assert_eq!(pos.reported(1920, 1080, true), [100.0, 200.0, -1000.0]);
|
||||
assert_eq!(camera.camera_point_of_interest(), Some([960.0, 540.0, 0.0]));
|
||||
// A camera has no light intensity.
|
||||
assert_eq!(camera.light_intensity(), None);
|
||||
}
|
||||
|
||||
/// Lights type and position.
|
||||
#[test]
|
||||
fn lights_type_and_intensity() {
|
||||
// 254: a spot light, Intensity 100 -> 50 (stored as 50.0 percent, absent at the default 100).
|
||||
fn lights_type_and_position() {
|
||||
// 254: a spot light (its Intensity 50 is checked on import).
|
||||
let bytes = fixture!("254-light-spot-intensity-50.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let light = layer_of_type(&first_comp(&project), LayerType::Light);
|
||||
let h = light.header().unwrap();
|
||||
assert_eq!((h.light_type(), h.light_type_code, h.source_id, h.is_auto_oriented(), h.is_three_d()), (Some(LightType::Spot), 1, None, true, true));
|
||||
let intensity = light.light_intensity().unwrap();
|
||||
assert_eq!((intensity.value, intensity.source), (50.0, ValueSource::Stored));
|
||||
assert!(light.camera_position().unwrap().auto_state);
|
||||
assert_near(&light.camera_position().unwrap().stored, &[0.0, 0.0, -1333.33], 0.01);
|
||||
|
||||
// 252: a point light (light type 2) at the default intensity, which is not stored.
|
||||
// 252: a point light (light type 2).
|
||||
let bytes = fixture!("252-light-point.aep");
|
||||
let file = open(&bytes);
|
||||
let project = Project::new(&file).unwrap();
|
||||
let light = layer_of_type(&first_comp(&project), LayerType::Light);
|
||||
let h = light.header().unwrap();
|
||||
assert_eq!((h.light_type(), h.light_type_code), (Some(LightType::Point), 2));
|
||||
let intensity = light.light_intensity().unwrap();
|
||||
assert_eq!((intensity.value, intensity.source), (100.0, ValueSource::Default));
|
||||
// The solid under it is no light.
|
||||
let solid = base_layer(&first_comp(&project)).header().unwrap();
|
||||
assert_eq!((solid.light_type(), solid.light_type_code), (None, 0));
|
||||
@@ -220,6 +211,6 @@ fn solid_colour_is_four_float32_argb() {
|
||||
// L is still red.
|
||||
let red = project.layer_source(&base_layer(&comp)).unwrap().footage().unwrap();
|
||||
assert_eq!(red.solid_rgb(), Some([1.0, 0.0, 0.0]));
|
||||
// The new layer has no user-set name flag (it shows its source's name).
|
||||
assert!(!blue.header().unwrap().name_is_user_set());
|
||||
// The new layer has no name of its own (it shows its source's name).
|
||||
assert_eq!(blue.name(), None);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ fn layers(name: &str) -> Option<Vec<(String, bool, Option<TrackMatte>, u32)>> {
|
||||
comp.layers()
|
||||
.map(|l| {
|
||||
let h = l.header().expect("header");
|
||||
(project.layer_display_name(&l).unwrap_or_default(), h.is_video_enabled(), l.track_matte(), h.id)
|
||||
(l.name().or_else(|| project.layer_source(&l)?.display_name()).unwrap_or_default(), h.is_video_enabled(), l.track_matte(), h.id)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
||||
@@ -154,16 +154,15 @@ use effectcraft_aep::{AepFile, Body, Chunk, Comp, Layer, Project, PropGroup, Pro
|
||||
|
||||
/// Touches the property accessors; none may panic on a damaged property.
|
||||
fn exercise_property(p: &Property<'_, '_>) {
|
||||
let _ = (p.header(), p.dims(), p.is_animated(), p.static_value(), p.time_scale(), p.flags(), p.is_static_flag_set());
|
||||
let _ = (p.expression(), p.expression_flags().map(|f| (f.all_set(), f.disabled())), p.expression_enabled(), p.user_name(), p.first_key_value());
|
||||
let _ = p.color_argb();
|
||||
let _ = (p.header(), p.dims(), p.is_animated(), p.static_value(), p.time_scale(), p.flags());
|
||||
let _ = (p.expression(), p.expression_flags().map(|f| f.disabled()), p.expression_enabled(), p.user_name(), p.first_key_value());
|
||||
if let Some(keys) = p.keys() {
|
||||
let scale = p.time_scale().unwrap_or(0);
|
||||
for k in keys.keyframes() {
|
||||
let _ = (k.time_units(), k.spatial_value(), k.raw().len(), k.kind(), k.seconds(scale), k.seconds(0));
|
||||
let _ = (k.time_units(), k.raw().len(), k.kind(), k.seconds(scale), k.seconds(0));
|
||||
let _ = (k.interpolation_in(), k.interpolation_out(), k.flags(), k.label(), k.is_roving());
|
||||
let _ = (k.scalar_value(), k.ease(), k.spatial(), k.components(), k.value(), k.plain_ease_slots());
|
||||
let _ = (k.ease_components(), k.color_distance());
|
||||
let _ = (k.scalar_value(), k.ease(), k.spatial(), k.components(), k.value());
|
||||
let _ = k.ease_components();
|
||||
for component in [0, 1, 2, 3, 7, 255, usize::MAX] {
|
||||
let _ = k.ease_component(component);
|
||||
}
|
||||
@@ -193,17 +192,14 @@ fn exercise_group(g: &PropGroup<'_, '_>, depth: usize) {
|
||||
fn exercise_layer(project: &Project<'_, '_>, comp_size: (u32, u32), layer: &Layer<'_, '_>) {
|
||||
let _ = (layer.name(), layer.is_three_d(), layer.id(), layer.track_matte());
|
||||
if let Some(h) = layer.header() {
|
||||
let _ = (h.in_point(), h.out_point(), h.in_point_seconds(), h.out_point_seconds(), h.start_seconds(), h.stretch_percent());
|
||||
let _ = (h.stretch_ratio(), h.stretch_den);
|
||||
let _ = (h.in_point(), h.out_point(), h.stretch_ratio(), h.stretch_den);
|
||||
let _ = (h.is_shy(), h.is_locked(), h.is_solo(), h.is_three_d(), h.is_motion_blur(), h.is_adjustment(), h.is_guide());
|
||||
let _ = (h.is_null_object(), h.collapses_transformations(), h.name_is_user_set(), h.quality, h.blend_mode, h.layer_type);
|
||||
let _ = (h.is_null_object(), h.collapses_transformations(), h.quality, h.blend_mode, h.layer_type);
|
||||
let _ = (h.is_enabled(), h.is_video_enabled(), h.is_audio_enabled(), h.is_effects_enabled(), h.is_auto_oriented(), h.light_type(), h.blend_mode.code());
|
||||
}
|
||||
let _ = (layer.is_enabled(), layer.is_audio_enabled(), layer.is_effects_enabled());
|
||||
let _ = (layer.camera_position().map(|p| p.reported(comp_size.0, comp_size.1, true)), layer.camera_point_of_interest(), layer.light_intensity());
|
||||
let _ = layer.camera_position().map(|p| (p.stored, p.auto_state));
|
||||
let _ = project.layer_anchor_px(layer);
|
||||
let _ = (layer.camera_zoom(), layer.camera_depth_of_field(), layer.camera_focus_distance(), layer.camera_aperture());
|
||||
let _ = (layer.light_color(), layer.light_cone_angle(), layer.light_cone_feather());
|
||||
let _ = layer
|
||||
.time_remap()
|
||||
.map(|t| (t.enabled, t.keys.iter().fold(0.0, |acc, k| acc + k.value_seconds + k.time_seconds.unwrap_or(0.0) + f64::from(k.time_units))));
|
||||
@@ -230,7 +226,7 @@ fn exercise_layer(project: &Project<'_, '_>, comp_size: (u32, u32), layer: &Laye
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = (project.layer_source(layer).map(|i| i.id()), project.layer_display_name(layer), project.layer_source_size(layer));
|
||||
let _ = (project.layer_source(layer).map(|i| i.id()), project.layer_source(layer).and_then(|i| i.display_name()), project.layer_source_size(layer));
|
||||
if let Some(t) = layer.transform(comp_size.0, comp_size.1) {
|
||||
let _ = (t.anchor_px(f64::from(comp_size.0), f64::from(comp_size.1)), t.position.value, t.opacity_percent.value);
|
||||
}
|
||||
@@ -263,7 +259,6 @@ fn exercise_layer(project: &Project<'_, '_>, comp_size: (u32, u32), layer: &Laye
|
||||
}
|
||||
for m in layer.masks() {
|
||||
let _ = (m.name.clone(), m.mode, m.inverted, m.counter, m.feather, m.opacity_percent, m.expansion, m.path_animated, m.path_key_seconds.len());
|
||||
let _ = project.mask_vertices_px(layer, &m).map(|shapes| shapes.iter().map(Vec::len).sum::<usize>());
|
||||
for s in &m.shapes {
|
||||
let _ = (s.vertex_count(), s.vertices((1920.0, 1080.0)).len(), s.vertices((f64::NAN, f64::INFINITY)).len(), s.open);
|
||||
}
|
||||
@@ -291,10 +286,9 @@ fn exercise_comp(project: &Project<'_, '_>, comp: &Comp<'_, '_>) {
|
||||
let mut size = (1920, 1080);
|
||||
if let Some(h) = comp.header() {
|
||||
size = (u32::from(h.width), u32::from(h.height));
|
||||
let _ = (h.frame_rate(), h.frame_rate_from_fixed(), h.duration_seconds(), h.work_area_start_seconds(), h.work_area_end_seconds());
|
||||
let _ = (h.frame_rate_exact(), h.duration_frames());
|
||||
let _ = (h.background_rgb(), h.pixel_aspect_ratio(), h.pixel_aspect.reduced(), h.shutter_angle, h.motion_blur);
|
||||
let _ = (h.shutter_phase, h.display_start, h.display_start_seconds(), h.display_start_frame());
|
||||
let _ = (h.frame_rate(), h.frame_rate_fixed, h.duration_seconds(), h.work_area_start_units, h.work_area_end_units);
|
||||
let _ = (h.background, h.pixel_aspect.to_f64(), h.pixel_aspect.reduced(), h.shutter_angle, h.motion_blur);
|
||||
let _ = (h.shutter_phase, h.display_start.map(|r| r.to_f64()));
|
||||
}
|
||||
for layer in comp.layers() {
|
||||
exercise_layer(project, size, &layer);
|
||||
@@ -305,10 +299,8 @@ fn exercise_comp(project: &Project<'_, '_>, comp: &Comp<'_, '_>) {
|
||||
fn exercise(file: &AepFile<'_>) {
|
||||
let Some(project) = Project::new(file) else { return };
|
||||
for item in project.all_items() {
|
||||
let _ = (item.kind(), item.name(), item.id(), item.label(), item.used_item_ids(), item.footage(), item.display_name());
|
||||
let _ = item
|
||||
.footage()
|
||||
.map(|f| (f.duration, f.native_frame_rate, f.bits_per_pixel, f.file_size, f.audio_sample_rate, f.is_sequence, f.sequence_frame_count()));
|
||||
let _ = (item.kind(), item.name(), item.id(), item.label(), item.footage(), item.display_name());
|
||||
let _ = item.footage().map(|f| (f.duration, f.native_frame_rate, f.bits_per_pixel, f.file_size, f.audio_sample_rate, f.is_sequence));
|
||||
let _ = item.id().and_then(|id| project.item_by_id(id));
|
||||
if let Some(comp) = item.comp() {
|
||||
exercise_comp(&project, &comp);
|
||||
@@ -561,12 +553,12 @@ fn extreme_values_in_the_decoded_headers() {
|
||||
use effectcraft_aep::{CompHeader, LayerHeader, Rational, ShapePath};
|
||||
// Every field at its maximum: no overflow, no division by zero, no panic.
|
||||
let h = LayerHeader::parse(&[0xff; 164]).unwrap();
|
||||
let _ = (h.in_point(), h.out_point(), h.in_point_seconds(), h.out_point_seconds(), h.start_seconds(), h.stretch_percent());
|
||||
let _ = (h.in_point(), h.out_point(), h.start.to_f64(), h.stretch_ratio());
|
||||
let mut zero_den = [0u8; 164];
|
||||
zero_den[8..12].copy_from_slice(&u32::MAX.to_be_bytes());
|
||||
zero_den[12..16].copy_from_slice(&i32::MIN.to_be_bytes());
|
||||
let h = LayerHeader::parse(&zero_den).unwrap();
|
||||
assert_eq!((h.in_point(), h.out_point(), h.start_seconds()), (None, None, None));
|
||||
assert_eq!((h.in_point(), h.out_point(), h.start.to_f64()), (None, None, None));
|
||||
let mut wide = [0u8; 164];
|
||||
wide[8..12].copy_from_slice(&u32::MAX.to_be_bytes());
|
||||
wide[12..16].copy_from_slice(&i32::MIN.to_be_bytes());
|
||||
@@ -574,14 +566,12 @@ fn extreme_values_in_the_decoded_headers() {
|
||||
wide[20..24].copy_from_slice(&i32::MAX.to_be_bytes());
|
||||
wide[24..28].copy_from_slice(&u32::MAX.to_be_bytes());
|
||||
let h = LayerHeader::parse(&wide).unwrap();
|
||||
let _ = (h.in_point(), h.in_point_seconds());
|
||||
let _ = h.in_point();
|
||||
let c = CompHeader::parse(&[0xff; 204]).unwrap();
|
||||
assert_eq!((c.duration_seconds(), c.work_area_start_seconds(), c.work_area_end_units), (None, None, None));
|
||||
let _ = (c.frame_rate(), c.frame_rate_from_fixed(), c.background_rgb(), c.pixel_aspect_ratio(), c.frame_rate_exact());
|
||||
assert_eq!(c.duration_frames(), Some(1));
|
||||
assert_eq!((c.duration_seconds(), c.work_area_end_units), (None, None));
|
||||
let _ = (c.frame_rate(), c.pixel_aspect.to_f64());
|
||||
let zero = CompHeader::parse(&[0; 204]).unwrap();
|
||||
assert_eq!((zero.frame_rate(), zero.pixel_aspect_ratio(), zero.duration_seconds()), (None, None, None));
|
||||
assert_eq!((zero.frame_rate_exact(), zero.duration_frames()), (None, None));
|
||||
assert_eq!((zero.frame_rate(), zero.pixel_aspect.to_f64(), zero.duration_seconds()), (None, None, None));
|
||||
let all = LayerHeader::parse(&[0xff; 164]).unwrap();
|
||||
let _ = (all.is_enabled(), all.is_auto_oriented(), all.light_type(), all.blend_mode.code());
|
||||
assert_eq!(LayerHeader::parse(&[0u8; 164]).unwrap().light_type(), None);
|
||||
@@ -680,7 +670,7 @@ fn hostile_text_dictionaries_and_marker_headers_never_panic() {
|
||||
|
||||
#[test]
|
||||
fn extreme_values_in_the_batch_3_fields() {
|
||||
use effectcraft_aep::{CompHeader, Footage, LayerHeader, Rational};
|
||||
use effectcraft_aep::{CompHeader, LayerHeader};
|
||||
// Time stretch: zero and maximal numerators and denominators (bytes 8 and 108), with extreme times.
|
||||
for (num, den) in [(0u32, 0u32), (1, 0), (0, 1), (u32::MAX, 1), (1, u32::MAX), (u32::MAX, u32::MAX), (3, 2)] {
|
||||
let mut ldta = [0u8; 164];
|
||||
@@ -693,7 +683,7 @@ fn extreme_values_in_the_batch_3_fields() {
|
||||
ldta[28..32].copy_from_slice(&i32::MIN.to_be_bytes());
|
||||
ldta[32..36].copy_from_slice(&1u32.to_be_bytes());
|
||||
let h = LayerHeader::parse(&ldta).unwrap();
|
||||
let _ = (h.stretch_ratio(), h.stretch_percent(), h.in_point(), h.out_point(), h.in_point_seconds(), h.out_point_seconds());
|
||||
let _ = (h.stretch_ratio(), h.in_point(), h.out_point());
|
||||
if den == 0 {
|
||||
assert_eq!((h.stretch_ratio(), h.in_point(), h.out_point()), (None, None, None));
|
||||
}
|
||||
@@ -701,31 +691,8 @@ fn extreme_values_in_the_batch_3_fields() {
|
||||
// Display start and shutter phase from extreme bytes; a missing tail leaves them unknown.
|
||||
for fill in [0x00u8, 0x7f, 0x80, 0xff] {
|
||||
let c = CompHeader::parse(&[fill; 204]).unwrap();
|
||||
let _ = (c.shutter_phase, c.display_start, c.display_start_seconds(), c.display_start_frame());
|
||||
let _ = (c.shutter_phase, c.display_start.map(|r| r.to_f64()));
|
||||
}
|
||||
let zero_rate = CompHeader::parse(&[0; 204]).unwrap();
|
||||
assert_eq!((zero_rate.display_start_seconds(), zero_rate.display_start_frame()), (None, None));
|
||||
// Footage durations: zero denominator, negative and maximal numerators, a huge frame rate.
|
||||
let base = Footage {
|
||||
file_type: String::new(),
|
||||
width: 0,
|
||||
height: 0,
|
||||
name: None,
|
||||
is_solid: false,
|
||||
solid_argb: None,
|
||||
path: None,
|
||||
duration: None,
|
||||
native_frame_rate: 0,
|
||||
bits_per_pixel: 0,
|
||||
file_size: 0,
|
||||
audio_sample_rate: None,
|
||||
is_sequence: true,
|
||||
};
|
||||
for (num, den, rate) in [(3i64, 30i64, 30u32), (3, 0, 30), (-3, 30, 30), (i64::MAX, 1, u32::MAX), (i64::MIN, -1, u32::MAX), (1, i64::MAX, 1), (0, 1, 0)] {
|
||||
let f = Footage { duration: Some(Rational { num, den }), native_frame_rate: rate, ..base.clone() };
|
||||
let _ = f.sequence_frame_count();
|
||||
}
|
||||
assert_eq!(Footage { duration: Some(Rational { num: 3, den: 30 }), native_frame_rate: 30, ..base.clone() }.sequence_frame_count(), Some(3));
|
||||
assert_eq!(Footage { duration: Some(Rational { num: 3, den: 0 }), native_frame_rate: 30, ..base.clone() }.sequence_frame_count(), None);
|
||||
assert_eq!(Footage { duration: None, ..base }.sequence_frame_count(), None);
|
||||
// A zero denominator has no value.
|
||||
assert_eq!(CompHeader::parse(&[0; 204]).unwrap().display_start.and_then(|r| r.to_f64()), None);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ fn text_layer_document(name: &str) -> Option<TextDocument> {
|
||||
let layer = comp.layers().find(|l| l.name().as_deref() == Some("T")).expect("the text layer T");
|
||||
let h = layer.header().unwrap();
|
||||
assert_eq!(h.layer_type, LayerType::Text);
|
||||
assert!(h.name_is_user_set());
|
||||
layer.text_document().expect("text document")
|
||||
})
|
||||
}
|
||||
@@ -192,7 +191,6 @@ fn png_footage_layer() {
|
||||
// The path comes from the alias JSON (the fixture holds a neutral replacement of the original).
|
||||
assert!(f.path.as_deref().is_some_and(|p| p.ends_with("test8x8.png")), "{:?}", f.path);
|
||||
assert_eq!(project.layer_source_size(&layer), Some((8, 8)));
|
||||
assert_eq!(project.layer_display_name(&layer).as_deref(), Some("png"));
|
||||
// L is still there below it.
|
||||
assert_eq!(comp.layers().count(), 2);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
//! The flat tree index the importer reads ([`TreeIndex`]) against the owned chunk tree, on every
|
||||
//! file of the fixture directory: the same tree, and the same answers from the typed view.
|
||||
|
||||
use std::fmt::Write as _;
|
||||
|
||||
use effectcraft_aep::container::index::TreeIndex;
|
||||
use effectcraft_aep::{
|
||||
AepFile, Chunk, CryptomatteData, CurvesData, Effect, HueSaturationData, LevelsData, Limits, MeshData, Project, PropGroup, PropNode, is_aepx, parse,
|
||||
parse_with_limits, read_aepx, write,
|
||||
};
|
||||
|
||||
/// Every `.aep` and `.aepx` in the fixture directory (the real projects included), sorted.
|
||||
fn every_file() -> Vec<std::path::PathBuf> {
|
||||
let Some(dir) = crate::common::dir() else {
|
||||
crate::common::skipped("*.aep");
|
||||
return Vec::new();
|
||||
};
|
||||
let Ok(entries) = std::fs::read_dir(&dir) else {
|
||||
crate::common::skipped("*.aep");
|
||||
return Vec::new();
|
||||
};
|
||||
let mut out: Vec<std::path::PathBuf> =
|
||||
entries.filter_map(Result::ok).map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "aep" || x == "aepx")).collect();
|
||||
out.sort();
|
||||
out
|
||||
}
|
||||
|
||||
/// What the typed view reads from a project, as text: items, compositions, layers with their
|
||||
/// headers, transforms, masks, effects with every parameter value, text, markers, the whole
|
||||
/// property tree with static values and key records, settings and versions.
|
||||
fn dump(view: &Project<'_, '_>) -> String {
|
||||
let mut s = String::new();
|
||||
let defs = view.effect_definition_index();
|
||||
for item in view.all_items() {
|
||||
let _ = writeln!(s, "item {:?} {:?} {:?} {:?} {:?}", item.kind(), item.name(), item.display_name(), item.id(), item.label());
|
||||
let _ = writeln!(s, " footage {:?} {:?} {:?}", item.footage(), item.sequence_info(), item.conform_frame_rate());
|
||||
let _ = writeln!(s, " folder {} {}", item.has_folder_contents(), item.folder_contents_unreadable());
|
||||
let Some(comp) = item.comp() else { continue };
|
||||
let _ = writeln!(s, " comp {:?} {:?} {:?}", comp.time_base(), comp.header(), comp.markers());
|
||||
for layer in comp.layers() {
|
||||
let _ = writeln!(s, " layer {:?} {:?} {:?} {:?}", layer.name(), layer.id(), layer.header(), layer.track_matte());
|
||||
let _ = writeln!(s, " transform {:?}", layer.transform(1920, 1080));
|
||||
let _ = writeln!(s, " time remap {:?} orientation {:?} {:?}", layer.time_remap(), layer.orientation(), layer.orientation_keys());
|
||||
let _ = writeln!(s, " masks {:?}", layer.mask_atoms().iter().map(|m| (&m.mask, &m.path_shapes)).collect::<Vec<_>>());
|
||||
let _ = writeln!(s, " shapes {:?}", layer.shape_groups());
|
||||
let _ =
|
||||
writeln!(s, " text {:?} {} {:?}", layer.text_document(), layer.text_document_count(), layer.source_text_property().map(|p| p.is_animated()));
|
||||
let _ = writeln!(s, " markers {:?} source {:?}", layer.markers(), view.layer_source(&layer).map(|i| i.id()));
|
||||
for fx in layer.effects() {
|
||||
let _ =
|
||||
writeln!(s, " fx {} {:?} {:?} {:?} {:?}", fx.match_name(), fx.display_name(), fx.enabled(), defs.source(&fx), fx.value_record_names());
|
||||
let _ = writeln!(s, " names {:?} {:?} {:?} {:?}", fx.name(), fx.user_name(), fx.declared_param_count(), fx.has_own_definitions());
|
||||
for p in defs.params(&fx) {
|
||||
let _ = writeln!(s, " {} {:?} {:?} {:?} {:?}", p.match_name, p.kind, p.name, p.items, p.value());
|
||||
arbitrary(&fx, &p.match_name, &mut s);
|
||||
}
|
||||
for name in fx.value_record_names() {
|
||||
arbitrary(&fx, &name, &mut s);
|
||||
}
|
||||
}
|
||||
if let Some(root) = layer.properties() {
|
||||
tree(&root, 0, &mut s);
|
||||
}
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// The arbitrary data stored for a parameter and what each decoder reads from it.
|
||||
fn arbitrary(fx: &Effect<'_, '_>, name: &str, s: &mut String) {
|
||||
let Some(data) = fx.arbitrary_data(name) else { return };
|
||||
let _ = writeln!(s, " arbitrary {name} {data:?}");
|
||||
let _ = writeln!(s, " {:?} {:?}", HueSaturationData::parse(data), LevelsData::parse(data));
|
||||
let _ = writeln!(s, " {:?} {:?} {:?}", CurvesData::parse(data), MeshData::parse(data), CryptomatteData::parse(data));
|
||||
}
|
||||
|
||||
/// Appends a group and everything below it to the dump, depth-limited.
|
||||
fn tree(group: &PropGroup<'_, '_>, depth: usize, s: &mut String) {
|
||||
if depth > 32 {
|
||||
return;
|
||||
}
|
||||
let _ = writeln!(s, "{:depth$}group {:?} {:?}", "", group.user_name(), group.flags());
|
||||
for e in group.entries() {
|
||||
match e.node {
|
||||
PropNode::Group(g) => tree(&g, depth + 1, s),
|
||||
PropNode::Property(p) => {
|
||||
let keys: Option<Vec<Vec<u8>>> = p.keys().map(|k| k.records().map(<[u8]>::to_vec).collect());
|
||||
let _ = writeln!(s, "{:depth$} {} {:?} {:?} {:?} {:?}", "", e.match_name, p.user_name(), p.header(), p.static_value(), keys);
|
||||
}
|
||||
PropNode::Other(c) => {
|
||||
let _ = writeln!(s, "{:depth$} {} other {:?} {}", "", e.match_name, c.list_type(), c.descendants().count());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The index is the parsed tree and the view reads the same on every file.
|
||||
#[test]
|
||||
fn the_index_is_the_parsed_tree_and_the_view_reads_the_same_on_every_file() {
|
||||
for path in every_file() {
|
||||
let name = path.display().to_string();
|
||||
let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
// `.aepx` is read into the chunk tree and indexed from it; `.aep` is indexed in place.
|
||||
// A file that does not read (a damaged sample) must fail the index the same way.
|
||||
let file: AepFile<'_> = match if is_aepx(&bytes) { read_aepx(&bytes) } else { parse(&bytes) } {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
if !is_aepx(&bytes) {
|
||||
assert_eq!(TreeIndex::parse(&bytes).err(), Some(e), "{name}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let index = (if is_aepx(&bytes) { TreeIndex::from_file(&file) } else { TreeIndex::parse(&bytes) }).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
assert!(index.to_file() == file, "{name}: the index is not the parsed tree");
|
||||
assert_eq!(index.len(), file.walk().count(), "{name}");
|
||||
assert_eq!(index.file_version(), file.file_version(), "{name}");
|
||||
assert_eq!(index.saved_by_version(), file.saved_by_version(), "{name}");
|
||||
assert_eq!(effectcraft_aep::ProjectSettings::read_index(&index), effectcraft_aep::ProjectSettings::read(&file), "{name}");
|
||||
let (Some(a), Some(b)) = (Project::new(&file), Project::from_index(&index)) else {
|
||||
assert!(Project::new(&file).is_none() && Project::from_index(&index).is_none(), "{name}");
|
||||
continue;
|
||||
};
|
||||
let (da, db) = (dump(&a), dump(&b));
|
||||
assert!(da == db, "{name}: the view reads differently through the index");
|
||||
}
|
||||
}
|
||||
|
||||
/// The index and the parser fail alike under tight limits.
|
||||
#[test]
|
||||
fn the_index_and_the_parser_fail_alike_under_tight_limits() {
|
||||
for path in every_file().into_iter().filter(|p| p.extension().is_some_and(|x| x == "aep")) {
|
||||
let name = path.display().to_string();
|
||||
let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
let total = parse(&bytes).map(|f| f.walk().count()).unwrap_or(0);
|
||||
for limits in [
|
||||
Limits { max_depth: 2, max_chunks: 10_000_000 },
|
||||
Limits { max_depth: 6, max_chunks: 10_000_000 },
|
||||
Limits { max_depth: 64, max_chunks: total },
|
||||
Limits { max_depth: 64, max_chunks: total.saturating_sub(1) },
|
||||
Limits { max_depth: 64, max_chunks: total / 2 },
|
||||
] {
|
||||
let old = parse_with_limits(&bytes, limits);
|
||||
let new = TreeIndex::parse_with_limits(&bytes, limits);
|
||||
match (old, new) {
|
||||
(Ok(f), Ok(i)) => assert!(i.to_file() == f, "{name}: {limits:?}"),
|
||||
(Err(a), Err(b)) => assert_eq!(a, b, "{name}: {limits:?}"),
|
||||
(a, b) => panic!("{name}: {limits:?}: {:?} vs {:?}", a.err(), b.err()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A 40-byte NUL-padded match name.
|
||||
fn tdmn(name: &str) -> Chunk<'static> {
|
||||
let mut b = name.as_bytes().to_vec();
|
||||
b.resize(40, 0);
|
||||
Chunk::data(*b"tdmn", b)
|
||||
}
|
||||
|
||||
/// A nested chunk `id` holding one `Utf8` with `text`.
|
||||
fn utf8(id: [u8; 4], text: &str) -> Chunk<'static> {
|
||||
Chunk { id, body: effectcraft_aep::Body::Chunks(vec![Chunk::data(*b"Utf8", text.as_bytes().to_vec())]), pad: None }
|
||||
}
|
||||
|
||||
/// A project with one composition, one layer and one effect whose five parameters carry arbitrary
|
||||
/// data in the sizes the decoders read (Hue/Saturation, Levels, Curves, a 2 x 2 mesh, Cryptomatte),
|
||||
/// so the arbitrary-data path runs without the fixture directory.
|
||||
fn synthetic() -> Vec<u8> {
|
||||
let mut mesh = vec![0u8; 180];
|
||||
mesh[..8].copy_from_slice(&[0, 0, 0, 2, 0, 0, 0, 2]);
|
||||
let mut cry = vec![0u8; 200];
|
||||
cry[..4].copy_from_slice(b"cry1");
|
||||
cry[32..37].copy_from_slice(b"Layer");
|
||||
let mut levels = vec![0u8; 108];
|
||||
levels[8..16].copy_from_slice(&1.0f64.to_be_bytes());
|
||||
let payloads: [Vec<u8>; 5] = [vec![7u8; 180], levels, vec![0u8; CurvesData::SIZE], mesh, cry];
|
||||
let (mut part, mut values) =
|
||||
(vec![Chunk::data(*b"parn", 6u32.to_be_bytes().to_vec())], vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), utf8(*b"tdsn", "Mine")]);
|
||||
for (i, data) in payloads.into_iter().enumerate() {
|
||||
let name = format!("FX-{:04}", i + 1);
|
||||
let mut pard = vec![0u8; 148];
|
||||
pard[12..16].copy_from_slice(&11u32.to_be_bytes());
|
||||
part.extend([tdmn(&name), Chunk::data(*b"pard", pard)]);
|
||||
let record = Chunk::list(*b"tdbs", vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec()), Chunk::data(*b"cdat", vec![0, 0, 0, 1])]);
|
||||
values.extend([tdmn(&name), record, Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", data)])]);
|
||||
}
|
||||
values.push(tdmn("ADBE Group End"));
|
||||
let sspc = Chunk::list(*b"sspc", vec![utf8(*b"fnam", "Effect"), Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)]);
|
||||
let parade = Chunk::list(*b"tdgp", vec![tdmn("FX"), sspc, tdmn("ADBE Group End")]);
|
||||
let root = Chunk::list(*b"tdgp", vec![tdmn("ADBE Effect Parade"), parade, tdmn("ADBE Group End")]);
|
||||
let layer = Chunk::list(*b"Layr", vec![Chunk::data(*b"ldta", vec![0u8; 160]), Chunk::data(*b"Utf8", b"Layer".to_vec()), root]);
|
||||
let mut idta = vec![0u8; 64];
|
||||
idta[..2].copy_from_slice(&4u16.to_be_bytes());
|
||||
idta[16..20].copy_from_slice(&2u32.to_be_bytes());
|
||||
let mut cdta = vec![0u8; 200];
|
||||
cdta[4..12].copy_from_slice(&[0, 0, 0, 1, 0, 0, 0, 30]);
|
||||
let item = Chunk::list(*b"Item", vec![Chunk::data(*b"idta", idta), Chunk::data(*b"Utf8", b"Comp".to_vec()), Chunk::data(*b"cdta", cdta), layer]);
|
||||
let file = AepFile { chunks: vec![Chunk::data(*b"head", vec![0u8; 20]), Chunk::list(*b"Fold", vec![item])], trailer: std::borrow::Cow::Borrowed(&[]) };
|
||||
write(&file).expect("write")
|
||||
}
|
||||
|
||||
/// The view reads arbitrary effect data the same through the index.
|
||||
#[test]
|
||||
fn the_view_reads_arbitrary_effect_data_the_same_through_the_index() {
|
||||
let bytes = synthetic();
|
||||
let file = parse(&bytes).expect("parse");
|
||||
let index = TreeIndex::parse(&bytes).expect("index");
|
||||
let (a, b) = (Project::new(&file).expect("project"), Project::from_index(&index).expect("project"));
|
||||
let (da, db) = (dump(&a), dump(&b));
|
||||
assert_eq!(da, db);
|
||||
// The synthetic effect really reaches every decoder (the dump is not empty of them).
|
||||
assert_eq!(da.matches("arbitrary FX-").count(), 10, "{da}");
|
||||
assert!(da.contains("Some(HueSaturationData") && da.contains("Some(LevelsData") && da.contains("Some(CurvesData"), "{da}");
|
||||
assert!(da.contains("Some(MeshData") && da.contains("Some(CryptomatteData"), "{da}");
|
||||
assert!(da.contains("Some(\"Mine\")"), "the user name is read: {da}");
|
||||
}
|
||||
@@ -111,7 +111,7 @@ fn match_names_come_from_the_tdmn_chunks() {
|
||||
assert!(!names.iter().any(|n| n == "ADBE Group End"));
|
||||
assert!(root.find(&["ADBE Transform Group", "ADBE Nonexistent"]).is_none());
|
||||
// The raw tdmn body is 40 bytes, NUL padded.
|
||||
let raw = root.chunk().children().iter().find(|c| c.is(b"tdmn")).unwrap();
|
||||
let raw = root.chunk().children().find(|c| c.is(b"tdmn")).unwrap();
|
||||
assert_eq!(raw.bytes().unwrap().len(), 40);
|
||||
}
|
||||
|
||||
@@ -150,8 +150,8 @@ fn effect_parameter_value() {
|
||||
assert!(instance.is_list(b"sspc"));
|
||||
// The effect's name is in a nested fnam chunk.
|
||||
let fnam = instance.child(b"fnam").unwrap();
|
||||
assert!(matches!(fnam.body, Body::Chunks(_)));
|
||||
assert_eq!(fnam.children()[0].bytes(), Some(&b"Slider Control"[..]));
|
||||
assert!(matches!(fnam.to_chunk().body, Body::Chunks(_)));
|
||||
assert_eq!(fnam.children().next().unwrap().bytes(), Some(&b"Slider Control"[..]));
|
||||
// The parameters are a property group inside the instance.
|
||||
let params = PropGroup::from_chunk(instance.child_list(b"tdgp").unwrap()).unwrap();
|
||||
assert_eq!(params.names(), ["ADBE Slider Control-0000", "ADBE Slider Control-0001", "ADBE Effect Built In Params"]);
|
||||
@@ -186,7 +186,7 @@ fn position_keyframes() {
|
||||
assert_eq!(times, [0, 25_600, 64_000]);
|
||||
let seconds: Vec<f64> = times.iter().map(|t| tb.seconds(*t).unwrap()).collect();
|
||||
assert_eq!(seconds, [0.0, 1.0, 2.5]);
|
||||
let values: Vec<[f64; 3]> = keys.keyframes().map(|k| k.spatial_value().unwrap()).collect();
|
||||
let values: Vec<Vec<f64>> = keys.keyframes().map(|k| k.value().unwrap()).collect();
|
||||
assert_eq!(values, [[0.0, 0.0, 0.0], [100.0, 0.0, 0.0], [200.0, 100.0, 0.0]]);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ fn linear_position_keys() {
|
||||
let values: Vec<_> = keys.iter().map(|k| k.spatial().unwrap().value).collect();
|
||||
assert_eq!(values, [[0.0, 0.0, 0.0], [100.0, 0.0, 0.0], [200.0, 100.0, 0.0]]);
|
||||
assert_eq!(p.first_key_value(), Some(vec![0.0, 0.0, 0.0]));
|
||||
assert_eq!(p.is_static_flag_set(), Some(false));
|
||||
assert!(p.is_animated());
|
||||
}));
|
||||
// The transform of the layer reports the animated Position as keyframed (value at the first key).
|
||||
let (t, _) = skip!(transform("055-key-position-3key-inserted-t2.5.aep"));
|
||||
@@ -181,7 +181,7 @@ fn roving_and_label_flags() {
|
||||
assert_eq!(roving, [false, true, false]);
|
||||
assert_eq!(keys[1].time_units(), Some(26509));
|
||||
assert_eq!(keys[1].seconds(25600), Some(1.0355078125));
|
||||
assert_eq!(keys[1].spatial_value(), Some([100.0, 0.0, 0.0]));
|
||||
assert_eq!(keys[1].value(), Some(vec![100.0, 0.0, 0.0]));
|
||||
assert_eq!(keys[1].flags(), Some(0x0027));
|
||||
assert_eq!(keys[1].label(), Some(0));
|
||||
}));
|
||||
@@ -193,7 +193,7 @@ fn roving_and_label_flags() {
|
||||
assert_eq!(keys[1].flags(), Some(0x0247));
|
||||
assert_eq!(keys[0].flags(), Some(0x0007));
|
||||
assert_eq!(keys[1].is_roving(), Some(false));
|
||||
assert_eq!(keys[1].spatial_value(), Some([100.0, 0.0, 0.0]));
|
||||
assert_eq!(keys[1].value(), Some(vec![100.0, 0.0, 0.0]));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -204,7 +204,6 @@ fn scalar_opacity_keys() {
|
||||
assert!(p.is_animated());
|
||||
assert_eq!(p.dims(), Some(1));
|
||||
assert_eq!(p.time_scale(), Some(25600));
|
||||
assert_eq!(p.is_static_flag_set(), Some(false));
|
||||
let list = p.keys().unwrap();
|
||||
assert_eq!(list.header.record_size, 48);
|
||||
let keys: Vec<_> = list.keyframes().collect();
|
||||
@@ -243,10 +242,8 @@ fn expression_text_and_flag_bytes() {
|
||||
assert_eq!(p.expression(), None);
|
||||
let flags = p.expression_flags().unwrap();
|
||||
assert_eq!((flags.byte_76, flags.byte_77, flags.byte_120), (0, 0, 0));
|
||||
assert!(!flags.all_set());
|
||||
// A written static property: tdsb 1, byte 5 of tdb4 has bit 0 set (15 for Position).
|
||||
assert_eq!(p.flags(), Some(1));
|
||||
assert_eq!(p.is_static_flag_set(), Some(true));
|
||||
assert_eq!(p.header().and_then(|h| h.get(5).copied()), Some(15));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -83,6 +83,63 @@ fn ntsc_and_odd_frame_rates_use_the_time_bases_after_effects_writes() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every ntsc rate reads back as the rate it was written for.
|
||||
#[test]
|
||||
fn every_ntsc_rate_reads_back_as_the_rate_it_was_written_for() {
|
||||
// The export's time base for each NTSC rate and the import's rate for that time base use the
|
||||
// one NTSC table; the real paths must agree both ways.
|
||||
for rate in [FrameRate::FPS_23_976, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_119_88] {
|
||||
let mut p = Project::default();
|
||||
add_comp(&mut p, "R", 640, 360, rate, 2.0, None);
|
||||
let r = export_all(&p);
|
||||
let exists = |_: &str| true;
|
||||
let options = effectcraft_aep::import::ImportOptions { allow_losses: true, ..effectcraft_aep::import::ImportOptions::new(&exists) };
|
||||
let mut back = Project::default();
|
||||
let imported = effectcraft_aep::import::import(&mut back, &r.bytes, &options).expect("import");
|
||||
let comp = imported.comps.first().and_then(|c| back.comp(*c)).expect("comp");
|
||||
assert_eq!(comp.frame_rate, rate, "{}", rate.label());
|
||||
}
|
||||
}
|
||||
|
||||
/// #3099: After Effects reads a null's absent Anchor Point as its top-left corner `[0, 0]`. A
|
||||
/// null anchored at its centre is written (it was left out as "the default" and came back at the
|
||||
/// corner); one at the corner is not, and both import back as they were.
|
||||
#[test]
|
||||
fn null_anchor_points_round_trip() {
|
||||
let mut p = Project::default();
|
||||
let c = add_comp(&mut p, "C", 800, 600, FrameRate::new(30, 1), 2.0, None);
|
||||
add_layer(&mut p, c, "Corner", LayerSource::Null, (100, 100));
|
||||
add_layer(&mut p, c, "Centre", LayerSource::Null, (100, 100));
|
||||
for (idx, anchor) in [(0, [50.0, 50.0, 0.0]), (1, [0.0, 0.0, 0.0])] {
|
||||
with_layer(&mut p, c, idx, |l| {
|
||||
if let Some(a) = l.props.prop_mut("transform/anchor") {
|
||||
a.value = Value::Vec3(anchor);
|
||||
}
|
||||
});
|
||||
}
|
||||
let r = export_all(&p);
|
||||
let file = parse(&r.bytes).expect("parse");
|
||||
let view = effectcraft_aep::Project::new(&file).expect("project");
|
||||
let comp = view.all_items().into_iter().find(|i| i.comp().is_some()).expect("comp");
|
||||
let stored: Vec<_> =
|
||||
comp.comp().expect("c").layers().map(|l| (l.name().unwrap_or_default(), l.transform(800, 600).expect("transform").anchor_fraction.source)).collect();
|
||||
assert_eq!(stored, [("Centre".to_string(), effectcraft_aep::ValueSource::Stored), ("Corner".to_string(), effectcraft_aep::ValueSource::Default)]);
|
||||
let mut back = Project::default();
|
||||
let none = |_: &str| false;
|
||||
let res = effectcraft_aep::import::import(
|
||||
&mut back,
|
||||
&r.bytes,
|
||||
&effectcraft_aep::import::ImportOptions { allow_losses: true, ..effectcraft_aep::import::ImportOptions::new(&none) },
|
||||
)
|
||||
.expect("import");
|
||||
let comp = res.comps.first().and_then(|id| back.comp(*id)).expect("comp");
|
||||
for (name, want) in [("Centre", [50.0, 50.0]), ("Corner", [0.0, 0.0])] {
|
||||
let l = comp.layers.iter().find(|l| l.name == name).expect("layer");
|
||||
let a = l.props.prop("transform/anchor").expect("anchor").value.as_vec2();
|
||||
assert!(close(a[0], want[0]) && close(a[1], want[1]), "{name}: {a:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_header_fields() {
|
||||
let mut p = Project::default();
|
||||
@@ -139,8 +196,7 @@ fn layer_header_fields() {
|
||||
assert!(h[2].is_motion_blur() && h[2].is_guide());
|
||||
assert_eq!(h[2].blend_mode, AepBlend::Screen);
|
||||
assert_eq!((h[2].start.num, h[2].start.den), (46_080, 30_720));
|
||||
assert_eq!(h[2].in_point_seconds(), Some(2.0));
|
||||
assert_eq!(h[2].out_point_seconds(), Some(6.0));
|
||||
assert_eq!((h[2].in_point(), h[2].out_point()), (effectcraft_aep::Rational::new(2, 1), effectcraft_aep::Rational::new(6, 1)));
|
||||
assert_eq!(h[2].name_copy, "Mid");
|
||||
// Ids are unique.
|
||||
let mut ids: Vec<u32> = h.iter().map(|x| x.id).collect();
|
||||
|
||||
@@ -426,7 +426,7 @@ fn static_records(file: &AepFile<'_>) -> std::collections::BTreeMap<(String, usi
|
||||
for (li, layer) in comp.layers().enumerate() {
|
||||
for (ei, e) in layer.effects().into_iter().enumerate() {
|
||||
let Some(spec) = effectcraft_aep::effect_map::by_match_name(e.match_name()) else { continue };
|
||||
let Some(values) = e.chunk().child_list(b"tdgp") else { continue };
|
||||
let Some(values) = e.chunk().child_list(b"tdgp").map(|v| v.to_chunk()) else { continue };
|
||||
let k = values.children();
|
||||
for (i, c) in k.iter().enumerate() {
|
||||
let Some(name) =
|
||||
|
||||
@@ -201,8 +201,9 @@ fn every_written_field_parses_back() {
|
||||
for m in [&masks[0], &masks[2], &masks[4]] {
|
||||
assert_eq!((m.feather.source, m.opacity_percent.source, m.expansion.source), (ValueSource::Default, ValueSource::Default, ValueSource::Default));
|
||||
}
|
||||
// Paths: vertices in layer pixels, open bit.
|
||||
let px = view.mask_vertices_px(&layer, &masks[2]).expect("vertices");
|
||||
// Paths: vertices in layer pixels (the box scaled by the source size, as the importer does), open bit.
|
||||
let (w, h) = view.layer_source_size(&layer).expect("size");
|
||||
let px: Vec<_> = masks[2].shapes.iter().map(|s| s.vertices((f64::from(w), f64::from(h)))).collect();
|
||||
let open = open_path();
|
||||
assert!(masks[2].shapes[0].open && !masks[0].shapes[0].open);
|
||||
for (v, (want, (ti, to))) in px[0].iter().zip(open.vertices.iter().zip(open.in_tangents.iter().zip(&open.out_tangents))) {
|
||||
|
||||
@@ -190,6 +190,20 @@ fn with_props(p: &mut Project, c: effectcraft_project::ItemId, idx: usize, set:
|
||||
});
|
||||
}
|
||||
|
||||
/// The layers of the first composition as the importer reads `bytes` back.
|
||||
fn reimported_layers(bytes: &[u8]) -> Vec<effectcraft_project::Layer> {
|
||||
let exists = |_: &str| true;
|
||||
let options = effectcraft_aep::import::ImportOptions { allow_losses: true, ..effectcraft_aep::import::ImportOptions::new(&exists) };
|
||||
let mut p = Project::default();
|
||||
let r = effectcraft_aep::import::import(&mut p, bytes, &options).expect("import");
|
||||
p.comp(r.comps[0]).expect("comp").layers.iter().cloned().collect()
|
||||
}
|
||||
|
||||
/// The value at `path` of a read-back layer.
|
||||
fn value(l: &effectcraft_project::Layer, path: &str) -> effectcraft_keyframe::Value {
|
||||
l.props.prop(path).unwrap_or_else(|| panic!("no {path}")).value.clone()
|
||||
}
|
||||
|
||||
fn first_comp_layers(bytes: &[u8], mut f: impl FnMut(&effectcraft_aep::Layer<'_, '_>)) {
|
||||
let file = parse(bytes).expect("parse");
|
||||
assert_eq!(effectcraft_aep::write(&file).expect("write"), bytes);
|
||||
@@ -229,12 +243,18 @@ fn cameras_are_written_with_position_point_of_interest_and_options() {
|
||||
assert!(h.is_three_d() && h.is_auto_oriented(), "two-node camera");
|
||||
let pos = l.camera_position().expect("position");
|
||||
assert_eq!((pos.stored, pos.auto_state), ([100.0, 200.0, -1000.0], false));
|
||||
assert_eq!(l.camera_point_of_interest(), Some([960.0, 540.0, 0.0]));
|
||||
assert_eq!(l.camera_depth_of_field().map(|t| t.value), Some(true));
|
||||
assert_eq!(l.camera_focus_distance().map(|t| t.value), Some(800.0));
|
||||
assert_eq!(l.camera_aperture().map(|t| t.value), Some(30.0));
|
||||
assert_eq!(l.camera_zoom().map(|t| t.value), Some(1500.0));
|
||||
});
|
||||
// The importer reads the written options back.
|
||||
let back = reimported_layers(&r.bytes);
|
||||
for (path, want) in [
|
||||
("transform/poi", Value::Vec3([960.0, 540.0, 0.0])),
|
||||
("cameraOptions/dof", Value::Bool(true)),
|
||||
("cameraOptions/focusDistance", Value::Scalar(800.0)),
|
||||
("cameraOptions/aperture", Value::Scalar(30.0)),
|
||||
("cameraOptions/zoom", Value::Scalar(1500.0)),
|
||||
] {
|
||||
assert_eq!(value(&back[0], path), want, "{path}");
|
||||
}
|
||||
// One-node (auto-orient off): bit 0x40 clear (251).
|
||||
with_layer(&mut p, c, 0, |l| l.auto_orient = effectcraft_project::AutoOrient::Off);
|
||||
first_comp_layers(&export_all(&p).bytes, |l| assert!(!l.header().expect("h").is_auto_oriented()));
|
||||
@@ -271,20 +291,25 @@ fn spot_and_point_lights_are_written_with_their_options() {
|
||||
seen.push(h.light_type());
|
||||
match h.light_type() {
|
||||
Some(effectcraft_aep::LightType::Spot) => {
|
||||
assert_eq!(l.light_intensity().map(|t| t.value), Some(50.0));
|
||||
assert_eq!(l.light_color().map(|t| t.value), Some([1.0, 1.0, 0.0, 0.0]));
|
||||
assert_eq!(l.light_cone_angle().map(|t| t.value), Some(60.0));
|
||||
assert_eq!(l.light_cone_feather().map(|t| t.value), Some(30.0));
|
||||
assert_eq!(l.camera_position().map(|p| p.stored), Some([100.0, 50.0, -500.0]));
|
||||
assert_eq!(l.camera_point_of_interest(), Some([960.0, 540.0, 0.0]));
|
||||
}
|
||||
Some(effectcraft_aep::LightType::Point) => {
|
||||
assert_eq!(l.light_intensity().map(|t| t.value), Some(100.0));
|
||||
}
|
||||
Some(effectcraft_aep::LightType::Point) => {}
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
});
|
||||
assert_eq!(seen.len(), 2);
|
||||
// The importer reads the written options back (layer 0 is the point light, 1 the spot).
|
||||
let back = reimported_layers(&r.bytes);
|
||||
assert_eq!(value(&back[0], "lightOptions/intensity"), Value::Scalar(100.0));
|
||||
for (path, want) in [
|
||||
("lightOptions/intensity", Value::Scalar(50.0)),
|
||||
("lightOptions/color", Value::Color([1.0, 0.0, 0.0, 1.0])),
|
||||
("lightOptions/coneAngle", Value::Scalar(60.0)),
|
||||
("lightOptions/coneFeather", Value::Scalar(30.0)),
|
||||
("transform/poi", Value::Vec3([960.0, 540.0, 0.0])),
|
||||
] {
|
||||
assert_eq!(value(&back[1], path), want, "{path}");
|
||||
}
|
||||
// Parallel and ambient lights, and unsampled options, are reported.
|
||||
let mut q = Project::default();
|
||||
let c = add_comp(&mut q, "C", 640, 360, FrameRate::new(25, 1), 1.0, None);
|
||||
@@ -468,7 +493,7 @@ fn shape_records(bytes: &[u8]) -> std::collections::BTreeMap<(usize, String), ef
|
||||
for item in view.all_items() {
|
||||
let Some(comp) = item.comp() else { continue };
|
||||
for (li, layer) in comp.layers().enumerate() {
|
||||
if let Some(g) = layer.chunk().child_list(b"tdgp") {
|
||||
if let Some(g) = layer.chunk().child_list(b"tdgp").map(|g| g.to_chunk()) {
|
||||
walk(g.children(), "", li, false, &mut out);
|
||||
}
|
||||
}
|
||||
@@ -593,7 +618,7 @@ fn keyed_shape_records(bytes: &[u8]) -> Vec<(String, Vec<u8>, Vec<u8>, Vec<u8>,
|
||||
for item in view.all_items() {
|
||||
let Some(comp) = item.comp() else { continue };
|
||||
for layer in comp.layers() {
|
||||
if let Some(g) = layer.chunk().child_list(b"tdgp") {
|
||||
if let Some(g) = layer.chunk().child_list(b"tdgp").map(|g| g.to_chunk()) {
|
||||
walk(g.children(), "", false, &mut out);
|
||||
}
|
||||
}
|
||||
@@ -828,7 +853,8 @@ fn a_camera_transform_group_ends_with_its_group_end() {
|
||||
let view = effectcraft_aep::Project::new(&file).expect("project");
|
||||
let comp = view.all_items().into_iter().find_map(|i| i.comp()).expect("comp");
|
||||
let layer = comp.layers().next().expect("camera");
|
||||
let root = layer.chunk().child_list(b"tdgp").expect("tree").children();
|
||||
let tree = layer.chunk().child_list(b"tdgp").expect("tree").to_chunk();
|
||||
let root = tree.children();
|
||||
let name =
|
||||
|c: &effectcraft_aep::Chunk<'_>| String::from_utf8_lossy(c.bytes().unwrap_or_default().split(|b| *b == 0).next().unwrap_or_default()).into_owned();
|
||||
let at = root.iter().position(|c| c.is(b"tdmn") && name(c) == "ADBE Transform Group").expect("transform");
|
||||
|
||||
@@ -47,10 +47,10 @@ fn a_precomposition_layer_points_at_its_composition() {
|
||||
let (c, pre) = (by_name("C"), by_name("Pre"));
|
||||
let pre_id = pre.id().expect("id");
|
||||
// C records the composition it uses (idpi, little-endian), idpc byte 0 is 1.
|
||||
assert_eq!(c.used_item_ids(), vec![pre_id]);
|
||||
assert_eq!(crate::common::used_item_ids(&c), vec![pre_id]);
|
||||
let idpc = c.chunk().child(b"idpc").and_then(|x| x.bytes()).expect("idpc");
|
||||
assert_eq!(idpc.first(), Some(&1));
|
||||
assert_eq!(pre.used_item_ids(), Vec::<u32>::new());
|
||||
assert_eq!(crate::common::used_item_ids(&pre), Vec::<u32>::new());
|
||||
assert_eq!(pre.chunk().child(b"idpc").and_then(|x| x.bytes()).and_then(|b| b.first().copied()), Some(0));
|
||||
let layer = c.comp().expect("comp").layers().next().expect("layer");
|
||||
let h = layer.header().expect("header");
|
||||
@@ -107,7 +107,7 @@ fn one_composition_used_twice_is_recorded_once_and_chains_nest() {
|
||||
let view = effectcraft_aep::Project::new(&file).expect("project");
|
||||
let items = view.all_items();
|
||||
let id = |n: &str| items.iter().find(|i| i.display_name().as_deref() == Some(n)).and_then(|i| i.id()).expect(n);
|
||||
let used = |n: &str| items.iter().find(|i| i.display_name().as_deref() == Some(n)).expect(n).used_item_ids();
|
||||
let used = |n: &str| items.iter().find(|i| i.display_name().as_deref() == Some(n)).map(crate::common::used_item_ids).expect(n);
|
||||
assert_eq!(used("B"), vec![id("A")]);
|
||||
// Ascending ids (601; the order carries no meaning), and idpc counts them.
|
||||
let mut ab = vec![id("A"), id("B")];
|
||||
|
||||
@@ -53,7 +53,7 @@ fn stored_group(bytes: &[u8]) -> Vec<u8> {
|
||||
{
|
||||
// As far as the exporter writes records (`decoded`).
|
||||
let mut f2 = effectcraft_aep::AepFile {
|
||||
chunks: vec![crate::export::helpers::decoded(&g.chunk().clone().into_owned())],
|
||||
chunks: vec![crate::export::helpers::decoded(&g.chunk().to_chunk().into_owned())],
|
||||
trailer: std::borrow::Cow::Owned(vec![]),
|
||||
};
|
||||
f2.trailer = std::borrow::Cow::Owned(vec![]);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
mod helpers;
|
||||
|
||||
mod aepx;
|
||||
mod ai_mask;
|
||||
mod blend_modes;
|
||||
mod cameras;
|
||||
mod cases;
|
||||
@@ -17,10 +18,12 @@ mod effects_round2;
|
||||
mod effects_round3;
|
||||
mod effects_thirdparty;
|
||||
mod fx_inject;
|
||||
mod issue_3087;
|
||||
mod lumetri;
|
||||
mod markers;
|
||||
mod masks;
|
||||
mod mattes;
|
||||
mod placeholders;
|
||||
mod puppet;
|
||||
mod resaved_defaults;
|
||||
mod robustness;
|
||||
@@ -30,5 +33,6 @@ mod styles;
|
||||
mod synthetic;
|
||||
mod text;
|
||||
mod text_anim;
|
||||
mod text_synthetic;
|
||||
mod timing;
|
||||
mod versions;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user