Merge remote-tracking branch 'upstream/main' into r4-print-shrink-147

This commit is contained in:
midasmatterhorn
2026-11-14 16:55:58 +03:00
3311 changed files with 1032565 additions and 3288 deletions
+2
View File
@@ -0,0 +1,2 @@
[lints]
cargo.unused_workspace_dependencies = "allow"
+6
View File
@@ -0,0 +1,6 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
reviews:
auto_review:
# Dependabot bumps are checked by CI; skip CodeRabbit reviews on them.
ignore_usernames:
- "dependabot[bot]"
+16
View File
@@ -0,0 +1,16 @@
# Font-build test fixtures are compared byte for byte: a checkout must not convert them.
crates/fonts-build/tests/fixture/** -text
# The pinned font index is hashed and compiled in as committed: a checkout must not convert its
# line endings, or `Index::bundled` fails its checksum on Windows.
crates/font-store/index/sources.json -text
crates/font-store/index/indexes/*.gz binary
# Copies of the vendored krilla source diff, one per patch (see vendor/krilla/README.craft.md).
vendor/krilla/patches/*.patch linguist-generated=true
# Has a pinned digest and is embedded as bytes by craft-font-store.
crates/font-store/index/sources.json -text
# The build fixture verifies these license files are copied byte-for-byte.
crates/fonts-build/tests/fixture/craft-fonts/fonts/**/OFL.txt -text
+32
View File
@@ -0,0 +1,32 @@
version: 2
updates:
# Maintain Rust / Cargo dependencies
- package-ecosystem: "cargo"
directories:
- "/"
- "/crates/pdf/read-only-contract"
schedule:
interval: "daily"
time: "06:00"
timezone: "America/New_York"
# Consolidate updates into a single PR rather than one PR per crate
groups:
cargo-dependencies:
patterns:
- "*"
commit-message:
prefix: "chore(deps)"
# Maintain GitHub Actions workflows
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
time: "06:00"
timezone: "America/New_York"
groups:
actions:
patterns:
- "*"
commit-message:
prefix: "ci(deps)"
+44
View File
@@ -0,0 +1,44 @@
name: AI model
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/ai-core/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/ai-core.yml']
pull_request:
paths: ['crates/ai-core/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/ai-core.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: ai-core-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
ai-core:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- run: cargo fmt --check
- run: cargo clippy -p craft-ai-core --all-targets --locked -- -D warnings
- run: cargo test -p craft-ai-core --locked
# The model promises to compile for the web.
- run: cargo check -p craft-ai-core --target wasm32-unknown-unknown --locked
+26 -3
View File
@@ -11,18 +11,30 @@ on:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: atomic-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
atomic:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- name: Install ACL tools
if: runner.os == 'Linux'
@@ -33,3 +45,14 @@ jobs:
- name: Check inherited Linux ACLs
if: runner.os == 'Linux'
run: cargo test -p craft-atomic --locked -- --ignored --nocapture
wasm:
name: Atomic WASM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- run: cargo check -p craft-atomic --target wasm32-unknown-unknown
+163
View File
@@ -0,0 +1,163 @@
name: Shared audio
on:
push:
branches: [main]
paths: ["crates/audio/**", "crates/media/**", "crates/media-testkit/**", "scripts/fetch-opus-vectors.sh", "Cargo.toml", "Cargo.lock", ".github/workflows/audio.yml"]
pull_request:
paths: ["crates/audio/**", "crates/media/**", "crates/media-testkit/**", "scripts/fetch-opus-vectors.sh", "Cargo.toml", "Cargo.lock", ".github/workflows/audio.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-audio-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
lint:
timeout-minutes: 15
name: Audio lint, feature sets, docs, WASM
runs-on: ubuntu-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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-audio-lint
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-audio --check
# Each feature on its own, so code that needs another feature fails here.
- name: Clippy, each feature alone
run: |
for f in "" decode decode-native symphonia encode lossless-encode pcm-encode flac-encode peaks aac-decode aac-encode "aac-encode,rayon" opus-decode opus-encode ac3-decode mpa-decode serde; do
echo "::group::features: ${f:-none}"
cargo clippy -p craft-audio --all-targets --locked --no-default-features ${f:+--features "$f"} -- -D warnings
echo "::endgroup::"
done
- run: cargo clippy -p craft-audio --all-targets --locked --all-features -- -D warnings
# missing_docs is a warning in the crate; -D warnings makes it (and broken links) fail here.
- run: cargo doc -p craft-audio --all-features --no-deps --locked
env:
RUSTDOCFLAGS: "-D warnings"
# Partial feature sets must document too (their links to other features are allowed to dangle).
- run: cargo doc -p craft-audio --no-default-features --features decode-native --no-deps --locked
env:
RUSTDOCFLAGS: "-D warnings"
- run: cargo doc -p craft-audio --no-default-features --features lossless-encode --no-deps --locked
env:
RUSTDOCFLAGS: "-D warnings"
- run: cargo check -p craft-audio --all-features --locked --target wasm32-unknown-unknown
- run: cargo check -p craft-audio --no-default-features --features lossless-encode --locked --target wasm32-unknown-unknown
msrv:
timeout-minutes: 10
name: Audio on the minimum Rust version
runs-on: ubuntu-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
# The workspace's rust-version.
- run: rustup toolchain install 1.95.0 --profile minimal
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-audio-msrv
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo +1.95.0 check -p craft-audio -p craft-media --all-features --locked
features:
timeout-minutes: 10
name: Audio tests without symphonia and lossless-encode only
runs-on: ubuntu-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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-audio-features
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo test -p craft-audio --no-default-features --features lossless-encode --locked
- run: cargo test -p craft-audio --no-default-features --features pcm-encode --locked --lib
- run: cargo test -p craft-audio --no-default-features --features flac-encode --locked --lib
- run: cargo test -p craft-audio --no-default-features --features decode-native --locked
test:
timeout-minutes: 20
name: Audio tests with ffmpeg oracles and the Opus conformance vectors
# Pinned for the ffmpeg its apt ships (8.0), so the files the oracle tests write do not change
# with the runner image.
runs-on: ubuntu-26.04
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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-audio-test
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/media-fixtures/opus/vectors
# The archive's SHA-256 (scripts/fetch-opus-vectors.sh checks it).
key: opus-testvectors-rfc8251-6b26a22f
- name: Build tests while installing ffmpeg and fetching the Opus vectors
run: |
# The man-db index rebuild after dpkg is slow on hosted runners.
sudo rm -f /var/lib/man-db/auto-update
# A mirror can stall for most of the job's time limit, and the next try usually gets a good one.
install_ffmpeg() {
for attempt in 1 2 3; do
# timeout runs as root, so a stalled apt-get is killed too and frees the dpkg lock.
sudo timeout -k 10 180 sh -c 'apt-get update -qq && apt-get install -y -qq --no-install-recommends ffmpeg' && return 0
echo "apt: attempt $attempt failed with exit code $?"
sudo timeout -k 10 60 dpkg --configure -a || true
done
return 1
}
# The vectors are fetched after ffmpeg, so the two downloads do not slow each other.
{
install_ffmpeg > "$RUNNER_TEMP/apt.log" 2>&1 || exit 1
scripts/fetch-opus-vectors.sh "$RUNNER_TEMP/media-fixtures/opus/vectors" > "$RUNNER_TEMP/vectors.log" 2>&1 || exit 2
} &
fetch=$!
cargo test -p craft-audio --all-features --locked --no-run
wait "$fetch" || case $? in
1) cat "$RUNNER_TEMP/apt.log"; exit 1 ;;
*) cat "$RUNNER_TEMP/vectors.log"; exit 1 ;;
esac
ffmpeg -hide_banner -version | sed -n 1p
- run: cargo test -p craft-audio --all-features --locked
env:
CRAFT_MEDIA_REQUIRE_ORACLES: "1"
CRAFT_MEDIA_FIXTURES_DIR: ${{ runner.temp }}/media-fixtures
+26
View File
@@ -0,0 +1,26 @@
name: Colour management
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/cms/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/cms.yml']
pull_request:
paths: ['crates/cms/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/cms.yml']
permissions:
contents: read
jobs:
cms:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- run: cargo clippy -p craft-cms --all-targets --all-features --locked -- -D warnings
# Release: the FOGRA39 fit and ink-limit tests take about 35 s in debug and 4 s here. Tests that need
# installed system profiles print "skipped:" when none are present.
- run: cargo test -p craft-cms --all-features --release --locked -- --nocapture
+101
View File
@@ -0,0 +1,101 @@
name: Shared CRW
on:
push:
branches: [main]
paths: ["crates/crw/**", "scripts/fetch-crw-samples.py", "Cargo.toml", "Cargo.lock", ".github/workflows/crw.yml"]
pull_request:
paths: ["crates/crw/**", "scripts/fetch-crw-samples.py", "Cargo.toml", "Cargo.lock", ".github/workflows/crw.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-crw-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
native:
timeout-minutes: 20
name: CRW lint and tests (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-crw-${{ matrix.os }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-crw --check
- run: cargo clippy -p craft-crw --all-targets --locked -- -D warnings
- run: cargo test -p craft-crw --locked
wasm:
timeout-minutes: 10
name: CRW WASM
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-crw-wasm
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo check -p craft-crw --locked --target wasm32-unknown-unknown
samples:
timeout-minutes: 20
name: CRW sample files decode exactly
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-crw-samples
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Cache the CC0 sample files
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/crw-samples
key: crw-samples-${{ hashFiles('crates/crw/tests/samples.json') }}
- name: Fetch the pinned CC0 sample files (raw.pixls.us)
run: python scripts/fetch-crw-samples.py "$RUNNER_TEMP/crw-samples"
- run: cargo test -p craft-crw --release --locked --test samples -- --nocapture
env:
CRAFT_CRW_SAMPLES: ${{ runner.temp }}/crw-samples
CRAFT_CRW_REQUIRE_SAMPLES: "1"
+42
View File
@@ -0,0 +1,42 @@
name: Dialogs
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/dialogs/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/dialogs.yml']
pull_request:
paths: ['crates/dialogs/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/dialogs.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: dialogs-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
dialogs:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
# The token isn't needed after checkout; cargo runs build scripts and proc macros from
# dependencies, so don't leave it in .git/config for that third-party code to read.
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: clippy
# The macOS code is linted on Linux: it compiles for the target without the SDK.
targets: aarch64-apple-darwin
- run: cargo clippy -p craft-dialogs --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-dialogs --target aarch64-apple-darwin --locked -- -D warnings
- run: cargo test -p craft-dialogs --locked
+47
View File
@@ -0,0 +1,47 @@
name: Craft documents
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/doc/**', 'crates/pcraft-format/**', 'crates/vectorcraft-format/**', 'crates/ecproj-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/doc.yml']
pull_request:
paths: ['crates/doc/**', 'crates/pcraft-format/**', 'crates/vectorcraft-format/**', 'crates/ecproj-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/doc.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: doc-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
doc:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- run: cargo fmt --check
- run: cargo clippy -p craft-doc --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-doc --all-targets --all-features --locked -- -D warnings
- run: cargo test -p craft-doc --locked -- --nocapture
- run: cargo test -p craft-doc --all-features --locked -- --nocapture
- run: cargo check -p craft-doc --all-features --locked --target wasm32-unknown-unknown
+41
View File
@@ -0,0 +1,41 @@
name: Document paths
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/docpath/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/docpath.yml']
pull_request:
paths: ['crates/docpath/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/docpath.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: docpath-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
docpath:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check
- run: cargo clippy -p craft-docpath --all-targets --locked -- -D warnings
- run: cargo test -p craft-docpath --locked -- --nocapture
+45
View File
@@ -0,0 +1,45 @@
name: EffectCraft project format
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/ecproj-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/ecproj-format.yml']
pull_request:
paths: ['crates/ecproj-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/ecproj-format.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: ecproj-format-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
ecproj-format:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- run: cargo fmt --check
- run: cargo clippy -p craft-ecproj-format --all-targets --locked -- -D warnings
- run: cargo test -p craft-ecproj-format --locked -- --nocapture
- run: cargo check -p craft-ecproj-format --locked --target wasm32-unknown-unknown
+47
View File
@@ -0,0 +1,47 @@
name: Font store
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/font-store/**', 'crates/font-catalog/**', 'crates/atomic/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/font-store.yml']
pull_request:
paths: ['crates/font-store/**', 'crates/font-catalog/**', 'crates/atomic/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/font-store.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: font-store-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
font-store:
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- run: cargo fmt --check
- run: cargo clippy -p craft-font-store --all-targets --locked -- -D warnings
- run: cargo test -p craft-font-store --locked
- run: cargo clippy -p craft-font-catalog --all-targets --locked -- -D warnings
- run: cargo test -p craft-font-catalog --locked
- name: Check the web build
if: runner.os == 'Linux'
run: cargo check -p craft-font-store --target wasm32-unknown-unknown --locked
+111
View File
@@ -0,0 +1,111 @@
name: Shared format crates
on:
push:
branches: [main]
paths:
- "crates/xml/**"
- "crates/mime/**"
- "crates/cfb/**"
- "crates/mesh/**"
- "crates/metafile/**"
- "crates/dxf/**"
- "crates/gcode/**"
- "crates/svg-paths/**"
- "crates/silhouette-studio/**"
- "crates/tiff/**"
- "crates/heif/**"
- "crates/cms/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/formats.yml"
pull_request:
paths:
- "crates/xml/**"
- "crates/mime/**"
- "crates/cfb/**"
- "crates/mesh/**"
- "crates/metafile/**"
- "crates/dxf/**"
- "crates/gcode/**"
- "crates/svg-paths/**"
- "crates/silhouette-studio/**"
- "crates/tiff/**"
- "crates/heif/**"
- "crates/cms/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/formats.yml"
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-formats-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
check:
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
# `features`: each is linted alone, so code that needs another feature fails here.
- { crate: craft-xml, features: "" }
- { crate: craft-mime, features: "" }
- { crate: craft-cfb, features: "" }
- { crate: craft-mesh, features: "stl obj ply gltf" }
- { crate: craft-metafile, features: "write" }
- { crate: craft-dxf, features: "" }
- { crate: craft-gcode, features: "" }
- { crate: craft-svg-paths, features: "" }
- { crate: craft-silhouette-studio, features: "" }
- { crate: craft-tiff, features: "" }
- { crate: craft-heif, features: "testdata" }
- { crate: craft-cms, features: "" }
name: ${{ matrix.crate }} lint, tests, WASM
runs-on: ubuntu-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
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: ${{ matrix.crate }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p "$CRATE" --check
env:
CRATE: ${{ matrix.crate }}
- name: Clippy, default features and each feature alone
env:
CRATE: ${{ matrix.crate }}
FEATURES: ${{ matrix.features }}
run: |
cargo clippy -p "$CRATE" --all-targets --locked -- -D warnings
for f in $FEATURES; do
echo "::group::feature: $f"
cargo clippy -p "$CRATE" --all-targets --locked --no-default-features --features "$f" -- -D warnings
echo "::endgroup::"
done
- run: cargo clippy -p "$CRATE" --all-targets --locked --all-features -- -D warnings
env:
CRATE: ${{ matrix.crate }}
- run: cargo test -p "$CRATE" --all-features --locked
env:
CRATE: ${{ matrix.crate }}
- run: cargo check -p "$CRATE" --all-features --locked --target wasm32-unknown-unknown
env:
CRATE: ${{ matrix.crate }}
+28
View File
@@ -0,0 +1,28 @@
name: House rules
on:
push:
branches: [main]
paths:
- AGENTS.md
- CLAUDE.md
- .github/workflows/house-rules.yml
pull_request:
paths:
- AGENTS.md
- CLAUDE.md
- .github/workflows/house-rules.yml
workflow_dispatch:
permissions:
contents: read
concurrency:
group: house-rules-${{ github.ref }}
cancel-in-progress: true
jobs:
house-rules:
uses: storytold/craft-common-actions/.github/workflows/house-rules.yml@main
with:
rust: true
+41
View File
@@ -0,0 +1,41 @@
name: Translations
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/i18n/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/i18n.yml']
pull_request:
paths: ['crates/i18n/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/i18n.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: i18n-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
i18n:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check
- run: cargo clippy -p craft-i18n --all-targets --features collate --locked -- -D warnings
- run: cargo test -p craft-i18n --features collate --locked -- --nocapture
+46
View File
@@ -0,0 +1,46 @@
name: Shared JPEG
on:
push:
branches: [main]
paths: ["crates/jpeg/**", "Cargo.toml", "Cargo.lock", ".github/workflows/jpeg.yml"]
pull_request:
paths: ["crates/jpeg/**", "Cargo.toml", "Cargo.lock", ".github/workflows/jpeg.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-jpeg-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
check:
timeout-minutes: 10
name: JPEG lint, tests, WASM
runs-on: ubuntu-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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-jpeg
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-jpeg --check
- run: cargo clippy -p craft-jpeg --all-targets --locked -- -D warnings
- run: cargo test -p craft-jpeg --locked
- run: cargo check -p craft-jpeg --locked --target wasm32-unknown-unknown
+115
View File
@@ -0,0 +1,115 @@
name: Keymap
on:
push:
branches: [main]
paths: ["crates/keymap/**", "crates/settings/**", "crates/ui/**", "crates/i18n/**", "Cargo.toml", "Cargo.lock", ".github/workflows/keymap.yml"]
pull_request:
paths: ["crates/keymap/**", "crates/settings/**", "crates/ui/**", "crates/i18n/**", "Cargo.toml", "Cargo.lock", ".github/workflows/keymap.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: keymap-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
linux:
timeout-minutes: 15
name: Keymap (Linux)
runs-on: ubuntu-latest
env:
CRAFT_FONTS_DIR: ${{ github.workspace }}/.test-inputs/craft-fonts
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Checkout test fonts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: storytold/craft-fonts
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
path: .test-inputs/craft-fonts
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-keymap-linux
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-keymap --check
- run: cargo clippy -p craft-keymap --all-targets --no-default-features --locked -- -D warnings
# `snapshot` covers `ui` and `egui` and compiles the dialog screenshots, which need a GPU
# to run, so the test steps leave them out.
- run: cargo clippy -p craft-keymap --all-targets --features snapshot --locked -- -D warnings
# Doctests run once, in the `ui` step.
- name: Test core
run: cargo test -p craft-keymap --no-default-features --lib --tests --locked
- name: Test egui dispatch and the shortcuts dialog
run: cargo test -p craft-keymap --features ui --locked
native:
timeout-minutes: 15
name: Keymap (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["macos-latest","windows-latest"]') || fromJSON('["windows-latest"]') }}
runs-on: ${{ matrix.os }}
env:
CRAFT_FONTS_DIR: ${{ github.workspace }}/.test-inputs/craft-fonts
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Checkout test fonts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: storytold/craft-fonts
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
path: .test-inputs/craft-fonts
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-keymap-${{ matrix.os }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo test -p craft-keymap --features ui --locked
wasm:
timeout-minutes: 10
name: Keymap WASM
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-keymap-wasm
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo check -p craft-keymap --features ui --locked --target wasm32-unknown-unknown
+84
View File
@@ -0,0 +1,84 @@
name: Shared media
on:
push:
branches: [main]
paths: ["crates/media/**", "crates/media-testkit/**", "Cargo.toml", "Cargo.lock", ".github/workflows/media.yml"]
pull_request:
paths: ["crates/media/**", "crates/media-testkit/**", "Cargo.toml", "Cargo.lock", ".github/workflows/media.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-media-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
lint:
timeout-minutes: 10
name: Media lint, feature sets, WASM
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-media-lint
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-media --check
- run: cargo clippy -p craft-media --all-targets --locked --no-default-features -- -D warnings
- run: cargo clippy -p craft-media --all-targets --locked --no-default-features --features bitstream -- -D warnings
- run: cargo clippy -p craft-media --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-media --all-targets --locked --no-default-features --features matroska -- -D warnings
- run: cargo clippy -p craft-media --all-targets --locked --no-default-features --features ogg -- -D warnings
- run: cargo clippy -p craft-media --all-targets --locked --all-features -- -D warnings
- run: cargo clippy -p craft-media-testkit --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-media --all-targets --locked --no-default-features --features serde -- -D warnings
- run: cargo check -p craft-media --all-features --locked --target wasm32-unknown-unknown
test:
timeout-minutes: 15
name: Media tests with ffmpeg oracles
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-media-test
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Build tests while installing ffmpeg
run: |
# The man-db index rebuild after dpkg is slow on hosted runners.
sudo rm -f /var/lib/man-db/auto-update
(sudo apt-get update -qq && sudo apt-get install -y -qq --no-install-recommends ffmpeg) > "$RUNNER_TEMP/apt.log" 2>&1 &
apt=$!
cargo test -p craft-media --all-features --locked --no-run
wait "$apt" || { cat "$RUNNER_TEMP/apt.log"; exit 1; }
ffmpeg -hide_banner -version | sed -n 1p
- run: cargo test -p craft-media --all-features --locked
env:
CRAFT_MEDIA_REQUIRE_ORACLES: "1"
CRAFT_MEDIA_FIXTURES_DIR: ${{ runner.temp }}/media-fixtures
+39
View File
@@ -0,0 +1,39 @@
name: Menu
on:
push:
branches: [main]
paths: ["crates/menu/**", "crates/keymap/**", "crates/quit/**", "Cargo.toml", "Cargo.lock", ".github/workflows/menu.yml"]
pull_request:
paths: ["crates/menu/**", "crates/keymap/**", "crates/quit/**", "Cargo.toml", "Cargo.lock", ".github/workflows/menu.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: menu-${{ github.ref }}
cancel-in-progress: true
jobs:
linux:
timeout-minutes: 15
name: Menu (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
components: rustfmt, clippy
targets: aarch64-apple-darwin, wasm32-unknown-unknown
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: craft-menu-linux
- run: cargo fmt -p craft-menu --check
- run: cargo clippy -p craft-menu --all-targets --locked -- -D warnings
# The macOS backend type-checks from Linux; it needs no linker or SDK.
- run: cargo clippy -p craft-menu --lib --locked --target aarch64-apple-darwin -- -D warnings
- run: cargo clippy -p craft-menu --lib --locked --target wasm32-unknown-unknown -- -D warnings
- run: cargo test -p craft-menu --locked
+45
View File
@@ -0,0 +1,45 @@
name: PhotoCraft format
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/pcraft-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/pcraft-format.yml']
pull_request:
paths: ['crates/pcraft-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/pcraft-format.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: pcraft-format-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
pcraft-format:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: "1.95"
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- run: cargo fmt --check
- run: cargo clippy -p craft-pcraft-format --all-targets --locked -- -D warnings
- run: cargo test -p craft-pcraft-format --locked -- --nocapture
- run: cargo check -p craft-pcraft-format --locked --target wasm32-unknown-unknown
+77 -18
View File
@@ -3,17 +3,20 @@ name: Shared PDF
on:
push:
branches: [main]
paths: ["crates/pdf/**", "vendor/hayro*/**", "vendor/krilla/**", "scripts/test-pdf-backends.sh", "scripts/*fetch-pdf-test-fonts.py", "Cargo.toml", "Cargo.lock", ".github/workflows/pdf.yml"]
paths: ["crates/pdf/**", "crates/plate-test/**", "crates/prepress/**", "crates/cms/**", "vendor/hayro*/**", "vendor/krilla/**", "vendor/linesweeper/**","scripts/test-pdf-backends.sh", "scripts/*fetch-pdf-test-fonts.py", "Cargo.toml", "Cargo.lock", ".github/workflows/pdf.yml"]
pull_request:
paths: ["crates/pdf/**", "vendor/hayro*/**", "vendor/krilla/**", "scripts/test-pdf-backends.sh", "scripts/*fetch-pdf-test-fonts.py", "Cargo.toml", "Cargo.lock", ".github/workflows/pdf.yml"]
paths: ["crates/pdf/**", "crates/plate-test/**", "crates/prepress/**", "crates/cms/**", "vendor/hayro*/**", "vendor/krilla/**", "vendor/linesweeper/**","scripts/test-pdf-backends.sh", "scripts/*fetch-pdf-test-fonts.py", "Cargo.toml", "Cargo.lock", ".github/workflows/pdf.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: shared-pdf-${{ github.ref }}
cancel-in-progress: true
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-pdf-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
native:
@@ -21,19 +24,26 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
env:
RUSTFLAGS: --cfg craft_pdf_unicode_fixtures
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-pdf
- uses: actions/setup-python@v5
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Provision licensed PDF test fonts
@@ -50,11 +60,18 @@ jobs:
name: PDF vendored contracts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-pdf-backends
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: bash scripts/test-pdf-backends.sh
wasm:
name: PDF WASM runtime
@@ -63,14 +80,20 @@ jobs:
RUSTFLAGS: --cfg craft_pdf_unicode_fixtures
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-pdf-wasm
- uses: actions/setup-python@v5
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Provision licensed PDF test fonts
@@ -79,10 +102,46 @@ jobs:
python scripts/test-fetch-pdf-test-fonts.py
python scripts/fetch-pdf-test-fonts.py "$RUNNER_TEMP/craft-pdf-test-fonts"
echo "CRAFT_PDF_TEST_FONT_DIR=$RUNNER_TEMP/craft-pdf-test-fonts" >> "$GITHUB_ENV"
- name: Install the matching WASM test runner
- name: Read the wasm-bindgen version from Cargo.lock
id: wasm-bindgen
shell: bash
run: |
runner_version=$(python3 -c 'import tomllib; d=tomllib.load(open("Cargo.lock", "rb")); print(next(p["version"] for p in d["package"] if p["name"] == "wasm-bindgen"))')
cargo install wasm-bindgen-cli --version "$runner_version" --locked
echo "version=$runner_version" >> "$GITHUB_OUTPUT"
- name: Install the matching WASM test runner
# A prebuilt, checksum-verified binary instead of building it from source on every run.
# A version the pinned action does not list yet falls back to `cargo install --locked`.
uses: step-security/taiki-e-install-action@76747d22a7567cc4438546a84f11bdf18e670ab8 # v2.87.32
with:
tool: wasm-bindgen@${{ steps.wasm-bindgen.outputs.version }}
fallback: cargo-install
- run: cargo test -p craft-pdf --all-features --locked --target wasm32-unknown-unknown
- run: cargo test --manifest-path crates/pdf/read-only-contract/Cargo.toml --locked --target wasm32-unknown-unknown
plate-test:
name: Plate tests and craft-prepress
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: clippy
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-plate-test
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Provision licensed PDF test fonts
shell: bash
run: |
python scripts/test-fetch-pdf-test-fonts.py
python scripts/fetch-pdf-test-fonts.py "$RUNNER_TEMP/craft-pdf-test-fonts"
echo "CRAFT_PDF_TEST_FONT_DIR=$RUNNER_TEMP/craft-pdf-test-fonts" >> "$GITHUB_ENV"
- run: cargo clippy -p craft-plate-test -p craft-prepress --all-targets --all-features --locked -- -D warnings
- run: cargo test -p craft-plate-test -p craft-prepress --all-features --locked
+14 -3
View File
@@ -8,18 +8,29 @@ on:
paths: ['crates/print/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/print.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: print-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
print:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check
- run: cargo clippy -p craft-print --all-targets -- -D warnings
+77
View File
@@ -0,0 +1,77 @@
name: Proofing
on:
push:
branches: [main]
paths: ["crates/proof/**", "Cargo.toml", "Cargo.lock", ".github/workflows/proof.yml"]
pull_request:
paths: ["crates/proof/**", "Cargo.toml", "Cargo.lock", ".github/workflows/proof.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: craft-proof-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
check:
timeout-minutes: 20
name: Proofing lint, tests with and without Language data, WASM
runs-on: ubuntu-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
# The Language data (craft-i18n `language-data/`), embedded by crates/proof/build.rs.
# Pinned to storytold/craft-i18n#114's head (#109's SCOWL dictionaries + judgment/judgement,
# CP2.1); TODO(CP2.1): move to #114's merge commit once it merges.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: storytold/craft-i18n
ref: c239f934ace90b7939afaceb23b472ceeafd6b8a
path: craft-i18n
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-proof
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-proof --check
- name: Without Language data (a fork, docs.rs, offline)
run: |
cargo clippy -p craft-proof --all-targets --locked -- -D warnings
cargo test -p craft-proof --locked
cargo check -p craft-proof --locked --target wasm32-unknown-unknown
- name: A release without Language data fails
run: |
if CRAFT_I18N_REQUIRED=1 cargo check -p craft-proof --locked 2>build.log; then
echo "::error::CRAFT_I18N_REQUIRED=1 without CRAFT_I18N_DIR built"; exit 1
fi
grep -q "CRAFT_I18N_REQUIRED=1 but CRAFT_I18N_DIR is unset" build.log
- name: With Language data
env:
CRAFT_I18N_DIR: ${{ github.workspace }}/craft-i18n
CRAFT_I18N_REQUIRED: "1"
run: |
cargo clippy -p craft-proof --all-targets --locked -- -D warnings
cargo test -p craft-proof --locked
cargo check -p craft-proof --locked --target wasm32-unknown-unknown
- name: The English-only build (CRAFT_PROOF_EMBED=en, CP4.4's default once Language packs ship)
env:
CRAFT_I18N_DIR: ${{ github.workspace }}/craft-i18n
CRAFT_I18N_REQUIRED: "1"
CRAFT_PROOF_EMBED: en
run: cargo test -p craft-proof --locked
+27
View File
@@ -0,0 +1,27 @@
name: SonarCloud
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
concurrency:
group: sonarcloud-${{ github.ref }}
# A push to main is the run that publishes coverage; superseded runs there would never finish.
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
sonarcloud:
# Track shared CI improvements on main.
uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main
with:
pdf-test-fonts: true
# The codec and format code behind features that are off by default. Without these the
# coverage build never compiles it, and new code there reads as untested.
cargo-features: >-
craft-video/dnx,craft-video/vp8,craft-video/prores,craft-video/h264,craft-video/hevc,craft-video/vp9,craft-video/av1,craft-video/threads,craft-audio/decode,craft-audio/encode,craft-audio/peaks,craft-audio/rayon,craft-audio/serde,craft-media/matroska,craft-media/ogg,craft-media/bitstream,craft-media/serde,craft-mesh/stl,craft-mesh/obj,craft-mesh/ply,craft-mesh/gltf,craft-metafile/write
secrets: inherit
+27 -11
View File
@@ -3,17 +3,20 @@ name: Shared UI
on:
push:
branches: [main]
paths: ["crates/ui/**", "Cargo.toml", "Cargo.lock", ".github/workflows/ui.yml"]
paths: ["crates/ui/**", "crates/i18n/**", "Cargo.toml", "Cargo.lock", ".github/workflows/ui.yml"]
pull_request:
paths: ["crates/ui/**", "Cargo.toml", "Cargo.lock", ".github/workflows/ui.yml"]
paths: ["crates/ui/**", "crates/i18n/**", "Cargo.toml", "Cargo.lock", ".github/workflows/ui.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: shared-ui-${{ github.ref }}
cancel-in-progress: true
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-ui-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
native:
@@ -22,22 +25,29 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- name: Install software Vulkan renderer
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y mesa-vulkan-drivers libvulkan1
echo 'WGPU_BACKEND=vulkan' >> "$GITHUB_ENV"
- uses: dtolnay/rust-toolchain@stable
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-ui
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt --check
- run: cargo clippy -p craft-ui --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-ui --all-targets --all-features --locked -- -D warnings
@@ -48,11 +58,17 @@ jobs:
name: UI WASM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-ui-wasm
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo check -p craft-ui --all-features --locked --target wasm32-unknown-unknown
+48
View File
@@ -0,0 +1,48 @@
name: App updates
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/update/**', 'Cargo.toml', 'Cargo.lock', 'rustfmt.toml', 'clippy.toml', '.github/workflows/update.yml']
pull_request:
paths: ['crates/update/**', 'Cargo.toml', 'Cargo.lock', 'rustfmt.toml', 'clippy.toml', '.github/workflows/update.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: update-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
update:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
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:
# The token isn't needed after checkout; cargo runs build scripts and proc macros from
# dependencies, so don't leave it in .git/config for that third-party code to read.
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check
# Default (no egui) and the egui feature both build and lint cleanly.
- run: cargo clippy -p craft-update --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-update --all-targets --locked --features egui -- -D warnings
- run: cargo test -p craft-update --locked -- --nocapture
- run: cargo test -p craft-update --locked --features egui -- --nocapture
+45
View File
@@ -0,0 +1,45 @@
name: VectorCraft format
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/vectorcraft-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/vectorcraft-format.yml']
pull_request:
paths: ['crates/vectorcraft-format/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/vectorcraft-format.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: vectorcraft-format-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
vectorcraft-format:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: "1.95"
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- run: cargo fmt --check
- run: cargo clippy -p craft-vectorcraft-format --all-targets --locked -- -D warnings
- run: cargo test -p craft-vectorcraft-format --locked -- --nocapture
- run: cargo check -p craft-vectorcraft-format --locked --target wasm32-unknown-unknown
+80
View File
@@ -0,0 +1,80 @@
name: Shared video
on:
push:
branches: [main]
paths: ["crates/video/**", "crates/media/**", "crates/media-testkit/**", "Cargo.toml", "Cargo.lock", ".github/workflows/video.yml"]
pull_request:
paths: ["crates/video/**", "crates/media/**", "crates/media-testkit/**", "Cargo.toml", "Cargo.lock", ".github/workflows/video.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: shared-video-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
timeout-minutes: 20
name: Video lint, feature sets, docs, WASM
runs-on: ubuntu-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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: "1.95"
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-video-lint
- run: cargo fmt -p craft-video --check
# Each feature on its own, so code that needs another feature fails here.
- name: Clippy, each feature alone
run: |
for f in "" dnx vp8 prores h264 hevc vp9 vp9-decode vp9-encode av1 threads; do
echo "::group::features: ${f:-none}"
cargo clippy -p craft-video --all-targets --locked --no-default-features ${f:+--features "$f"} -- -D warnings
echo "::endgroup::"
done
- run: cargo clippy -p craft-video --all-targets --locked --all-features -- -D warnings
- run: cargo doc -p craft-video --all-features --no-deps --locked
env:
RUSTDOCFLAGS: "-D warnings"
- run: cargo check -p craft-video --all-features --locked --target wasm32-unknown-unknown
test:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: Video tests (${{ matrix.os }})
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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: "1.95"
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-video-${{ matrix.os }}
- name: Install ffmpeg (Linux)
if: runner.os == 'Linux'
run: |
sudo rm -f /var/lib/man-db/auto-update
sudo apt-get update -qq && sudo apt-get install -y -qq --no-install-recommends ffmpeg
- run: cargo test -p craft-video --all-features --locked
+57
View File
@@ -0,0 +1,57 @@
name: Web API (page command API)
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/web-api/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/web-api.yml']
pull_request:
paths: ['crates/web-api/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/web-api.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: web-api-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
web-api:
# One OS: the crate is platform-independent JSON handling plus wasm32; no platform code.
timeout-minutes: 30
runs-on: ubuntu-latest
env:
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- name: Read the wasm-bindgen version from Cargo.lock
id: wasm-bindgen
shell: bash
run: |
runner_version=$(python3 -c 'import tomllib; d=tomllib.load(open("Cargo.lock", "rb")); print(next(p["version"] for p in d["package"] if p["name"] == "wasm-bindgen"))')
echo "version=$runner_version" >> "$GITHUB_OUTPUT"
- name: Install the matching WASM test runner
# A prebuilt, checksum-verified binary instead of building it from source on every run.
# A version the pinned action does not list yet falls back to `cargo install --locked`.
uses: step-security/taiki-e-install-action@76747d22a7567cc4438546a84f11bdf18e670ab8 # v2.87.32
with:
tool: wasm-bindgen@${{ steps.wasm-bindgen.outputs.version }}
fallback: cargo-install
- run: cargo fmt --check
- run: cargo clippy -p craft-web-api --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-web-api --all-targets --locked --target wasm32-unknown-unknown -- -D warnings
- run: cargo test -p craft-web-api --locked
- run: cargo test -p craft-web-api --locked --target wasm32-unknown-unknown
+62
View File
@@ -0,0 +1,62 @@
name: Shared web host
on:
push:
branches: [main]
paths: ["crates/web-host/**", "Cargo.toml", "Cargo.lock", ".github/workflows/web-host.yml"]
pull_request:
paths: ["crates/web-host/**", "Cargo.toml", "Cargo.lock", ".github/workflows/web-host.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
# always gets to save the cache.
group: shared-web-host-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
check:
timeout-minutes: 20
name: Web host lint, tests, WASM tests
runs-on: ubuntu-latest
env:
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
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
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: step-security/rust-cache@8871c8ba063416da7c32246932ea6ae08700453e # v2.9.2
with:
key: craft-web-host
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo fmt -p craft-web-host --check
- run: cargo clippy -p craft-web-host --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-web-host --all-targets --locked --target wasm32-unknown-unknown -- -D warnings
- run: cargo test -p craft-web-host --locked
- name: Read the wasm-bindgen version from Cargo.lock
id: wasm-bindgen
shell: bash
run: |
runner_version=$(grep -A1 '^name = "wasm-bindgen"$' Cargo.lock | sed -n 's/^version = "\(.*\)"$/\1/p')
echo "version=$runner_version" >> "$GITHUB_OUTPUT"
- name: Install the matching WASM test runner
# A prebuilt, checksum-verified binary instead of building it from source on every run.
# A version the pinned action does not list yet falls back to `cargo install --locked`.
uses: step-security/taiki-e-install-action@76747d22a7567cc4438546a84f11bdf18e670ab8 # v2.87.32
with:
tool: wasm-bindgen@${{ steps.wasm-bindgen.outputs.version }}
fallback: cargo-install
- run: cargo test -p craft-web-host --locked --target wasm32-unknown-unknown
+50
View File
@@ -0,0 +1,50 @@
name: Window decorations
on:
workflow_dispatch:
push:
branches: [main]
paths: ['crates/window/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/window.yml']
pull_request:
paths: ['crates/window/**', 'Cargo.toml', 'Cargo.lock', '.github/workflows/window.yml']
permissions:
contents: read
concurrency:
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
# run (main, manual) gets a group of its own, so it is neither cancelled nor replaced while queued.
group: window-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
window:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# macOS runners are kept for releases: macOS runs only when started by hand.
os: ${{ github.event_name == 'workflow_dispatch' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7
with:
# The token isn't needed after checkout; cargo runs build scripts and proc macros from
# dependencies, so don't leave it in .git/config for that third-party code to read.
persist-credentials: false
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check
# Default (no egui) and the egui feature both build and lint cleanly.
- run: cargo clippy -p craft-window --all-targets --locked -- -D warnings
- run: cargo clippy -p craft-window --all-targets --locked --features egui -- -D warnings
- run: cargo test -p craft-window --locked -- --nocapture
- run: cargo test -p craft-window --locked --features egui -- --nocapture
- run: cargo clippy -p craft-window --all-targets --locked --features restore -- -D warnings
- run: cargo test -p craft-window --locked --features restore,egui -- --nocapture
+79
View File
@@ -0,0 +1,79 @@
name: Workspace
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
native:
name: Workspace
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
with:
os: '["ubuntu-latest","windows-latest","macos-latest"]'
timeout-minutes: 120
tools: ""
packages: mesa-vulkan-drivers libvulkan1
craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
linux-env: WGPU_BACKEND=vulkan
windows-env: CRAFT_PRINT_REQUIRE_QUEUE=1
env: CRAFT_PRINT_REQUIRE_QUEUE=0
setup-command: |
set -euo pipefail
corpus_fetcher=.test-inputs/photocraft
mkdir -p "$corpus_fetcher"
git -C "$corpus_fetcher" init
git -C "$corpus_fetcher" remote add origin https://github.com/storytold/PhotoCraft.git
git -C "$corpus_fetcher" fetch --quiet --depth=1 origin 74330157cb601573ae4523a95bb9132822fc3918
git -C "$corpus_fetcher" checkout --quiet --detach FETCH_HEAD
(cd "$corpus_fetcher" && cargo xtask corpus --psd --psd-tools --atn --exr --heif --pngsuite)
mkdir -p corpus
cp -a "$corpus_fetcher/corpus/." corpus/
python scripts/test-fetch-pdf-test-fonts.py
python scripts/fetch-pdf-test-fonts.py "$RUNNER_TEMP/craft-pdf-test-fonts"
printf 'CRAFT_PSD_CORPUS=%s\n' "$GITHUB_WORKSPACE/$corpus_fetcher/corpus" >> "$GITHUB_ENV"
printf 'CRAFT_PDF_TEST_FONT_DIR=%s\n' "$RUNNER_TEMP/craft-pdf-test-fonts" >> "$GITHUB_ENV"
command: |
cargo fmt --check
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
cargo test --workspace --locked
cargo test --workspace --all-features --locked
windows-command: |
powershell.exe -NoProfile -Command '$ErrorActionPreference = "Stop"; Start-Service Spooler; Add-PrinterDriver -Name "Generic / Text Only"'
cargo fmt --check
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
cargo test --workspace --locked
cargo test --workspace --all-features --locked
msrv:
name: Rust 1.95
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
with:
os: '["ubuntu-latest"]'
toolchain: 1.95.0
targets: ""
tools: ""
craft-fonts-ref: ""
require-craft-fonts: false
timeout-minutes: 15
dev-debug: ""
command: cargo check --workspace --lib --all-features --locked
wasm:
name: UI and settings WASM
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
with:
os: '["ubuntu-latest"]'
targets: wasm32-unknown-unknown
tools: ""
craft-fonts-ref: ""
require-craft-fonts: false
timeout-minutes: 15
command: cargo check -p craft-ui -p craft-settings --all-features --locked --target wasm32-unknown-unknown
+4
View File
@@ -2,6 +2,10 @@
plan/
plans/
/target
# Also a sub-crate's own build directory: `crates/pdf/read-only-contract/target/` is not covered
# by the anchored `/target` above, and 803 of its files reached a commit once (#185 review).
target/
.DS_Store
/.claude/
.idea/
/vendor/*/target
+56 -7
View File
@@ -1,14 +1,63 @@
<!-- craft-house-rules:start core source=dde09ea31e2e457f5b4653a6e76f7cdf55944bdf sha256=540e6cea75d12d0710c3dca89658328e81e508ecef102446ca5bb95b7c0b92bb -->
## House rules
These apply in every Craft repository. A later rule may be stricter, not weaker. The source is `standards/house-rules-core.md` in `storytold/craft-contrib`. Propose changes there, not in a copy.
1. **A person is accountable.** Whoever runs an agent answers for what it opens and for its review comments.
2. **Check, then claim.** Before writing code, read the issue comments, search pull requests for `#N` and the keywords, and check recent commits on `main`. Comment on the issue first. Release a claim you will not finish.
3. **Verify, don't guess.** Open a definition before using it. Confirm the cause in the code, even when someone names a location.
4. **Keep fixes narrow and tested.** Fix what the issue describes, where the bug is. Add a test that fails without the fix.
5. **Review the diff before opening a pull request.** Identifiers exist as used, the test fails without the fix, nothing unrelated changed, and the description is true.
6. **Look for a better pull request.** If another fixes the same thing, close yours when it is better or equal, and say why.
7. **Report only what ran.** Say what you tested and what you could not run. Without a local build or test, say so and rely on CI before marking ready.
8. **`main` changes through a pull request.** Do not push to it. Branch protection enforces this. There is no exception.
9. **Stop and ask only about** licensing outside the allowlist, publishing, releases, a new remote, secrets, spending money, destructive git, and anything else hard to undo. Otherwise keep working. `plan/` is a gitignored notebook, not rules. Without it, do not ask for it and do not stop.
10. **Keep secrets and personal details out** of the repository, logs and requests.
11. **CI stays shared.** Workflows call `storytold/craft-common-actions`. Do not change CI in a feature or fix pull request. If CI cannot cover a change, open an issue there.
12. **Guards say why.** A check that looks removable says what it prevents. Read that before changing it.
13. **Instructions must be readable by everyone.** No notes about one machine, and no links to files a reader cannot open. `craftrules` is retired. Do not link to it.
14. **Keep pull requests moving.** Concurrent pull requests are fine; unanswered actionable feedback is not. Respond in 7 days, a reminder at 14, closure eligible at 30, from when an actionable request waits on the author. Suggestions and unconfirmed bot findings do not start the clock. A fix, explanation or agreed plan resets it; unrelated activity does not. Waiting on a reviewer or maintainer pauses it and does not count against the author. A maintainer decides closure; it is never automatic. Reuse search results, do not poll, and stop at a rate limit.
15. **No agent attribution.** A pull request does not say an agent wrote it. A repository rule may not require that.
<!-- craft-house-rules:end -->
<!-- craft-house-rules:start rust source=dde09ea31e2e457f5b4653a6e76f7cdf55944bdf sha256=387e0ccb4b49e567f60951d7d6fff7305054c89f43ad812b9993dc7c38528013 -->
## Rust Craft repositories
These apply to native Craft apps and to shared Rust libraries. Select them by repository type. A repository that merely contains some Rust does not take this block. Rules later in a repository's file may be stricter, but not weaker. The source is `standards/house-rules-rust.md` in [storytold/craft-contrib](https://github.com/storytold/craft-contrib).
1. **Never crash.** Non-test code does not panic and has no `unsafe`, except where the repository file names an exception. Return errors, treat input as hostile, and bound recursion and allocations. New production crate roots copy the `deny` attribute from an existing crate: `clippy::unwrap_used`, `clippy::expect_used`, `clippy::panic`, `clippy::unimplemented`, `clippy::todo`, `clippy::unreachable`. Every crash fix comes with a test that panicked before the fix.
2. **Clean room.** Learn from observed behaviour and public specifications. Do not copy another product's code, assets, strings or artwork. Check a dependency's licence before adding it.
3. **Assets and fonts.** Every asset is original or suitably licensed, and is recorded in `ATTRIBUTION.md` in the same change. Font files live in [storytold/craft-fonts](https://github.com/storytold/craft-fonts), not in the app repository.
4. **Rust only for native Craft apps.** No handwritten JavaScript or TypeScript, and no Tauri, Electron or webview shell, in those apps. Shared tooling follows its documented technical scope and maintainer-approved exceptions. Craft PR Review's existing Tauri and TypeScript UI is one such exception. It does not relax this rule for native apps. Preserve any existing web build.
5. **Time goes through `chrono`.** Do not hand-roll calendar conversion. For dates beyond what `chrono` can represent, follow [standards/time.md](https://github.com/storytold/craft-contrib/blob/main/standards/time.md).
6. **Contributor credits.** Add or edit only your own person's entry in `contributors/people.toml`, and only after asking them. Never guess a name or hand-edit `contributors.json`.
## Licence allowlist
Dependencies and assets use SPDX identifiers. An expression is allowed when every identifier is in this list. A repository may name a shorter list. It may not add an identifier here by editing its own copy of these rules.
- `ISC`
- `MIT`
- `BSD-2-Clause`
- `BSD-3-Clause`
- `Apache-2.0`
- `OFL-1.1`
- `Ubuntu-font-1.0`
- `Bitstream-Vera`
- `CC0-1.0`
- `CC-BY-4.0`
- `CC-BY-SA-4.0`
- `LicenseRef-Public-Domain`
`LicenseRef-Storyteller-Trademark` is not in this list. It covers Storyteller brand marks only, where a repository already says so.
<!-- craft-house-rules:end -->
# AGENTS.md
Shared Rust libraries for the Craft Apps. The shared standards live in
[craftrules](https://github.com/storytold/craftrules) (`../../craftrules` on a dev machine): read its
`AGENTS.md`, then `standards/never-crash.md`, `standards/engineering.md` and `standards/licensing.md`.
Shared Rust libraries for the Craft Apps.
- **Never crash.** Every crate's `lib.rs` starts with
`#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]`.
No `unsafe` (the workspace forbids it).
- **New crates** go in `crates/<name>`, named `craft-<name>`, inherit the workspace package fields
and lints, and are listed in `[workspace.dependencies]`.
and lints, and are listed in `[workspace.dependencies]`. A new crate's `Cargo.toml` includes
`[lints] workspace = true`.
- **No app code.** A crate here must be useful to more than one app and must not depend on any app.
- **Before merging:** `cargo fmt --check`, `cargo clippy --workspace --all-targets -- -D warnings`,
`cargo test --workspace`.
+42 -5
View File
@@ -6,9 +6,32 @@ author, source and license. Library code and original assets are under the repos
| File | Author | Source | License |
|---|---|---|---|
| `licenses/dwg/acadrust-MPL-2.0.txt`, `licenses/dwg/acadrust-THIRD_PARTY_NOTICES.md` | `acadrust` contributors; ACadSharp authors for the noted ported routines | [acadrust 0.6.6](https://github.com/hakanaktt/acadrust), used unmodified as `craft-dwg`'s optional native dependency | MPL-2.0; embedded ACadSharp notice is MIT; see both retained files |
| `crates/cms/profiles/photocraft-coated-cmyk.icc` | PhotoCraft contributors; generated by `craft_cms::synth::coated_cmyk` | [PhotoCraft `crates/cms`](https://github.com/storytold/photocraft/tree/b3222ee8e7e6bcb4799c37f904c595f20f9baf5e/crates/cms) | CC0-1.0 |
| `crates/cms/profiles/craft-coated-fogra39.icc` | craft-libs contributors; generated by `crates/cms/tests/fogra39.rs` from the FOGRA39 data below | this repository | CC0-1.0 |
| `crates/font-store/index/sources.json` (unmodified) | craft-font-index contributors | [aiongg/craft-font-index@5a9a7f8](https://github.com/aiongg/craft-font-index/tree/5a9a7f8038c8f3e2e1583a79c92a816e8e71b34f) | Apache-2.0 |
| `crates/font-store/index/indexes/google-fonts.json.gz` (unmodified) | craft-font-index contributors; generated from the METADATA.pb files of [google/fonts](https://github.com/google/fonts) at `45e3d5269e4a17d823f6d84470bc084dc5ae46f6` | [aiongg/craft-font-index@5a9a7f8](https://github.com/aiongg/craft-font-index/tree/5a9a7f8038c8f3e2e1583a79c92a816e8e71b34f) | Apache-2.0 |
| `crates/font-store/index/indexes/noto.json.gz` (unmodified) | craft-font-index contributors; generated from [notofonts/notofonts.github.io](https://github.com/notofonts/notofonts.github.io) at `93fac8abebe6c7fed0c5b7d2456d8fa484fa146c` and [noto-cjk](https://github.com/notofonts/noto-cjk) releases | [aiongg/craft-font-index@5a9a7f8](https://github.com/aiongg/craft-font-index/tree/5a9a7f8038c8f3e2e1583a79c92a816e8e71b34f) | Apache-2.0 |
| `crates/cms/tests/data/FOGRA39.txt` (unmodified) | Fogra | [Fogra characterisation data](https://fogra.org/en/downloads/work-tools/characterisation-data), `FOGRA39_to_FOGRA60_v2.zip` | Fogra terms: free use and redistribution, unmodified, with Fogra identified as the source; "FOGRA39" identifies the reference data only and implies no certification, approval or endorsement by Fogra (full text in [NOTICE](NOTICE)) |
| `vendor/linesweeper/tests/regression/`, `vendor/linesweeper/proptest-regressions/`, the `.snap` files under `vendor/linesweeper/src/` and the path data in `vendor/linesweeper/benches/painted_dreams.rs` (all unmodified; hashes in `vendor/linesweeper/SOURCE.json`) | As published in the package, whose manifest names Joe Neeman as author and records no other source | [linesweeper 0.5.0](https://crates.io/crates/linesweeper/0.5.0) | MIT OR Apache-2.0 (the package's `license` field) |
| `crates/i18n/data/collation.postcard` | Unicode, Inc. (ICU 78.1 collation data, CLDR 48.2.1); generated by `crates/i18n/data/generate-collation.sh` | [ICU](https://github.com/unicode-org/icu/releases/tag/release-78.1rc) | Unicode-3.0 |
| `crates/text/assets/hyphen/en-us.dic` | Grady Ward (Moby Hyphenator II), converted by DesignCraft | [Project Gutenberg eBook #3204](https://www.gutenberg.org/ebooks/3204) | Public domain |
| `crates/proof/data/en-words.dic` | Grady Ward (Moby Hyphenator II word list); break points dropped by craft-proof contributors with `crates/proof/examples/en_words.rs` | [Project Gutenberg eBook #3204](https://www.gutenberg.org/ebooks/3204), via craft-i18n `language-data/en-us/en-us.dic` | Public domain |
| `crates/proof/data/en-extra.txt` | WordCraft contributors (original list, no other dictionary copied) | craft-i18n `language-data/en-us/en-extra.txt` | MIT OR Apache-2.0 |
| `crates/text/assets/hyphen/en-us.pat` | DesignCraft contributors, trained from the Moby Hyphenator II list | `crates/text/examples/hyphgen.rs` | CC0-1.0 |
| Patterns embedded through `hypher` (optional `craft-text` language features) | hyph-utf8 authors, per language | [tex-hyphen](https://github.com/hyphenation/tex-hyphen), as packaged in [hypher](https://github.com/typst/hypher/tree/main/patterns) | Per file header: LPPL, MIT, BSD-3-Clause, Unlicense or a permit-any-use notice (or a choice including one); Slovak (`hyph-sk.tex`, embedded whenever `hypher/slovak` is on: feature `slovak-gpl`, or another dependency through feature unification) is GPL-2.0-or-later; Spanish (`hyph-es.tex` 5.0, Javier Bezos, CervanTeX) is MIT |
| Word-break dictionaries and LSTM models embedded through `icu_segmenter_data` (optional `craft-text` features `thai`, `lao`, `khmer`, `burmese`) | Unicode, Inc. and ICU4X contributors | [ICU4X](https://github.com/unicode-org/icu4x) | Unicode-3.0 |
| `crates/ui/tests/fonts/NotoSansArabic-test.ttf` (subset to the test strings, default weight set to 100, width axis dropped) | The Noto Project Authors | [google/fonts@7085eb8 `ofl/notosansarabic`](https://github.com/google/fonts/tree/7085eb89a950e85db5b166b7a58d414544b4140c/ofl/notosansarabic), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansArabic.txt`) |
| `crates/ui/tests/fonts/NotoSansCJKsc-test.otf` (subset to the test strings) | The Noto Project Authors (Adobe, Google) | [notofonts/noto-cjk@f8d1575 `Sans/OTF/SimplifiedChinese`](https://github.com/notofonts/noto-cjk/tree/f8d157532fbfaeda587e826d4cd5b21a49186f7c/Sans/OTF/SimplifiedChinese), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansCJK.txt`) |
| `crates/ui/tests/fonts/NotoSansArabic-screens.ttf` (instance at weight 400 and width 100, subset to the screen test strings) | The Noto Project Authors | [google/fonts@7085eb8 `ofl/notosansarabic`](https://github.com/google/fonts/tree/7085eb89a950e85db5b166b7a58d414544b4140c/ofl/notosansarabic), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansArabic.txt`) |
| `crates/ui/tests/fonts/NotoSansCJKsc-screens.otf` (subset to printable ASCII and the screen test strings) | The Noto Project Authors (Adobe, Google) | [notofonts/noto-cjk@f8d1575 `Sans/OTF/SimplifiedChinese`](https://github.com/notofonts/noto-cjk/tree/f8d157532fbfaeda587e826d4cd5b21a49186f7c/Sans/OTF/SimplifiedChinese), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansCJK.txt`) |
| `crates/ui/tests/fonts/NotoSansThai-screens.ttf` (instance at weight 400 and width 100, subset to the screen test strings) | The Noto Project Authors | [google/fonts@8b0a1d0 `ofl/notosansthai`](https://github.com/google/fonts/tree/8b0a1d0f5983c89bc2b93f1b5fb55f9e252744b5/ofl/notosansthai), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansThai.txt`) |
| `crates/crw/tests/samples.json` (manifest only; the 11 raw files are not bundled, `scripts/fetch-crw-samples.py` downloads them outside the checkout) | The photographers who contributed each file to raw.pixls.us (Canon EOS D30, D60, 10D ×3, 300D ×2, Digital Rebel, PowerShot G1, G5, G6) | [raw.pixls.us](https://raw.pixls.us/), each file's `getfile.php` URL and SHA-256 in the manifest | CC0-1.0 (as published by raw.pixls.us for each file) |
| `crates/crw/src/tables.rs`, `crates/crw/clean-room/logs/table_sel*.json` | craft-crw contributors (derived in LightCraft, 2026-10, by known-plaintext alignment of the sample files' entropy streams; `crates/crw/clean-room/02-crw-format.md`) | this repository | MIT OR Apache-2.0 |
| `crates/crw/clean-room/logs/private-corpus.tsv` (file names, sizes and SHA-256 of the maintainer's own EOS D60 files; no image content) | craft-crw contributors (LightCraft derivation record) | this repository | MIT OR Apache-2.0 |
| `crates/prc/src/acof/table.rs` (the rows of the PRC `Double` prefix-code table, reformatted as Rust tuples) | Kristof Ralovich (prc-rs); the table is defined by ISO 14739-1 | [ralovich/prc-rs@287b671](https://github.com/ralovich/prc-rs/blob/287b671bb5b31b05efb5ec1b98f7c359b9e4dd7d/src/double.rs), through [PdfCraft `crates/prc`](https://github.com/storytold/pdfcraft/tree/80e26e674d1aa33078e83c8139875047f3289eb6/crates/prc) | MIT (`licenses/prc-rs/LICENSE.txt`; the notice is also in the file header) |
| `crates/math/tests/corpus/equations.tsv`, `crates/math/tests/corpus/latex.tsv` (unmodified) | shuff57 (equaSHion) | [storytold/craft-libs#29](https://github.com/storytold/craft-libs/pull/29) at `7a6ef6b9`, `corpus/` | MIT OR Apache-2.0 |
| `crates/math/tests/corpus/omml/*.xml` (unmodified) | WordCraft and DeckCraft contributors, collected by shuff57 (equaSHion) | [storytold/craft-libs#29](https://github.com/storytold/craft-libs/pull/29) at `7a6ef6b9`, `corpus/omml/` | MIT OR Apache-2.0 |
Original assets are covered by the repository licence.
@@ -28,14 +51,15 @@ The profile licence is retained in `licenses/pdf-writer/LICENSE-ICC.txt`.
| `krilla 0.8.2 / icc/sRGB-v4.icc` | Clinton Ingram | https://github.com/LaurenzV/krilla/blob/3ffdf0588cf98050aad6edba51ca70162e1fb5b5/crates/krilla/icc/sRGB-v4.icc | CC0-1.0 | `c56e1685d888f5edb92fe07f2750f387f8fe8e91b32ff8fb0b56bfbbb9458353` | PDF writer colour profiles |
The four Krilla ICC entries above are also stored unchanged in `vendor/krilla/icc`.
The vendored source patch and per-file hashes are recorded in `vendor/krilla/README.craft.md` and `vendor/krilla/SOURCE.json`.
The vendored source patches are in `vendor/krilla/patches`, described in `vendor/krilla/README.craft.md`; per-file hashes are in `vendor/krilla/SOURCE.json`.
## Assets retained with the optional PDF reader
The shared reader centralizes the four existing patched Hayro source trees from PdfCraft.
The shared reader centralizes the five patched Hayro source trees from PdfCraft and the
patched crates.io `hayro-postscript` 0.1.0 scanner, which bundles no assets.
The standard-14 fonts, CMYK profile and generated metrics listed below remain byte-identical
in `vendor/hayro-interpret`; no application document fonts are added. CMaps remain a pinned
registry dependency. The removed upstream LAB.icc profile is not restored. Source hashes
in `vendor/hayro-interpret`, and the CMaps in `vendor/hayro-cmap/assets`; no application
document fonts are added. The removed upstream LAB.icc profile is not restored. Source hashes
and the exact transfer revision are recorded in each vendored crate's SOURCE.json.
| Crate / file | Author | Source | Licence | SHA-256 | Use |
@@ -55,5 +79,18 @@ and the exact transfer revision are recorded in each vendored crate's SOURCE.jso
| `hayro-interpret 0.7.0 / assets/FoxitSerifItalic.pfb` | Foxit Software Inc. / PDFium Authors | https://github.com/storytold/pdfcraft/blob/7437bde378f43856eada40af25b983812e615e8a/vendor/hayro-interpret/assets/FoxitSerifItalic.pfb | BSD-3-Clause | `610ae0687198045c4db5d1a6650fd5e92536631706382eb8b72e38df578d0ae9` | Renders non-embedded standard-14 fonts (pinned hayro-interpret) |
| `hayro-interpret 0.7.0 / assets/FoxitSymbol.pfb` | Foxit Software Inc. / PDFium Authors | https://github.com/storytold/pdfcraft/blob/7437bde378f43856eada40af25b983812e615e8a/vendor/hayro-interpret/assets/FoxitSymbol.pfb | BSD-3-Clause | `47967d055530e7357088a08403115425643ec2cdfd6201ba8af0fbd7116c1539` | Renders non-embedded standard-14 fonts (pinned hayro-interpret) |
| `hayro-interpret 0.7.0 / assets/CGATS001Compat-v2-micro.icc` | Clinton Ingram (saucecontrol/Compact-ICC-Profiles) | https://github.com/storytold/pdfcraft/blob/7437bde378f43856eada40af25b983812e615e8a/vendor/hayro-interpret/assets/CGATS001Compat-v2-micro.icc | CC0-1.0 | `73e1ba37d2bad5bab2a964f40a9eed96209666efc067c3322626214bbef234a0` | Default CMYK colour conversion (pinned hayro-interpret) |
| `hayro-cmap 0.1.0 / assets/cmaps.brotli` | Adobe | https://crates.io/crates/hayro-cmap/0.1.0 | BSD-3-Clause | `ddf37af521d904d5646c2fc37b2b7e912dc1b56f0d210190b61f598154758e46` | Character-code mapping tables required to read CJK PDFs. Non-visual dependency data; existing embedding unchanged |
| `hayro-cmap 0.1.0 / assets/cmaps.brotli` | Adobe | https://github.com/storytold/pdfcraft/blob/a2ec27b4775f53c40cad3456936d9406611e3a8d/vendor/hayro-cmap/assets/cmaps.brotli | BSD-3-Clause | `ddf37af521d904d5646c2fc37b2b7e912dc1b56f0d210190b61f598154758e46` | Character-code mapping tables required to read CJK PDFs. Non-visual dependency data; existing embedding unchanged |
| `hayro-interpret 0.7.0 / src/font/generated/metrics.rs` | Adobe (Core 14 AFM metrics, PDF specification encodings); tables by The Hayro Authors | https://github.com/storytold/pdfcraft/blob/7437bde378f43856eada40af25b983812e615e8a/vendor/hayro-interpret/src/font/generated/metrics.rs | MIT OR Apache-2.0 | `2ec9e608573eda459de1e1d9bda3bb494315e36bee885acc88912a11fe0caa41` | Glyph widths and encodings for non-embedded standard fonts. Non-visual dependency data; existing embedding unchanged |
| `crates/audio/src/ac3/golden_frames.bin` | FilmCraft contributors (original work: 12 AC-3 and E-AC-3 syncframes that ffmpeg's `ac3` and `eac3` encoders made from tones and seeded noise synthesised by ffmpeg's lavfi generators; no third-party or recorded audio) | [FilmCraft `crates/ac3`](https://github.com/storytold/filmcraft/tree/1c9c2e82/crates/ac3/src) | MIT OR Apache-2.0 |
| `crates/audio/tests/fixtures/` | SoundCraft and craft-libs contributors (original work: 0.1 s test tones from ffmpeg's `sine` generator and hand-built silent MPEG frames; no third-party or recorded audio; commands in `crates/audio/tests/fixtures/README.md`) | [SoundCraft `crates/audio-io/tests/fixtures`](https://github.com/storytold/soundcraft/tree/e86d09a/crates/audio-io/tests/fixtures); `tone.mov`, `tone.mka`, `tone.opus`, `tone.ac3` and `tone.eac3` made in this repository | MIT OR Apache-2.0 |
| `crates/image-codecs/src/codecs/xpm/x11_colors.rs` | X.Org Foundation and X11 contributors (X11 `rgb.txt` colour names and values, normalised into a lookup table) | <https://cgit.freedesktop.org/xorg/app/rgb/tree/rgb.txt>, via [PhotoCraft `crates/codecs`](https://github.com/storytold/photocraft/tree/5000240c6/crates/codecs/src/codecs/xpm) | MIT (X.Org app/rgb) |
| `crates/raster-codecs/src/xpm/x11_colors.rs` | X.Org Foundation and X11 contributors (X11 `rgb.txt` colour names and values, normalised into a lookup table) | <https://cgit.freedesktop.org/xorg/app/rgb/tree/rgb.txt>, via [PhotoCraft `crates/codecs`](https://github.com/storytold/photocraft/tree/63b641b55e54bf8f5c83efd977fdb16a2c255431/crates/codecs/src/codecs/xpm) | MIT (X.Org app/rgb) |
| `crates/psd/tests/fixtures/atn/*.atn` (seven synthetic action sets, encoded field by field; `crates/psd/tests/fixtures/atn/README.md`) | PhotoCraft contributors | [PhotoCraft `crates/psd/tests/fixtures/atn`](https://github.com/storytold/photocraft/tree/63b641b55e54bf8f5c83efd977fdb16a2c255431/crates/psd/tests/fixtures/atn) | MIT OR Apache-2.0 |
| `crates/lottie/tests/fixtures/` | EffectCraft contributors (original work: four hand-written Lottie JSON documents, written from the public Lottie format description; not exported from any Adobe product or third-party file) | [EffectCraft `crates/lottie/tests/fixtures`](https://github.com/storytold/effectcraft/tree/e18f48fb/crates/lottie/tests/fixtures) | MIT OR Apache-2.0 |
| `crates/pkcs7/tests/data/` | PdfCraft contributors (original work: throw-away test keys and certificates made with OpenSSL 3 for these tests, as seven PKCS #12 files with the password `test` and two PEM certificates; they protect nothing; commands in `crates/pkcs7/tests/data/README.md`) | [PdfCraft `crates/sign/tests/data`](https://github.com/storytold/pdfcraft/tree/1d7a9f9f/crates/sign/tests/data) | MIT OR Apache-2.0 |
| `crates/affinity/tests/support/corpus.tsv`, `crates/affinity/tests/support/affinity3-signatures.txt` (manifest and measured signatures only; the 51 documents are not bundled, `scripts/fetch-affinity-corpus.sh` downloads them outside the checkout) | The authors of each document: samuel-etver (vector-art), Seth A. Robinson (Patchy fixtures), Nick Beeuwsaert (AFDesignLoad), Jeremy Cantu (Branding), eviltwo (AssetStoreTemplate), Square (leakcanary) | each file's pinned upstream URL and SHA-256 in the manifest; list carried over from [VectorCraft `xtask/src/affinity_corpus.rs`](https://github.com/storytold/vectorcraft/blob/6e873b806c9d5b3f2b55f651df57bd97933b579a/xtask/src/affinity_corpus.rs) | CC0-1.0, MIT or Apache-2.0 (per file, in the manifest) |
| `crates/raw/docs/coverage/adobe-cameras.tsv` | Facts (maker, model, extension, profile, minimum Camera Raw version) parsed by LightCraft contributors from Adobe's published list | [Adobe Camera Raw supported cameras](https://helpx.adobe.com/camera-raw/desktop/dng-and-file-formats/camera-raw-plug-supported-cameras.html), Wayback capture 20261003133011; moved from [LightCraft `docs/raw`](https://github.com/storytold/lightcraft/tree/5ff567a4a2e067bef1b6bce152c11e7f727ccbaf/docs/raw) | Facts, not copyrightable expression; the file is MIT OR Apache-2.0 |
| `crates/raw/docs/coverage/{coverage,coverage-sweep,evidence,usage-weights}.tsv`, `coverage.py` | LightCraft contributors | [LightCraft `docs/raw`](https://github.com/storytold/lightcraft/tree/5ff567a4a2e067bef1b6bce152c11e7f727ccbaf/docs/raw) | MIT OR Apache-2.0 |
| `crates/raw/docs/raf-corpus.sha256` (hashes only; the files are not bundled) | The photographers who contributed each file to raw.pixls.us | [raw.pixls.us](https://raw.pixls.us/) | CC0-1.0 |
| `crates/drawingml/src/preset_text.txt` | DeckCraft contributors (Nikita Rakitin); generated by `crates/drawingml/tests/fixtures/make_preset_guides.py` from the guide formulas of ECMA-376 Part 1 `presetShapeDefinitions.xml` | [storytold/deckcraft#650](https://github.com/storytold/deckcraft/pull/650) | MIT OR Apache-2.0 (the formulas are the format's definition in ECMA-376) |
| `crates/drawingml/tests/fixtures/preset_table.txt` | DeckCraft contributors (Nikita Rakitin); generated by `crates/drawingml/tests/fixtures/make_preset_table.py` from ECMA-376 Part 1 `presetShapeDefinitions.xml` | [storytold/deckcraft#650](https://github.com/storytold/deckcraft/pull/650) | MIT OR Apache-2.0 (the formulas are the format's definition in ECMA-376) |
+65
View File
@@ -0,0 +1,65 @@
# Changelog
All crates share the workspace version. See [the versioning policy](docs/versioning.md).
## v0.1.0 — 2026-10-12
First coordinated Git release of craft-libs. Applications can pin a named baseline instead of
following development commits. This is an initial 0.x release: compatibility is maintained
within `0.1.x`; changes requiring consumer migration use a new minor version.
### Included crates
- **craft-atomic:** same-directory staged file replacement, exclusive creation, streaming
writes, transient rename retries and fault-injection support, extracted from PhotoCraft.
- **craft-settings:** app-owned TOML settings with platform/portable paths, atomic saves,
backups, damaged-file recovery, schema migrations and preservation of unknown fields.
- **craft-quit:** native macOS termination, optional egui close handling and an optional
application menu. Save decisions and prompts stay with the app.
- **craft-print:** CUPS and native Windows PDF submission, printer discovery, copies, duplex,
colour and scaling options. Includes bounded PDF sheet handling and the pinned Windows
completion fix. PDF generation stays with the app.
- **craft-ui:** egui icon buttons, tabs, splits, resize handles, toolbar overflow, transactional
docking, theme helpers and print-settings controls. Commands, content, localization and
application state stay with the consumer. Docking serialization is opt-in through `serde`.
### Requirements and adoption
- Rust **1.95+**, edition 2024. Public UI integrations use **egui 0.36**.
- Use `git = "https://github.com/storytold/craft-libs", tag = "v0.1.0"` for each required crate;
use the same tag everywhere. The [README](README.md#use-a-released-version) has a complete
manifest example and a commit-pin alternative. Commit application lockfiles.
- No automatic migration from an arbitrary earlier Git revision is implied. Compare the API
you used with this release and test affected workflows before changing pins.
- For `craft-quit`, run the close hook last in `eframe::App::logic`, after the app's unsaved-work
decision. Finish asynchronous saves before requesting close; termination does not execute
code after `run_native`. See the crate's API documentation before adoption.
- This release is distributed through Git only. No crates.io packages are published by it.
### Platform coverage and known limits
The release gate checks the workspace on Linux, macOS and Windows with default and all features,
plus Linux minimum-compiler and UI/settings WASM checks. UI tests include offscreen visual
regressions. Windows print tests exercise a temporary paused spooler queue; those checks do
not establish physical printer fidelity or every application's native GUI behavior.
- `craft-ui` supports native and WASM use. Font coverage, bidirectional text and screen-reader
behavior still depend on the application and upstream stack; see [#17](https://github.com/storytold/craft-libs/issues/17).
- `craft-settings` persistence is native-only. WASM exposes settings traits, document helpers
and error types. Concurrent writers are best-effort, last-writer-wins; strict coordination
needs an application-owned lock.
- `craft-atomic` does not preserve all filesystem metadata during replacement. Directory sync
is best effort; tests do not prove physical power-loss durability. See its README's contract.
- `craft-quit`'s native behavior is macOS-specific; other platforms keep their normal close
path. Earlier hardware testing of the close hook is recorded in
[#3](https://github.com/storytold/craft-libs/issues/3); it does not qualify every consuming app.
- `craft-print` requires CUPS command-line tools on Linux/macOS or the native Windows spooler.
Browser submission is unsupported. Windows accepts a bounded subset of print-ready PDFs;
unsupported inputs and driver paper/scaling mismatches return errors. Printing is synchronous,
so call it from a worker. Physical output needs hardware testing.
- Windows printing retains a pinned Git dependency on the maintained `winprint` fork. Its
build dependencies require the license/advisory policy exceptions documented in
[craft-print's README](crates/print/README.md). Registry publication is deferred.
Planned crates and open feature PRs are not part of this release. Existing commit pins remain
valid, and consumers do not need to update simply because `main` changes.
+1 -1
View File
@@ -1 +1 @@
Read `AGENTS.md`.
@AGENTS.md
Generated
+6120 -398
View File
File diff suppressed because it is too large Load Diff
+190 -2
View File
@@ -1,7 +1,7 @@
[workspace]
resolver = "3"
members = ["crates/*"]
exclude = ["vendor/krilla", "vendor/hayro", "vendor/hayro-interpret", "vendor/hayro-syntax", "vendor/hayro-jbig2"]
exclude = ["vendor/krilla", "vendor/hayro", "vendor/hayro-interpret", "vendor/hayro-syntax", "vendor/hayro-jbig2", "vendor/hayro-cmap", "vendor/hayro-postscript", "vendor/linesweeper"]
[workspace.package]
version = "0.1.0"
@@ -11,28 +11,182 @@ rust-version = "1.95"
repository = "https://github.com/storytold/craft-libs"
[workspace.dependencies]
acadrust = "=0.6.6"
log = "0.4"
# internal: add each crate here as `craft-<name> = { path = "crates/<name>" }`
craft-platform = { path = "crates/platform" }
craft-aep = { path = "crates/aep" }
craft-affinity = { path = "crates/affinity" }
craft-ai-core = { path = "crates/ai-core" }
craft-anicraft-format = { path = "crates/anicraft-format" }
craft-pdf = { path = "crates/pdf", version = "=0.1.0" }
craft-ps = { path = "crates/ps", version = "=0.1.0" }
craft-pdn = { path = "crates/pdn" }
craft-plate-test = { path = "crates/plate-test" }
pdf-writer = "0.15"
miniz_oxide = "0.8"
weezl = "0.1"
skrifa = "0.47"
krilla = { version = "=0.8.2", default-features = false, features = ["raster-images"] }
hayro = { version = "=0.7.1", default-features = false }
hayro-interpret = { version = "=0.7.0", default-features = false, features = ["embed-fonts", "embed-cmaps"] }
hayro-syntax = { version = "=0.7.2", default-features = false, features = ["std"] }
bytemuck = "1"
kurbo = "0.13"
thiserror = "2"
craft-aaf = { path = "crates/aaf" }
craft-atomic = { path = "crates/atomic" }
craft-captions = { path = "crates/captions" }
craft-cfb = { path = "crates/cfb" }
craft-codepage = { path = "crates/codepage" }
craft-cms = { path = "crates/cms" }
craft-crs = { path = "crates/crs" }
craft-crw = { path = "crates/crw" }
craft-csv = { path = "crates/csv" }
craft-dav = { path = "crates/dav" }
craft-dialogs = { path = "crates/dialogs" }
craft-doc-binary = { path = "crates/doc-binary" }
craft-docx = { path = "crates/docx" }
craft-document-bundle = { path = "crates/document-bundle" }
craft-designcraft-format = { path = "crates/designcraft-format" }
craft-dxf = { path = "crates/dxf" }
craft-drawingml = { path = "crates/drawingml" }
craft-eps = { path = "crates/eps" }
craft-file-formats = { path = "crates/file-formats" }
craft-file-import = { path = "crates/file-import" }
vectorcraft-doc = { git = "https://github.com/storytold/vectorcraft.git", rev = "6b3a6b8788ebcb420d69449199cbdf323888d27e" }
vectorcraft-eps = { git = "https://github.com/storytold/vectorcraft.git", rev = "6b3a6b8788ebcb420d69449199cbdf323888d27e" }
vectorcraft-geom = { git = "https://github.com/storytold/vectorcraft.git", rev = "6b3a6b8788ebcb420d69449199cbdf323888d27e" }
vectorcraft-pathops = { git = "https://github.com/storytold/vectorcraft.git", rev = "6b3a6b8788ebcb420d69449199cbdf323888d27e" }
craft-doc = { path = "crates/doc" }
craft-docpath = { path = "crates/docpath" }
craft-dpx = { path = "crates/dpx" }
craft-dwg = { path = "crates/dwg" }
craft-ecproj-format = { path = "crates/ecproj-format" }
craft-figma-rest = { path = "crates/figma-rest" }
craft-exr = { path = "crates/exr" }
craft-flags = { path = "crates/flags" }
craft-font-catalog = { path = "crates/font-catalog" }
craft-font-manager = { path = "crates/font-manager" }
craft-font-store = { path = "crates/font-store" }
craft-gainmap = { path = "crates/gainmap" }
craft-flow = { path = "crates/flow" }
craft-gcode = { path = "crates/gcode" }
craft-gif = { path = "crates/gif" }
craft-hdr = { path = "crates/hdr" }
craft-mesh = { path = "crates/mesh" }
craft-html = { path = "crates/html" }
craft-heif = { path = "crates/heif" }
craft-fig = { path = "crates/fig" }
craft-fonts-build = { path = "crates/fonts-build" }
craft-i18n = { path = "crates/i18n" }
craft-idml = { path = "crates/idml" }
craft-indd = { path = "crates/indd" }
craft-jmap = { path = "crates/jmap" }
craft-ical = { path = "crates/ical" }
craft-jpeg = { path = "crates/jpeg" }
craft-jxl = { path = "crates/jxl" }
craft-kiwi = { path = "crates/kiwi" }
craft-keymap = { path = "crates/keymap" }
craft-assuan = { path = "crates/assuan" }
craft-kra = { path = "crates/kra" }
craft-audio = { path = "crates/audio" }
# No default features, so craft-audio's `encode` builds craft-media without `isobmff`.
craft-latex = { path = "crates/latex" }
craft-markdown = { path = "crates/markdown" }
craft-math = { path = "crates/math" }
craft-media = { path = "crates/media", default-features = false }
craft-materialx = { path = "crates/materialx" }
craft-media-testkit = { path = "crates/media-testkit" }
craft-midi = { path = "crates/midi" }
craft-sf2 = { path = "crates/sf2" }
craft-mime = { path = "crates/mime" }
craft-odf = { path = "crates/odf" }
craft-ods = { path = "crates/ods" }
craft-prc = { path = "crates/prc" }
craft-lottie = { path = "crates/lottie" }
craft-menu = { path = "crates/menu" }
craft-metafile = { path = "crates/metafile" }
craft-offcrypto = { path = "crates/offcrypto" }
craft-opc = { path = "crates/opc" }
craft-openpgp = { path = "crates/openpgp" }
craft-ora = { path = "crates/ora" }
craft-pptx = { path = "crates/pptx" }
craft-penpot = { path = "crates/penpot" }
craft-pcraft-format = { path = "crates/pcraft-format" }
craft-pcraft-bundle = { path = "crates/pcraft-bundle" }
craft-pkcs7 = { path = "crates/pkcs7" }
craft-plotter = { path = "crates/plotter" }
craft-prepress = { path = "crates/prepress" }
craft-print = { path = "crates/print" }
craft-proof = { path = "crates/proof" }
craft-raster-codecs = { path = "crates/raster-codecs" }
craft-image-codecs = { path = "crates/image-codecs" }
craft-psd = { path = "crates/psd" }
craft-pst = { path = "crates/pst" }
craft-quit = { path = "crates/quit" }
craft-rtf = { path = "crates/rtf" }
craft-raw = { path = "crates/raw" }
craft-sheet = { path = "crates/sheet" }
craft-sketch = { path = "crates/sketch" }
craft-settings = { path = "crates/settings" }
craft-scraft-format = { path = "crates/scraft-format" }
craft-time = { path = "crates/time" }
craft-silhouette-studio = { path = "crates/silhouette-studio" }
craft-svg = { path = "crates/svg" }
craft-stencilcraft-format = { path = "crates/stencilcraft-format" }
craft-stencilcraft-document = { path = "crates/stencilcraft-document" }
craft-svg-paths = { path = "crates/svg-paths" }
craft-stream-codecs = { path = "crates/stream-codecs" }
craft-text = { path = "crates/text" }
craft-tga = { path = "crates/tga" }
craft-timeline = { path = "crates/timeline" }
craft-tiff = { path = "crates/tiff" }
craft-metadata = { path = "crates/metadata" }
craft-ui = { path = "crates/ui" }
egui = { version = "0.36", default-features = false }
craft-update = { path = "crates/update" }
craft-vcard = { path = "crates/vcard" }
craft-vectorcraft-format = { path = "crates/vectorcraft-format" }
craft-vectordrawable = { path = "crates/vectordrawable" }
craft-xls = { path = "crates/xls" }
craft-xfl = { path = "crates/xfl" }
craft-wordmodel = { path = "crates/wordmodel" }
craft-xlsx = { path = "crates/xlsx" }
indd = { git = "https://github.com/storytold/indd-utils", rev = "7f3060e5bce78d21ea70e0d5eacb96edce15dfbe" }
craft-xcf = { path = "crates/xcf" }
craft-xml = { path = "crates/xml" }
craft-zip = { path = "crates/zip" }
craft-y4m = { path = "crates/y4m" }
craft-epub = { path = "crates/epub" }
craft-ews = { path = "crates/ews" }
craft-video = { path = "crates/video" }
craft-web-api = { path = "crates/web-api" }
craft-window = { path = "crates/window" }
craft-web-host = { path = "crates/web-host" }
craft-webp = { path = "crates/webp" }
egui = { version = "0.37", default-features = false }
md5 = { package = "md-5", version = "0.10", default-features = false }
jxl-oxide = { version = "0.12", default-features = false }
jixel = "=0.3.4"
rayon = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
proptest = "1"
# Character sets of the WHATWG Encoding Standard (craft-mime). (Apache-2.0 OR MIT) AND BSD-3-Clause.
encoding_rs = "0.8"
# All date/time conversion goes through chrono (no hand-rolled calendar code beyond the 400-year range extension; AGENTS.md).
chrono = { version = "0.4.45", default-features = false, features = ["std"] }
[workspace.lints.rust]
unsafe_code = "forbid"
unused_workspace_dependencies = "allow"
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(craft_pdf_unicode_fixtures)"] }
[workspace.lints.clippy]
cognitive_complexity = "deny"
too_many_arguments = "deny"
unused_workspace_dependencies = "allow"
wildcard_imports = "deny"
dbg_macro = "warn"
todo = "warn"
@@ -43,3 +197,37 @@ hayro = { path = "vendor/hayro" }
hayro-interpret = { path = "vendor/hayro-interpret" }
hayro-syntax = { path = "vendor/hayro-syntax" }
hayro-jbig2 = { path = "vendor/hayro-jbig2" }
hayro-cmap = { path = "vendor/hayro-cmap" }
hayro-postscript = { path = "vendor/hayro-postscript" }
linesweeper = { path = "vendor/linesweeper" }
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" }
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
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" }
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
# symphonia's FLAC decoder restores LPC samples as `residual + (prediction as i32)`. In a valid
# 32-bit stream the prediction can leave the i32 range while the sum does not, so a debug build
# panics where a release build wraps to the right sample. Apps that decode 32-bit FLAC through
# craft-audio's `decode` need the same override in their own workspace.
[profile.dev.package.symphonia-bundle-flac]
overflow-checks = false
# Codec hot loops: the oracle and conformance tests of a debug build take minutes below opt-level 3.
[profile.dev.package.craft-video]
opt-level = 3
# The object-stream parser follows nesting 384 levels deep: unoptimised, its frames overflow the
# 2 MiB stack of a test thread. The apps this reader came from build their crates at this level.
[profile.dev.package.craft-affinity]
opt-level = 1
+195 -6
View File
@@ -5,6 +5,17 @@ Licensed under the MIT License or the Apache License, Version 2.0, at your optio
Third-party material
Optional DWG bridge
`craft-dwg` uses `acadrust` 0.6.6 unmodified as a separate dependency for DWG reading and writing.
It is licensed under the Mozilla Public License 2.0. The license text and upstream third-party
notices are retained in `licenses/dwg/`; the crate is available from crates.io and
https://github.com/hakanaktt/acadrust.
The byte-level bridge source was moved from CADCraft `crates/dwg` at revision
`664837df8925f932e90a7ae37c58d2f54e7a1320`. The bridge itself is MIT OR Apache-2.0; its only
MPL-2.0 component is the unmodified `acadrust` dependency.
This product bundles third-party material under its own licenses, listed below. The per-file
list (author, source, license) is in ATTRIBUTION.md.
@@ -19,11 +30,101 @@ crates/cms/tests/data/FOGRA39.txt: FOGRA39 characterisation data, distributed un
the data are distributed unmodified and Fogra is identified as the source. The designation
FOGRAxx may be used solely to identify the respective reference data. Such use does not
imply certification, approval or endorsement by Fogra."
crates/text/assets/hyphen/en-us.dic: public domain, derived from the Moby Hyphenator II list by
Grady Ward (Project Gutenberg eBook #3204).
crates/proof/data/en-words.dic: public domain, the words of the Moby Hyphenator II list by Grady
Ward (Project Gutenberg eBook #3204), without its break points.
crates/proof/data/en-extra.txt: MIT OR Apache-2.0, WordCraft contributors' own list of modern
English words (a copy of craft-i18n's language-data/en-us/en-extra.txt).
craft-proof Language data, embedded at build time from craft-i18n's language-data/ when
CRAFT_I18N_DIR is set (CRAFT_PROOF_EMBED picks the locales; by default English and the German,
Polish, Portuguese, Italian and Russian data). Each file keeps its licence header; the
licences are listed in craft-i18n's ATTRIBUTION.md, and a pattern file's notice ships with any
application that embeds it. The Portuguese hyphenation patterns (language-data/pt/
hyphenation.pat, hyph-utf8 hyph-pt 1.4) are under the BSD 3-clause licence:
Copyright (C) 1987, 1994, 1996, 2015 Pedro J. de Rezende, 1996, 2015 J. Joao Dias Almeida,
2024 Leonardo Araujo and Aline Benevides.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the University of Campinas, of the University of Minho nor the names of
its contributors may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PEDRO J. DE REZENDE OR J.JOAO
DIAS ALMEIDA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
crates/text/assets/hyphen/en-us.pat: CC0-1.0, trained from en-us.dic by DesignCraft's trainer.
Hyphenation patterns for other languages, embedded through the hypher crate only when the
matching craft-text feature is enabled (none are by default). They come from hyph-utf8,
https://github.com/hyphenation/tex-hyphen, as packaged in https://github.com/typst/hypher
(patterns/). Each file is under the license stated in its header: LPPL, MIT, BSD-3-Clause, the
Unlicense, a notice permitting any use, or a choice of licenses that includes one of these. An
application that enables a language ships that file's copyright and license notice. The
exception is Slovak (hyph-sk.tex, Copyright (C) 1992 Jana Chlebíková), under the GNU General
Public License, version 2 or later (SPDX: GPL-2.0-or-later). craft-text asks for it through the
feature "slovak-gpl", which "all-languages" does not include; an application that enables it
ships GPL-licensed data. Cargo unifies features, so another dependency that enables hypher's
"slovak" feature (hypher's default features do) embeds the same data; a build that must exclude
it checks its dependency graph. The Spanish patterns (feature "spanish") are hyph-es.tex 5.0.
Copyright (C) 1993, 1997 Javier Bezos, 2001-2019 Javier Bezos, CervanTeX. MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions: The above copyright notice
and this permission notice shall be included in all copies or substantial portions of the
Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Word-break dictionaries and LSTM models for Thai, Lao, Khmer and Burmese, embedded through the
icu_segmenter_data crate only when craft-text's "thai", "lao", "khmer" or "burmese" feature is
enabled (none are by default). From ICU4X, https://github.com/unicode-org/icu4x.
Copyright (c) 2020-2024 Unicode, Inc. Unicode License v3 (SPDX: Unicode-3.0); portions adapted
from ICU4C, (c) 1995-2016 International Business Machines Corporation and others. An
application that enables one of these features ships the Unicode License v3 copyright and
permission notice, https://www.unicode.org/license.txt.
The optional PDF writer bundles four CC0 ICC profiles by Clinton Ingram. See ATTRIBUTION.md for per-file sources and hashes.
Source provenance
crates/image-codecs (craft-image-codecs) is moved from PhotoCraft's standalone `photocraft-codecs`
crate, including its bounded decoders, encoders, format registry, image model, metadata handling,
orientation, fidelity warnings, and tests, from revision 5000240c6:
https://github.com/storytold/photocraft
Copyright (c) 2026 ArtCraft Team and the PhotoCraft contributors. The format implementations are
clean-room work based on their public specifications; dependency licences and X.Org's `rgb.txt`
attribution are listed in ATTRIBUTION.md.
crates/raw (craft-raw) is moved from LightCraft, with behaviour ported from two other readers:
- LightCraft, crates/raw (src/lib.rs, dng.rs, dngwrite.rs, tiffraw.rs, unpack.rs, ljpeg.rs, jxl.rs,
opcodes.rs, profile.rs, gaintable.rs, semantic.rs, preview.rs, vendor/crw.rs, vendor/hasselblad.rs,
vendor.rs (shared level helpers), vendor/mrw.rs, vendor/erf.rs, vendor/mef.rs, vendor/kodak.rs, vendor/pef.rs,
vendor/srw.rs, vendor/cr2.rs, vendor/cr2/sraw.rs, vendor/nef.rs, vendor/nefc.rs, vendor/nef_lens.rs, docs/nikon-lens-corrections.md, vendor/rw2.rs, vendor/raf.rs, vendor/rafc.rs, vendor/raf_lens.rs, docs/raf-compression.md, docs/raf-corpus.sha256, vendor/orf.rs, docs/orf-compression.md, vendor/arw.rs, vendor/arw6.rs, vendor/arw6_curve.rs, vendor/arw6_testenc.rs, vendor/arw_lens.rs, vendor/arw_lens_rm6.rs, vendor/sr2.rs, llvc.rs, lens_metadata.rs, docs/arw6-compression.md, docs/sony-lens-corrections.md, docs/sony-ilce7rm6-lens-corrections.md, vendor/cr3.rs, vendor/crx.rs, vendor/crx_wavelet.rs, sparse.rs, saturation.rs (the CR3 white extension), docs/cr3.md, docs/raw/, kelvin_presets.rs (the preset ordering), tests/it/vendor_robust.rs and their tests) and crates/meta/src/mrw.rs (the MRW block container),
revision 5ff567a4a2e067bef1b6bce152c11e7f727ccbaf.
https://github.com/storytold/lightcraft
Copyright (c) 2026 ArtCraft Team and the LightCraft contributors.
- PhotoCraft, crates/raw/src/dng.rs, hasselblad.rs and tests/it/dng.rs (default-crop defaults,
white-level fallbacks, the 8-bit rule for lossy JPEG, Hasselblad's per-site black levels),
revision c1b22bdaae2a1359ba3d164eca4d4b0c7378b547.
https://github.com/storytold/photocraft
Copyright (c) 2026 ArtCraft Team and the PhotoCraft contributors.
- FilmCraft, crates/dng/src/lib.rs (the CinemaDNG frame tags and time code), revision
4bec22bd03bd1d995c9cf72e02a284f96d3d72cd.
https://github.com/storytold/filmcraft
Copyright (c) 2026 ArtCraft Team and the FilmCraft contributors.
The SVG icon preparation in crates/ui is adapted from:
- PhotoCraft, crates/ui-egui/src/icons.rs, revision e7a83ca342cdff568254f85f442b9cc8afb08066.
https://github.com/storytold/photocraft
@@ -53,6 +154,13 @@ The transactional panel model and drop-zone semantics in crates/ui/src/docking d
FilmCraft/EffectCraft split, tab and accordion layouts and VectorCraft floating groups listed
above. The generic transaction validation, optional renderer and workspace-location helpers
are implemented here without dependencies on application engines or native window helpers.
The hyphenation code, data and generator in crates/text (src/hyphen/, assets/hyphen/ and
examples/hyphgen.rs) are adapted from:
- DesignCraft, crates/compose/src/hyphen/, crates/compose/examples/hyphgen.rs and
assets/hyphenation/, revision e161878e4c7744fa06f9a2eede8103cb4c296355 (above).
- WordCraft, crates/proof/src/hyphen.rs, revision e4b7d155f15a7784197ba34eeea0b54490d70eb2.
https://github.com/storytold/wordcraft
Copyright (c) 2026 ArtCraft Team and the WordCraft contributors.
All sources listed above are licensed MIT OR Apache-2.0. No icon artwork is copied here.
The PDF spooler in crates/print is extracted from:
@@ -75,6 +183,31 @@ PrintTicket and its driver-paper preference):
Copyright (c) 2026 ArtCraft Team and the PdfCraft contributors.
Licensed MIT OR Apache-2.0.
The menu layout and native-menu driver in crates/menu are extracted from:
- PhotoCraft, crates/ui-egui/src/native_menu.rs, revision 6f85054288a564f9fbbccb99268ffdb34e581584.
https://github.com/storytold/photocraft
Copyright (c) 2026 ArtCraft Team and the PhotoCraft contributors.
Licensed MIT OR Apache-2.0. PhotoCraft's menus, translations and command handling are not copied.
The macOS backend in crates/menu/src/mac.rs is adapted from:
- PhotoCraft, apps/photocraft/src/mac_menu.rs, revision 6f85054288a564f9fbbccb99268ffdb34e581584.
https://github.com/storytold/photocraft
Copyright (c) 2026 ArtCraft Team and the PhotoCraft contributors.
- VectorCraft, apps/vectorcraft/src/mac_menu.rs, revision 0d0ea352df99044589a7ce0efc7004f7a5b6b7c0
(closing an open menu on a click or Escape, and its tests, in crates/menu/src/driver.rs).
https://github.com/storytold/vectorcraft
Copyright (c) 2026 ArtCraft Team and the VectorCraft contributors.
Both licensed MIT OR Apache-2.0.
The egui menu bar in crates/menu/src/bar (its menu navigation, scrolling, submenu hover
intent, keyboard access and mnemonics, and their tests) is ported from:
- PhotoCraft, crates/ui-egui/src/menu_nav.rs and menu_nav_tests.rs, menu_keys.rs and
menu_keys_tests.rs, and the menu bar in crates/ui-egui/src/menus.rs, revision
c36e46c3873ee39f299cc50a3dcd28494c78366d.
https://github.com/storytold/photocraft
Copyright (c) 2026 ArtCraft Team and the PhotoCraft contributors, among them aiongg, artman67,
BFlat, Brandon Thomas, Brennan Stehling, Daniel Lošák, David Mann, Fabio Lissi, FredApps,
Higgs32584, itsF4LCON, jason4short, Korg1ch, MarekSpodBiedry and Nigel Ihza Firdausy.
Licensed MIT OR Apache-2.0. PhotoCraft's menus, theme and Help search are not copied.
The colour management module in crates/cms is extracted from:
- PhotoCraft, crates/cms, revision b3222ee8e7e6bcb4799c37f904c595f20f9baf5e.
https://github.com/storytold/photocraft
@@ -91,18 +224,74 @@ The optional writer embeds Compact ICC Profiles by Clinton Ingram
See licenses/pdf-writer/LICENSE-ICC.txt and ATTRIBUTION.md for sources and hashes.
The writer adds no font files. Its four existing ICC profiles are retained under vendor/krilla/icc.
Krilla is vendored with a native unwind-cleanup patch; see vendor/krilla/README.craft.md
Krilla is vendored with the local patches in vendor/krilla/patches; see vendor/krilla/README.craft.md
and vendor/krilla/SOURCE.json. Its upstream MIT/Apache-2.0 licences and CC0 profiles are unchanged.
Optional PDF reader
Hayro 0.7.1, hayro-interpret 0.7.0, hayro-syntax 0.7.2 and hayro-jbig2 0.3.0
(https://github.com/LaurenzV/hayro), MIT OR Apache-2.0, retain their upstream licence files.
These patched sources are transferred from PdfCraft revision
7437bde378f43856eada40af25b983812e615e8a (https://github.com/storytold/pdfcraft).
Hayro 0.7.1, hayro-interpret 0.7.0, hayro-syntax 0.7.2, hayro-jbig2 0.3.0, hayro-cmap 0.1.0
and hayro-postscript 0.1.0 (https://github.com/LaurenzV/hayro), MIT OR Apache-2.0, retain their
upstream licence files. The first five are patched sources transferred from PdfCraft
(https://github.com/storytold/pdfcraft): hayro-cmap from revision
a2ec27b4775f53c40cad3456936d9406611e3a8d, the others from revision
ec0a965074f376a5bf610435948e4e5184bf3299. hayro-postscript is the crates.io 0.1.0 package
(upstream revision a2354aebaf86f5ab13e5fd6b6b0521306488bf9d) with one local patch.
See vendor/README.craft-reader.md and each crate's SOURCE.json for provenance and local changes.
The hayro-interpret plate mode (separations, overprint and output-intent simulation) is ported
from PdfCraft pull request #2770 by Guillem Hermida, commit
6fcf2a4aca29e943e28cb69017ff8f87d00656c6 (https://github.com/storytold/pdfcraft/pull/2770),
MIT OR Apache-2.0; crates/pdf/tests/plates.rs and tests/support/synthetic_icc.rs adapt its tests.
Knockout transparency groups in hayro-interpret and hayro are ported from PdfCraft pull request
#2974 by mtlcl410, commit bae69819594a6385a027fec1f67e6b3c36c259b4
(https://github.com/storytold/pdfcraft/pull/2974), MIT OR Apache-2.0;
crates/pdf/tests/knockout.rs adapts its test.
The reader retains the existing Foxit/PDFium standard-14 font assets (BSD-3-Clause),
Compact ICC Profiles by Clinton Ingram (CC0-1.0), and dependency CMaps (BSD-3-Clause).
Their licences and per-file hashes are retained in vendor/hayro-interpret/assets,
licenses/pdf-backend and ATTRIBUTION.md. These are existing reader dependency assets;
vendor/hayro-cmap/assets, licenses/pdf-backend and ATTRIBUTION.md. These are existing reader dependency assets;
applications retain their own document-font selection and licensing policy.
linesweeper
linesweeper 0.5.0 (https://crates.io/crates/linesweeper/0.5.0), MIT OR Apache-2.0, is stored in
vendor/linesweeper with its upstream license files and one local patch. Its manifest names Joe Neeman
as author, and its LICENSE-MIT reads "Copyright (c) 2018 Raph Levien". See
vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance, the local patch
and the files left out.
Platform lifecycle source provenance
The optional crates/platform services adapt the preserved local platform candidate
9b135779a1e7136438a217c18afe1693ea23f1ab (dialog outcomes and browser resource ownership),
and current application implementations:
- PdfCraft crates/platform/src/desktop_theme.rs, a8cd797a917b1007544575c7280c9a0ce6a17e8f.
- CADCraft apps/cadcraft/src/desktop_theme.rs, 0cc66ad3066e71f2c3d4cacb7de905e79ba1c95b.
- ArtCraft Launcher apps/artcraft-launcher/src/system_theme.rs, f1676dfb41c226b5be490721f486ee6427419d80.
- Earlier PhotoCraft, FilmCraft and EffectCraft appearance services at revisions
0c72d95425dece90ef9a1cceb49e3315c96e22d5, 794a25fc9ed2e3f6fab51a254625bc9b99a88015
and 1b4d47f34f2b1c1b4a89f4b7348889def8fd648b respectively.
Sources: https://github.com/storytold/pdfcraft, https://github.com/storytold/cadcraft,
https://github.com/storytold/craft-launcher, https://github.com/storytold/photocraft,
https://github.com/storytold/filmcraft, https://github.com/storytold/effectcraft.
Copyright (c) 2026 ArtCraft Team and the respective application and craft-libs contributors.
All adapted source is licensed MIT OR Apache-2.0.
The Canon CRW decoder in crates/crw (src/lib.rs, src/tables.rs, src/tests.rs, tests/) and its
derivation record (crates/crw/clean-room/) come from:
- LightCraft, crates/raw/src/vendor/crw.rs, crates/raw/src/vendor/crw_tables.rs,
crates/raw/tests/crw_oracle.rs, crates/raw/tests/it/vendor_robust.rs and clean-room/crw/,
https://github.com/storytold/lightcraft/pull/3021, revision 6ca439b5155820d2befeacd81ec0c6a80b2bd3bc
(decoder ported at 70c755e42a65661401142819278d51b0c5977f7f; the record is identical at both).
https://github.com/storytold/lightcraft
Copyright (c) 2026 ArtCraft Team and the LightCraft contributors.
Its white-level plateau estimate (saturation_plateau) is LightCraft's vendor::white_from_data at the
same revision. The CRW compression was derived clean-room from CC0 sample files and the
maintainer's own photographs by black-box comparison with a reference decoder's command-line
output; no raw-decoder source was consulted (crates/crw/clean-room/sources.md).
crates/audio/src/alac/ (the ALAC decoder and encoder) is ported from Apple's ALAC reference
implementation, https://github.com/macosforge/alac at c38887c5c5e64a4b31108733bd79ca9b2496d987
(codec/), Copyright (c) 2011 Apple Inc., licensed under the Apache License, Version 2.0
(LICENSE-APACHE). The files are modified: translated to Rust, with bounds checks on hostile input,
wrapping integer arithmetic, the unrolled predictor and per-width matrix routines folded into one,
and the average bit rate filled in. Those files are Apache-2.0 only.
+347 -2
View File
@@ -1,6 +1,8 @@
Craft App Libraries
===================
<a href="https://sonarcloud.io/project/overview?id=storytold_craft-libs"><img alt="Scanned by SonarCloud" src="https://img.shields.io/badge/Scanned_by-SonarCloud-4b9fd5?style=flat-square&logo=sonarqubecloud&logoColor=white"></a>
This repo contains libraries used by the various Craft Apps. It's a Rust monorepo workspace, and the libraries can be included by any Craft Apps that need them.
In the future this may grow to include non-Rust library code.
@@ -15,29 +17,372 @@ A Cargo workspace (edition 2024, resolver 3). Each library is a crate under `cra
(`license.workspace = true`, and so on) and `[lints] workspace = true`. Register each crate in
`[workspace.dependencies]` in the root `Cargo.toml`.
Apps depend on a crate by git:
## Use a released version
The first coordinated release is **[v0.1.0](https://github.com/storytold/craft-libs/releases/tag/v0.1.0)**.
It gives consumers a fixed baseline while development continues on `main`. All five crates
share this version. They require Rust 1.95 or later; the UI integrations use egui 0.36.
Add only the crates you need, using the same tag for every craft-libs dependency:
```toml
craft-<name> = { git = "https://github.com/storytold/craft-libs", rev = "<commit>" }
[dependencies]
craft-ui = { git = "https://github.com/storytold/craft-libs", tag = "v0.1.0" }
craft-settings = { git = "https://github.com/storytold/craft-libs", tag = "v0.1.0" }
# Optional, for egui close handling and the macOS application menu:
craft-quit = { git = "https://github.com/storytold/craft-libs", tag = "v0.1.0", features = ["menu"] }
```
`craft-atomic` and `craft-print` use the same dependency syntax. Enable `craft-ui`'s
`serde` feature if you need to serialize its docking layout. These are Git releases;
crates.io publication is deferred.
Release tags are never moved or reused. For a commit pin, resolve the tag with
`git ls-remote https://github.com/storytold/craft-libs 'refs/tags/v0.1.0^{}'` and replace
`tag = "v0.1.0"` with `rev = "<full commit SHA>"` on every craft-libs dependency.
Use either `tag` or `rev`, not both. An existing commit pin keeps working; switching to this
release may require adapting to changes since that commit.
Commit your application's `Cargo.lock` and build with `cargo build --locked` for reproducible
Rust dependency resolution. A Git pin fixes craft-libs source, not every transitive dependency.
A library's own lockfile does not constrain its downstream consumers. Upgrade deliberately:
read the release notes, update all craft-libs pins together, refresh the lockfile with
`cargo check`, and run your application's tests and affected workflows before committing.
See the [release notes](CHANGELOG.md) for included functionality and known limits, and the
[versioning policy](docs/versioning.md) for compatibility guarantees and release checks.
## Libraries
- [`craft-platform`](crates/platform/README.md): optional native dialog lifecycle, Linux/BSD desktop appearance observation and browser download ownership; application policy stays in the apps.
- [`craft-aep`](crates/aep/README.md): After Effects projects: the `.aep` (RIFX) and `.aepx`
container as a lossless chunk tree that writes back byte for byte, and a typed, read-only view
of compositions, layers, properties, keyframes, effects, masks, shapes, text and footage.
Clean room, from EffectCraft. Mapping onto an app's document stays in the app.
- [`craft-ai-core`](crates/ai-core/README.md): the data model and contract for AI in the Craft Apps (connections, models, tools, requests, jobs, consent, history, route spec). Pure, no I/O, wasm-safe. Contract in [docs/ai-shared-layer.md](docs/ai-shared-layer.md).
- [`craft-pdf`](crates/pdf/README.md): independently optional PDF parsing, interpretation, rasterization and guarded authoring. Apps retain layout, fonts, editing and export policy; writer-only consumers do not enable the shared reader.
- [`craft-pdn`](crates/pdn/README.md): Paint.NET documents (`.pdn`, PDN3), read: the layer list, blend modes and chunked gzip pixel blocks, with a data-only MS-NRBF (.NET binary serialization) reader. From PhotoCraft.
- [`craft-aaf`](crates/aaf/README.md): clean-room AAF (Edit Protocol, structured storage) and OMF Interchange 2.0 (Bento) readers and writers over one mob-style composition model with exact times, clip gain, markers, nested compositions and embedded PCM essence. From FilmCraft.
- [`craft-assuan`](crates/assuan/README.md): the Assuan protocol and gpg-agent's operations (key lookup, signing a digest, decrypting a session key) over any `Read + Write` stream, with a bounded canonical S-expression reader. No sockets; everything the agent sends is capped.
- [`craft-affinity`](crates/affinity/README.md): bounded reader for native Affinity documents (`.af`, `.afdesign`, `.afphoto`, `.afpub`): archive, object stream and a neutral document model with layers, artboards, vectors, text, tables, images and masks. Read only; mapping onto an app's document stays in the app.
- [`craft-atomic`](crates/atomic/README.md): Crash-safe atomic file writing and replacement with same-directory staging, directory fsync, Apple `F_FULLFSYNC` fallback, transient lock backoff, and fault injection for the Craft suite.
- [`craft-captions`](crates/captions/README.md): caption and subtitle files behind one neutral
model (cues with exact tick times): SubRip, WebVTT, Scenarist SCC, MacCaption MCC, EBU STL and
TTML / IMSC1 / DFXP readers and writers, and CEA-608 / CEA-708 byte-pair coding. Carved from
FilmCraft.
- [`craft-cfb`](crates/cfb/README.md): clean-room Compound File Binary ([MS-CFB], OLE structured
storage) reader and writer: the container of legacy Office files, Outlook messages, encrypted
OOXML packages and AAF. Bounded on hostile input; what the streams hold stays with each format.
- [`craft-dav`](crates/dav/README.md): WebDAV multistatus documents (RFC 4918) with the CalDAV and
CardDAV namespaces, from MailCraft: read fail-closed into a bounded `craft-xml` tree with fixed
prefixes, and the successful properties of each response. No I/O.
- [`craft-cms`](crates/cms/README.md): pure-Rust ICC v2/v4 colour management: profile parsing
and writing, transforms, rendering intents, black point compensation, soft proofing, gamut
checks, 3D LUTs and built-in profiles (sRGB, Display P3, synthetic coated CMYK and others).
- [`craft-crs`](crates/crs/README.md): Adobe Camera Raw settings (the `crs:` namespace of an XMP packet or `.xmp` sidecar, read through craft-metadata): the settings by name, numbers, tone curve points, local corrections and the crop, read and written. From PhotoCraft.
- [`craft-codepage`](crates/codepage/README.md): legacy 8-bit code pages, one table each: the single-byte Windows pages, Mac OS Roman and fifteen DOS pages, keyed by Windows code page number, with the RTF/Word font charsets. craft-rtf, craft-dxf and craft-mime decode through it.
- [`craft-crw`](crates/crw/README.md): clean-room Canon CRW (CIFF) raw decoder, from LightCraft:
the heap container, the entropy coding derived by black-box analysis (frozen code tables), sensor
black and white levels and as-shot white balance. The complete derivation record (plan, sources
log, scripts, verification) is in `crates/crw/clean-room/`. Colour stays in each app.
- [`craft-csv`](crates/csv/README.md): delimited text (CSV, TSV) and SYLK: encoding detection (UTF-8, UTF-16, Windows-1252 or Windows-1256), delimiter sniffing, a record parser with a cap on fields per record, field quoting for writers, and a SYLK (`.slk`) reader with R1C1 formulas rewritten to A1.
- [`craft-dialogs`](crates/dialogs/README.md): native file and message dialogs that never block
the event loop: queued requests shown at the end of the frame and answered on a later frame,
free-standing Open and Folder panels and Save sheets on macOS, case-insensitive filters. What
to do with the answer stays in each app.
- [`craft-doc`](crates/doc/README.md): reads PhotoCraft `.pcraft`, VectorCraft `.vectorcraft`
and EffectCraft `.ecproj` documents without the apps: the kind and version, the previews and
PDF they carry, and their pages and layers. Rendering and editing stay in each app.
- [`craft-doc-binary`](crates/doc-binary/README.md): the Word 97-2003 binary format (`.doc`, [MS-DOC]) read into
`craft-wordmodel`, with XOR, RC4 and RC4 CryptoAPI password protection. WordCraft's reader, on `craft-cfb`.
- [`craft-docpath`](crates/docpath/src/lib.rs): decides whether a path or `file:` URL stored in a
document may be opened. Paths stored in documents are followed only when they are local or on the
document's own network share; other network paths, device paths and non-file URLs are refused.
- [`craft-dpx`](crates/dpx/src/lib.rs): DPX (SMPTE ST 268) and Kodak Cineon frames, from PhotoCraft,
FilmCraft and EffectCraft: header fields and code values at 8, 10, 12 and 16 bits in both byte
orders, filled and packed, RGB, RGBA, ABGR, luma and Y'CbCr descriptors, and a writer for both
formats. Bounded on hostile input. Colour conversion and orientation stay in each app.
- [`craft-drawingml`](crates/drawingml/README.md): the DrawingML that PPTX, DOCX and XLSX share:
EMU units and `a:xfrm`, colours with theme slots and colour transforms, preset shape outlines
(`a:prstGeom`), custom geometry with guide formulas (`a:custGeom`) and preset text warps
(`a:prstTxWarp`). From DeckCraft. Takes `craft-xml` trees; packages stay with each format.
- [`craft-eps`](crates/eps/README.md): Encapsulated PostScript files as a container: the binary
preview header (read and write), the DSC header comments and bounding boxes (also `(atend)`),
the EPSI preview bitmap, ASCII85 data, and telling EPS, PostScript and Illustrator files
(PostScript- or PDF-based) apart. No PostScript interpreter.
- [`craft-docx`](crates/docx/README.md): DOCX (WordprocessingML) read and written on `craft-wordmodel`, with
Word XML (Flat OPC) and Word 2003 XML, password-protected packages and Restrict Editing hashes.
WordCraft's DOCX crate on `craft-opc`, `craft-xml` and `craft-offcrypto`.
- [`craft-dxf`](crates/dxf/src/lib.rs): DXF tag reader and writer, from CADCraft: ASCII and
binary DXF as (group code, value) tags, split into sections and entities, with pre-2007 code
pages and version detection, and written back; and `model`, the drawing above the tags (header
variables, tables, blocks, layouts, entities) and its writer (R12 to 2018), merged from CADCraft's and VectorCraft's readers. Bounded
on hostile input. Mapping the model onto a document stays in each app.
- [`craft-dwg`](crates/dwg/README.md): bounded byte-level DWG↔DXF conversion with diagnostics,
capped output and an optional child-process worker; the `acadrust` dependency remains isolated
behind bytes and is unavailable on wasm32 and FreeBSD/aarch64.
- [`craft-ecproj-format`](crates/ecproj-format/README.md): the envelope of EffectCraft `.ecproj`
project files: `savedBy`, the schema version and its check, and the file object with the
project and its saved view as type parameters. The project model stays in EffectCraft.
- [`craft-fig`](crates/fig/README.md): clean-room reader and writer for the `.fig` container
(Figma Design and FigJam local copies): the ZIP archive, the chunked canvas with its kiwi schema
and message, images, and the vector network and geometry blobs. Bounded on hostile input.
Carved from FigCraft.
- [`craft-epub`](crates/epub/README.md): EPUB packages: the OCF ZIP container, the package document (metadata, manifest, spine) and the navigation document, written as EPUB 3 (reflowable and fixed layout) and read (EPUB 2 and 3) with bounded entry sizes. Content documents are the caller's.
- [`craft-figma-rest`](crates/figma-rest/README.md): typed model of the Figma REST API file JSON
(document tree, paints, effects, text styles, layout, component metadata), read and written with
serde without losing fields it has no name for. The neutral model the `.fig` and `.sketch`
readers map onto, with their extensions documented.
- [`craft-ews`](crates/ews/README.md): the SOAP layer of Exchange Web Services, from MailCraft, without
sockets: the request envelope and an escaping element builder, and the answer envelope, faults
and response messages with their codes, read with `craft-xml`. The operations and everything
over HTTP stay in each app.
- [`craft-exr`](crates/exr/src/lib.rs): OpenEXR pieces shared by PhotoCraft and EffectCraft: layer
and channel names, the channels that make a colour picture, and Cryptomatte IDs, metadata keys,
manifests and rank channels. The optional `decode` feature adds bounded part listing, flat
decoding (scan lines, tiles, every compression of the `exr` crate) and writing.
- [`craft-flags`](crates/flags/README.md): Feature flags shared by the Craft apps and the ArtCraft Launcher: one per-user `ArtCraft/flags.toml`, a `CRAFT_FLAGS` override, every flag off by default (`AI-MCP`, `AI-MODELS`).
- [`craft-flow`](crates/flow/README.md): the flow model every text format maps to (paragraphs with a kind, lists and formatted spans; tables; pictures, fields, notes, equations), converted to and from a craft-wordmodel `Document`.
- [`craft-font-catalog`](crates/font-catalog/README.md): the installed fonts on every platform
(font folders, fontconfig and Flatpak host folders, CoreText, DirectWrite, the font store),
lookup by family, style, localized, legacy, full and PostScript names, family loads shared
between threads, and rescans when fonts are installed or removed.
- [`craft-font-manager`](crates/font-manager/README.md): Craft Font Manager as a library: search
and filters over the Google Fonts index, installed fonts by family, the font store interface,
and (`egui` feature) `FontsPanel`, the whole interface as one panel for the launcher's Fonts tab
and the standalone app.
- [`craft-font-store`](crates/font-store/README.md): the suite's font store: the pinned Google
Fonts and Noto indexes plus indexes the user adds (never curated), exact lookup by family and
style or PostScript name, and installs from each source's URLs (jsDelivr, then raw GitHub)
checked by size, sha256 and parsing, with the licence, a manifest, and removal. Off until the
user turns downloading on; agents can't.
- [`craft-fonts-build`](crates/fonts-build/README.md): embeds the optional craft-fonts faces
from an app's `build.rs` (`CRAFT_FONTS_DIR`, `CRAFT_FONTS_REQUIRED`, script filters) as a table
of `EmbeddedFace`s. No dependencies; the app picks the faces.
- [`craft-gainmap`](crates/gainmap/README.md): HDR gain maps, from LightCraft: the ISO 21496-1
metadata and Adobe `hdrgm` XMP (read and write), measuring a gain map from SDR and HDR
renditions, applying one, and Apple's legacy maps. Encoding and the container stay in each app.
- [`craft-gcode`](crates/gcode/src/lib.rs): Grbl-style G-code writer: polylines in
millimetres to `G0`/`G1` moves with laser power and feed, for cutting lasers and plotters, as a
commented file or as bare lines for streaming. Its `grbl` module has the real-time command bytes
and the status and acknowledgement parsers.
- [`craft-gif`](crates/gif/src/lib.rs): GIF block reader, from PhotoCraft: the logical screen,
every frame's position, delay, disposal and transparent colour, the loop count and the first
frame's colour table, without decompressing pixels. Tells an animation from a still and whether
a file can hold the picture it declares before a decoder runs.
- [`craft-hdr`](crates/hdr/src/lib.rs): Radiance HDR (RGBE) picture reader, from FilmCraft: flat,
old and new run-length scan lines and all eight axis orders, to linear float RGB. Scan lines are
validated before the picture is allocated.
- [`craft-heif`](crates/heif/README.md): optional HEIF/HEIC still-image decoder, from LightCraft:
heic-rs reads the container and HEVC pictures, and this crate converts to 16-bit RGB to match
libheif (VUI range and matrix, chroma upsampling, `imir`, ICC on grid tiles). Also orientation,
alpha, EXIF/XMP and thumbnails. It never panics, and apps put it behind a non-default feature.
- [`craft-html`](crates/html/README.md): the bottom layer of reading and writing HTML: a tolerant tokenizer (text, start tags, end tags; elements to drop or to read as raw text are options), character references with the legacy names browsers accept without `;`, escaping, and the character set a page declares. With the `flow` feature, HTML documents read into and written from the craft-flow model.
- [`craft-i18n`](crates/i18n/README.md): translations over the embedded craft-i18n catalogs:
lookup with fallback (`pt-br` → `pt` → English), plurals, language names, the system locale and
a pseudo locale. The catalogs stay a fully optional build input; apps keep `tl!` and their
language setting.
- [`craft-raw`](crates/raw/README.md): camera raw files, the file-format layer, from LightCraft with
what PhotoCraft's and FilmCraft's readers added: container parsing and decompression to a neutral
raw image (samples, CFA, black and white levels, active area, crop, orientation, colour tags,
opcode lists, embedded previews), one Cargo feature per format. DNG reading and writing,
Hasselblad 3FR/FFF, Minolta MRW, Epson ERF, Mamiya MEF, Kodak DCS, Pentax PEF, Samsung SRW, Canon CR2, Nikon NEF/NRW, Panasonic RW2, Fujifilm RAF, Olympus ORF (uncompressed), Sony ARW, Canon CR3 and Canon CRW (through
`craft-crw`) so far; demosaicing and everything after stay with the develop
pipeline.
- [`craft-tga`](crates/tga/src/lib.rs): Truevision Targa, from FilmCraft (reader) and PhotoCraft
(writer): true-colour, grayscale and colour-mapped pictures, raw or run-length encoded, any
origin, to RGBA8, and a run-length writer whose packets end with their scan line. Bounded on
hostile input.
- [`craft-idml`](crates/idml/README.md): IDML (InDesign Markup Language) packages: the ZIP container read with bounded part sizes and lenient part names, `designmap.xml` with its includes in place, the `<Properties>` form on craft-xml elements, value codecs and the package writer; and InDesign Tagged Text, read and written.
- [`craft-ical`](crates/ical/README.md): iCalendar (RFC 5545) building blocks, from MailCraft: content
lines, DATE/DATE-TIME values, durations, TEXT escaping, the common subset of recurrence rules,
and `VTIMEZONE` definitions read and written. No time-zone database; what events and to-dos
mean stays in each app. Bounded and panic-free on hostile input.
- [`craft-stream-codecs`](crates/stream-codecs/README.md): byte-stream and bi-level image codecs that
PDF, PostScript and TIFF share: LZW, ASCII85, ASCIIHex, RunLength, TIFF and PNG predictors,
CCITT Group 3 and 4 decoding and Group 4 encoding, JBIG2 decoding and lossless encoding. Every
decoder is bounded and returns its partial output on damage. From PdfCraft; a PDF filter chain
is built on it in `craft-pdf`.
- [`craft-timeline`](crates/timeline/README.md): editorial timeline interchange: exact media time and SMPTE timecode, import/export reports, media path and `file://` URL handling, Avid Log Exchange (ALE) and CMX 3600 EDL documents, format detection. From FilmCraft.
- [`craft-time`](crates/time/README.md): exact rational ticks and SMPTE time across media, with a `soundcraft` compatibility module retaining SoundCraft's sample-index timebase, tempo maps, grids and session serialization semantics.
- [`craft-scraft-format`](crates/scraft-format/README.md): SoundCraft's typed `.scraft` session schema, versioned reader/writer, hostile-input validation, and `.scraftz` bundle reader/writer. Engine and UI mapping stays in SoundCraft.
- [`craft-metadata`](crates/metadata/README.md): photo metadata, from LightCraft: EXIF (read and write,
maker-note lens and focus point, every tag by name), IPTC-IIM, XMP packets (read, write, and a merge
that keeps what another program wrote), GPX track logs, and the blocks that carry them in JPEG, PNG,
WebP, TIFF-based, RAF and CR3 files. One `Metadata` model for all of them. Built on `craft-tiff`.
- [`craft-tiff`](crates/tiff/README.md): TIFF and BigTIFF IFD reader and writer, from LightCraft:
every field type, the IFD chain, SubIFDs and Exif/GPS/Interop pointer IFDs, maker-note IFDs
(Canon, Nikon, Sony, Fujifilm, Olympus, Panasonic, Pentax), strip and tile layout. Bounded and
panic-free on hostile input. Pixel decompression stays with the callers.
- [`craft-metafile`](crates/metafile/README.md): Windows metafiles, from DeckCraft, WordCraft and
VectorCraft: a WMF, EMF and EMF+ reader into a neutral picture (paths with line styles, pattern
fills, bitmaps, text, clip regions and clip paths) and, behind `write`, EMF and WMF writers.
Bounded and panic-free on hostile input. Mapping the picture onto a document stays in each app.
- [`craft-psd`](crates/psd/README.md): Adobe Photoshop PSD and PSB reader and writer, from
PhotoCraft: a lossless format-level model (layers, masks, tagged blocks, image resources,
descriptors, all four compressions, lazy reading from a file) that writes an unmodified file
back byte for byte, a builder for new files, and the Photoshop resource files that share its
primitives (`.abr`, `.asl`, `.aco`, `.act`, `.ase`, `.grd`, `.pat`, `.atn`, `.csh`, `.shc`) and
the Photoshop blocks of a layered TIFF. Bounded and panic-free on hostile input. Compositing
and the mapping onto a document stay in each app.
- [`craft-jmap`](crates/jmap/README.md): the JMAP protocol core (RFC 8620), from MailCraft, without
sockets: session, requests of method calls with back-references, responses, ids, address
templates, credentials and the judgement of HTTP answers, over any HTTP implementation. Bounded
on hostile answers; what a program asks and makes of the answers stays in it.
- [`craft-jpeg`](crates/jpeg/README.md): clean-room JPEG decoder for 12-bit and arithmetic-coded
frames (T.81 SOF0/SOF1 at 12 bits, SOF9, SOF10), band decoding, and an optimized 8-bit baseline
encoder, from PhotoCraft; includes a frame probe for routing. Metadata interpretation stays in
each app.
- [`craft-raster-codecs`](crates/raster-codecs/README.md): small raster formats, one module each,
from PhotoCraft: DDS (BC1 to BC3, read and write), DICOM, FITS (read and write), IFF/ILBM (read
and write), PCX, PNM/PAM/PFM (read and write) and XPM, into one flat image type. Bounded and
panic-free on hostile input. Colour, orientation and the document mapping stay in each app.
- [`craft-kiwi`](crates/kiwi/README.md): clean-room decoder and encoder for the kiwi binary schema
format (the encoding inside `.fig` files): a schema of enums, structs and messages, and messages
decoded with it into a tree keyed by field name. Bounded on hostile input. Carved from FigCraft.
- [`craft-keymap`](crates/keymap/README.md): keyboard bindings: chords and their text forms,
scopes, conflicts, user overrides stored through craft-settings and import of other
applications' shortcut sets. Command catalogs, file readers and the shortcut editor UI stay
in each app.
- [`craft-audio`](crates/audio/README.md): audio file I/O and codecs (WAV, AIFF, FLAC, AAC, Opus,
AC-3/E-AC-3, MP1/MP2, MP3 encoding), streaming and seeking, and packet decoding for any demuxer. See its
README for formats and features.
- [`craft-latex`](crates/latex/README.md): LaTeX documents read (the everyday subset) and written (a standalone article), to and from the craft-flow model.
- [`craft-markdown`](crates/markdown/README.md): Markdown read and written (a CommonMark subset with GitHub tables and strikethrough), to and from the craft-flow model.
- [`craft-math`](crates/math/README.md): equations as one tree (the Office Math object model) with its syntaxes, read and written: OMML, presentation MathML, LaTeX math and the UnicodeMath linear format.
- [`craft-media`](crates/media/README.md): bit-level I/O (`bitstream`), clean-room MP4/MOV
(`isobmff`), Matroska/WebM (`matroska`) and MXF (`mxf`) demuxers and muxers, Ogg (`ogg`), AVI (`avi`) and
MPEG-TS/PS (`mpegts`) demuxers, from FilmCraft, and an ISO BMFF box reader. Containers only; codecs are in `craft-audio`, and
video codecs will go in a separate crate.
- [`craft-lottie`](crates/lottie/README.md): Lottie (Bodymovin) JSON: the document model of
lottie-spec 1.0 (animation, assets, layers by type, shape items, masks, effects, text, markers)
with a bounded reader and a writer that keep what they do not know, and the encodings of its
values (keyframes, ease tangents, bezier paths, gradients, data URIs). From EffectCraft; mapping
onto an app's document stays in the app.
- [`craft-menu`](crates/menu/README.md): an app's menus as a macOS menu bar: the Mac layout
(app menu, Window, Help, system-key clashes), a platform backend trait, and key equivalents
fed back to egui as the input egui-winit would have made. Commands and their enabled state
stay in each app.
- [`craft-mesh`](crates/mesh/README.md): 3D mesh file formats behind one neutral model (meshes
of polygons with per-corner indices, materials, a node hierarchy): STL, OBJ with MTL, PLY,
glTF 2.0 / GLB and 3MF, one feature each. Readers are bounded by `Limits`, never open a file themselves
glTF 2.0 / GLB and FBX, one feature each. Readers are bounded by `Limits`, never open a file themselves
and never panic. Carved from EffectCraft, SolidCraft, TextureCraft and MaterialCraft.
- [`craft-midi`](crates/midi/README.md): Standard MIDI Files: a bounded reader for formats 0, 1 and
2 and a format-1 writer, over a neutral model of notes and channel events in ticks at 960 per
quarter note. From SoundCraft.
- [`craft-mime`](crates/mime/README.md): Internet messages and MIME, read and written: RFC 5322
header fields, MIME parts and multiparts, encoded-words, RFC 2231 parameters, base64 and
quoted-printable, character sets, address lists, dates, mbox files and the `multipart/related`
lookups of MHT web archives. What a message means (body, attachments, flags) stays in each app.
- [`craft-openpgp`](crates/openpgp/README.md): OpenPGP as mail carries it: PGP/MIME and cleartext
Digital signatures checked, attached Public keys and `Autocrypt:` headers read, a secret key
file inspected without using it. Built on rPGP; no I/O, and every size and count is capped.
- [`craft-odf`](crates/odf/README.md): OpenDocument packages (ODF 1.3 Part 2), read and written: the ZIP container with its `mimetype` and manifest within limits, password protection (AES-256-CBC with PBKDF2, as LibreOffice writes it) and flat single-file documents. With the `text` feature, OpenDocument Text documents read into and written from the craft-flow model.
- [`craft-prc`](crates/prc/README.md): a reader for PRC (ISO 14739-1), the 3D model format of PDF 3D
annotations: container, bit-level primitives, schema, tessellations and the product tree as
placed, coloured triangle meshes and a model tree. Bounded on hostile input. From PdfCraft;
rendering stays in the app.
- [`craft-offcrypto`](crates/offcrypto/README.md): clean-room Office document cryptography ([MS-OFFCRYPTO]): password-encrypted OOXML packages on `craft-cfb` (agile and standard encryption read, with the integrity check enforced; agile written), unsupported schemes named, and the password hashes of document and sheet protection.
- [`craft-ods`](crates/ods/README.md): OpenDocument spreadsheets (`.ods`, `.ots`) on `craft-odf`: the tables of `content.xml` with typed values, displayed text, formulas as text, style names, repeats expanded and merged cells, with dates and durations as serial numbers. Bounded cells, merges and text; strict XML.
- [`craft-opc`](crates/opc/README.md): Open Packaging Conventions, the ZIP container of DOCX, XLSX and PPTX
files: bounded readers (every part up front, or on demand), part names, relationships, content
types and a deterministic package writer. What the parts hold stays with each format's crate.
- [`craft-pcraft-format`](crates/pcraft-format/README.md): the envelope of PhotoCraft's `.pcraft`
bundle: `Manifest<D>` with the document as a type parameter, `TileRef`, the entry paths, the
manifest decode limits and the migration runner. The document model stays in PhotoCraft.
- [`craft-pkcs7`](crates/pkcs7/README.md): the formats of digital signatures, read, verified and
written: ASN.1 DER, X.509 certificates and chains, CMS SignedData (PKCS #7), PKCS #12 identity
files, RFC 3161 timestamps, and CRL / OCSP revocation evidence. What a signature means for a
document or a message stays in each app.
- [`craft-penpot`](crates/penpot/README.md): clean-room reader and writer for the Penpot 2.x export
container (`.penpot`): the ZIP archive, its manifest, the per-file, per-page and per-shape JSON
members and media objects, as the JSON the file holds. Bounded on hostile input. Carved from
FigCraft.
- [`craft-plotter`](crates/plotter/README.md): cutter and pen-plotter command languages: HP-GL,
DMPL and GP-GL (plain and the Silhouette dialect, three generations, registration marks) from a
job in millimetres, plus the Silhouette device queries and reply parsers. No I/O.
- [`craft-pptx`](crates/pptx/README.md): PresentationML, the model of a `.pptx` presentation:
masters, layouts, slides, shapes, placeholders and their inheritance, transitions and animations,
comments, sections, media and kept parts. From DeckCraft. DrawingML comes from `craft-drawingml`.
- [`craft-print`](crates/print/README.md): PDF submission to CUPS and Windows, printer discovery,
duplex/copies/colour and driver preferences. PDF generation stays in each app.
- [`craft-proof`](crates/proof/README.md): proofing per language (spelling, suggestions, grammar,
hyphenation, a Hunspell reader, user words, Language packs). The word lists and patterns are
craft-i18n's `language-data/`, embedded at build time from `CRAFT_I18N_DIR`: English and the
carry-over locales by default, the set `CRAFT_PROOF_EMBED` names otherwise (`en` for English
only); other languages come from installed Language packs.
- [`craft-pst`](crates/pst/README.md): Outlook personal folders files (`.pst`, [MS-PST]) read over any
`Read + Seek`, from MailCraft: the node database, property and table contexts, folders, messages,
recipients, attachments, attached messages and named properties, ANSI and Unicode, encoded or not,
with a password. Salvages damaged files. Bounded and panic-free on hostile input. What an item
means stays in each app.
- [`craft-quit`](crates/quit/src/lib.rs): native macOS quit, egui close handling and an optional
app menu. Unsaved-document decisions and save prompts stay in each app.
- [`craft-rtf`](crates/rtf/README.md): Rich Text Format: a tokenizer, text decoding in the file's code pages
(`\uN`, `\'hh`, single-byte and East Asian multibyte pages), escaping and dates, and a reader and writer
for a small neutral model (paragraphs, character formatting, outline levels, tables).
- [`craft-settings`](crates/settings/README.md): `config.toml` settings storage for every app: platform folders, portable mode and overrides, atomic saves while running, backup, damaged-file recovery and schema migrations. Policy in [docs/settings-storage.md](docs/settings-storage.md).
- [`craft-sheet`](crates/sheet/README.md): spreadsheet vocabulary shared by `craft-xls`, `craft-xlsx` and `craft-ods`: cell positions and A1 text, cell values and error values, sheet-name quoting, Excel's built-in number formats and indexed colour palette. Not a file format; no dependencies.
- [`craft-sf2`](crates/sf2/README.md): SoundFont 2 (`.sf2`) reader: the sample pool and, per preset, the key and velocity regions a note sounds, with tuning, loop points, pan, level and volume envelope resolved from the preset and instrument zones. Bounded on hostile input. From LoopCraft.
- [`craft-silhouette-studio`](crates/silhouette-studio/src/lib.rs): bounded, fail-closed reader for Silhouette Studio `.studio` and `.studio3` documents: outlines, line colours and page size in millimetres. Protected designs are refused.
- [`craft-stencilcraft-format`](crates/stencilcraft-format/README.md): the versioned `.stencilcraft` JSON wire schema and envelope: required members, version 1 defaults, optional fields, and header checks.
- `craft-stencilcraft-document`: StencilCraft's typed document model, geometry helpers, validation, and native `.stencilcraft` codec.
- [`craft-sketch`](crates/sketch/README.md): clean-room reader for the `.sketch` container (Sketch 48 and newer): the ZIP archive, the version cut, `document.json`, the pages in document order and images, as the JSON the file holds. Bounded on hostile input. Carved from FigCraft.
- [`craft-svg`](crates/svg/src/lib.rs): SVG. `sniff` recognises SVG and SVGZ data; `svgz` unpacks
SVGZ within a byte limit, decodes UTF-8, UTF-16 and ISO 8859-1, and compresses; `guard` bounds
element nesting and entity expansion before any XML reader sees the text; `paths` reads geometry
(shapes, transforms, `<use>`/`<symbol>` instances and the CSS cascade as Bézier paths in
millimetres, each tagged by the caller); `color` parses CSS colours; `write` writes documents
(elements with escaping, path data, numbers). Feature `tree`: the full parser, usvg at the one
version every Craft app uses, re-exported behind an entry point that runs those checks first
(plus nesting with references followed, attribute counts, bounded embedded SVGs), and a budget
check for drawing a tree with resvg. Apps take usvg from here, not as their own dependency.
- [`craft-svg-paths`](crates/svg-paths/src/lib.rs): the former name of `craft-svg`'s `paths`,
`color` and `write`; re-exports them for existing users.
- [`craft-text`](crates/text/README.md): text processing below the composer. Its `hyphen` module finds
hyphenation points, with a bundled US English dictionary and patterns and optional hypher patterns
for 47 more languages (one cargo feature each).
- [`craft-ui`](crates/ui/README.md): SVG catalogs, icon buttons, tabs, pane controls, transactional docking, print settings and theme helpers for egui frontends;
assets, themes, localization and command handling stay in each app. Requires Rust 1.95 or later.
- [`craft-vcard`](crates/vcard/README.md): vCard contacts, from MailCraft: vCard 2.1, 3.0 and 4.0 read
(legacy character sets, quoted-printable, labels and Apple label groups, `KEY` certificates and
OpenPGP public keys), vCard 3.0 written. Bounded and panic-free on hostile input. The mapping onto
an app's contact type stays in each app.
- [`craft-vectorcraft-format`](crates/vectorcraft-format/README.md): the envelope of VectorCraft's
`.vectorcraft` file: its members, versions, embedded images and the data after the JSON, with the
document as a type parameter. The document and its migrations stay in VectorCraft.
- [`craft-vectordrawable`](crates/vectordrawable/src/lib.rs): Android Vector Drawable writer: a model of
paths, groups, clip outlines, strokes and linear, radial and sweep gradients; the XML as Android
Studio formats it; and the mapping of a gradient on any affine frame to what a drawable can say.
What a drawable cannot draw is the caller's to bake in or leave out. No reader.
- [`craft-web-api`](crates/web-api/README.md): the page command API every Craft web build offers its page — one
`window.<app>` shape (`request`, `execute`, `commands`, `docInspect`, `uiInspect`, `screenshot`) over the app's
JSON control channel.
- [`craft-web-host`](crates/web-host/README.md): the host messages between a Craft app's web build and the page that hosts it (`?host=parent` or `data-host="page"`): one contract and one bridge for every app.
- [`craft-webp`](crates/webp/src/lib.rs): the WebP container, from EffectCraft (reader) and
PhotoCraft (writer): canvas size, alpha and every animation frame's timing from the chunk
headers without decoding, and the RIFF container around an encoded VP8 frame with alpha, ICC,
EXIF and XMP chunks. The VP8 and VP8L codecs are not part of it.
- [`craft-xls`](crates/xls/README.md): clean-room Excel 97-2003 workbook (`.xls`, BIFF8) reader: worksheets, cell values, formulas as A1 text (shared and array formulas included), cell formats with resolved palette colours, merged cells, column and row records, defined names, print areas and calculation settings, with limits on records, cells and text.
- [`craft-wordmodel`](crates/wordmodel/README.md): a word-processing document model (stories, paragraphs,
runs, tables, sections, styles, numbering, fields, notes, comments, revisions, drawings, math): what the
text-format crates read into and write from. WordCraft's model without its editing code.
- [`craft-xlsx`](crates/xlsx/README.md): Excel workbooks (`.xlsx`, `.xlsm`, SpreadsheetML, transitional and strict) and binary workbooks (`.xlsb`) on `craft-opc`: the workbook part, shared strings, the styles tables and worksheet rows streamed one at a time, with limits on the package, the XML and the binary records.
- [`craft-ora`](crates/ora/README.md): OpenRaster documents (`.ora`): the ZIP archive and the `stack.xml` layer tree as written, read with bounded sizes and written. From PhotoCraft.
- [`craft-y4m`](crates/y4m/src/lib.rs): YUV4MPEG2 (`.y4m`) reader, from FilmCraft: the stream
header, colour space layouts at 8 to 16 bits, a frame index built from the `FRAME` lines without
loading the file, and plane access. Bounded on hostile input.
- [`craft-kra`](crates/kra/README.md): Krita documents (`.kra`, `.krz`), read: the ZIP archive, the `maindoc.xml` node tree as written, and the tiled pixel files with their LZF compression, a tile at a time. From PhotoCraft.
- [`craft-xcf`](crates/xcf/README.md): GIMP XCF images (`.xcf`, `.xcf.gz`), read: header, properties, parasites, layers with their item paths, channels, and tiled pixels (uncompressed, RLE, zlib) at every precision, under a caller's byte budget. From PhotoCraft.
- [`craft-xml`](crates/xml/README.md): bounded XML for hostile input: an owned element tree with limits on size, depth, nodes and attributes, streaming of repeated elements, namespace handling (as written, by local name, or canonical prefixes by URI), escaping and a writer. No DTDs and no entity expansion.
- [`craft-zip`](crates/zip/README.md): ZIP archives from untrusted files: an entry-count check before the archive is indexed (ZIP64 included), entry reads within per-entry and total budgets that count real bytes, duplicate-name detection, a strict structure preflight, and a deterministic stored/deflate writer. The shared ZIP layer for the package formats.
- [Shared UI component audit](docs/ui-components-audit.md): source inventory, extraction priorities
and compatibility boundaries across the Craft suite.
- [Theme infrastructure](docs/theme-infrastructure.md): eight-app comparison and the small shared
+4
View File
@@ -2,3 +2,7 @@ allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
allow-indexing-slicing-in-tests = true
cognitive-complexity-threshold = 30
disallowed-types = [
{ path = "egui::ComboBox", reason = "use craft_ui::ComboBox: egui's combo box menu can't grow back while open (egui#5225)" },
]
+18
View File
@@ -0,0 +1,18 @@
[package]
name = "craft-aaf"
description = "Clean-room AAF (Edit Protocol, structured storage) and OMF Interchange 2.0 (Bento) readers and writers over one mob-style composition model, with embedded PCM essence."
version.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true
repository.workspace = true
[lints]
workspace = true
[dependencies]
craft-cfb = { workspace = true }
craft-timeline = { workspace = true }
# WAV and AIFF around embedded PCM essence: the one WAV/AIFF implementation, not a second one here.
craft-audio = { workspace = true, features = ["decode-native", "pcm-encode"] }
thiserror = { workspace = true }
+67
View File
@@ -0,0 +1,67 @@
# craft-aaf
AAF and OMF, the two mob-based editorial interchange formats, read and written through one
composition model.
| Module | What |
|---|---|
| `model` | `Document`: compositions (tracks of fillers, source clips and overlapping transitions; clip gain, constant or keyframed; markers; start timecode), nested compositions, and the media `Source`s they reference (file path or embedded PCM, picture size and rate, sound channels / rate / bits, start timecode, markers). Times are exact `craft_timeline::time::Tick`s. |
| `aaf` | `read`, `write`, `sniff`: AAF Edit Protocol in structured storage (`craft-cfb`). |
| `omf` | `read`, `write`, `sniff`: OMF Interchange 2.0 in a Bento container. Sound only. |
No file I/O: documents are bytes and media references are strings. An application maps its own
timeline onto `model` once and gets both formats. Embedded audio is PCM in the model; the WAVE and
AIFF wrappers the formats use come from `craft-audio`.
## Specifications
Clean-room: written from public specifications only. The AAF SDK, pyaaf2, the OMF Toolkit and
other implementations were not consulted. Where a specification leaves a layout open (how a
nested sequence is written, how several video tracks share a slot), what Premiere Pro does was
read off files it exports.
| Format | Document | Edition | Used for |
|---|---|---|---|
| AAF | AMWA *AAF Object Specification* | v1.1 (2005) | classes, properties, mob / slot / segment model, sequences and transitions, operation groups, parameters, definitions, descriptors, locators, essence data |
| AAF | AMWA *AAF Low-Level Container Specification* | v1.0.1 | objects as structured storages, `properties` streams, stored forms, strong / weak reference collections and their index streams, `referenced properties` |
| AAF | AMWA *AAF Edit Protocol* | v1.0 (AMWA AS-01) | top-level composition, mob chains (composition → master → file → physical source), operation definitions, usage codes |
| AAF | SMPTE RP 224 / RP 210 registers | — | data definition, class and type labels |
| AAF | Microsoft [MS-CFB] | rev. 10.0 | the container, see `craft-cfb` |
| OMF | Avid *OMF Interchange Specification* | Version 2.0 (1997) | classes (`HEAD`, `CMOB`, `MMOB`, `SMOB`, `MSLT`, `TRKD`, `SEQU`, `SCLP`, `FILL`, `TRAN`, `EFFE`, `ESLT`, `CVAL`, `VVAL`, `TCCP`, `WAVD`, `AIFD`, `WAVE`, `AIFC`, locators), property and type names |
| OMF | Apple *Bento Specification* | revision 1.0d5 | container label, TOC encoding, objects / properties / types, references |
## What is read and written
AAF: a top-level composition mob with a timecode slot, a timeline slot per track (sequences of
fillers, source clips and transitions; `VideoDissolve`, `VideoFadeToBlack`, `SMPTEVideoWipe`,
`MonoAudioDissolve`), clip gain as a `MonoAudioGain` operation group with a constant or varying
amplitude, markers as comment markers in an event slot, a composition mob for every nested
composition, and per media item a master mob, file source mobs (CDCI or PCM descriptor with a
network locator, or `EssenceData` with embedded PCM) and a tape source mob with the start
timecode. The reader also takes sequences inside sequences, selectors, essence groups, legacy data
definitions, and Premiere Pro's layout (all video tracks as layers of one slot, nested compositions
tagged top-level). 512-byte or 4096-byte sectors.
OMF: a composition mob with a timecode slot and a sound slot per track, in samples; transitions as
`SimpleMonoAudioDissolve`; gain as `MonoAudioGain`; master, file (`WAVD` / `AIFD`, embedded `WAVE`
data or a locator) and tape mobs.
Not represented: speed changes, video effects other than transitions, OMF picture and markers.
Private tags, first written by FilmCraft and kept so existing files read back: AAF tagged values
`FilmCraft Effect`, `FilmCraft Frame Size`, `FilmCraft Audio Sample Rate`; OMF properties
`FilmCraft:SCLP:ClipName`, `FilmCraft:EFFE:EffectID`.
## Hostile input
A damaged or crafted file gives an error or a report entry, never a panic, a hang or an allocation
sized by a count in the file: weak-collection counts are checked against the index stream, zero-size
keys are refused, a storage owned twice is an error, nesting of segments and of compositions is
bounded, times are clamped to about three days. `src/aaf/hostile_tests.rs` and
`src/roundtrip_tests.rs` (truncation at every 97th byte, 400 random 8-byte corruptions per format)
cover them.
## Origin
Moved from FilmCraft's `filmcraft-interchange` (`aaf`, `omf`, the model types of `comp`). The
mapping between the model and an application's project stays in the application.
+84
View File
@@ -0,0 +1,84 @@
//! AAF (Advanced Authoring Format) import and export, following the AAF Edit Protocol.
//!
//! Written from the public AMWA specifications: *AAF Object Specification v1.1*, *AAF Low-Level
//! Container Specification v1.0.1* (structured storage mapping, see [`store`]) and *AAF Edit
//! Protocol v1.0*; the container is Microsoft's Compound File Binary format ([`craft_cfb`]).
//!
//! A written file holds one top-level **CompositionMob** (Edit Protocol usage code
//! "top level") with
//!
//! - a timecode slot (sequence start timecode, rounded rate, drop frame),
//! - one timeline slot per video track (picture) and per audio track (sound; one per channel when
//! broken out to mono), each a **Sequence** of **Filler**s, **SourceClip**s and **Transition**s
//! (Cross Dissolve → `VideoDissolve_2`, Dip to Black → `VideoFadeToBlack`, audio crossfades →
//! `MonoAudioDissolve`; the model's transition name is kept in a tagged value),
//! - clip volume as a `MonoAudioGain` **OperationGroup** around the source clip with an
//! `Amplitude` **ConstantValue** or **VaryingValue** (keyframes as control points),
//! - sequence markers as **CommentMarker**s in an event slot;
//!
//! a **CompositionMob** without a usage code for every nested sequence, built the same way (a
//! clip of the nested sequence is a **SourceClip** that points at that mob, at its first slot of
//! the clip's kind, with its start in that slot's edit units; Premiere Pro writes nested sequences
//! this way);
//!
//! and for every media item a **MasterMob**, a file **SourceMob** per essence (a CDCI or PCM
//! descriptor with a network locator to the file, or `EssenceData` holding embedded PCM) and a
//! tape **SourceMob** carrying the media's start timecode. Clip and media markers become comment
//! markers on the master mob.
//!
//! Import reads the same structures (and the common variations: sequences inside sequences,
//! selectors, operation groups around clips, legacy data definitions, essence groups, and Premiere
//! Pro's one video slot holding a nested scope with a segment per video track) into the model:
//! compositions (one that others use is a nested composition), sources (with their path, or their
//! embedded audio as PCM) and markers.
//!
//! Private tags. Three tagged values are not in any register; they were first written by FilmCraft
//! and keep their names so that existing files read back: `FilmCraft Effect` (a transition's
//! name), `FilmCraft Frame Size` and `FilmCraft Audio Sample Rate` (on the composition).
mod ids;
mod read;
pub(crate) mod store;
mod write;
use crate::model::Document;
use crate::{Identity, Report, Result};
/// How to write an AAF file.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct WriteOptions<'a> {
pub identity: Identity<'a>,
/// Write 512-byte sectors (compound file version 3) instead of 4096-byte sectors.
pub small_sectors: bool,
}
/// Write `doc` as an AAF file: its first composition is the top-level one, with every nested
/// composition and every source it uses. Times that are not on whole edit units are rounded and
/// reported.
pub fn write(doc: &Document, opts: &WriteOptions<'_>, report: &mut Report) -> Result<Vec<u8>> {
let version = if opts.small_sectors { craft_cfb::Version::V3 } else { craft_cfb::Version::V4 };
write::write(doc, version, &opts.identity, report)
}
/// Read an AAF file: its top-level compositions, the compositions nested in them and their
/// sources. What cannot be represented is skipped and named in `report`.
pub fn read(bytes: &[u8], report: &mut Report) -> Result<Document> {
read::read(bytes, report)
}
/// Whether `bytes` look like an AAF file (a compound file whose root has the AAF root class or a
/// `Header-2` storage).
pub fn sniff(bytes: &[u8]) -> bool {
if !craft_cfb::sniff(bytes) {
return false;
}
match craft_cfb::CompoundFile::open(bytes) {
Ok(cf) => cf.root().clsid == ids::ROOT || cf.find("Header-2").is_ok(),
Err(_) => false,
}
}
#[cfg(test)]
mod hostile_tests;
#[cfg(test)]
mod tests;
+110
View File
@@ -0,0 +1,110 @@
//! Hostile object trees: a crafted file must give an error, never a crash, a hang or an
//! allocation sized by a count in the file (AGENTS.md §0).
use craft_cfb::{Version, Writer};
use super::store::{self, SF_STRONG_VECTOR, SF_WEAK_SET, SF_WEAK_VECTOR, Value, utf16z};
const PID: u16 = 0x0007;
/// A root object whose one property `PID` is a weak reference vector or set (stored form `sf`)
/// named `Keys`, with `index` as its `Keys index` stream.
fn weak_collection_file(sf: u16, index: Vec<u8>) -> Vec<u8> {
let name = utf16z("Keys");
// byte order 'L', format version, 1 entry { pid, stored form, value length }, the value
let mut props = vec![0x4C, 0x20];
for x in [1, PID, sf, name.len() as u16] {
props.extend_from_slice(&x.to_le_bytes());
}
props.extend_from_slice(&name);
let mut w = Writer::new(Version::V3);
w.stream(Writer::ROOT, "properties", props).unwrap();
w.stream(Writer::ROOT, "Keys index", index).unwrap();
w.finish()
}
/// A weak collection index: u32 count, u16 tag, u16 key pid, u8 key size, then the keys.
fn index(count: u32, size: u8, keys: &[u8]) -> Vec<u8> {
let mut v = count.to_le_bytes().to_vec();
v.extend_from_slice(&0u16.to_le_bytes());
v.extend_from_slice(&0x1B01u16.to_le_bytes());
v.push(size);
v.extend_from_slice(keys);
v
}
fn read_keys(sf: u16, index: Vec<u8>) -> Result<Vec<Vec<u8>>, String> {
match store::read(&weak_collection_file(sf, index))?.get(PID) {
Some(Value::WeakVec(_, _, keys)) => Ok(keys.clone()),
other => panic!("not a weak collection: {other:?}"),
}
}
/// With a key size of 0 every key fits, so the count alone drove the loop: up to 4.29 billion
/// empty keys (about 100 GB) from a 9-byte index. A million is enough to show it, cheaply.
#[test]
fn zero_size_weak_collection_keys_are_an_error() {
for sf in [SF_WEAK_VECTOR, SF_WEAK_SET] {
match read_keys(sf, index(1_000_000, 0, &[])) {
Err(e) => assert!(e.contains("zero-size"), "{e}"),
Ok(keys) => panic!("read {} empty keys instead of an error", keys.len()),
}
}
}
#[test]
fn weak_collection_count_beyond_the_index_is_an_error() {
for sf in [SF_WEAK_VECTOR, SF_WEAK_SET] {
let e = read_keys(sf, index(u32::MAX, 4, &[1, 2, 3, 4, 5, 6, 7, 8])).unwrap_err();
assert!(e.contains("short weak collection index"), "{e}");
}
}
#[test]
fn weak_collections_within_the_index_are_read() {
for sf in [SF_WEAK_VECTOR, SF_WEAK_SET] {
assert_eq!(read_keys(sf, index(0, 0, &[])).unwrap(), Vec::<Vec<u8>>::new());
assert_eq!(read_keys(sf, index(2, 4, &[1, 2, 3, 4, 5, 6, 7, 8])).unwrap(), [vec![1, 2, 3, 4], vec![5, 6, 7, 8]]);
}
}
/// A strong vector whose entries all name the same child storage would rebuild that subtree once
/// per entry; a storage has one owner, so the repeat is an error.
#[test]
fn a_storage_owned_twice_is_an_error() {
let name = utf16z("Items");
let mut props = vec![0x4C, 0x20];
for x in [1, PID, SF_STRONG_VECTOR, name.len() as u16] {
props.extend_from_slice(&x.to_le_bytes());
}
props.extend_from_slice(&name);
// count, next free key, last key, then the entry keys
let mut idx = 3u32.to_le_bytes().to_vec();
idx.extend_from_slice(&[0; 8]);
for _ in 0..3 {
idx.extend_from_slice(&1u32.to_le_bytes());
}
let mut w = Writer::new(Version::V3);
w.stream(Writer::ROOT, "properties", props).unwrap();
w.stream(Writer::ROOT, "Items index", idx).unwrap();
let child = w.storage(Writer::ROOT, "Items{1}", [0; 16]).unwrap();
w.stream(child, "properties", vec![0x4C, 0x20, 0, 0]).unwrap();
let e = store::read(&w.finish()).unwrap_err();
assert!(e.contains("more than one reference"), "{e}");
}
/// Objects nest through strong references; a chain deeper than the reader follows is an error,
/// and one within it reads.
#[test]
fn objects_nested_too_deeply_are_an_error() {
let chain = |depth: usize| {
let mut o = store::Obj::new([1; 16]);
for _ in 0..depth {
o = store::Obj::new([1; 16]).with(PID, Value::Strong(Box::new(o)));
}
store::write(&o, Version::V4).unwrap()
};
assert!(store::read(&chain(150)).is_ok());
let e = store::read(&chain(250)).unwrap_err();
assert!(e.contains("nested too deeply"), "{e}");
}
+262
View File
@@ -0,0 +1,262 @@
//! Class ids, property ids and definition ids of the AAF object model subset read and
//! writes (AAF Object Specification v1.1, AAF Edit Protocol). Class and data definition AUIDs are
//! SMPTE labels (RP 224 / RP 210 registers) in AUID byte order; property ids are the AAF / ST 377-1
//! local tags.
use super::store::Auid;
/// AUID of a SMPTE universal label: the label's last 8 bytes become Data1–Data3 (stored
/// little-endian), its first 8 bytes Data4.
pub(crate) const fn ul(b: [u8; 16]) -> Auid {
[b[11], b[10], b[9], b[8], b[13], b[12], b[15], b[14], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]]
}
/// A GUID `{d1-d2-d3-d4}` in AUID byte order.
pub(crate) const fn guid(d1: u32, d2: u16, d3: u16, d4: [u8; 8]) -> Auid {
let a = d1.to_le_bytes();
let b = d2.to_le_bytes();
let c = d3.to_le_bytes();
[a[0], a[1], a[2], a[3], b[0], b[1], c[0], c[1], d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]]
}
/// Class AUID: SMPTE label 06.0E.2B.34.02.06.01.01.0D.01.01.01.01.01.xx.00.
pub(crate) const fn class(xx: u8) -> Auid {
ul([0x06, 0x0E, 0x2B, 0x34, 0x02, 0x06, 0x01, 0x01, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, xx, 0x00])
}
/// The root object's class (the storage class of the file's root).
pub(crate) const ROOT: Auid = guid(0xB3B398A5, 0x1C90, 0x11D4, [0x80, 0x53, 0x08, 0x00, 0x36, 0x21, 0x08, 0x04]);
/// The meta-dictionary (class 0x25 of the meta-model, 06.0E.2B.34.02.06.01.01.0D.01.01.01.02.25.00.00).
pub(crate) const META_DICTIONARY: Auid = ul([0x06, 0x0E, 0x2B, 0x34, 0x02, 0x06, 0x01, 0x01, 0x0D, 0x01, 0x01, 0x01, 0x02, 0x25, 0x00, 0x00]);
#[allow(dead_code)]
pub(crate) mod cls {
use super::class;
use crate::aaf::store::Auid;
pub const COMMENT_MARKER: Auid = class(0x08);
pub const FILLER: Auid = class(0x09);
pub const OPERATION_GROUP: Auid = class(0x0A);
pub const NESTED_SCOPE: Auid = class(0x0B);
pub const SCOPE_REFERENCE: Auid = class(0x0D);
pub const SELECTOR: Auid = class(0x0E);
pub const SEQUENCE: Auid = class(0x0F);
pub const SOURCE_CLIP: Auid = class(0x11);
pub const TIMECODE: Auid = class(0x14);
pub const TRANSITION: Auid = class(0x17);
pub const CONTENT_STORAGE: Auid = class(0x18);
pub const CONTROL_POINT: Auid = class(0x19);
pub const DATA_DEFINITION: Auid = class(0x1B);
pub const OPERATION_DEFINITION: Auid = class(0x1C);
pub const PARAMETER_DEFINITION: Auid = class(0x1D);
pub const CONTAINER_DEFINITION: Auid = class(0x20);
pub const INTERPOLATION_DEFINITION: Auid = class(0x21);
pub const DICTIONARY: Auid = class(0x22);
pub const ESSENCE_DATA: Auid = class(0x23);
pub const CDCI_DESCRIPTOR: Auid = class(0x28);
pub const TAPE_DESCRIPTOR: Auid = class(0x2E);
pub const HEADER: Auid = class(0x2F);
pub const IDENTIFICATION: Auid = class(0x30);
pub const NETWORK_LOCATOR: Auid = class(0x32);
pub const COMPOSITION_MOB: Auid = class(0x35);
pub const MASTER_MOB: Auid = class(0x36);
pub const SOURCE_MOB: Auid = class(0x37);
pub const EVENT_MOB_SLOT: Auid = class(0x39);
pub const TIMELINE_MOB_SLOT: Auid = class(0x3B);
pub const CONSTANT_VALUE: Auid = class(0x3D);
pub const VARYING_VALUE: Auid = class(0x3E);
pub const TAGGED_VALUE: Auid = class(0x3F);
pub const DESCRIPTIVE_MARKER: Auid = class(0x41);
pub const PCM_DESCRIPTOR: Auid = class(0x48);
pub const IMPORT_DESCRIPTOR: Auid = class(0x4A);
/// Classes with a `Locator` and media properties read as file descriptors.
pub const WAVE_DESCRIPTOR: Auid = class(0x2C);
pub const AIFC_DESCRIPTOR: Auid = class(0x26);
pub const SOUND_DESCRIPTOR: Auid = class(0x42);
pub const RGBA_DESCRIPTOR: Auid = class(0x29);
pub const MULTIPLE_DESCRIPTOR: Auid = class(0x44);
}
/// Property ids.
#[allow(dead_code)]
pub(crate) mod pid {
// Root
pub const ROOT_META_DICTIONARY: u16 = 0x0001;
pub const ROOT_HEADER: u16 = 0x0002;
// MetaDictionary and MetaDefinition
pub const META_CLASS_DEFINITIONS: u16 = 0x0003;
pub const META_TYPE_DEFINITIONS: u16 = 0x0004;
pub const META_IDENTIFICATION: u16 = 0x0005;
// Header
pub const BYTE_ORDER: u16 = 0x3B01;
pub const LAST_MODIFIED: u16 = 0x3B02;
pub const CONTENT: u16 = 0x3B03;
pub const DICTIONARY: u16 = 0x3B04;
pub const VERSION: u16 = 0x3B05;
pub const IDENTIFICATION_LIST: u16 = 0x3B06;
pub const OBJECT_MODEL_VERSION: u16 = 0x3B07;
pub const OPERATIONAL_PATTERN: u16 = 0x3B09;
// Identification
pub const COMPANY_NAME: u16 = 0x3C01;
pub const PRODUCT_NAME: u16 = 0x3C02;
pub const PRODUCT_VERSION_STRING: u16 = 0x3C04;
pub const PRODUCT_ID: u16 = 0x3C05;
pub const DATE: u16 = 0x3C06;
pub const PLATFORM: u16 = 0x3C08;
pub const GENERATION_AUID: u16 = 0x3C09;
// ContentStorage
pub const MOBS: u16 = 0x1901;
pub const ESSENCE_DATA: u16 = 0x1902;
// Dictionary
pub const OPERATION_DEFINITIONS: u16 = 0x2603;
pub const PARAMETER_DEFINITIONS: u16 = 0x2604;
pub const DATA_DEFINITIONS: u16 = 0x2605;
pub const CONTAINER_DEFINITIONS: u16 = 0x2608;
pub const INTERPOLATION_DEFINITIONS: u16 = 0x2609;
// DefinitionObject
pub const IDENTIFICATION: u16 = 0x1B01;
pub const NAME: u16 = 0x1B02;
pub const DESCRIPTION: u16 = 0x1B03;
// OperationDefinition
pub const OPDEF_DATA_DEFINITION: u16 = 0x1E01;
pub const OPDEF_IS_TIME_WARP: u16 = 0x1E02;
pub const OPDEF_NUMBER_INPUTS: u16 = 0x1E07;
pub const OPDEF_PARAMETERS_DEFINED: u16 = 0x1E09;
// ParameterDefinition
pub const PARAMDEF_DISPLAY_UNITS: u16 = 0x1F03;
// Mob
pub const MOB_ID: u16 = 0x4401;
pub const MOB_NAME: u16 = 0x4402;
pub const SLOTS: u16 = 0x4403;
pub const MOB_LAST_MODIFIED: u16 = 0x4404;
pub const MOB_CREATION_TIME: u16 = 0x4405;
pub const MOB_USER_COMMENTS: u16 = 0x4406;
pub const USAGE_CODE: u16 = 0x4408;
// SourceMob
pub const ESSENCE_DESCRIPTION: u16 = 0x4701;
// MobSlot
pub const SLOT_ID: u16 = 0x4801;
pub const SLOT_NAME: u16 = 0x4802;
pub const SEGMENT: u16 = 0x4803;
pub const PHYSICAL_TRACK_NUMBER: u16 = 0x4804;
// TimelineMobSlot / EventMobSlot
pub const EDIT_RATE: u16 = 0x4B01;
pub const ORIGIN: u16 = 0x4B02;
pub const EVENT_EDIT_RATE: u16 = 0x4901;
// Component
pub const DATA_DEFINITION: u16 = 0x0201;
pub const LENGTH: u16 = 0x0202;
pub const COMPONENT_USER_COMMENTS: u16 = 0x0204;
// Sequence
pub const COMPONENTS: u16 = 0x1001;
// SourceReference / SourceClip
pub const SOURCE_ID: u16 = 0x1101;
pub const SOURCE_MOB_SLOT_ID: u16 = 0x1102;
pub const START_TIME: u16 = 0x1201;
// Event
pub const POSITION: u16 = 0x0601;
pub const COMMENT: u16 = 0x0602;
// Timecode
pub const TC_START: u16 = 0x1501;
pub const TC_FPS: u16 = 0x1502;
pub const TC_DROP: u16 = 0x1503;
// Transition
pub const OPERATION_GROUP: u16 = 0x1801;
pub const CUT_POINT: u16 = 0x1802;
// OperationGroup
pub const OPERATION: u16 = 0x0B01;
pub const INPUT_SEGMENTS: u16 = 0x0B02;
pub const PARAMETERS: u16 = 0x0B03;
// Selector / NestedScope
pub const SELECTED: u16 = 0x0F01;
pub const NESTED_SLOTS: u16 = 0x0C01;
// Parameter / ConstantValue / VaryingValue / ControlPoint
pub const PARAMETER_DEFINITION: u16 = 0x4C01;
pub const CONSTANT_VALUE: u16 = 0x4D01;
pub const INTERPOLATION: u16 = 0x4E01;
pub const POINT_LIST: u16 = 0x4E02;
pub const CP_VALUE: u16 = 0x1A02;
pub const CP_TIME: u16 = 0x1A03;
pub const CP_EDIT_HINT: u16 = 0x1A04;
// TaggedValue
pub const TAG_NAME: u16 = 0x5001;
pub const TAG_VALUE: u16 = 0x5003;
// EssenceDescriptor / FileDescriptor
pub const LOCATOR: u16 = 0x2F01;
pub const SAMPLE_RATE: u16 = 0x3001;
pub const FILE_LENGTH: u16 = 0x3002;
pub const CONTAINER_FORMAT: u16 = 0x3004;
pub const STORED_HEIGHT: u16 = 0x3202;
pub const STORED_WIDTH: u16 = 0x3203;
pub const FRAME_LAYOUT: u16 = 0x320C;
pub const VIDEO_LINE_MAP: u16 = 0x320D;
pub const IMAGE_ASPECT_RATIO: u16 = 0x320E;
pub const COMPONENT_WIDTH: u16 = 0x3301;
pub const HORIZONTAL_SUBSAMPLING: u16 = 0x3302;
pub const QUANTIZATION_BITS: u16 = 0x3D01;
pub const LOCKED: u16 = 0x3D02;
pub const AUDIO_SAMPLING_RATE: u16 = 0x3D03;
pub const CHANNELS: u16 = 0x3D07;
pub const AVERAGE_BPS: u16 = 0x3D09;
pub const BLOCK_ALIGN: u16 = 0x3D0A;
// NetworkLocator
pub const URL_STRING: u16 = 0x4001;
// EssenceData
pub const ESSENCE_MOB_ID: u16 = 0x2701;
pub const ESSENCE_STREAM: u16 = 0x2702;
}
/// Data definitions (SMPTE RP 224 labels 06.0E.2B.34.04.01.01.01.01.03.02.xx.yy).
pub(crate) mod ddef {
use super::{guid, ul};
use crate::aaf::store::Auid;
pub const PICTURE: Auid = ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00]);
pub const SOUND: Auid = ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00]);
pub const TIMECODE: Auid = ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00]);
pub const DESCRIPTIVE_METADATA: Auid = ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00]);
/// Pre-SMPTE ("legacy") data definitions written by older applications.
pub const LEGACY_PICTURE: Auid = guid(0x6F3C8CE1, 0x6CEF, 0x11D2, [0x80, 0x7D, 0x00, 0x60, 0x08, 0x14, 0x3E, 0x6F]);
pub const LEGACY_SOUND: Auid = guid(0x78E1EBE1, 0x6CEF, 0x11D2, [0x80, 0x7D, 0x00, 0x60, 0x08, 0x14, 0x3E, 0x6F]);
pub const LEGACY_TIMECODE: Auid = guid(0x7F275E81, 0x77E5, 0x11D2, [0x80, 0x7F, 0x00, 0x60, 0x08, 0x14, 0x3E, 0x6F]);
}
/// Operation, parameter, interpolation and container definitions.
pub(crate) mod def {
use super::guid;
use crate::aaf::store::Auid;
const AV: [u8; 8] = [0x8A, 0x09, 0x00, 0x60, 0x08, 0x14, 0x3E, 0x6F];
pub const VIDEO_DISSOLVE: Auid = guid(0x0C3BEA41, 0xFC05, 0x11D2, AV);
pub const VIDEO_FADE_TO_BLACK: Auid = guid(0x0C3BEA40, 0xFC05, 0x11D2, AV);
pub const SMPTE_VIDEO_WIPE: Auid = guid(0x0C3BEA43, 0xFC05, 0x11D2, AV);
pub const MONO_AUDIO_DISSOLVE: Auid = guid(0x0C3BEA44, 0xFC05, 0x11D2, AV);
const AG: [u8; 8] = [0x8A, 0x38, 0x00, 0x50, 0x04, 0x0E, 0xF7, 0xD2];
pub const MONO_AUDIO_GAIN: Auid = guid(0x9D2EA893, 0x0968, 0x11D3, AG);
const PD: [u8; 8] = [0x8A, 0x4C, 0x00, 0x50, 0x04, 0x0E, 0xF7, 0xD2];
pub const PARAM_LEVEL: Auid = guid(0xE4962320, 0x2267, 0x11D3, PD);
pub const PARAM_AMPLITUDE: Auid = guid(0xE4962321, 0x2267, 0x11D3, PD);
const IP: [u8; 8] = [0x80, 0xA9, 0x00, 0x60, 0x08, 0x14, 0x3E, 0x6F];
pub const INTERP_LINEAR: Auid = guid(0x5B6C85A4, 0x0EDE, 0x11D3, IP);
pub const INTERP_CONSTANT: Auid = guid(0x5B6C85A5, 0x0EDE, 0x11D3, IP);
const CD: [u8; 8] = [0x80, 0x9B, 0x00, 0x60, 0x08, 0x14, 0x3E, 0x6F];
pub const CONTAINER_AAF: Auid = guid(0x4313B571, 0xD8BA, 0x11D2, CD);
pub const CONTAINER_EXTERNAL: Auid = guid(0x4313B572, 0xD8BA, 0x11D2, CD);
/// Type ids of indirect values (SMPTE RP 210 type labels).
pub const TYPE_RATIONAL: Auid = super::ul([0x06, 0x0E, 0x2B, 0x34, 0x01, 0x04, 0x01, 0x01, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]);
pub const TYPE_STRING: Auid = super::ul([0x06, 0x0E, 0x2B, 0x34, 0x01, 0x04, 0x01, 0x01, 0x01, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]);
/// Edit Protocol operational pattern (`AAFEditProtocol`) and mob usage codes (`Usage_TopLevel`),
/// as in the SMPTE Labels register.
pub const OP_EDIT_PROTOCOL: Auid = super::ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x05, 0x0D, 0x01, 0x12, 0x01, 0x01, 0x00, 0x00, 0x00]);
pub const USAGE_TOP_LEVEL: Auid = super::ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0D, 0x01, 0x01, 0x02, 0x01, 0x01, 0x07, 0x00]);
/// The label FilmCraft 0.16 and earlier wrote as the top-level usage code (in no register).
/// Import reads it as top-level too.
pub const USAGE_TOP_LEVEL_OLD: Auid = super::ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x05, 0x0D, 0x01, 0x12, 0x01, 0x02, 0x03, 0x00, 0x00]);
}
/// Weak reference target paths (pids from the root object).
pub(crate) mod path {
use super::pid;
pub const DATA_DEFS: [u16; 3] = [pid::ROOT_HEADER, pid::DICTIONARY, pid::DATA_DEFINITIONS];
pub const OPERATION_DEFS: [u16; 3] = [pid::ROOT_HEADER, pid::DICTIONARY, pid::OPERATION_DEFINITIONS];
pub const PARAMETER_DEFS: [u16; 3] = [pid::ROOT_HEADER, pid::DICTIONARY, pid::PARAMETER_DEFINITIONS];
pub const INTERPOLATION_DEFS: [u16; 3] = [pid::ROOT_HEADER, pid::DICTIONARY, pid::INTERPOLATION_DEFINITIONS];
pub const CONTAINER_DEFS: [u16; 3] = [pid::ROOT_HEADER, pid::DICTIONARY, pid::CONTAINER_DEFINITIONS];
}
+759
View File
@@ -0,0 +1,759 @@
//! AAF objects → composition model.
use std::collections::{HashMap, HashSet};
use craft_timeline::time::{FrameRate, Tick};
use super::ids::{cls, ddef, def, pid};
use super::store::{self, Auid, Obj, Value, rational_of, utf16_of};
use crate::model::{CClip, CItem, CKind, CMarker, CTrack, CTransition, Composition, Document, Gain, Source, units_to_ticks};
use crate::{Error, Report, Result};
type MobId = [u8; 32];
#[derive(Clone, Copy, PartialEq, Eq)]
enum DataKind {
Picture,
Sound,
Timecode,
Other,
}
fn data_kind(o: &Obj) -> DataKind {
match o.weak_key(pid::DATA_DEFINITION).and_then(|k| <Auid>::try_from(k).ok()) {
Some(k) if k == ddef::PICTURE || k == ddef::LEGACY_PICTURE => DataKind::Picture,
Some(k) if k == ddef::SOUND || k == ddef::LEGACY_SOUND => DataKind::Sound,
Some(k) if k == ddef::TIMECODE || k == ddef::LEGACY_TIMECODE => DataKind::Timecode,
Some(_) => DataKind::Other,
None => DataKind::Other,
}
}
fn len_of(o: &Obj) -> i64 {
o.i64(pid::LENGTH).unwrap_or(0).max(0)
}
/// The value of an indirect property: (type id, bytes).
fn indirect(d: &[u8]) -> Option<(Auid, &[u8])> {
if d.len() >= 17 && (d[0] == 0x4C || d[0] == 0x42) {
return Some((d[1..17].try_into().ok()?, &d[17..]));
}
if d.len() >= 16 {
return Some((d[..16].try_into().ok()?, &d[16..]));
}
None
}
fn tagged_values(o: &Obj, p: u16) -> Vec<(String, String)> {
o.objs(p)
.iter()
.filter_map(|t| {
let name = t.string(pid::TAG_NAME)?;
let (ty, v) = indirect(t.data(pid::TAG_VALUE)?)?;
let value = if ty == def::TYPE_STRING || v.len() % 2 == 0 { utf16_of(v) } else { String::new() };
Some((name, value))
})
.collect()
}
fn indirect_f64(d: &[u8]) -> Option<f64> {
let (_, v) = indirect(d)?;
match v.len() {
8 => rational_of(v).filter(|r| r.1 != 0).map(|(n, d)| n as f64 / d as f64),
4 => Some(i32::from_le_bytes(v.try_into().ok()?) as f64),
_ => None,
}
}
struct R<'a> {
report: &'a mut Report,
mobs: HashMap<MobId, &'a Obj>,
essence: HashMap<MobId, &'a [u8]>,
doc: Document,
/// (file mob id, slot id, master key) → source index
sources: HashMap<(MobId, u32, String), usize>,
/// Composition mobs read as nested compositions: their index in `doc.nested`.
nests: HashMap<MobId, usize>,
/// The compositions being read, outermost first.
open: Vec<MobId>,
}
struct NestClip<'a> {
mob_id: MobId,
slot_id: u32,
rate: (i64, i64),
kind: CKind,
name: String,
mob: &'a Obj,
}
/// Compositions nested deeper than this are read as gaps.
const MAX_NESTING: usize = 16;
pub(crate) fn read(bytes: &[u8], report: &mut Report) -> Result<Document> {
let root = store::read(bytes).map_err(|e| Error::Parse { format: "AAF", message: e })?;
let header = root.strong(pid::ROOT_HEADER).ok_or_else(|| Error::Parse { format: "AAF", message: "no header object".into() })?;
let content = header.strong(pid::CONTENT).ok_or_else(|| Error::Parse { format: "AAF", message: "no content storage".into() })?;
let mut mobs = HashMap::new();
for m in content.objs(pid::MOBS) {
if let Some(id) = m.mob_id(pid::MOB_ID) {
mobs.insert(id, m);
}
}
let mut essence = HashMap::new();
for e in content.objs(pid::ESSENCE_DATA) {
if let (Some(id), Some(d)) = (e.mob_id(pid::ESSENCE_MOB_ID), e.stream(pid::ESSENCE_STREAM)) {
essence.insert(id, d);
}
}
let mut r = R { report, mobs, essence, doc: Document::default(), sources: HashMap::new(), nests: HashMap::new(), open: Vec::new() };
// Top-level compositions: those no other composition uses, among the ones tagged top-level
// when any are. (Premiere Pro tags a nested sequence's composition top-level too; it is still
// only a nested sequence.) Compositions that only use each other in a circle all count. The
// label older FilmCraft versions wrote for top-level counts as top-level too.
let comps: Vec<&Obj> = content.objs(pid::MOBS).iter().filter(|m| m.class == cls::COMPOSITION_MOB).collect();
let mut referenced = HashSet::new();
for c in &comps {
collect_refs(c, &mut referenced);
}
let is_top = |c: &&Obj| c.auid(pid::USAGE_CODE).is_some_and(|u| u == def::USAGE_TOP_LEVEL || u == def::USAGE_TOP_LEVEL_OLD);
let tagged_top: Vec<&Obj> = comps.iter().copied().filter(is_top).collect();
let pool = if tagged_top.is_empty() { comps } else { tagged_top };
let unused: Vec<&Obj> = pool.iter().copied().filter(|c| c.mob_id(pid::MOB_ID).is_none_or(|id| !referenced.contains(&id))).collect();
let top = if unused.is_empty() { pool } else { unused };
for c in top {
r.open.extend(c.mob_id(pid::MOB_ID));
let comp = r.composition(c);
r.open.clear();
r.doc.compositions.push(comp);
}
if r.doc.compositions.is_empty() {
return Err(Error::Empty);
}
Ok(r.doc)
}
fn collect_refs(o: &Obj, out: &mut HashSet<MobId>) {
if o.class == cls::SOURCE_CLIP
&& let Some(id) = o.mob_id(pid::SOURCE_ID)
{
out.insert(id);
}
for (_, v) in &o.props {
match v {
Value::Strong(c) => collect_refs(c, out),
Value::StrongVec(v) | Value::StrongSet(v, _) => v.iter().for_each(|c| collect_refs(c, out)),
_ => {}
}
}
}
fn rate_of(o: &Obj, p: u16) -> Option<(i64, i64)> {
o.rational(p).filter(|r| r.0 > 0 && r.1 > 0)
}
impl R<'_> {
fn composition(&mut self, c: &Obj) -> Composition {
let name = c.string(pid::MOB_NAME).unwrap_or_else(|| "Sequence".into());
let slots = c.objs(pid::SLOTS);
let pic_rate = slots
.iter()
.filter(|s| s.class == cls::TIMELINE_MOB_SLOT)
.find(|s| s.strong(pid::SEGMENT).is_some_and(|g| matches!(data_kind(g), DataKind::Picture | DataKind::Timecode)))
.and_then(|s| rate_of(s, pid::EDIT_RATE))
.or_else(|| slots.iter().find_map(|s| rate_of(s, pid::EDIT_RATE)))
.unwrap_or((25, 1));
let rate = FrameRate::new(pic_rate.0, pic_rate.1);
let tags = tagged_values(c, pid::MOB_USER_COMMENTS);
let tag = |n: &str| tags.iter().find(|(k, _)| k == n).map(|(_, v)| v.clone());
let (mut width, mut height) = tag("FilmCraft Frame Size")
.and_then(|s| s.split_once('x').and_then(|(a, b)| Some((a.trim().parse().ok()?, b.trim().parse().ok()?))))
.unwrap_or((0, 0));
let mut sample_rate = tag("FilmCraft Audio Sample Rate").and_then(|s| s.parse().ok()).unwrap_or(0u32);
let mut comp = Composition {
name,
aaf_mob_id: c.mob_id(pid::MOB_ID).map(|id| hex(&id)),
rate,
sample_rate: 48_000,
width: 1920,
height: 1080,
start_tc: 0,
drop: false,
tracks: Vec::new(),
markers: Vec::new(),
};
let (mut nv, mut na) = (0, 0);
for s in slots {
let Some(seg) = s.strong(pid::SEGMENT) else { continue };
if s.class == cls::EVENT_MOB_SLOT {
let er = rate_of(s, pid::EVENT_EDIT_RATE).unwrap_or(pic_rate);
comp.markers.extend(markers_of(seg, er));
continue;
}
let er = rate_of(s, pid::EDIT_RATE).unwrap_or(pic_rate);
let origin = s.i64(pid::ORIGIN).unwrap_or(0);
match data_kind(seg) {
DataKind::Timecode => {
if let Some(tc) = find_class(seg, cls::TIMECODE) {
comp.start_tc = tc.i64(pid::TC_START).unwrap_or(0);
comp.drop = tc.u8(pid::TC_DROP).unwrap_or(0) != 0;
}
}
kind @ (DataKind::Picture | DataKind::Sound) => {
let ckind = if kind == DataKind::Picture { CKind::Picture } else { CKind::Sound };
if ckind == CKind::Sound && sample_rate == 0 && er.1 == 1 && er.0 >= 8000 {
sample_rate = er.0 as u32;
}
// Premiere Pro writes every video track into one slot: a nested scope with a
// segment per track, the lowest track first. (A scope whose last segment
// refers to the others is an effect over layers: one track, as before.)
let layers: Vec<&Obj> = if ckind == CKind::Picture && seg.class == cls::NESTED_SCOPE && !refers_to_scope(seg, 0) {
seg.objs(pid::NESTED_SLOTS).iter().collect()
} else {
Vec::new()
};
let layered = !layers.is_empty();
let whole = units_to_ticks(len_of(seg), er.0, er.1);
for layer in if layered { layers } else { vec![seg] } {
let mut items = self.segment(layer, er, ckind, 0);
if layered {
fit(&mut items, whole);
}
if origin > 0 {
// material before the origin is not shown
trim_front(&mut items, units_to_ticks(origin, er.0, er.1));
}
let number = s.u32(pid::PHYSICAL_TRACK_NUMBER).unwrap_or(0);
let name = s.string(pid::SLOT_NAME).unwrap_or_default();
let channels = if ckind == CKind::Sound {
items
.iter()
.filter_map(|i| match i {
CItem::Clip(c) => self.doc.sources.get(c.source).map(|s| s.channels),
_ => None,
})
.max()
.unwrap_or(1)
.min(6)
} else {
0
};
let n = if ckind == CKind::Picture {
nv += 1;
nv
} else {
na += 1;
na
};
comp.tracks.push(CTrack { kind: ckind, name, number: if number > 0 && !layered { number } else { n }, channels, items });
}
}
DataKind::Other => self.report.info("a slot of an unsupported data kind was skipped"),
}
}
if width == 0 {
// no size in the file: that of the first picture this composition shows, else of any
let own = comp.tracks.iter().filter(|t| t.kind == CKind::Picture).flat_map(|t| &t.items).find_map(|i| match i {
CItem::Clip(c) => self.doc.sources.get(c.source).filter(|s| s.kind == CKind::Picture && s.width > 0 && s.nested.is_none()),
_ => None,
});
let pic = own.or_else(|| self.doc.sources.iter().find(|s| s.kind == CKind::Picture && s.width > 0));
(width, height) = pic.map_or((1920, 1080), |p| (p.width, p.height));
}
comp.width = width;
comp.height = height;
if sample_rate > 0 {
comp.sample_rate = sample_rate;
}
comp
}
/// Items of a segment (a sequence or a single component).
fn segment(&mut self, seg: &Obj, rate: (i64, i64), kind: CKind, depth: usize) -> Vec<CItem> {
if depth > 32 {
self.report.warn("segments nested too deeply were skipped");
return vec![CItem::Filler(units_to_ticks(len_of(seg), rate.0, rate.1))];
}
if seg.class == cls::SEQUENCE {
let mut out = Vec::new();
for c in seg.objs(pid::COMPONENTS) {
out.extend(self.component(c, rate, kind, depth + 1));
}
return out;
}
self.component(seg, rate, kind, depth + 1)
}
fn component(&mut self, c: &Obj, rate: (i64, i64), kind: CKind, depth: usize) -> Vec<CItem> {
let len = units_to_ticks(len_of(c), rate.0, rate.1);
match c.class {
x if x == cls::FILLER => vec![CItem::Filler(len)],
x if x == cls::SOURCE_CLIP => vec![self.clip(c, rate, kind, None)],
x if x == cls::SEQUENCE => self.segment(c, rate, kind, depth),
x if x == cls::TRANSITION => {
let cut = units_to_ticks(c.i64(pid::CUT_POINT).unwrap_or(0), rate.0, rate.1);
let og = c.strong(pid::OPERATION_GROUP);
let effect = og
.and_then(|o| tagged_values(o, pid::COMPONENT_USER_COMMENTS).into_iter().find(|(k, _)| k == "FilmCraft Effect").map(|(_, v)| v))
.unwrap_or_else(|| {
let op = og.and_then(|o| o.weak_key(pid::OPERATION)).and_then(|k| <Auid>::try_from(k).ok());
match (kind, op) {
(CKind::Sound, _) => "constant_power".into(),
(_, Some(o)) if o == def::VIDEO_FADE_TO_BLACK => "dip_to_black".into(),
(_, Some(o)) if o == def::SMPTE_VIDEO_WIPE => "wipe".into(),
_ => "cross_dissolve".into(),
}
});
vec![CItem::Transition(CTransition { len, cut: cut.clamp(Tick::ZERO, len), effect })]
}
x if x == cls::OPERATION_GROUP => {
let op = c.weak_key(pid::OPERATION).and_then(|k| <Auid>::try_from(k).ok());
let inputs = c.objs(pid::INPUT_SEGMENTS);
let Some(input) = inputs.first() else {
self.report.info("an effect without input was imported as a gap");
return vec![CItem::Filler(len)];
};
let gain = if op == Some(def::MONO_AUDIO_GAIN) {
self.gain(c, len, rate)
} else {
self.report.warn("effects other than audio gain are not imported (their first input is used)");
None
};
let mut items = self.segment(input, rate, kind, depth);
// the operation's length rules
fit(&mut items, len);
if let Some(g) = gain {
match items.as_mut_slice() {
[CItem::Clip(cl)] => cl.gain = Some(g),
_ => self.report.warn("audio gain around several clips was not imported"),
}
}
items
}
x if x == cls::SELECTOR => {
self.report.info("a selector was flattened to its selected input");
match c.strong(pid::SELECTED) {
Some(s) => {
let mut items = self.segment(s, rate, kind, depth);
fit(&mut items, len);
items
}
None => vec![CItem::Filler(len)],
}
}
x if x == cls::NESTED_SCOPE => {
self.report.info("a nested scope was flattened to its final input");
match c.objs(pid::NESTED_SLOTS).last() {
Some(s) => {
let mut items = self.segment(s, rate, kind, depth);
fit(&mut items, len);
items
}
None => vec![CItem::Filler(len)],
}
}
_ => {
self.report.info("an unsupported component was imported as a gap");
vec![CItem::Filler(len)]
}
}
}
fn gain(&mut self, og: &Obj, len: Tick, _rate: (i64, i64)) -> Option<Gain> {
let p = og
.objs(pid::PARAMETERS)
.iter()
.find(|p| p.auid(pid::PARAMETER_DEFINITION) == Some(def::PARAM_AMPLITUDE))
.or_else(|| og.objs(pid::PARAMETERS).first())?;
if p.class == cls::CONSTANT_VALUE {
return p.data(pid::CONSTANT_VALUE).and_then(indirect_f64).map(Gain::Constant);
}
if p.class == cls::VARYING_VALUE {
let linear = p.weak_key(pid::INTERPOLATION).and_then(|k| <Auid>::try_from(k).ok()) != Some(def::INTERP_CONSTANT);
let points: Vec<(Tick, f64)> = p
.objs(pid::POINT_LIST)
.iter()
.filter_map(|cp| {
let (n, d) = cp.rational(pid::CP_TIME).filter(|r| r.1 != 0)?;
let v = cp.data(pid::CP_VALUE).and_then(indirect_f64)?;
Some((Tick((len.0 as i128 * n as i128 / d as i128).clamp(-(1i128 << 56), 1i128 << 56) as i64), v))
})
.collect();
return (!points.is_empty()).then_some(Gain::Varying { linear, points });
}
None
}
fn clip(&mut self, c: &Obj, rate: (i64, i64), kind: CKind, master_key: Option<String>) -> CItem {
let len = units_to_ticks(len_of(c), rate.0, rate.1);
let tagged_name = tagged_values(c, pid::COMPONENT_USER_COMMENTS).into_iter().find(|(k, _)| k == "Clip Name").map(|(_, v)| v);
let (Some(id), Some(slot)) = (c.mob_id(pid::SOURCE_ID), c.u32(pid::SOURCE_MOB_SLOT_ID)) else { return CItem::Filler(len) };
let name = tagged_name.or_else(|| self.mobs.get(&id).and_then(|mob| mob.string(pid::MOB_NAME))).unwrap_or_default();
if id == [0; 32] {
return CItem::Filler(len);
}
if let Some(mob) = self.mobs.get(&id).copied().filter(|m| m.class == cls::COMPOSITION_MOB) {
return self.nest_clip(c, NestClip { mob, mob_id: id, slot_id: slot, rate, kind, name });
}
let source_rate = self
.mobs
.get(&id)
.and_then(|mob| mob.objs(pid::SLOTS).iter().find(|s| s.u32(pid::SLOT_ID) == Some(slot)))
.and_then(|s| rate_of(s, pid::EDIT_RATE))
.unwrap_or(rate);
let start = units_to_ticks(c.i64(pid::START_TIME).unwrap_or(0), source_rate.0, source_rate.1);
match self.resolve(id, slot, start, kind, master_key, 0) {
Some((source, t)) => CItem::Clip(CClip { len, source, start: t, gain: None, name }),
None => CItem::Filler(len),
}
}
/// A source clip that points at a composition: a nested sequence (Premiere Pro writes its
/// nested sequences this way). The composition is read once, however many clips use it.
fn nest_clip(&mut self, c: &Obj, clip: NestClip<'_>) -> CItem {
let NestClip { mob, mob_id: id, slot_id, rate, kind, name } = clip;
let len = units_to_ticks(len_of(c), rate.0, rate.1);
let index = match self.nests.get(&id) {
Some(&i) => i,
None => {
if self.open.contains(&id) || self.open.len() >= MAX_NESTING {
self.report.warn("a composition nested in itself or nested too deeply was imported as a gap");
return CItem::Filler(len);
}
self.open.push(id);
let comp = self.composition(mob);
self.open.pop();
let i = self.doc.nested.len();
self.doc.nested.push(comp);
self.nests.insert(id, i);
i
}
};
// the start counts edit units of the slot the clip points at
let slot_rate =
mob.objs(pid::SLOTS).iter().find(|s| s.u32(pid::SLOT_ID) == Some(slot_id)).and_then(|s| rate_of(s, pid::EDIT_RATE)).unwrap_or(rate);
let start = units_to_ticks(c.i64(pid::START_TIME).unwrap_or(0), slot_rate.0, slot_rate.1);
let skey = (id, if kind == CKind::Picture { 0 } else { 1 }, "composition".to_string());
let source = match self.sources.get(&skey) {
Some(&i) => i,
None => {
let Some(comp) = self.doc.nested.get(index) else { return CItem::Filler(len) };
let length = comp
.tracks
.iter()
.map(|t| {
Tick(t.items.iter().fold(0i64, |a, i| {
if matches!(i, CItem::Transition(_)) { a.saturating_sub(i.len().0) } else { a.saturating_add(i.len().0) }
}))
})
.max()
.unwrap_or(Tick::ZERO);
let channels = if kind == CKind::Sound { 2 } else { 0 };
let s = Source {
key: format!("composition:{}", hex(&id)),
name: comp.name.clone(),
kind,
path: None,
channel: None,
channels,
file_channels: channels,
width: comp.width,
height: comp.height,
frame_rate: comp.rate,
sample_rate: comp.sample_rate,
bits: 16,
length,
offset: Tick::ZERO,
start_tc: None,
tc_rate: comp.rate,
embedded: None,
markers: Vec::new(),
nested: Some(index),
};
let i = self.doc.sources.len();
self.doc.sources.push(s);
self.sources.insert(skey, i);
i
}
};
CItem::Clip(CClip { len, source, start, gain: None, name })
}
/// Follow a source reference to a file source mob: (source index, file time).
fn resolve(&mut self, id: MobId, slot_id: u32, start: Tick, kind: CKind, master_key: Option<String>, depth: usize) -> Option<(usize, Tick)> {
if depth > 16 {
return None;
}
let Some(mob) = self.mobs.get(&id).copied() else {
self.report.warn("a clip references a mob that is not in the file (imported as a gap)");
return None;
};
let slot = mob.objs(pid::SLOTS).iter().find(|s| s.u32(pid::SLOT_ID) == Some(slot_id))?;
let rate = rate_of(slot, pid::EDIT_RATE).unwrap_or((25, 1));
let seg = slot.strong(pid::SEGMENT)?;
if mob.class == cls::COMPOSITION_MOB {
self.report.warn("nested compositions are not supported (imported as gaps)");
return None;
}
if mob.class == cls::MASTER_MOB {
let key = master_key.unwrap_or_else(|| hex(&id));
let clip = first_clip(seg)?;
let next = clip.mob_id(pid::SOURCE_ID)?;
let next_slot = clip.u32(pid::SOURCE_MOB_SLOT_ID)?;
let source_rate = self
.mobs
.get(&next)
.and_then(|m| m.objs(pid::SLOTS).iter().find(|s| s.u32(pid::SLOT_ID) == Some(next_slot)))
.and_then(|s| rate_of(s, pid::EDIT_RATE))
.unwrap_or(rate);
let inner = units_to_ticks(clip.i64(pid::START_TIME).unwrap_or(0), source_rate.0, source_rate.1);
if next == [0; 32] {
return None;
}
let markers = mob
.objs(pid::SLOTS)
.iter()
.filter(|s| s.class == cls::EVENT_MOB_SLOT)
.flat_map(|s| s.strong(pid::SEGMENT).map(|g| markers_of(g, rate_of(s, pid::EVENT_EDIT_RATE).unwrap_or(rate))).unwrap_or_default())
.collect::<Vec<_>>();
let r = self.resolve(next, next_slot, start + inner, kind, Some(key), depth + 1)?;
let src = &mut self.doc.sources[r.0];
if src.markers.is_empty() {
src.markers = markers;
}
if src.name.is_empty()
&& let Some(n) = mob.string(pid::MOB_NAME)
{
src.name = n;
}
return Some(r);
}
// a source mob: file (has a file descriptor) or physical (tape / import)
let desc = mob.strong(pid::ESSENCE_DESCRIPTION);
let is_file = desc.is_some_and(|d| d.get(pid::SAMPLE_RATE).is_some() || d.get(pid::LOCATOR).is_some() || self.essence.contains_key(&id));
if !is_file {
return None;
}
let key = master_key.unwrap_or_else(|| hex(&id));
let skey = (id, slot_id, key.clone());
if let Some(&i) = self.sources.get(&skey) {
return Some((i, start));
}
let d = desc?;
let seg_kind = match data_kind(seg) {
DataKind::Picture => CKind::Picture,
DataKind::Sound => CKind::Sound,
_ => kind,
};
let path = d.objs(pid::LOCATOR).iter().find_map(|l| l.string(pid::URL_STRING)).map(|u| locator_path(&u));
let file_rate = rate_of(d, pid::SAMPLE_RATE).unwrap_or(rate);
let length = d
.i64(pid::FILE_LENGTH)
.map(|l| units_to_ticks(l, file_rate.0, file_rate.1))
.unwrap_or_else(|| units_to_ticks(len_of(seg), rate.0, rate.1));
let sound_slots = mob.objs(pid::SLOTS).iter().filter(|s| s.strong(pid::SEGMENT).is_some_and(|g| data_kind(g) == DataKind::Sound)).count();
let file_channels = d.u32(pid::CHANNELS).unwrap_or(1).max(1);
let channel = (seg_kind == CKind::Sound && file_channels > 1 && sound_slots > 1)
.then(|| slot.u32(pid::PHYSICAL_TRACK_NUMBER).unwrap_or(slot_id).saturating_sub(1).min(file_channels - 1));
let mut layout = d.u8(pid::FRAME_LAYOUT).unwrap_or(0);
if layout > 4 {
layout = 0;
}
let stored_h = d.u32(pid::STORED_HEIGHT).unwrap_or(0);
let fr = FrameRate::new(file_rate.0, file_rate.1);
// timecode from the physical source mob
let tc = first_clip(seg).and_then(|clip| {
let tid = clip.mob_id(pid::SOURCE_ID)?;
let tape = self.mobs.get(&tid)?;
let tslot = tape.objs(pid::SLOTS).iter().find_map(|s| {
let g = s.strong(pid::SEGMENT)?;
let t = find_class(g, cls::TIMECODE)?;
Some((t.i64(pid::TC_START).unwrap_or(0), t.u16(pid::TC_FPS).unwrap_or(25).max(1) as i64, rate_of(s, pid::EDIT_RATE)))
})?;
let off = units_to_ticks(clip.i64(pid::START_TIME).unwrap_or(0), rate.0, rate.1);
let tcr = tslot.2.map(|r| FrameRate::new(r.0, r.1)).unwrap_or_else(|| FrameRate::new(tslot.1, 1));
Some((tslot.0 + tcr.frame_at(off), tcr))
});
let mut s = Source {
key,
name: mob.string(pid::MOB_NAME).unwrap_or_default(),
kind: seg_kind,
path,
channel,
channels: if channel.is_some() { 1 } else { file_channels },
file_channels,
width: d.u32(pid::STORED_WIDTH).unwrap_or(0),
height: if matches!(layout, 1 | 3) { stored_h.saturating_mul(2) } else { stored_h },
frame_rate: if seg_kind == CKind::Picture { fr } else { FrameRate::FPS_25 },
sample_rate: d
.rational(pid::AUDIO_SAMPLING_RATE)
.filter(|r| r.1 > 0 && r.0 > 0)
.map(|r| (r.0 / r.1) as u32)
.unwrap_or(file_rate.0 as u32),
bits: d.u32(pid::QUANTIZATION_BITS).unwrap_or(16).clamp(8, 32) as u16,
length,
offset: Tick::ZERO,
start_tc: tc.map(|t| t.0),
tc_rate: tc.map(|t| t.1).unwrap_or(fr),
embedded: None,
markers: Vec::new(),
nested: None,
};
if s.kind == CKind::Sound {
s.frame_rate = FrameRate::FPS_25;
if let Some(data) = self.essence.get(&id) {
s.embedded = Some(data.to_vec());
// embedded essence may be a whole WAVE / AIFF file
if let Some((pcm, ch, sr, bits)) = crate::pcm::parse_wav(data) {
s.embedded = Some(pcm);
s.file_channels = ch as u32;
s.channels = if s.channel.is_some() { 1 } else { ch as u32 };
s.sample_rate = sr;
s.bits = bits;
}
}
}
if s.kind == CKind::Picture && s.width == 0 {
s.width = 1920;
s.height = 1080;
}
let i = self.doc.sources.len();
self.doc.sources.push(s);
self.sources.insert(skey, i);
Some((i, start))
}
}
/// Drop `t` from the front of a track's items (slot origin).
fn trim_front(items: &mut Vec<CItem>, mut t: Tick) {
while t > Tick::ZERO && !items.is_empty() {
let l = items[0].len();
if matches!(items[0], CItem::Transition(_)) {
items.remove(0);
continue;
}
if l <= t {
items.remove(0);
t -= l;
} else {
match &mut items[0] {
CItem::Filler(x) => *x -= t,
CItem::Clip(c) => {
c.len -= t;
c.start += t;
}
CItem::Transition(_) => {}
}
t = Tick::ZERO;
}
}
}
/// Make the items exactly `len` long (an operation group / selector is as long as itself).
fn fit(items: &mut Vec<CItem>, len: Tick) {
let total = Tick(
items.iter().fold(0i64, |a, i| if matches!(i, CItem::Transition(_)) { a.saturating_sub(i.len().0) } else { a.saturating_add(i.len().0) }),
);
if total == len || items.is_empty() {
if items.is_empty() {
items.push(CItem::Filler(len));
}
return;
}
if total < len {
items.push(CItem::Filler(len - total));
return;
}
let mut excess = total - len;
while excess > Tick::ZERO {
match items.last_mut() {
Some(CItem::Filler(x)) | Some(CItem::Clip(CClip { len: x, .. })) if *x > excess => {
*x -= excess;
excess = Tick::ZERO;
}
Some(CItem::Transition(_)) => {
items.pop();
}
Some(other) => {
excess -= other.len();
items.pop();
}
None => break,
}
}
}
/// Whether anything inside `o` is a scope reference (a nested scope used as an effect's layers).
fn refers_to_scope(o: &Obj, depth: usize) -> bool {
if o.class == cls::SCOPE_REFERENCE {
return true;
}
if depth > 32 {
return false;
}
o.props.iter().any(|(_, v)| match v {
Value::Strong(c) => refers_to_scope(c, depth + 1),
Value::StrongVec(v) | Value::StrongSet(v, _) => v.iter().any(|c| refers_to_scope(c, depth + 1)),
_ => false,
})
}
fn first_clip(seg: &Obj) -> Option<&Obj> {
if seg.class == cls::SOURCE_CLIP {
return Some(seg);
}
if seg.class == cls::SEQUENCE {
return seg.objs(pid::COMPONENTS).iter().find_map(first_clip);
}
// essence group (choices 0x0501) / operation group inputs
seg.objs(0x0501).iter().find_map(first_clip).or_else(|| seg.objs(pid::INPUT_SEGMENTS).iter().find_map(first_clip))
}
fn find_class(seg: &Obj, class: Auid) -> Option<&Obj> {
if seg.class == class {
return Some(seg);
}
seg.objs(pid::COMPONENTS).iter().find_map(|c| find_class(c, class))
}
fn markers_of(seg: &Obj, rate: (i64, i64)) -> Vec<CMarker> {
let events: Vec<&Obj> = if seg.class == cls::SEQUENCE { seg.objs(pid::COMPONENTS).iter().collect() } else { vec![seg] };
events
.into_iter()
.filter(|e| e.class == cls::COMMENT_MARKER || e.class == cls::DESCRIPTIVE_MARKER || e.get(pid::POSITION).is_some())
.map(|e| {
let tags = tagged_values(e, pid::COMPONENT_USER_COMMENTS);
let tag = |n: &str| tags.iter().find(|(k, _)| k == n).map(|(_, v)| v.clone());
let comment = e.string(pid::COMMENT).unwrap_or_default();
let start = units_to_ticks(e.i64(pid::POSITION).unwrap_or(0), rate.0, rate.1);
CMarker {
start,
duration: units_to_ticks(e.i64(pid::LENGTH).unwrap_or(0).max(0), rate.0, rate.1),
name: tag("Name").unwrap_or_else(|| comment.clone()),
comment: tag("Comment").unwrap_or_else(|| if tags.is_empty() { String::new() } else { comment.clone() }),
color: tag("Color"),
}
})
.collect()
}
fn hex(b: &[u8]) -> String {
b.iter().map(|x| format!("{x:02x}")).collect()
}
fn locator_path(url: &str) -> String {
if url.contains("://") { craft_timeline::path::file_url_to_path(url) } else { craft_timeline::path::decode_uri_path(url) }
}
#[cfg(test)]
mod locator_tests {
use super::locator_path;
#[test]
fn decodes_relative_locator_escapes_without_losing_remote_authorities() {
assert_eq!(locator_path("Audio%20Files/Di%C3%A1logo%20%231.wav"), "Audio Files/Diálogo #1.wav");
assert_eq!(locator_path("file:///tmp/a%20b.wav"), "/tmp/a b.wav");
assert_eq!(locator_path("file://server/share/a.wav"), "//server/share/a.wav");
assert_eq!(locator_path("https://example.com/a%20b.wav"), "https://example.com/a%20b.wav");
}
}
+539
View File
@@ -0,0 +1,539 @@
//! AAF objects in structured storage (the AAF Low-Level Container Specification): every object
//! is a storage whose class id is the object's class AUID, holding a `properties` stream; strong
//! references are child storages, collections have an index stream, weak references name a key
//! in a target collection through the root's `referenced properties` table.
//!
//! `properties` stream (little-endian):
//!
//! ```text
//! u8 byte order (0x4C 'L') u8 format version (0x20) u16 entry count
//! entry count × { u16 pid, u16 stored form, u16 value length } the values, in entry order
//! ```
//!
//! | stored form | value |
//! |---|---|
//! | 0x82 data | the property's bytes |
//! | 0x22 strong reference | UTF-16 name of the child storage |
//! | 0x32 strong reference vector | UTF-16 collection name; storages `name{key}`, stream `name index`: u32 count, u32 first free key, u32 last free key, count × u32 local key |
//! | 0x3A strong reference set | as a vector; the index adds u16 key pid, u8 key size, and each entry is u32 local key, u32 reference count, key bytes |
//! | 0x02 weak reference | u16 referenced-property tag, u16 key pid, u8 key size, key bytes |
//! | 0x12 / 0x1A weak reference vector / set | UTF-16 collection name; stream `name index`: u32 count, u16 tag, u16 key pid, u8 key size, count × key |
//! | 0x42 data stream | u8 byte order, UTF-16 name of the stream |
//!
//! `referenced properties` (root stream): u8 byte order, u16 path count, u32 pid count, then the
//! pids of each path (from the root object) terminated by a 0 pid.
use craft_cfb::{CompoundFile, EntryKind, NodeId, Version, Writer};
pub(crate) type Auid = [u8; 16];
pub(crate) const SF_DATA: u16 = 0x82;
pub(crate) const SF_DATA_STREAM: u16 = 0x42;
pub(crate) const SF_STRONG: u16 = 0x22;
pub(crate) const SF_STRONG_VECTOR: u16 = 0x32;
pub(crate) const SF_STRONG_SET: u16 = 0x3A;
pub(crate) const SF_WEAK: u16 = 0x02;
pub(crate) const SF_WEAK_VECTOR: u16 = 0x12;
pub(crate) const SF_WEAK_SET: u16 = 0x1A;
const BYTE_ORDER_LE: u8 = 0x4C;
const FORMAT_VERSION: u8 = 0x20;
/// A property value.
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum Value {
Data(Vec<u8>),
Strong(Box<Obj>),
StrongVec(Vec<Obj>),
/// Objects keyed by the data property `key_pid` of each.
StrongSet(Vec<Obj>, u16),
/// (path of pids from the root to the target collection, key pid, key)
Weak(Vec<u16>, u16, Vec<u8>),
WeakVec(Vec<u16>, u16, Vec<Vec<u8>>),
Stream(Vec<u8>),
}
/// An AAF object: its class and properties.
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct Obj {
pub class: Auid,
pub props: Vec<(u16, Value)>,
}
impl Obj {
pub fn new(class: Auid) -> Obj {
Obj { class, props: Vec::new() }
}
pub fn set(&mut self, pid: u16, v: Value) -> &mut Obj {
match self.props.iter_mut().find(|(p, _)| *p == pid) {
Some(slot) => slot.1 = v,
None => self.props.push((pid, v)),
}
self
}
pub fn with(mut self, pid: u16, v: Value) -> Obj {
self.set(pid, v);
self
}
pub fn data_prop(mut self, pid: u16, d: Vec<u8>) -> Obj {
self.set(pid, Value::Data(d));
self
}
pub fn get(&self, pid: u16) -> Option<&Value> {
self.props.iter().find(|(p, _)| *p == pid).map(|(_, v)| v)
}
pub fn data(&self, pid: u16) -> Option<&[u8]> {
match self.get(pid)? {
Value::Data(d) => Some(d),
_ => None,
}
}
pub fn strong(&self, pid: u16) -> Option<&Obj> {
match self.get(pid)? {
Value::Strong(o) => Some(o),
_ => None,
}
}
/// Elements of a strong vector or set (empty when absent).
pub fn objs(&self, pid: u16) -> &[Obj] {
match self.get(pid) {
Some(Value::StrongVec(v)) | Some(Value::StrongSet(v, _)) => v,
_ => &[],
}
}
pub fn weak_key(&self, pid: u16) -> Option<&[u8]> {
match self.get(pid)? {
Value::Weak(_, _, k) => Some(k),
_ => None,
}
}
pub fn stream(&self, pid: u16) -> Option<&[u8]> {
match self.get(pid)? {
Value::Stream(d) => Some(d),
_ => None,
}
}
pub fn u8(&self, pid: u16) -> Option<u8> {
self.data(pid).and_then(|d| d.first().copied())
}
pub fn u16(&self, pid: u16) -> Option<u16> {
self.data(pid).filter(|d| d.len() >= 2).map(|d| u16::from_le_bytes([d[0], d[1]]))
}
pub fn u32(&self, pid: u16) -> Option<u32> {
self.data(pid).filter(|d| d.len() >= 4).map(|d| u32::from_le_bytes([d[0], d[1], d[2], d[3]]))
}
pub fn i64(&self, pid: u16) -> Option<i64> {
let d = self.data(pid)?;
match d.len() {
8.. => Some(i64::from_le_bytes(d[..8].try_into().ok()?)),
4..=7 => Some(i32::from_le_bytes(d[..4].try_into().ok()?) as i64),
_ => None,
}
}
pub fn rational(&self, pid: u16) -> Option<(i64, i64)> {
self.data(pid).and_then(rational_of)
}
pub fn string(&self, pid: u16) -> Option<String> {
self.data(pid).map(utf16_of)
}
pub fn auid(&self, pid: u16) -> Option<Auid> {
self.data(pid).and_then(|d| d.get(..16)).and_then(|d| d.try_into().ok())
}
pub fn mob_id(&self, pid: u16) -> Option<[u8; 32]> {
self.data(pid).and_then(|d| d.get(..32)).and_then(|d| d.try_into().ok())
}
}
pub(crate) fn rational_of(d: &[u8]) -> Option<(i64, i64)> {
(d.len() >= 8).then(|| (i32::from_le_bytes([d[0], d[1], d[2], d[3]]) as i64, i32::from_le_bytes([d[4], d[5], d[6], d[7]]) as i64))
}
pub(crate) fn rational(num: i64, den: i64) -> Vec<u8> {
let mut v = (num.clamp(i32::MIN as i64, i32::MAX as i64) as i32).to_le_bytes().to_vec();
v.extend_from_slice(&(den.clamp(i32::MIN as i64, i32::MAX as i64) as i32).to_le_bytes());
v
}
/// UTF-16LE with a terminating NUL.
pub(crate) fn utf16z(s: &str) -> Vec<u8> {
let mut v: Vec<u8> = s.encode_utf16().flat_map(u16::to_le_bytes).collect();
v.extend_from_slice(&[0, 0]);
v
}
pub(crate) fn utf16_of(d: &[u8]) -> String {
let u: Vec<u16> = d.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).take_while(|&c| c != 0).collect();
String::from_utf16_lossy(&u)
}
/// Short property names used to name storages and streams (any name is valid: readers follow
/// the names stored in the property values).
fn prop_name(pid: u16) -> &'static str {
match pid {
0x0001 => "MetaDictionary",
0x0002 => "Header",
0x0003 => "ClassDefinitions",
0x0004 => "TypeDefinitions",
0x3B03 => "Content",
0x3B04 => "Dictionary",
0x3B06 => "IdentificationList",
0x1901 => "Mobs",
0x1902 => "EssenceData",
0x2603 => "OperationDefinitions",
0x2604 => "ParameterDefinitions",
0x2605 => "DataDefinitions",
0x2607 => "CodecDefinitions",
0x2608 => "ContainerDefinitions",
0x2609 => "InterpolationDefs",
0x4403 => "Slots",
0x4406 => "UserComments",
0x4803 => "Segment",
0x1001 => "Components",
0x1801 => "OperationGroup",
0x0B02 => "InputSegments",
0x0B03 => "Parameters",
0x4E02 => "PointList",
0x4701 => "EssenceDescription",
0x2F01 => "Locator",
0x2702 => "Data",
0x0204 => "ComponentComments",
0x1E09 => "ParametersDefined",
_ => "Property",
}
}
/// The key size of a strong reference set keyed by `key_pid`, for a set with no entry to take it
/// from: AUIDs (definitions) are 16 bytes, MobIDs 32.
fn set_key_size(key_pid: u16) -> usize {
match key_pid {
0x0005 | 0x1B01 => 16,
0x4401 | 0x2701 => 32,
_ => 0,
}
}
fn storage_name(pid: u16) -> String {
let suffix = format!("-{pid:x}");
let name: String = prop_name(pid).chars().take(22 - suffix.len()).collect();
format!("{name}{suffix}")
}
/// Errors while reading the object tree.
fn bad(s: impl Into<String>) -> String {
s.into()
}
// ---------------------------------------------------------------------------------------------
// Writing
// ---------------------------------------------------------------------------------------------
struct W {
cfb: Writer,
paths: Vec<Vec<u16>>,
}
/// Serialise `root` (the Root object: MetaDictionary 0x0001, Header 0x0002) into a compound file.
pub(crate) fn write(root: &Obj, version: Version) -> Result<Vec<u8>, String> {
let mut w = W { cfb: Writer::new(version), paths: Vec::new() };
w.obj(Writer::ROOT, root)?;
let mut rp = vec![BYTE_ORDER_LE];
rp.extend_from_slice(&(w.paths.len() as u16).to_le_bytes());
let n: usize = w.paths.iter().map(|p| p.len() + 1).sum();
rp.extend_from_slice(&(n as u32).to_le_bytes());
for p in &w.paths {
for pid in p {
rp.extend_from_slice(&pid.to_le_bytes());
}
rp.extend_from_slice(&0u16.to_le_bytes());
}
w.cfb.stream(Writer::ROOT, "referenced properties", rp).map_err(|e| e.to_string())?;
Ok(w.cfb.finish())
}
impl W {
fn tag(&mut self, path: &[u16]) -> u16 {
match self.paths.iter().position(|p| p == path) {
Some(i) => i as u16,
None => {
self.paths.push(path.to_vec());
(self.paths.len() - 1) as u16
}
}
}
fn obj(&mut self, node: NodeId, o: &Obj) -> Result<(), String> {
self.cfb.set_clsid(node, o.class);
let mut entries: Vec<(u16, u16, Vec<u8>)> = Vec::new();
for (pid, v) in &o.props {
let pid = *pid;
let (sf, value) = match v {
Value::Data(d) => (SF_DATA, d.clone()),
Value::Strong(child) => {
let name = storage_name(pid);
let s = self.cfb.storage(node, &name, child.class).map_err(|e| e.to_string())?;
self.obj(s, child)?;
(SF_STRONG, utf16z(&name))
}
Value::StrongVec(items) | Value::StrongSet(items, _) => {
let name = storage_name(pid);
let mut index = Vec::new();
index.extend_from_slice(&(items.len() as u32).to_le_bytes());
index.extend_from_slice(&(items.len() as u32).to_le_bytes()); // first free key
index.extend_from_slice(&u32::MAX.to_le_bytes()); // last free key
let set_key = if let Value::StrongSet(_, k) = v { Some(*k) } else { None };
let key_size = set_key.map(|k| items.first().and_then(|i| i.data(k)).map_or_else(|| set_key_size(k), <[u8]>::len)).unwrap_or(0);
if let Some(k) = set_key {
index.extend_from_slice(&k.to_le_bytes());
index.push(key_size as u8);
}
for (i, item) in items.iter().enumerate() {
let s = self.cfb.storage(node, &format!("{name}{{{i:x}}}"), item.class).map_err(|e| e.to_string())?;
self.obj(s, item)?;
index.extend_from_slice(&(i as u32).to_le_bytes());
if let Some(k) = set_key {
index.extend_from_slice(&1u32.to_le_bytes());
let mut key = item.data(k).unwrap_or(&[]).to_vec();
key.resize(key_size, 0);
index.extend_from_slice(&key);
}
}
self.cfb.stream(node, &format!("{name} index"), index).map_err(|e| e.to_string())?;
(if set_key.is_some() { SF_STRONG_SET } else { SF_STRONG_VECTOR }, utf16z(&name))
}
Value::Weak(path, key_pid, key) => {
let mut d = self.tag(path).to_le_bytes().to_vec();
d.extend_from_slice(&key_pid.to_le_bytes());
d.push(key.len() as u8);
d.extend_from_slice(key);
(SF_WEAK, d)
}
Value::WeakVec(path, key_pid, keys) => {
let name = storage_name(pid);
let tag = self.tag(path);
let size = keys.first().map_or(0, Vec::len);
let mut index = (keys.len() as u32).to_le_bytes().to_vec();
index.extend_from_slice(&tag.to_le_bytes());
index.extend_from_slice(&key_pid.to_le_bytes());
index.push(size as u8);
for k in keys {
let mut k = k.clone();
k.resize(size, 0);
index.extend_from_slice(&k);
}
self.cfb.stream(node, &format!("{name} index"), index).map_err(|e| e.to_string())?;
(SF_WEAK_VECTOR, utf16z(&name))
}
Value::Stream(data) => {
let name = storage_name(pid);
self.cfb.stream(node, &name, data.clone()).map_err(|e| e.to_string())?;
let mut d = vec![BYTE_ORDER_LE];
d.extend_from_slice(&utf16z(&name));
(SF_DATA_STREAM, d)
}
};
if value.len() > u16::MAX as usize {
return Err(format!("property {pid:#06x} is {} bytes (the limit is 65535)", value.len()));
}
entries.push((pid, sf, value));
}
let mut props = vec![BYTE_ORDER_LE, FORMAT_VERSION];
props.extend_from_slice(&(entries.len() as u16).to_le_bytes());
for (pid, sf, v) in &entries {
props.extend_from_slice(&pid.to_le_bytes());
props.extend_from_slice(&sf.to_le_bytes());
props.extend_from_slice(&(v.len() as u16).to_le_bytes());
}
for (_, _, v) in &entries {
props.extend_from_slice(v);
}
self.cfb.stream(node, "properties", props).map_err(|e| e.to_string())?;
Ok(())
}
}
// ---------------------------------------------------------------------------------------------
// Reading
// ---------------------------------------------------------------------------------------------
struct R<'a> {
cf: CompoundFile<'a>,
paths: Vec<Vec<u16>>,
objects: usize,
materialized_stream_bytes: usize,
/// Storages already read: a storage is owned by one parent, so a second strong reference to it
/// (which would rebuild its whole subtree again) is refused.
owned: std::collections::HashSet<usize>,
/// Bytes of weak-reference target paths copied into the tree so far.
path_bytes: usize,
}
const MAX_DEPTH: usize = 200;
const MAX_OBJECTS: usize = 2_000_000;
const MAX_MATERIALIZED_STREAM_BYTES: usize = 256 << 20;
/// Each weak reference carries its own copy of its target path (real paths are a handful of
/// property ids); the copies together may not exceed this.
const MAX_PATH_BYTES: usize = 64 << 20;
/// Parse the object tree of an AAF compound file (the root object).
pub(crate) fn read(bytes: &[u8]) -> Result<Obj, String> {
let cf = CompoundFile::open(bytes).map_err(|e| e.to_string())?;
cf.validate_root_chain().map_err(|e| e.to_string())?;
let mut paths = Vec::new();
if let Ok(rp) = cf.read_path("referenced properties")
&& rp.len() >= 7
{
let count = u16::from_le_bytes([rp[1], rp[2]]) as usize;
let mut cur = Vec::new();
for c in rp[7..].as_chunks::<2>().0 {
let pid = u16::from_le_bytes([c[0], c[1]]);
if pid == 0 {
paths.push(std::mem::take(&mut cur));
if paths.len() == count {
break;
}
} else {
cur.push(pid);
}
}
}
let mut r = R { cf, paths, objects: 0, materialized_stream_bytes: 0, owned: Default::default(), path_bytes: 0 };
r.obj(0, 0)
}
fn rd_u16(b: &[u8], at: usize) -> Option<u16> {
b.get(at..at + 2).map(|s| u16::from_le_bytes([s[0], s[1]]))
}
fn rd_u32(b: &[u8], at: usize) -> Option<u32> {
b.get(at..at + 4).map(|s| u32::from_le_bytes([s[0], s[1], s[2], s[3]]))
}
impl R<'_> {
fn child(&self, parent: usize, name: &str) -> Result<usize, String> {
self.cf.child(parent, name).ok_or_else(|| bad(format!("missing storage or stream \"{name}\"")))
}
fn stream(&mut self, parent: usize, name: &str) -> Result<Vec<u8>, String> {
let id = self.child(parent, name)?;
let data = self.cf.read(id).map_err(|e| e.to_string())?;
self.materialized_stream_bytes = self
.materialized_stream_bytes
.checked_add(data.len())
.filter(|&n| n <= MAX_MATERIALIZED_STREAM_BYTES)
.ok_or_else(|| bad("AAF materialized stream data exceeds the memory limit"))?;
Ok(data)
}
/// A copy of weak-reference path `tag`, counted against [`MAX_PATH_BYTES`].
fn path(&mut self, tag: u16) -> Result<Vec<u16>, String> {
let path = self.paths.get(tag as usize).cloned().unwrap_or_default();
self.path_bytes = self.path_bytes.saturating_add(path.len() * 2);
if self.path_bytes > MAX_PATH_BYTES {
return Err(bad("weak reference paths exceed the memory limit"));
}
Ok(path)
}
fn obj(&mut self, entry: usize, depth: usize) -> Result<Obj, String> {
if depth > MAX_DEPTH {
return Err(bad("objects nested too deeply"));
}
if !self.owned.insert(entry) {
return Err(bad("a storage is owned by more than one reference"));
}
self.objects += 1;
if self.objects > MAX_OBJECTS {
return Err(bad("too many objects"));
}
let e = self.cf.entry(entry).ok_or_else(|| bad("bad directory entry"))?;
if !matches!(e.kind, EntryKind::Root | EntryKind::Storage) {
return Err(bad(format!("\"{}\" is not a storage", e.name)));
}
let mut o = Obj::new(e.clsid);
let props = self.stream(entry, "properties")?;
if props.len() < 4 {
return Err(bad("short properties stream"));
}
if props[0] != BYTE_ORDER_LE {
return Err(bad("big-endian AAF files are not supported"));
}
let n = rd_u16(&props, 2).unwrap_or(0) as usize;
let mut at = 4 + n * 6;
if at > props.len() {
return Err(bad("truncated property index"));
}
for i in 0..n {
let (Some(pid), Some(sf), Some(len)) = (rd_u16(&props, 4 + i * 6), rd_u16(&props, 6 + i * 6), rd_u16(&props, 8 + i * 6)) else {
return Err(bad("truncated property index"));
};
if o.props.iter().any(|(previous, _)| *previous == pid) {
return Err(bad("duplicate property id"));
}
let v = props.get(at..at + len as usize).ok_or_else(|| bad("truncated property value"))?;
at += len as usize;
let value = match sf {
SF_STRONG => {
let c = self.child(entry, &utf16_of(v))?;
Value::Strong(Box::new(self.obj(c, depth + 1)?))
}
SF_STRONG_VECTOR | SF_STRONG_SET => {
let name = utf16_of(v);
let idx = self.stream(entry, &format!("{name} index"))?;
let count = rd_u32(&idx, 0).ok_or_else(|| bad("short collection index"))? as usize;
let mut items = Vec::new();
if sf == SF_STRONG_VECTOR {
for k in 0..count {
let key = rd_u32(&idx, 12 + k * 4).ok_or_else(|| bad("short vector index"))?;
let c = self.child(entry, &format!("{name}{{{key:x}}}"))?;
items.push(self.obj(c, depth + 1)?);
}
Value::StrongVec(items)
} else {
let key_pid = rd_u16(&idx, 12).ok_or_else(|| bad("short set index"))?;
let key_size = *idx.get(14).ok_or_else(|| bad("short set index"))? as usize;
let stride = 8 + key_size;
for k in 0..count {
let key = rd_u32(&idx, 15 + k * stride).ok_or_else(|| bad("short set index"))?;
let c = self.child(entry, &format!("{name}{{{key:x}}}"))?;
items.push(self.obj(c, depth + 1)?);
}
Value::StrongSet(items, key_pid)
}
}
SF_WEAK => {
let (Some(tag), Some(key_pid), Some(&size)) = (rd_u16(v, 0), rd_u16(v, 2), v.get(4)) else {
return Err(bad("short weak reference"));
};
let key = v.get(5..5 + size as usize).ok_or_else(|| bad("short weak reference"))?.to_vec();
Value::Weak(self.path(tag)?, key_pid, key)
}
SF_WEAK_VECTOR | SF_WEAK_SET => {
let name = utf16_of(v);
let idx = self.stream(entry, &format!("{name} index"))?;
let (Some(count), Some(tag), Some(key_pid), Some(&size)) = (rd_u32(&idx, 0), rd_u16(&idx, 4), rd_u16(&idx, 6), idx.get(8)) else {
return Err(bad("short weak collection index"));
};
let size = size as usize;
if count > 0 && size == 0 {
return Err(bad("zero-size weak collection key"));
}
// every key must lie in the index, so its length (not the count) bounds the loop
if (count as usize).checked_mul(size).and_then(|n| n.checked_add(9)).is_none_or(|end| end > idx.len()) {
return Err(bad("short weak collection index"));
}
let mut keys = Vec::new();
for k in 0..count as usize {
keys.push(idx.get(9 + k * size..9 + (k + 1) * size).ok_or_else(|| bad("short weak collection index"))?.to_vec());
}
Value::WeakVec(self.path(tag)?, key_pid, keys)
}
SF_DATA_STREAM => {
let name = utf16_of(v.get(1..).unwrap_or(&[]));
Value::Stream(self.stream(entry, &name)?)
}
_ => Value::Data(v.to_vec()),
};
o.props.push((pid, value));
}
Ok(o)
}
}
+559
View File
@@ -0,0 +1,559 @@
//! Structural checks of written AAF files against the required properties and rules of the AAF
//! Object Specification v1.1 and the Edit Protocol, read back through the compound file reader.
use std::collections::HashSet;
use craft_timeline::time::FrameRate;
use super::ids::{self, cls, ddef, def, path, pid};
use super::store::{self, Obj, Value};
use super::*;
use crate::model::{CItem, CKind};
use crate::testdoc::{IDENTITY, clip, composition, picture_and_sound_cut, source, track};
fn document() -> Document {
// two 48-frame clips from source frames 10 and 200, a 12-frame transition
picture_and_sound_cut(FrameRate::FPS_24, 48, 12, (10, 200))
}
fn written(doc: &Document, small_sectors: bool) -> Vec<u8> {
let mut report = Report::default();
let bytes = write(doc, &WriteOptions { identity: IDENTITY, small_sectors }, &mut report).unwrap();
assert!(!report.has_warnings(), "{report}");
bytes
}
fn read_clean(bytes: &[u8]) -> Document {
let mut report = Report::default();
let doc = read(bytes, &mut report).unwrap();
assert!(!report.has_warnings(), "{report}");
doc
}
fn walk<'a>(o: &'a Obj, out: &mut Vec<&'a Obj>) {
out.push(o);
for (_, v) in &o.props {
match v {
Value::Strong(c) => walk(c, out),
Value::StrongVec(v) | Value::StrongSet(v, _) => v.iter().for_each(|c| walk(c, out)),
_ => {}
}
}
}
fn keys(dict: &Obj, p: u16) -> HashSet<Vec<u8>> {
dict.objs(p).iter().filter_map(|d| d.data(pid::IDENTIFICATION).map(<[u8]>::to_vec)).collect()
}
/// filmcraft#323: readers that load the meta-dictionary (pyaaf2) need its ClassDefinitions and
/// TypeDefinitions sets. They are empty: everything written uses the baseline classes and types
/// those readers already know.
#[test]
fn the_meta_dictionary_has_its_class_and_type_definition_sets() {
for small in [false, true] {
let bytes = written(&document(), small);
let cf = craft_cfb::CompoundFile::open(&bytes).unwrap();
assert_eq!(cf.entries[cf.find("MetaDictionary-1").unwrap()].clsid, ids::META_DICTIONARY);
for name in ["ClassDefinitions-3", "TypeDefinitions-4"] {
// u32 count, u32 first free key, u32 last free key, u16 key pid, u8 key size
let index = cf.read_path(&format!("MetaDictionary-1/{name} index")).unwrap_or_else(|e| panic!("{name}: {e}"));
assert_eq!(index.len(), 15, "{name}: an empty set");
assert_eq!(index[0..4], 0u32.to_le_bytes(), "{name}: no entries");
assert_eq!(u16::from_le_bytes([index[12], index[13]]), pid::META_IDENTIFICATION, "{name}: keyed by the definition's AUID");
assert_eq!(index[14], 16, "{name}: 16-byte keys");
}
let root = store::read(&bytes).unwrap();
let meta = root.strong(pid::ROOT_META_DICTIONARY).unwrap();
for set in [pid::META_CLASS_DEFINITIONS, pid::META_TYPE_DEFINITIONS] {
assert!(matches!(meta.get(set), Some(Value::StrongSet(items, k)) if items.is_empty() && *k == pid::META_IDENTIFICATION), "{set:#06x}");
}
}
}
#[test]
fn written_files_have_the_required_structure() {
for small in [false, true] {
let bytes = written(&document(), small);
assert_written_file(&bytes, small);
}
}
/// The top-level composition is tagged `Usage_TopLevel`, which the SMPTE Labels register gives as
/// urn:smpte:ul:060e2b34.04010101.0d010102.01010700, stored as the AUID
/// {0d010102-0101-0700-060e-2b3404010101}. Readers that look for it (LibAAF) find no sequence
/// without it.
#[test]
fn the_top_level_composition_has_the_registered_usage_code() {
let bytes = written(&document(), false);
let root = store::read(&bytes).unwrap();
let content = root.strong(pid::ROOT_HEADER).unwrap().strong(pid::CONTENT).unwrap();
let comp = content.objs(pid::MOBS).iter().find(|m| m.class == cls::COMPOSITION_MOB).unwrap();
let usage = [0x02, 0x01, 0x01, 0x0D, 0x01, 0x01, 0x00, 0x07, 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01];
assert_eq!(comp.data(pid::USAGE_CODE), Some(&usage[..]));
}
/// Files from FilmCraft 0.16 and earlier tag the top-level composition with the unregistered label
/// 060e2b34.04010105.0d011201.02030000. They still import: the composition no other one uses is
/// the edit.
#[test]
fn files_with_the_old_usage_code_still_import() {
let bytes = written(&document(), false);
let mut root = store::read(&bytes).unwrap();
let content = strong_mut(strong_mut(&mut root, pid::ROOT_HEADER), pid::CONTENT);
for mob in objs_mut(content, pid::MOBS).iter_mut().filter(|m| m.class == cls::COMPOSITION_MOB) {
mob.set(pid::USAGE_CODE, Value::Data(def::USAGE_TOP_LEVEL_OLD.to_vec()));
}
let old_file = store::write(&root, craft_cfb::Version::V4).unwrap();
let got = read_clean(&old_file);
assert_eq!(got.compositions.len(), 1);
assert_eq!(got, read_clean(&bytes));
}
/// A file that holds one edit tagged with each label (a tool merged a composition from an older
/// file into a newer one) imports both edits.
#[test]
fn edits_tagged_with_either_usage_code_both_import() {
let bytes = written(&document(), false);
let mut root = store::read(&bytes).unwrap();
let content = strong_mut(strong_mut(&mut root, pid::ROOT_HEADER), pid::CONTENT);
let mobs = objs_mut(content, pid::MOBS);
let mut old = mobs.iter().find(|m| m.class == cls::COMPOSITION_MOB).unwrap().clone();
let mut id = old.mob_id(pid::MOB_ID).unwrap();
id[31] ^= 0xFF;
old.set(pid::MOB_ID, Value::Data(id.to_vec()));
old.set(pid::MOB_NAME, Value::Data(store::utf16z("Old")));
old.set(pid::USAGE_CODE, Value::Data(def::USAGE_TOP_LEVEL_OLD.to_vec()));
mobs.push(old);
let mixed = store::write(&root, craft_cfb::Version::V4).unwrap();
let document = read_clean(&mixed);
let mut ids: Vec<_> = document.compositions.iter().map(|c| c.aaf_mob_id.as_deref().unwrap()).collect();
assert_eq!(ids.len(), 2);
assert!(ids.iter().all(|id| id.len() == 64 && id.bytes().all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase())));
ids.sort_unstable();
ids.dedup();
assert_eq!(ids.len(), 2, "each composition keeps its own MobID");
let mut names: Vec<String> = document.compositions.into_iter().map(|c| c.name).collect();
names.sort();
assert_eq!(names, ["Old", "S"]);
}
fn assert_written_file(bytes: &[u8], small: bool) {
assert_compound_file(bytes, small);
let root = store::read(bytes).unwrap();
assert!(root.strong(pid::ROOT_META_DICTIONARY).is_some());
let header = root.strong(pid::ROOT_HEADER).unwrap();
let content = assert_header(header);
let dict = header.strong(pid::DICTIONARY).unwrap();
let definitions = Definitions {
data: keys(dict, pid::DATA_DEFINITIONS),
operations: keys(dict, pid::OPERATION_DEFINITIONS),
interpolation: keys(dict, pid::INTERPOLATION_DEFINITIONS),
containers: keys(dict, pid::CONTAINER_DEFINITIONS),
parameters: keys(dict, pid::PARAMETER_DEFINITIONS),
};
let mobs = content.objs(pid::MOBS);
let comp = assert_mob_set(content, mobs);
for mob in mobs {
assert_mob(mob, mobs, &definitions);
}
assert_composition(comp);
}
fn assert_compound_file(bytes: &[u8], small: bool) {
let cf = craft_cfb::CompoundFile::open(bytes).unwrap();
assert_eq!(cf.version, if small { 3 } else { 4 });
assert_eq!(cf.root().clsid, ids::ROOT);
let references = cf.read_path("referenced properties").unwrap();
let pids: Vec<u16> = references[7..].as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect();
assert!(pids.windows(3).any(|w| w == path::DATA_DEFS));
let header = cf.find("Header-2").unwrap();
assert_eq!(cf.entries[header].clsid, cls::HEADER);
assert!(cf.read_path("Header-2/properties").unwrap().starts_with(&[0x4C, 0x20]));
}
fn assert_header(header: &Obj) -> &Obj {
for req in [pid::BYTE_ORDER, pid::LAST_MODIFIED, pid::CONTENT, pid::DICTIONARY, pid::VERSION, pid::IDENTIFICATION_LIST, pid::OBJECT_MODEL_VERSION]
{
assert!(header.get(req).is_some(), "Header property {req:#06x}");
}
assert_eq!(header.auid(pid::OPERATIONAL_PATTERN), Some(def::OP_EDIT_PROTOCOL));
let ident = &header.objs(pid::IDENTIFICATION_LIST)[0];
for req in [pid::COMPANY_NAME, pid::PRODUCT_NAME, pid::PRODUCT_VERSION_STRING, pid::PRODUCT_ID, pid::DATE, pid::GENERATION_AUID] {
assert!(ident.get(req).is_some(), "Identification property {req:#06x}");
}
header.strong(pid::CONTENT).unwrap()
}
struct Definitions {
data: HashSet<Vec<u8>>,
operations: HashSet<Vec<u8>>,
interpolation: HashSet<Vec<u8>>,
containers: HashSet<Vec<u8>>,
parameters: HashSet<Vec<u8>>,
}
fn assert_mob_set<'a>(content: &Obj, mobs: &'a [Obj]) -> &'a Obj {
let mob_ids: Vec<[u8; 32]> = mobs.iter().map(|m| m.mob_id(pid::MOB_ID).unwrap()).collect();
assert_eq!(mob_ids.iter().collect::<HashSet<_>>().len(), mob_ids.len(), "unique mob ids");
assert!(matches!(content.get(pid::MOBS), Some(Value::StrongSet(_, k)) if *k == pid::MOB_ID));
let compositions: Vec<&Obj> = mobs.iter().filter(|m| m.class == cls::COMPOSITION_MOB).collect();
assert_eq!(compositions.len(), 1);
assert_eq!(compositions[0].auid(pid::USAGE_CODE), Some(def::USAGE_TOP_LEVEL));
assert_eq!(mobs.iter().filter(|m| m.class == cls::MASTER_MOB).count(), 1);
assert_eq!(mobs.iter().filter(|m| m.class == cls::SOURCE_MOB).count(), 3, "picture file, sound file, tape");
compositions[0]
}
fn assert_mob(mob: &Obj, mobs: &[Obj], definitions: &Definitions) {
for req in [pid::MOB_ID, pid::MOB_NAME, pid::SLOTS, pid::MOB_LAST_MODIFIED, pid::MOB_CREATION_TIME] {
assert!(mob.get(req).is_some(), "Mob property {req:#06x}");
}
assert_source_descriptor(mob, &definitions.containers);
for slot in mob.objs(pid::SLOTS) {
assert!(slot.get(pid::SLOT_ID).is_some() && slot.get(pid::SEGMENT).is_some());
if slot.class == cls::TIMELINE_MOB_SLOT {
assert!(slot.rational(pid::EDIT_RATE).is_some_and(|r| r.0 > 0 && r.1 > 0));
assert!(slot.get(pid::ORIGIN).is_some());
}
}
let mut all = Vec::new();
walk(mob, &mut all);
for component in all {
assert_component(component, mobs, definitions);
}
}
fn assert_source_descriptor(mob: &Obj, containers: &HashSet<Vec<u8>>) {
if mob.class != cls::SOURCE_MOB {
return;
}
let descriptor = mob.strong(pid::ESSENCE_DESCRIPTION).expect("SourceMob::EssenceDescription");
if descriptor.class != cls::TAPE_DESCRIPTOR {
for req in [pid::SAMPLE_RATE, pid::FILE_LENGTH, pid::CONTAINER_FORMAT] {
assert!(descriptor.get(req).is_some(), "FileDescriptor property {req:#06x}");
}
assert!(containers.contains(descriptor.weak_key(pid::CONTAINER_FORMAT).unwrap()));
let url = descriptor.objs(pid::LOCATOR)[0].string(pid::URL_STRING).unwrap();
assert_eq!(url, "file:///m/a.mov");
}
if descriptor.class == cls::PCM_DESCRIPTOR {
assert_eq!(descriptor.u32(pid::CHANNELS), Some(2));
assert_eq!(descriptor.u32(pid::QUANTIZATION_BITS), Some(24));
assert_eq!(descriptor.u16(pid::BLOCK_ALIGN), Some(6));
}
}
fn assert_component(o: &Obj, mobs: &[Obj], definitions: &Definitions) {
if is_component(o) {
let dd = o.weak_key(pid::DATA_DEFINITION).expect("Component::DataDefinition");
assert!(definitions.data.contains(dd), "data definition in the dictionary");
let event_seq = o.class == cls::SEQUENCE && dd == ddef::DESCRIPTIVE_METADATA;
assert!(event_seq || o.get(pid::LENGTH).is_some(), "Component::Length");
}
if o.class == cls::SOURCE_CLIP {
assert_source_clip(o, mobs);
} else if o.class == cls::OPERATION_GROUP {
assert_operation_group(o, definitions);
} else if o.class == cls::SEQUENCE && o.get(pid::LENGTH).is_some() {
assert_sequence_length(o);
}
}
fn is_component(o: &Obj) -> bool {
[cls::FILLER, cls::SOURCE_CLIP, cls::SEQUENCE, cls::TRANSITION, cls::OPERATION_GROUP, cls::TIMECODE, cls::COMMENT_MARKER].contains(&o.class)
}
fn assert_source_clip(clip: &Obj, mobs: &[Obj]) {
let id = clip.mob_id(pid::SOURCE_ID).unwrap();
let slot = clip.u32(pid::SOURCE_MOB_SLOT_ID).unwrap();
assert!(clip.get(pid::START_TIME).is_some());
if id != [0; 32] {
let target = mobs.iter().find(|m| m.mob_id(pid::MOB_ID) == Some(id)).expect("source clip target in the file");
assert!(target.objs(pid::SLOTS).iter().any(|s| s.u32(pid::SLOT_ID) == Some(slot)), "target slot exists");
}
}
fn assert_operation_group(group: &Obj, definitions: &Definitions) {
assert!(definitions.operations.contains(group.weak_key(pid::OPERATION).unwrap()));
for parameter in group.objs(pid::PARAMETERS) {
assert!(definitions.parameters.contains(parameter.auid(pid::PARAMETER_DEFINITION).unwrap().as_slice()));
if parameter.class == cls::VARYING_VALUE {
assert!(definitions.interpolation.contains(parameter.weak_key(pid::INTERPOLATION).unwrap()));
assert!(!parameter.objs(pid::POINT_LIST).is_empty());
}
}
}
fn assert_sequence_length(sequence: &Obj) {
let components = sequence.objs(pid::COMPONENTS);
let sum = components
.iter()
.enumerate()
.map(|(i, component)| {
let len = component.i64(pid::LENGTH).unwrap();
if component.class == cls::TRANSITION {
assert!(i > 0 && i + 1 < components.len(), "transition at a sequence end");
assert!(components[i - 1].class != cls::TRANSITION && components[i + 1].class != cls::TRANSITION);
assert!(components[i - 1].i64(pid::LENGTH).unwrap() >= len && components[i + 1].i64(pid::LENGTH).unwrap() >= len);
let cut = component.i64(pid::CUT_POINT).unwrap();
assert!((0..=len).contains(&cut));
assert!(component.strong(pid::OPERATION_GROUP).is_some());
-len
} else {
len
}
})
.sum::<i64>();
assert_eq!(sum, sequence.i64(pid::LENGTH).unwrap(), "sequence length = segments − transitions");
}
fn assert_composition(comp: &Obj) {
let slots = comp.objs(pid::SLOTS);
let tc = slots[0].strong(pid::SEGMENT).unwrap();
assert_eq!(tc.class, cls::TIMECODE);
assert_eq!(tc.u16(pid::TC_FPS), Some(24));
let video = slots[1].strong(pid::SEGMENT).unwrap().objs(pid::COMPONENTS);
assert_eq!(video.iter().map(|c| c.class).collect::<Vec<_>>(), vec![cls::SOURCE_CLIP, cls::TRANSITION, cls::SOURCE_CLIP]);
assert_eq!(video[0].i64(pid::LENGTH), Some(54), "outgoing clip extends to the transition end");
assert_eq!(video[2].i64(pid::LENGTH), Some(54), "incoming clip starts at the transition start");
assert_eq!(video[2].i64(pid::START_TIME), Some(194));
assert_eq!(video[1].i64(pid::CUT_POINT), Some(6));
assert_eq!(video[1].strong(pid::OPERATION_GROUP).unwrap().weak_key(pid::OPERATION), Some(&def::VIDEO_DISSOLVE[..]));
assert_audio_composition_slot(&slots[2]);
}
fn assert_audio_composition_slot(slot: &Obj) {
let audio = slot.strong(pid::SEGMENT).unwrap().objs(pid::COMPONENTS);
assert_eq!(slot.rational(pid::EDIT_RATE), Some((48_000, 1)));
assert_eq!(audio[2].class, cls::OPERATION_GROUP);
assert_eq!(audio[2].weak_key(pid::OPERATION), Some(&def::MONO_AUDIO_GAIN[..]));
let amplitude = audio[2].objs(pid::PARAMETERS)[0].data(pid::CONSTANT_VALUE).unwrap();
let (numerator, denominator) = store::rational_of(&amplitude[17..]).unwrap();
assert!((numerator as f64 / denominator as f64 - 10f64.powf(-3.0 / 20.0)).abs() < 1e-4);
assert_eq!(audio[1].strong(pid::OPERATION_GROUP).unwrap().weak_key(pid::OPERATION), Some(&def::MONO_AUDIO_DISSOLVE[..]));
}
#[test]
fn store_round_trips_every_stored_form() {
let leaf = |n: u8| Obj::new([n; 16]).data_prop(0x1B01, vec![n; 16]);
let root = Obj::new(ids::ROOT)
.data_prop(0x0003, vec![1, 2, 3])
.with(0x0004, Value::Strong(Box::new(leaf(1).with(0x0005, Value::StrongVec(vec![leaf(2), leaf(3)])))))
.with(
0x0002,
Value::Strong(Box::new(
Obj::new([9; 16])
.with(0x3B04, Value::Strong(Box::new(Obj::new([8; 16]).with(0x2605, Value::StrongSet(vec![leaf(4), leaf(5)], 0x1B01))))),
)),
)
.with(0x0006, Value::Weak(path::DATA_DEFS.to_vec(), 0x1B01, vec![5; 16]))
.with(0x0007, Value::WeakVec(path::DATA_DEFS.to_vec(), 0x1B01, vec![vec![4; 16], vec![5; 16]]))
.with(0x0008, Value::Stream((0..10_000u32).map(|i| i as u8).collect()));
for v in [craft_cfb::Version::V3, craft_cfb::Version::V4] {
let bytes = store::write(&root, v).unwrap();
assert_eq!(store::read(&bytes).unwrap(), root);
}
// a data value longer than a property can hold is an error, not a panic
assert!(store::write(&Obj::new(ids::ROOT).data_prop(1, vec![0; 70_000]), craft_cfb::Version::V4).is_err());
}
/// The property `p` of `o` as a list of objects, to change.
fn objs_mut(o: &mut Obj, p: u16) -> &mut Vec<Obj> {
match o.props.iter_mut().find(|(k, _)| *k == p).map(|(_, v)| v) {
Some(Value::StrongVec(v)) | Some(Value::StrongSet(v, _)) => v,
_ => panic!("no object list {p:#06x}"),
}
}
fn strong_mut(o: &mut Obj, p: u16) -> &mut Obj {
match o.props.iter_mut().find(|(k, _)| *k == p).map(|(_, v)| v) {
Some(Value::Strong(v)) => v,
_ => panic!("no object {p:#06x}"),
}
}
fn is_picture(o: &Obj) -> bool {
o.weak_key(pid::DATA_DEFINITION) == Some(&ddef::PICTURE[..])
}
/// How Premiere Pro 26.5.2 lays a sequence with a nested sequence out in AAF (seen in a file it
/// exported): every composition is tagged top-level, the nested one too; all video tracks of a
/// composition are in ONE slot, a nested scope with a segment per track, lowest first; a clip of
/// the nested sequence is a source clip that points at its composition. Our own file is rewritten
/// into that layout and must read back as the same edit.
#[test]
fn premiere_style_layers_and_nested_compositions_are_read() {
let r = FrameRate::FPS_24;
// "Outer": media on V1 and V3, the sequence "S" nested on V2 with its sound on A1
let inner = document();
let mut sources = inner.sources.clone();
for kind in [CKind::Picture, CKind::Sound] {
let mut nest = source("seq:2", "S", kind, r, 16, None);
(nest.path, nest.nested, nest.length, nest.width, nest.height) = (None, Some(0), r.tick_of(96), 1920, 1080);
sources.push(nest);
}
let gap = |frames: i64| CItem::Filler(r.tick_of(frames));
let outer = composition(
"Outer",
r,
vec![
track(CKind::Picture, "V1", 1, vec![clip(r, 0, 5, 30, "a")]),
track(CKind::Picture, "V2", 2, vec![gap(10), clip(r, 2, 12, 40, "S")]),
track(CKind::Picture, "V3", 3, vec![gap(60), clip(r, 0, 100, 20, "a")]),
track(CKind::Sound, "A1", 1, vec![gap(10), clip(r, 3, 12, 40, "S")]),
],
);
let ours = written(&Document { compositions: vec![outer], sources, nested: inner.compositions }, false);
let mut root = store::read(&ours).unwrap();
let content = strong_mut(strong_mut(&mut root, pid::ROOT_HEADER), pid::CONTENT);
let mut compositions = 0;
for mob in objs_mut(content, pid::MOBS).iter_mut().filter(|m| m.class == cls::COMPOSITION_MOB) {
compositions += 1;
mob.set(pid::USAGE_CODE, Value::Data(def::USAGE_TOP_LEVEL.to_vec()));
let slots = objs_mut(mob, pid::SLOTS);
let picture: Vec<usize> = slots.iter().enumerate().filter(|(_, s)| s.strong(pid::SEGMENT).is_some_and(is_picture)).map(|(i, _)| i).collect();
let layers: Vec<Obj> = picture.iter().map(|&i| slots[i].strong(pid::SEGMENT).unwrap().clone()).collect();
let length = layers.iter().filter_map(|l| l.i64(pid::LENGTH)).max().unwrap_or(0);
let scope = Obj::new(cls::NESTED_SCOPE)
.with(pid::DATA_DEFINITION, Value::Weak(path::DATA_DEFS.to_vec(), pid::IDENTIFICATION, ddef::PICTURE.to_vec()))
.data_prop(pid::LENGTH, length.to_le_bytes().to_vec())
.with(pid::NESTED_SLOTS, Value::StrongVec(layers));
// the first video slot keeps its id (clips of the nested sequence point at it) and holds
// every layer; the other video slots go
slots[picture[0]].set(pid::SEGMENT, Value::Strong(Box::new(scope)));
for &i in picture[1..].iter().rev() {
slots.remove(i);
}
}
assert_eq!(compositions, 2);
let theirs = store::write(&root, craft_cfb::Version::V4).unwrap();
assert_ne!(theirs, ours);
let want = read_clean(&ours);
let got = read_clean(&theirs);
// one edit; the nested composition is one it uses, not a second edit
assert_eq!(got.compositions.len(), 1);
assert_eq!(got.nested.len(), 1);
// layers of one slot share its name and are all as long as the scope: the same edit apart
// from picture track names and gaps after the last clip
let edit = |mut doc: Document| {
for t in doc.compositions.iter_mut().chain(&mut doc.nested).flat_map(|c| &mut c.tracks).filter(|t| t.kind == CKind::Picture) {
t.name.clear();
while matches!(t.items.last(), Some(CItem::Filler(_))) {
t.items.pop();
}
}
doc
};
assert_eq!(edit(got.clone()), edit(want));
// and that edit is the one that was written: three video tracks, the nest on the second
let q = &got.compositions[0];
let picture: Vec<_> = q.tracks.iter().filter(|t| t.kind == CKind::Picture).collect();
assert_eq!(picture.iter().map(|t| t.items.iter().filter(|i| matches!(i, CItem::Clip(_))).count()).collect::<Vec<_>>(), [1, 1, 1]);
let nest_of = |kind: CKind| {
let t = q.tracks.iter().filter(|t| t.kind == kind).nth(if kind == CKind::Picture { 1 } else { 0 }).unwrap();
let [CItem::Filler(gap), CItem::Clip(c), ..] = &t.items[..] else { panic!("{:?}", t.items) };
(*gap, c.len, c.start, got.sources[c.source].nested, got.sources[c.source].name.clone())
};
assert_eq!(nest_of(CKind::Picture), (r.tick_of(10), r.tick_of(40), r.tick_of(12), Some(0), "S".to_string()));
assert_eq!(nest_of(CKind::Sound), nest_of(CKind::Picture));
assert_eq!(got.nested[0].name, "S");
}
/// A slot's name is the track's name, whatever it starts with; a track without one reads back
/// without one.
#[test]
fn audio_tracks_keep_their_names() {
for name in ["Dialogue.Dialogue-1", "Dialogue.Dialogue-1 L", "", "é", "音声", "🎤 Dialogue", "Ä1"] {
let mut doc = document();
doc.compositions[0].tracks[1].name = name.into();
let back = read_clean(&written(&doc, false));
assert_eq!(back.compositions[0].tracks[1].name, name);
}
}
#[test]
fn unnamed_source_clip_uses_the_referenced_master_name() {
let mut doc = crate::testdoc::sound_only(None);
let name = doc.sources[0].name.clone();
for item in &mut doc.compositions[0].tracks[0].items {
if let CItem::Clip(clip) = item {
clip.name = name.clone();
}
}
let mut root = store::read(&written(&doc, false)).unwrap();
let content = strong_mut(strong_mut(&mut root, pid::ROOT_HEADER), pid::CONTENT);
let master = objs_mut(content, pid::MOBS).iter_mut().find(|m| m.class == cls::MASTER_MOB).unwrap();
master.set(pid::MOB_NAME, Value::Data(store::utf16z("Master edit")));
let bytes = store::write(&root, craft_cfb::Version::V4).unwrap();
let back = read_clean(&bytes);
let clip = back.compositions[0].tracks[0]
.items
.iter()
.find_map(|item| match item {
CItem::Clip(c) => Some(c),
_ => None,
})
.unwrap();
assert_eq!(clip.name, "Master edit");
}
#[test]
fn sound_source_offsets_use_audio_sample_rate_on_disk() {
let doc = crate::testdoc::sound_only(None);
let bytes = written(&doc, false);
let root = store::read(&bytes).unwrap();
let mut all = Vec::new();
walk(&root, &mut all);
let starts: Vec<i64> = all.iter().filter(|o| o.class == cls::SOURCE_CLIP).filter_map(|o| o.i64(pid::START_TIME)).collect();
assert!(starts.contains(&19_200), "expected 0.4 seconds at 48 kHz: {starts:?}");
let back = read_clean(&bytes);
let clip = back.compositions[0].tracks[0]
.items
.iter()
.find_map(|i| match i {
CItem::Clip(c) => Some(c),
_ => None,
})
.unwrap();
assert_eq!(clip.start, craft_timeline::time::FrameRate::FPS_25.tick_of(10));
}
#[test]
fn flattened_selectors_and_nested_scopes_are_reported() {
for (class, property, message) in
[(cls::SELECTOR, pid::SELECTED, "selector was flattened"), (cls::NESTED_SCOPE, pid::NESTED_SLOTS, "nested scope was flattened")]
{
let mut root = store::read(&written(&document(), false)).unwrap();
let content = strong_mut(strong_mut(&mut root, pid::ROOT_HEADER), pid::CONTENT);
let comp = objs_mut(content, pid::MOBS).iter_mut().find(|mob| mob.class == cls::COMPOSITION_MOB).unwrap();
let slot = objs_mut(comp, pid::SLOTS)
.iter_mut()
.find(|slot| {
slot.strong(pid::SEGMENT).is_some_and(|s| s.class == cls::SEQUENCE && s.weak_key(pid::DATA_DEFINITION) == Some(&ddef::SOUND[..]))
})
.unwrap();
let segment = strong_mut(slot, pid::SEGMENT);
let child = segment.clone();
let mut wrapper = Obj::new(class)
.with(pid::DATA_DEFINITION, child.get(pid::DATA_DEFINITION).unwrap().clone())
.with(pid::LENGTH, child.get(pid::LENGTH).unwrap().clone());
let value = if class == cls::SELECTOR { Value::Strong(Box::new(child)) } else { Value::StrongVec(vec![child]) };
wrapper.set(property, value);
*segment = wrapper;
let bytes = store::write(&root, craft_cfb::Version::V4).unwrap();
let mut report = Report::default();
read(&bytes, &mut report).unwrap();
assert!(report.mentions(message), "{report}");
}
}
#[test]
fn relative_media_locator_round_trips_escaped_characters() {
let mut doc = document();
doc.sources[0].path = Some("Audio Files/100%20 #1.wav".into());
let bytes = written(&doc, false);
let got = read_clean(&bytes);
assert!(got.sources.iter().any(|s| s.path.as_deref() == Some("Audio Files/100%20 #1.wav")));
}
+804
View File
@@ -0,0 +1,804 @@
//! Composition model → AAF objects.
use std::collections::HashMap;
use craft_timeline::time::{FrameRate, Tick};
use super::ids::{META_DICTIONARY, ROOT, cls, ddef, def, path, pid};
use super::store::{self, Auid, Obj, Value, rational, utf16z};
use crate::model::{CItem, CKind, CMarker, Composition, Document, Gain, Source, ticks_to_units};
use crate::{Error, Identity, Report, Result};
/// UMID-style mob id (SMPTE 330 basic UMID): label, length 0x13, instance 0, material number.
pub(crate) fn mob_id(seed: u64, n: u64) -> [u8; 32] {
let mut id = [0u8; 32];
id[..12].copy_from_slice(&[0x06, 0x0A, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05, 0x01, 0x01, 0x0F, 0x20]);
id[12] = 0x13;
let a = mix(seed ^ n.wrapping_mul(0x9E37_79B9_7F4A_7C15));
let b = mix(a ^ 0xD6E8_FEB8_6659_FD93);
id[16..24].copy_from_slice(&a.to_le_bytes());
id[24..32].copy_from_slice(&b.to_le_bytes());
// a "random" material number per RFC 4122 v4 layout keeps it a valid UUID
id[22] = (id[22] & 0x0F) | 0x40;
id[24] = (id[24] & 0x3F) | 0x80;
id
}
fn mix(mut z: u64) -> u64 {
z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
z ^ (z >> 31)
}
pub(crate) fn fnv(s: &[u8], h: u64) -> u64 {
s.iter().fold(h, |h, &b| (h ^ b as u64).wrapping_mul(0x0000_0100_0000_01B3))
}
fn timestamp() -> Vec<u8> {
// 1970-01-01 00:00:00.00: written files are reproducible
let mut v = 1970i16.to_le_bytes().to_vec();
v.extend_from_slice(&[1, 1, 0, 0, 0, 0]);
v
}
fn weak(path: [u16; 3], key: Auid) -> Value {
Value::Weak(path.to_vec(), pid::IDENTIFICATION, key.to_vec())
}
fn data_def(kind: CKind) -> Auid {
match kind {
CKind::Picture => ddef::PICTURE,
CKind::Sound => ddef::SOUND,
}
}
/// An indirect value: byte order, type id, value.
pub(crate) fn indirect(ty: Auid, v: &[u8]) -> Vec<u8> {
let mut d = vec![0x4C];
d.extend_from_slice(&ty);
d.extend_from_slice(v);
d
}
fn tagged(name: &str, value: &str) -> Obj {
Obj::new(cls::TAGGED_VALUE).data_prop(pid::TAG_NAME, utf16z(name)).data_prop(pid::TAG_VALUE, indirect(def::TYPE_STRING, &utf16z(value)))
}
fn gain_rational(g: f64) -> Vec<u8> {
rational((g.max(0.0) * 65536.0).round().min(i32::MAX as f64) as i64, 65536)
}
fn definition(class: Auid, id: Auid, name: &str) -> Obj {
Obj::new(class).data_prop(pid::IDENTIFICATION, id.to_vec()).data_prop(pid::NAME, utf16z(name)).data_prop(pid::DESCRIPTION, utf16z(""))
}
struct W<'a> {
report: &'a mut Report,
inexact: bool,
}
struct IdGen {
seed: u64,
next: u64,
}
impl IdGen {
fn for_document(doc: &Document, comp: &Composition) -> Self {
let mut seed = fnv(comp.name.as_bytes(), 0xCBF2_9CE4_8422_2325);
for source in &doc.sources {
seed = fnv(source.path.as_deref().unwrap_or("").as_bytes(), fnv(source.key.as_bytes(), seed));
}
seed = fnv(&(comp.tracks.len() as u64).to_le_bytes(), seed);
Self { seed, next: 0 }
}
fn next(&mut self) -> [u8; 32] {
self.next += 1;
mob_id(self.seed, self.next)
}
}
struct MediaOutput {
mobs: Vec<Obj>,
essence: Vec<Obj>,
master_ref: HashMap<usize, ([u8; 32], u32)>,
}
type FileMob = ((Option<String>, usize, CKind), [u8; 32], Vec<Obj>, usize);
struct GroupSlots {
master_id: [u8; 32],
tape_id: [u8; 32],
timecode: Option<(i64, FrameRate)>,
master_slots: Vec<Obj>,
tape_slots: Vec<Obj>,
files: Vec<FileMob>,
master_ref: HashMap<usize, ([u8; 32], u32)>,
}
struct GroupSlotBuilder<'a, 'b> {
doc: &'a Document,
master_id: [u8; 32],
tape_id: [u8; 32],
ids: &'b mut IdGen,
files: &'b mut Vec<FileMob>,
master_slots: &'b mut Vec<Obj>,
tape_slots: &'b mut Vec<Obj>,
master_ref: &'b mut HashMap<usize, ([u8; 32], u32)>,
}
struct FileSlotInput<'a> {
source: &'a Source,
file_slot: u32,
length: i64,
has_timecode: bool,
tape_id: [u8; 32],
member_index: usize,
slots: &'a mut Vec<Obj>,
rate: (i64, i64),
}
impl W<'_> {
/// Edit units at `rate` of tick `t`.
fn u(&mut self, t: Tick, rate: (i64, i64)) -> i64 {
let (n, exact) = ticks_to_units(t, rate.0, rate.1);
if !exact {
self.inexact = true;
}
n
}
}
fn source_rate(s: &Source) -> (i64, i64) {
match s.kind {
CKind::Picture => (s.frame_rate.num, s.frame_rate.den),
CKind::Sound => (s.sample_rate.max(1) as i64, 1),
}
}
fn write_media(doc: &Document, w: &mut W<'_>, ids: &mut IdGen) -> MediaOutput {
let mut groups: Vec<(String, Vec<usize>)> = Vec::new();
for (index, source) in doc.sources.iter().enumerate() {
if source.nested.is_some() {
continue;
}
match groups.iter_mut().find(|(key, _)| *key == source.key) {
Some((_, members)) => members.push(index),
None => groups.push((source.key.clone(), vec![index])),
}
}
let mut output = MediaOutput { mobs: Vec::new(), essence: Vec::new(), master_ref: HashMap::new() };
for (_, members) in groups {
write_source_group(doc, &members, w, ids, &mut output);
}
output
}
fn write_source_group(doc: &Document, members: &[usize], w: &mut W<'_>, ids: &mut IdGen, output: &mut MediaOutput) {
let first = &doc.sources[members[0]];
let slots = build_group_slots(doc, members, w, ids);
output.master_ref.extend(slots.master_ref);
let mut master_slots = slots.master_slots;
add_master_markers(doc, members, w, &mut master_slots);
output.mobs.push(
Obj::new(cls::MASTER_MOB)
.data_prop(pid::MOB_ID, slots.master_id.to_vec())
.data_prop(pid::MOB_NAME, utf16z(&first.name))
.data_prop(pid::MOB_LAST_MODIFIED, timestamp())
.data_prop(pid::MOB_CREATION_TIME, timestamp())
.with(pid::SLOTS, Value::StrongVec(master_slots)),
);
let tape_id = slots.tape_id;
let timecode = slots.timecode;
let tape_slots = slots.tape_slots;
add_file_mobs(doc, slots.files, w, output);
add_tape_mob(first, tape_id, timecode, tape_slots, output);
}
fn build_group_slots(doc: &Document, members: &[usize], w: &mut W<'_>, ids: &mut IdGen) -> GroupSlots {
let master_id = ids.next();
let tape_id = ids.next();
let timecode = members.iter().find_map(|&i| doc.sources[i].start_tc.map(|t| (t, doc.sources[i].tc_rate)));
let mut tape_slots = Vec::new();
if let Some((start, rate)) = timecode {
tape_slots.push(timecode_slot(members, doc, w, start, rate));
}
let mut files: Vec<FileMob> = Vec::new();
let mut master_slots = Vec::new();
let mut master_ref = HashMap::new();
let mut builder = GroupSlotBuilder {
doc,
master_id,
tape_id,
ids,
files: &mut files,
master_slots: &mut master_slots,
tape_slots: &mut tape_slots,
master_ref: &mut master_ref,
};
for (member_index, &source_index) in members.iter().enumerate() {
builder.add_source(source_index, member_index, timecode.is_some(), w);
}
GroupSlots { master_id, tape_id, timecode, master_slots, tape_slots, files, master_ref }
}
fn timecode_slot(members: &[usize], doc: &Document, w: &mut W<'_>, start: i64, rate: FrameRate) -> Obj {
let edit_rate = (rate.num, rate.den);
let len = members.iter().map(|&i| doc.sources[i].length).max().unwrap_or(Tick::ZERO);
let units = w.u(len, edit_rate);
timeline_slot(
1,
"TC1",
0,
edit_rate,
Obj::new(cls::TIMECODE)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, ddef::TIMECODE))
.data_prop(pid::LENGTH, units.to_le_bytes().to_vec())
.data_prop(pid::TC_START, start.to_le_bytes().to_vec())
.data_prop(pid::TC_FPS, (rate.timecode_base().clamp(1, u16::MAX as i64) as u16).to_le_bytes().to_vec())
.data_prop(pid::TC_DROP, vec![0]),
)
}
impl GroupSlotBuilder<'_, '_> {
fn add_source(&mut self, source_index: usize, member_index: usize, has_timecode: bool, w: &mut W<'_>) {
let source = &self.doc.sources[source_index];
let rate = source_rate(source);
let embedded_key = if source.embedded.is_some() { source_index } else { usize::MAX };
let file_key = (source.path.clone(), embedded_key, source.kind);
let file_slot = source.channel.map_or(1, |channel| channel + 1);
let len_units = w.u(source.length, rate);
let file_index = match self.files.iter().position(|file| file.0 == file_key) {
Some(index) => index,
None => {
self.files.push((file_key, self.ids.next(), Vec::new(), source_index));
self.files.len() - 1
}
};
let file_id = self.files[file_index].1;
add_file_slot(FileSlotInput {
source,
file_slot,
length: len_units,
has_timecode,
tape_id: self.tape_id,
member_index,
slots: &mut self.files[file_index].2,
rate,
});
if has_timecode {
let tape_slot_id = 2 + member_index as u32;
self.tape_slots.push(timeline_slot(
tape_slot_id,
&slot_name(source.kind, member_index as u32 + 1),
member_index as u32 + 1,
rate,
source_clip(source.kind, len_units, [0; 32], 0, 0),
));
}
let master_slot = member_index as u32 + 1;
self.master_slots.push(timeline_slot(
master_slot,
&slot_name(source.kind, master_slot),
master_slot,
rate,
source_clip(source.kind, len_units, file_id, file_slot, 0),
));
self.master_ref.insert(source_index, (self.master_id, master_slot));
}
}
fn add_file_slot(input: FileSlotInput<'_>) {
let FileSlotInput { source, file_slot, length, has_timecode, tape_id, member_index, slots, rate } = input;
if slots.iter().any(|slot| slot.u32(pid::SLOT_ID) == Some(file_slot)) {
return;
}
let tape_slot_id = if has_timecode { 2 + member_index as u32 } else { 0 };
let mob_id = if has_timecode { tape_id } else { [0; 32] };
let clip = source_clip(source.kind, length, mob_id, tape_slot_id, 0);
slots.push(timeline_slot(file_slot, &slot_name(source.kind, file_slot), file_slot, rate, clip));
}
fn add_master_markers(doc: &Document, members: &[usize], w: &mut W<'_>, master_slots: &mut Vec<Obj>) {
let first = &doc.sources[members[0]];
let marker_rate =
members.iter().map(|&i| &doc.sources[i]).find(|source| source.kind == CKind::Picture).map(source_rate).unwrap_or_else(|| source_rate(first));
let markers: Vec<&CMarker> = members.iter().flat_map(|&i| doc.sources[i].markers.iter()).collect();
if markers.is_empty() {
return;
}
let mut unique: Vec<CMarker> = markers.into_iter().cloned().collect();
unique.sort_by(|a, b| (a.start, &a.name).cmp(&(b.start, &b.name)));
unique.dedup();
master_slots.push(event_slot(w, members.len() as u32 + 1, marker_rate, &unique));
}
fn add_file_mobs(doc: &Document, files: Vec<FileMob>, w: &mut W<'_>, output: &mut MediaOutput) {
for (_, file_id, slots, source_index) in files {
let source = &doc.sources[source_index];
let desc = descriptor(w, source);
output.mobs.push(
Obj::new(cls::SOURCE_MOB)
.data_prop(pid::MOB_ID, file_id.to_vec())
.data_prop(pid::MOB_NAME, utf16z(&source.name))
.data_prop(pid::MOB_LAST_MODIFIED, timestamp())
.data_prop(pid::MOB_CREATION_TIME, timestamp())
.with(pid::SLOTS, Value::StrongVec(slots))
.with(pid::ESSENCE_DESCRIPTION, Value::Strong(Box::new(desc))),
);
if let Some(data) = &source.embedded {
output.essence.push(
Obj::new(cls::ESSENCE_DATA).data_prop(pid::ESSENCE_MOB_ID, file_id.to_vec()).with(pid::ESSENCE_STREAM, Value::Stream(data.clone())),
);
}
}
}
fn add_tape_mob(first: &Source, tape_id: [u8; 32], timecode: Option<(i64, FrameRate)>, tape_slots: Vec<Obj>, output: &mut MediaOutput) {
let Some(_) = timecode else { return };
let reel = first.path.as_deref().map(craft_timeline::path::file_stem).unwrap_or(&first.name).to_string();
output.mobs.push(
Obj::new(cls::SOURCE_MOB)
.data_prop(pid::MOB_ID, tape_id.to_vec())
.data_prop(pid::MOB_NAME, utf16z(&reel))
.data_prop(pid::MOB_LAST_MODIFIED, timestamp())
.data_prop(pid::MOB_CREATION_TIME, timestamp())
.with(pid::SLOTS, Value::StrongVec(tape_slots))
.with(pid::ESSENCE_DESCRIPTION, Value::Strong(Box::new(Obj::new(cls::TAPE_DESCRIPTOR)))),
);
}
/// Serialise a composition document.
pub(crate) fn write(doc: &Document, version: craft_cfb::Version, identity: &Identity<'_>, report: &mut Report) -> Result<Vec<u8>> {
let comp = doc.compositions.first().ok_or(Error::Empty)?;
let mut w = W { report, inexact: false };
let mut ids = IdGen::for_document(doc, comp);
let MediaOutput { mut mobs, essence, master_ref } = write_media(doc, &mut w, &mut ids);
let mut used_ops: Vec<Auid> = Vec::new();
let mut uses_varying = false;
// ---- nested compositions: a clip refers to one as it does to a master mob, through the
// composition's first track of the clip's kind (a broken-out channel: that channel's track)
let mut refs = Refs { mobs: master_ref, rates: doc.sources.iter().enumerate().map(|(i, s)| (i, source_rate(s))).collect() };
let nested_ids: Vec<[u8; 32]> = doc.nested.iter().map(|_| ids.next()).collect();
for (si, s) in doc.sources.iter().enumerate() {
let Some((comp, id)) = s.nested.and_then(|n| Some((doc.nested.get(n)?, nested_ids.get(n)?))) else { continue };
let of_kind: Vec<usize> = comp.tracks.iter().enumerate().filter(|(_, t)| t.kind == s.kind).map(|(i, _)| i).collect();
let Some(&track) = s.channel.and_then(|c| of_kind.get(c as usize)).or(of_kind.first()) else { continue };
let rate = match s.kind {
CKind::Picture => (comp.rate.num, comp.rate.den),
CKind::Sound => (comp.sample_rate.max(1) as i64, 1),
};
refs.mobs.insert(si, (*id, track as u32 + 2));
refs.rates.insert(si, rate);
}
// ---- the compositions: the exported sequence first
let comp_id = ids.next();
let composition_mobs = {
let mut composition_writer = CompositionWriter { w: &mut w, doc, refs: &refs, used_ops: &mut used_ops, uses_varying: &mut uses_varying };
let mut output = vec![composition_writer.write(comp, comp_id, true)];
output.extend(doc.nested.iter().zip(&nested_ids).map(|(nested, id)| composition_writer.write(nested, *id, false)));
output
};
mobs.splice(0..0, composition_mobs);
if w.inexact {
w.report.info("some times are not on whole edit units and were rounded");
}
// ---- dictionary
let mut ddefs = Vec::new();
for (id, name) in
[(ddef::PICTURE, "Picture"), (ddef::SOUND, "Sound"), (ddef::TIMECODE, "Timecode"), (ddef::DESCRIPTIVE_METADATA, "DescriptiveMetadata")]
{
ddefs.push(definition(cls::DATA_DEFINITION, id, name));
}
let mut opdefs = Vec::new();
for op in &used_ops {
let (name, dd, inputs) = match *op {
x if x == def::VIDEO_DISSOLVE => ("Video Dissolve", ddef::PICTURE, 2),
x if x == def::VIDEO_FADE_TO_BLACK => ("Video Fade To Black", ddef::PICTURE, 1),
x if x == def::SMPTE_VIDEO_WIPE => ("SMPTE Video Wipe", ddef::PICTURE, 2),
x if x == def::MONO_AUDIO_DISSOLVE => ("Mono Audio Dissolve", ddef::SOUND, 2),
_ => ("Mono Audio Gain", ddef::SOUND, 1i32),
};
let params: Vec<Vec<u8>> = if *op == def::MONO_AUDIO_GAIN {
vec![def::PARAM_AMPLITUDE.to_vec()]
} else if *op == def::VIDEO_DISSOLVE {
vec![def::PARAM_LEVEL.to_vec()]
} else {
Vec::new()
};
let mut o = definition(cls::OPERATION_DEFINITION, *op, name)
.with(pid::OPDEF_DATA_DEFINITION, weak(path::DATA_DEFS, dd))
.data_prop(pid::OPDEF_IS_TIME_WARP, vec![0])
.data_prop(pid::OPDEF_NUMBER_INPUTS, inputs.to_le_bytes().to_vec());
if !params.is_empty() {
o.set(pid::OPDEF_PARAMETERS_DEFINED, Value::WeakVec(path::PARAMETER_DEFS.to_vec(), pid::IDENTIFICATION, params));
}
opdefs.push(o);
}
let pdefs = vec![
definition(cls::PARAMETER_DEFINITION, def::PARAM_LEVEL, "Level").data_prop(pid::PARAMDEF_DISPLAY_UNITS, utf16z("")),
definition(cls::PARAMETER_DEFINITION, def::PARAM_AMPLITUDE, "Amplitude").data_prop(pid::PARAMDEF_DISPLAY_UNITS, utf16z("")),
];
let idefs = if uses_varying || !used_ops.is_empty() {
vec![
definition(cls::INTERPOLATION_DEFINITION, def::INTERP_LINEAR, "Linear"),
definition(cls::INTERPOLATION_DEFINITION, def::INTERP_CONSTANT, "Constant"),
]
} else {
Vec::new()
};
let cdefs = vec![
definition(cls::CONTAINER_DEFINITION, def::CONTAINER_EXTERNAL, "External Container"),
definition(cls::CONTAINER_DEFINITION, def::CONTAINER_AAF, "AAF Container"),
];
let mut dict = Obj::new(cls::DICTIONARY)
.with(pid::DATA_DEFINITIONS, Value::StrongSet(ddefs, pid::IDENTIFICATION))
.with(pid::PARAMETER_DEFINITIONS, Value::StrongSet(pdefs, pid::IDENTIFICATION))
.with(pid::CONTAINER_DEFINITIONS, Value::StrongSet(cdefs, pid::IDENTIFICATION));
if !opdefs.is_empty() {
dict.set(pid::OPERATION_DEFINITIONS, Value::StrongSet(opdefs, pid::IDENTIFICATION));
}
if !idefs.is_empty() {
dict.set(pid::INTERPOLATION_DEFINITIONS, Value::StrongSet(idefs, pid::IDENTIFICATION));
}
let mut content = Obj::new(cls::CONTENT_STORAGE).with(pid::MOBS, Value::StrongSet(mobs, pid::MOB_ID));
if !essence.is_empty() {
content.set(pid::ESSENCE_DATA, Value::StrongSet(essence, pid::ESSENCE_MOB_ID));
}
let ident = Obj::new(cls::IDENTIFICATION)
.data_prop(pid::COMPANY_NAME, utf16z(identity.company))
.data_prop(pid::PRODUCT_NAME, utf16z(identity.product))
.data_prop(pid::PRODUCT_VERSION_STRING, utf16z(identity.version))
.data_prop(pid::PRODUCT_ID, identity.product_id.to_vec())
.data_prop(pid::DATE, timestamp())
.data_prop(pid::PLATFORM, utf16z(identity.platform))
.data_prop(pid::GENERATION_AUID, mob_id(ids.seed, 0)[16..].to_vec());
let header = Obj::new(cls::HEADER)
.data_prop(pid::BYTE_ORDER, 0x4949i16.to_le_bytes().to_vec())
.data_prop(pid::LAST_MODIFIED, timestamp())
.data_prop(pid::VERSION, vec![1, 1])
.data_prop(pid::OBJECT_MODEL_VERSION, 1u32.to_le_bytes().to_vec())
.data_prop(pid::OPERATIONAL_PATTERN, def::OP_EDIT_PROTOCOL.to_vec())
.with(pid::CONTENT, Value::Strong(Box::new(content)))
.with(pid::DICTIONARY, Value::Strong(Box::new(dict)))
.with(pid::IDENTIFICATION_LIST, Value::StrongVec(vec![ident]));
// The meta-dictionary holds only extensions to the baseline object model, and everything written
// here is baseline, so its class and type definition sets are empty; readers that load them
// (pyaaf2) still need the sets to be there (filmcraft#323).
let meta = Obj::new(META_DICTIONARY)
.with(pid::META_CLASS_DEFINITIONS, Value::StrongSet(Vec::new(), pid::META_IDENTIFICATION))
.with(pid::META_TYPE_DEFINITIONS, Value::StrongSet(Vec::new(), pid::META_IDENTIFICATION));
let root = Obj::new(ROOT).with(pid::ROOT_META_DICTIONARY, Value::Strong(Box::new(meta))).with(pid::ROOT_HEADER, Value::Strong(Box::new(header)));
store::write(&root, version).map_err(Error::Other)
}
/// Where clips find their sources: source index → (mob id, slot id), and for nested compositions
/// the edit rate of that slot.
#[derive(Default)]
struct Refs {
mobs: HashMap<usize, ([u8; 32], u32)>,
rates: HashMap<usize, (i64, i64)>,
}
/// The composition mob of `comp`. Slot 1 is its timecode; its tracks follow from slot 2 in order.
struct CompositionWriter<'a, 'b, 'c> {
w: &'a mut W<'c>,
doc: &'b Document,
refs: &'b Refs,
used_ops: &'a mut Vec<Auid>,
uses_varying: &'a mut bool,
}
impl CompositionWriter<'_, '_, '_> {
fn write(&mut self, comp: &Composition, id: [u8; 32], top: bool) -> Obj {
let w = &mut *self.w;
let doc = self.doc;
let refs = self.refs;
let used_ops = &mut *self.used_ops;
let uses_varying = &mut *self.uses_varying;
let crate_rate = (comp.rate.num, comp.rate.den);
let mut slots = Vec::new();
let total = comp
.tracks
.iter()
.map(|t| {
let mut c = Tick::ZERO;
for i in &t.items {
match i {
CItem::Transition(x) => c -= x.len,
other => c += other.len(),
}
}
c
})
.max()
.unwrap_or(Tick::ZERO);
let total_units = w.u(total, crate_rate);
slots.push(timeline_slot(
1,
"TC1",
0,
crate_rate,
Obj::new(cls::TIMECODE)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, ddef::TIMECODE))
.data_prop(pid::LENGTH, total_units.to_le_bytes().to_vec())
.data_prop(pid::TC_START, comp.start_tc.to_le_bytes().to_vec())
.data_prop(pid::TC_FPS, (comp.rate.timecode_base().clamp(1, u16::MAX as i64) as u16).to_le_bytes().to_vec())
.data_prop(pid::TC_DROP, vec![comp.drop as u8]),
));
let mut slot_id = 2u32;
for t in &comp.tracks {
let rate = match t.kind {
CKind::Picture => crate_rate,
CKind::Sound => (comp.sample_rate.max(1) as i64, 1),
};
let dd = data_def(t.kind);
let mut comps = Vec::new();
let mut cursor = Tick::ZERO;
for it in &t.items {
match it {
CItem::Filler(l) => {
let n = w.u(cursor + *l, rate) - w.u(cursor, rate);
cursor += *l;
comps.push(
Obj::new(cls::FILLER)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, dd))
.data_prop(pid::LENGTH, n.to_le_bytes().to_vec()),
);
}
CItem::Clip(c) => {
let n = w.u(cursor + c.len, rate) - w.u(cursor, rate);
let s = &doc.sources[c.source];
let (mid, mslot) = refs.mobs.get(&c.source).copied().unwrap_or(([0; 32], 0));
// (a nested composition counts the start in its own slot's edit units)
let start = w.u(c.start, refs.rates.get(&c.source).copied().unwrap_or(rate));
let mut sc = source_clip(t.kind, n, mid, mslot, start);
if !c.name.is_empty() && c.name != s.name {
sc.set(pid::COMPONENT_USER_COMMENTS, Value::StrongVec(vec![tagged("Clip Name", &c.name)]));
}
let seg = match (&c.gain, t.kind) {
(Some(g), CKind::Sound) => {
if !used_ops.contains(&def::MONO_AUDIO_GAIN) {
used_ops.push(def::MONO_AUDIO_GAIN);
}
let param = match g {
Gain::Constant(a) => Obj::new(cls::CONSTANT_VALUE)
.data_prop(pid::PARAMETER_DEFINITION, def::PARAM_AMPLITUDE.to_vec())
.data_prop(pid::CONSTANT_VALUE, indirect(def::TYPE_RATIONAL, &gain_rational(*a))),
Gain::Varying { linear, points } => {
*uses_varying = true;
let pts = points
.iter()
.map(|(off, a)| {
let o = w.u(cursor + *off, rate) - w.u(cursor, rate);
Obj::new(cls::CONTROL_POINT)
.data_prop(pid::CP_TIME, rational(o, n.max(1)))
.data_prop(pid::CP_VALUE, indirect(def::TYPE_RATIONAL, &gain_rational(*a)))
.data_prop(pid::CP_EDIT_HINT, vec![0])
})
.collect();
Obj::new(cls::VARYING_VALUE)
.data_prop(pid::PARAMETER_DEFINITION, def::PARAM_AMPLITUDE.to_vec())
.with(
pid::INTERPOLATION,
weak(path::INTERPOLATION_DEFS, if *linear { def::INTERP_LINEAR } else { def::INTERP_CONSTANT }),
)
.with(pid::POINT_LIST, Value::StrongVec(pts))
}
};
Obj::new(cls::OPERATION_GROUP)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, dd))
.data_prop(pid::LENGTH, n.to_le_bytes().to_vec())
.with(pid::OPERATION, weak(path::OPERATION_DEFS, def::MONO_AUDIO_GAIN))
.with(pid::INPUT_SEGMENTS, Value::StrongVec(vec![sc]))
.with(pid::PARAMETERS, Value::StrongVec(vec![param]))
}
_ => sc,
};
comps.push(seg);
cursor += c.len;
}
CItem::Transition(x) => {
let ts = cursor - x.len;
let n = w.u(cursor, rate) - w.u(ts, rate);
let cut = w.u(ts + x.cut, rate) - w.u(ts, rate);
cursor = ts;
let op = transition_op(t.kind, &x.effect);
if !used_ops.contains(&op) {
used_ops.push(op);
}
let mut og = Obj::new(cls::OPERATION_GROUP)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, dd))
.data_prop(pid::LENGTH, n.to_le_bytes().to_vec())
.with(pid::OPERATION, weak(path::OPERATION_DEFS, op))
.with(pid::COMPONENT_USER_COMMENTS, Value::StrongVec(vec![tagged("FilmCraft Effect", &x.effect)]));
if op == def::VIDEO_DISSOLVE {
*uses_varying = true;
let pts = [(0, 0), (1, 1)]
.iter()
.map(|&(t, v)| {
Obj::new(cls::CONTROL_POINT)
.data_prop(pid::CP_TIME, rational(t, 1))
.data_prop(pid::CP_VALUE, indirect(def::TYPE_RATIONAL, &rational(v, 1)))
.data_prop(pid::CP_EDIT_HINT, vec![0])
})
.collect();
og.set(
pid::PARAMETERS,
Value::StrongVec(vec![
Obj::new(cls::VARYING_VALUE)
.data_prop(pid::PARAMETER_DEFINITION, def::PARAM_LEVEL.to_vec())
.with(pid::INTERPOLATION, weak(path::INTERPOLATION_DEFS, def::INTERP_LINEAR))
.with(pid::POINT_LIST, Value::StrongVec(pts)),
]),
);
}
comps.push(
Obj::new(cls::TRANSITION)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, dd))
.data_prop(pid::LENGTH, n.to_le_bytes().to_vec())
.data_prop(pid::CUT_POINT, cut.to_le_bytes().to_vec())
.with(pid::OPERATION_GROUP, Value::Strong(Box::new(og))),
);
}
}
}
let len: i64 = comps
.iter()
.map(|c| {
let l = c.i64(pid::LENGTH).unwrap_or(0);
if c.class == cls::TRANSITION { -l } else { l }
})
.sum();
let seq = Obj::new(cls::SEQUENCE)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, dd))
.data_prop(pid::LENGTH, len.to_le_bytes().to_vec())
.with(pid::COMPONENTS, Value::StrongVec(comps));
slots.push(timeline_slot(slot_id, &t.name, t.number, rate, seq));
slot_id += 1;
}
if !comp.markers.is_empty() {
slots.push(event_slot(w, slot_id, crate_rate, &comp.markers));
}
let mut mob = Obj::new(cls::COMPOSITION_MOB)
.data_prop(pid::MOB_ID, id.to_vec())
.data_prop(pid::MOB_NAME, utf16z(&comp.name))
.data_prop(pid::MOB_LAST_MODIFIED, timestamp())
.data_prop(pid::MOB_CREATION_TIME, timestamp());
// only the exported sequence is a top-level composition; a nested sequence is found through
// the clips that use it
if top {
mob.set(pid::USAGE_CODE, Value::Data(def::USAGE_TOP_LEVEL.to_vec()));
}
mob.with(pid::SLOTS, Value::StrongVec(slots)).with(
pid::MOB_USER_COMMENTS,
Value::StrongVec(vec![
tagged("FilmCraft Frame Size", &format!("{}x{}", comp.width, comp.height)),
tagged("FilmCraft Audio Sample Rate", &comp.sample_rate.to_string()),
]),
)
}
}
fn slot_name(kind: CKind, n: u32) -> String {
match kind {
CKind::Picture => format!("V{n}"),
CKind::Sound => format!("A{n}"),
}
}
fn timeline_slot(id: u32, name: &str, number: u32, rate: (i64, i64), segment: Obj) -> Obj {
let mut o = Obj::new(cls::TIMELINE_MOB_SLOT)
.data_prop(pid::SLOT_ID, id.to_le_bytes().to_vec())
.data_prop(pid::SLOT_NAME, utf16z(name))
.data_prop(pid::EDIT_RATE, rational(rate.0, rate.1))
.data_prop(pid::ORIGIN, 0i64.to_le_bytes().to_vec())
.with(pid::SEGMENT, Value::Strong(Box::new(segment)));
if number > 0 {
o.set(pid::PHYSICAL_TRACK_NUMBER, Value::Data(number.to_le_bytes().to_vec()));
}
o
}
fn source_clip(kind: CKind, len: i64, source: [u8; 32], slot: u32, start: i64) -> Obj {
Obj::new(cls::SOURCE_CLIP)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, data_def(kind)))
.data_prop(pid::LENGTH, len.to_le_bytes().to_vec())
.data_prop(pid::SOURCE_ID, source.to_vec())
.data_prop(pid::SOURCE_MOB_SLOT_ID, slot.to_le_bytes().to_vec())
.data_prop(pid::START_TIME, start.to_le_bytes().to_vec())
}
fn event_slot(w: &mut W, id: u32, rate: (i64, i64), markers: &[CMarker]) -> Obj {
let comps = markers
.iter()
.map(|m| {
let pos = w.u(m.start, rate);
let len = w.u(m.start + m.duration, rate) - pos;
let mut tags = vec![tagged("Name", &m.name), tagged("Comment", &m.comment)];
if let Some(c) = &m.color {
tags.push(tagged("Color", c));
}
Obj::new(cls::COMMENT_MARKER)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, ddef::DESCRIPTIVE_METADATA))
.data_prop(pid::LENGTH, len.to_le_bytes().to_vec())
.data_prop(pid::POSITION, pos.to_le_bytes().to_vec())
.data_prop(pid::COMMENT, utf16z(if m.comment.is_empty() { &m.name } else { &m.comment }))
.with(pid::COMPONENT_USER_COMMENTS, Value::StrongVec(tags))
})
.collect();
Obj::new(cls::EVENT_MOB_SLOT)
.data_prop(pid::SLOT_ID, id.to_le_bytes().to_vec())
.data_prop(pid::SLOT_NAME, utf16z("Markers"))
.data_prop(pid::EVENT_EDIT_RATE, rational(rate.0, rate.1))
.with(
pid::SEGMENT,
Value::Strong(Box::new(
Obj::new(cls::SEQUENCE)
.with(pid::DATA_DEFINITION, weak(path::DATA_DEFS, ddef::DESCRIPTIVE_METADATA))
.with(pid::COMPONENTS, Value::StrongVec(comps)),
)),
)
}
fn transition_op(kind: CKind, effect: &str) -> Auid {
match kind {
CKind::Sound => def::MONO_AUDIO_DISSOLVE,
CKind::Picture => match effect {
"dip_to_black" => def::VIDEO_FADE_TO_BLACK,
e if e.contains("wipe") => def::SMPTE_VIDEO_WIPE,
_ => def::VIDEO_DISSOLVE,
},
}
}
fn descriptor(w: &mut W, s: &Source) -> Obj {
let rate = source_rate(s);
let len = w.u(s.length, rate);
let container = if s.embedded.is_some() { def::CONTAINER_AAF } else { def::CONTAINER_EXTERNAL };
let mut d = match s.kind {
CKind::Picture => Obj::new(cls::CDCI_DESCRIPTOR)
.data_prop(pid::STORED_WIDTH, s.width.to_le_bytes().to_vec())
.data_prop(pid::STORED_HEIGHT, s.height.to_le_bytes().to_vec())
.data_prop(pid::FRAME_LAYOUT, vec![0])
.data_prop(pid::IMAGE_ASPECT_RATIO, rational(s.width.max(1) as i64, s.height.max(1) as i64))
.data_prop(pid::VIDEO_LINE_MAP, {
let mut v = 2u32.to_le_bytes().to_vec();
v.extend_from_slice(&4u32.to_le_bytes());
v.extend_from_slice(&0i32.to_le_bytes());
v.extend_from_slice(&0i32.to_le_bytes());
v
})
.data_prop(pid::COMPONENT_WIDTH, 8u32.to_le_bytes().to_vec())
.data_prop(pid::HORIZONTAL_SUBSAMPLING, 2u32.to_le_bytes().to_vec()),
CKind::Sound => {
// Channel counts and rates come from the project: saturate, as these fields can't
// hold more anyway.
let block = s.file_channels.max(1).saturating_mul((s.bits as u32).div_ceil(8));
Obj::new(cls::PCM_DESCRIPTOR)
.data_prop(pid::AUDIO_SAMPLING_RATE, rational(s.sample_rate as i64, 1))
.data_prop(pid::LOCKED, vec![1])
.data_prop(pid::CHANNELS, s.file_channels.max(1).to_le_bytes().to_vec())
.data_prop(pid::QUANTIZATION_BITS, (s.bits as u32).to_le_bytes().to_vec())
.data_prop(pid::BLOCK_ALIGN, u16::try_from(block).unwrap_or(u16::MAX).to_le_bytes().to_vec())
.data_prop(pid::AVERAGE_BPS, block.saturating_mul(s.sample_rate).to_le_bytes().to_vec())
}
};
d.set(pid::SAMPLE_RATE, Value::Data(rational(rate.0, rate.1)));
d.set(pid::FILE_LENGTH, Value::Data(len.to_le_bytes().to_vec()));
d.set(pid::CONTAINER_FORMAT, weak(path::CONTAINER_DEFS, container));
if let Some(p) = &s.path {
let url = if craft_timeline::path::is_absolute(p) {
craft_timeline::path::path_to_file_url(p, false)
} else {
craft_timeline::path::encode_uri_path(p)
};
d.set(pid::LOCATOR, Value::StrongVec(vec![Obj::new(cls::NETWORK_LOCATOR).data_prop(pid::URL_STRING, utf16z(&url))]));
}
d
}
+60
View File
@@ -0,0 +1,60 @@
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable))]
//! AAF and OMF: the two mob-based editorial interchange formats, read and written through one
//! composition model.
//!
//! - [`model`]: a [`model::Document`] of compositions (tracks of fillers, source clips and
//! overlapping transitions, with clip gain and markers) and the media sources they reference,
//! with exact times ([`craft_timeline::time::Tick`]).
//! - [`aaf`]: Advanced Authoring Format, Edit Protocol, in structured storage (`craft-cfb`).
//! - [`omf`]: OMF Interchange 2.0 in a Bento container; sound only.
//!
//! Both read into and write from the same model, so an application maps its timeline onto the
//! model once. Audio essence can be embedded: the model carries it as PCM, and the WAVE / AIFF
//! wrappers the formats use are craft-audio's.
//!
//! Clean-room: written from the public specifications only (AMWA *AAF Object Specification* v1.1,
//! *AAF Low-Level Container Specification* v1.0.1, *AAF Edit Protocol* v1.0, SMPTE RP 224 / RP 210
//! labels; Avid *OMF Interchange Specification* 2.0, Apple *Bento Specification* 1.0d5). No file
//! I/O: documents are bytes and media references are strings.
//!
//! Input is untrusted: a damaged or crafted file gives an [`Error`] or a [`Report`] entry, never
//! a panic, a hang or an allocation sized by a count in the file.
pub mod aaf;
pub mod model;
pub mod omf;
mod pcm;
#[cfg(test)]
mod roundtrip_tests;
#[cfg(test)]
mod testdoc;
pub use craft_timeline::report::Report;
/// Error from a reader or writer. Unsupported *features* never error; they go in the [`Report`].
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum Error {
/// The bytes are not a readable document of the format.
#[error("{format} parse error: {message}")]
Parse { format: &'static str, message: String },
/// The document has no composition.
#[error("the document contains no timeline")]
Empty,
/// The document could not be written.
#[error("{0}")]
Other(String),
}
pub type Result<T> = std::result::Result<T, Error>;
/// Who a written file says made it (the AAF `Identification` object, the OMF `IDNT` object).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Identity<'a> {
pub company: &'a str,
pub product: &'a str,
/// The product's version, as text.
pub version: &'a str,
pub platform: &'a str,
/// AAF `ProductID`: an AUID naming the product.
pub product_id: [u8; 16],
}
+189
View File
@@ -0,0 +1,189 @@
//! A format-neutral mob-style composition model shared by AAF and OMF.
//!
//! Both formats describe a timeline as a composition of slots (tracks) whose segments are
//! sequences of fillers, source clips and transitions, where a transition *overlaps* the end of
//! the segment before it and the start of the segment after it (the sequence's length is the sum of
//! its segment lengths minus its transition lengths). Source clips reference media through master
//! mobs and file source mobs: here, a [`Source`] per essence, grouped into one media item by its
//! key. All times are ticks; the format serialisers convert to and from edit units.
use craft_timeline::time::{FrameRate, TICKS_PER_SECOND, Tick};
/// Picture or sound.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum CKind {
Picture,
Sound,
}
/// A whole document: compositions and the media they reference.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Document {
/// The top-level compositions.
pub compositions: Vec<Composition>,
pub sources: Vec<Source>,
/// Compositions that are only used inside others (nested sequences); a [`Source`] refers to
/// one by its index here. They may nest further.
pub nested: Vec<Composition>,
}
/// How a nested sequence is written. Premiere Pro writes one as a composition of its own in AAF
/// (clips refer to it the way they refer to media) and renders its sound in OMF, which has no
#[derive(Clone, Debug, PartialEq)]
pub struct Composition {
pub name: String,
/// AAF CompositionMob identifier as 64 lowercase hexadecimal digits. OMF has no equivalent.
/// It is a read identity for applications that let a user choose among compositions; writers
/// generate fresh format identifiers and do not preserve it.
pub aaf_mob_id: Option<String>,
pub rate: FrameRate,
pub sample_rate: u32,
pub width: u32,
pub height: u32,
pub start_tc: i64,
pub drop: bool,
pub tracks: Vec<CTrack>,
pub markers: Vec<CMarker>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct CTrack {
pub kind: CKind,
pub name: String,
/// Physical track number (1-based, per kind).
pub number: u32,
/// Sound: channels of the track (1 mono, 2 stereo, 6 5.1).
pub channels: u32,
pub items: Vec<CItem>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum CItem {
Filler(Tick),
Clip(CClip),
Transition(CTransition),
}
impl CItem {
/// The item's length on the track.
pub fn len(&self) -> Tick {
match self {
CItem::Filler(l) => *l,
CItem::Clip(c) => c.len,
CItem::Transition(t) => t.len,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct CClip {
pub len: Tick,
/// Index into [`Document::sources`].
pub source: usize,
/// Source (file) time of the segment's first frame.
pub start: Tick,
pub gain: Option<Gain>,
pub name: String,
}
/// Clip gain (linear amplitude).
#[derive(Clone, Debug, PartialEq)]
pub enum Gain {
Constant(f64),
/// Points at offsets from the segment start; `linear` false = hold (step) interpolation.
Varying {
linear: bool,
points: Vec<(Tick, f64)>,
},
}
#[derive(Clone, Debug, PartialEq)]
pub struct CTransition {
pub len: Tick,
/// Where the cut lies, from the transition start.
pub cut: Tick,
/// The transition, by a name of the writing application's choosing; it is kept in a private tag
/// and comes back unchanged. Names the formats themselves can say: `cross_dissolve` and
/// `dip_to_black` (picture), any name containing `wipe` (a SMPTE wipe), `constant_power` (sound).
/// A file without the tag reads as one of these.
pub effect: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct CMarker {
pub start: Tick,
pub duration: Tick,
pub name: String,
pub comment: String,
pub color: Option<String>,
}
/// One essence: a file (or embedded data) carrying the picture, or some channels of sound, of a
/// media item.
#[derive(Clone, Debug, PartialEq)]
pub struct Source {
/// Groups the sources of one media item (one master mob).
pub key: String,
pub name: String,
pub kind: CKind,
pub path: Option<String>,
/// Sound: the (0-based) channel of the file this source exposes (broken out to mono), or
/// `None` for all of them.
pub channel: Option<u32>,
/// Sound: channels this source exposes (1 when `channel` is set, else `file_channels`).
pub channels: u32,
/// Sound: channels of the file / embedded data.
pub file_channels: u32,
pub width: u32,
pub height: u32,
/// Picture: the frame rate of the media.
pub frame_rate: FrameRate,
pub sample_rate: u32,
pub bits: u16,
pub length: Tick,
/// Media time of the essence's time 0 (trimmed / consolidated essence).
pub offset: Tick,
/// Start timecode in frames at `tc_rate`.
pub start_tc: Option<i64>,
pub tc_rate: FrameRate,
pub embedded: Option<Vec<u8>>,
pub markers: Vec<CMarker>,
/// Not media but a nested composition: its index in [`Document::nested`]. `start` of a clip
/// that uses it is a time in that composition.
pub nested: Option<usize>,
}
impl Source {
/// A picture source with no length: a still image.
pub fn is_still(&self) -> bool {
self.kind == CKind::Picture && self.length == Tick::ZERO
}
}
/// The largest time read from a document (about 3.3 days).
pub const MAX_TIME: Tick = Tick(1 << 56);
/// Ticks of `n` edit units at rate `num/den` (rounded to the nearest tick).
pub fn units_to_ticks(n: i64, num: i64, den: i64) -> Tick {
if num <= 0 || den <= 0 {
return Tick::ZERO;
}
let t = n as i128 * den as i128 * TICKS_PER_SECOND as i128;
let q = t.div_euclid(num as i128);
let r = t.rem_euclid(num as i128);
// documents are untrusted: keep every time far from overflow (±3 days)
Tick((q + if r * 2 >= num as i128 { 1 } else { 0 }).clamp(-MAX_TIME.0 as i128, MAX_TIME.0 as i128) as i64)
}
/// Edit units at rate `num/den` nearest to `t`; the flag is false when `t` is not on a unit.
pub fn ticks_to_units(t: Tick, num: i64, den: i64) -> (i64, bool) {
if num <= 0 || den <= 0 {
return (0, false);
}
let x = t.0 as i128 * num as i128;
let d = den as i128 * TICKS_PER_SECOND as i128;
let q = x.div_euclid(d);
let r = x.rem_euclid(d);
let n = q + if r * 2 >= d { 1 } else { 0 };
(n.clamp(i64::MIN as i128, i64::MAX as i128) as i64, r == 0)
}
+47
View File
@@ -0,0 +1,47 @@
//! OMF Interchange 2.0 for audio post: written, and the same structures read.
//!
//! Written from the public *OMF Interchange Specification Version 2.0* (Avid Technology, 1995/97)
//! and Apple's *Bento Specification* revision 1.0d5 for the container ([`bento`]).
//!
//! The file holds a composition mob (`CMOB`) with a timecode slot and one sound slot per audio
//! track (one per channel when broken out to mono): sequences (`SEQU`) of fillers (`FILL`), source
//! clips (`SCLP`) and transitions (`TRAN` with a `SimpleMonoAudioDissolve` effect); clip volume is a
//! `MonoAudioGain` effect (`EFFE`) whose slot −1 is the clip and slot 1 the amplitude
//! (`CVAL` constant or `VVAL` keyframes). Every media item has a master mob (`MMOB`), a file source
//! mob (`SMOB` with a `WAVD` / `AIFD` descriptor: embedded essence in a `WAVE` media data object,
//! or a locator to a separate file) and a tape source mob carrying its timecode. Times are in
//! samples (sound slots use the sample rate as edit rate) so edits are sample-exact.
//!
//! Only sound is written: picture tracks and markers of the model are left out, and a nested
//! composition is not written as one (readers of OMF do not follow compositions). A caller with
//! nested sequences mixes their sound and passes it as media like any other; Premiere Pro's OMF
//! export does the same.
//!
//! Private properties. `FilmCraft:SCLP:ClipName` (a clip's name) and `FilmCraft:EFFE:EffectID` (a
//! transition's name) are not in the specification; they were first written by FilmCraft and keep
//! their names so that existing files read back.
pub(crate) mod bento;
mod read;
mod write;
use crate::model::Document;
use crate::{Identity, Report, Result};
/// Write the sound of `doc`'s first composition as an OMF 2.0 file.
pub fn write(doc: &Document, identity: &Identity<'_>, report: &mut Report) -> Result<Vec<u8>> {
write::write(doc, identity, report)
}
/// Read an OMF 2.0 file (as written by [`write`] and by applications using the same structures).
pub fn read(bytes: &[u8], report: &mut Report) -> Result<Document> {
read::read(bytes, report)
}
/// Whether `bytes` end with a Bento container label (OMF files do).
pub fn sniff(bytes: &[u8]) -> bool {
bento::sniff(bytes)
}
#[cfg(test)]
mod tests;
+407
View File
@@ -0,0 +1,407 @@
//! The Bento container (Apple, *Bento Specification* revision 1.0d5), the storage layer of OMF
//! Interchange 2.0 files.
//!
//! A Bento container is a heap of value bytes, a table of contents (TOC) describing every value of
//! every object, and a fixed-size label at the very end of the file that locates the TOC:
//!
//! ```text
//! label (24 bytes, big-endian): magic A4 'C' 'M' A5 'H' 'd' 'r' D7, u16 flags, u16 buffer size
//! (KiB), u16 major version (1), u16 minor version (0),
//! u32 TOC offset, u32 TOC size
//! ```
//!
//! Every value belongs to an (object id, property id, type id) triple. Properties and types are
//! themselves objects carrying a global name (`"OMFI:CPNT:Length"`, `"omfi:Length32"`). The TOC
//! is a stream of one-byte operations, each followed by its operands (big-endian):
//!
//! | op | operands | meaning |
//! |---|---|---|
//! | 1 NewObject | u32 id | following entries belong to this object |
//! | 2 NewProperty | u32 id | … to this property |
//! | 3 NewType | u32 id | starts a new value of this type |
//! | 4 ExplicitGen | u32 | generation of the value |
//! | 5 Offset4Len4 | u32 offset, u32 length | a value segment in the file |
//! | 6 ContdOffset4Len4 | u32 offset, u32 length | a continuation segment |
//! | 7 Offset8Len4 / 8 Contd… | u64 offset, u32 length | segments beyond 4 GiB |
//! | 9–13 Immediate0–4 | 4 bytes | a value of 0–4 bytes stored in the TOC |
//! | 14 ContdImmediate4 | 4 bytes | continuation |
//! | 15 ReferenceListID | u32 id | the object holding this value's reference list |
//! | 24 EndOfBufr | — | skip to the end of the current TOC buffer |
//! | 0xFF Padding | — | ignored |
//!
//! Object references (OMF's `omfi:ObjRef`) are 4-byte keys resolved through the referencing
//! object's reference list (standard property 22: pairs of u32 key, u32 object id). FilmCraft
//! uses the referenced object's id as the key.
use std::collections::{BTreeMap, HashMap};
pub(crate) const MAGIC: [u8; 8] = [0xA4, b'C', b'M', 0xA5, b'H', b'd', b'r', 0xD7];
pub(crate) const LABEL_SIZE: usize = 24;
// standard object ids
const TOC_OBJECT: u32 = 1;
const TOC_SEED: u32 = 2;
const TOC_MIN_SEED: u32 = 3;
const TOC_TYPE: u32 = 19;
const TYPE_7BIT_ASCII: u32 = 21;
pub(crate) const OBJ_REFERENCES: u32 = 22;
const GLOBAL_TYPE_NAME: u32 = 23;
const GLOBAL_PROP_NAME: u32 = 24;
const MIN_USER_ID: u32 = 100;
const OP_NEW_OBJECT: u8 = 1;
const OP_NEW_PROPERTY: u8 = 2;
const OP_NEW_TYPE: u8 = 3;
const OP_EXPLICIT_GEN: u8 = 4;
const OP_OFFSET4_LEN4: u8 = 5;
const OP_CONTD_OFFSET4_LEN4: u8 = 6;
const OP_OFFSET8_LEN4: u8 = 7;
const OP_CONTD_OFFSET8_LEN4: u8 = 8;
const OP_IMMEDIATE0: u8 = 9;
const OP_IMMEDIATE4: u8 = 13;
const OP_CONTD_IMMEDIATE4: u8 = 14;
const OP_REFERENCE_LIST_ID: u8 = 15;
const OP_END_OF_BUFFER: u8 = 24;
const OP_PADDING: u8 = 0xFF;
const TOC_BUFFER_KIB: u16 = 8;
#[derive(Clone, Debug, PartialEq, Eq)]
enum Seg {
Imm(Vec<u8>),
At(u64, u32),
}
/// Bento values are metadata, not essence payloads. Limit reassembled segments so repeated
/// references cannot amplify a small OMF into an enormous allocation.
const MAX_VALUE_BYTES: usize = 16 << 20;
/// Most bytes of global names (property and type names) kept for one container. Real files name a
/// few hundred short strings; without a cap, many objects naming one large shared range would each
/// retain their own copy.
const MAX_NAME_BYTES: usize = 4 << 20;
/// Builds a Bento container.
pub(crate) struct Writer {
data: Vec<u8>,
names: HashMap<(u32, String), u32>,
next: u32,
/// (object, property, type, segments)
entries: Vec<(u32, u32, u32, Vec<Seg>)>,
}
impl Writer {
pub fn new() -> Writer {
Writer { data: Vec::new(), names: HashMap::new(), next: MIN_USER_ID, entries: Vec::new() }
}
fn named(&mut self, kind: u32, name: &str) -> u32 {
if let Some(&id) = self.names.get(&(kind, name.to_string())) {
return id;
}
let id = self.new_object();
let mut v = name.as_bytes().to_vec();
v.push(0);
let seg = self.store(&v);
self.entries.push((id, kind, TYPE_7BIT_ASCII, vec![seg]));
self.names.insert((kind, name.to_string()), id);
id
}
pub fn property(&mut self, name: &str) -> u32 {
self.named(GLOBAL_PROP_NAME, name)
}
pub fn type_id(&mut self, name: &str) -> u32 {
self.named(GLOBAL_TYPE_NAME, name)
}
pub fn new_object(&mut self) -> u32 {
let id = self.next;
self.next += 1;
id
}
fn store(&mut self, v: &[u8]) -> Seg {
if v.len() <= 4 {
return Seg::Imm(v.to_vec());
}
let at = self.data.len() as u64;
self.data.extend_from_slice(v);
Seg::At(at, v.len() as u32)
}
/// Set a value of `obj` (values of more than 4 GiB are not supported by OMF).
pub fn set(&mut self, obj: u32, property: &str, ty: &str, value: &[u8]) {
let p = self.property(property);
let t = self.type_id(ty);
let seg = self.store(value);
self.entries.push((obj, p, t, vec![seg]));
}
/// The reference list of `obj` (keys are object ids).
pub fn set_references(&mut self, obj: u32, targets: &[u32]) {
let mut v = Vec::with_capacity(targets.len() * 8);
for t in targets {
v.extend_from_slice(&t.to_be_bytes());
v.extend_from_slice(&t.to_be_bytes());
}
let seg = self.store(&v);
self.entries.push((obj, OBJ_REFERENCES, TYPE_7BIT_ASCII, vec![seg]));
}
pub fn finish(mut self) -> Vec<u8> {
let seed = self.next;
self.entries.push((TOC_OBJECT, TOC_SEED, TOC_TYPE, vec![Seg::Imm(seed.to_be_bytes().to_vec())]));
self.entries.push((TOC_OBJECT, TOC_MIN_SEED, TOC_TYPE, vec![Seg::Imm(MIN_USER_ID.to_be_bytes().to_vec())]));
self.entries.sort_by_key(|e| (e.0, e.1, e.2));
let mut toc = Vec::new();
let (mut cur_obj, mut cur_prop) = (u32::MAX, u32::MAX);
for (obj, prop, ty, segs) in &self.entries {
if *obj != cur_obj {
toc.push(OP_NEW_OBJECT);
toc.extend_from_slice(&obj.to_be_bytes());
cur_obj = *obj;
cur_prop = u32::MAX;
}
if *prop != cur_prop {
toc.push(OP_NEW_PROPERTY);
toc.extend_from_slice(&prop.to_be_bytes());
cur_prop = *prop;
}
toc.push(OP_NEW_TYPE);
toc.extend_from_slice(&ty.to_be_bytes());
for (i, s) in segs.iter().enumerate() {
match s {
Seg::Imm(b) => {
toc.push(if i > 0 { OP_CONTD_IMMEDIATE4 } else { OP_IMMEDIATE0 + b.len() as u8 });
let mut w = [0u8; 4];
w[..b.len()].copy_from_slice(b);
toc.extend_from_slice(&w);
}
Seg::At(off, len) if *off <= u32::MAX as u64 => {
toc.push(if i > 0 { OP_CONTD_OFFSET4_LEN4 } else { OP_OFFSET4_LEN4 });
toc.extend_from_slice(&(*off as u32).to_be_bytes());
toc.extend_from_slice(&len.to_be_bytes());
}
Seg::At(off, len) => {
toc.push(if i > 0 { OP_CONTD_OFFSET8_LEN4 } else { OP_OFFSET8_LEN4 });
toc.extend_from_slice(&off.to_be_bytes());
toc.extend_from_slice(&len.to_be_bytes());
}
}
}
}
let mut out = self.data;
let toc_at = out.len() as u64;
out.extend_from_slice(&toc);
let mut label = MAGIC.to_vec();
label.extend_from_slice(&0u16.to_be_bytes()); // flags
label.extend_from_slice(&TOC_BUFFER_KIB.to_be_bytes());
label.extend_from_slice(&1u16.to_be_bytes());
label.extend_from_slice(&0u16.to_be_bytes());
label.extend_from_slice(&(toc_at.min(u32::MAX as u64) as u32).to_be_bytes());
label.extend_from_slice(&(toc.len() as u32).to_be_bytes());
out.extend_from_slice(&label);
out
}
}
/// One value of a parsed object.
#[derive(Clone, Debug)]
pub(crate) struct Prop {
pub prop: u32,
#[allow(dead_code)]
pub ty: u32,
segs: Vec<Seg>,
}
/// A parsed Bento container.
pub(crate) struct Container<'a> {
data: &'a [u8],
pub objects: BTreeMap<u32, Vec<Prop>>,
names: HashMap<u32, String>,
by_name: HashMap<String, u32>,
}
fn be32(b: &[u8], at: usize) -> Option<u32> {
b.get(at..at + 4).map(|s| u32::from_be_bytes([s[0], s[1], s[2], s[3]]))
}
/// Whether `b` ends with a Bento label.
pub(crate) fn sniff(b: &[u8]) -> bool {
b.len() >= LABEL_SIZE && b[b.len() - LABEL_SIZE..b.len() - LABEL_SIZE + 8] == MAGIC
}
impl<'a> Container<'a> {
pub fn open(data: &'a [u8]) -> Result<Container<'a>, String> {
if !sniff(data) {
return Err("no Bento label at the end of the file".into());
}
let l = &data[data.len() - LABEL_SIZE..];
let buf = (u16::from_be_bytes([l[10], l[11]]) as usize).max(1) * 1024;
let toc_at = be32(l, 16).unwrap_or(0) as usize;
let toc_len = be32(l, 20).unwrap_or(0) as usize;
let toc = data.get(toc_at..toc_at.checked_add(toc_len).ok_or("bad TOC size")?).ok_or("the TOC lies outside the file")?;
let mut c = Container { data, objects: BTreeMap::new(), names: HashMap::new(), by_name: HashMap::new() };
let (mut obj, mut prop) = (0u32, 0u32);
let mut i = 0;
while i < toc.len() {
let op = toc[i];
i += 1;
let need = |n: usize| -> Result<&[u8], String> { toc.get(i..i + n).ok_or_else(|| "truncated TOC".to_string()) };
match op {
OP_NEW_OBJECT => {
obj = be32(need(4)?, 0).unwrap_or(0);
i += 4;
}
OP_NEW_PROPERTY => {
prop = be32(need(4)?, 0).unwrap_or(0);
i += 4;
}
OP_NEW_TYPE => {
let ty = be32(need(4)?, 0).unwrap_or(0);
i += 4;
c.objects.entry(obj).or_default().push(Prop { prop, ty, segs: Vec::new() });
}
OP_EXPLICIT_GEN | OP_REFERENCE_LIST_ID => {
need(4)?;
i += 4;
}
OP_OFFSET4_LEN4 | OP_CONTD_OFFSET4_LEN4 => {
let b = need(8)?;
let seg = Seg::At(be32(b, 0).unwrap_or(0) as u64, be32(b, 4).unwrap_or(0));
i += 8;
c.push_seg(obj, seg)?;
}
OP_OFFSET8_LEN4 | OP_CONTD_OFFSET8_LEN4 => {
let b = need(12)?;
let off = u64::from_be_bytes(b[..8].try_into().map_err(|_| "truncated TOC")?);
let seg = Seg::At(off, be32(b, 8).unwrap_or(0));
i += 12;
c.push_seg(obj, seg)?;
}
x @ (OP_IMMEDIATE0..=OP_IMMEDIATE4 | OP_CONTD_IMMEDIATE4) => {
let b = need(4)?;
let n = if x == OP_CONTD_IMMEDIATE4 { 4 } else { (x - OP_IMMEDIATE0) as usize };
let seg = Seg::Imm(b[..n].to_vec());
i += 4;
c.push_seg(obj, seg)?;
}
OP_END_OF_BUFFER => {
// the rest of this TOC buffer is unused
i = (i - 1) / buf * buf + buf;
}
OP_PADDING | 0 => {}
other => return Err(format!("unknown TOC operation {other}")),
}
}
// global names
let ids: Vec<u32> = c.objects.keys().copied().collect();
let mut name_bytes = 0usize;
for id in ids {
let name = c.objects[&id].iter().find(|p| p.prop == GLOBAL_PROP_NAME || p.prop == GLOBAL_TYPE_NAME).and_then(|p| c.value(p).ok());
if let Some(n) = name {
name_bytes = name_bytes.saturating_add(n.len());
if name_bytes > MAX_NAME_BYTES {
return Err("Bento global names exceed the name budget".into());
}
let s = String::from_utf8_lossy(&n).trim_end_matches('\0').to_string();
c.by_name.insert(s.clone(), id);
c.names.insert(id, s);
}
}
Ok(c)
}
fn push_seg(&mut self, obj: u32, seg: Seg) -> Result<(), String> {
let p = self.objects.get_mut(&obj).and_then(|v| v.last_mut()).ok_or("a value without a type in the TOC")?;
if p.segs.len() > 1 << 20 {
return Err("too many value segments".into());
}
p.segs.push(seg);
Ok(())
}
/// The bytes of a value.
pub fn value(&self, p: &Prop) -> Result<Vec<u8>, String> {
let total = p.segs.iter().try_fold(0usize, |total, s| {
let len = match s {
Seg::Imm(b) => b.len(),
Seg::At(_, len) => *len as usize,
};
total.checked_add(len).ok_or_else(|| "Bento value length overflows".to_string())
})?;
if total > MAX_VALUE_BYTES {
return Err("Bento value exceeds the decoded-value budget".into());
}
let mut out = Vec::new();
out.try_reserve_exact(total).map_err(|_| "cannot allocate Bento value")?;
for s in &p.segs {
match s {
Seg::Imm(b) => out.extend_from_slice(b),
Seg::At(off, len) => {
let start = usize::try_from(*off).map_err(|_| "value offset too large")?;
let b =
self.data.get(start..start.checked_add(*len as usize).ok_or("bad value length")?).ok_or("a value lies outside the file")?;
out.extend_from_slice(b);
}
}
}
Ok(out)
}
pub fn id_of(&self, name: &str) -> Option<u32> {
self.by_name.get(name).copied()
}
#[allow(dead_code)]
pub fn name_of(&self, id: u32) -> Option<&str> {
self.names.get(&id).map(String::as_str)
}
/// The first value of property `name` of `obj`.
pub fn get(&self, obj: u32, name: &str) -> Option<Vec<u8>> {
let pid = self.id_of(name)?;
let p = self.objects.get(&obj)?.iter().find(|p| p.prop == pid)?;
self.value(p).ok()
}
/// Resolve an object reference key of `obj` through its reference list.
pub fn resolve(&self, obj: u32, key: u32) -> u32 {
if let Some(p) = self.objects.get(&obj).and_then(|v| v.iter().find(|p| p.prop == OBJ_REFERENCES))
&& let Ok(v) = self.value(p)
{
for pair in v.as_chunks::<8>().0 {
if be32(pair, 0) == Some(key) {
return be32(pair, 4).unwrap_or(key);
}
}
}
key
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn many_objects_cannot_name_themselves_with_one_shared_range() {
let mut w = Writer::new();
w.data = vec![b'a'; 1 << 20];
let ids: Vec<u32> = (0..8).map(|_| w.new_object()).collect();
for id in ids {
w.entries.push((id, GLOBAL_PROP_NAME, TYPE_7BIT_ASCII, vec![Seg::At(0, 1 << 20)]));
}
let file = w.finish();
assert!(Container::open(&file).err().is_some_and(|e| e.contains("name budget")));
}
#[test]
fn repeated_segments_cannot_expand_a_value_past_its_budget() {
let p = Prop { prop: 1, ty: 1, segs: vec![Seg::At(0, MAX_VALUE_BYTES as u32), Seg::Imm(vec![0])] };
let c = Container { data: &[], objects: BTreeMap::new(), names: HashMap::new(), by_name: HashMap::new() };
assert!(c.value(&p).unwrap_err().contains("budget"));
}
}
+439
View File
@@ -0,0 +1,439 @@
//! OMF 2.0 objects (Bento) → composition model.
use std::collections::{HashMap, HashSet};
use craft_timeline::time::{FrameRate, Tick};
use super::bento::Container;
use crate::model::{CClip, CItem, CKind, CTrack, CTransition, Composition, Document, Gain, Source, units_to_ticks};
use crate::{Error, Report, Result};
type Uid = [u8; 12];
const MAX_REFERENCE_VISITS: usize = 65_536;
struct R<'a, 'b> {
c: &'b Container<'a>,
report: &'b mut Report,
/// big-endian values ("MM"); "II" files are little-endian
be: bool,
mobs: HashMap<Uid, u32>,
media: HashMap<Uid, Vec<u8>>,
doc: Document,
sources: HashMap<(Uid, u32, String), usize>,
}
pub(crate) fn read(bytes: &[u8], report: &mut Report) -> Result<Document> {
let perr = |m: String| Error::Parse { format: "OMF", message: m };
let c = Container::open(bytes).map_err(perr)?;
let class_of = |o: u32| c.get(o, "OMFI:OOBJ:ObjClass").and_then(|v| v.get(..4).map(|b| [b[0], b[1], b[2], b[3]]));
let head = c.objects.keys().copied().find(|&o| class_of(o) == Some(*b"HEAD")).ok_or_else(|| perr("no OMF header object".into()))?;
let be = c.get(head, "OMFI:HEAD:ByteOrder").is_none_or(|v| v.first() != Some(&0x49));
let mut r = R { c: &c, report, be, mobs: HashMap::new(), media: HashMap::new(), doc: Document::default(), sources: HashMap::new() };
let mob_list = r.refs(head, "OMFI:HEAD:Mobs");
let mob_list = if mob_list.is_empty() {
c.objects.keys().copied().filter(|&o| matches!(class_of(o).as_ref(), Some(b"CMOB" | b"MMOB" | b"SMOB"))).collect()
} else {
mob_list
};
for &m in &mob_list {
if let Some(id) = r.uid(m, "OMFI:MOBJ:MobID") {
r.mobs.insert(id, m);
}
}
let md = r.refs(head, "OMFI:HEAD:MediaData");
let md =
if md.is_empty() { c.objects.keys().copied().filter(|&o| matches!(class_of(o).as_ref(), Some(b"WAVE" | b"AIFC"))).collect() } else { md };
for m in md {
let Some(id) = r.uid(m, "OMFI:MDAT:MobID") else { continue };
if let Some(d) = c.get(m, "OMFI:WAVE:Data") {
r.media.insert(id, d);
} else if let Some(d) = c.get(m, "OMFI:AIFC:Data") {
r.media.insert(id, d);
}
}
let cmobs: Vec<u32> = mob_list.iter().copied().filter(|&m| class_of(m) == Some(*b"CMOB")).collect();
let mut referenced = HashSet::new();
let mut visited = HashSet::new();
let mut visits = 0;
for &m in &cmobs {
r.collect_refs(m, &mut referenced, &mut visited, &mut visits, 0);
}
let primary: Vec<u32> = r.refs(head, "OMFI:HEAD:PrimaryMobs").into_iter().filter(|m| cmobs.contains(m)).collect();
let top: Vec<u32> = if !primary.is_empty() {
primary
} else {
cmobs.iter().copied().filter(|m| r.uid(*m, "OMFI:MOBJ:MobID").is_none_or(|id| !referenced.contains(&id))).collect()
};
for m in top {
let comp = r.composition(m);
r.doc.compositions.push(comp);
}
if r.doc.compositions.is_empty() {
return Err(Error::Empty);
}
Ok(r.doc)
}
impl R<'_, '_> {
fn class(&self, o: u32) -> [u8; 4] {
self.c.get(o, "OMFI:OOBJ:ObjClass").and_then(|v| v.get(..4).map(|b| [b[0], b[1], b[2], b[3]])).unwrap_or(*b"????")
}
fn u32_of(&self, b: &[u8]) -> Option<u32> {
let a: [u8; 4] = b.get(..4)?.try_into().ok()?;
Some(if self.be { u32::from_be_bytes(a) } else { u32::from_le_bytes(a) })
}
fn i32(&self, o: u32, p: &str) -> Option<i64> {
self.c.get(o, p).and_then(|v| self.u32_of(&v)).map(|x| x as i32 as i64)
}
fn u32(&self, o: u32, p: &str) -> Option<u32> {
self.c.get(o, p).and_then(|v| self.u32_of(&v))
}
fn u16(&self, o: u32, p: &str) -> Option<u16> {
let v = self.c.get(o, p)?;
let a: [u8; 2] = v.get(..2)?.try_into().ok()?;
Some(if self.be { u16::from_be_bytes(a) } else { u16::from_le_bytes(a) })
}
fn rational(&self, o: u32, p: &str) -> Option<(i64, i64)> {
let v = self.c.get(o, p)?;
self.rational_of(&v)
}
fn rational_of(&self, v: &[u8]) -> Option<(i64, i64)> {
Some((self.u32_of(v)? as i32 as i64, self.u32_of(v.get(4..)?)? as i32 as i64))
}
fn string(&self, o: u32, p: &str) -> Option<String> {
self.c.get(o, p).map(|v| String::from_utf8_lossy(&v).trim_end_matches('\0').to_string())
}
fn uid(&self, o: u32, p: &str) -> Option<Uid> {
self.c.get(o, p).and_then(|v| v.get(..12).and_then(|b| b.try_into().ok()))
}
fn r#ref(&self, o: u32, p: &str) -> Option<u32> {
let v = self.c.get(o, p)?;
let key = u32::from_be_bytes(v.get(..4)?.try_into().ok()?);
Some(self.c.resolve(o, key))
}
fn refs(&self, o: u32, p: &str) -> Vec<u32> {
let Some(v) = self.c.get(o, p) else { return Vec::new() };
if v.len() < 2 {
return Vec::new();
}
let n = u16::from_be_bytes([v[0], v[1]]) as usize;
v[2..].as_chunks::<4>().0.iter().take(n).map(|k| self.c.resolve(o, u32::from_be_bytes([k[0], k[1], k[2], k[3]]))).collect()
}
fn data_kind(&self, o: u32) -> String {
self.r#ref(o, "OMFI:CPNT:DataKind").and_then(|d| self.string(d, "OMFI:DDEF:DataKindID")).unwrap_or_default()
}
fn len(&self, o: u32) -> i64 {
self.i32(o, "OMFI:CPNT:Length").unwrap_or(0).max(0)
}
fn collect_refs(&self, o: u32, out: &mut HashSet<Uid>, visited: &mut HashSet<u32>, visits: &mut usize, depth: usize) {
if depth > 64 || !visited.insert(o) || *visits >= MAX_REFERENCE_VISITS {
return;
}
*visits += 1;
if self.class(o) == *b"SCLP"
&& let Some(id) = self.uid(o, "OMFI:SCLP:SourceID")
{
out.insert(id);
}
for p in ["OMFI:MOBJ:Slots", "OMFI:SEQU:Components", "OMFI:EFFE:EffectSlots"] {
for c in self.refs(o, p) {
self.collect_refs(c, out, visited, visits, depth + 1);
}
}
for p in ["OMFI:MSLT:Segment", "OMFI:ESLT:ArgValue"] {
if let Some(c) = self.r#ref(o, p) {
self.collect_refs(c, out, visited, visits, depth + 1);
}
}
}
fn composition(&mut self, m: u32) -> Composition {
let name = self.string(m, "OMFI:MOBJ:Name").unwrap_or_else(|| "Sequence".into());
let mut comp = Composition {
name,
aaf_mob_id: None,
rate: FrameRate::FPS_25,
sample_rate: 48_000,
width: 1920,
height: 1080,
start_tc: 0,
drop: false,
tracks: Vec::new(),
markers: Vec::new(),
};
let slots = self.refs(m, "OMFI:MOBJ:Slots");
let mut na = 0;
for s in slots {
let Some(seg) = self.r#ref(s, "OMFI:MSLT:Segment") else { continue };
let rate = self.rational(s, "OMFI:MSLT:EditRate").filter(|r| r.0 > 0 && r.1 > 0).unwrap_or((25, 1));
let kind = self.data_kind(seg);
if self.class(seg) == *b"TCCP" || kind == "omfi:data:Timecode" {
comp.rate = FrameRate::new(rate.0, rate.1);
if self.class(seg) == *b"TCCP" {
comp.start_tc = self.i32(seg, "OMFI:TCCP:Start").unwrap_or(0);
comp.drop = self.c.get(seg, "OMFI:TCCP:Drop").and_then(|v| v.first().copied()).unwrap_or(0) != 0;
}
continue;
}
let ckind = match kind.as_str() {
"omfi:data:Sound" => CKind::Sound,
"omfi:data:Picture" | "omfi:data:PictureWithMatte" => CKind::Picture,
_ => {
self.report.info("an OMF slot of an unsupported data kind was skipped");
continue;
}
};
if ckind == CKind::Picture {
self.report.info("OMF picture slots are not imported (audio only)");
continue;
}
if rate.1 == 1 && rate.0 >= 8000 {
comp.sample_rate = rate.0 as u32;
}
let items = self.segment(seg, rate, 0);
na += 1;
let td = self.r#ref(s, "OMFI:MSLT:TrackDesc");
let tname = td.and_then(|t| self.string(t, "OMFI:TRKD:TrackName")).unwrap_or_else(|| format!("A{na}"));
let number = td.and_then(|t| self.u32(t, "OMFI:TRKD:PhysicalTrack")).unwrap_or(na);
let channels = items
.iter()
.filter_map(|i| match i {
CItem::Clip(c) => Some(self.doc.sources[c.source].channels),
_ => None,
})
.max()
.unwrap_or(1)
.min(6);
comp.tracks.push(CTrack { kind: CKind::Sound, name: tname, number, channels, items });
}
comp
}
fn segment(&mut self, seg: u32, rate: (i64, i64), depth: usize) -> Vec<CItem> {
let len = units_to_ticks(self.len(seg), rate.0, rate.1);
if depth > 32 {
return vec![CItem::Filler(len)];
}
match &self.class(seg) {
b"SEQU" => {
let mut out = Vec::new();
for c in self.refs(seg, "OMFI:SEQU:Components") {
out.extend(self.segment(c, rate, depth + 1));
}
out
}
b"FILL" => vec![CItem::Filler(len)],
b"SCLP" => vec![self.clip(seg, rate)],
b"TRAN" => {
let cut = units_to_ticks(self.i32(seg, "OMFI:TRAN:CutPoint").unwrap_or(0), rate.0, rate.1);
let effect = self
.r#ref(seg, "OMFI:TRAN:Effect")
.and_then(|e| self.string(e, "FilmCraft:EFFE:EffectID"))
.unwrap_or_else(|| "constant_power".into());
vec![CItem::Transition(CTransition { len, cut: cut.clamp(Tick::ZERO, len), effect })]
}
b"EFFE" => {
let kind = self.r#ref(seg, "OMFI:EFFE:EffectKind").and_then(|k| self.string(k, "OMFI:EDEF:EffectID")).unwrap_or_default();
let slots = self.refs(seg, "OMFI:EFFE:EffectSlots");
let arg = |r: &Self, id: i64| {
slots.iter().copied().find(|&s| r.i32(s, "OMFI:ESLT:ArgID") == Some(id)).and_then(|s| r.r#ref(s, "OMFI:ESLT:ArgValue"))
};
let Some(input) = arg(self, -1).or_else(|| arg(self, 1).filter(|_| kind != "omfi:effect:MonoAudioGain")) else {
return vec![CItem::Filler(len)];
};
let gain = if kind == "omfi:effect:MonoAudioGain" {
arg(self, 1).and_then(|v| self.gain(v, len))
} else {
self.report.warn("OMF effects other than audio gain are not imported (their input is used)");
None
};
let mut items = self.segment(input, rate, depth + 1);
if let (Some(g), [CItem::Clip(c)]) = (gain, items.as_mut_slice()) {
c.gain = Some(g);
}
items
}
_ => {
self.report.info("an unsupported OMF component was imported as a gap");
vec![CItem::Filler(len)]
}
}
}
fn amp(&self, v: &[u8]) -> Option<f64> {
self.rational_of(v).filter(|r| r.1 != 0).map(|(n, d)| n as f64 / d as f64)
}
fn gain(&mut self, v: u32, len: Tick) -> Option<Gain> {
match &self.class(v) {
b"CVAL" => self.c.get(v, "OMFI:CVAL:Value").and_then(|d| self.amp(&d)).map(Gain::Constant),
b"VVAL" => {
let linear = self.u16(v, "OMFI:VVAL:Interpolation") != Some(1);
let points: Vec<(Tick, f64)> = self
.refs(v, "OMFI:VVAL:PointList")
.into_iter()
.filter_map(|p| {
let (n, d) = self.rational(p, "OMFI:CTLP:Time").filter(|r| r.1 != 0)?;
let a = self.c.get(p, "OMFI:CTLP:Value").and_then(|d| self.amp(&d))?;
Some((Tick((len.0 as i128 * n as i128 / d as i128).clamp(-(1i128 << 56), 1i128 << 56) as i64), a))
})
.collect();
(!points.is_empty()).then_some(Gain::Varying { linear, points })
}
_ => None,
}
}
fn clip(&mut self, c: u32, rate: (i64, i64)) -> CItem {
let len = units_to_ticks(self.len(c), rate.0, rate.1);
let start = units_to_ticks(self.i32(c, "OMFI:SCLP:StartTime").unwrap_or(0), rate.0, rate.1);
let name = self.string(c, "FilmCraft:SCLP:ClipName").unwrap_or_default();
let (Some(id), Some(track)) = (self.uid(c, "OMFI:SCLP:SourceID"), self.u32(c, "OMFI:SCLP:SourceTrackID")) else { return CItem::Filler(len) };
if id == [0; 12] {
return CItem::Filler(len);
}
match self.resolve(id, track, start, None, 0) {
Some((source, t)) => CItem::Clip(CClip { len, source, start: t, gain: None, name }),
None => CItem::Filler(len),
}
}
fn slot_of(&self, mob: u32, track: u32) -> Option<u32> {
self.refs(mob, "OMFI:MOBJ:Slots")
.into_iter()
.find(|&s| self.r#ref(s, "OMFI:MSLT:TrackDesc").and_then(|t| self.u32(t, "OMFI:TRKD:TrackID")) == Some(track))
}
fn first_clip(&self, seg: u32) -> Option<u32> {
match &self.class(seg) {
b"SCLP" => Some(seg),
b"SEQU" => self.refs(seg, "OMFI:SEQU:Components").into_iter().find_map(|c| self.first_clip(c)),
_ => None,
}
}
fn resolve(&mut self, id: Uid, track: u32, start: Tick, master: Option<String>, depth: usize) -> Option<(usize, Tick)> {
if depth > 16 {
return None;
}
let Some(&mob) = self.mobs.get(&id) else {
self.report.warn("a clip references a mob that is not in the file (imported as a gap)");
return None;
};
let slot = self.slot_of(mob, track)?;
let rate = self.rational(slot, "OMFI:MSLT:EditRate").filter(|r| r.0 > 0 && r.1 > 0).unwrap_or((48_000, 1));
let seg = self.r#ref(slot, "OMFI:MSLT:Segment")?;
match &self.class(mob) {
b"MMOB" => {
let key = master.unwrap_or_else(|| id.iter().map(|b| format!("{b:02x}")).collect());
let clip = self.first_clip(seg)?;
let inner = units_to_ticks(self.i32(clip, "OMFI:SCLP:StartTime").unwrap_or(0), rate.0, rate.1);
let next = self.uid(clip, "OMFI:SCLP:SourceID")?;
let next_track = self.u32(clip, "OMFI:SCLP:SourceTrackID")?;
let name = self.string(mob, "OMFI:MOBJ:Name");
let r = self.resolve(next, next_track, start + inner, Some(key), depth + 1)?;
if let Some(n) = name {
self.doc.sources[r.0].name = n;
}
Some(r)
}
b"SMOB" => {
let desc = self.r#ref(mob, "OMFI:SMOB:MediaDescription")?;
let sr = self.rational(desc, "OMFI:MDFL:SampleRate");
if sr.is_none() && !self.media.contains_key(&id) {
return None; // a tape / physical source
}
let key = master.unwrap_or_else(|| id.iter().map(|b| format!("{b:02x}")).collect());
let skey = (id, track, key.clone());
if let Some(&i) = self.sources.get(&skey) {
return Some((i, start));
}
let file_rate = sr.filter(|r| r.0 > 0 && r.1 > 0).unwrap_or(rate);
let length = units_to_ticks(self.i32(desc, "OMFI:MDFL:Length").unwrap_or(0), file_rate.0, file_rate.1);
let summary = self.c.get(desc, "OMFI:WAVD:Summary").or_else(|| self.c.get(desc, "OMFI:AIFD:Summary")).unwrap_or_default();
let fmt = crate::pcm::parse_wav(&summary).or_else(|| crate::pcm::parse_aiff(&summary)).map(|(_, ch, sr, bits)| (ch as u32, sr, bits));
let mut path = None;
for l in self.refs(desc, "OMFI:MDES:Locator") {
let p = match &self.class(l) {
b"UNXL" => self.string(l, "OMFI:UNXL:PathName"),
b"DOSL" => self.string(l, "OMFI:DOSL:PathName"),
b"MACL" => self.string(l, "OMFI:MACL:PathName"),
b"TXTL" => self.string(l, "OMFI:TXTL:Name"),
b"NETL" => self.string(l, "OMFI:NETL:URLString").map(|u| craft_timeline::path::file_url_to_path(&u)),
_ => None,
};
if p.is_some() {
path = p;
break;
}
}
let sound_slots = self.refs(mob, "OMFI:MOBJ:Slots").len();
let (file_channels, sample_rate, bits) = fmt.unwrap_or((1, file_rate.0 as u32, 16));
let channel = (file_channels > 1 && sound_slots > 1).then(|| track.saturating_sub(1).min(file_channels - 1));
// timecode of the physical source
let tc = self.first_clip(seg).and_then(|clip| {
let tid = self.uid(clip, "OMFI:SCLP:SourceID")?;
let tape = *self.mobs.get(&tid)?;
let (start_tc, fps, trate) = self.refs(tape, "OMFI:MOBJ:Slots").into_iter().find_map(|s| {
let g = self.r#ref(s, "OMFI:MSLT:Segment")?;
(self.class(g) == *b"TCCP").then(|| {
(
self.i32(g, "OMFI:TCCP:Start").unwrap_or(0),
self.u16(g, "OMFI:TCCP:FPS").unwrap_or(25),
self.rational(s, "OMFI:MSLT:EditRate"),
)
})
})?;
let tcr = trate
.filter(|r| r.0 > 0 && r.1 > 0)
.map(|r| FrameRate::new(r.0, r.1))
.unwrap_or_else(|| FrameRate::new(fps.max(1) as i64, 1));
let off = units_to_ticks(self.i32(clip, "OMFI:SCLP:StartTime").unwrap_or(0), rate.0, rate.1);
Some((start_tc + tcr.frame_at(off), tcr))
});
let mut s = Source {
key,
name: self.string(mob, "OMFI:MOBJ:Name").unwrap_or_default(),
kind: CKind::Sound,
path,
channel,
channels: if channel.is_some() { 1 } else { file_channels },
file_channels,
width: 0,
height: 0,
frame_rate: FrameRate::FPS_25,
sample_rate,
bits,
length,
offset: Tick::ZERO,
start_tc: tc.map(|t| t.0),
tc_rate: tc.map(|t| t.1).unwrap_or(FrameRate::FPS_25),
embedded: None,
markers: Vec::new(),
nested: None,
};
if let Some(d) = self.media.get(&id) {
if let Some((pcm, ch, sr, b)) = crate::pcm::parse_wav(d).or_else(|| crate::pcm::parse_aiff(d)) {
s.embedded = Some(pcm);
s.file_channels = ch as u32;
s.channels = if s.channel.is_some() { 1 } else { ch as u32 };
s.sample_rate = sr;
s.bits = b;
} else {
self.report.warn("embedded OMF audio in an unsupported format was skipped");
}
}
let i = self.doc.sources.len();
self.doc.sources.push(s);
self.sources.insert(skey, i);
Some((i, start))
}
_ => {
self.report.warn("nested OMF compositions are not supported (imported as gaps)");
None
}
}
}
}
+135
View File
@@ -0,0 +1,135 @@
//! Structural checks of written OMF files: the Bento label and TOC, and the required properties of
//! the OMF Interchange 2.0 classes written.
use std::collections::HashMap;
use super::bento::{self, Container};
use super::*;
use crate::testdoc::{IDENTITY, sound_only};
/// Every object of a class written has the properties the specification requires of it.
fn assert_required_properties(c: &Container<'_>, by_class: &HashMap<String, Vec<u32>>) {
let required: &[(&str, &[&str])] = &[
(
"HEAD",
&[
"OMFI:HEAD:ByteOrder",
"OMFI:HEAD:LastModified",
"OMFI:HEAD:Version",
"OMFI:HEAD:Mobs",
"OMFI:HEAD:MediaData",
"OMFI:HEAD:DefinitionObjects",
],
),
("CMOB", &["OMFI:MOBJ:MobID", "OMFI:MOBJ:Slots", "OMFI:MOBJ:LastModified", "OMFI:MOBJ:CreationTime"]),
("MMOB", &["OMFI:MOBJ:MobID", "OMFI:MOBJ:Slots", "OMFI:MOBJ:LastModified", "OMFI:MOBJ:CreationTime"]),
("SMOB", &["OMFI:MOBJ:MobID", "OMFI:MOBJ:Slots", "OMFI:SMOB:MediaDescription"]),
("MSLT", &["OMFI:MSLT:Segment", "OMFI:MSLT:EditRate", "OMFI:MSLT:TrackDesc"]),
("TRKD", &["OMFI:TRKD:Origin", "OMFI:TRKD:TrackID"]),
("SEQU", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length", "OMFI:SEQU:Components"]),
("SCLP", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length", "OMFI:SCLP:SourceID", "OMFI:SCLP:SourceTrackID", "OMFI:SCLP:StartTime"]),
("FILL", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length"]),
("TRAN", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length", "OMFI:TRAN:CutPoint", "OMFI:TRAN:Effect"]),
("EFFE", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length", "OMFI:EFFE:EffectKind"]),
("ESLT", &["OMFI:ESLT:ArgID", "OMFI:ESLT:ArgValue"]),
("CVAL", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length", "OMFI:CVAL:Value"]),
("EDEF", &["OMFI:EDEF:EffectID"]),
("DDEF", &["OMFI:DDEF:DataKindID"]),
("TCCP", &["OMFI:CPNT:DataKind", "OMFI:CPNT:Length", "OMFI:TCCP:Start", "OMFI:TCCP:FPS", "OMFI:TCCP:Drop"]),
("WAVD", &["OMFI:MDFL:IsOMFI", "OMFI:MDFL:SampleRate", "OMFI:MDFL:Length", "OMFI:WAVD:Summary"]),
("WAVE", &["OMFI:MDAT:MobID", "OMFI:WAVE:Data"]),
("IDNT", &["OMFI:IDNT:CompanyName", "OMFI:IDNT:ProductName"]),
];
for (k, props) in required {
let Some(objs) = by_class.get(*k) else {
assert_eq!(*k, "FILL", "no {k} object");
continue;
};
for &o in objs {
for prop in *props {
assert!(c.get(o, prop).is_some(), "{k} {o} lacks {prop}");
}
}
}
}
#[test]
fn written_files_have_the_required_structure() {
let mut report = Report::default();
let bytes = write(&sound_only(Some(vec![7; 480 * 4])), &IDENTITY, &mut report).unwrap();
assert!(!report.has_warnings(), "{report}");
// label
let l = &bytes[bytes.len() - bento::LABEL_SIZE..];
assert_eq!(&l[..8], &bento::MAGIC);
assert_eq!(u16::from_be_bytes([l[12], l[13]]), 1, "Bento major version");
let c = Container::open(&bytes).unwrap();
let class = |o: u32| c.get(o, "OMFI:OOBJ:ObjClass").map(|v| String::from_utf8_lossy(&v).to_string());
let mut by_class: HashMap<String, Vec<u32>> = HashMap::new();
for &o in c.objects.keys() {
if let Some(k) = class(o) {
by_class.entry(k).or_default().push(o);
}
}
assert_required_properties(&c, &by_class);
assert_eq!(by_class["HEAD"].len(), 1);
assert_eq!(by_class["CMOB"].len(), 1);
let head = by_class["HEAD"][0];
assert_eq!(c.get(head, "OMFI:HEAD:Version"), Some(vec![2, 0]));
assert_eq!(c.get(head, "OMFI:HEAD:ByteOrder"), Some(b"MM".to_vec()));
// object references resolve to objects of the right class
let refs = |o: u32, p: &str| -> Vec<u32> {
let v = c.get(o, p).unwrap();
let n = u16::from_be_bytes([v[0], v[1]]) as usize;
v[2..].as_chunks::<4>().0.iter().take(n).map(|k| c.resolve(o, u32::from_be_bytes([k[0], k[1], k[2], k[3]]))).collect()
};
let one = |o: u32, p: &str| -> u32 { c.resolve(o, u32::from_be_bytes(c.get(o, p).unwrap()[..4].try_into().unwrap())) };
for m in refs(head, "OMFI:HEAD:Mobs") {
assert!(matches!(class(m).as_deref(), Some("CMOB" | "MMOB" | "SMOB")));
for s in refs(m, "OMFI:MOBJ:Slots") {
assert_eq!(class(s).as_deref(), Some("MSLT"));
assert_eq!(class(one(s, "OMFI:MSLT:TrackDesc")).as_deref(), Some("TRKD"));
}
}
// embedded media: WAVE data is a WAVE file of the file mob it names
for w in &by_class["WAVE"] {
let data = c.get(*w, "OMFI:WAVE:Data").unwrap();
let (pcm, ch, sr, bits) = crate::pcm::parse_wav(&data).unwrap();
assert_eq!((pcm.len(), ch, sr, bits), (480 * 4, 2, 48_000, 16));
let id = c.get(*w, "OMFI:MDAT:MobID").unwrap();
assert!(by_class["SMOB"].iter().any(|s| c.get(*s, "OMFI:MOBJ:MobID") == Some(id.clone())));
}
// the composition's sound sequence: clip, transition, gain effect around a clip
let cm = by_class["CMOB"][0];
let slots = refs(cm, "OMFI:MOBJ:Slots");
assert_eq!(class(one(slots[0], "OMFI:MSLT:Segment")).as_deref(), Some("TCCP"));
let seq = one(slots[1], "OMFI:MSLT:Segment");
let comps = refs(seq, "OMFI:SEQU:Components");
let classes: Vec<String> = comps.iter().map(|&o| class(o).unwrap()).collect();
assert_eq!(classes, vec!["EFFE", "TRAN", "SCLP"]);
let len = |o: u32| i32::from_be_bytes(c.get(o, "OMFI:CPNT:Length").unwrap()[..4].try_into().unwrap()) as i64;
let samples = |f: i64| f * 48_000 / 25;
assert_eq!(len(comps[0]), samples(55));
assert_eq!(len(comps[1]), samples(10));
assert_eq!(len(comps[2]), samples(55));
assert_eq!(len(seq), samples(100));
assert_eq!(c.get(one(comps[0], "OMFI:EFFE:EffectKind"), "OMFI:EDEF:EffectID"), Some(b"omfi:effect:MonoAudioGain\0".to_vec()));
}
#[test]
fn bento_values_round_trip() {
let mut w = bento::Writer::new();
let a = w.new_object();
let b = w.new_object();
w.set(a, "Test:Small", "test:Bytes", &[1, 2]);
w.set(a, "Test:Empty", "test:Bytes", &[]);
w.set(b, "Test:Big", "test:Bytes", &vec![9; 100_000]);
w.set_references(a, &[b]);
let bytes = w.finish();
let c = Container::open(&bytes).unwrap();
assert_eq!(c.get(a, "Test:Small"), Some(vec![1, 2]));
assert_eq!(c.get(a, "Test:Empty"), Some(vec![]));
assert_eq!(c.get(b, "Test:Big").map(|v| v.len()), Some(100_000));
assert_eq!(c.resolve(a, b), b);
assert_eq!(c.name_of(c.id_of("Test:Big").unwrap()), Some("Test:Big"));
assert!(Container::open(&bytes[..bytes.len() - 1]).is_err());
}
+419
View File
@@ -0,0 +1,419 @@
//! Composition model → OMF 2.0 objects in a Bento container.
use std::collections::HashMap;
use craft_timeline::time::Tick;
use super::bento;
use crate::model::{CItem, CKind, Document, Gain, Source, ticks_to_units};
use crate::{Error, Identity, Report, Result};
/// An OMF mob id (`omfi:UID`): prefix, major, minor.
pub(crate) type Uid = [u8; 12];
pub(crate) fn uid(prefix: u32, major: u32, minor: u32) -> Uid {
let mut u = [0u8; 12];
u[..4].copy_from_slice(&prefix.to_be_bytes());
u[4..8].copy_from_slice(&major.to_be_bytes());
u[8..].copy_from_slice(&minor.to_be_bytes());
u
}
struct W<'a> {
b: bento::Writer,
refs: HashMap<u32, Vec<u32>>,
ddefs: HashMap<&'static str, u32>,
edefs: HashMap<&'static str, u32>,
defs: Vec<u32>,
report: &'a mut Report,
inexact: bool,
}
fn rational(n: i64, d: i64) -> Vec<u8> {
let mut v = (n.clamp(i32::MIN as i64, i32::MAX as i64) as i32).to_be_bytes().to_vec();
v.extend_from_slice(&(d.clamp(i32::MIN as i64, i32::MAX as i64) as i32).to_be_bytes());
v
}
fn cstr(s: &str) -> Vec<u8> {
let mut v = s.as_bytes().to_vec();
v.push(0);
v
}
impl W<'_> {
fn obj(&mut self, class: &[u8; 4]) -> u32 {
let id = self.b.new_object();
self.b.set(id, "OMFI:OOBJ:ObjClass", "omfi:ClassID", class);
id
}
fn str(&mut self, o: u32, p: &str, v: &str) {
self.b.set(o, p, "omfi:String", &cstr(v));
}
fn i32(&mut self, o: u32, p: &str, ty: &str, v: i64) {
if v > i32::MAX as i64 || v < i32::MIN as i64 {
self.report.warn("a time does not fit OMF's 32-bit positions and was clamped");
}
self.b.set(o, p, ty, &(v.clamp(i32::MIN as i64, i32::MAX as i64) as i32).to_be_bytes());
}
fn r#ref(&mut self, o: u32, p: &str, target: u32) {
self.b.set(o, p, "omfi:ObjRef", &target.to_be_bytes());
self.refs.entry(o).or_default().push(target);
}
fn refs(&mut self, o: u32, p: &str, targets: &[u32]) {
let mut v = (targets.len() as u16).to_be_bytes().to_vec();
for t in targets {
v.extend_from_slice(&t.to_be_bytes());
}
self.b.set(o, p, "omfi:ObjRefArray", &v);
self.refs.entry(o).or_default().extend_from_slice(targets);
}
fn u(&mut self, t: Tick, rate: (i64, i64)) -> i64 {
let (n, exact) = ticks_to_units(t, rate.0, rate.1);
if !exact {
self.inexact = true;
}
n
}
fn ddef(&mut self, kind: &'static str) -> u32 {
if let Some(&d) = self.ddefs.get(kind) {
return d;
}
let d = self.obj(b"DDEF");
self.b.set(d, "OMFI:DDEF:DataKindID", "omfi:UniqueName", &cstr(kind));
self.ddefs.insert(kind, d);
self.defs.push(d);
d
}
fn edef(&mut self, id: &'static str, name: &str) -> u32 {
if let Some(&d) = self.edefs.get(id) {
return d;
}
let d = self.obj(b"EDEF");
self.b.set(d, "OMFI:EDEF:EffectID", "omfi:UniqueName", &cstr(id));
self.str(d, "OMFI:EDEF:EffectName", name);
self.b.set(d, "OMFI:EDEF:Bypass", "omfi:ArgIDType", &(-1i32).to_be_bytes());
self.edefs.insert(id, d);
self.defs.push(d);
d
}
fn cpnt(&mut self, o: u32, kind: &'static str, len: i64) {
let d = self.ddef(kind);
self.r#ref(o, "OMFI:CPNT:DataKind", d);
self.i32(o, "OMFI:CPNT:Length", "omfi:Length32", len);
}
fn mob(&mut self, class: &[u8; 4], id: Uid, name: &str, slots: &[u32]) -> u32 {
let m = self.obj(class);
self.b.set(m, "OMFI:MOBJ:MobID", "omfi:UID", &id);
self.str(m, "OMFI:MOBJ:Name", name);
self.refs(m, "OMFI:MOBJ:Slots", slots);
self.b.set(m, "OMFI:MOBJ:LastModified", "omfi:TimeStamp", &[0, 0, 0, 0, 1]);
self.b.set(m, "OMFI:MOBJ:CreationTime", "omfi:TimeStamp", &[0, 0, 0, 0, 1]);
m
}
fn slot(&mut self, rate: (i64, i64), segment: u32, track_id: u32, name: &str, physical: u32) -> u32 {
let t = self.obj(b"TRKD");
self.i32(t, "OMFI:TRKD:Origin", "omfi:Position32", 0);
self.b.set(t, "OMFI:TRKD:TrackID", "omfi:UInt32", &track_id.to_be_bytes());
self.str(t, "OMFI:TRKD:TrackName", name);
if physical > 0 {
self.b.set(t, "OMFI:TRKD:PhysicalTrack", "omfi:UInt32", &physical.to_be_bytes());
}
let s = self.obj(b"MSLT");
self.b.set(s, "OMFI:MSLT:EditRate", "omfi:Rational", &rational(rate.0, rate.1));
self.r#ref(s, "OMFI:MSLT:Segment", segment);
self.r#ref(s, "OMFI:MSLT:TrackDesc", t);
s
}
fn sclp(&mut self, kind: &'static str, len: i64, source: Uid, track: u32, start: i64) -> u32 {
let c = self.obj(b"SCLP");
self.cpnt(c, kind, len);
self.b.set(c, "OMFI:SCLP:SourceID", "omfi:UID", &source);
self.b.set(c, "OMFI:SCLP:SourceTrackID", "omfi:UInt32", &track.to_be_bytes());
self.i32(c, "OMFI:SCLP:StartTime", "omfi:Position32", start);
c
}
fn tccp(&mut self, len: i64, start: i64, fps: i64, drop: bool) -> u32 {
let t = self.obj(b"TCCP");
self.cpnt(t, "omfi:data:Timecode", len);
self.i32(t, "OMFI:TCCP:Start", "omfi:Position32", start);
self.b.set(t, "OMFI:TCCP:FPS", "omfi:UInt16", &(fps.clamp(1, u16::MAX as i64) as u16).to_be_bytes());
self.b.set(t, "OMFI:TCCP:Drop", "omfi:Boolean", &[drop as u8]);
t
}
fn value(&mut self, len: i64, g: &Gain, seg_len: i64, rate: (i64, i64), base: Tick) -> u32 {
match g {
Gain::Constant(a) => {
let v = self.obj(b"CVAL");
self.cpnt(v, "omfi:data:Rational", len);
self.b.set(v, "OMFI:CVAL:Value", "omfi:DataValue", &amp(*a));
v
}
Gain::Varying { linear, points } => {
let mut pts = Vec::new();
for (off, a) in points {
let o = self.u(base + *off, rate) - self.u(base, rate);
let p = self.obj(b"CTLP");
self.b.set(p, "OMFI:CTLP:Time", "omfi:Rational", &rational(o, seg_len.max(1)));
self.b.set(p, "OMFI:CTLP:Value", "omfi:DataValue", &amp(*a));
self.b.set(p, "OMFI:CTLP:EditHint", "omfi:EditHintType", &[0]);
pts.push(p);
}
let v = self.obj(b"VVAL");
self.cpnt(v, "omfi:data:Rational", len);
self.b.set(v, "OMFI:VVAL:Interpolation", "omfi:InterpKind", &(if *linear { 2u16 } else { 1u16 }).to_be_bytes());
self.refs(v, "OMFI:VVAL:PointList", &pts);
v
}
}
}
}
fn fnv(s: &[u8], h: u64) -> u64 {
s.iter().fold(h, |h, &b| (h ^ b as u64).wrapping_mul(0x0000_0100_0000_01B3))
}
fn amp(a: f64) -> Vec<u8> {
rational((a.max(0.0) * 65536.0).round().min(i32::MAX as f64) as i64, 65536)
}
fn rate_of(s: &Source) -> (i64, i64) {
match s.kind {
CKind::Picture => (s.frame_rate.num, s.frame_rate.den),
CKind::Sound => (s.sample_rate.max(1) as i64, 1),
}
}
pub(crate) fn write(doc: &Document, identity: &Identity<'_>, report: &mut Report) -> Result<Vec<u8>> {
let comp = doc.compositions.first().ok_or(Error::Empty)?;
let mut w =
W { b: bento::Writer::new(), refs: HashMap::new(), ddefs: HashMap::new(), edefs: HashMap::new(), defs: Vec::new(), report, inexact: false };
let mut seed = fnv(comp.name.as_bytes(), 0xCBF2_9CE4_8422_2325);
for s in &doc.sources {
seed = fnv(s.path.as_deref().unwrap_or("").as_bytes(), fnv(s.key.as_bytes(), seed));
}
let major = (seed >> 32) as u32 ^ seed as u32;
let mut minor = 0u32;
let mut new_uid = || {
minor += 1;
uid(0x464C_4D43, major, minor)
};
let mut mobs = Vec::new();
let mut media_data = Vec::new();
let mut master_ref: HashMap<usize, (Uid, u32)> = HashMap::new();
// media
let mut groups: Vec<(String, Vec<usize>)> = Vec::new();
for (i, s) in doc.sources.iter().enumerate() {
if s.kind != CKind::Sound {
continue;
}
match groups.iter_mut().find(|(k, _)| *k == s.key) {
Some((_, v)) => v.push(i),
None => groups.push((s.key.clone(), vec![i])),
}
}
for (_, members) in &groups {
let first = &doc.sources[members[0]];
let master = new_uid();
let tc = members.iter().find_map(|&i| doc.sources[i].start_tc.map(|t| (t, doc.sources[i].tc_rate)));
let tape = new_uid();
let mut tape_slots = Vec::new();
if let Some((start, r)) = tc {
let len = members.iter().map(|&i| doc.sources[i].length).max().unwrap_or(Tick::ZERO);
let l = w.u(len, (r.num, r.den));
let t = w.tccp(l, start, r.timecode_base(), false);
tape_slots.push(w.slot((r.num, r.den), t, 1, "TC1", 0));
}
let mut master_slots = Vec::new();
for (k, &si) in members.iter().enumerate() {
let s = &doc.sources[si];
let rate = rate_of(s);
let len = w.u(s.length, rate);
// file mob
let file = new_uid();
let file_track = s.channel.map_or(1, |c| c + 1);
let tape_track = 2 + k as u32;
let to_tape =
if tc.is_some() { w.sclp("omfi:data:Sound", len, tape, tape_track, 0) } else { w.sclp("omfi:data:Sound", len, uid(0, 0, 0), 0, 0) };
let fslot = w.slot(rate, to_tape, file_track, &format!("A{file_track}"), file_track);
let desc = descriptor(&mut w, s, len);
let fm = w.mob(b"SMOB", file, &s.name, &[fslot]);
w.r#ref(fm, "OMFI:SMOB:MediaDescription", desc);
mobs.push(fm);
if let Some(pcm) = &s.embedded {
let md = w.obj(b"WAVE");
w.b.set(md, "OMFI:MDAT:MobID", "omfi:UID", &file);
w.b.set(
md,
"OMFI:WAVE:Data",
"omfi:DataValue",
&craft_audio::pcm_wav_file(pcm, u16::try_from(s.file_channels.max(1)).unwrap_or(u16::MAX), s.sample_rate, s.bits),
);
media_data.push(md);
}
if tc.is_some() {
let c = w.sclp("omfi:data:Sound", len, uid(0, 0, 0), 0, 0);
tape_slots.push(w.slot(rate, c, tape_track, &format!("A{}", k + 1), k as u32 + 1));
}
let mclip = w.sclp("omfi:data:Sound", len, file, file_track, 0);
master_slots.push(w.slot(rate, mclip, k as u32 + 1, &format!("A{}", k + 1), k as u32 + 1));
master_ref.insert(si, (master, k as u32 + 1));
}
mobs.push(w.mob(b"MMOB", master, &first.name, &master_slots));
if tc.is_some() {
let d = w.obj(b"MDTP");
let reel = first.path.as_deref().map(craft_timeline::path::file_stem).unwrap_or(&first.name).to_string();
let tm = w.mob(b"SMOB", tape, &reel, &tape_slots);
w.r#ref(tm, "OMFI:SMOB:MediaDescription", d);
mobs.push(tm);
}
}
// composition
let crate_rate = (comp.rate.num, comp.rate.den);
let mut slots = Vec::new();
let total = comp
.tracks
.iter()
.map(|t| t.items.iter().fold(Tick::ZERO, |a, i| if matches!(i, CItem::Transition(_)) { a - i.len() } else { a + i.len() }))
.max()
.unwrap_or(Tick::ZERO);
let tl = w.u(total, crate_rate);
let tcc = w.tccp(tl, comp.start_tc, comp.rate.timecode_base(), comp.drop);
slots.push(w.slot(crate_rate, tcc, 1, "TC1", 0));
for (track_id, t) in (2..).zip(comp.tracks.iter().filter(|t| t.kind == CKind::Sound)) {
let rate = (comp.sample_rate.max(1) as i64, 1);
let mut comps = Vec::new();
let mut cursor = Tick::ZERO;
for it in &t.items {
match it {
CItem::Filler(l) => {
let n = w.u(cursor + *l, rate) - w.u(cursor, rate);
cursor += *l;
let f = w.obj(b"FILL");
w.cpnt(f, "omfi:data:Sound", n);
comps.push(f);
}
CItem::Clip(c) => {
let n = w.u(cursor + c.len, rate) - w.u(cursor, rate);
let (mid, mtrack) = master_ref.get(&c.source).copied().unwrap_or((uid(0, 0, 0), 0));
let start = w.u(c.start, rate);
let sc = w.sclp("omfi:data:Sound", n, mid, mtrack, start);
if !c.name.is_empty() {
w.str(sc, "FilmCraft:SCLP:ClipName", &c.name);
}
let seg = match &c.gain {
Some(g) => {
let v = w.value(n, g, n, rate, cursor);
let input = w.obj(b"ESLT");
w.b.set(input, "OMFI:ESLT:ArgID", "omfi:ArgIDType", &(-1i32).to_be_bytes());
w.r#ref(input, "OMFI:ESLT:ArgValue", sc);
let level = w.obj(b"ESLT");
w.b.set(level, "OMFI:ESLT:ArgID", "omfi:ArgIDType", &1i32.to_be_bytes());
w.r#ref(level, "OMFI:ESLT:ArgValue", v);
let kind = w.edef("omfi:effect:MonoAudioGain", "Mono Audio Gain");
let e = w.obj(b"EFFE");
w.cpnt(e, "omfi:data:Sound", n);
w.r#ref(e, "OMFI:EFFE:EffectKind", kind);
w.refs(e, "OMFI:EFFE:EffectSlots", &[input, level]);
e
}
None => sc,
};
comps.push(seg);
cursor += c.len;
}
CItem::Transition(x) => {
let ts = cursor - x.len;
let n = w.u(cursor, rate) - w.u(ts, rate);
let cut = w.u(ts + x.cut, rate) - w.u(ts, rate);
cursor = ts;
let kind = w.edef("omfi:effect:SimpleMonoAudioDissolve", "Simple Mono Audio Dissolve");
let e = w.obj(b"EFFE");
w.cpnt(e, "omfi:data:Sound", n);
w.r#ref(e, "OMFI:EFFE:EffectKind", kind);
w.refs(e, "OMFI:EFFE:EffectSlots", &[]);
w.str(e, "FilmCraft:EFFE:EffectID", &x.effect);
let tr = w.obj(b"TRAN");
w.cpnt(tr, "omfi:data:Sound", n);
w.i32(tr, "OMFI:TRAN:CutPoint", "omfi:Position32", cut);
w.r#ref(tr, "OMFI:TRAN:Effect", e);
comps.push(tr);
}
}
}
let len = w.u(cursor.max(Tick::ZERO), rate);
let seq = w.obj(b"SEQU");
w.cpnt(seq, "omfi:data:Sound", len);
w.refs(seq, "OMFI:SEQU:Components", &comps);
slots.push(w.slot(rate, seq, track_id, &t.name, t.number));
}
let cmob = w.mob(b"CMOB", new_uid(), &comp.name, &slots);
mobs.insert(0, cmob);
if w.inexact {
w.report.info("some times are not on whole samples / frames and were rounded");
}
let ident = w.obj(b"IDNT");
w.str(ident, "OMFI:IDNT:CompanyName", identity.company);
w.str(ident, "OMFI:IDNT:ProductName", identity.product);
w.str(ident, "OMFI:IDNT:ProductVersionString", identity.version);
w.str(ident, "OMFI:IDNT:Platform", identity.platform);
w.b.set(ident, "OMFI:IDNT:Date", "omfi:TimeStamp", &[0, 0, 0, 0, 1]);
let head = w.obj(b"HEAD");
w.b.set(head, "OMFI:HEAD:ByteOrder", "omfi:Int16", &0x4D4Di16.to_be_bytes());
w.b.set(head, "OMFI:HEAD:LastModified", "omfi:TimeStamp", &[0, 0, 0, 0, 1]);
w.b.set(head, "OMFI:HEAD:Version", "omfi:VersionType", &[2, 0]);
w.refs(head, "OMFI:HEAD:Mobs", &mobs);
w.refs(head, "OMFI:HEAD:MediaData", &media_data);
w.refs(head, "OMFI:HEAD:PrimaryMobs", &[cmob]);
let defs = w.defs.clone();
w.refs(head, "OMFI:HEAD:DefinitionObjects", &defs);
w.refs(head, "OMFI:HEAD:IdentificationList", &[ident]);
let refs = std::mem::take(&mut w.refs);
let mut keys: Vec<_> = refs.keys().copied().collect();
keys.sort_unstable();
for k in keys {
let mut t = refs[&k].clone();
t.sort_unstable();
t.dedup();
w.b.set_references(k, &t);
}
Ok(w.b.finish())
}
fn descriptor(w: &mut W, s: &Source, len: i64) -> u32 {
let aiff =
s.embedded.is_none() && s.path.as_deref().is_some_and(|p| matches!(craft_timeline::path::extension(p).as_str(), "aif" | "aiff" | "aifc"));
let d = w.obj(if aiff { b"AIFD" } else { b"WAVD" });
w.b.set(d, "OMFI:MDFL:IsOMFI", "omfi:Boolean", &[s.embedded.is_some() as u8]);
let r = rate_of(s);
w.b.set(d, "OMFI:MDFL:SampleRate", "omfi:Rational", &rational(r.0, r.1));
w.i32(d, "OMFI:MDFL:Length", "omfi:Length32", len);
let frames = u32::try_from(len.max(0)).unwrap_or(u32::MAX);
// Channel counts come from the project: saturate, as the headers can't hold more anyway.
let bytes_per_frame = s.file_channels.max(1).saturating_mul((s.bits as u32).div_ceil(8));
let channels = u16::try_from(s.file_channels.max(1)).unwrap_or(u16::MAX);
if aiff {
w.b.set(d, "OMFI:AIFD:Summary", "omfi:DataValue", &craft_audio::pcm_aiff_header(frames, channels, s.sample_rate, s.bits));
} else {
w.b.set(
d,
"OMFI:WAVD:Summary",
"omfi:DataValue",
&craft_audio::pcm_wav_header(frames.saturating_mul(bytes_per_frame), channels, s.sample_rate, s.bits),
);
}
if let Some(p) = &s.path {
let mut locs = Vec::new();
let dos = p.len() > 2 && p.as_bytes()[1] == b':';
let l = w.obj(if dos { b"DOSL" } else { b"UNXL" });
w.str(l, if dos { "OMFI:DOSL:PathName" } else { "OMFI:UNXL:PathName" }, p);
locs.push(l);
if craft_timeline::path::is_absolute(p) {
let n = w.obj(b"NETL");
w.str(n, "OMFI:NETL:URLString", &craft_timeline::path::path_to_file_url(p, false));
locs.push(n);
}
w.refs(d, "OMFI:MDES:Locator", &locs);
}
d
}
+11
View File
@@ -0,0 +1,11 @@
//! Embedded PCM essence in and out of WAVE and AIFF wrappers (craft-audio does the containers).
/// PCM (little-endian, 8-bit unsigned), channels, sample rate and bits of a WAVE file.
pub(crate) fn parse_wav(b: &[u8]) -> Option<(Vec<u8>, u16, u32, u16)> {
craft_audio::wav_pcm(b).map(|p| (p.data, p.channels, p.sample_rate, p.bits))
}
/// The same for an AIFF / AIFF-C (`NONE`, `twos`, `sowt`) file.
pub(crate) fn parse_aiff(b: &[u8]) -> Option<(Vec<u8>, u16, u32, u16)> {
craft_audio::aiff_pcm(b).map(|p| (p.data, p.channels, p.sample_rate, p.bits))
}
+251
View File
@@ -0,0 +1,251 @@
//! Documents written and read back, in both formats; damaged files.
use craft_timeline::time::{FrameRate, Tick};
use crate::model::{CItem, CKind, CMarker, Composition, Document, Gain};
use crate::testdoc::{IDENTITY, pcm_ramp, picture_and_sound, sound_only};
use crate::{Error, Report, aaf, omf};
fn aaf_bytes(doc: &Document, small_sectors: bool) -> Vec<u8> {
let mut report = Report::default();
let bytes = aaf::write(doc, &aaf::WriteOptions { identity: IDENTITY, small_sectors }, &mut report).unwrap();
assert!(report.is_empty(), "{report}");
bytes
}
fn omf_bytes(doc: &Document) -> Vec<u8> {
let mut report = Report::default();
let bytes = omf::write(doc, &IDENTITY, &mut report).unwrap();
assert!(!report.has_warnings(), "{report}");
bytes
}
fn read_clean(bytes: &[u8], is_aaf: bool) -> Document {
let mut report = Report::default();
let doc = if is_aaf { aaf::read(bytes, &mut report) } else { omf::read(bytes, &mut report) }.unwrap();
assert!(!report.has_warnings(), "{report}");
doc
}
/// What a track holds, with each clip's source by what it is rather than by index. Gain is stored
/// as a rational: four decimals survive.
fn shape(doc: &Document) -> Vec<(CKind, String, u32, Vec<String>)> {
let comp = &doc.compositions[0];
comp.tracks
.iter()
.map(|t| {
let items = t
.items
.iter()
.map(|i| match i {
CItem::Filler(l) => format!("gap {}", l.0),
CItem::Transition(x) => format!("{} {} cut {}", x.effect, x.len.0, x.cut.0),
CItem::Clip(c) => {
let s = &doc.sources[c.source];
let gain = match &c.gain {
None => "unity".to_string(),
Some(Gain::Constant(g)) => format!("{g:.4}"),
Some(Gain::Varying { linear, points }) => {
format!("{linear} {:?}", points.iter().map(|(t, g)| (t.0, format!("{g:.4}"))).collect::<Vec<_>>())
}
};
format!("clip {} from {} of {:?} {:?} gain {gain}", c.len.0, c.start.0, s.path, s.kind)
}
})
.collect();
(t.kind, t.name.clone(), t.number, items)
})
.collect()
}
#[test]
fn aaf_round_trips_the_edit_at_every_rate() {
for (rate, drop) in [(FrameRate::FPS_25, false), (FrameRate::FPS_29_97, true), (FrameRate::FPS_23_976, false), (FrameRate::FPS_59_94, true)] {
let mut doc = picture_and_sound(rate);
let comp = &mut doc.compositions[0];
(comp.start_tc, comp.drop) = (rate.timecode_base() * 3600, drop);
comp.markers = vec![
CMarker { start: rate.tick_of(10), duration: Tick::ZERO, name: "Slate".into(), comment: "take 2".into(), color: Some("Green".into()) },
CMarker { start: rate.tick_of(40), duration: rate.tick_of(5), name: "Range".into(), comment: String::new(), color: None },
];
// keyframed gain on the first sound clip, held gain steps on nothing else
if let Some(CItem::Clip(c)) = comp.tracks[1].items.first_mut() {
c.gain = Some(Gain::Varying { linear: true, points: vec![(Tick::ZERO, 1.0), (rate.tick_of(25), 0.5)] });
}
doc.sources[0].markers =
vec![CMarker { start: rate.tick_of(30), duration: Tick::ZERO, name: "In media".into(), comment: String::new(), color: None }];
for small in [false, true] {
let back = read_clean(&aaf_bytes(&doc, small), true);
let (want, got) = (&doc.compositions[0], &back.compositions[0]);
assert_eq!(shape(&back), shape(&doc), "{rate} small {small}");
assert_eq!((&got.name, got.rate, got.start_tc, got.drop), (&want.name, want.rate, want.start_tc, want.drop), "{rate}");
assert_eq!((got.width, got.height, got.sample_rate), (1920, 1080, 48_000), "{rate}");
let markers = |m: &[CMarker]| m.iter().map(|m| (m.start, m.duration, m.name.clone(), m.comment.clone())).collect::<Vec<_>>();
assert_eq!(markers(&got.markers), markers(&want.markers), "{rate}");
assert_eq!(back.nested, []);
let picture = back.sources.iter().find(|s| s.kind == CKind::Picture).unwrap();
assert_eq!((picture.width, picture.height, picture.frame_rate, picture.length), (1280, 720, rate, doc.sources[0].length), "{rate}");
assert_eq!((picture.start_tc, picture.tc_rate), (Some(86_400), rate), "{rate}");
assert_eq!(markers(&picture.markers), markers(&doc.sources[0].markers), "{rate}");
let sound = back.sources.iter().find(|s| s.kind == CKind::Sound).unwrap();
assert_eq!((sound.channels, sound.file_channels, sound.sample_rate, sound.bits), (2, 2, 48_000, 24), "{rate}");
assert_eq!(sound.key, picture.key, "one media item");
// what was read, written again, reads as the same edit (mob ids, and so source keys, are new;
// a writer generates fresh format identifiers and never preserves `aaf_mob_id`)
let again = read_clean(&aaf_bytes(&back, small), true);
let no_ids = |c: &[Composition]| {
c.iter()
.cloned()
.map(|mut c| {
c.aaf_mob_id = None;
c
})
.collect::<Vec<_>>()
};
assert_eq!((shape(&again), no_ids(&again.compositions)), (shape(&back), no_ids(&back.compositions)), "{rate}");
}
}
}
#[test]
fn embedded_audio_comes_back_bit_for_bit() {
let pcm = pcm_ramp(480, 2, 3);
let mut doc = sound_only(Some(pcm.clone()));
// trimmed essence: its first sample is media time 0.2 s
doc.sources[0].offset = Tick::from_units(9_600, 48_000);
for is_aaf in [true, false] {
let bytes = if is_aaf { aaf_bytes(&doc, false) } else { omf_bytes(&doc) };
assert_eq!((aaf::sniff(&bytes), omf::sniff(&bytes)), (is_aaf, !is_aaf));
let back = read_clean(&bytes, is_aaf);
let s = &back.sources[0];
assert_eq!(s.embedded.as_deref(), Some(&pcm[..]), "aaf {is_aaf}");
assert_eq!((s.path.as_deref(), s.file_channels, s.sample_rate, s.bits), (None, 2, 48_000, 16), "aaf {is_aaf}");
assert_eq!(s.length, Tick::from_units(480, 48_000), "aaf {is_aaf}");
assert_eq!(shape(&back), shape(&doc), "aaf {is_aaf}");
}
}
#[test]
fn omf_round_trips_sound_linked_to_wave_and_aiff_files() {
for path in ["/m/a.wav", "/m/a.aif"] {
let mut doc = sound_only(None);
doc.sources[0].path = Some(path.into());
let back = read_clean(&omf_bytes(&doc), false);
assert_eq!(shape(&back), shape(&doc), "{path}");
let s = &back.sources[0];
assert_eq!((s.file_channels, s.sample_rate, s.bits, s.embedded.as_ref()), (2, 48_000, 16, None), "{path}");
assert_eq!(back.compositions[0].rate, FrameRate::FPS_25);
}
}
#[test]
fn omf_leaves_picture_out() {
let doc = picture_and_sound(FrameRate::FPS_25);
let back = read_clean(&omf_bytes(&doc), false);
assert!(back.compositions[0].tracks.iter().all(|t| t.kind == CKind::Sound));
assert_eq!(shape(&back).len(), 1);
}
#[test]
fn empty_and_foreign_documents() {
let none = Document::default();
assert_eq!(aaf::write(&none, &aaf::WriteOptions { identity: IDENTITY, small_sectors: false }, &mut Report::default()), Err(Error::Empty));
assert_eq!(omf::write(&none, &IDENTITY, &mut Report::default()), Err(Error::Empty));
let mut empty = sound_only(None);
empty.compositions[0].tracks.clear();
empty.sources.clear();
for small in [false, true] {
assert_eq!(read_clean(&aaf_bytes(&empty, small), true).compositions.len(), 1);
}
assert_eq!(read_clean(&omf_bytes(&empty), false).compositions.len(), 1);
assert!(matches!(aaf::read(b"not an aaf", &mut Report::default()), Err(Error::Parse { format: "AAF", .. })));
assert!(matches!(omf::read(b"not an omf", &mut Report::default()), Err(Error::Parse { format: "OMF", .. })));
assert!(!aaf::sniff(b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1 but short"));
assert!(!omf::sniff(b""));
}
/// Truncation and random corruption: an error or a document, never a panic.
#[test]
fn damaged_documents_never_panic() {
let aaf_file = aaf_bytes(&picture_and_sound(FrameRate::FPS_25), true);
let omf_file = omf_bytes(&sound_only(Some(pcm_ramp(100, 2, 1))));
for (bytes, is_aaf) in [(&aaf_file, true), (&omf_file, false)] {
let read = |b: &[u8]| {
let mut report = Report::default();
let _ = if is_aaf { aaf::read(b, &mut report) } else { omf::read(b, &mut report) };
};
for cut in (0..bytes.len()).step_by(97) {
read(&bytes[..cut]);
}
let mut seed = 0xA5A5_1234_5678_9ABCu64;
for _ in 0..400 {
let mut g = bytes.clone();
for _ in 0..8 {
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
let at = (seed as usize) % g.len();
g[at] = (seed >> 40) as u8;
}
read(&g);
}
}
}
/// A time that is not on a whole edit unit is rounded, and the report says so.
#[test]
fn off_grid_times_are_rounded_and_reported() {
let mut doc = picture_and_sound(FrameRate::FPS_25);
if let Some(CItem::Clip(c)) = doc.compositions[0].tracks[0].items.first_mut() {
c.start += Tick(7);
}
let mut report = Report::default();
aaf::write(&doc, &aaf::WriteOptions { identity: IDENTITY, small_sectors: false }, &mut report).unwrap();
assert!(report.mentions("rounded"), "{report}");
}
/// A composition that uses itself (a damaged file) is a gap with a warning, not a recursion.
#[test]
fn a_composition_nested_in_itself_is_a_gap() {
let rate = FrameRate::FPS_25;
let mut doc = picture_and_sound(rate);
let mut inner = doc.compositions[0].clone();
inner.name = "Inner".into();
let mut nest = doc.sources[0].clone();
(nest.key, nest.path, nest.nested, nest.start_tc) = ("seq:9".into(), None, Some(0), None);
doc.sources.push(nest);
let uses_inner = CItem::Clip(crate::model::CClip { len: rate.tick_of(20), source: 2, start: Tick::ZERO, gain: None, name: "Inner".into() });
inner.tracks[0].items = vec![uses_inner.clone()];
doc.nested.push(inner);
doc.compositions[0].tracks[0].items = vec![uses_inner];
let bytes = aaf::write(&doc, &aaf::WriteOptions { identity: IDENTITY, small_sectors: false }, &mut Report::default()).unwrap();
let mut report = Report::default();
let back = aaf::read(&bytes, &mut report).unwrap();
assert!(report.mentions("nested in itself"), "{report}");
assert_eq!(back.nested.len(), 1);
assert!(matches!(back.nested[0].tracks[0].items[..], [CItem::Filler(_)]), "{:?}", back.nested[0].tracks[0].items);
}
#[test]
fn aaf_source_start_uses_referenced_slot_rate() {
let doc = sound_only(None);
let bytes = aaf_bytes(&doc, false);
let back = read_clean(&bytes, true);
let original = doc.compositions[0].tracks[0]
.items
.iter()
.find_map(|item| match item {
CItem::Clip(c) => Some(c.start),
_ => None,
})
.unwrap();
let actual = back.compositions[0].tracks[0]
.items
.iter()
.find_map(|item| match item {
CItem::Clip(c) => Some(c.start),
_ => None,
})
.unwrap();
assert_eq!(actual, original);
}
+117
View File
@@ -0,0 +1,117 @@
//! Documents the tests write: what an editor's two-clip sequence with a dissolve looks like in
//! the model.
use craft_timeline::time::{FrameRate, Tick};
use crate::Identity;
use crate::model::{CClip, CItem, CKind, CTrack, CTransition, Composition, Document, Gain, Source};
pub(crate) const IDENTITY: Identity<'static> =
Identity { company: "Craft", product: "craft-aaf tests", version: "1.2.3", platform: "test", product_id: *b"craft-aaf-tests." };
/// A source of `kind` for the media item `key` at `path`: 1280×720 picture at `rate`, or stereo
/// 48 kHz sound of `bits` bits; 100 seconds long.
pub(crate) fn source(key: &str, path: &str, kind: CKind, rate: FrameRate, bits: u16, start_tc: Option<i64>) -> Source {
let sound = kind == CKind::Sound;
Source {
key: key.into(),
name: path.rsplit('/').next().unwrap_or(path).into(),
kind,
path: Some(path.into()),
channel: None,
channels: if sound { 2 } else { 0 },
file_channels: if sound { 2 } else { 0 },
width: if sound { 0 } else { 1280 },
height: if sound { 0 } else { 720 },
frame_rate: rate,
sample_rate: 48_000,
bits,
length: rate.tick_of(100 * rate.timecode_base()),
offset: Tick::ZERO,
start_tc,
tc_rate: rate,
embedded: None,
markers: Vec::new(),
nested: None,
}
}
pub(crate) fn clip(rate: FrameRate, source: usize, start: i64, len: i64, name: &str) -> CItem {
CItem::Clip(CClip { len: rate.tick_of(len), source, start: rate.tick_of(start), gain: None, name: name.into() })
}
/// Two clips of `source` cut at frame `cut`, each `cut` frames long on the timeline, joined by a
/// transition of `dur` frames centred on the cut: each clip runs half the transition past the cut.
pub(crate) fn two_clips(rate: FrameRate, source: usize, cut: i64, dur: i64, (in_a, in_b): (i64, i64), effect: &str) -> Vec<CItem> {
let half = dur / 2;
vec![
clip(rate, source, in_a, cut + half, "a"),
CItem::Transition(CTransition { len: rate.tick_of(dur), cut: rate.tick_of(half), effect: effect.into() }),
clip(rate, source, in_b - half, cut + half, "a"),
]
}
pub(crate) fn composition(name: &str, rate: FrameRate, tracks: Vec<CTrack>) -> Composition {
Composition {
name: name.into(),
aaf_mob_id: None,
rate,
sample_rate: 48_000,
width: 1920,
height: 1080,
start_tc: 0,
drop: false,
tracks,
markers: Vec::new(),
}
}
pub(crate) fn track(kind: CKind, name: &str, number: u32, items: Vec<CItem>) -> CTrack {
CTrack { kind, name: name.into(), number, channels: if kind == CKind::Sound { 2 } else { 0 }, items }
}
/// "S" at `rate`: V1 and A1 each hold two clips of `a.mov`, `cut` frames each on the timeline (from
/// source frames `ins`), with a transition of `dur` frames centred on the cut; the second sound
/// clip is 3 dB down.
pub(crate) fn picture_and_sound_cut(rate: FrameRate, cut: i64, dur: i64, ins: (i64, i64)) -> Document {
let sources = vec![
source("item:1", "/m/a.mov", CKind::Picture, rate, 24, Some(86_400)),
source("item:1", "/m/a.mov", CKind::Sound, rate, 24, Some(86_400)),
];
let mut sound = two_clips(rate, 1, cut, dur, ins, "constant_power");
if let Some(CItem::Clip(c)) = sound.last_mut() {
c.gain = Some(Gain::Constant(10f64.powf(-3.0 / 20.0)));
}
let tracks = vec![track(CKind::Picture, "V1", 1, two_clips(rate, 0, cut, dur, ins, "cross_dissolve")), track(CKind::Sound, "A1", 1, sound)];
Document { compositions: vec![composition("S", rate, tracks)], sources, nested: Vec::new() }
}
/// [`picture_and_sound_cut`] with 50-frame clips from source frames 10 and 205 and a 10-frame
/// transition: every time is a multiple of five frames, which is a whole number of 48 kHz samples
/// at the NTSC rates too.
pub(crate) fn picture_and_sound(rate: FrameRate) -> Document {
picture_and_sound_cut(rate, 50, 10, (10, 205))
}
/// 16-bit PCM: `frames` frames of `channels` channels, every sample different from its neighbours.
pub(crate) fn pcm_ramp(frames: usize, channels: usize, seed: i32) -> Vec<u8> {
(0..frames * channels).flat_map(|i| ((i as i32 * 37 + seed * 1000) as i16).to_le_bytes()).collect()
}
/// "S" at 25 fps, sound only: A1 holds two 50-frame clips of `a.wav` (from source frames 10 and
/// 300) with a 10-frame crossfade centred on the cut; the first clip is 6 dB up. The sound is
/// embedded when `embedded` is given (480 frames of 16-bit stereo).
pub(crate) fn sound_only(embedded: Option<Vec<u8>>) -> Document {
let rate = FrameRate::FPS_25;
let mut s = source("item:1", "/m/a.wav", CKind::Sound, rate, 16, None);
if let Some(pcm) = embedded {
s.path = None;
s.length = Tick::from_units((pcm.len() / 4) as i64, 48_000);
s.embedded = Some(pcm);
}
let mut items = two_clips(rate, 0, 50, 10, (10, 300), "constant_power");
if let Some(CItem::Clip(c)) = items.first_mut() {
c.gain = Some(Gain::Constant(10f64.powf(6.0 / 20.0)));
}
Document { compositions: vec![composition("S", rate, vec![track(CKind::Sound, "A1", 1, items)])], sources: vec![s], nested: Vec::new() }
}
+16
View File
@@ -0,0 +1,16 @@
[package]
name = "craft-aep"
description = "After Effects projects: the .aep (RIFX 'Egg!') and .aepx container as a lossless chunk tree with a typed, read-only view (compositions, layers, properties, keyframes, effects, masks, shapes, text, footage), bounded on hostile input"
version.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true
repository.workspace = true
[lints]
workspace = true
# The tool's own tests run with the crate's (examples are only built by default).
[[example]]
name = "stubicc"
test = true
+104
View File
@@ -0,0 +1,104 @@
# craft-aep
After Effects projects (`.aep`, `.aepx`): the container as a lossless chunk tree, and a typed,
read-only view of what it holds. Bytes in, a neutral model out, and the tree back to bytes.
Mapping the view onto an application's document (which effect becomes which, units, what is
reported as lost) stays in the application.
No file access: callers pass bytes, so the crate builds for wasm32. No dependencies.
| Form | Read | Write |
|---|---|---|
| `.aep` (RIFX `Egg!`) | chunk tree and typed view | the chunk tree, byte for byte |
| `.aepx` (XML) | into the same chunk tree | no |
## Container
An `.aep` is a `RIFX` container (big-endian RIFF) with form type `Egg!`: chunks of a 4-byte id, a
big-endian `u32` size and a body padded to an even length; `LIST` chunks start with a 4-byte list
type followed by chunks. `parse` builds the tree, `write` serialises it, and for every input that
parses, `write(parse(x)) == x` byte for byte (container and chunk sizes are recomputed from the
tree; pad bytes, odd bodies and the bytes after the container, an XMP packet, are kept).
The XML form of a project (`.aepx`) is read into the same tree by `read_aepx` (a small bounded
XML tokenizer of its own); `parse_any` picks the reader by content, so the typed view takes
either form. The mapping is in [`docs/aep-format.md`](docs/aep-format.md), section 1.
A reader that only looks does not need the owned tree. `TreeIndex` is the same tree as one flat,
read-only array in depth-first order, borrowed from the input: `TreeIndex::parse` for an `.aep`,
`index_aepx` and `TreeIndex::from_drafts` for an `.aepx` (decoded into one buffer first). It
counts the same chunks against the same `Limits` and returns the same errors as `parse`, and the
typed view reads through either (`Project::new` for the owned tree, `Project::from_index` for the
index). An importer should use the index; it is about twice as fast and allocates far less.
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
input, nesting and chunk count are bounded (`Limits`), nothing is allocated from a declared size,
and truncated or damaged files return `Err` (or, inside the container, an opaque body).
## Typed view
The container layer decodes no chunk body. On top of it, a typed view (`Project`, `Item`, `Comp`,
`Layer`, `Property`, ...) reads the fields whose layout was verified against the values the test
files were made with: layer and composition headers (switches, exact times and time stretch, size,
frame rate, work area, shutter phase, display start, renderer), static transform values in After
Effects' units with the "absent = default" rule, keyframe records (interpolation sides, ease per
component, plain and spatial templates), Time Remapping, expressions with their enable switch,
effect instances and parameter values (with the settings data of Curves, Levels, Hue/Saturation,
Cryptomatte, EXtractoR, IDentifier and Puppet meshes), masks and bezier paths with tangents, shape
layer groups, text documents (paragraph and style runs, box, justification, tracking, faux styles,
caps, leading), markers with duration, strings and cue data, cameras and lights with their
options, track mattes, project settings and the working space's name, the version that saved the
file, footage (stills, audio, image sequences, the layer of a Photoshop file an item shows), solids
and precomp links. Every accessor returns
`Option` or an empty list on damaged data and never panics. Which fields are verified, which are
not decoded, and how it was found is in [`docs/aep-format.md`](docs/aep-format.md).
Writing a project from an application's document (building every chunk in code) is not here: it
is EffectCraft's exporter, which is written against EffectCraft's own model.
## Specifications
Public specifications used for parts the format embeds:
- ICC.1:2010: the profile description of a working-space profile (a v2 `desc` or a v4 `mluc`
tag), from which the working space's name is read (`settings.rs`).
- RFC 4648 (base64): the profile data in the project's colour settings JSON.
## Clean room
Everything here comes from our own observations: project files that we generated ourselves with
After Effects, one change per file, compared byte by byte. No source code or format
documentation of another `.aep` reader or writer was used, and no Adobe asset is used.
## Tests
The unit tests and the robustness tests build their input in code. The tests of the typed view
read generated projects (own test data): a few combined projects, one composition per case
([`tests/fixtures/CASES.md`](tests/fixtures/CASES.md)). They are not in this repository but in
[storytold/effectcraft-corpus](https://github.com/storytold/effectcraft-corpus), with their
attribution, the generation notes and the inspection of their embedded content.
`tests/fixtures/corpus.lock` pins the commit and lists the SHA-256 of every file used. To run
against them:
```sh
git clone https://github.com/storytold/effectcraft-corpus.git
git -C effectcraft-corpus checkout <commit from corpus.lock>
CRAFT_AEP_FIXTURES=$PWD/effectcraft-corpus/aep CRAFT_AEP_FIXTURES_REQUIRED=1 cargo test -p craft-aep
```
The tests reach the projects only through `tests/it/common/mod.rs`, which hands a test its case
as a project of its own cut from the combined file. Without `CRAFT_AEP_FIXTURES` such a test
prints `SKIPPED: fixture <name> missing` and passes; with `CRAFT_AEP_FIXTURES_REQUIRED` set, a
missing project fails it.
## Tools
- `examples/aepdump.rs`: prints the chunk tree of a file (ids, sizes, short data, match names):
`cargo run -p craft-aep --example aepdump -- file.aep`.
- `examples/stubicc.rs`: replaces every embedded ICC profile of a saved project by a stub that
keeps only the profile's description: the JSON `colorProfileData` of the working space in an
`.aep` chunk or the `.aepx` text, and a raw profile of an imported image:
`cargo run -p craft-aep --example stubicc -- in.aep out.aep`. A profile it cannot replace stops
it before anything is written. Use it before a generated project becomes test data, so no
vendor colour data stays in it, and check the result independently.
File diff suppressed because it is too large Load Diff
+75
View File
@@ -0,0 +1,75 @@
//! Developer tool: prints the chunk tree of an .aep (ids, sizes, short data), match names inline.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
use craft_aep::{Body, Chunk};
/// Ends this developer tool with a message instead of a panic.
trait OrExit<T> {
fn or_exit(self, what: &str) -> T;
}
impl<T> OrExit<T> for Option<T> {
fn or_exit(self, what: &str) -> T {
match self {
Some(v) => v,
None => exit(what),
}
}
}
impl<T, E: std::fmt::Debug> OrExit<T> for Result<T, E> {
fn or_exit(self, what: &str) -> T {
match self {
Ok(v) => v,
Err(e) => exit(&format!("{what}: {e:?}")),
}
}
}
fn exit(msg: &str) -> ! {
eprintln!("{msg}");
std::process::exit(1)
}
fn show(c: &Chunk<'_>, depth: usize, max: usize, hex: usize) {
let ind = " ".repeat(depth);
let id = String::from_utf8_lossy(&c.id).to_string();
match &c.body {
Body::Data(d) if &c.id == b"tdmn" => {
let n: String = d.iter().take_while(|b| **b != 0).map(|b| *b as char).collect();
println!("{ind}tdmn {n}");
}
Body::Data(d) => {
let h: String = d.iter().take(hex).map(|b| format!("{b:02x}")).collect();
let a: String = d.iter().take(hex).map(|b| if (32..127).contains(b) { *b as char } else { '.' }).collect();
println!("{ind}{id} [{}] {h} |{a}|", d.len());
}
Body::Chunks(k) => {
println!("{ind}{id} (nested)");
if depth < max {
for x in k {
show(x, depth + 1, max, hex);
}
}
}
Body::List { list_type, children } => {
println!("{ind}LIST {} ({} children)", String::from_utf8_lossy(list_type), children.len());
if depth < max {
for x in children {
show(x, depth + 1, max, hex);
}
}
}
Body::OpaqueList { list_type, data } => println!("{ind}LIST {} opaque [{}]", String::from_utf8_lossy(list_type), data.len()),
}
}
fn main() {
let a: Vec<String> = std::env::args().collect();
let bytes = std::fs::read(a.get(1).or_exit("usage: see the comment at the top of this file")).or_exit("read");
let max: usize = a.get(2).and_then(|s| s.parse().ok()).unwrap_or(4);
let hex: usize = a.get(3).and_then(|s| s.parse().ok()).unwrap_or(32);
let f = craft_aep::parse(&bytes).or_exit("parse");
for c in &f.chunks {
show(c, 0, max, hex);
}
println!("trailer {} bytes", f.trailer.len());
}
+360
View File
@@ -0,0 +1,360 @@
//! Developer tool: replaces every embedded ICC profile of an .aep / .aepx by a stub that keeps only the
//! profile's description. Fixture hygiene: a saved project carries the vendor's working-space profile
//! (a few KB of colour data); the importer reads only the profile's name, the `desc` tag, so the stub
//! (a 128-byte header, one `desc` tag, no colour data, made here) imports identically.
//!
//! `cargo run -p craft-aep --example stubicc -- in.aep out.aep`
//!
//! It handles:
//! - the JSON value `"colorProfileData": "<base64>"` in any chunk of an .aep and anywhere in the text
//! of an .aepx (white space around the colon, `\/` escapes and quotes written as `&quot;` allowed);
//! - a raw ICC profile stored as a chunk of its own (the profile of an imported image), in an .aep
//! as the chunk's bytes and in an .aepx as its `bdata="<hex>"` attribute.
//!
//! A profile it cannot replace (no readable description, data that does not decode) stops the tool
//! before anything is written. Check the result independently (the corpus has
//! `tools/aep/inspect-embedded.py`), not by this tool's own count.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
use craft_aep::{Body, Chunk};
const B64: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/// Ends this developer tool with a message instead of a panic.
trait OrExit<T> {
fn or_exit(self, what: &str) -> T;
}
impl<T> OrExit<T> for Option<T> {
fn or_exit(self, what: &str) -> T {
match self {
Some(v) => v,
None => exit(what),
}
}
}
impl<T, E: std::fmt::Debug> OrExit<T> for Result<T, E> {
fn or_exit(self, what: &str) -> T {
match self {
Ok(v) => v,
Err(e) => exit(&format!("{what}: {e:?}")),
}
}
}
fn exit(msg: &str) -> ! {
eprintln!("{msg}");
std::process::exit(1)
}
fn b64_decode(text: &[u8]) -> Option<Vec<u8>> {
let (mut out, mut acc, mut bits) = (Vec::new(), 0u32, 0u32);
for &c in text.iter().filter(|c| **c != b'=') {
let v = u32::try_from(B64.iter().position(|b| *b == c)?).ok()?;
acc = (acc << 6 | v) & 0x00ff_ffff;
bits += 6;
if bits >= 8 {
bits -= 8;
out.push(((acc >> bits) & 0xff) as u8);
}
}
Some(out)
}
fn b64_encode(data: &[u8]) -> Vec<u8> {
let mut out = Vec::new();
for ch in data.chunks(3) {
let at = |i: usize| u32::from(ch.get(i).copied().unwrap_or(0));
let n = (at(0) << 16) | (at(1) << 8) | at(2);
for i in 0..4usize {
if i <= ch.len() {
out.push(B64.get(((n >> (18 - 6 * i)) & 63) as usize).copied().unwrap_or(b'A'));
} else {
out.push(b'=');
}
}
}
out
}
fn be32(d: &[u8], at: usize) -> Option<usize> {
let b: [u8; 4] = d.get(at..at.checked_add(4)?)?.try_into().ok()?;
usize::try_from(u32::from_be_bytes(b)).ok()
}
/// The profile description (ICC.1 `desc`: v2 ASCII or v4 `mluc`, first record).
fn description(icc: &[u8]) -> Option<String> {
let count = be32(icc, 128)?;
let tag = (0..count.min(1024)).find_map(|i| {
let at = 132usize.checked_add(i.checked_mul(12)?)?;
(icc.get(at..at.checked_add(4)?)? == b"desc").then_some(at)
})?;
let off = be32(icc, tag.checked_add(4)?)?;
let body = icc.get(off..off.checked_add(be32(icc, tag.checked_add(8)?)?)?)?;
let text = match body.get(..4)? {
b"desc" => {
let n = be32(body, 8)?;
String::from_utf8_lossy(body.get(12..12usize.checked_add(n)?)?.split(|b| *b == 0).next()?).into_owned()
}
b"mluc" => {
let (n, at) = (be32(body, 20)?, be32(body, 24)?);
let units: Vec<u16> =
body.get(at..at.checked_add(n)?)?.chunks(2).filter_map(|p| Some(u16::from_be_bytes([*p.first()?, *p.get(1)?]))).collect();
String::from_utf16_lossy(&units)
}
_ => return None,
};
Some(text.trim_end_matches('\0').trim().to_owned())
}
/// A profile with a header, one `desc` tag and no colour data.
fn stub(desc: &str) -> Option<Vec<u8>> {
let mut body = b"desc\0\0\0\0".to_vec();
body.extend_from_slice(&u32::try_from(desc.len().checked_add(1)?).ok()?.to_be_bytes());
body.extend_from_slice(desc.as_bytes());
body.push(0);
body.extend_from_slice(&[0; 4 + 4 + 2 + 1 + 67]);
let mut p = vec![0u8; 128];
for (at, v) in [(8, &0x0240_0000u32.to_be_bytes()[..]), (12, b"mntr"), (16, b"RGB "), (20, b"XYZ "), (36, b"acsp")] {
p.get_mut(at..at + v.len())?.copy_from_slice(v);
}
p.extend_from_slice(&1u32.to_be_bytes());
p.extend_from_slice(b"desc");
p.extend_from_slice(&144u32.to_be_bytes());
p.extend_from_slice(&u32::try_from(body.len()).ok()?.to_be_bytes());
p.extend_from_slice(&body);
let size = u32::try_from(p.len()).ok()?.to_be_bytes();
p.get_mut(..4)?.copy_from_slice(&size);
Some(p)
}
/// The JSON key, without its quotes.
const KEY: &[u8] = b"colorProfileData";
/// How a JSON quote is written: as is (a `Utf8` chunk, the `<string>` text of an .aepx) and as an
/// XML entity (JSON inside an attribute of an .aepx).
const QUOTES: [&[u8]; 2] = [b"\"", b"&quot;"];
/// What the tool did, counted.
#[derive(Default)]
struct Tally {
stubbed: usize,
/// Values too short to be a profile (no ICC header), kept as they are.
kept_short: usize,
/// Profiles that could not be replaced (no readable description, undecodable data): the tool
/// fails, so no profile is ever left behind silently.
failed: Vec<String>,
}
fn is_profile(d: &[u8]) -> bool {
d.len() > 132 && d.get(36..40) == Some(b"acsp")
}
/// The stub for the bytes `d` of a value, or `None` (counted) when it holds no profile or the
/// profile has no readable description.
fn stub_of(d: &[u8], at: usize, tally: &mut Tally) -> Option<Vec<u8>> {
if !is_profile(d) {
tally.kept_short += 1;
return None;
}
let s = description(d).and_then(|t| stub(&t));
if s.is_none() {
tally.failed.push(format!("profile at byte {at}: no readable description"));
}
s
}
/// At the start of `t`: the key in quotes, optional white space, a colon, optional white space and
/// the opening quote of the value. Returns the length up to and including that quote, and the quote.
fn value_start(t: &[u8]) -> Option<(usize, &'static [u8])> {
let ws = |mut i: usize| {
while t.get(i).is_some_and(u8::is_ascii_whitespace) {
i += 1;
}
i
};
QUOTES.into_iter().find_map(|q| {
let key_end = q.len().checked_mul(2)?.checked_add(KEY.len())?;
let quoted = t.get(..key_end)?;
if !(quoted.starts_with(q) && quoted.get(q.len()..q.len() + KEY.len())? == KEY && quoted.ends_with(q)) {
return None;
}
let colon = ws(key_end);
if t.get(colon) != Some(&b':') {
return None;
}
let open = ws(colon + 1);
t.get(open..)?.starts_with(q).then_some((open + q.len(), q))
})
}
fn hex_decode(h: &[u8]) -> Option<Vec<u8>> {
if !h.len().is_multiple_of(2) {
return None;
}
h.chunks(2).map(|p| u8::from_str_radix(std::str::from_utf8(p).ok()?, 16).ok()).collect()
}
fn hex_encode(d: &[u8], upper: bool) -> Vec<u8> {
d.iter().flat_map(|b| if upper { format!("{b:02X}") } else { format!("{b:02x}") }.into_bytes()).collect()
}
/// Replaces, in `text`, every `colorProfileData` JSON value (base64; `\/` escapes, white space
/// around the colon and quotes written as `&quot;` allowed) and every .aepx `bdata="<hex>"`
/// attribute that holds a raw profile.
fn stub_text(text: &[u8], tally: &mut Tally) -> Vec<u8> {
const BDATA: &[u8] = b"bdata=\"";
let (mut out, mut i) = (Vec::with_capacity(text.len()), 0);
while let Some(&b) = text.get(i) {
let rest = text.get(i..).unwrap_or_default();
if let Some((open, q)) = value_start(rest)
&& let Some(len) = rest.get(open..).and_then(|v| v.windows(q.len()).position(|w| w == q))
{
let raw = rest.get(open..open + len).unwrap_or_default();
let unescaped: Vec<u8> = raw.iter().copied().filter(|c| *c != b'\\').collect();
let replaced = match b64_decode(&unescaped) {
Some(d) => stub_of(&d, i, tally).map(|s| b64_encode(&s)),
None => {
tally.failed.push(format!("colorProfileData at byte {i}: not base64"));
None
}
};
out.extend_from_slice(rest.get(..open).unwrap_or_default());
match replaced {
Some(enc) => {
out.extend_from_slice(&enc);
tally.stubbed += 1;
}
None => out.extend_from_slice(raw),
}
i += open + len;
continue;
}
if rest.starts_with(BDATA)
&& let Some(len) = rest.get(BDATA.len()..).and_then(|v| v.iter().position(|c| *c == b'"'))
{
let hex = rest.get(BDATA.len()..BDATA.len() + len).unwrap_or_default();
let replaced = hex_decode(hex).filter(|d| is_profile(d)).and_then(|d| stub_of(&d, i, tally));
out.extend_from_slice(BDATA);
match replaced {
Some(s) => {
out.extend_from_slice(&hex_encode(&s, hex.iter().any(u8::is_ascii_uppercase)));
tally.stubbed += 1;
}
None => out.extend_from_slice(hex),
}
i += BDATA.len() + len;
continue;
}
out.push(b);
i += 1;
}
out
}
fn walk(chunks: &mut [Chunk<'_>], tally: &mut Tally) {
for c in chunks.iter_mut() {
// Only a data chunk is rewritten as one: an opaque `LIST` also has bytes, but replacing it by
// a data chunk would drop its list type.
let data = if let Body::Data(d) = &c.body { Some(d.to_vec()) } else { None };
match data {
Some(d) if d.windows(KEY.len()).any(|w| w == KEY) => {
let new = stub_text(&d, tally);
*c = Chunk::data(c.id, new);
}
Some(d) if is_profile(&d) => {
if let Some(s) = stub_of(&d, 0, tally) {
*c = Chunk::data(c.id, s);
tally.stubbed += 1;
}
}
_ => {
if let Body::List { children, .. } | Body::Chunks(children) = &mut c.body {
walk(children, tally);
}
}
}
}
}
fn main() {
let args: Vec<String> = std::env::args().collect();
let (Some(input), Some(output)) = (args.get(1), args.get(2)) else { exit("usage: stubicc <in.aep|in.aepx> <out>") };
let bytes = std::fs::read(input).or_exit("read the input");
let mut tally = Tally::default();
let out = if input.ends_with(".aepx") {
stub_text(&bytes, &mut tally)
} else {
let mut file = craft_aep::parse(&bytes).or_exit("parse the input");
walk(&mut file.chunks, &mut tally);
craft_aep::write(&file).or_exit("write the output")
};
if !tally.failed.is_empty() {
exit(&format!("nothing written: {} profile(s) could not be replaced:\n{}", tally.failed.len(), tally.failed.join("\n")));
}
std::fs::write(output, out).or_exit("write the output");
println!("stubbed {} profile(s); kept {} short value(s) that hold no profile", tally.stubbed, tally.kept_short);
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
fn profile(desc: &str) -> Vec<u8> {
// A profile with colour data after the description (like a real one): the stub of `desc`
// plus 3000 bytes, its size field updated.
let mut p = stub(desc).unwrap();
p.extend(std::iter::repeat_n(0x5a, 3000));
let size = u32::try_from(p.len()).unwrap().to_be_bytes();
p[..4].copy_from_slice(&size);
p
}
fn stubbed(text: &[u8]) -> (Vec<u8>, Tally) {
let mut tally = Tally::default();
(stub_text(text, &mut tally), tally)
}
#[test]
fn json_values_in_every_spelling_are_replaced() {
let b64 = String::from_utf8(b64_encode(&profile("sRGB IEC61966-2.1"))).unwrap();
let want = String::from_utf8(b64_encode(&stub("sRGB IEC61966-2.1").unwrap())).unwrap();
for (before, after) in [
(format!("{{\"colorProfileData\":\"{b64}\"}}"), format!("{{\"colorProfileData\":\"{want}\"}}")),
(format!("{{\"colorProfileData\" : \n\t\"{b64}\"}}"), format!("{{\"colorProfileData\" : \n\t\"{want}\"}}")),
(format!("{{\"colorProfileData\":\"{}\"}}", b64.replace('/', "\\/")), format!("{{\"colorProfileData\":\"{want}\"}}")),
(format!("{{&quot;colorProfileData&quot;: &quot;{b64}&quot;}}"), format!("{{&quot;colorProfileData&quot;: &quot;{want}&quot;}}")),
] {
let (out, tally) = stubbed(before.as_bytes());
assert_eq!(String::from_utf8(out).unwrap(), after);
assert_eq!((tally.stubbed, tally.failed.len()), (1, 0));
}
}
#[test]
fn a_raw_profile_in_aepx_hex_is_replaced_and_other_hex_kept() {
let hex = String::from_utf8(hex_encode(&profile("Rec.709 Gamma 2.4"), false)).unwrap();
let want = String::from_utf8(hex_encode(&stub("Rec.709 Gamma 2.4").unwrap(), false)).unwrap();
let text = format!("<icc bdata=\"{hex}\"/><PwCs bdata=\"01\"/><cdta bdata=\"{}\"/>", "ab".repeat(200));
let (out, tally) = stubbed(text.as_bytes());
assert_eq!(String::from_utf8(out).unwrap(), format!("<icc bdata=\"{want}\"/><PwCs bdata=\"01\"/><cdta bdata=\"{}\"/>", "ab".repeat(200)));
assert_eq!((tally.stubbed, tally.failed.len()), (1, 0));
// Upper-case hex stays upper case.
let (out, _) = stubbed(format!("bdata=\"{}\"", hex.to_uppercase()).as_bytes());
assert_eq!(String::from_utf8(out).unwrap(), format!("bdata=\"{}\"", want.to_uppercase()));
}
#[test]
fn a_profile_that_cannot_be_replaced_is_a_failure_not_a_silent_copy() {
// An ICC header whose tag table has no `desc`.
let mut p = profile("x");
p[132..136].copy_from_slice(b"wtpt");
let (_, tally) = stubbed(format!("\"colorProfileData\":\"{}\"", String::from_utf8(b64_encode(&p)).unwrap()).as_bytes());
assert_eq!((tally.stubbed, tally.failed.len()), (0, 1));
let (_, tally) = stubbed(b"\"colorProfileData\":\"not*base64\"");
assert_eq!(tally.failed.len(), 1);
// A short value holds no profile: kept and counted, not a failure.
let (out, tally) = stubbed(b"\"colorProfileData\":\"AAAA\"");
assert_eq!((out.as_slice(), tally.kept_short, tally.failed.len()), (&b"\"colorProfileData\":\"AAAA\""[..], 1, 0));
}
}
File diff suppressed because it is too large Load Diff
+362
View File
@@ -0,0 +1,362 @@
//! 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::chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS};
use crate::error::AepError;
use crate::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))
}
+554
View File
@@ -0,0 +1,554 @@
//! Arbitrary-data effect parameters (type 11): the values of Hue/Saturation and Levels that are not
//! ordinary parameters.
//!
//! In the effect's value group (`sspc/tdgp`) the parameter's `tdbs` (`tdsb` 1, a 4-byte `cdat`) is
//! followed by a `LIST aRbs` holding one `aRbp`: the data. The `aRbp` in `parT` right after the
//! parameter's `pard` holds the default (443, 511). Setting Master Hue, Saturation or Lightness of
//! 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::bytes::{be_f32, be_i32, be_u16, be_u32};
use crate::effects::Effect;
use crate::index::Node;
impl<'f, 'a> Effect<'f, 'a> {
/// The arbitrary data stored for the parameter with this match name (`<effect>-NNNN`): the
/// `aRbp` of the `LIST aRbs` that follows the parameter's value record. `None` when there is
/// none.
pub fn arbitrary_data(&self, match_name: &str) -> Option<&'f [u8]> {
let values = self.chunk().child_list(b"tdgp")?;
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(Node::bytes)
}
}
fn name_is(body: &[u8], name: &str) -> bool {
let end = body.iter().position(|c| *c == 0).unwrap_or(body.len());
body.get(..end) == Some(name.as_bytes())
}
/// Hue/Saturation's data (180 bytes, `ADBE HUE SATURATION-0003`): the master hue, saturation and
/// lightness as `i32` at bytes 0, 4 and 8 (444: hue 90 is `0x5a`; 445: saturation 50; 446:
/// lightness -30), then six colour ranges (Reds, Yellows, Greens, Cyans, Blues, Magentas) of 28
/// bytes each: four `i32` range points in degrees (Reds 315, 345, 15, 45 by default) and the
/// range's hue, saturation and lightness. Only the master values are sampled; the ranges' layout is
/// read from the default data.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct HueSaturationData {
/// Master hue (degrees), saturation and lightness (-100..100).
pub master: [i32; 3],
/// Per colour range: the four range points (degrees) and its hue, saturation and lightness.
pub ranges: [([i32; 4], [i32; 3]); 6],
}
impl HueSaturationData {
/// The default data (443): master 0, 0, 0 and every range at its default points.
pub const DEFAULT_RANGES: [[i32; 4]; 6] =
[[315, 345, 15, 45], [15, 45, 75, 105], [75, 105, 135, 165], [135, 165, 195, 225], [195, 225, 255, 285], [255, 285, 315, 345]];
/// Decodes the data; `None` when it is not 180 bytes.
pub fn parse(data: &[u8]) -> Option<Self> {
if data.len() != 180 {
return None;
}
let i = |at: usize| be_i32(data, at);
let master = [i(0)?, i(4)?, i(8)?];
let mut ranges = [([0; 4], [0; 3]); 6];
for (k, r) in ranges.iter_mut().enumerate() {
let base = 12usize.checked_add(k.checked_mul(28)?)?;
r.0 = [i(base)?, i(base + 4)?, i(base + 8)?, i(base + 12)?];
r.1 = [i(base + 16)?, i(base + 20)?, i(base + 24)?];
}
Some(Self { master, ranges })
}
/// Whether every colour range is at its default (points as in 443, no adjustment).
pub fn ranges_are_default(&self) -> bool {
self.ranges.iter().zip(Self::DEFAULT_RANGES).all(|((points, hsl), d)| *points == d && *hsl == [0, 0, 0])
}
}
/// Levels' data (108 bytes, `ADBE Easy Levels2-0002`): a `u32` 0x000f10a7 and a `u32` 1 (511, in
/// every sample), then five channels (RGB, Red, Green, Blue, Alpha) of five `f32`: input black,
/// input white, gamma, output black, output white. The RGB values are sampled (512 input black
/// 0.1, 513 input white 0.8, 514 gamma 2, 515 output black 0.2, 516 output white 0.9); the other
/// channels' layout is read from the default data (0, 1, 1, 0, 1).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LevelsData {
pub header: [u32; 2],
/// RGB, Red, Green, Blue, Alpha: input black, input white, gamma, output black, output white.
pub channels: [[f32; 5]; 5],
}
impl LevelsData {
/// The values of a channel at its default.
pub const DEFAULT_CHANNEL: [f32; 5] = [0.0, 1.0, 1.0, 0.0, 1.0];
/// Decodes the data; `None` when it is not 108 bytes.
pub fn parse(data: &[u8]) -> Option<Self> {
if data.len() != 108 {
return None;
}
let header = [be_u32(data, 0)?, be_u32(data, 4)?];
let mut channels = [[0.0; 5]; 5];
for (k, c) in channels.iter_mut().enumerate() {
let base = 8usize.checked_add(k.checked_mul(20)?)?;
for (j, v) in c.iter_mut().enumerate() {
*v = be_f32(data, base.checked_add(j.checked_mul(4)?)?)?;
}
}
Some(Self { header, channels })
}
}
/// Curves' data (1644 bytes, `ADBE CurvesCustom-0001`; FORMAT S.1, 961-964): `u16` 1, `u16` 1,
/// five 256-byte lookup tables (RGB, Red, Green, Blue, Alpha: output 0..255 per input 0..255),
/// then five 72-byte point records: 16 slots of (`u16` input, `u16` output), both 0..255, the
/// number of points as `u32` at 64 and an `i32` at 68 (-1 at the default; the point count - 2 in
/// every edited sample, H: the active point). Every stored table is the natural cubic spline
/// through its points ([`curve_lut`]).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CurvesData {
/// RGB, Red, Green, Blue, Alpha: the points (input, output), as stored.
pub curves: [Vec<(u8, u8)>; 5],
}
/// The points of an untouched curve.
pub const CURVE_IDENTITY: [(u8, u8); 2] = [(0, 0), (255, 255)];
impl CurvesData {
pub const SIZE: usize = 1644;
const POINTS: usize = 1284;
/// Decodes the data; `None` when it is not 1644 bytes or a point count is beyond 16.
pub fn parse(data: &[u8]) -> Option<Self> {
if data.len() != Self::SIZE {
return None;
}
let mut curves: [Vec<(u8, u8)>; 5] = Default::default();
for (c, pts) in curves.iter_mut().enumerate() {
let base = Self::POINTS.checked_add(c.checked_mul(72)?)?;
let n = usize::try_from(be_u32(data, base.checked_add(64)?)?).ok()?;
if n > 16 {
return None;
}
for k in 0..n {
let at = base.checked_add(k.checked_mul(4)?)?;
let x = u8::try_from(be_u16(data, at)?).ok()?;
let y = u8::try_from(be_u16(data, at.checked_add(2)?)?).ok()?;
pts.push((x, y));
}
}
Some(Self { curves })
}
/// Whether every curve is the identity.
pub fn is_default(&self) -> bool {
self.curves.iter().all(|c| c.as_slice() == CURVE_IDENTITY)
}
/// The data After Effects stores for these curves: the tables rebuilt from the points.
/// `None` when a curve has fewer than 2 or more than 16 points or inputs that do not rise.
pub fn to_bytes(&self) -> Option<Vec<u8>> {
let mut out = vec![0u8; Self::SIZE];
out.get_mut(0..4)?.copy_from_slice(&[0, 1, 0, 1]);
for (c, pts) in self.curves.iter().enumerate() {
if pts.len() > 16 {
return None;
}
let lut = curve_lut(pts)?;
out.get_mut(4 + 256 * c..4 + 256 * (c + 1))?.copy_from_slice(&lut);
let base = Self::POINTS + 72 * c;
for (k, (x, y)) in pts.iter().enumerate() {
out.get_mut(base + 4 * k..base + 4 * k + 4)?.copy_from_slice(&[0, *x, 0, *y]);
}
let n = u32::try_from(pts.len()).ok()?;
out.get_mut(base + 64..base + 68)?.copy_from_slice(&n.to_be_bytes());
let active: i32 = if pts.as_slice() == CURVE_IDENTITY { -1 } else { i32::try_from(pts.len()).ok()? - 2 };
out.get_mut(base + 68..base + 72)?.copy_from_slice(&active.to_be_bytes());
}
Some(out)
}
}
fn rising(points: &[(u8, u8)]) -> bool {
points.windows(2).all(|w| matches!(w, [a, b] if a.0 < b.0))
}
/// The lookup table After Effects stores for a curve: the natural cubic spline (second derivative
/// 0 at both ends) through the points, at the integers 0..255, rounded to the nearest integer and
/// clamped to 0..255; flat outside the first and last point (961-964: 0 of 1280 entries differ).
/// `None` for fewer than 2 points or inputs that do not rise.
pub fn curve_lut(points: &[(u8, u8)]) -> Option<[u8; 256]> {
let n = points.len();
if n < 2 || !rising(points) {
return None;
}
let xs: Vec<f64> = points.iter().map(|p| f64::from(p.0)).collect();
let ys: Vec<f64> = points.iter().map(|p| f64::from(p.1)).collect();
let x = |i: usize| xs.get(i).copied().unwrap_or(0.0);
let y = |i: usize| ys.get(i).copied().unwrap_or(0.0);
let h = |i: usize| (x(i + 1) - x(i)).max(1.0);
let slope = |i: usize| (y(i + 1) - y(i)) / h(i);
// Second derivatives: the tridiagonal system of the natural spline (Thomas algorithm).
let mut m = vec![0.0f64; n];
let k = n - 2;
if k > 0 {
let mut diag: Vec<f64> = (0..k).map(|i| 2.0 * (h(i) + h(i + 1))).collect();
let upper: Vec<f64> = (0..k).map(|i| h(i + 1)).collect();
let mut rhs: Vec<f64> = (0..k).map(|i| 6.0 * (slope(i + 1) - slope(i))).collect();
for i in 1..k {
let (Some(&dp), Some(&up), Some(&rp)) = (diag.get(i - 1), upper.get(i - 1), rhs.get(i - 1)) else { return None };
let w = h(i) / dp;
if let (Some(d), Some(r)) = (diag.get_mut(i), rhs.get_mut(i)) {
*d -= w * up;
*r -= w * rp;
}
}
for i in (0..k).rev() {
let next = m.get(i + 2).copied().unwrap_or(0.0);
let (Some(&r), Some(&u), Some(&d)) = (rhs.get(i), upper.get(i), diag.get(i)) else { return None };
if let Some(slot) = m.get_mut(i + 1) {
*slot = (r - u * next) / d;
}
}
}
let mut lut = [0u8; 256];
for (xi, slot) in lut.iter_mut().enumerate() {
let xf = xi as f64;
let v = if xf <= x(0) {
y(0)
} else if xf >= x(n - 1) {
y(n - 1)
} else {
let i = (0..n - 1).find(|&i| xf >= x(i) && xf <= x(i + 1)).unwrap_or(0);
let hh = h(i);
let (a, b) = ((x(i + 1) - xf) / hh, (xf - x(i)) / hh);
let (mi, mj) = (m.get(i).copied().unwrap_or(0.0), m.get(i + 1).copied().unwrap_or(0.0));
a * y(i) + b * y(i + 1) + ((a * a * a - a) * mi + (b * b * b - b) * mj) * hh * hh / 6.0
};
*slot = (v + 0.5).floor().clamp(0.0, 255.0) as u8;
}
Some(lut)
}
/// Mesh Warp's data (`ADBE MESH WARP-0004`; FORMAT S.2, 965, 985): `u32` rows plus one, `u32`
/// columns plus one (a 1 x 2-cell read-back test renders as made only in this order, `export-tests\mesh`;
/// the vertices run row-major, columns plus one per row), 12 more bytes (zero, then
/// `0d 0d`),
/// then per vertex, row-major, ten `f32`: the position and the handles top, right, bottom and
/// left, all as fractions 0..1 of the layer; a handle pointing out of the mesh is stored (0, 0).
#[derive(Debug, Clone, PartialEq)]
pub struct MeshData {
pub columns: u32,
pub rows: u32,
/// Bytes 8..20 as stored.
pub tail: [u8; 12],
/// Per vertex: position, top, right, bottom, left.
pub vertices: Vec<[[f32; 2]; 5]>,
}
impl MeshData {
/// Decodes the data; `None` when the size does not fit the grid or the grid is beyond 31 x 31
/// cells.
pub fn parse(data: &[u8]) -> Option<Self> {
let (r1, c1) = (be_u32(data, 0)?, be_u32(data, 4)?);
if !(2..=32).contains(&c1) || !(2..=32).contains(&r1) {
return None;
}
let count = usize::try_from(c1.checked_mul(r1)?).ok()?;
if data.len() != 20usize.checked_add(count.checked_mul(40)?)? {
return None;
}
let mut tail = [0u8; 12];
tail.copy_from_slice(data.get(8..20)?);
let mut vertices = Vec::with_capacity(count);
for v in 0..count {
let base = 20 + 40 * v;
let mut rec = [[0.0f32; 2]; 5];
for (j, p) in rec.iter_mut().enumerate() {
*p = [be_f32(data, base + 8 * j)?, be_f32(data, base + 8 * j + 4)?];
}
vertices.push(rec);
}
Some(Self { columns: c1 - 1, rows: r1 - 1, tail, vertices })
}
/// The vertex at column `i`, row `j` of an undistorted mesh with its default handles (one
/// third of a cell along the grid lines; those pointing out of the mesh are (0, 0)).
pub fn default_vertex(columns: u32, rows: u32, i: u32, j: u32) -> [[f32; 2]; 5] {
let (cw, rh) = (1.0 / f64::from(columns.max(1)), 1.0 / f64::from(rows.max(1)));
let (x, y) = (f64::from(i) * cw, f64::from(j) * rh);
let p = |dx: f64, dy: f64, out: bool| if out { [0.0, 0.0] } else { [(x + dx) as f32, (y + dy) as f32] };
[[x as f32, y as f32], p(0.0, -rh / 3.0, j == 0), p(cw / 3.0, 0.0, i == columns), p(0.0, rh / 3.0, j == rows), p(-cw / 3.0, 0.0, i == 0)]
}
/// The bytes After Effects stores for this mesh.
pub fn to_bytes(&self) -> Option<Vec<u8>> {
let count = usize::try_from(self.columns.checked_add(1)?.checked_mul(self.rows.checked_add(1)?)?).ok()?;
if self.vertices.len() != count {
return None;
}
let mut out = Vec::with_capacity(20 + 40 * count);
out.extend((self.rows + 1).to_be_bytes());
out.extend((self.columns + 1).to_be_bytes());
out.extend(self.tail);
for v in &self.vertices {
for p in v {
out.extend(p[0].to_be_bytes());
out.extend(p[1].to_be_bytes());
}
}
Some(out)
}
}
/// EXtractoR's Channel Info data (`EXtractoR-0013`, 688 bytes, the plug-in's own little-endian
/// layout; read from the instances of the importer block of 2026-11-05: the defaults and a preset
/// of our own that reads `Z` into Red, Green and Blue): a `u32` 1 and 28 bytes, then four records
/// of 164 bytes (Red, Green, Blue, Alpha), each a kind in byte 0 (1 a channel of the footage by
/// name, 2 the input's own channel: `(copy)`; bytes 1..4 are not always zero, `0x32` at 3 in one
/// definition's default, so only byte 0 is read) and the channel name from byte 35,
/// NUL-terminated. The other bytes are not read (they differ between instances with the same
/// channels; the `u32` at 4 of a chosen channel looks like its position in the footage's sorted
/// channel list, 13 of 14 for `Z`, where the defaults hold 0). Only the name is read.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExtractorChannels {
/// Per output channel (red, green, blue, alpha): the kind and the name.
pub channels: [(u32, String); 4],
}
impl ExtractorChannels {
/// The data's length.
pub const LEN: usize = 688;
const RECORD: usize = 164;
/// `None` when the data does not have this layout.
pub fn parse(data: &[u8]) -> Option<Self> {
if data.len() != Self::LEN || data.get(..4)? != 1u32.to_le_bytes() {
return None;
}
let mut channels: [(u32, String); 4] = Default::default();
for (k, slot) in channels.iter_mut().enumerate() {
let at = 32usize.checked_add(k.checked_mul(Self::RECORD)?)?;
let rec = data.get(at..at.checked_add(Self::RECORD)?)?;
let kind = u32::from(*rec.first()?);
let name = rec.get(35..)?;
let end = name.iter().position(|b| *b == 0)?;
let name = std::str::from_utf8(name.get(..end)?).ok()?;
*slot = (kind, name.to_string());
}
Some(Self { channels })
}
/// The channels of a fresh EXtractoR: Red, Green and Blue from the channels of those names,
/// Alpha copied from the input.
pub fn is_default(&self) -> bool {
let want = [(1, "R"), (1, "G"), (1, "B"), (2, "(copy)")];
self.channels.iter().zip(want).all(|((k, n), (wk, wn))| *k == wk && n == wn)
}
/// Per output channel (red, green, blue, alpha) the channel it reads, `Err` with the
/// position of the first record of another kind or without a name: a named channel by its
/// name, `(copy)` as `copy`, the caller's name for the effect input's own channel of the
/// same position. `(copy)` is not `R`, `G`, `B` or `A`: those name channels of the footage
/// file, which do not have what an earlier effect did to the channel.
pub fn sources(&self, copy: &str) -> Result<[String; 4], usize> {
let mut out: [String; 4] = Default::default();
for (k, ((kind, name), slot)) in self.channels.iter().zip(out.iter_mut()).enumerate() {
*slot = match (kind, name.trim()) {
(1, n) if !n.is_empty() => n.to_string(),
(2, _) => copy.to_string(),
_ => return Err(k),
};
}
Ok(out)
}
}
/// IDentifier's Channel Info data (`IDentifier-0005`, 148 bytes): the chosen channel's name,
/// NUL-terminated from byte 19, or `Object ID` when none is chosen (importer blocks 1300 and 1310
/// of 2026-11-05: `objectId` in a preset of our own that chose that UINT channel, `Object ID` in
/// every other instance). The bytes around it differ between instances with the same settings
/// and are not read (a chosen channel has 15 at byte 4, which looks like its position in the
/// EXR's sorted channel list, as for EXtractoR).
pub fn identifier_channel_type(data: &[u8]) -> Option<&str> {
let s = data.get(19..)?;
let end = s.iter().position(|b| *b == 0)?;
std::str::from_utf8(s.get(..end)?).ok()
}
/// The Cryptomatte plug-in's Settings data (`Cryptomatte-0001`, the plug-in's own layout,
/// little-endian; read from 88 instances of one project and from our own sample 1400, fresh
/// instances and two presets that pick a layer and an object, docs/aep-format.md 3.7): the magic
/// `cry1`; bytes 4..32 are not read (they differ between instances holding the same settings);
/// the Cryptomatte layer's name at 32, NUL-padded to 64 bytes (`CryptoObject`); at 96 a `u32` 1
/// and a `u32` (neither read); at 104 the `u32` length of the selection text including its NUL,
/// the `u32` MurmurHash3 (x86, 32-bit, seed 0) of that text with its NUL (not read) and a zero
/// byte; the selection text from byte 113 (`<11a97486>, <deadbeef>`, the matte list as ID hashes,
/// the hashes of the picked names). Bytes after it are left-overs of a longer earlier text. A
/// fresh effect stores no layer and an empty text (length 1, its NUL); the `u32`s at 100 and 108
/// are then both `0x514e28b7`, the hash of one NUL byte: the one at 100 looks like the hash of a
/// first text that is empty in every sample, the zero byte at 112 like that text.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CryptomatteData {
/// The Cryptomatte layer's name (`CryptoMaterial`: the EXR layer's name, which is also its
/// channel prefix in every sample); empty when none is chosen.
pub layer: String,
/// The selection (matte list) as the plug-in stores it.
pub selection: String,
}
impl CryptomatteData {
/// Decodes the data; `None` when it is not this layout (no `cry1`, too short, a length past
/// the end, no zero byte at 112, a text without its NUL, text that is not UTF-8).
pub fn parse(data: &[u8]) -> Option<Self> {
if data.get(..4)? != b"cry1" {
return None;
}
let text = |b: &[u8]| -> Option<String> {
let end = b.iter().position(|c| *c == 0).unwrap_or(b.len());
String::from_utf8(b.get(..end)?.to_vec()).ok()
};
let layer = text(data.get(32..96)?)?;
let len = usize::try_from(u32::from_le_bytes(data.get(104..108)?.try_into().ok()?)).ok()?;
if *data.get(112)? != 0 {
return None;
}
let selection = if len == 0 {
String::new()
} else {
// The length counts the text's NUL as its last byte: a text without it, or with an early
// NUL before more bytes (which `text` would silently cut short), is not this layout.
let b = data.get(113..113usize.checked_add(len)?)?;
let (last, text_bytes) = b.split_last()?;
if *last != 0 || text_bytes.contains(&0) {
return None;
}
text(b)?
};
Some(Self { layer, selection })
}
}
#[cfg(test)]
mod tests {
use super::CryptomatteData;
/// Settings data in the layout [`CryptomatteData::parse`] reads, with `noise` in the bytes it
/// does not read.
fn crypto(layer: &str, selection: &str, noise: u8) -> Vec<u8> {
let mut d = b"cry1".to_vec();
d.resize(32, noise);
d.extend(layer.as_bytes());
d.resize(96, 0);
d.extend(1u32.to_le_bytes());
d.extend([noise; 4]);
let len = if selection.is_empty() { 0 } else { selection.len() + 1 };
d.extend(u32::try_from(len).unwrap_or(0).to_le_bytes());
d.extend([noise; 4]);
d.push(0);
d.extend(selection.as_bytes());
d.push(0);
// Left-overs of an earlier, longer text.
d.extend(b" <de");
d
}
#[test]
fn cryptomatte_settings_are_read() {
for noise in [0, 0x5a] {
let d = CryptomatteData::parse(&crypto("Layer_A", "<0000002a>, <deadbeef>", noise));
assert_eq!(d, Some(CryptomatteData { layer: "Layer_A".into(), selection: "<0000002a>, <deadbeef>".into() }), "noise {noise}");
}
}
#[test]
fn a_selection_whose_nul_is_not_its_last_byte_is_refused() {
// An early NUL followed by more declared bytes would shorten the selection silently.
let mut d = crypto("Layer_A", "<0000002a>, <deadbeef>", 0);
d[113 + 4] = 0;
assert_eq!(CryptomatteData::parse(&d), None);
// No NUL at the end of the declared length.
let mut d = crypto("Layer_A", "<0000002a>", 0);
d[113 + 10] = b'x';
assert_eq!(CryptomatteData::parse(&d), None);
}
#[test]
fn the_default_cryptomatte_settings_are_empty() {
let mut d = b"cry1".to_vec();
d.resize(116, 0);
assert_eq!(CryptomatteData::parse(&d), Some(CryptomatteData::default()));
// What After Effects 2026 wrote for a fresh effect (plug-in 2.6.6, sample 1400
// `crypto-00-defaults`, the `pard` default and the instance's record alike): an empty text
// of length 1 and its hash, twice.
let mut fresh = b"cry1".to_vec();
fresh.resize(96, 0);
for _ in 0..2 {
fresh.extend(1u32.to_le_bytes());
fresh.extend(0x514e_28b7u32.to_le_bytes());
}
fresh.extend([0; 4]);
assert_eq!(fresh.len(), 116);
assert_eq!(CryptomatteData::parse(&fresh), Some(CryptomatteData::default()));
}
/// The Settings data After Effects 2026 wrote for the two presets of sample 1400 (plug-in
/// 2.6.6, `crypto-06-preset-object-box` and `crypto-07-preset-material-paint`: a layer chosen
/// and one object or material picked in the plug-in's UI), byte for byte: 127 bytes, the `u32`
/// at 108 the MurmurHash3 of the text with its NUL, three zero bytes after the text.
#[test]
fn the_presets_of_our_sample_are_read() {
for (layer, selection, hash) in [("CryptoObject", "<11a97486>", 0x2788_0767u32), ("CryptoMaterial", "<a5deeb9e>", 0xf737_4a5b)] {
let mut d = b"cry1".to_vec();
d.resize(32, 0);
d.extend(layer.as_bytes());
d.resize(96, 0);
for v in [1, 0x514e_28b7, 11, hash] {
d.extend(u32::to_le_bytes(v));
}
d.push(0);
d.extend(selection.as_bytes());
d.extend([0; 4]);
assert_eq!(d.len(), 127);
assert_eq!(CryptomatteData::parse(&d), Some(CryptomatteData { layer: layer.into(), selection: selection.into() }), "{layer}");
}
}
#[test]
fn damaged_cryptomatte_settings_are_not_read() {
let good = crypto("L", "<00000001>", 0);
let mut bad_magic = good.clone();
bad_magic[0] = b'x';
let mut past_end = good.clone();
past_end[104..108].copy_from_slice(&u32::MAX.to_le_bytes());
let mut no_zero = good.clone();
no_zero[112] = b'<';
let mut not_utf8 = good.clone();
not_utf8[32] = 0xff;
// The length covers the text without its NUL (`<00000001>` is 10 bytes, its NUL the 11th).
let mut no_nul = good.clone();
no_nul[104..108].copy_from_slice(&10u32.to_le_bytes());
// No zero byte at 112 with an empty text.
let mut empty_no_zero = crypto("L", "", 0);
empty_no_zero[112] = b'<';
for (what, d) in [
("magic", bad_magic),
("length", past_end),
("zero byte", no_zero),
("utf-8", not_utf8),
("no NUL", no_nul),
("empty text, zero byte", empty_no_zero),
("short", good[..100].to_vec()),
("empty", Vec::new()),
] {
assert_eq!(CryptomatteData::parse(&d), None, "{what}");
}
}
}
+50
View File
@@ -0,0 +1,50 @@
//! Bounds-checked big-endian readers shared by the typed views. Every read returns `None` when the
//! bytes are not there; nothing here indexes a slice directly.
pub(crate) fn text(b: &[u8]) -> String {
String::from_utf8_lossy(b).into_owned()
}
/// The bytes up to the first NUL (all of them when there is none).
pub(crate) fn until_nul(b: &[u8]) -> &[u8] {
let end = b.iter().position(|c| *c == 0).unwrap_or(b.len());
b.get(..end).unwrap_or(&[])
}
/// A NUL-terminated ASCII (or Latin-1) string at `at`, at most `max` bytes long.
pub(crate) fn cstr(b: &[u8], at: usize, max: usize) -> Option<String> {
let end = at.checked_add(max)?.min(b.len());
let field = b.get(at..end)?;
Some(until_nul(field).iter().map(|c| char::from(*c)).collect())
}
pub(crate) fn array<const N: usize>(b: &[u8], at: usize) -> Option<[u8; N]> {
let s = b.get(at..at.checked_add(N)?)?;
let mut a = [0u8; N];
a.copy_from_slice(s);
Some(a)
}
pub(crate) fn be_u16(b: &[u8], at: usize) -> Option<u16> {
array::<2>(b, at).map(u16::from_be_bytes)
}
pub(crate) fn be_u32(b: &[u8], at: usize) -> Option<u32> {
array::<4>(b, at).map(u32::from_be_bytes)
}
pub(crate) fn be_i32(b: &[u8], at: usize) -> Option<i32> {
array::<4>(b, at).map(i32::from_be_bytes)
}
pub(crate) fn le_u32(b: &[u8], at: usize) -> Option<u32> {
array::<4>(b, at).map(u32::from_le_bytes)
}
pub(crate) fn be_f32(b: &[u8], at: usize) -> Option<f32> {
array::<4>(b, at).map(f32::from_be_bytes)
}
pub(crate) fn be_f64(b: &[u8], at: usize) -> Option<f64> {
array::<8>(b, at).map(f64::from_be_bytes)
}
+46
View File
@@ -0,0 +1,46 @@
//! Cameras and lights.
//!
//! Both are layers without a source (`ldta` byte 40 is 0 for a camera and `0xffff_ffff` for a light)
//! whose type is 2 (camera) or 1 (light). Their `ldta` carries the auto-orient bit (byte 38, `0x40`)
//! and, for a light, the light type (see [`LayerHeader::light_type`](crate::LayerHeader)). The
//! properties sit in the same Transform group as on other layers but follow other conventions:
//!
//! * **Position** is stored as given once the user has set it. While it is at its computed default
//! the record is an "auto state" (`tdb4` bytes 76 and 77 are 1 although there is no expression)
//! that holds `[0, 0, -zoom]`. After Effects reports and renders the stored value, also for a
//! two-node camera (256 read back `[0, 0, -2666.67]` in session S16; 537 renders from there). An
//! earlier batch-3 note had a two-node camera report the composition centre; that was not
//! reproduced.
//! * **Anchor Point** of a camera is its point of interest, in pixels (not a fraction).
//! * A light's **Intensity** (`ADBE Light Options Group/ADBE Light Intensity`, percent) is stored
//! only when it is not the default 100.
use crate::typed::{Layer, PropNode};
/// The Position of a camera or light layer as stored.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CameraPosition {
/// `[x, y, z]` in pixels as stored: the absolute position once set by the user, `[0, 0, -zoom]`
/// in the auto state (camera) or `[0, 0, -1333.33]` (default light).
pub stored: [f64; 3],
/// True while the position is derived (`tdb4` bytes 76 and 77 are 1 without an expression).
pub auto_state: bool,
}
impl<'f, 'a> Layer<'f, 'a> {
/// The Position record of a camera or light layer.
pub fn camera_position(&self) -> Option<CameraPosition> {
let Some(PropNode::Group(transform)) = self.properties()?.get("ADBE Transform Group") else { return None };
let Some(PropNode::Property(position)) = transform.get("ADBE Position") else { return None };
let v = position.static_value()?;
let stored = *v.as_slice().first_chunk::<3>()?;
let h = position.header()?;
let derived = h.get(76) == Some(&1) && h.get(77) == Some(&1) && position.expression().is_none();
Some(CameraPosition { stored, auto_state: derived })
}
}
/// 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;
+213
View File
@@ -0,0 +1,213 @@
//! The lossless chunk tree.
use std::borrow::Cow;
/// The id of a list chunk.
pub const LIST: [u8; 4] = *b"LIST";
/// Non-`LIST` chunk ids whose body is itself a sequence of chunks (observed: each holds one `Utf8`
/// chunk). They are parsed as [`Body::Chunks`] when the body is a well-formed chunk sequence and
/// kept as [`Body::Data`] otherwise.
pub const NESTED_IDS: [[u8; 4]; 3] = [*b"tdsn", *b"pdnm", *b"fnam"];
/// One chunk: a 4-byte id, a body and an optional pad byte.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Chunk<'a> {
/// The 4-byte id, as stored (case matters; some ids end in a space, e.g. `seq `).
pub id: [u8; 4],
/// The body.
pub body: Body<'a>,
/// The pad byte that followed an odd-sized body (normally `0`). `None` when the body is even,
/// or when an odd body is the last thing of its parent and the file has no pad byte there.
/// On writing, an odd body that is not the last sibling always gets a pad byte (`0` if this is
/// `None`); the last sibling gets one only if this is `Some`.
pub pad: Option<u8>,
}
/// The body of a [`Chunk`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Body<'a> {
/// Opaque bytes (the content of nearly all chunks).
Data(Cow<'a, [u8]>),
/// A body that is a sequence of chunks although the id is not `LIST` (see [`NESTED_IDS`]).
Chunks(Vec<Chunk<'a>>),
/// A `LIST`: a 4-byte list type followed by chunks.
List { list_type: [u8; 4], children: Vec<Chunk<'a>> },
/// A `LIST` whose content is not a well-formed chunk sequence (or is nested deeper than the
/// limit), kept as bytes after the list type (observed: `LIST btdk` holds raw text).
OpaqueList { list_type: [u8; 4], data: Cow<'a, [u8]> },
}
impl<'a> Chunk<'a> {
/// A data chunk with the pad byte its length needs.
pub fn data(id: [u8; 4], data: impl Into<Cow<'a, [u8]>>) -> Self {
let data = data.into();
let pad = if data.len() % 2 == 1 { Some(0) } else { None };
Self { id, body: Body::Data(data), pad }
}
/// A `LIST` chunk.
pub fn list(list_type: [u8; 4], children: Vec<Chunk<'a>>) -> Self {
Self { id: LIST, body: Body::List { list_type, children }, pad: None }
}
/// The raw bytes of a [`Body::Data`] chunk, or the bytes after the list type of an opaque list.
pub fn bytes(&self) -> Option<&[u8]> {
match &self.body {
Body::Data(d) => Some(d),
Body::OpaqueList { data, .. } => Some(data),
Body::Chunks(_) | Body::List { .. } => None,
}
}
/// The child chunks of a list or nested chunk; empty for data.
pub fn children(&self) -> &[Chunk<'a>] {
match &self.body {
Body::Chunks(c) | Body::List { children: c, .. } => c,
Body::Data(_) | Body::OpaqueList { .. } => &[],
}
}
/// Mutable child chunks; empty for data.
pub fn children_mut(&mut self) -> &mut [Chunk<'a>] {
match &mut self.body {
Body::Chunks(c) | Body::List { children: c, .. } => c,
Body::Data(_) | Body::OpaqueList { .. } => &mut [],
}
}
/// The list type when this is a `LIST` (parsed or opaque).
pub fn list_type(&self) -> Option<[u8; 4]> {
match &self.body {
Body::List { list_type, .. } | Body::OpaqueList { list_type, .. } => Some(*list_type),
Body::Data(_) | Body::Chunks(_) => None,
}
}
/// True when this is a `LIST` of the given type.
pub fn is_list(&self, list_type: &[u8; 4]) -> bool {
self.id == LIST && self.list_type().is_some_and(|t| &t == list_type)
}
/// True when this is a `LIST` whose content could not be read as chunks (see
/// [`Body::OpaqueList`]): damaged, or nested deeper than the limit.
pub fn is_opaque_list(&self) -> bool {
matches!(self.body, Body::OpaqueList { .. })
}
/// True when this is a chunk (not a `LIST`) with the given id.
pub fn is(&self, id: &[u8; 4]) -> bool {
&self.id == id
}
/// The first child (non-list) chunk with this id.
pub fn child(&self, id: &[u8; 4]) -> Option<&Chunk<'a>> {
self.children().iter().find(|c| c.is(id))
}
/// The first child `LIST` of this type.
pub fn child_list(&self, list_type: &[u8; 4]) -> Option<&Chunk<'a>> {
self.children().iter().find(|c| c.is_list(list_type))
}
/// Visits every chunk below this one depth-first (children before later siblings), without
/// recursion; the depth counts from 1 for the children of this chunk.
pub fn descendants(&self) -> Walk<'_, 'a> {
Walk { stack: vec![(self.children().iter(), 1)] }
}
/// The first descendant `LIST` of this type, searching depth-first.
pub fn find_list(&self, list_type: &[u8; 4]) -> Option<&Chunk<'a>> {
self.descendants().map(|(_, c)| c).find(|c| c.is_list(list_type))
}
/// Copies all borrowed bytes so the tree no longer borrows the input.
pub fn into_owned(self) -> Chunk<'static> {
let body = match self.body {
Body::Data(d) => Body::Data(Cow::Owned(d.into_owned())),
Body::Chunks(c) => Body::Chunks(c.into_iter().map(Chunk::into_owned).collect()),
Body::List { list_type, children } => Body::List { list_type, children: children.into_iter().map(Chunk::into_owned).collect() },
Body::OpaqueList { list_type, data } => Body::OpaqueList { list_type, data: Cow::Owned(data.into_owned()) },
};
Chunk { id: self.id, body, pad: self.pad }
}
}
/// A parsed `.aep`: the `RIFX` container's chunks and the bytes after its declared end.
///
/// Writing it back with [`crate::write`] reproduces the input byte for byte (the container size
/// and every list size are recomputed from the tree and equal what the file declared).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AepFile<'a> {
/// The top-level chunks (after the `Egg!` form type).
pub chunks: Vec<Chunk<'a>>,
/// The bytes after the container's declared end. After Effects puts an XMP packet there.
pub trailer: Cow<'a, [u8]>,
}
impl<'a> AepFile<'a> {
/// The first top-level chunk with this id.
pub fn chunk(&self, id: &[u8; 4]) -> Option<&Chunk<'a>> {
self.chunks.iter().find(|c| c.is(id))
}
/// The first top-level `LIST` of this type.
pub fn list(&self, list_type: &[u8; 4]) -> Option<&Chunk<'a>> {
self.chunks.iter().find(|c| c.is_list(list_type))
}
/// The XMP packet in the trailer (from `<?xpacket begin` to the end of `<?xpacket end ...?>`).
pub fn xmp(&self) -> Option<&[u8]> {
let start = find(&self.trailer, b"<?xpacket begin")?;
let rest = self.trailer.get(start..)?;
let end_marker = find(rest, b"<?xpacket end")?;
let tail = rest.get(end_marker..)?;
let close = find(tail, b"?>")?;
rest.get(..end_marker.checked_add(close)?.checked_add(2)?)
}
/// Visits every chunk depth-first with its nesting depth (the top level is 1), without recursion.
pub fn walk(&self) -> Walk<'_, 'a> {
Walk { stack: vec![(self.chunks.iter(), 1)] }
}
/// Copies all borrowed bytes so the file no longer borrows the input.
pub fn into_owned(self) -> AepFile<'static> {
AepFile { chunks: self.chunks.into_iter().map(Chunk::into_owned).collect(), trailer: Cow::Owned(self.trailer.into_owned()) }
}
}
fn find(hay: &[u8], needle: &[u8]) -> Option<usize> {
if needle.is_empty() {
return Some(0);
}
hay.windows(needle.len()).position(|w| w == needle)
}
/// Depth-first iterator over all chunks, see [`AepFile::walk`].
pub struct Walk<'f, 'a> {
stack: Vec<(std::slice::Iter<'f, Chunk<'a>>, usize)>,
}
impl<'f, 'a> Iterator for Walk<'f, 'a> {
type Item = (usize, &'f Chunk<'a>);
fn next(&mut self) -> Option<Self::Item> {
loop {
let (iter, depth) = self.stack.last_mut()?;
let depth = *depth;
match iter.next() {
Some(chunk) => {
let kids = chunk.children();
if !kids.is_empty() {
self.stack.push((kids.iter(), depth.saturating_add(1)));
}
return Some((depth, chunk));
}
None => {
self.stack.pop();
}
}
}
}
}
+812
View File
@@ -0,0 +1,812 @@
//! Effect instances: match name, instance name, the parameter list from `parT`/`pard` and the
//! values stored with the instance.
//!
//! An effect on a layer is a `LIST sspc` under `ADBE Effect Parade`. It holds `fnam` (the
//! instance name), `LIST parT` (the parameter definitions: `parn`, then a `tdmn` and a 148-byte
//! `pard` per parameter, a `pdnm` after a popup), `LIST tdgp` (the values) and `pgui`. Only
//! parameters that differ from their `pard` default have a value record in the `tdgp` (the Layer
//! Control and button records are the exceptions: they always exist).
//!
//! When several layers carry an effect of the same type, only one instance has a full `parT`; the
//! others have an empty `LIST parT` (case 383). Their parameter definitions are the ones in the
//! project-level `LIST EfdG` (one `EfDf` per effect type: a `tdmn` with the match name, then a copy
//! of one instance's `sspc`), see [`Project::effect_params`]. That copy also carries the values of
//! the instance it was copied from, so values are only ever read from the instance's own `tdgp`.
//!
//! Some files have no `EfdG` at all (seen in 17 projects, all from inside After Effects-made
//! Motion Graphics templates). In those, one instance per effect type kept its full `parT` (which
//! one is not known) and it is the only place the definitions are written, so the other instances
//! of that type borrow them from it (#3170).
use std::collections::{HashMap, HashSet};
use crate::bytes::{array, be_f32, be_f64, be_i32, be_u16, be_u32, cstr, text, until_nul};
use crate::index::Node;
use crate::typed::{KeyList, Layer, Project, PropGroup, PropNode, Property};
/// The parameter type, the `u32` at byte 12 of `pard`. The numbering matches the plug-in
/// parameter types of the After Effects effect interface.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParamKind {
/// `0`: a layer reference (also the implicit first parameter, the input layer).
Layer,
/// `1`: an integer slider (Fast Box Blur's Iterations, 412-414): the default is an `i32` at
/// `pard` byte 56 (3), the valid maximum an `i32` at byte 128 (50), the value record a plain
/// `f64` (1.0).
IntSlider,
/// `2`: a fixed-point (16.16) slider.
FixedSlider,
/// `3`: an angle (16.16 degrees).
Angle,
/// `4`
Checkbox,
/// `5`
Color,
/// `6`
Point,
/// `7`: a popup menu (the items are in the `pdnm` chunk).
Popup,
/// `9`: no data (the group-end entry `ADBE Effect Built In Params`).
NoData,
/// `10`: a floating-point slider.
FloatSlider,
/// `11`: arbitrary data (Hue/Saturation's Channel Range, Levels' Histogram, 443, 511): the
/// value record is a 4-byte `cdat`, the data itself the `aRbp` of the `LIST aRbs` after it,
/// see [`Effect::arbitrary_data`].
ArbitraryData,
/// `12`: a path / mask reference.
Path,
/// `13`: the start of a twirl-down group (Exposure's Master, Red, Green and Blue, 389). It
/// holds no value; its value record always exists with `cdat` 0.
GroupStart,
/// `14`: the end of a twirl-down group (its name repeats the group's name, 389). It holds no
/// value; its value record always exists with `cdat` 0.
GroupEnd,
/// `15`: a button (Tint's and Gradient Ramp's Swap Colors). It holds no value; its value
/// record always exists with `cdat` 0 (356, 368).
Button,
/// Any other value.
Other(u32),
}
impl ParamKind {
fn from_u32(v: u32) -> Self {
match v {
0 => Self::Layer,
1 => Self::IntSlider,
2 => Self::FixedSlider,
3 => Self::Angle,
4 => Self::Checkbox,
5 => Self::Color,
6 => Self::Point,
7 => Self::Popup,
9 => Self::NoData,
10 => Self::FloatSlider,
11 => Self::ArbitraryData,
12 => Self::Path,
13 => Self::GroupStart,
14 => Self::GroupEnd,
15 => Self::Button,
other => Self::Other(other),
}
}
}
/// A decoded parameter value.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ParamValue {
/// A slider or angle value as stored: float sliders, fixed sliders and angles keep a plain
/// `f64` in their value record (an angle in degrees; a fixed slider in its own scale, see
/// [`EffectParam::valid_max`]); defaults read from `pard` are 16.16 decoded for fixed sliders
/// and angles.
Number(f64),
/// A checkbox: stored as 1.0 when on; an absent record means off.
Bool(bool),
/// A point control as stored: a fraction of the layer size (`[111, 222]` px on a 1920x1080
/// layer is `[111/1920, 222/1080]`).
Point([f64; 2]),
/// A layer control: the id of the chosen layer (the `tdpi` chunk next to the value record).
/// In the implicit first parameter it is the id of the layer that owns the effect.
Layer(u32),
/// A colour as ARGB fractions 0..1 (stored as doubles 0..255 in the order alpha, red, green,
/// blue: a colour `[0.2, 0.6, 1]` is `[255, 51, 153, 255]`, with float rounding).
Argb([f64; 4]),
/// A popup's item index, 1-based (Gradient Ramp's Radial Ramp is 2, 377): the default in
/// `pard`, or the stored selection.
Index(u32),
}
/// What a Layer Control points at, given the id of the layer that owns the effect.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayerRef {
/// The layer itself (the default, "Layer 1" on the first layer): the stored `tdpi` equals the
/// owning layer's id.
This,
/// None: the stored `tdpi` is 0.
Nothing,
/// Another layer, by id.
Layer(u32),
}
/// An effect instance on a layer.
#[derive(Debug, Clone)]
pub struct Effect<'f, 'a> {
match_name: String,
chunk: Node<'f, 'a>,
}
/// Where the parameter definitions of an effect instance come from.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DefinitionSource {
/// The instance's own `parT`.
Instance,
/// The project-level `EfdG/EfDf` copy for the effect's match name (the instance's own `parT`
/// is empty, 383).
Project,
/// The own `parT` of another instance of the same match name in the file: the instance's
/// own `parT` is empty and the file has no project-level copy of the type (a project without
/// `EfdG`, #3170).
OtherInstance,
/// None of these has any: the effect has no readable parameter definitions.
Missing,
}
/// One parameter of an effect.
#[derive(Debug, Clone)]
pub struct EffectParam<'f, 'a> {
/// The position in `parT` (0 is the implicit input layer).
pub index: usize,
/// The `tdmn` match name (`<effect match name>-NNNN`, the last one is
/// `ADBE Effect Built In Params`).
pub match_name: String,
pub kind: ParamKind,
/// The parameter name (`Blurriness`, `Slider`, ...; empty for the implicit parameters).
pub name: String,
/// The popup items (`pdnm`, split at `|`; for a button its label, e.g. `Swap Colors`).
pub items: Option<Vec<String>>,
/// True when the definition is borrowed: the project-level copy ([`DefinitionSource::Project`])
/// or another instance's ([`DefinitionSource::OtherInstance`]).
pub borrowed_definition: bool,
pard: &'f [u8],
stored: Option<Property<'f, 'a>>,
}
impl<'f, 'a> Effect<'f, 'a> {
/// The effect's match name (`ADBE Slider Control`, `ADBE Gaussian Blur 2`, ...).
pub fn match_name(&self) -> &str {
&self.match_name
}
/// The underlying `LIST sspc` chunk.
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")?.child(b"Utf8")?.bytes().map(text)
}
/// The name the user gave the instance: the `tdsn` of the instance's value group when it is
/// not the placeholder `-_0_/-` (610: `My Tint`; `fnam` keeps the effect's own name `Tint`).
/// `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")?.child(b"Utf8")?.bytes().map(text)?;
(name != "-_0_/-" && !name.is_empty()).then_some(name)
}
/// The instance's fx switch: the `tdsb` of its value group is 1 when on and 0 when switched
/// off (`fx-switch` cases: one instance on, one off, both in one save). `None` for another
/// value or a missing group.
pub fn enabled(&self) -> Option<bool> {
match be_u32(self.chunk.child_list(b"tdgp")?.child(b"tdsb")?.bytes()?, 0)? {
1 => Some(true),
0 => Some(false),
_ => None,
}
}
/// The name After Effects shows for the instance: [`Effect::user_name`], else [`Effect::name`].
pub fn display_name(&self) -> Option<String> {
self.user_name().or_else(|| self.name())
}
/// The number of parameters declared by `parn` (the implicit input layer and the built-in
/// entry included).
pub fn declared_param_count(&self) -> Option<u32> {
be_u32(self.chunk.child_list(b"parT")?.child(b"parn")?.bytes()?, 0)
}
/// True when the instance's own `parT` holds parameter definitions (a `pard`). A second
/// instance of an effect type has an empty `parT` (383).
pub fn has_own_definitions(&self) -> bool {
self.chunk.child_list(b"parT").is_some_and(has_pard)
}
/// The match names of the value records in the instance's own `tdgp` (properties only, not
/// groups), in file order, each once.
pub fn value_record_names(&self) -> Vec<String> {
let mut seen: HashSet<String> = HashSet::new();
self.chunk
.child_list(b"tdgp")
.and_then(PropGroup::from_chunk)
.map(|g| g.entries())
.unwrap_or_default()
.into_iter()
.filter(|e| matches!(e.node, PropNode::Property(_)))
.map(|e| e.match_name)
.filter(|n| seen.insert(n.clone()))
.collect()
}
/// The parameters in the order of the instance's own `parT`. Empty for an instance whose
/// `parT` is empty; [`Project::effect_params`] falls back to the project's definitions.
pub fn params(&self) -> Vec<EffectParam<'f, 'a>> {
match self.chunk.child_list(b"parT") {
Some(part) => self.params_from(part, false),
None => Vec::new(),
}
}
/// The parameters described by `part` (a `LIST parT`) with the values of this instance.
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
// would scan the whole group for each of them.
let mut values: HashMap<String, Option<Property<'f, 'a>>> = HashMap::new();
for e in self.chunk.child_list(b"tdgp").and_then(PropGroup::from_chunk).map(|g| g.entries()).unwrap_or_default() {
let stored = if let PropNode::Property(p) = e.node { Some(p) } else { None };
values.entry(e.match_name).or_insert(stored);
}
let mut pending: Option<String> = None;
for c in part.children() {
if c.is(b"tdmn") {
pending = c.bytes().map(|b| text(until_nul(b)));
} else if c.is(b"pard") {
let Some(pard) = c.bytes() else { continue };
let match_name = pending.take().unwrap_or_default();
let stored = values.get(&match_name).copied().flatten();
out.push(EffectParam {
index: out.len(),
match_name,
kind: Pard(pard).kind(),
name: Pard(pard).name().unwrap_or_default(),
items: None,
borrowed_definition: borrowed,
pard,
stored,
});
} else if c.is(b"pdnm")
&& let Some(last) = out.last_mut()
&& let Some(u) = c.child(b"Utf8")
&& let Some(b) = u.bytes()
// An empty `pdnm` names nothing (some writers store one: the effect
// supplies its items).
&& !b.is_empty()
{
last.items = Some(text(b).split('|').map(str::to_string).collect());
}
}
out
}
}
/// 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> {
/// The project-level effect definitions (`LIST EfdG`): one entry per effect type, the match
/// 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, 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().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))
&& seen.insert(n.clone())
{
out.push((n, part));
}
}
}
out
}
/// [`Self::effect_definitions`] indexed by match name, for looking up many effects: build it
/// once per file, not once per effect (a file can hold many definitions and many instances).
/// 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, 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() {
for fx in layer.effects() {
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)) {
instances.insert(fx.match_name, part);
}
}
}
}
EffectDefinitions { by_name, instances }
}
/// Where the parameter definitions of `effect` come from. Builds the index each call: use
/// [`Self::effect_definition_index`] for more than one effect.
pub fn definition_source(&self, effect: &Effect<'f, 'a>) -> DefinitionSource {
self.effect_definition_index().source(effect)
}
/// The parameters of `effect` ([`EffectDefinitions::params`]). Builds the index each call:
/// use [`Self::effect_definition_index`] for more than one effect.
pub fn effect_params(&self, effect: &Effect<'f, 'a>) -> Vec<EffectParam<'f, 'a>> {
self.effect_definition_index().params(effect)
}
}
/// The borrowable effect definitions by match name ([`Project::effect_definition_index`]).
#[derive(Debug, Clone, Default)]
pub struct EffectDefinitions<'f, 'a> {
/// The project-level copies (`EfdG`).
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, Node<'f, 'a>>,
}
impl<'f, 'a> EffectDefinitions<'f, 'a> {
/// Where the parameter definitions of `effect` come from.
pub fn source(&self, effect: &Effect<'f, 'a>) -> DefinitionSource {
if effect.has_own_definitions() {
DefinitionSource::Instance
} else if self.by_name.contains_key(effect.match_name()) {
DefinitionSource::Project
} else if self.instances.contains_key(effect.match_name()) {
DefinitionSource::OtherInstance
} else {
DefinitionSource::Missing
}
}
/// The parameters of `effect`: from its own `parT`, or, when that is empty, from the
/// project-level definition of its match name, else from another instance of it that has
/// its own ([`EffectParam::borrowed_definition`]). Values always come from the instance's own
/// records (absent = the `pard` default); the values next to borrowed definitions belong to
/// another instance and are never read.
pub fn params(&self, effect: &Effect<'f, 'a>) -> Vec<EffectParam<'f, 'a>> {
if effect.has_own_definitions() {
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),
None => Vec::new(),
}
}
}
impl<'f, 'a> EffectParam<'f, 'a> {
/// The raw 148-byte `pard` record (it contains stale memory after the name).
pub fn pard(&self) -> &'f [u8] {
self.pard
}
/// The value record stored with the instance (`<match>-NNNN` in the instance's `tdgp`), which
/// exists only for parameters that differ from the default.
pub fn stored(&self) -> Option<Property<'f, 'a>> {
self.stored
}
/// True when the parameter's value record has keyframes ([`EffectParam::keys`]); then
/// [`EffectParam::stored_value`] is `None` and [`EffectParam::value`] is not the value.
pub fn is_animated(&self) -> bool {
self.stored.is_some_and(|p| p.is_animated())
}
/// The keyframes of an animated parameter: plain 48-byte records for sliders (363), 152-byte
/// colour records (364) and 104-byte spatial records for points (382), with the values in the
/// stored units of [`EffectParam::stored_value`].
pub fn keys(&self) -> Option<KeyList<'f>> {
self.stored?.keys()
}
/// The value in the value record: float and fixed sliders, angles, checkboxes, points,
/// colours, popups and layer controls. A record counts when its `tdsb` is 1 and it has no
/// keyframes; a layer control reads the `tdpi` chunk; a button has no value.
pub fn stored_value(&self) -> Option<ParamValue> {
let p = self.stored?;
if self.kind != ParamKind::Layer && p.flags() != Some(1) {
return None;
}
self.recorded_value()
}
/// The value in the value record when the record is written (`tdsb` 1) or in the default
/// state (`tdsb` 3): what [`EffectParam::stored_value`] reads, also from a default-state
/// record. Lumetri Color writes the values of its hidden parameters so (High Dynamic Range,
/// HDR Specular, Look: 1200 `lumetri-01-set-all`, `-02-sec-top`, `-06-sec-light`; After
/// Effects reads back the recorded values). `None` with keyframes, without a record or for a
/// record in any other state (no sample has one; the importer reports it as damaged).
pub fn recorded_value(&self) -> Option<ParamValue> {
let p = self.stored?;
if self.kind == ParamKind::Layer {
return be_u32(p.chunk().child(b"tdpi")?.bytes()?, 0).map(ParamValue::Layer);
}
if !matches!(p.flags(), Some(1 | 3)) || p.is_animated() {
return None;
}
let v = p.static_value()?;
match self.kind {
ParamKind::FloatSlider | ParamKind::FixedSlider | ParamKind::Angle | ParamKind::IntSlider => v.first().copied().map(ParamValue::Number),
ParamKind::Checkbox => v.first().map(|x| ParamValue::Bool(*x != 0.0)),
ParamKind::Point => {
let [x, y] = *v.as_slice().first_chunk::<2>()?;
Some(ParamValue::Point([x, y]))
}
ParamKind::Popup => {
let index = v.first().copied()?;
(0.0..=f64::from(u32::MAX)).contains(&index).then(|| ParamValue::Index(index.round() as u32))
}
ParamKind::Color => {
let [a, r, g, b] = *v.as_slice().first_chunk::<4>()?;
Some(ParamValue::Argb([a / 255.0, r / 255.0, g / 255.0, b / 255.0]))
}
_ => None,
}
}
/// The default stored in `pard` at byte 56: a float slider's `f64`, a fixed slider's or angle's
/// 16.16 value, a colour's ARGB bytes, a popup's item index, a point's two 16.16 fractions of
/// the layer size (Point Control 0.5, 0.5: the layer centre, also on a 100x100 layer;
/// Gradient Ramp Start 0.5, 0 and End 0.5, 1), an integer slider's `i32` (Iterations 3, 412),
/// a checkbox's `u32` (1 = on: Repeat Edge Pixels of Fast Box Blur and Gaussian Blur, read back
/// on, 412, 417; 0 = off: Shadow Only 420, Bypass Linear Light Conversion 389); other types:
/// `None`.
///
/// It is the default and not the current value: Gaussian Blur with Blurriness 40 still has 25
/// here and a value record with 40 (After Effects itself reads a fresh Gaussian Blur back as 25).
/// Exception: selecting a popup item also writes the selection to this slot. So a popup whose
/// definition was borrowed from the project copy ([`EffectParam::borrowed_definition`]) has no
/// reliable default here (the slot holds the copied instance's selection): `None`.
pub fn pard_default(&self) -> Option<ParamValue> {
match self.kind {
ParamKind::Popup if self.borrowed_definition => None,
kind => Pard(self.pard).default(kind),
}
}
/// True when the parameter is at its default: it has no value record (a record exists exactly
/// when the value differs from the `pard` default; setting a value back to the default removes
/// the record again), or the record equals the default. A record in the default state (`tdsb`
/// 3) counts with its value ([`EffectParam::recorded_value`]). `None` when that cannot be
/// decided (unknown parameter type, keyframes).
pub fn is_default(&self) -> Option<bool> {
match (self.stored, self.kind) {
// A Layer Control always has its record, and a popup selection overwrites the default
// in `pard`. Buttons and group markers hold no value at all.
(_, ParamKind::Layer | ParamKind::Button | ParamKind::GroupStart | ParamKind::GroupEnd) => None,
(None, _) => Some(true),
(Some(_), ParamKind::Popup) => Some(false),
(Some(_), _) => {
let stored = self.recorded_value()?;
// A checkbox's default is in `pard` too (on for Repeat Edge Pixels, 412).
Some(self.pard_default().is_some_and(|d| d == stored))
}
}
}
/// A point control in pixels of a layer of this size (the stored point is a fraction of the
/// layer size; the default is the layer centre). `None` for other parameter types.
pub fn point_px(&self, layer_width: f64, layer_height: f64) -> Option<[f64; 2]> {
match self.value()? {
ParamValue::Point([x, y]) if self.kind == ParamKind::Point => Some([x * layer_width, y * layer_height]),
_ => None,
}
}
/// For a Layer Control: what the stored layer id means for the layer that owns the effect.
/// `None` for other types and for the implicit first parameter of an effect.
pub fn layer_ref(&self, owner_layer_id: u32) -> Option<LayerRef> {
if self.kind != ParamKind::Layer || self.index == 0 {
return None;
}
match self.stored_value()? {
ParamValue::Layer(0) => Some(LayerRef::Nothing),
ParamValue::Layer(id) if id == owner_layer_id => Some(LayerRef::This),
ParamValue::Layer(id) => Some(LayerRef::Layer(id)),
_ => None,
}
}
/// The largest valid value of a slider, from `pard`: a fixed slider's 16.16 at byte 128 (Tint
/// Amount to Tint 100, Gradient Ramp Ramp Scatter 512 and Blend With Original 1.0, Drop Shadow
/// Opacity 255), a float slider's `f32` at byte 108 (Blurriness 30000, Exposure 100, Exposure's
/// Gamma Correction 10). The stored scale of a
/// slider differs per parameter (Amount 37.5 % is stored 37.5, Blend 25 % is stored 0.25), so
/// this is what tells a reader the scale. `None` for other types.
pub fn valid_max(&self) -> Option<f64> {
Pard(self.pard).valid_max(self.kind)
}
/// The smallest valid value of a float slider, the `f32` at byte 104 of `pard` (Exposure
/// -100, Offset -2, Gamma Correction 0.1: 389). `None` for other types (a fixed slider's
/// minimum is not decoded).
pub fn valid_min(&self) -> Option<f64> {
Pard(self.pard).valid_min(self.kind)
}
/// The range of a float slider's slider (what the control's drag covers, inside the valid
/// range): the `f32` pair at bytes 112 and 116 of `pard` (Exposure -4..4, Offset -0.5..0.5,
/// Gamma Correction 0.1..10: 389). Each value record repeats it as `tdum` / `tduM`. `None`
/// for other types.
pub fn slider_range(&self) -> Option<(f64, f64)> {
match self.kind {
ParamKind::FloatSlider => Pard(self.pard).slider_range(self.kind),
_ => None,
}
}
/// For a popup: the number of items (`u16` at byte 60 of `pard`).
pub fn popup_item_count(&self) -> Option<u16> {
if self.kind != ParamKind::Popup {
return None;
}
Pard(self.pard).popup_item_count()
}
/// For a popup: the selected item index (1-based): the stored selection, else the default.
pub fn popup_selected_index(&self) -> Option<u32> {
match self.value()? {
ParamValue::Index(i) if self.kind == ParamKind::Popup => Some(i),
_ => None,
}
}
/// For a popup: the text of the selected item.
pub fn popup_selected_item(&self) -> Option<&str> {
let index = usize::try_from(self.popup_selected_index()?).ok()?.checked_sub(1)?;
self.items.as_ref()?.get(index).map(String::as_str)
}
/// The effective value: the value in the record when there is one, also in a record in the
/// default state (`tdsb` 3, [`EffectParam::recorded_value`]), else the `pard` default (absent =
/// default); a checkbox without a record is off.
pub fn value(&self) -> Option<ParamValue> {
self.recorded_value().or_else(|| self.pard_default()).or(match self.kind {
ParamKind::Checkbox if self.stored.is_none() => Some(ParamValue::Bool(false)),
_ => None,
})
}
}
/// A parameter definition (`pard`, 148 bytes; aep-format.md 3.7): the one decoder of its fields.
/// The import reads them through [`EffectParam`]; the export writes them from its effect table and
/// its tests read them back through this.
#[derive(Clone, Copy, Debug)]
pub struct Pard<'f>(pub &'f [u8]);
impl Pard<'_> {
/// The type code, the `u32` at byte 12.
pub fn code(self) -> Option<u32> {
be_u32(self.0, 12)
}
/// The parameter type (an unreadable code is [`ParamKind::Other`]).
pub fn kind(self) -> ParamKind {
ParamKind::from_u32(self.code().unwrap_or(u32::MAX))
}
/// The parameter name at byte 16 (32 bytes).
pub fn name(self) -> Option<String> {
cstr(self.0, 16, 32)
}
/// The default at byte 56 as a parameter of type `kind` reads it (see
/// [`EffectParam::pard_default`]).
pub fn default(self, kind: ParamKind) -> Option<ParamValue> {
let p = self.0;
match kind {
ParamKind::FloatSlider => be_f64(p, 56).map(ParamValue::Number),
ParamKind::FixedSlider | ParamKind::Angle => be_i32(p, 56).map(|v| ParamValue::Number(f64::from(v) / 65536.0)),
ParamKind::IntSlider => be_i32(p, 56).map(|v| ParamValue::Number(f64::from(v))),
ParamKind::Checkbox => be_u32(p, 56).map(|v| ParamValue::Bool(v != 0)),
ParamKind::Popup => be_u32(p, 56).map(ParamValue::Index),
ParamKind::Point => {
let pt = [f64::from(be_i32(p, 56)?) / 65536.0, f64::from(be_i32(p, 60)?) / 65536.0];
// A fresh instance stores fractions of the layer (0.5, 0.5); After Effects' save of
// a project it opened stores percent (50, 50: the re-saves of read-back tests e1 and
// e2, where Gradient Ramp's Start and End and every other point default came back
// as 50 / 0 and 50 / 100). Point
// defaults lie inside the layer, so a component beyond 1 tells percent.
let percent = pt.iter().any(|c| c.abs() > 1.0 + 1e-9);
Some(ParamValue::Point(if percent { pt.map(|c| c / 100.0) } else { pt }))
}
ParamKind::Color => {
let [a, r, g, b] = array::<4>(p, 56)?.map(|c| f64::from(c) / 255.0);
Some(ParamValue::Argb([a, r, g, b]))
}
_ => None,
}
}
/// The valid maximum of a slider (see [`EffectParam::valid_max`]).
pub fn valid_max(self, kind: ParamKind) -> Option<f64> {
match kind {
ParamKind::FixedSlider => be_i32(self.0, 128).map(|v| f64::from(v) / 65536.0),
ParamKind::FloatSlider => be_f32(self.0, 108).map(f64::from),
ParamKind::IntSlider => be_i32(self.0, 128).map(f64::from),
_ => None,
}
}
/// The valid minimum of a float slider (see [`EffectParam::valid_min`]).
pub fn valid_min(self, kind: ParamKind) -> Option<f64> {
match kind {
ParamKind::FloatSlider => be_f32(self.0, 104).map(f64::from),
_ => None,
}
}
/// A slider's range, the one its value records repeat as `tdum` / `tduM`: a float slider's
/// `f32` pair at 112 / 116, a fixed slider's 16.16 pair and an integer slider's `i32` pair at
/// 132 / 136.
pub fn slider_range(self, kind: ParamKind) -> Option<(f64, f64)> {
let p = self.0;
match kind {
ParamKind::FloatSlider => Some((f64::from(be_f32(p, 112)?), f64::from(be_f32(p, 116)?))),
ParamKind::FixedSlider => Some((f64::from(be_i32(p, 132)?) / 65536.0, f64::from(be_i32(p, 136)?) / 65536.0)),
ParamKind::IntSlider => Some((f64::from(be_i32(p, 132)?), f64::from(be_i32(p, 136)?))),
_ => None,
}
}
/// A popup's item count, the `u16` at byte 60.
pub fn popup_item_count(self) -> Option<u16> {
be_u16(self.0, 60)
}
}
impl<'f, 'a> Layer<'f, 'a> {
/// The effects on the layer, in stack order (`ADBE Effect Parade`).
pub fn effects(&self) -> Vec<Effect<'f, 'a>> {
let Some(root) = self.properties() else { return Vec::new() };
let Some(PropNode::Group(parade)) = root.get("ADBE Effect Parade") else { return Vec::new() };
parade
.entries()
.into_iter()
.filter_map(|e| match e.node {
PropNode::Other(chunk) if chunk.is_list(b"sspc") => Some(Effect { match_name: e.match_name, chunk }),
_ => None,
})
.collect()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Chunk;
#[test]
fn a_parameter_definition_reads_its_fields_and_nothing_from_a_cut_record() {
let mut b = vec![0u8; 148];
b[12..16].copy_from_slice(&7u32.to_be_bytes());
b[16..22].copy_from_slice(b"Amount");
b[56..64].copy_from_slice(&2.5f64.to_be_bytes());
let p = Pard(&b);
assert_eq!((p.code(), p.name().as_deref()), (Some(7), Some("Amount")));
assert_eq!(p.default(ParamKind::FloatSlider), Some(ParamValue::Number(2.5)));
// The same bytes as a checkbox and as a popup: the `u32` at 56, and the `u16` at 60.
b[56..60].copy_from_slice(&1u32.to_be_bytes());
b[60..62].copy_from_slice(&3u16.to_be_bytes());
let p = Pard(&b);
assert_eq!(p.default(ParamKind::Checkbox), Some(ParamValue::Bool(true)));
assert_eq!((p.default(ParamKind::Popup), p.popup_item_count()), (Some(ParamValue::Index(1)), Some(3)));
assert_eq!(p.default(ParamKind::IntSlider), Some(ParamValue::Number(1.0)));
// A record cut before a field has no value for it, and an unreadable code is `Other`.
let cut = Pard(&b[..12]);
assert_eq!((cut.code(), cut.kind(), cut.name(), cut.popup_item_count()), (None, ParamKind::Other(u32::MAX), None, None));
assert_eq!(cut.default(ParamKind::FloatSlider), None);
assert_eq!(Pard(&b[..58]).default(ParamKind::Checkbox), None);
}
fn tdmn(name: &str) -> Chunk<'static> {
let mut b = name.as_bytes().to_vec();
b.resize(40, 0);
Chunk::data(*b"tdmn", b)
}
fn pard() -> Chunk<'static> {
Chunk::data(*b"pard", vec![0u8; 48])
}
fn tdbs() -> Chunk<'static> {
Chunk::list(*b"tdbs", Vec::new())
}
/// An effect instance whose `parT` names `defs` and whose `tdgp` stores `stored` (in order).
fn instance(defs: &[String], stored: &[(String, Chunk<'static>)]) -> Chunk<'static> {
let part = defs.iter().flat_map(|n| [tdmn(n), pard()]).collect();
let values = stored.iter().flat_map(|(n, c)| [tdmn(n), c.clone()]).collect();
Chunk::list(*b"sspc", vec![Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)])
}
#[test]
fn a_parameter_takes_the_first_stored_entry_of_its_name() {
let names: Vec<String> = ["A", "B", "C"].map(String::from).to_vec();
// `A` is stored twice (the first wins), `B` names a group (no stored value), `C` is absent.
let stored = vec![
("A".to_string(), tdbs()),
("B".to_string(), Chunk::list(*b"tdgp", Vec::new())),
("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: 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().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()));
}
#[test]
fn many_parameters_are_read_in_linear_time() {
// 100 000 parameters with 100 000 stored values: a lookup per parameter that scans the
// group (as before) is 1e10 entry builds; one index is instant.
let n = 100_000;
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: Node::from(&chunk) };
let params = fx.params();
assert_eq!(params.len(), n);
assert!(params.iter().all(|p| p.stored.is_some()));
}
#[test]
fn many_project_definitions_are_indexed_once() {
// 50 000 definitions, each twice (the first copy wins), then 1000 instances without
// their own definitions looked up through one index.
let n = 50_000;
let mut defs = Vec::new();
for round in 0..2 {
for i in 0..n {
let part = Chunk::list(*b"parT", vec![tdmn(&format!("R{round}")), pard()]);
defs.push(Chunk::list(*b"EfDf", vec![tdmn(&format!("FX{i}")), Chunk::list(*b"sspc", vec![part])]));
}
}
let efdg = Chunk::list(*b"EfdG", defs);
let fold = Chunk::list(*b"Fold", Vec::new());
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: 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: Node::from(&bare) };
assert_eq!(index.source(&unknown), DefinitionSource::Missing);
assert!(index.params(&unknown).is_empty());
assert_eq!(project.definition_source(&unknown), DefinitionSource::Missing);
}
}
+57
View File
@@ -0,0 +1,57 @@
//! Errors of the container reader and writer.
use std::fmt;
/// Why a file could not be read or written.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AepError {
/// The input is shorter than the 12-byte `RIFX` header, or does not start with `RIFX`.
NotRifx,
/// The form type after the declared size is not `Egg!`.
BadFormType([u8; 4]),
/// The declared container size runs past the end of the input.
Truncated { declared: u64, available: u64 },
/// A chunk declares more body bytes than remain in its parent (`offset` is the chunk header).
ChunkTooLarge { offset: usize, size: u64, available: u64 },
/// The chunk structure is not well formed at `offset` (what is wrong is in `what`).
Malformed { offset: usize, what: &'static str },
/// Nesting is deeper than the allowed maximum.
TooDeep,
/// More chunks than the allowed maximum.
TooManyChunks,
/// A chunk or the whole file would not fit the 32-bit size fields when writing.
TooLarge,
/// An `.aepx` is not well-formed XML of the subset After Effects writes, at byte `offset`
/// (what is wrong is in `what`).
Xml { offset: usize, what: &'static str },
}
impl AepError {
/// Structural problems of the input that a lenient caller may repair by keeping a body opaque;
/// limits (`TooDeep`, `TooManyChunks`) are never repaired.
pub(crate) fn is_structural(&self) -> bool {
matches!(self, Self::ChunkTooLarge { .. } | Self::Malformed { .. } | Self::Truncated { .. })
}
}
impl fmt::Display for AepError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotRifx => write!(f, "not an After Effects project: no RIFX header"),
Self::BadFormType(t) => write!(f, "RIFX form type {:?} is not \"Egg!\"", String::from_utf8_lossy(t)),
Self::Truncated { declared, available } => {
write!(f, "truncated file: the container declares {declared} bytes, {available} are available")
}
Self::ChunkTooLarge { offset, size, available } => {
write!(f, "chunk at offset {offset} declares {size} bytes, only {available} remain")
}
Self::Malformed { offset, what } => write!(f, "malformed chunk structure at offset {offset}: {what}"),
Self::TooDeep => write!(f, "chunks are nested too deeply"),
Self::TooManyChunks => write!(f, "too many chunks"),
Self::TooLarge => write!(f, "chunk too large for the 32-bit size field"),
Self::Xml { offset, what } => write!(f, "not a readable After Effects XML project (.aepx): {what} at byte {offset}"),
}
}
}
impl std::error::Error for AepError {}
+475
View File
@@ -0,0 +1,475 @@
//! Item ids and labels, footage items (solids and files), precomp linkage, and the name and size
//! of a layer's source.
use crate::bytes::{be_f32, be_f64, be_i32, be_u32, cstr, le_u32, text, until_nul};
use crate::header::Rational;
use crate::index::Node;
use crate::typed::{Item, ItemKind, Layer, Project};
/// The footage data of an item (`LIST Pin ` with `sspc`, `opti` and, for files, `Als2/alas`).
#[derive(Debug, Clone, PartialEq)]
pub struct Footage {
/// The 4-character file type tag at byte 22 of `sspc` (`Soli` for a solid, `png!` for a png).
pub file_type: String,
/// The width in pixels (`u32` at byte 30 of `sspc`).
pub width: u32,
/// The height in pixels (`u32` at byte 34 of `sspc`).
pub height: u32,
/// The display name stored in `opti` (the item's own `Utf8` name is empty for footage): at byte
/// 26 for a solid and at byte 58 for a file.
pub name: Option<String>,
/// True for a solid (tag `Soli` at the start of `opti`).
pub is_solid: bool,
/// The colour of a solid as ARGB floats 0..1 (`opti` bytes 10, 14, 18, 22); a red solid is
/// `[1, 1, 0, 0]`.
pub solid_argb: Option<[f32; 4]>,
/// The file path from the alias JSON (`Als2/alas`, key `fullpath`); none for solids. For an
/// image sequence it is the sequence **folder**.
pub path: Option<String>,
/// The duration in seconds as stored (`sspc` `u32` at byte 38 over `u32` at byte 42; unreduced):
/// 0/1 for stills, 48000/48000 for the 1 s WAV (the sample rate is the denominator), 3/30 for
/// the three-frame image sequence (the frame rate is the denominator).
pub duration: Option<Rational>,
/// The native frame rate (`sspc` `u32` at byte 56): 30 for the image sequence, 0 for stills,
/// audio and solids (also 0 when the byte is missing).
pub native_frame_rate: u32,
/// The bits per pixel (`sspc` `u32` at byte 60): 32 for an RGBA still, 24 for an RGB sequence,
/// 0 for solids and audio.
pub bits_per_pixel: u32,
/// The size in bytes of the source file(s) (`sspc` `u32` at byte 208): 149 for the png, 96044
/// for the WAV (44 + 48000 x 2), 504 for three 168-byte png files.
pub file_size: u32,
/// The audio sample rate (`sspc` `f64` at byte 160, 48000.0 for the WAV and for an mp4 with
/// 48 kHz sound); `None` for footage without audio.
pub audio_sample_rate: Option<f64>,
/// 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 solid's colour as fractions R, G, B.
pub fn solid_rgb(&self) -> Option<[f32; 3]> {
let [_, r, g, b] = self.solid_argb?;
Some([r, g, b])
}
}
/// The boolean value of `"key"` in a flat JSON object (`true` / `false`); `None` when missing.
pub(crate) fn json_bool(json: &[u8], key: &str) -> Option<bool> {
let needle = format!("\"{key}\":");
let needle = needle.as_bytes();
let at = json.windows(needle.len()).position(|w| w == needle)?;
let rest = json.get(at.checked_add(needle.len())?..)?;
if rest.starts_with(b"true") {
Some(true)
} else if rest.starts_with(b"false") {
Some(false)
} else {
None
}
}
/// The string value of `"key"` in a flat JSON object, with the standard escapes decoded.
/// Returns `None` when the key is missing or the value is not a string. The key is the first
/// occurrence of `"key"` that is followed by `:` (the same text as a value is skipped).
pub(crate) fn json_string(json: &[u8], key: &str) -> Option<String> {
let needle = format!("\"{key}\"");
let needle = needle.as_bytes();
let mut from = 0usize;
loop {
let at = from.checked_add(json.get(from..)?.windows(needle.len()).position(|w| w == needle)?)?;
let after = at.checked_add(needle.len())?;
if let Some(v) = json_string_at(json, after) {
return Some(v);
}
from = at.checked_add(1)?;
}
}
/// The string value right after a key ending at `i` (`: "…"`), or `None` when none follows.
fn json_string_at(json: &[u8], mut i: usize) -> Option<String> {
let skip_ws = |i: &mut usize| {
while json.get(*i).is_some_and(|c| c.is_ascii_whitespace()) {
*i = i.saturating_add(1);
}
};
skip_ws(&mut i);
if json.get(i) != Some(&b':') {
return None;
}
i = i.saturating_add(1);
skip_ws(&mut i);
if json.get(i) != Some(&b'"') {
return None;
}
i = i.saturating_add(1);
let mut out: Vec<u8> = Vec::new();
loop {
let c = *json.get(i)?;
i = i.saturating_add(1);
match c {
b'"' => return Some(text(&out)),
b'\\' => {
let e = *json.get(i)?;
i = i.saturating_add(1);
match e {
b'n' => out.push(b'\n'),
b't' => out.push(b'\t'),
b'r' => out.push(b'\r'),
b'b' => out.push(8),
b'f' => out.push(12),
b'u' => {
let hex4 = |at: usize| {
json.get(at..at.checked_add(4)?).and_then(|h| std::str::from_utf8(h).ok()).and_then(|h| u32::from_str_radix(h, 16).ok())
};
let mut code = hex4(i)?;
i = i.saturating_add(4);
// A character outside the BMP is a high surrogate and a `\u` low surrogate.
if (0xd800..0xdc00).contains(&code)
&& json.get(i..i.saturating_add(2)) == Some(b"\\u")
&& let Some(lo) = hex4(i.saturating_add(2)).filter(|lo| (0xdc00..0xe000).contains(lo))
{
code = 0x10000 + ((code - 0xd800) << 10) + (lo - 0xdc00);
i = i.saturating_add(6);
}
let ch = char::from_u32(code).unwrap_or('\u{fffd}');
let mut buf = [0u8; 4];
out.extend_from_slice(ch.encode_utf8(&mut buf).as_bytes());
}
other => out.push(other),
}
}
other => out.push(other),
}
}
}
/// The numbering of an image sequence item (353, 603), or its file list when it was imported with
/// Force alphabetical order.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SequenceInfo {
/// The file name before the frame number (`seq_`, `shot_`): the first `Utf8` after the alias.
/// An empty prefix is not stored (`0001.png`): the one `Utf8` is then the suffix.
pub prefix: String,
/// The file name after the frame number (`.png`, `.exr`): the second `Utf8` after the alias.
pub suffix: String,
/// The first and last frame number (`sspc` `u32` at 172 and 176: 1 and 3 in 353, 101 and 103
/// in 603; both `0xFFFFFFFF` for a sequence with a file list).
pub start: u32,
pub end: u32,
/// The digits of the frame number (`sspc` `u32` at 180: 3 for `seq_001`, 4 for `shot_0101`).
pub digits: u32,
/// The file names in order for a sequence imported with Force alphabetical order (`LIST StVc`
/// after the alias: `StVS` with the count as a little-endian `u32`, then one `Utf8` per file);
/// empty for a numbered sequence. When set, it replaces the numbering.
pub files: Vec<String>,
}
impl SequenceInfo {
/// The file name of frame `n` (`shot_0101.exr`).
pub fn file_name(&self, n: u32) -> String {
let width = usize::try_from(self.digits.min(16)).unwrap_or(0);
format!("{}{n:0width$}{}", self.prefix, self.suffix)
}
/// The number of files: the listed files, or the frame numbers from start to end (0 when the
/// end lies before the start).
pub fn frame_count(&self) -> u32 {
if self.files.is_empty() {
self.end.checked_sub(self.start).map_or(0, |d| d.saturating_add(1))
} else {
u32::try_from(self.files.len()).unwrap_or(u32::MAX)
}
}
/// The name of the `i`-th file (from 0): from the file list, or numbered from `start`; `None`
/// past the last file.
pub fn nth_file_name(&self, i: u32) -> Option<String> {
if self.files.is_empty() {
let n = self.start.checked_add(i).filter(|n| *n <= self.end)?;
Some(self.file_name(n))
} else {
self.files.get(usize::try_from(i).ok()?).cloned()
}
}
}
/// The file names of a `LIST StVc` (Force alphabetical order): the `Utf8` children in order, at most
/// as many as the count in `StVS` (little-endian `u32`) says. Empty names count toward that number
/// and are then skipped. Without a readable count (no `StVS`, or one shorter than 4 bytes) the list
/// 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: 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().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();
}
names
}
/// The prefix and suffix of a sequence whose naming holds one `Utf8` (`part`): After Effects leaves
/// out an empty prefix (`0001.png` stores only `.png`). The stored first file name (`opti`) decides:
/// a name starting with `part` has it as the prefix, one ending with it as the suffix. Without that
/// evidence, a `part` starting with `.` is the suffix (an extension); anything else is not read.
fn single_name_part(part: &str, first_file: Option<&str>) -> Option<(String, String)> {
if let Some(first) = first_file.filter(|_| !part.is_empty()) {
match (first.starts_with(part), first.ends_with(part)) {
(true, false) => return Some((part.to_string(), String::new())),
(false, true) => return Some((String::new(), part.to_string())),
_ => {}
}
}
part.starts_with('.').then(|| (String::new(), part.to_string()))
}
impl<'f, 'a> Item<'f, 'a> {
/// The numbering of an image sequence (an item whose alias is a folder); `None` for anything
/// else.
pub fn sequence_info(&self) -> Option<SequenceInfo> {
let f = self.footage()?;
if !f.is_sequence {
return None;
}
let pin = self.chunk.child_list(b"Pin ")?;
let sspc = pin.child(b"sspc")?.bytes()?;
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")) {
let files = sequence_file_list(list);
if files.is_empty() {
return None;
}
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(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`).
[one] => single_name_part(one, f.name.as_deref())?,
_ => return None,
};
Some(SequenceInfo { prefix, suffix, start, end, digits, files: Vec::new() })
}
/// The rate a clip is conformed to (Interpret Footage ▸ Conform to frame rate; `sspc` `u32` at
/// byte 146): 30 for the 25 fps mp4 conformed to 30 (645), `None` when not conformed (0 in 644,
/// 606) or for an item without footage data. The effective rate is then also at byte 150 while
/// the stored duration (bytes 38 / 42) and byte 56 stay native. A conformed image sequence
/// stores the new rate in bytes 42, 56 and 150 instead and keeps 0 here (615).
pub fn conform_frame_rate(&self) -> Option<u32> {
let sspc = self.chunk.child_list(b"Pin ")?.child(b"sspc")?.bytes()?;
be_u32(sspc, 146).filter(|r| *r > 0)
}
/// The item id: the big-endian `u32` at byte 16 of `idta` (what a layer's source id refers to).
pub fn id(&self) -> Option<u32> {
be_u32(self.chunk.child(b"idta")?.bytes()?, 16)
}
/// The label colour index, byte 58 of `idta` (15 for a composition made by precomposing).
pub fn label(&self) -> Option<u8> {
self.chunk.child(b"idta")?.bytes()?.get(58).copied()
}
/// The footage data of a footage item.
pub fn footage(&self) -> Option<Footage> {
if self.kind()? != ItemKind::Footage {
return None;
}
let pin = self.chunk.child_list(b"Pin ")?;
let sspc = pin.child(b"sspc")?.bytes()?;
let opti = pin.child(b"opti")?.bytes()?;
let is_solid = opti.get(..4) == Some(&b"Soli"[..]);
let alias = pin.child_list(b"Als2").and_then(|als| als.child(b"alas")).and_then(|alas| alas.bytes());
let path = alias.and_then(|json| json_string(json, "fullpath"));
let is_sequence = alias.and_then(|json| json_bool(json, "target_is_folder")).unwrap_or(false);
let solid_argb = if is_solid { Some([be_f32(opti, 10)?, be_f32(opti, 14)?, be_f32(opti, 18)?, be_f32(opti, 22)?]) } else { None };
Some(Footage {
file_type: cstr(sspc, 22, 4)?,
width: be_u32(sspc, 30)?,
height: be_u32(sspc, 34)?,
name: cstr(opti, if is_solid { 26 } else { 58 }, 256).filter(|n| !n.is_empty()),
is_solid,
solid_argb,
path,
duration: be_u32(sspc, 38).zip(be_u32(sspc, 42)).map(|(num, den)| Rational { num: i64::from(num), den: i64::from(den) }),
native_frame_rate: be_u32(sspc, 56).unwrap_or(0),
bits_per_pixel: be_u32(sspc, 60).unwrap_or(0),
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),
})
}
/// The name this item shows in the project: the item name, or for footage the name stored in
/// `opti`.
pub fn display_name(&self) -> Option<String> {
self.name().or_else(|| self.footage().and_then(|f| f.name))
}
}
impl<'f, 'a> Project<'f, 'a> {
/// The item with this id (`idta` byte 16), searching every item including those in folders.
pub fn item_by_id(&self, id: u32) -> Option<Item<'f, 'a>> {
self.all_items().into_iter().find(|i| i.id() == Some(id))
}
/// The item a layer is made from (its source id), e.g. the solid, the footage or the precomp.
pub fn layer_source(&self, layer: &Layer<'f, 'a>) -> Option<Item<'f, 'a>> {
self.item_by_id(layer.header()?.source_id?)
}
/// 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)> {
let source = self.layer_source(layer)?;
match source.kind()? {
ItemKind::Footage => source.footage().map(|f| (f.width, f.height)),
ItemKind::Composition => source.comp()?.header().map(|h| (u32::from(h.width), u32::from(h.height))),
ItemKind::Folder | ItemKind::Other(_) => None,
}
}
}
#[cfg(test)]
mod tests {
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() {
let json = br#"{"a":1,"fullpath":"C:\\dir\\f\u00e9.png","b":"x"}"#;
assert_eq!(json_string(json, "fullpath").as_deref(), Some(r"C:\dir\fé.png"));
assert_eq!(json_string(json, "b").as_deref(), Some("x"));
assert_eq!(json_string(json, "missing"), None);
assert_eq!(json_string(br#"{"a" : "spaced"}"#, "a").as_deref(), Some("spaced"));
// The key's text as an earlier value is not the key.
assert_eq!(json_string(br#"{"a":"fullpath","fullpath":"x"}"#, "fullpath").as_deref(), Some("x"));
// A surrogate pair is one character; a lone half stays U+FFFD.
assert_eq!(json_string(br#"{"a":"x\ud83d\ude00y"}"#, "a").as_deref(), Some("x😀y"));
assert_eq!(json_string(br#"{"a":"\ud83dz"}"#, "a").as_deref(), Some("\u{fffd}z"));
assert_eq!(json_string(br#"{"a":"\ude00"}"#, "a").as_deref(), Some("\u{fffd}"));
}
#[test]
fn damaged_json_never_panics() {
for json in [
&br#"{"fullpath":"#[..],
br#"{"fullpath":"abc"#,
br#"{"fullpath":"ab\"#,
br#"{"fullpath":"\u12"}"#,
br#"{"fullpath":"\uzzzz"}"#,
br#"{"fullpath":5}"#,
br#"{"fullpath"}"#,
b"\"fullpath\"",
b"",
b"\"",
br#"{"fullpath":"\ud800"}"#,
] {
let _ = json_string(json, "fullpath");
}
assert_eq!(json_string(br#"{"fullpath":"\ud800"}"#, "fullpath").as_deref(), Some("\u{fffd}"));
}
}
+468
View File
@@ -0,0 +1,468 @@
//! The layer header (`ldta`) and the composition header (`cdta`, `PRin`).
//!
//! Every field here has a verified layout: the decoded value equals the value the generated corpus
//! was made with (see `docs/aep-format.md`, sections 4 and 5, for the evidence per field). Fields that
//! the corpus does not decide are not decoded; the raw bytes stay reachable through the chunk.
use crate::bytes::{array, be_i32, be_u16, be_u32, cstr, text, until_nul};
use crate::typed::{Comp, Item, Layer, TimeBase, utf8_child};
/// An exact fraction. Used for times (`seconds = num / den`) and for the pixel aspect ratio. The
/// fields hold the stored values unreduced; [`Rational::reduced`] normalises.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Rational {
pub num: i64,
pub den: i64,
}
impl Rational {
/// A fraction with a positive denominator, reduced; `None` for a zero denominator.
pub fn new(num: i64, den: i64) -> Option<Self> {
Self { num, den }.reduced()
}
/// The value as `f64`, `None` for a zero denominator.
pub fn to_f64(&self) -> Option<f64> {
(self.den != 0).then(|| self.num as f64 / self.den as f64)
}
/// The same value in lowest terms with a positive denominator, `None` for a zero denominator.
pub fn reduced(&self) -> Option<Self> {
if self.den == 0 {
return None;
}
let (mut a, mut b) = (i128::from(self.num).unsigned_abs(), i128::from(self.den).unsigned_abs());
let (mut x, mut y) = (a, b);
while y != 0 {
(x, y) = (y, x % y);
}
if x == 0 {
x = 1;
}
a /= x;
b /= x;
let negative = (self.num < 0) != (self.den < 0);
let num = i64::try_from(a).ok()?;
let den = i64::try_from(b).ok()?;
Some(Self { num: if negative { num.checked_neg()? } else { num }, den })
}
/// `self + other * factor`, exact, `None` on a zero denominator or overflow.
fn plus_scaled(&self, other: &Rational, factor: &Rational) -> Option<Rational> {
if self.den == 0 || other.den == 0 || factor.den == 0 {
return None;
}
// other * factor = (other.num * factor.num) / (other.den * factor.den)
let scaled_num = i128::from(other.num).checked_mul(i128::from(factor.num))?;
let scaled_den = i128::from(other.den).checked_mul(i128::from(factor.den))?;
let den = i128::from(self.den).checked_mul(scaled_den)?;
let num = i128::from(self.num).checked_mul(scaled_den)?.checked_add(scaled_num.checked_mul(i128::from(self.den))?)?;
Rational { num: i64::try_from(num).ok()?, den: i64::try_from(den).ok()? }.reduced()
}
}
/// The layer quality switch, `ldta` byte 5.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Quality {
/// `1`
Draft,
/// `2`
Best,
/// Any other value (`0` on cameras and lights; wireframe was not sampled).
Other(u8),
}
/// The blend mode, `ldta` byte 99. Six modes were sampled; any other mode is kept as its raw code.
/// The codes 2, 4, 5, 6 and 7 coincide with the numbers of the After Effects plug-in transfer
/// modes; Difference is 26.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlendMode {
/// `2`
Normal,
/// `4`
Add,
/// `5`
Multiply,
/// `6`
Screen,
/// `7`
Overlay,
/// `26`
Difference,
/// Any other value (not sampled; `0` on cameras and lights).
Other(u8),
}
impl BlendMode {
/// The mode for a code.
pub fn from_code(code: u8) -> Self {
match code {
2 => Self::Normal,
4 => Self::Add,
5 => Self::Multiply,
6 => Self::Screen,
7 => Self::Overlay,
26 => Self::Difference,
other => Self::Other(other),
}
}
/// The code as stored.
pub fn code(&self) -> u8 {
match self {
Self::Normal => 2,
Self::Add => 4,
Self::Multiply => 5,
Self::Screen => 6,
Self::Overlay => 7,
Self::Difference => 26,
Self::Other(code) => *code,
}
}
}
/// The light type, `ldta` `u32` at byte 136 of a light layer (0 on every other layer).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LightType {
/// `0` (701)
Parallel,
/// `1`
Spot,
/// `2`
Point,
/// `3` (702; a light created as an environment light by script without the Advanced 3D
/// renderer is stored as an ambient light too, 704)
Ambient,
/// Any other value (an environment light was not sampled).
Other(u32),
}
/// The layer type, `ldta` `u32` at byte 128.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayerType {
/// `0`: solid, footage, precomp or null object (an AV layer).
Av,
/// `1`
Light,
/// `2`
Camera,
/// `3`
Text,
/// `4`
Shape,
/// Any other value.
Other(u32),
}
/// The decoded fields of a layer's `ldta` chunk (164 bytes; the fields below need the first 140).
///
/// Times are stored as a numerator and a denominator (the denominator is the composition's
/// timescale, 1 in a precomp layer). The in and out points are stored **relative to the start**:
/// the absolute in point is `start + in * stretch`, see [`LayerHeader::in_point`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LayerHeader {
/// The layer id (unique in the project); parent links use it.
pub id: u32,
pub quality: Quality,
/// The numerator of the time stretch (signed `i32` at byte 8). The stretch is the exact ratio
/// `stretch / stretch_den`: `1/1` = 100 %, `2/1` = 200 %, `1/2` = 50 %, `3/2` = 150 %, `-1/1` =
/// -100 % (a time-reversed layer, 981), `-1/2` = -50 % (983), see
/// [`LayerHeader::stretch_ratio`].
pub stretch: i32,
/// The denominator of the time stretch (`u32` at byte 108; 1 in every file before 50 % was
/// sampled).
pub stretch_den: u32,
/// The layer start time, as stored.
pub start: Rational,
/// The in point relative to the start, as stored.
pub in_relative: Rational,
/// The out point relative to the start, as stored.
pub out_relative: Rational,
/// Bytes 37, 38 and 39 of `ldta`: the switch bits (see the `is_*` methods).
pub flag_bytes: [u8; 3],
/// The id of the source item (`ldta` byte 40), `None` for the values `0` (shape, text, camera)
/// and `0xffff_ffff` (light).
pub source_id: Option<u32>,
/// The label colour index (`ldta` byte 61: 1 red, 5, 8 blue, ...).
pub label: u8,
/// The copy of the layer name at byte 64 (31 characters at most; the layer's `Utf8` child holds
/// the full name).
pub name_copy: String,
pub blend_mode: BlendMode,
pub layer_type: LayerType,
/// The id of the parent layer, `None` when there is none.
pub parent_id: Option<u32>,
/// The `u32` at byte 136 (the light type of a light layer, 0 elsewhere), see
/// [`LayerHeader::light_type`].
pub light_type_code: u32,
}
impl LayerHeader {
/// Decodes an `ldta` body; `None` when it is shorter than 140 bytes.
pub fn parse(ldta: &[u8]) -> Option<Self> {
let time = |at: usize| Some(Rational { num: i64::from(be_i32(ldta, at)?), den: i64::from(be_u32(ldta, at.checked_add(4)?)?) });
let source = be_u32(ldta, 40)?;
let parent = be_u32(ldta, 132)?;
Some(Self {
id: be_u32(ldta, 0)?,
quality: match *ldta.get(5)? {
1 => Quality::Draft,
2 => Quality::Best,
other => Quality::Other(other),
},
stretch: be_i32(ldta, 8)?,
stretch_den: be_u32(ldta, 108)?,
start: time(12)?,
in_relative: time(20)?,
out_relative: time(28)?,
flag_bytes: array::<3>(ldta, 37)?,
source_id: (source != 0 && source != u32::MAX).then_some(source),
label: *ldta.get(61)?,
name_copy: text(until_nul(ldta.get(64..96)?)),
blend_mode: BlendMode::from_code(*ldta.get(99)?),
layer_type: match be_u32(ldta, 128)? {
0 => LayerType::Av,
1 => LayerType::Light,
2 => LayerType::Camera,
3 => LayerType::Text,
4 => LayerType::Shape,
other => LayerType::Other(other),
},
parent_id: (parent != 0).then_some(parent),
light_type_code: be_u32(ldta, 136)?,
})
}
fn flag(&self, byte: usize, mask: u8) -> bool {
self.flag_bytes.get(byte).is_some_and(|b| b & mask != 0)
}
/// Byte 37 bit `0x02`: guide layer.
pub fn is_guide(&self) -> bool {
self.flag(0, 0x02)
}
/// Byte 38 bit `0x02`: adjustment layer.
pub fn is_adjustment(&self) -> bool {
self.flag(1, 0x02)
}
/// Byte 38 bit `0x04`: the 3D layer switch.
pub fn is_three_d(&self) -> bool {
self.flag(1, 0x04)
}
/// Byte 38 bit `0x40`: the layer orients itself towards its point of interest. Set on two-node
/// cameras (byte 38 is `0x44`) and on all lights, clear on a one-node camera (`0x04`).
pub fn is_auto_oriented(&self) -> bool {
self.flag(1, 0x40)
}
/// Byte 38 bit `0x08`: solo.
pub fn is_solo(&self) -> bool {
self.flag(1, 0x08)
}
/// Byte 38 bit `0x80`: the layer was created as a null object.
pub fn is_null_object(&self) -> bool {
self.flag(1, 0x80)
}
/// Byte 39 bit `0x01`: the video switch (the layer's eye icon; `enabled` in the scripting API).
pub fn is_video_enabled(&self) -> bool {
self.flag(2, 0x01)
}
/// The same as [`LayerHeader::is_video_enabled`].
pub fn is_enabled(&self) -> bool {
self.is_video_enabled()
}
/// Byte 39 bit `0x02`: the audio switch (`audioEnabled`).
pub fn is_audio_enabled(&self) -> bool {
self.flag(2, 0x02)
}
/// Byte 39 bit `0x04`: the effects switch (`effectsActive`).
pub fn is_effects_enabled(&self) -> bool {
self.flag(2, 0x04)
}
/// Byte 39 bit `0x08`: the motion blur switch.
pub fn is_motion_blur(&self) -> bool {
self.flag(2, 0x08)
}
/// Byte 39 bit `0x20`: locked.
pub fn is_locked(&self) -> bool {
self.flag(2, 0x20)
}
/// Byte 39 bit `0x40`: shy.
pub fn is_shy(&self) -> bool {
self.flag(2, 0x40)
}
/// Byte 39 bit `0x80`: collapse transformations / continuously rasterize. Shape and text
/// layers have it set from creation.
pub fn collapses_transformations(&self) -> bool {
self.flag(2, 0x80)
}
/// The light type of a light layer: parallel 0, spot 1, point 2, ambient 3 (`None` for any
/// other layer type).
pub fn light_type(&self) -> Option<LightType> {
(self.layer_type == LayerType::Light).then_some(match self.light_type_code {
0 => LightType::Parallel,
1 => LightType::Spot,
2 => LightType::Point,
3 => LightType::Ambient,
other => LightType::Other(other),
})
}
/// The time stretch as an exact reduced ratio (`stretch / stretch_den`: 50 % is `1/2`, 150 %
/// is `3/2`); `None` for a zero denominator.
pub fn stretch_ratio(&self) -> Option<Rational> {
Rational::new(i64::from(self.stretch), i64::from(self.stretch_den))
}
/// 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()?)
}
/// The absolute out point, `start + out * stretch`, exact and reduced. For a footage layer the
/// stored denominator is the footage time base (the sample rate of an audio layer, the frame
/// rate of an image sequence), not the composition timescale.
pub fn out_point(&self) -> Option<Rational> {
self.start.plus_scaled(&self.out_relative, &self.stretch_ratio()?)
}
}
impl<'f, 'a> Layer<'f, 'a> {
/// The layer id (`ldta` byte 0).
pub fn id(&self) -> Option<u32> {
be_u32(self.chunk.child(b"ldta")?.bytes()?, 0)
}
/// The decoded `ldta`, see [`LayerHeader`].
pub fn header(&self) -> Option<LayerHeader> {
LayerHeader::parse(self.chunk.child(b"ldta")?.bytes()?)
}
/// The video switch (byte 39 bit `0x01`), `enabled` in the scripting API.
pub fn is_enabled(&self) -> Option<bool> {
self.header().map(|h| h.is_video_enabled())
}
/// The audio switch (byte 39 bit `0x02`), `audioEnabled`.
pub fn is_audio_enabled(&self) -> Option<bool> {
self.header().map(|h| h.is_audio_enabled())
}
/// The effects switch (byte 39 bit `0x04`), `effectsActive`.
pub fn is_effects_enabled(&self) -> Option<bool> {
self.header().map(|h| h.is_effects_enabled())
}
}
/// The renderer of a composition (`LIST PRin` / `prin`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Renderer {
/// The match name (`ADBE Escher` for the Classic 3D renderer in the base project,
/// `ADBE Calder` for Advanced 3D).
pub match_name: String,
/// The display name (`Classic 3D`, `Advanced 3D`).
pub display_name: String,
}
/// The decoded fields of a composition's `cdta` chunk (204 bytes; the fields below need 176).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CompHeader {
/// Frame duration (`u32` at byte 4) and timescale (`u32` at byte 8).
pub time_base: TimeBase,
/// The frame rate as 16.16 fixed point (`u32` at byte 156).
pub frame_rate_fixed: u32,
/// The composition duration in time units.
pub duration_units: u32,
/// The work area start in time units.
pub work_area_start_units: u32,
/// The work area end (start + duration) in time units; `None` when it is the whole
/// composition (stored as `0xffff_ffff`).
pub work_area_end_units: Option<u32>,
/// The background colour as R, G, B (bytes 52 to 54), 8 bits per channel: 0.5 is stored as 128
/// and reads back as 128/255.
pub background: [u8; 3],
/// The shutter angle in degrees.
pub shutter_angle: u32,
pub width: u16,
pub height: u16,
/// The pixel aspect ratio as stored: numerator and denominator.
pub pixel_aspect: Rational,
/// The composition's motion blur switch.
pub motion_blur: bool,
/// The shutter phase in degrees (`i32` at byte 180, 0 by default, -90 in the sample); `None`
/// when the chunk ends before byte 184.
pub shutter_phase: Option<i32>,
/// The display start time (the comp start timecode) as `num / den` seconds: `u32` at byte 164
/// over `u32` at byte 168 (0/1 by default; display start frame 100 at 25 fps is 102400/25600).
/// `None` when the chunk ends before byte 172.
pub display_start: Option<Rational>,
}
impl CompHeader {
/// Decodes a `cdta` body; `None` when it is shorter than 176 bytes.
pub fn parse(cdta: &[u8]) -> Option<Self> {
let work_end = be_u32(cdta, 36)?;
Some(Self {
time_base: TimeBase { frame_duration: be_u32(cdta, 4)?, timescale: be_u32(cdta, 8)? },
frame_rate_fixed: be_u32(cdta, 156)?,
duration_units: be_u32(cdta, 44)?,
work_area_start_units: be_u32(cdta, 28)?,
work_area_end_units: (work_end != u32::MAX).then_some(work_end),
background: array::<3>(cdta, 52)?,
shutter_angle: be_u32(cdta, 172)?,
width: be_u16(cdta, 140)?,
height: be_u16(cdta, 142)?,
pixel_aspect: Rational { num: i64::from(be_u32(cdta, 144)?), den: i64::from(be_u32(cdta, 148)?) },
motion_blur: cdta.get(139)? & 0x08 != 0,
shutter_phase: be_i32(cdta, 180),
display_start: be_u32(cdta, 164).zip(be_u32(cdta, 168)).map(|(num, den)| Rational { num: i64::from(num), den: i64::from(den) }),
})
}
/// Frames per second from the time base (`timescale / frame_duration`).
pub fn frame_rate(&self) -> Option<f64> {
self.time_base.frame_rate()
}
/// The duration in seconds.
pub fn duration_seconds(&self) -> Option<f64> {
self.time_base.seconds(i32::try_from(self.duration_units).ok()?)
}
}
impl<'f, 'a> Comp<'f, 'a> {
/// The decoded `cdta`, see [`CompHeader`].
pub fn header(&self) -> Option<CompHeader> {
CompHeader::parse(self.item.child(b"cdta")?.bytes()?)
}
/// The composition name (the item's `Utf8` child).
pub fn name(&self) -> Option<String> {
utf8_child(self.item).filter(|n| !n.is_empty())
}
/// The item this composition data belongs to.
pub fn item(&self) -> Item<'f, 'a> {
Item { chunk: self.item }
}
/// The renderer (`LIST PRin` / `prin`: match name at byte 4, display name at byte 52, 32
/// bytes each).
pub fn renderer(&self) -> Option<Renderer> {
let prin = self.item.child_list(b"PRin")?.child(b"prin")?.bytes()?;
Some(Renderer { match_name: cstr(prin, 4, 32)?, display_name: cstr(prin, 52, 32)? })
}
}
File diff suppressed because it is too large Load Diff
+322
View File
@@ -0,0 +1,322 @@
//! Keyframe records, property flags and expressions.
//!
//! Keyframe times are **layer time**, in units of the property's own time scale
//! ([`Property::time_scale`], equal to the composition's timescale in every sample).
//!
//! Every record starts with an 8-byte header: `i32` time, `u8` at byte 4 = the interpolation of the
//! **incoming** side, `u8` at byte 5 = the **outgoing** side (1 linear, 2 bezier, 3 hold), and a
//! `u16` of flags (label, roving). The rest depends on the property header (`tdb4`), which selects
//! one of two templates for `n` value components:
//!
//! * **plain** (`tdb4` byte 7 = 0; Opacity, Rotation, Scale, 2-D properties, sliders): the value
//! (`n` x `f64`) at byte 8, then four `f64` per component of ease, type-major (`[in speed x n]
//! [in influence x n][out speed x n][out influence x n]`). Size `8 + 40 n`.
//! * **spatial** (`tdb4` byte 7 != 0; Position with `n` = 3, colours with `n` = 4): a `u32` at 8, the
//! arc length (`f64`) at 16, the four ease slots at 24 to 55, the value (`n` x `f64`) at 56, then
//! the spatial in tangent and out tangent (`n` x `f64` each). Size `56 + 24 n`.
use crate::bytes::{be_f64, be_u16, be_u32, text};
use crate::typed::{Keyframe, Property};
/// A keyframe interpolation type (a byte of the record header).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Interpolation {
/// `1`
Linear,
/// `2`
Bezier,
/// `3`
Hold,
/// Any other value.
Other(u8),
}
impl Interpolation {
fn from_byte(b: u8) -> Self {
match b {
1 => Self::Linear,
2 => Self::Bezier,
3 => Self::Hold,
other => Self::Other(other),
}
}
}
/// What a keyframe record is, judged by the property header (when the list belongs to a property)
/// and the record size.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyframeKind {
/// The plain template: `8 + 40 n` bytes, 48 for one component (Opacity, Rotation, Slider), 88 for
/// two (Mask Feather, Rectangle Size), 128 for three (Scale).
Plain { components: usize },
/// The spatial template: `56 + 24 n` bytes, 128 for Position (3 components), 152 for a colour (4).
Spatial { components: usize },
/// 64 bytes: a mask path key; the path itself is in the matching `shap` chunk. The ease sits at
/// byte 24 as in the spatial template (599, 700: speed 0, influences 0.75 / 0.20 / 0.50); the
/// `f64` at byte 16 is 1 or 2 on a first key and 0 on a last one (093, 599, 700; meaning not
/// decoded).
MaskPath,
/// 16 bytes: a marker (time and two hold bytes).
Marker,
/// Any other size.
Other(usize),
}
/// The ease of a key: speed and influence of the incoming and outgoing side. Speed is in stored
/// value units per second (for Opacity a fraction, so 100 times smaller than the percent shown in
/// the UI; for Position pixels per second); influence is a fraction (20 % is `0.2`). After Effects
/// reports the first key's incoming speed and the last key's outgoing speed as 0, but the file
/// keeps the requested values, so these two slots are not meaningful.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct KeyEase {
pub in_speed: f64,
pub in_influence: f64,
pub out_speed: f64,
pub out_influence: f64,
}
/// The fields of a spatial keyframe record.
#[derive(Debug, Clone, PartialEq)]
pub struct SpatialKey {
/// The `u32` at byte 8: `1` normally, `0` after the spatial interpolation was changed to
/// non-auto-bezier / non-continuous (the two switches were changed together).
pub auto_bezier_flag: u32,
/// The `f64` at byte 16: the arc length of the segment to the next key, updated lazily by
/// After Effects (0 right after creation). Safe to ignore.
pub segment_length: f64,
/// The four `f64` at bytes 24, 32, 40 and 48 as stored: in speed, in influence, out speed, out
/// influence (see [`KeyEase`]).
pub ease: [f64; 4],
/// The value (x, y, z in pixels for Position; ARGB 0..255 for a colour), from byte 56.
pub value: Vec<f64>,
/// The spatial in tangent as an offset from the value.
pub in_tangent: Vec<f64>,
/// The spatial out tangent as an offset from the value.
pub out_tangent: Vec<f64>,
}
fn doubles(b: &[u8], at: usize, n: usize) -> Option<Vec<f64>> {
(0..n).map(|i| be_f64(b, at.checked_add(i.checked_mul(8)?)?)).collect()
}
fn ease_at(b: &[u8], at: usize) -> Option<KeyEase> {
Some(KeyEase {
in_speed: be_f64(b, at)?,
in_influence: be_f64(b, at.checked_add(8)?)?,
out_speed: be_f64(b, at.checked_add(16)?)?,
out_influence: be_f64(b, at.checked_add(24)?)?,
})
}
impl<'f> Keyframe<'f> {
/// The record kind. For a list that belongs to a property, the header's component count and
/// template flag decide; without a property, 48 bytes is read as plain with one component and
/// 128 bytes as spatial with three.
pub fn kind(&self) -> KeyframeKind {
let len = self.record.len();
if let Some(layout) = self.layout {
let n = usize::from(layout.components);
if n > 0 {
if layout.spatial && Some(len) == n.checked_mul(24).and_then(|v| v.checked_add(56)) {
return KeyframeKind::Spatial { components: n };
}
if !layout.spatial && Some(len) == n.checked_mul(40).and_then(|v| v.checked_add(8)) {
return KeyframeKind::Plain { components: n };
}
}
}
match (len, self.layout) {
(64, _) => KeyframeKind::MaskPath,
(16, _) => KeyframeKind::Marker,
(48, None) => KeyframeKind::Plain { components: 1 },
(128, None) => KeyframeKind::Spatial { components: 3 },
(other, _) => KeyframeKind::Other(other),
}
}
/// The time in seconds given the property's time scale (units per second).
pub fn seconds(&self, time_scale: u32) -> Option<f64> {
if time_scale == 0 {
return None;
}
Some(f64::from(self.time_units()?) / f64::from(time_scale))
}
/// The interpolation of the incoming side: the byte at offset 4.
pub fn interpolation_in(&self) -> Option<Interpolation> {
self.record.get(4).copied().map(Interpolation::from_byte)
}
/// The interpolation of the outgoing side: the byte at offset 5.
pub fn interpolation_out(&self) -> Option<Interpolation> {
self.record.get(5).copied().map(Interpolation::from_byte)
}
/// The flags word at byte 6.
pub fn flags(&self) -> Option<u16> {
be_u16(self.record, 6)
}
/// The keyframe label: bits 6 to 9 of the flags (label 9 gives `0x0247` on a spatial key).
pub fn label(&self) -> Option<u8> {
u8::try_from((self.flags()? >> 6) & 0x0f).ok()
}
/// True when the key is roving: bit `0x20` of the flags.
pub fn is_roving(&self) -> Option<bool> {
Some(self.flags()? & 0x0020 != 0)
}
/// The number of value components of a plain or spatial record.
pub fn components(&self) -> Option<usize> {
match self.kind() {
KeyframeKind::Plain { components } | KeyframeKind::Spatial { components } => Some(components),
KeyframeKind::MaskPath | KeyframeKind::Marker | KeyframeKind::Other(_) => None,
}
}
/// The stored value of a plain (from byte 8) or spatial (from byte 56) record, in the units of
/// the property's static value (fractions for Opacity and Scale, ARGB 0..255 for colours).
pub fn value(&self) -> Option<Vec<f64>> {
match self.kind() {
KeyframeKind::Plain { components } => doubles(self.record, 8, components),
KeyframeKind::Spatial { components } => doubles(self.record, 56, components),
KeyframeKind::MaskPath | KeyframeKind::Marker | KeyframeKind::Other(_) => None,
}
}
/// The value of a record with one component (Opacity, Rotation, a slider).
pub fn scalar_value(&self) -> Option<f64> {
match self.kind() {
KeyframeKind::Plain { components: 1 } => be_f64(self.record, 8),
_ => None,
}
}
/// 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`].
pub fn ease(&self) -> Option<KeyEase> {
match self.kind() {
KeyframeKind::Plain { components: 1 } => ease_at(self.record, 16),
KeyframeKind::Spatial { .. } | KeyframeKind::MaskPath => ease_at(self.record, 24),
_ => 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
/// block layout with Scale `n = 3` and Mask Feather `n = 2` keys whose ease was the same in
/// every dimension; that different values sit in the slots of their dimension is inferred).
/// A spatial record (Position, colours) has one ease entry for all components, so only
/// `component == 0` returns it. For one component this is [`Keyframe::ease`].
pub fn ease_component(&self, component: usize) -> Option<KeyEase> {
match self.kind() {
KeyframeKind::Plain { components } if component < components => {
let block = components.checked_mul(8)?;
let first = block.checked_add(8)?;
let at = |k: usize| first.checked_add(block.checked_mul(k)?)?.checked_add(component.checked_mul(8)?);
Some(KeyEase {
in_speed: be_f64(self.record, at(0)?)?,
in_influence: be_f64(self.record, at(1)?)?,
out_speed: be_f64(self.record, at(2)?)?,
out_influence: be_f64(self.record, at(3)?)?,
})
}
KeyframeKind::Spatial { .. } if component == 0 => ease_at(self.record, 24),
_ => None,
}
}
/// The ease of every value component of a plain record, see [`Keyframe::ease_component`]
/// (one entry for a spatial record).
pub fn ease_components(&self) -> Option<Vec<KeyEase>> {
let n = match self.kind() {
KeyframeKind::Plain { components } => components,
KeyframeKind::Spatial { .. } => 1,
KeyframeKind::MaskPath | KeyframeKind::Marker | KeyframeKind::Other(_) => return None,
};
(0..n).map(|i| self.ease_component(i)).collect()
}
/// 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 };
let r = self.record;
let span = n.checked_mul(8)?;
let ease = ease_at(r, 24)?;
Some(SpatialKey {
auto_bezier_flag: be_u32(r, 8)?,
segment_length: be_f64(r, 16)?,
ease: [ease.in_speed, ease.in_influence, ease.out_speed, ease.out_influence],
value: doubles(r, 56, n)?,
in_tangent: doubles(r, 56usize.checked_add(span)?, n)?,
out_tangent: doubles(r, 56usize.checked_add(span.checked_mul(2)?)?, n)?,
})
}
}
/// The bytes of a property header that mark an expression: bytes 76, 77 and 120 of `tdb4` are all 1
/// when the property has an expression (76 and 77 are also 1 on a camera's auto-computed Position,
/// which has none). Byte 119 is 1 when the expression is disabled.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExpressionFlags {
pub byte_76: u8,
pub byte_77: u8,
/// 1 when the expression is disabled (`expression.disable_all`); the text stays in the file.
pub byte_119: u8,
pub byte_120: u8,
}
impl ExpressionFlags {
/// True when byte 119 is 1.
pub fn disabled(&self) -> bool {
self.byte_119 == 1
}
}
impl<'f, 'a> Property<'f, 'a> {
/// The time scale (units per second) of this property's keyframe times: the `u32` at byte 12
/// of `tdb4` (25600 at 25 fps, 30720 at 30 fps, 23976 at 29.97 and 23.976 fps).
pub fn time_scale(&self) -> Option<u32> {
be_u32(self.header()?, 12)
}
/// The property's `tdsb` flags: `1` for a property that was written (non-default), `3` for
/// the default state.
pub fn flags(&self) -> Option<u32> {
be_u32(self.chunk.child(b"tdsb")?.bytes()?, 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> {
self.chunk.child(b"Utf8").and_then(|c| c.bytes()).map(text)
}
/// The expression flag bytes of `tdb4`.
pub fn expression_flags(&self) -> Option<ExpressionFlags> {
let h = self.header()?;
Some(ExpressionFlags { byte_76: *h.get(76)?, byte_77: *h.get(77)?, byte_119: *h.get(119)?, byte_120: *h.get(120)? })
}
/// Whether the expression is enabled: `None` when the property has no expression (byte 120 is
/// not 1 or there is no `Utf8` text), else `Some(false)` when byte 119 marks it disabled. Byte
/// 119 also changes by itself on built-in view layers after a save, so it only counts together
/// with an expression.
pub fn expression_enabled(&self) -> Option<bool> {
let flags = self.expression_flags()?;
if flags.byte_120 != 1 || self.expression().is_none() {
return None;
}
Some(!flags.disabled())
}
/// The value of the first keyframe (plain or spatial record), for reading an animated property
/// at its first key.
pub fn first_key_value(&self) -> Option<Vec<f64>> {
self.keys()?.keyframes().next()?.value()
}
}
+65
View File
@@ -0,0 +1,65 @@
//! After Effects project (`.aep`, `.aepx`) container reader and writer.
//!
//! An `.aep` is a `RIFX` container (big-endian RIFF) with form type `Egg!`. This crate reads it
//! into a lossless chunk tree ([`AepFile`]) and writes it back byte for byte. The XML form of a
//! project (`.aepx`) is read into the same tree by [`read_aepx`]; [`parse_any`] picks the reader
//! by content. See
//! `docs/aep-format.md` for the observed format and how it was established (clean room: only
//! files we generated ourselves, one change per file).
//!
//! [`Project::new`] opens a typed, read-only view over the tree: items, compositions
//! ([`CompHeader`]), layers ([`LayerHeader`], [`Transform`], effects, masks, text documents,
//! markers), properties, keyframes and footage. Only fields whose layout was verified against the
//! values the test files were made with are decoded; every accessor returns `None` (or an empty
//! list) on damaged data instead of failing.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
// Ranges and borrowed bytes are passed around as plain tuples, as in EffectCraft, which allows this lint.
#![allow(clippy::type_complexity)]
mod aepx;
mod arbitrary;
mod bytes;
mod camera;
mod chunk;
mod effects;
mod error;
mod footage;
mod header;
pub mod index;
mod keys;
mod masks;
mod matte;
mod read;
mod settings;
mod shapes;
mod textdoc;
mod typed;
mod values;
mod version;
mod write;
pub use aepx::{AepxDrafts, index_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,
};
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, Pard};
pub use error::AepError;
pub use footage::{Footage, PsdLayer, SequenceInfo};
pub use header::{BlendMode, CompHeader, LayerHeader, LayerType, LightType, Quality, Rational, Renderer};
pub use index::{Draft, Node, NodeWalk, Nodes, Root, TreeIndex};
pub use keys::{ExpressionFlags, Interpolation, KeyEase, KeyframeKind, SpatialKey};
pub use masks::{Mask, MaskAtom, MaskMode, PathVertex, ShapePath};
pub use matte::{MatteMode, TrackMatte};
pub use read::{Limits, parse, parse_with_limits};
pub use settings::{ProjectSettings, TimeDisplay, WorkingSpace};
pub use shapes::{GradientType, PolystarType, ShapeDetail, ShapeGroup, ShapeItem, Stroke, StrokeCap, StrokeJoin};
pub use textdoc::{
AutoKern, Caps, CueType, FontBaseline, Justification, KernRun, Marker, ParagraphRun, StyleRun, TextBox, TextDocument, TextValue, parse_text_dict,
};
pub use typed::{Comp, Item, ItemKind, KeyLayout, KeyList, Keyframe, Layer, ListHeader, Project, PropEntry, PropGroup, PropNode, Property, TimeBase};
pub use values::{Orientation, OrientationKey, TimeRemap, TimeRemapKey, Tracked, Transform, ValueSource};
pub use version::AeVersion;
pub use write::{write, write_to};
+250
View File
@@ -0,0 +1,250 @@
//! Masks and bezier paths.
//!
//! A layer's masks are in `tdgp[ADBE Mask Parade]`: one `mkif` chunk (mode and invert switch) next
//! to one `tdgp[ADBE Mask Atom]` per mask. The atom holds the optional properties feather, opacity
//! and expansion (stored only when not at their defaults) and `om-s[ADBE Mask Shape]`: the path
//! 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::bytes::{be_f32, be_u32, until_nul};
use crate::index::Node;
use crate::typed::{KeyList, Layer, PropGroup, PropNode, Property};
use crate::values::{Tracked, read};
/// The mask mode (`mkif` `u32` at byte 4).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MaskMode {
/// `0` (329)
None,
/// `1`
Add,
/// `2`
Subtract,
/// `3`
Intersect,
/// `4`
Lighten,
/// `5`
Darken,
/// `6`
Difference,
/// Any other value (not sampled).
Other(u32),
}
impl MaskMode {
/// The mode for a stored id.
pub fn from_id(id: u32) -> Self {
match id {
0 => Self::None,
1 => Self::Add,
2 => Self::Subtract,
3 => Self::Intersect,
4 => Self::Lighten,
5 => Self::Darken,
6 => Self::Difference,
other => Self::Other(other),
}
}
}
/// A vertex of a bezier path with its two control points as absolute positions.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PathVertex {
pub position: [f64; 2],
/// The control point of the incoming segment.
pub in_handle: [f64; 2],
/// The control point of the outgoing segment.
pub out_handle: [f64; 2],
}
impl PathVertex {
/// The in tangent: the in handle minus the vertex (what the scripting API calls `inTangents`).
pub fn in_tangent(&self) -> [f64; 2] {
[self.in_handle[0] - self.position[0], self.in_handle[1] - self.position[1]]
}
/// The out tangent: the out handle minus the vertex (`outTangents`).
pub fn out_tangent(&self) -> [f64; 2] {
[self.out_handle[0] - self.position[0], self.out_handle[1] - self.position[1]]
}
}
/// One path shape (`LIST shap`): a bounding box and the control points normalised inside it.
///
/// The `shph` chunk holds a magic word whose last byte carries the flags (`0x01` closed, `0x09` open:
/// bit `0x08`), the box (left, top, right, bottom) as four `f32`, and the byte at offset 20 (`1` in
/// every sample). The box is the box of the vertices **and** their handles. The `list` holds three
/// points per vertex, each as two `f32` in [0, 1] of the box, in the order `[vertex i, out handle i,
/// in handle i + 1]`; the last record is the in handle of vertex 0. For masks the box is normalised
/// to the **layer** size (the size of the layer's source, not the composition's: on a 100x100 solid
/// a 60x40 mask rectangle at the centre has the box `0.2, 0.3, 0.8, 0.7`, 309); for the paths of shape layers it is in pixels. Handles equal their vertex when a
/// vertex has no tangents; a tangent is the handle minus the vertex, without a sign change.
#[derive(Debug, Clone, PartialEq)]
pub struct ShapePath {
/// Left, top, right, bottom.
pub bbox: [f32; 4],
/// The byte at offset 20 of `shph` (`1` in every sample, also for the open path).
pub closed_flag: u8,
/// True for an open path: bit `0x08` of the last byte of the first `shph` word.
pub open: bool,
/// The normalised points as stored, three per vertex.
pub points: Vec<[f32; 2]>,
}
impl ShapePath {
/// Decodes a `LIST shap` (a [`Chunk`](crate::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)?;
let open = shph.get(3)? & 0x08 != 0;
let list = KeyList::from_chunk(shap.child_list(b"list")?)?;
if list.header.record_size != 8 {
return None;
}
let points = list.records().map(|r| Some([be_f32(r, 0)?, be_f32(r, 4)?])).collect::<Option<Vec<_>>>()?;
Some(Self { bbox, closed_flag, open, points })
}
/// The number of vertices (`points / 3`).
pub fn vertex_count(&self) -> usize {
self.points.len() / 3
}
/// The vertices with absolute control points: `box.left + u * (box.right - box.left)` (and the
/// same for y), multiplied by `scale` (the layer size in pixels for a mask, `(1, 1)` for a
/// shape layer path).
pub fn vertices(&self, scale: (f64, f64)) -> Vec<PathVertex> {
let [left, top, right, bottom] = self.bbox.map(f64::from);
let abs = |p: Option<&[f32; 2]>| -> [f64; 2] {
let [u, v] = p.copied().unwrap_or([0.0, 0.0]).map(f64::from);
[(left + u * (right - left)) * scale.0, (top + v * (bottom - top)) * scale.1]
};
let n = self.vertex_count();
let total = n.saturating_mul(3);
(0..n)
.map(|i| {
let base = i.saturating_mul(3);
PathVertex {
position: abs(self.points.get(base)),
out_handle: abs(self.points.get(base.saturating_add(1))),
// The in handle of vertex i is the record before vertex i (the last one for vertex 0).
in_handle: abs(self.points.get(base.saturating_add(total).saturating_sub(1) % total.max(1))),
}
})
.collect()
}
}
/// One mask of a layer.
#[derive(Debug, Clone, PartialEq)]
pub struct Mask {
/// The mask name (`Mask 1`).
pub name: Option<String>,
/// The mode, from this mask's `mkif` (there is one `mkif` per mask, directly before its atom).
pub mode: Option<MaskMode>,
/// The invert switch (`mkif` byte 0).
pub inverted: Option<bool>,
/// The running mask id counter of the layer (`mkif` `u32` at byte 8): 1 for the first mask
/// created on a layer, +1 per mask created later on the same layer (undo does not reset it).
/// A session counter, not a stable id.
pub counter: Option<u32>,
/// Feather in pixels `[x, y]`; absent = `[0, 0]`.
pub feather: Tracked<[f64; 2]>,
/// Opacity in percent (stored as a fraction); absent = 100.
pub opacity_percent: Tracked<f64>,
/// Expansion in pixels; absent = 0.
pub expansion: Tracked<f64>,
/// True when the path has keyframes.
pub path_animated: bool,
/// The path keyframe times in seconds (empty for a static path).
pub path_key_seconds: Vec<f64>,
/// The path shapes: one for a static path, one per keyframe otherwise.
pub shapes: Vec<ShapePath>,
}
fn mask_from_atom(atom: &PropGroup<'_, '_>, mkif: Option<&[u8]>) -> Mask {
let opacity = read(atom, "ADBE Mask Opacity", [100.0], 100.0);
let expansion = read(atom, "ADBE Mask Offset", [0.0], 1.0);
let mut mask = Mask {
name: atom.user_name(),
mode: mkif.and_then(|m| be_u32(m, 4)).map(MaskMode::from_id),
inverted: mkif.and_then(|m| m.first()).map(|b| *b != 0),
counter: mkif.and_then(|m| be_u32(m, 8)),
feather: read(atom, "ADBE Mask Feather", [0.0, 0.0], 1.0),
opacity_percent: Tracked { value: opacity.value[0], source: opacity.source },
expansion: Tracked { value: expansion.value[0], source: expansion.source },
path_animated: false,
path_key_seconds: Vec::new(),
shapes: Vec::new(),
};
if let Some(PropNode::Other(oms)) = atom.get("ADBE Mask Shape") {
if let Some(prop) = oms.child_list(b"tdbs").and_then(Property::from_chunk) {
mask.path_animated = prop.is_animated();
if let (Some(keys), Some(scale)) = (prop.keys(), prop.time_scale()) {
mask.path_key_seconds = keys.keyframes().filter_map(|k| k.seconds(scale)).collect();
}
}
if let Some(omks) = oms.child_list(b"omks") {
mask.shapes = omks.children().filter(|c| c.is_list(b"shap")).filter_map(ShapePath::from_chunk).collect();
}
}
mask
}
/// 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.
#[derive(Debug, Clone)]
pub struct MaskAtom<'f, 'a> {
/// The decoded mask (as [`Layer::masks`] returns it).
pub mask: Mask,
/// The atom group (`tdgp[ADBE Mask Atom]`).
pub atom: PropGroup<'f, 'a>,
/// The path property (`om-s[ADBE Mask Shape]/tdbs`): its key list holds one 64-byte record
/// per path keyframe (time, interpolation, label and roving flags; 093).
pub path: Option<Property<'f, 'a>>,
/// Every `LIST shap` of `omks` in file order, `None` where one is malformed, so that index `i`
/// stays the shape of path keyframe `i` (one entry for a static path).
pub path_shapes: Vec<Option<ShapePath>>,
}
impl<'f, 'a> Layer<'f, 'a> {
/// The layer's masks, in stack order.
pub fn masks(&self) -> Vec<Mask> {
self.mask_atoms().into_iter().map(|m| m.mask).collect()
}
/// The layer's masks with the views of their records, in stack order.
pub fn mask_atoms(&self) -> Vec<MaskAtom<'f, 'a>> {
let Some(root) = self.properties() else { return Vec::new() };
let Some(PropNode::Group(parade)) = root.get("ADBE Mask Parade") else { return Vec::new() };
// Per mask: `tdmn` (Mask Atom), `mkif`, then the atom's `tdgp`.
let mut masks = Vec::new();
let (mut name, mut mkif): (Option<&[u8]>, Option<&[u8]>) = (None, None);
for c in parade.chunk().children() {
if c.is(b"tdmn") {
name = c.bytes();
} else if c.is(b"mkif") {
mkif = c.bytes();
} else if c.is_list(b"tdgp") {
let is_atom = name.take().is_some_and(|n| until_nul(n) == b"ADBE Mask Atom");
if is_atom && let Some(atom) = PropGroup::from_chunk(c) {
let mask = mask_from_atom(&atom, mkif.take());
let (mut path, mut path_shapes) = (None, Vec::new());
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().filter(|c| c.is_list(b"shap")).map(ShapePath::from_chunk).collect();
}
}
masks.push(MaskAtom { mask, atom, path, path_shapes });
}
}
}
masks
}
}
+68
View File
@@ -0,0 +1,68 @@
//! Track mattes: the matte mode and the matte layer, two fields of the layer header `ldta`.
//!
//! Cases 402-408 (a 960x540 grey solid `M` above the red solid `L`): setting a track matte on a
//! layer changes exactly two fields of that layer's `ldta` (and the video switch of the matte
//! layer, which After Effects turns off by itself):
//!
//! * byte 107 (`u8`; bytes 104..106 are 0 in every file of the corpus): the matte mode, 1 alpha
//! (403), 2 alpha inverted (404), 3 luma (405), 4 luma inverted (406), 0 no matte (every other
//! case);
//! * the `u32` at byte 160: the id of the matte layer (`ldta` byte 0 of that layer), `0x1d` = `M`
//! in 403-406 and 408, `0x1b` = `L` in 407, where the matte layer is BELOW the layer it mattes.
//! 0 in every file without a matte.
//!
//! A matte mode with a matte layer id of 0 (or an `ldta` too short to hold the id) has no case in
//! the corpus: After Effects 2026 writes the id. Before After Effects 23.0 a track matte always
//! used the layer directly above (the documented behaviour of those versions), so such a matte is
//! returned with [`TrackMatte::layer`] `None` and the caller decides.
use crate::Layer;
use crate::bytes::be_u32;
/// The matte mode (`ldta` byte 107).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MatteMode {
/// `1` (403)
Alpha,
/// `2` (404)
AlphaInverted,
/// `3` (405)
Luma,
/// `4` (406)
LumaInverted,
/// Any other non-zero value (not sampled).
Other(u8),
}
impl MatteMode {
/// The mode for a stored code; `None` for 0 (no matte).
pub fn from_code(code: u8) -> Option<Self> {
Some(match code {
0 => return None,
1 => Self::Alpha,
2 => Self::AlphaInverted,
3 => Self::Luma,
4 => Self::LumaInverted,
other => Self::Other(other),
})
}
}
/// The track matte of a layer.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TrackMatte {
pub mode: MatteMode,
/// The id of the matte layer (`u32` at `ldta` byte 160); `None` when it is 0 or the header is
/// too short to hold it (the older "layer above" form, see the module documentation).
pub layer: Option<u32>,
}
impl<'f, 'a> Layer<'f, 'a> {
/// The track matte of the layer, `None` when it has none (or the header is unreadable).
pub fn track_matte(&self) -> Option<TrackMatte> {
let ldta = self.chunk().child(b"ldta")?.bytes()?;
let mode = MatteMode::from_code(*ldta.get(107)?)?;
let layer = be_u32(ldta, 160).filter(|id| *id != 0);
Some(TrackMatte { mode, layer })
}
}
+278
View File
@@ -0,0 +1,278 @@
//! Parsing the `RIFX` container into an [`AepFile`].
use std::borrow::Cow;
use crate::bytes::{array, be_u32};
use crate::chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS};
use crate::error::AepError;
/// Bounds for hostile input.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Limits {
/// Deepest list nesting that is parsed (the top level is depth 1). A list or nested chunk
/// whose children would be deeper is kept opaque instead.
pub max_depth: usize,
/// Most chunks a file may contain (counted across all parse attempts) before parsing fails.
pub max_chunks: usize,
}
impl Default for Limits {
fn default() -> Self {
Self { max_depth: 64, max_chunks: 10_000_000 }
}
}
/// Parses an `.aep` with the default [`Limits`].
///
/// # Errors
/// Returns an error when the input is not a well-formed `RIFX`/`Egg!` container at the top level.
/// Odd bodies *inside* the container (a `LIST` whose content is not a chunk sequence) do not
/// fail the parse: they are kept opaque.
pub fn parse(data: &[u8]) -> Result<AepFile<'_>, AepError> {
parse_with_limits(data, Limits::default())
}
/// Parses an `.aep` with explicit [`Limits`].
///
/// # 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::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(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));
}
let available = (data.len() as u64).saturating_sub(8);
if declared < 4 || declared > available {
return Err(AepError::Truncated { declared, available });
}
// `declared <= available < data.len()`, so the end is inside the input.
usize::try_from(declared).map_err(|_| AepError::TooLarge)?.checked_add(8).ok_or(AepError::TooLarge)
}
/// 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> {
data: &'a [u8],
limits: Limits,
count: usize,
}
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 = 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 });
}
self.count = self.count.saturating_add(1);
if self.count > self.limits.max_chunks {
return Err(AepError::TooManyChunks);
}
let body_end = body_start + size;
let body = self.body(id, body_start, body_end, depth)?;
let mut next = body_end;
let mut pad = None;
if size % 2 == 1 && next < end {
pad = Some(self.data.get(next).copied().ok_or(AepError::Malformed { offset: next, what: "missing pad byte" })?);
next += 1;
}
out.push(Chunk { id, body, pad });
pos = next;
}
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) {
Ok(v) => Ok(Some(v)),
Err(e) if e.is_structural() => Ok(None),
Err(e) => Err(e),
}
}
fn slice(&self, start: usize, end: usize) -> &'a [u8] {
self.data.get(start..end).unwrap_or(&[])
}
fn body(&mut self, id: [u8; 4], start: usize, end: usize, depth: usize) -> Result<Body<'a>, AepError> {
let len = end - start;
if id == LIST && len >= 4 {
let list_type = id4(self.data, start).ok_or(AepError::Malformed { offset: start, what: "short read" })?;
let opaque = |p: &Self| Body::OpaqueList { list_type, data: Cow::Borrowed(p.slice(start + 4, end)) };
if depth >= self.limits.max_depth {
return Ok(opaque(self));
}
return Ok(match self.tentative(start + 4, end, depth + 1)? {
Some(children) => Body::List { list_type, children },
None => opaque(self),
});
}
if NESTED_IDS.contains(&id)
&& len >= 8
&& depth < self.limits.max_depth
&& let Some(children) = self.tentative(start, end, depth + 1)?
&& !children.is_empty()
{
return Ok(Body::Chunks(children));
}
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::write(&file).expect("write");
let parsed = parse(&bytes).expect("parse");
assert_eq!(crate::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::write(&f).expect("write"), data);
}
}
+237
View File
@@ -0,0 +1,237 @@
//! Project settings (File ▸ Project Settings): colour depth, working space, working gamma, the two
//! 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::bytes::be_u32;
use crate::chunk::AepFile;
use crate::footage::json_string;
use crate::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)]
pub enum TimeDisplay {
/// Timecode (the base, 620): byte 8 = 0.
Timecode,
/// Frames (629): byte 8 = 1.
Frames,
/// Feet + frames (633, 634): byte 8 = 1 and byte 11 = 1; byte 13 is the frames per foot,
/// 16 for 35 mm (633) and 40 for 16 mm (634).
FeetFrames { frames_per_foot: u8 },
}
/// The working colour space (`cpid` and the JSON `Utf8` after `PwCs`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WorkingSpace {
/// No colour management (623): `cpid` is 16 bytes of `0xff` and the JSON is `{}`.
None,
/// A colour profile, named as After Effects lists it (`baseColorProfile/colorProfileName`):
/// `sRGB IEC61966-2.1` in the base (620), `Rec.709 Gamma 2.4` in 624. The profile data next to
/// the name is kept as stored.
Profile(String),
}
/// The project settings that are decoded.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectSettings {
/// Bits per channel: 8, 16 or 32 (`nhed` byte 15 = 0 / 1 / 2: 621, 622, 620; the same byte
/// is `nnhd` byte 24). `None` for another value.
pub bits_per_channel: Option<u8>,
/// The working space; `None` when the chunks are missing or unreadable.
pub working_space: Option<WorkingSpace>,
/// Working gamma 2.4 (`dwga` `u32` @0 = 1, 625) or 2.2 (0, 620).
pub working_gamma_24: Option<bool>,
/// Linearize Working Space: a 1-byte `lnrp` chunk holding 1 exists (626, 632).
pub linearize: bool,
/// Blend Colors Using 1.0 Gamma: a 1-byte `lnrb` chunk holding 1 exists (627, 632).
pub blend_linear: bool,
/// Compensate for Scene-referred Profiles (`acer` = 1 in the base, 0 in 628).
pub scene_compensation: Option<bool>,
/// The time display style.
pub time_display: Option<TimeDisplay>,
/// Frame count start: `nhed` byte 14 holds 2 for a count from 0 (620) and 1 for a count from
/// 1 (630); this maps 2 to 0 and 1 to 1, anything else to `None`.
pub frame_start: Option<u8>,
}
impl ProjectSettings {
/// Reads the settings from the top-level chunks.
pub fn read(file: &AepFile<'_>) -> ProjectSettings {
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 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),
1 => Some(16),
2 => Some(32),
_ => None,
});
let time_display = match (byte(8), byte(11), byte(13)) {
(Some(0), _, _) => Some(TimeDisplay::Timecode),
(Some(1), Some(0), _) => Some(TimeDisplay::Frames),
(Some(1), Some(1), Some(fpf)) => Some(TimeDisplay::FeetFrames { frames_per_foot: fpf }),
_ => None,
};
let frame_start = byte(14).and_then(|v| match v {
2 => Some(0),
1 => Some(1),
_ => None,
});
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),
working_gamma_24,
linearize: flag(b"lnrp"),
blend_linear: flag(b"lnrb"),
scene_compensation,
time_display,
frame_start,
}
}
}
/// The working space: the `Utf8` right after `PwCs`.
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);
}
// After Effects 26.2.1 saves the profile data without the name (settings-c, 902): the name is
// then the profile's own description (ICC.1 `desc`).
json_string(json, "colorProfileName")
.or_else(|| json_string(json, "colorProfileData").and_then(|b| base64_decode(&b)).and_then(|icc| icc_description(&icc)))
.map(WorkingSpace::Profile)
}
/// Standard base64 (RFC 4648) with or without padding; `None` for any other character.
fn base64_decode(text: &str) -> Option<Vec<u8>> {
let mut out = Vec::with_capacity(text.len() / 4 * 3);
let (mut acc, mut bits) = (0u32, 0u32);
for c in text.bytes().filter(|c| *c != b'=') {
let v = match c {
b'A'..=b'Z' => c - b'A',
b'a'..=b'z' => c - b'a' + 26,
b'0'..=b'9' => c - b'0' + 52,
b'+' => 62,
b'/' => 63,
_ => return None,
};
acc = (acc << 6 | u32::from(v)) & 0x00ff_ffff;
bits += 6;
if bits >= 8 {
bits -= 8;
out.push(((acc >> bits) & 0xff) as u8);
}
}
Some(out)
}
/// 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| 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)?)?;
(icc.get(at..at.checked_add(4)?)? == b"desc").then_some(at)
})?;
let off = usize::try_from(be32(tag.checked_add(4)?)?).ok()?;
let len = usize::try_from(be32(tag.checked_add(8)?)?).ok()?;
let body = icc.get(off..off.checked_add(len)?)?;
let text = match body.get(..4)? {
b"desc" => {
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(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)
}
_ => return None,
};
let text = text.trim_end_matches('\0').trim().to_owned();
(!text.is_empty()).then_some(text)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn base64_decodes_with_and_without_padding() {
assert_eq!(base64_decode("Zm9vYmFy").as_deref(), Some(&b"foobar"[..]));
assert_eq!(base64_decode("Zm9vYmE=").as_deref(), Some(&b"fooba"[..]));
assert_eq!(base64_decode("Zm9vYg").as_deref(), Some(&b"foob"[..]));
assert_eq!(base64_decode("Zm9v*"), None);
}
/// A profile with one tag, `desc`, holding `body`.
fn profile(body: &[u8]) -> Vec<u8> {
let mut icc = vec![0u8; 128];
icc.extend_from_slice(&1u32.to_be_bytes());
icc.extend_from_slice(b"desc");
icc.extend_from_slice(&144u32.to_be_bytes());
icc.extend_from_slice(&u32::try_from(body.len()).unwrap().to_be_bytes());
icc.extend_from_slice(body);
icc
}
/// A version 2 `desc` body.
fn desc(text: &str) -> Vec<u8> {
let mut b = b"desc\0\0\0\0".to_vec();
b.extend_from_slice(&u32::try_from(text.len() + 1).unwrap().to_be_bytes());
b.extend_from_slice(text.as_bytes());
b.push(0);
b
}
/// A version 4 `mluc` body with one record.
fn mluc(text: &str) -> Vec<u8> {
let units: Vec<u8> = text.encode_utf16().flat_map(u16::to_be_bytes).collect();
let mut b = b"mluc\0\0\0\0".to_vec();
b.extend_from_slice(&1u32.to_be_bytes());
b.extend_from_slice(&12u32.to_be_bytes());
b.extend_from_slice(b"enUS");
b.extend_from_slice(&u32::try_from(units.len()).unwrap().to_be_bytes());
b.extend_from_slice(&28u32.to_be_bytes());
b.extend_from_slice(&units);
b
}
#[test]
fn the_description_of_a_profile_is_read() {
assert_eq!(icc_description(&profile(&desc("Rec.709 Gamma 2.4"))).as_deref(), Some("Rec.709 Gamma 2.4"));
assert_eq!(icc_description(&profile(&mluc("sRGB IEC61966-2.1"))).as_deref(), Some("sRGB IEC61966-2.1"));
assert_eq!(icc_description(&profile(&desc(""))), None);
}
#[test]
fn a_cut_or_damaged_profile_gives_no_description() {
let icc = profile(&mluc("Rec.709 Gamma 2.4"));
for n in 0..icc.len() {
let mut cut = icc.get(..n).unwrap_or_default().to_vec();
let _ = icc_description(&cut);
cut.iter_mut().for_each(|b| *b = 0xff);
let _ = icc_description(&cut);
}
assert_eq!(icc_description(&icc[..150]), None);
assert_eq!(icc_description(&[]), None);
}
}
+271
View File
@@ -0,0 +1,271 @@
//! Shape layers: the groups under `ADBE Root Vectors Group` and the items in them.
//!
//! A shape layer (layer type 4) holds `tdgp[ADBE Root Vectors Group]` with one `ADBE Vector Group`
//! per shape group; the group holds `ADBE Vectors Group` (the contents, in z-order) and
//! `ADBE Vector Transform Group` (the group transform, only the properties that differ from the
//! default). Only the items and properties whose layout was verified are decoded; anything else is
//! listed as [`ShapeItem::Other`] with its match name.
//!
//! Colours are stored as ARGB doubles 0..255 and returned as fractions. Sizes, positions and path
//! points are in pixels relative to the layer origin.
use crate::masks::ShapePath;
use crate::typed::{Layer, PropGroup, PropNode};
use crate::values::{Tracked, read, read_opt};
/// The stroke line cap (`ADBE Vector Stroke Line Cap`, stored as a double; butt is the default and
/// is not stored).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StrokeCap {
/// `1`
Butt,
/// `2`
Round,
/// Any other value (projecting square was not sampled).
Other(i64),
}
/// The stroke line join (`ADBE Vector Stroke Line Join`; miter is the default and is not stored).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StrokeJoin {
/// `1`
Miter,
/// `2`
Round,
/// Any other value (bevel was not sampled).
Other(i64),
}
/// A stroke item.
#[derive(Debug, Clone, PartialEq)]
pub struct Stroke {
/// The color as `[A, R, G, B]` fractions; `None` while the property is absent (its default is
/// not verified).
pub color: Option<Tracked<[f64; 4]>>,
/// The width in pixels; `None` while absent.
pub width: Option<Tracked<f64>>,
pub cap: Tracked<StrokeCap>,
pub join: Tracked<StrokeJoin>,
/// The miter limit; after the join was touched it is stored in its default state (4).
pub miter_limit: Option<Tracked<f64>>,
}
/// An item of a shape group's contents.
#[derive(Debug, Clone, PartialEq)]
pub enum ShapeItem {
/// `ADBE Vector Shape - Rect`: the rectangle path.
Rect { name: Option<String>, size: Option<Tracked<[f64; 2]>> },
/// `ADBE Vector Shape - Group`: a bezier path (one shape per keyframe), points in pixels.
Path { name: Option<String>, paths: Vec<ShapePath> },
/// `ADBE Vector Graphic - Fill`: the color as `[A, R, G, B]` fractions.
Fill { name: Option<String>, color: Option<Tracked<[f64; 4]>> },
/// `ADBE Vector Graphic - Stroke`
Stroke { name: Option<String>, stroke: Stroke },
/// `ADBE Vector Graphic - G-Fill`: the start and end point of the gradient in pixels (the
/// gradient type and the colour stops are not stored while they are at After Effects' default
/// and their encoding is not known).
GradientFill { name: Option<String>, start: Option<Tracked<[f64; 2]>>, end: Option<Tracked<[f64; 2]>> },
/// `ADBE Vector Filter - RC`: rounded corners, the radius in pixels.
RoundCorners { name: Option<String>, radius: Option<Tracked<f64>> },
/// Any other item (ellipse, polystar, trim, repeater, ...: not ported).
Other { match_name: String, name: Option<String> },
}
/// The polystar type (`ADBE Vector Star Type`; star is the default and is not stored).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PolystarType {
/// `1`
Star,
/// `2`
Polygon,
/// Any other value.
Other(i64),
}
/// The gradient type (`ADBE Vector Grad Type`; linear is the default and is not stored).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GradientType {
/// `1`
Linear,
/// `2`
Radial,
/// Any other value.
Other(i64),
}
/// Fields of shape items that [`ShapeItem`] does not carry, in the order of the group's items.
/// `item_index` is the index into [`ShapeGroup::items`].
#[derive(Debug, Clone, PartialEq)]
pub enum ShapeDetail {
/// `ADBE Vector Shape - Star` (listed as [`ShapeItem::Other`]). The defaults After Effects
/// applies when a property is absent are star, outer radius 100, inner radius 50, so a default
/// star has no property at all (330); a polygon stores the type and writes the inner radius and
/// the inner roundness (`ADBE Vector Star Inner Roundess`, After Effects' own spelling) in their
/// default state (331).
Polystar {
item_index: usize,
star_type: Tracked<PolystarType>,
outer_radius: Tracked<f64>,
inner_radius: Tracked<f64>,
/// `None` unless the roundness is stored.
inner_roundness: Option<Tracked<f64>>,
},
/// `ADBE Vector Graphic - G-Fill`: the gradient type and, for a radial gradient, the highlight
/// length and angle (written as stored records with value 0 when the type is radial, 332).
Gradient {
item_index: usize,
gradient_type: Tracked<GradientType>,
highlight_length: Option<Tracked<f64>>,
highlight_angle: Option<Tracked<f64>>,
},
/// The `ADBE Vector Rect Position` of a rectangle path (absent = `[0, 0]`), in pixels (333).
RectPosition { item_index: usize, position: Tracked<[f64; 2]> },
}
/// A shape group (`ADBE Vector Group`).
#[derive(Debug, Clone, PartialEq)]
pub struct ShapeGroup {
/// The group's name (`Group 1`).
pub name: Option<String>,
/// The group transform's Position in pixels; absent = `[0, 0]`.
pub position: Tracked<[f64; 2]>,
/// The contents in z-order (top first, as in the file). Two siblings with the same match name
/// (two rectangles) are two items.
pub items: Vec<ShapeItem>,
/// More fields of the items (polystar, gradient type, rectangle position), see [`ShapeDetail`].
pub details: Vec<ShapeDetail>,
}
const COLOR_SCALE: f64 = 1.0 / 255.0;
fn number(group: &PropGroup<'_, '_>, name: &str) -> Option<Tracked<f64>> {
read_opt::<1>(group, name, 1.0).map(|t| Tracked { value: t.value[0], source: t.source })
}
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().filter(|c| c.is_list(b"shap")).filter_map(ShapePath::from_chunk).collect()
}
fn item(match_name: String, group: &PropGroup<'_, '_>) -> ShapeItem {
let name = group.user_name();
match match_name.as_str() {
"ADBE Vector Shape - Rect" => ShapeItem::Rect { name, size: read_opt::<2>(group, "ADBE Vector Rect Size", 1.0) },
"ADBE Vector Shape - Group" => ShapeItem::Path { name, paths: paths_of(group) },
"ADBE Vector Graphic - Fill" => ShapeItem::Fill { name, color: read_opt::<4>(group, "ADBE Vector Fill Color", COLOR_SCALE) },
"ADBE Vector Graphic - Stroke" => {
let cap = read(group, "ADBE Vector Stroke Line Cap", [1.0], 1.0);
let join = read(group, "ADBE Vector Stroke Line Join", [1.0], 1.0);
let stroke = Stroke {
color: read_opt::<4>(group, "ADBE Vector Stroke Color", COLOR_SCALE),
width: number(group, "ADBE Vector Stroke Width"),
cap: Tracked {
value: match cap.value[0].round() as i64 {
1 => StrokeCap::Butt,
2 => StrokeCap::Round,
other => StrokeCap::Other(other),
},
source: cap.source,
},
join: Tracked {
value: match join.value[0].round() as i64 {
1 => StrokeJoin::Miter,
2 => StrokeJoin::Round,
other => StrokeJoin::Other(other),
},
source: join.source,
},
miter_limit: number(group, "ADBE Vector Stroke Miter Limit"),
};
ShapeItem::Stroke { name, stroke }
}
"ADBE Vector Graphic - G-Fill" => ShapeItem::GradientFill {
name,
start: read_opt::<2>(group, "ADBE Vector Grad Start Pt", 1.0),
end: read_opt::<2>(group, "ADBE Vector Grad End Pt", 1.0),
},
"ADBE Vector Filter - RC" => ShapeItem::RoundCorners { name, radius: number(group, "ADBE Vector RoundCorner Radius") },
_ => ShapeItem::Other { match_name, name },
}
}
fn detail(match_name: &str, group: &PropGroup<'_, '_>, item_index: usize) -> Option<ShapeDetail> {
let tracked = |name: &str, default: f64| {
let t = read(group, name, [default], 1.0);
Tracked { value: t.value[0], source: t.source }
};
match match_name {
"ADBE Vector Shape - Star" => {
let star_type = tracked("ADBE Vector Star Type", 1.0);
Some(ShapeDetail::Polystar {
item_index,
star_type: Tracked {
value: match star_type.value.round() as i64 {
1 => PolystarType::Star,
2 => PolystarType::Polygon,
other => PolystarType::Other(other),
},
source: star_type.source,
},
outer_radius: tracked("ADBE Vector Star Outer Radius", 100.0),
inner_radius: tracked("ADBE Vector Star Inner Radius", 50.0),
inner_roundness: number(group, "ADBE Vector Star Inner Roundess"),
})
}
"ADBE Vector Graphic - G-Fill" => {
let gradient_type = tracked("ADBE Vector Grad Type", 1.0);
Some(ShapeDetail::Gradient {
item_index,
gradient_type: Tracked {
value: match gradient_type.value.round() as i64 {
1 => GradientType::Linear,
2 => GradientType::Radial,
other => GradientType::Other(other),
},
source: gradient_type.source,
},
highlight_length: number(group, "ADBE Vector Grad HiLite Length"),
highlight_angle: number(group, "ADBE Vector Grad HiLite Angle"),
})
}
"ADBE Vector Shape - Rect" => {
Some(ShapeDetail::RectPosition { item_index, position: read(group, "ADBE Vector Rect Position", [0.0, 0.0], 1.0) })
}
_ => None,
}
}
fn group_of(group: &PropGroup<'_, '_>) -> ShapeGroup {
let (mut items, mut details) = (Vec::new(), Vec::new());
if let Some(PropNode::Group(contents)) = group.get("ADBE Vectors Group") {
for e in contents.entries() {
if let PropNode::Group(g) = e.node {
details.extend(detail(&e.match_name, &g, items.len()));
items.push(item(e.match_name, &g));
}
}
}
let position = match group.get("ADBE Vector Transform Group") {
Some(PropNode::Group(t)) => read(&t, "ADBE Vector Position", [0.0, 0.0], 1.0),
_ => Tracked { value: [0.0, 0.0], source: crate::values::ValueSource::Default },
};
ShapeGroup { name: group.user_name(), position, items, details }
}
impl<'f, 'a> Layer<'f, 'a> {
/// The shape groups of a shape layer (`ADBE Root Vectors Group`), top group first.
pub fn shape_groups(&self) -> Vec<ShapeGroup> {
let Some(root) = self.properties() else { return Vec::new() };
let Some(PropNode::Group(vectors)) = root.get("ADBE Root Vectors Group") else { return Vec::new() };
vectors
.entries()
.into_iter()
.filter(|e| e.match_name == "ADBE Vector Group")
.filter_map(|e| match e.node {
PropNode::Group(g) => Some(group_of(&g)),
PropNode::Property(_) | PropNode::Other(_) => None,
})
.collect()
}
}
File diff suppressed because it is too large Load Diff
+604
View File
@@ -0,0 +1,604 @@
//! A small typed view over the chunk tree: project items, compositions, layers, the property
//! tree and keyframe lists. The field decoders for headers, values, keyframes, effects, masks, text,
//! markers and footage are in the sibling modules and extend these types.
//!
//! 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 ([`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::Chunk) tree
//! ([`Project::new`]) or the flat [`TreeIndex`] the importer builds ([`Project::from_index`]);
//! both give the same answers.
use crate::bytes::{be_f64, be_u16, be_u32, text, until_nul};
use crate::chunk::AepFile;
use crate::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: 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: 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: Node<'f, 'a>,
/// The top-level `LIST EfdG` (project-level effect definitions), when there is one.
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> {
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 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().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.
pub fn items_unreadable(&self) -> bool {
self.fold.is_opaque_list()
}
/// Every item including those inside folders, depth-first, without recursion.
pub fn all_items(&self) -> Vec<Item<'f, 'a>> {
let mut out = Vec::new();
let mut stack: Vec<Item<'f, 'a>> = self.items().collect();
stack.reverse();
while let Some(item) = stack.pop() {
let mut kids: Vec<Item<'f, 'a>> = item.children().collect();
kids.reverse();
out.push(item);
stack.extend(kids);
}
out
}
}
/// What a project item is (the first 16-bit word of its `idta` chunk).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ItemKind {
/// `1`
Folder,
/// `4`
Composition,
/// `7`
Footage,
/// Any other value.
Other(u16),
}
/// A project item (`LIST Item`).
#[derive(Debug, Clone, Copy)]
pub struct Item<'f, 'a> {
pub(crate) chunk: Node<'f, 'a>,
}
impl<'f, 'a> Item<'f, 'a> {
/// The underlying chunk.
pub fn chunk(&self) -> Node<'f, 'a> {
self.chunk
}
/// The item kind, from `idta`.
pub fn kind(&self) -> Option<ItemKind> {
let idta = self.chunk.child(b"idta")?.bytes()?;
Some(match be_u16(idta, 0)? {
1 => ItemKind::Folder,
4 => ItemKind::Composition,
7 => ItemKind::Footage,
other => ItemKind::Other(other),
})
}
/// The item name (the `Utf8` child). `None` when absent or empty: a solid's footage item
/// stores no name there.
pub fn name(&self) -> Option<String> {
utf8_child(self.chunk).filter(|n| !n.is_empty())
}
/// 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(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
/// one for an empty folder).
pub fn has_folder_contents(&self) -> bool {
self.chunk.child_list(b"Sfdr").is_some()
}
/// 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(Node::is_opaque_list)
}
/// The composition view when this item has composition data (`cdta`).
pub fn comp(&self) -> Option<Comp<'f, 'a>> {
self.chunk.child(b"cdta").map(|_| Comp { item: self.chunk })
}
}
/// The time base of a composition: one frame lasts `frame_duration` units and a second has
/// `timescale` units. Keyframe times are counted in these units.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TimeBase {
pub frame_duration: u32,
pub timescale: u32,
}
impl TimeBase {
/// The NTSC rates as `(numerator, denominator)` and the value After Effects stores for each (a
/// float32 of exactly these decimals): the one table an importer and an exporter use.
pub const NTSC: [((u32, u32), f32); 4] = [((24000, 1001), 23.976), ((30000, 1001), 29.97), ((60000, 1001), 59.94), ((120000, 1001), 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))
}
/// Converts time units to seconds, `None` for a zero timescale.
pub fn seconds(&self, units: i32) -> Option<f64> {
(self.timescale != 0).then(|| f64::from(units) / f64::from(self.timescale))
}
}
/// A composition item (an [`Item`] with `cdta`).
#[derive(Debug, Clone, Copy)]
pub struct Comp<'f, 'a> {
pub(crate) item: Node<'f, 'a>,
}
impl<'f, 'a> Comp<'f, 'a> {
/// The time base from `cdta` (`u32` at byte 4 is the frame duration, `u32` at byte 8 the
/// timescale).
pub fn time_base(&self) -> Option<TimeBase> {
let cdta = self.item.child(b"cdta")?.bytes()?;
Some(TimeBase { frame_duration: be_u32(cdta, 4)?, timescale: be_u32(cdta, 8)? })
}
/// 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().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: Node<'f, 'a>,
}
impl<'f, 'a> Layer<'f, 'a> {
/// The underlying chunk.
pub fn chunk(&self) -> Node<'f, 'a> {
self.chunk
}
/// The layer name when it was set (the `Utf8` child); `None` when empty, in which case the
/// layer shows its source's name.
pub fn name(&self) -> Option<String> {
utf8_child(self.chunk).filter(|n| !n.is_empty())
}
/// The 3D layer switch: bit `0x04` of byte 38 of `ldta`.
pub fn is_three_d(&self) -> Option<bool> {
let ldta = self.chunk.child(b"ldta")?.bytes()?;
Some(ldta.get(38)? & 0x04 != 0)
}
/// The root of the layer's property tree.
pub fn properties(&self) -> Option<PropGroup<'f, 'a>> {
self.chunk.child_list(b"tdgp").map(|chunk| PropGroup { chunk })
}
}
/// A node of the property tree.
#[derive(Debug, Clone, Copy)]
pub enum PropNode<'f, 'a> {
/// A property group (`LIST tdgp`).
Group(PropGroup<'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(Node<'f, 'a>),
}
impl<'f, 'a> PropNode<'f, 'a> {
/// The node a `LIST` after a match name is.
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") {
PropNode::Property(Property { chunk: c })
} else {
PropNode::Other(c)
}
}
}
/// A match name with the node it names.
#[derive(Debug, Clone)]
pub struct PropEntry<'f, 'a> {
pub match_name: String,
pub node: PropNode<'f, 'a>,
}
/// A property group (`LIST tdgp`): after its `tdsb` and `tdsn` chunks come pairs of a `tdmn`
/// (the 40-byte NUL-padded ASCII match name) and the list it names; a `tdmn` named
/// `ADBE Group End` closes the group and names nothing.
#[derive(Debug, Clone, Copy)]
pub struct PropGroup<'f, 'a> {
pub(crate) chunk: Node<'f, 'a>,
}
impl<'f, 'a> PropGroup<'f, 'a> {
/// A group view of a `LIST tdgp` chunk (a [`Chunk`](crate::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) -> Node<'f, 'a> {
self.chunk
}
/// The name the user gave the group (e.g. `Mask 1`, `Group 1`); `None` when it has none.
pub fn user_name(&self) -> Option<String> {
user_name(self.chunk)
}
/// The group's flags (`tdsb`, a `u32`).
pub fn flags(&self) -> Option<u32> {
be_u32(self.chunk.child(b"tdsb")?.bytes()?, 0)
}
/// The entries in file order.
pub fn entries(&self) -> Vec<PropEntry<'f, 'a>> {
let mut out = Vec::new();
let mut pending: Option<String> = None;
for c in self.chunk.children() {
if c.is(b"tdmn") {
pending = c.bytes().map(match_name);
} else if c.is(&crate::chunk::LIST)
&& let Some(name) = pending.take()
{
out.push(PropEntry { match_name: name, node: PropNode::of(c) });
}
}
out
}
/// The match names of the entries, in file order.
pub fn names(&self) -> Vec<String> {
self.entries().into_iter().map(|e| e.match_name).collect()
}
/// The first entry with this match name. One pass that stops at it, without collecting the
/// group's entries (callers look names up in loops).
pub fn get(&self, name: &str) -> Option<PropNode<'f, 'a>> {
let mut pending: Option<&[u8]> = None;
for c in self.chunk.children() {
if c.is(b"tdmn") {
pending = c.bytes();
} else if c.is(&crate::chunk::LIST)
&& let Some(body) = pending.take()
&& match_name_is(body, name)
{
return Some(PropNode::of(c));
}
}
None
}
/// Follows a path of match names through nested groups.
pub fn find(&self, path: &[&str]) -> Option<PropNode<'f, 'a>> {
let (first, rest) = path.split_first()?;
let node = self.get(first)?;
if rest.is_empty() {
return Some(node);
}
match node {
PropNode::Group(g) => g.find(rest),
PropNode::Property(_) | PropNode::Other(_) => None,
}
}
}
/// The match name in a `tdmn` body: ASCII up to the first NUL.
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: Node<'f, 'a>,
}
impl<'f, 'a> Property<'f, 'a> {
/// A property view of a `LIST tdbs` chunk (a [`Chunk`](crate::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) -> Node<'f, 'a> {
self.chunk
}
/// The name the user gave the property; `None` when it has none.
pub fn user_name(&self) -> Option<String> {
user_name(self.chunk)
}
/// The raw 124-byte `tdb4` header.
pub fn header(&self) -> Option<&'f [u8]> {
self.chunk.child(b"tdb4")?.bytes()
}
/// The number of value components: byte 3 of `tdb4`.
pub fn dims(&self) -> Option<u8> {
self.header()?.get(3).copied()
}
/// True when the property has keyframes, i.e. its value is a `LIST list` instead of `cdat`.
/// `tdb4` byte 68 is 1 in exactly these properties.
pub fn is_animated(&self) -> bool {
self.chunk.child_list(b"list").is_some()
}
/// The static value: the first `dims` big-endian `f64` of `cdat`. `None` for animated
/// properties and for values that are not `f64` arrays.
pub fn static_value(&self) -> Option<Vec<f64>> {
let dims = usize::from(self.dims()?);
let cdat = self.chunk.child(b"cdat")?.bytes()?;
(0..dims).map(|i| be_f64(cdat, i.checked_mul(8)?)).collect()
}
/// The keyframe list of an animated property, with the record layout the property header
/// selects (`tdb4` byte 3 = components, byte 7 non-zero = spatial template, unless the record
/// size tells).
pub fn keys(&self) -> Option<KeyList<'f>> {
let list = KeyList::from_chunk(self.chunk.child_list(b"list")?)?;
let header = self.header();
// The record size decides where the two templates differ in size: a shape colour's keys
// are spatial (152 bytes for 4 components) although its `tdb4` byte 7 is 0 (854). For 3
// components both templates are 128 bytes; byte 7 decides.
let size = list.header.record_size;
let layout = header.and_then(|h| {
let components = *h.get(3)?;
let n = u32::from(components);
let (spatial_size, plain_size) = (56 + 24 * n, 8 + 40 * n);
let spatial = if size == spatial_size && size != plain_size {
true
} else if size == plain_size && size != spatial_size {
false
} else {
*h.get(7)? != 0
};
Some(KeyLayout { components, spatial })
});
Some(KeyList { layout, ..list })
}
}
/// The header `lhd3` of a `LIST list`: 13 big-endian `u32`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ListHeader {
/// Word 0, `0x00d00bee` in every list.
pub magic: u32,
/// Word 2: the number of records.
pub count: u32,
/// Word 4: the size of one record in bytes.
pub record_size: u32,
/// All 13 words.
pub words: [u32; 13],
}
impl ListHeader {
/// Parses a 52-byte `lhd3` body.
pub fn parse(body: &[u8]) -> Option<Self> {
if body.len() != 52 {
return None;
}
let mut words = [0u32; 13];
for (i, w) in words.iter_mut().enumerate() {
*w = be_u32(body, i * 4)?;
}
Some(Self { magic: words[0], count: words[2], record_size: words[4], words })
}
}
/// A `LIST list`: `lhd3` and `ldat`, where `len(ldat) == count * record_size`.
#[derive(Debug, Clone, Copy)]
pub struct KeyList<'f> {
pub header: ListHeader,
ldat: &'f [u8],
layout: Option<KeyLayout>,
}
/// What the property header says about its keyframe records: how many value components each
/// record holds and which of the two record templates applies (see [`KeyframeKind`]).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct KeyLayout {
/// `tdb4` byte 3.
pub components: u8,
/// `tdb4` byte 7 is non-zero: the spatial template (Position, colours) instead of the plain one.
pub spatial: bool,
}
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: '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(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 })
}
/// The number of records actually present (what [`Self::records`] yields). Not the declared
/// count: a list with record size 0 and no data passes [`Self::from_chunk`] whatever count it
/// declares, and a caller sizing an allocation by that count would abort.
pub fn len(&self) -> usize {
self.records().count()
}
/// True when there are no records.
pub fn is_empty(&self) -> bool {
self.ldat.is_empty()
}
/// The records as byte slices.
pub fn records(&self) -> impl Iterator<Item = &'f [u8]> {
let size = usize::try_from(self.header.record_size).unwrap_or(0);
self.ldat.chunks_exact(size.max(1))
}
/// The record layout from the property header, `None` for a list that does not belong to a
/// property (the point list of a path).
pub fn layout(&self) -> Option<KeyLayout> {
self.layout
}
/// The records of a keyframe list as [`Keyframe`]s.
pub fn keyframes(&self) -> impl Iterator<Item = Keyframe<'f>> {
let layout = self.layout;
self.records().map(move |record| Keyframe { record, layout })
}
}
/// One keyframe record: the time is the `i32` at byte 0, in the composition's time units
/// ([`TimeBase`]).
#[derive(Debug, Clone, Copy)]
pub struct Keyframe<'f> {
pub(crate) record: &'f [u8],
pub(crate) layout: Option<KeyLayout>,
}
impl<'f> Keyframe<'f> {
/// The whole record.
pub fn raw(&self) -> &'f [u8] {
self.record
}
/// The keyframe time in time units (layer time).
pub fn time_units(&self) -> Option<i32> {
be_u32(self.record, 0).map(|u| i32::from_be_bytes(u.to_be_bytes()))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Chunk;
fn key_list(count: u32, record_size: u32, ldat: &[u8]) -> Chunk<'static> {
let mut lhd3 = vec![0u8; 52];
lhd3[8..12].copy_from_slice(&count.to_be_bytes());
lhd3[16..20].copy_from_slice(&record_size.to_be_bytes());
Chunk::list(*b"list", vec![Chunk::data(*b"lhd3", lhd3), Chunk::data(*b"ldat", ldat.to_vec())])
}
#[test]
fn a_key_list_counts_the_records_it_holds() {
let two = key_list(2, 4, &[0; 8]);
assert_eq!(KeyList::from_chunk(&two).map(|l| l.len()), Some(2));
// Record size 0 with no data passes the size check whatever count is declared; the length
// is what is there, so no caller sizes an allocation by 4 billion records.
let hostile = key_list(u32::MAX, 0, &[]);
let list = KeyList::from_chunk(&hostile).expect("a well-formed empty list");
assert_eq!((list.len(), list.is_empty(), list.records().count()), (0, true, 0));
}
#[test]
fn get_finds_the_first_entry_of_a_name() {
let tdmn = |n: &str| {
let mut b = n.as_bytes().to_vec();
b.resize(40, 0);
Chunk::data(*b"tdmn", b)
};
let group = Chunk::list(
*b"tdgp",
vec![
tdmn("A"),
Chunk::list(*b"tdgp", Vec::new()),
tdmn("B"),
Chunk::list(*b"tdbs", Vec::new()),
tdmn("A"),
Chunk::list(*b"tdbs", Vec::new()),
],
);
let g = PropGroup::from_chunk(&group).expect("group");
assert!(matches!(g.get("A"), Some(PropNode::Group(_))), "the first A is the group");
assert!(matches!(g.get("B"), Some(PropNode::Property(_))));
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());
}
}
+261
View File
@@ -0,0 +1,261 @@
//! Static transform values with their units, and the "absent = default" rule.
//!
//! After Effects stores a property only when it differs from the default it computes for the layer
//! and composition (sparse storage), so a reader has to supply the defaults: Position defaults to
//! the composition centre `[width / 2, height / 2, 0]` (verified: after the composition is resized
//! without moving the layer, the old centre appears as a stored value), Anchor Point to the layer
//! centre (`0.5, 0.5` of the layer **source** size), Scale to 100 %, Rotation to 0 and Opacity to
//! 100 %. These defaults are verified for AV layers (solids); cameras and lights use other
//! conventions (see the `camera` module).
use crate::bytes::be_f64;
use crate::typed::{Layer, Project, PropGroup, PropNode};
/// Where a [`Tracked`] value came from.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ValueSource {
/// The property is absent from the file: the value is the computed default.
Default,
/// The property stores a static value.
Stored,
/// The property has keyframes: the value is that of the first keyframe.
Keyframed,
/// The property is present but its value could not be read: the value is the default.
Unreadable,
}
/// A value and where it came from.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Tracked<T> {
pub value: T,
pub source: ValueSource,
}
/// The five basic transform properties of an AV layer, in the units After Effects shows.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Transform {
/// Pixels `[x, y, z]`.
pub position: Tracked<[f64; 3]>,
/// Stored as a fraction of the layer's **source** size for x and y (`10, 20` px on a 100x100
/// solid in a 1920x1080 composition is `0.1, 0.2`; on a 400x300 solid `100, 50` is `0.25, 1/6`)
/// and in pixels for z; see [`Transform::anchor_px`] and [`Project::layer_anchor_px`].
pub anchor_fraction: Tracked<[f64; 3]>,
/// Percent `[x, y, z]` (stored as fractions: 50 % is `0.5`).
pub scale_percent: Tracked<[f64; 3]>,
/// Degrees (Rotation, the Z rotation).
pub rotation_degrees: Tracked<f64>,
/// Percent (stored as a fraction: 25 % is `0.25`).
pub opacity_percent: Tracked<f64>,
}
impl Transform {
/// The anchor point in pixels for a layer whose source has this size.
pub fn anchor_px(&self, width: f64, height: f64) -> [f64; 3] {
let [x, y, z] = self.anchor_fraction.value;
[x * width, y * height, z]
}
/// The anchor point of a **text** layer in layer pixels. A text layer has no source, so the
/// stored value is not a fraction: it is pixels as stored (385: Anchor Point `10, 20` is stored
/// `10, 20`), and an
/// absent anchor is the text origin `[0, 0, 0]` (After Effects' default for new text, absent in
/// every other text sample 110-114, 243-248, 334-340, 386).
pub fn text_anchor_px(&self) -> [f64; 3] {
match self.anchor_fraction.source {
ValueSource::Stored | ValueSource::Keyframed => self.anchor_fraction.value,
ValueSource::Default | ValueSource::Unreadable => [0.0; 3],
}
}
}
/// Reads `N` components from the property `name` of `group` and multiplies them by `scale` (stored
/// fractions to percent); `default` is in the output units and used when the property is absent.
pub(crate) fn read<const N: usize>(group: &PropGroup<'_, '_>, name: &str, default: [f64; N], scale: f64) -> Tracked<[f64; N]> {
let unreadable = Tracked { value: default, source: ValueSource::Unreadable };
let property = match group.get(name) {
None => return Tracked { value: default, source: ValueSource::Default },
Some(PropNode::Property(p)) => p,
Some(PropNode::Group(_) | PropNode::Other(_)) => return unreadable,
};
let (values, source) =
if property.is_animated() { (property.first_key_value(), ValueSource::Keyframed) } else { (property.static_value(), ValueSource::Stored) };
let Some(values) = values else { return unreadable };
if values.len() < N {
return unreadable;
}
let mut out = default;
for (slot, v) in out.iter_mut().zip(&values) {
*slot = *v * scale;
}
Tracked { value: out, source }
}
/// Like [`read`] but `None` when the property is absent or unreadable (for properties whose default
/// is not known), keeping the value's source.
pub(crate) fn read_opt<const N: usize>(group: &PropGroup<'_, '_>, name: &str, scale: f64) -> Option<Tracked<[f64; N]>> {
let tracked = read(group, name, [0.0; N], scale);
matches!(tracked.source, ValueSource::Stored | ValueSource::Keyframed).then_some(tracked)
}
impl<'f, 'a> Project<'f, 'a> {
/// The anchor point of an AV layer in pixels: the stored fraction times the size of the layer's
/// source (a solid or footage item, or a precomp's composition), z unchanged. `None` when the
/// layer has no source (shape, text, camera, light) or no Transform group.
pub fn layer_anchor_px(&self, layer: &Layer<'f, 'a>) -> Option<Tracked<[f64; 3]>> {
let (width, height) = self.layer_source_size(layer)?;
let Some(PropNode::Group(group)) = layer.properties()?.get("ADBE Transform Group") else { return None };
let fraction = read(&group, "ADBE Anchor Point", [0.5, 0.5, 0.0], 1.0);
let [x, y, z] = fraction.value;
Some(Tracked { value: [x * f64::from(width), y * f64::from(height), z], source: fraction.source })
}
}
impl<'f, 'a> Layer<'f, 'a> {
/// The transform of an AV layer in a composition of this size (pixels), with absent
/// properties replaced by their defaults. `None` when the layer has no Transform group.
pub fn transform(&self, comp_width: u32, comp_height: u32) -> Option<Transform> {
let Some(PropNode::Group(group)) = self.properties()?.get("ADBE Transform Group") else { return None };
let centre = [f64::from(comp_width) / 2.0, f64::from(comp_height) / 2.0, 0.0];
let rotation = read(&group, "ADBE Rotate Z", [0.0], 1.0);
let opacity = read(&group, "ADBE Opacity", [100.0], 100.0);
Some(Transform {
position: read(&group, "ADBE Position", centre, 1.0),
anchor_fraction: read(&group, "ADBE Anchor Point", [0.5, 0.5, 0.0], 1.0),
scale_percent: read(&group, "ADBE Scale", [100.0, 100.0, 100.0], 100.0),
rotation_degrees: Tracked { value: rotation.value[0], source: rotation.source },
opacity_percent: Tracked { value: opacity.value[0], source: opacity.source },
})
}
}
/// One key of a layer's Time Remapping property: the layer time of the key and the source time it
/// maps to, both in seconds.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TimeRemapKey {
/// The key time in the property's time units.
pub time_units: i32,
/// The key time in seconds (layer time).
pub time_seconds: Option<f64>,
/// The value in seconds (the plain record's value at byte 8).
pub value_seconds: f64,
}
/// The state of a layer's `ADBE Time Remapping` property. Every layer has the property; while the
/// remap is off it is an inert record (`tdsb` 3, static value 0, no keys). Enabling the remap turns
/// it into a keyed property (`tdsb` 1, `tdb4` byte 68 = 1, no `cdat`) with two keys: the layer's in
/// and out time mapped to the source time (319: 0 s and 5 s; 354: 0 s and 0.1 s).
#[derive(Debug, Clone, PartialEq)]
pub struct TimeRemap {
/// True when the property has keys.
pub enabled: bool,
pub keys: Vec<TimeRemapKey>,
}
impl<'f, 'a> Layer<'f, 'a> {
/// The Time Remapping state; `None` when the layer has no such property.
pub fn time_remap(&self) -> Option<TimeRemap> {
let Some(PropNode::Property(p)) = self.properties()?.get("ADBE Time Remapping") else { return None };
let scale = p.time_scale().unwrap_or(0);
let keys = match p.keys() {
Some(list) => list
.keyframes()
.filter_map(|k| Some(TimeRemapKey { time_units: k.time_units()?, time_seconds: k.seconds(scale), value_seconds: k.scalar_value()? }))
.collect(),
None => Vec::new(),
};
Some(TimeRemap { enabled: p.is_animated(), keys })
}
}
/// The Orientation of a 3D layer (`ADBE Orientation`, 488): a `LIST otst` holding a `tdbs` and a
/// `LIST otky` whose `otda` is three big-endian `f64` degrees `[x, y, z]`; absent at `[0, 0, 0]`
/// (485-487).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Orientation {
/// Degrees `[x, y, z]`: the static value (for a keyed Orientation the first `otda`, whose
/// meaning is not sampled).
pub degrees: [f64; 3],
/// The `tdbs` of the `otst` has keys (see [`Layer::orientation_keys`]).
pub animated: bool,
/// The `tdbs` of the `otst` has an expression.
pub has_expression: bool,
}
impl<'f, 'a> Layer<'f, 'a> {
/// The Orientation; `None` when it is absent (the default `[0, 0, 0]`) or unreadable.
pub fn orientation(&self) -> Option<Orientation> {
let Some(PropNode::Group(group)) = self.properties()?.get("ADBE Transform Group") else { return None };
let Some(PropNode::Other(otst)) = group.get("ADBE Orientation") else { return None };
if !otst.is_list(b"otst") {
return None;
}
let property = otst.child_list(b"tdbs").and_then(crate::typed::Property::from_chunk);
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() {
*slot = be_f64(otda, i * 8)?;
}
Some(Orientation {
degrees,
animated: property.as_ref().is_some_and(|p| p.is_animated()),
has_expression: property.as_ref().is_some_and(|p| p.expression().is_some()),
})
}
/// The time scale of the Orientation's key times (`tdb4` bytes 12..15), which follows the
/// layer's stretch like every property of the layer.
pub fn orientation_time_scale(&self) -> Option<u32> {
let Some(PropNode::Group(group)) = self.properties().and_then(|p| p.get("ADBE Transform Group")) else { return None };
let Some(PropNode::Other(otst)) = group.get("ADBE Orientation") else { return None };
otst.child_list(b"tdbs").and_then(crate::typed::Property::from_chunk).and_then(|p| p.time_scale())
}
/// The keyframes of a keyed Orientation (703): the `tdbs` of the `otst` holds one 80-byte
/// record per key (time, interpolation sides, flags; the rest is not decoded) and `otky` one
/// `otda` (three `f64` degrees) per key, in the same order. Empty when the Orientation is not
/// keyed or the counts differ. After Effects interpolates between the keys by a quaternion slerp
/// of the rotations `Rx Ry Rz`, not per component (703's values at 0.5 / 1 / 1.5 s).
pub fn orientation_keys(&self) -> Vec<OrientationKey> {
let Some(PropNode::Group(group)) = self.properties().and_then(|p| p.get("ADBE Transform Group")) else { return Vec::new() };
let Some(PropNode::Other(otst)) = group.get("ADBE Orientation") else { return Vec::new() };
let Some(list) = otst.child_list(b"tdbs").and_then(crate::typed::Property::from_chunk).and_then(|p| p.keys()) else { return Vec::new() };
let values: Vec<Option<[f64; 3]>> = otst
.child_list(b"otky")
.map(|k| {
k.children()
.filter(|c| c.is(b"otda"))
.map(|c| {
let b = c.bytes()?;
Some([be_f64(b, 0)?, be_f64(b, 8)?, be_f64(b, 16)?])
})
.collect()
})
.unwrap_or_default();
let keys: Vec<_> = list.keyframes().collect();
if keys.len() != values.len() {
return Vec::new();
}
keys.iter()
.zip(values)
.filter_map(|(k, v)| {
Some(OrientationKey {
time_units: k.time_units()?,
interpolation_in: k.interpolation_in()?,
interpolation_out: k.interpolation_out()?,
degrees: v?,
})
})
.collect()
}
}
/// A keyframe of a keyed Orientation.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct OrientationKey {
/// The time in the property's time units (layer time).
pub time_units: i32,
pub interpolation_in: crate::Interpolation,
pub interpolation_out: crate::Interpolation,
/// Degrees `[x, y, z]`.
pub degrees: [f64; 3],
}
+138
View File
@@ -0,0 +1,138 @@
//! The After Effects version a project is written for (`head` bytes 4 to 7) and the version of the
//! After Effects that wrote it (`svap`).
//!
//! Both hold the same packed `u32` (see `docs/aep-format.md`, section 1, "Version"). A project saved
//! normally has the same word in both; File ▸ Save a Copy As 25.x / 24.x of After Effects 2026 keeps
//! `svap` (the 2026 version) and writes the older version into `head`. The XMP packet after the
//! container names the application of the first save (`CreatorTool`) and is no guide to either.
use std::fmt;
use crate::bytes::be_u32;
use crate::chunk::AepFile;
use crate::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`).
///
/// Bit layout of the big-endian word (bit 31 first), decoded from the samples (the 2026 word
/// `0x0f11_0e02` is the version the saving After Effects reports, `26.2.1x2`; the down-saves give
/// `0x0f0b_0661` and `0x0f03_0641`, read as `25.6.0x97` and `24.6.0x65`):
///
/// | bits | field |
/// |---|---|
/// | 31-26 | not decoded (`000011` in every sample) |
/// | 25-24, 21-19 | major (high two bits, then low three bits) |
/// | 23-22 | not decoded (`00` in every sample) |
/// | 18-15 | minor |
/// | 14-11 | bug-fix |
/// | 10-8 | stage (6 in every sample) |
/// | 7-0 | build |
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AeVersion {
pub major: u8,
pub minor: u8,
pub bugfix: u8,
/// The release stage (6 in every sample; not shown in [`AeVersion::text`]).
pub stage: u8,
pub build: u8,
/// The word as stored.
pub raw: u32,
}
impl AeVersion {
/// Decodes a stored word; `None` for a word that holds no version (zero, all ones, or major 0:
/// After Effects itself refuses a file whose `head` version is zero, "[0.0x0]").
pub fn from_word(raw: u32) -> Option<Self> {
if raw == 0 || raw == u32::MAX {
return None;
}
let [b0, b1, b2, b3] = raw.to_be_bytes();
let major = ((b0 & 0x03) << 3) | ((b1 >> 3) & 0x07);
if major == 0 {
return None;
}
Some(Self { major, minor: ((b1 & 0x07) << 1) | (b2 >> 7), bugfix: (b2 >> 3) & 0x0f, stage: b2 & 0x07, build: b3, raw })
}
/// `26.2.1x2`.
pub fn text(&self) -> String {
self.to_string()
}
}
impl fmt::Display for AeVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}x{}", self.major, self.minor, self.bugfix, self.build)
}
}
impl AepFile<'_> {
/// The version the file is written for: `head` bytes 4 to 7. After Effects 2026 writes its own
/// 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> {
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> {
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()
}
/// [`AepFile::saved_by_version`] of the indexed file.
pub fn saved_by_version(&self) -> Option<AeVersion> {
Root::from(self).saved_by_version()
}
}
impl Root<'_, '_> {
/// The version the file is written for (`head` bytes 4 to 7).
pub fn file_version(self) -> Option<AeVersion> {
AeVersion::from_word(be_u32(self.chunk(b"head")?.bytes()?, 4)?)
}
/// The version of the application that wrote the file (`svap`).
pub fn saved_by_version(self) -> Option<AeVersion> {
AeVersion::from_word(be_u32(self.chunk(b"svap")?.bytes()?, 0)?)
}
}
#[cfg(test)]
mod tests {
use super::AeVersion;
#[test]
fn decodes_the_sampled_words() {
let v = AeVersion::from_word(0x0f11_0e02).unwrap();
assert_eq!((v.major, v.minor, v.bugfix, v.stage, v.build), (26, 2, 1, 6, 2));
assert_eq!(v.text(), "26.2.1x2");
assert_eq!(AeVersion::from_word(0x0f0b_0661).unwrap().text(), "25.6.0x97");
assert_eq!(AeVersion::from_word(0x0f03_0641).unwrap().text(), "24.6.0x65");
}
#[test]
fn a_word_without_a_version_is_none() {
assert_eq!(AeVersion::from_word(0), None);
assert_eq!(AeVersion::from_word(u32::MAX), None);
// Major 0 (only the undecoded high bits set).
assert_eq!(AeVersion::from_word(0x0c00_0000), None);
}
#[test]
fn every_field_takes_its_extremes() {
let v = AeVersion::from_word(0x03ff_ffff).unwrap();
assert_eq!((v.major, v.minor, v.bugfix, v.stage, v.build), (31, 15, 15, 7, 255));
let v = AeVersion::from_word(0x0000_0800 | 0x0008_0000).unwrap();
assert_eq!((v.major, v.minor, v.bugfix, v.build), (1, 0, 1, 0));
}
}
+179
View File
@@ -0,0 +1,179 @@
//! Writing an [`AepFile`] back to bytes.
use std::io::Write;
use crate::chunk::{AepFile, Body, Chunk};
use crate::error::AepError;
/// Deepest tree [`write`] accepts (a hand-built tree may be deeper than any parsed one).
const MAX_WRITE_DEPTH: usize = 256;
/// Serialises `file`: `RIFX`, the recomputed container size, `Egg!`, the chunks and the trailer.
/// Sizes of the container and of every chunk are recomputed from the tree; an unmodified parsed
/// file comes back byte for byte.
///
/// # Errors
/// [`AepError::TooLarge`] when a chunk or the container exceeds the 32-bit size field,
/// [`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!");
write_sequence(&mut out, &file.chunks, 1)?;
let size = u32::try_from(out.len().saturating_sub(8)).map_err(|_| AepError::TooLarge)?;
patch_u32(&mut out, 4, size)?;
out.extend_from_slice(&file.trailer);
Ok(out)
}
/// Like [`write`], into any writer.
///
/// # Errors
/// A size or depth error of [`write`] becomes `ErrorKind::InvalidData`; otherwise I/O errors.
pub fn write_to(file: &AepFile<'_>, w: &mut impl Write) -> std::io::Result<()> {
let bytes = write(file).map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
w.write_all(&bytes)
}
fn patch_u32(out: &mut [u8], at: usize, v: u32) -> Result<(), AepError> {
let end = at.checked_add(4).ok_or(AepError::TooLarge)?;
let dst = out.get_mut(at..end).ok_or(AepError::TooLarge)?;
for (d, s) in dst.iter_mut().zip(v.to_be_bytes()) {
*d = s;
}
Ok(())
}
fn write_sequence(out: &mut Vec<u8>, chunks: &[Chunk<'_>], depth: usize) -> Result<(), AepError> {
if depth > MAX_WRITE_DEPTH {
return Err(AepError::TooDeep);
}
let count = chunks.len();
for (i, chunk) in chunks.iter().enumerate() {
write_chunk(out, chunk, i + 1 == count, depth)?;
}
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();
out.extend_from_slice(&[0; 4]);
let body_start = out.len();
match &chunk.body {
Body::Data(d) => out.extend_from_slice(d),
Body::Chunks(c) => write_sequence(out, c, depth + 1)?,
Body::List { list_type, children } => {
out.extend_from_slice(list_type);
write_sequence(out, children, depth + 1)?;
}
Body::OpaqueList { list_type, data } => {
out.extend_from_slice(list_type);
out.extend_from_slice(data);
}
}
let len = out.len().saturating_sub(body_start);
patch_u32(out, size_at, u32::try_from(len).map_err(|_| AepError::TooLarge)?)?;
if len % 2 == 1 {
match chunk.pad {
Some(b) => out.push(b),
None if !is_last => out.push(0),
None => {}
}
}
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));
}
}
+390
View File
@@ -0,0 +1,390 @@
# The test cases and the files that hold them
The tests of `craft-aep` (and the After Effects import tests of `effectcraft-engine`) address
a case by the name of the single-case file it was first written against. The cases live in the
combined projects of the corpus (in the folder named by `CRAFT_AEP_FIXTURES`): each case is the composition named like the case without its
extension, built like the single-case file's composition `C` (1920x1080, 25 fps, 5 s, black, one
red 1920x1080 solid `L`) plus the case's change (and the compositions that change uses). A test
gets the case as a project of its own, cut from the combined file (`tests/it/common/mod.rs`).
`empty.aep` and `fx-switch.aep` (the fx switch of an effect instance) are files of their own.
Project settings have one value per project, so the settings cases share the files `settings-*`
(each file holds the changes of all its cases). The generator and how to run it:
[`tools/README.md`](tools/README.md). Every file has an `.attribution` sidecar in the corpus.
| case | file | composition | change |
|---|---|---|---|
| `000-base.aep` | `layers-comps.aep` | `000-base` | base state |
| `000-base.aepx` | `aepx-pair.aepx` | `000-base` | base state |
| `001-empty.aep` | `empty.aep` | (whole file) | an empty project saved by After Effects (no items) |
| `010-layer-name.aep` | `layers-comps.aep` | `010-layer-name` | layer name `L` -> `Renamed` (layer.name; source footage name stays `L`) |
| `012-layer-shy.aep` | `layers-comps.aep` | `012-layer-shy` | layer.shy false -> true |
| `013-layer-locked.aep` | `layers-comps.aep` | `013-layer-locked` | layer.locked false -> true |
| `014-layer-solo.aep` | `layers-comps.aep` | `014-layer-solo` | layer.solo false -> true |
| `015-layer-3d.aep` | `3d.aep` | `015-layer-3d` | layer.threeDLayer false -> true (3D layer switch; adds Orientation/X/Y/Z Rotation, Material Options groups) |
| `016-layer-blend-multiply.aep` | `layers-comps.aep` | `016-layer-blend-multiply` | blending mode Normal -> Multiply |
| `017-layer-motionblur.aep` | `layers-comps.aep` | `017-layer-motionblur` | layer.motionBlur false -> true |
| `018-layer-stretch200.aep` | `keyframes.aep` | `018-layer-stretch200` | time stretch 100 -> 200 (out point becomes 10 s; comp is 5 s) |
| `019-layer-inpoint1.aep` | `layers-comps.aep` | `019-layer-inpoint1` | inPoint 0 -> 1 (AE moved outPoint to 6, startTime stays 0; solid source is unbounded) |
| `021-layer-starttime0.5.aep` | `layers-comps.aep` | `021-layer-starttime0.5` | startTime 0 -> 0.5 (in 0.5, out 5.5) |
| `022-layer-parent-null.aep` | `layers-comps.aep` | `022-layer-parent-null` | NEW null layer "Null" (source "Null 1", 100x100) created on top; L (now index 2) parent = layer 1 (Null). Adds 1 layer + 1 footage item |
| `023-layer-quality-draft.aep` | `layers-comps.aep` | `023-layer-quality-draft` | layer.quality Best -> Draft |
| `024-layer-collapse.aep` | `layers-comps.aep` | `024-layer-collapse` | layer.collapseTransformation false -> true (API call accepted; AE may ignore it for a solid, compare with base) |
| `025-layer-adjustment.aep` | `layers-comps.aep` | `025-layer-adjustment` | layer.adjustmentLayer false -> true |
| `026-layer-guide.aep` | `layers-comps.aep` | `026-layer-guide` | layer.guideLayer false -> true |
| `030-comp-size-1280x720.aep` | `layers-comps.aep` | `030-comp-size-1280x720` | comp width/height 1920x1080 -> 1280x720 (layer L stays 1920x1080, not repositioned) |
| `031-comp-fps30.aep` | `layers-comps.aep` | `031-comp-fps30` | frameRate 25 -> 30 |
| `032-comp-duration10.aep` | `layers-comps.aep` | `032-comp-duration10` | duration 5 -> 10 s (work area duration also becomes 10) |
| `033-comp-bg-green.aep` | `layers-comps.aep` | `033-comp-bg-green` | bgColor [0,0,0] -> [0,1,0] |
| `034-comp-shutter90.aep` | `layers-comps.aep` | `034-comp-shutter90` | shutterAngle 180 -> 90 |
| `035-comp-workarea-1-2.aep` | `layers-comps.aep` | `035-comp-workarea-1-2` | workAreaStart 0 -> 1, workAreaDuration 5 -> 2 |
| `037-comp-pixelaspect2.aep` | `layers-comps.aep` | `037-comp-pixelaspect2` | pixelAspect 1 -> 2 |
| `038-comp-motionblur.aep` | `layers-comps.aep` | `038-comp-motionblur` | comp.motionBlur false -> true |
| `039-comp-renderer-advanced3d.aep` | `3d.aep` | `039-comp-renderer-advanced3d` | renderer `ADBE Advanced 3d` (classic) -> `ADBE Calder` (= "Advanced 3D" friendly name `advanced3d`) |
| `040-static-position-100-200.aep` | `layers-comps.aep` | `040-static-position-100-200` | Position [960,540,0] -> [100,200,0] |
| `041-static-scale-50.aep` | `layers-comps.aep` | `041-static-scale-50` | Scale [100,100,100] -> [50,50,100] |
| `042-static-rotation-45.aep` | `layers-comps.aep` | `042-static-rotation-45` | Rotation 0 -> 45 |
| `043-static-opacity-25.aep` | `layers-comps.aep` | `043-static-opacity-25` | Opacity 100 -> 25 |
| `044-static-anchor-10-20.aep` | `layers-comps.aep` | `044-static-anchor-10-20` | Anchor Point [960,540,0] -> [10,20,0] |
| `052-key-position-2key-ease.aep` | `keyframes.aep` | `052-key-position-2key-ease` | from 051: both keys set_easing preset 'ease' (bezier in/out, speed 0, influence 33) |
| `053-key-position-2key-hold-key1.aep` | `keyframes.aep` | `053-key-position-2key-hold-key1` | from 051: key1 inType/outType = HOLD (key2 stays linear) |
| `054-key-position-2key-spatial-bezier.aep` | `keyframes.aep` | `054-key-position-2key-spatial-bezier` | from 051: key1 spatial outTangent [30,60,0], key2 spatial inTangent [-30,-60,0], autoBezier=false, continuous=false (S-shaped path; verified: value at t=.25 = [23.7,16.95]) |
| `055-key-position-3key-inserted-t2.5.aep` | `keyframes.aep` | `055-key-position-3key-inserted-t2.5` | from 051: 3rd key inserted into the already animated property at t=2.5 value [200,100,0] (= keys at t=0,1,2.5, all linear) |
| `056-key-position-3key-roving-key2.aep` | `keyframes.aep` | `056-key-position-3key-roving-key2` | from 055: key2 roving=true (AE moved key2 to t=1.0355078125, value kept [100,0,0]) |
| `057-key-position-3key-label9-key2.aep` | `keyframes.aep` | `057-key-position-3key-label9-key2` | from 055: key2 keyframe label = 9 (Green). (056 was undone first) |
| `058-key-opacity-2key.aep` | `keyframes.aep` | `058-key-opacity-2key` | Opacity keys t=0 -> 0, t=2 -> 100 (linear) |
| `058-key-opacity-2key.aepx` | `aepx-pair.aepx` | `058-key-opacity-2key` | Opacity keys t=0 -> 0, t=2 -> 100 (linear) |
| `060-expr-opacity-wiggle.aep` | `keyframes.aep` | `060-expr-opacity-wiggle` | Opacity expression `wiggle(1,10)` (enabled, JavaScript engine = project default) |
| `060-expr-opacity-wiggle.aepx` | `aepx-pair.aepx` | `060-expr-opacity-wiggle` | Opacity expression `wiggle(1,10)` (enabled, JavaScript engine = project default) |
| `071-fx-slider-value77.aep` | `effects.aep` | `071-fx-slider-value77` | from 070: Slider 0 -> 77 |
| `073-fx-color-0.2-0.6-1.aep` | `effects.aep` | `073-fx-color-0.2-0.6-1` | add `ADBE Color Control`, Color -> [0.2,0.6,1] (no default-only Color file) |
| `077-fx-dropdown-default.aep` | `effects.aep` | `077-fx-dropdown-default` | add Dropdown Menu Control (matchName `Pseudo/@@S1iPXtJFTHK4QaDbgJvLhw`, default items) |
| `080-fx-dropshadow-default.aep` | `effects.aep` | `080-fx-dropshadow-default` | add `ADBE Drop Shadow` (default params) |
| `090-mask-rect.aep` | `masks.aep` | `090-mask-rect` | mask.add rect size [800,400] centre [960,540]: "Mask 1", vertices [560,340],[1360,340],[1360,740],[560,740], mode Add |
| `091-mask-rect-props.aep` | `masks.aep` | `091-mask-rect-props` | from 090: feather [0,0]->[20,20], opacity 100->50, mode Add->Subtract, inverted false->true, expansion 0->5 |
| `093-mask-path-2keys.aep` | `masks.aep` | `093-mask-path-2keys` | from 090: mask path keyed: t=0 rect 400x200 (vertices [760,440],[1160,440],[1160,640],[760,640]), t=1 rect 800x400; linear interp. NOTE: mask.set_path 'time' makes the first write at t=0 the first key (stopwatch on) |
| `110-text-A.aep` | `text.aep` | `110-text-A` | new point text layer T, text "A" (defaults: Times New Roman TimesNewRomanPSMT, size 100, fill white) |
| `110-text-A.aepx` | `aepx-pair.aepx` | `110-text-A` | new point text layer T, text "A" (defaults: Times New Roman TimesNewRomanPSMT, size 100, fill white) |
| `113-text-Hello-size60-fillorange.aep` | `text.aep` | `113-text-Hello-size60-fillorange` | from 112: fillColor [1,1,1] -> [1,0.5,0] |
| `114-text-animator-opacity.aep` | `text.aep` | `114-text-animator-opacity` | from 113: + text animator "Animator 1" with Opacity=0 and a Range Selector 1 |
| `122-marker-comp-1s.aep` | `markers.aep` | `122-marker-comp-1s` | comp marker at t=1 s, comment "CompMarker" |
| `123-marker-layer-1s.aep` | `markers.aep` | `123-marker-layer-1s` | layer marker on L at t=1 s, comment "LayerMarker" |
| `124-precomp-Pre.aep` | `footage-precomp.aep` | `124-precomp-Pre` | L precomposed (moveAll) into new comp "Pre" (1920x1080, 25 fps, 5 s); C now holds one layer "Pre" (label 15). Adds comp item "Pre" |
| `124-precomp-Pre.aepx` | `aepx-pair.aepx` | `124-precomp-Pre` | L precomposed (moveAll) into new comp "Pre" (1920x1080, 25 fps, 5 s); C now holds one layer "Pre" (label 15). Adds comp item "Pre" |
| `126-footage-png-layer.aep` | `footage-precomp.aep` | `126-footage-png-layer` | from 125: layer "png" created from that footage in C (index 1 above L) |
| `202-key-out-hold-in-linear.aep` | `keyframes.aep` | `202-key-out-hold-in-linear` | Position keys t=0 [0,0,0], t=1 [100,0,0]; key1 inType=LINEAR, outType=HOLD (key2 linear/linear). Confirmed by layer.info: key1 in=linear out=hold |
| `203-key-in-hold-out-linear.aep` | `keyframes.aep` | `203-key-in-hold-out-linear` | same keys; key1 inType=HOLD, outType=LINEAR. Confirmed: key1 in=hold out=linear |
| `204-key-ease-asymmetric.aep` | `keyframes.aep` | `204-key-ease-asymmetric` | Position keys t=0 [0,0,0], t=1 [100,0,0]; set_easing key1 inSpeed 5/inInfluence 20, outSpeed 50/outInfluence 80; key2 inSpeed 7/inInfl 60, outSpeed 9/outInfl 40. AE read-back (spatial property): key1 in speed forced to 0 (infl 20), key1 out 50/80, key2 in 7/60, key2 out speed forced to 0 (infl 40); both bezier/bezier |
| `205-key-opacity-ease-asymmetric.aep` | `keyframes.aep` | `205-key-opacity-ease-asymmetric` | (extra) Opacity keys t=0 -> 0, t=2 -> 100; set_easing key1 inSpeed 5/inInfl 20, outSpeed 20/outInfl 80; key2 inSpeed 30/inInfl 60, outSpeed 9/outInfl 40. AE read-back: key1 in speed 0 (infl 20), key1 out 20/80, key2 in 30/60, key2 out speed 0 (infl 40); bezier/bezier (scalar 48-byte record ease slots) |
| `206-key-scale-2key-linear.aep` | `keyframes.aep` | `206-key-scale-2key-linear` | Scale keys t=0 [100,100,100], t=1 [200,150,100] (linear; 3-component non-spatial record) |
| `208-key-mask-feather-2key-linear.aep` | `masks.aep` | `208-key-mask-feather-2key-linear` | NEW mask "Mask 1" (rect 800x400 centre [960,540], mode Add, = 090) + Mask Feather keys t=0 [0,0], t=1 [40,20] (linear, 2-D). Diff against 090 |
| `210-key-fill-color-2key-linear.aep` | `keyframes.aep` | `210-key-fill-color-2key-linear` | effect `ADBE Fill` (index 1) added (all other params default); Color keys t=0 [1,0,0], t=1 [0,0.5,1] (linear, colour record) |
| `211-anchor-100x100-solid-10-20.aep` | `layers-comps.aep` | `211-anchor-100x100-solid-10-20` | NEW solid layer `S100` 100x100 white [1,1,1] (new footage item `S100`) in the 1920x1080 comp, Anchor Point set [50,50,0] (default) -> [10,20,0]; Position left at default (comp centre [960,540]) |
| `212-anchor-400x300-solid-100-50.aep` | `layers-comps.aep` | `212-anchor-400x300-solid-100-50` | NEW solid layer `S400` 400x300 white [1,1,1] (new footage item `S400`), Anchor Point -> [100,50,0]; Position default |
| `213-expr-opacity-wiggle-disabled.aep` | `keyframes.aep` | `213-expr-opacity-wiggle-disabled` | Opacity expression `wiggle(1,10)` set (as in 060) and then `expression.disable_all` on comp C (sets expressionEnabled=false; the expression text stays in the file, grep confirms 1 occurrence). Diff against 060 to find the enable flag |
| `214-fx-gaussianblur-default.aep` | `effects.aep` | `214-fx-gaussianblur-default` | add `ADBE Gaussian Blur 2`, all params default (Blurriness 0, Dimensions Horizontal and Vertical, Repeat Edge Pixels off) |
| `215-fx-fill-default.aep` | `effects.aep` | `215-fx-fill-default` | add `ADBE Fill`, all params default (colour red, opacity 100 %) |
| `216-fx-gaussianblur-40.aep` | `effects.aep` | `216-fx-gaussianblur-40` | add `ADBE Gaussian Blur 2`, Blurriness 0 -> 40 (compare 214 and 078 = 25) |
| `217-fx-checkbox-on.aep` | `effects.aep` | `217-fx-checkbox-on` | add `ADBE Checkbox Control`, Checkbox 0 -> 1 (on) |
| `218-fx-point-111-222.aep` | `effects.aep` | `218-fx-point-111-222` | add `ADBE Point Control`, Point -> [111,222] |
| `219-fx-angle-90.aep` | `effects.aep` | `219-fx-angle-90` | add `ADBE Angle Control`, Angle 0 -> 90 |
| `220-fx-layercontrol-to-layer1.aep` | `effects.aep` | `220-fx-layercontrol-to-layer1` | NEW null layer `Null` created on top (index 1, new footage item `Null 1`); L (now index 2) gets `ADBE Layer Control` with Layer = 1 (the Null; layer index 1, read back as value 1). Compare 076 (Layer = None) and 022 (same null) |
| `221-fx-slider-2key.aep` | `effects.aep` | `221-fx-slider-2key` | add `ADBE Slider Control`, Slider keyed t=0 -> 10, t=2 -> 90 (linear) |
| `222-layer-video-off.aep` | `layers-comps.aep` | `222-layer-video-off` | layer.enabled true -> false (Video switch). aepx `ldta` byte 39: 07 -> 06 |
| `223-layer-audio-off.aep` | `layers-comps.aep` | `223-layer-audio-off` | `audioEnabled` = false on L (a solid has no audio; AE accepted it without warning and the flag did change: byte 39: 07 -> 05) |
| `224-layer-effects-off.aep` | `layers-comps.aep` | `224-layer-effects-off` | `effectsActive` = false on L (no effects present; byte 39: 07 -> 03) |
| `225-layer-blend-screen.aep` | `layers-comps.aep` | `225-layer-blend-screen` | blending mode Normal -> Screen (aepx `ldta` byte 99 = 6) |
| `226-layer-blend-add.aep` | `layers-comps.aep` | `226-layer-blend-add` | blending mode Normal -> Add (byte 99 = 4) |
| `227-layer-blend-overlay.aep` | `layers-comps.aep` | `227-layer-blend-overlay` | blending mode Normal -> Overlay (byte 99 = 7) |
| `228-layer-blend-difference.aep` | `layers-comps.aep` | `228-layer-blend-difference` | blending mode Normal -> Difference (byte 99 = 26) |
| `229-comp-fps-29.97.aep` | `layers-comps.aep` | `229-comp-fps-29.97` | comp frameRate 25 -> 29.97 (AE read-back 29.9700012207031; duration snapped 5 s -> 5.00500500500501 s = 150 frames; work area duration follows) |
| `230-comp-fps-23.976.aep` | `layers-comps.aep` | `230-comp-fps-23.976` | comp frameRate 25 -> 23.976 (read-back 23.9759979248047; duration snapped to 5.00500500500501 s = 120 frames) |
| `231-comp-bg-grey-0.5.aep` | `layers-comps.aep` | `231-comp-bg-grey-0.5` | comp bgColor [0,0,0] -> [0.5,0.5,0.5] (read-back 0.50196078431373 = 128/255 on all channels) |
| `232-mask-ellipse.aep` | `masks.aep` | `232-mask-ellipse` | mask.add shape ellipse size [800,400] centre [960,540], mode Add. AE read-back of the path: vertices [960,340],[1360,540],[960,740],[560,540]; inTangents [-220.913879394531,0],[0,-110.456970214844],[220.913940429688,0],[0,110.456970214844]; outTangents [220.913940429688,0],[0,110.456970214844],[-220.913879394531,0],[0,-110.456970214844]; closed |
| `233-mask-open-path.aep` | `masks.aep` | `233-mask-open-path` | mask.add (no shape, mode Add) + mask.set_path vertices [500,300],[960,700],[1400,300], closed=false, no tangents. Read-back closed=false, vertices stored as float32 (499.999969482422, 699.999938964844) |
| `234-mask-mode-intersect.aep` | `masks.aep` | `234-mask-mode-intersect` | rect mask 800x400 centre [960,540] (as 090) with mode Intersect (aepx `mkif` @4 = 3; Add = 1 in 090) |
| `235-mask-mode-lighten.aep` | `masks.aep` | `235-mask-mode-lighten` | same rect, mode Lighten |
| `236-mask-mode-darken.aep` | `masks.aep` | `236-mask-mode-darken` | same rect, mode Darken |
| `237-mask-mode-difference.aep` | `masks.aep` | `237-mask-mode-difference` | same rect, mode Difference |
| `238-shape-rect-rounded-corners.aep` | `shapes.aep` | `238-shape-rect-rounded-corners` | Group 1 = Rectangle Path 400x300 + Fill [0,1,0] + `shape.add_rounded_corners` radius 20 ("Round Corners 1", `ADBE Vector Filter - RC`, `ADBE Vector RoundCorner Radius` 20) |
| `239-shape-stroke-green-w8-round.aep` | `shapes.aep` | `239-shape-stroke-green-w8-round` | Group 1 = Rectangle Path 400x300 + Stroke colour [0,1,0,1] width 8, Line Cap = 2 (Round), Line Join = 2 (Round); NO fill; read back: cap 2, join 2 |
| `240-shape-custom-path-tangents.aep` | `shapes.aep` | `240-shape-custom-path-tangents` | Group 1 = Path (closed) vertices [0,-100],[100,100],[-100,100], inTangents [-10,-20],[30,20],[-60,10], outTangents [40,0],[-20,30],[0,-50] (read back out2 = -19.9999847412109) + Fill [0,1,0] |
| `241-shape-gradient-fill-linear.aep` | `shapes.aep` | `241-shape-gradient-fill-linear` | Group 1 = Rectangle Path 400x300 + Gradient Fill 1 (`ADBE Vector Graphic - G-Fill`), linear, start [-200,0], end [200,0]; colour stops left at AE's default (not scriptable) |
| `242-shape-group-position-50-50.aep` | `shapes.aep` | `242-shape-group-position-50-50` | Group 1 = Rectangle Path 400x300 + Fill [0,1,0]; Group 1 / Transform / Position [0,0] -> [50,50] |
| `243-text-multiline-A-CR-B.aep` | `text.aep` | `243-text-multiline-A-CR-B` | point text layer T, text `A\rB` (CR between, 2 paragraphs / 2 lines) |
| `245-text-box-400x200-Hello.aep` | `text.aep` | `245-text-box-400x200-Hello` | paragraph (box) text layer T, `Hello`, boxSize [400,200] (AE: box position [-200,-100] in layer space), left aligned (default) |
| `246-text-box-center-align.aep` | `text.aep` | `246-text-box-center-align` | FROM 245 (not from base): justification left -> center (one variable vs 245) |
| `247-text-tracking-100.aep` | `text.aep` | `247-text-tracking-100` | point text `Hello` with tracking 0 -> 100 (whole document, text.set_style tracking 100) |
| `248-text-range-fill-red-1-3.aep` | `text.aep` | `248-text-range-fill-red-1-3` | point text `Hello`; per-range style: characters [1,3) ("el") fill colour [1,0,0]; rest white |
| `249-marker-layer-full.aep` | `markers.aep` | `249-marker-layer-full` | layer marker on L at t=1 s: comment `LM`, duration 1 s, chapter `Chap`, url `http://a.example/u`, frameTarget `_blank`, cuePointName `CueX` (AE read-back: eventCuePoint=true, label 0, params {}). All four link strings non-empty and distinct so that the string order in `Nmrd` can be decided |
| `251-camera-one-node.aep` | `3d.aep` | `251-camera-one-node` | camera layer `Camera 1` (default 50 mm, label 4) with autoOrient = off (one-node camera). aepx `ldta` byte 38 of the camera: 0x44 (two-node, 120/256) -> 0x04, so bit 0x40 = "orient towards point of interest". AE's summary reports Position [0,0,-2666.67] for this layer (a two-node camera reports [960,540,-2666.67] as in 120) |
| `252-light-point.aep` | `3d.aep` | `252-light-point` | light layer `Light 1`, lightType point (default intensity 100 %, label 6) |
| `253-camera-position-100-200-m1000.aep` | `3d.aep` | `253-camera-position-100-200-m1000` | two-node camera `Camera 1`, Position [960,540,-2666.67] -> [100,200,-1000] (read back [100,200,-1000], Point of Interest stays [960,540,0]) |
| `254-light-spot-intensity-50.aep` | `3d.aep` | `254-light-spot-intensity-50` | spot light `Light 1`, Light Options / Intensity 100 -> 50 |
| `256-camera-two-node-default.aep` | `3d.aep` | `256-camera-two-node-default` | (extra, noise-matched reference) default two-node camera `Camera 1`, compare 251, 253 and 120 |
| `259-solid-blue-0-0-1.aep` | `layers-comps.aep` | `259-solid-blue-0-0-1` | NEW solid layer `Blue` [0,0,1], comp size 1920x1080, on top of L (new footage item `Blue`); the colour sits in the `Soli` footage `opti` (compare L red = 1.0,1.0,0,0 as float32 ARGB) |
| `299-save-noise.aep` | `layers-comps.aep` | `299-save-noise` | plain save of the freshly loaded base copy (no change at all) to measure save noise of THIS session; compare with 000-base and 200/201 |
| `300-fx-gaussianblur-0-explicit.aep` | `effects.aep` | `300-fx-gaussianblur-0-explicit` | layer 1 effect `ADBE Gaussian Blur 2` added; AE read-back of Blurriness right after add = **25** (property.get value 25, numKeys 0); then Blurriness set explicitly 25 -> 0 (read back 0) |
| `301-fx-gaussianblur-40-then-25.aep` | `effects.aep` | `301-fx-gaussianblur-40-then-25` | `ADBE Gaussian Blur 2` added, Blurriness 25 -> 40 -> 25 (set twice in one call; read back 25) |
| `302-fx-fill-opacity-100-explicit.aep` | `effects.aep` | `302-fx-fill-opacity-100-explicit` | `ADBE Fill` added (default Opacity read back 1 = 100 %; scale of effect.set_property is 0..1, 100 is rejected "out of range 0 to 1"); Opacity set explicitly to 1 |
| `303-fx-fill-opacity-50-then-100.aep` | `effects.aep` | `303-fx-fill-opacity-50-then-100` | `ADBE Fill` added, Opacity 1 -> 0.5 -> 1 (read back 1) |
| `304-fx-slider-0-explicit.aep` | `effects.aep` | `304-fx-slider-0-explicit` | `ADBE Slider Control` added, Slider set explicitly 0 -> 0 (default is 0; read back 0) |
| `305-key-scale-bezier-ease.aep` | `keyframes.aep` | `305-key-scale-bezier-ease` | layer 1 Transform/Scale keys t=0 [100,100,100] and t=2 [200,150,100]; set_easing key1 inSpeed 0/inInfl 33, outSpeed 20/outInfl 66; key2 inSpeed 10/inInfl 66, outSpeed 0/outInfl 33. AE read-back: bezier/bezier on both, ease arrays 3 identical entries per side with exactly these values |
| `306-key-maskfeather-bezier-ease.aep` | `masks.aep` | `306-key-maskfeather-bezier-ease` | NEW mask `Mask 1` (rect 800x400 centre [960,540], vertices [560,340],[1360,340],[1360,740],[560,740], mode Add) + Mask Feather keys t=0 [0,0], t=2 [50,30]; key1 inSpeed 0/infl 33, outSpeed 15/infl 66; key2 inSpeed 8/infl 66, outSpeed 0/infl 33; read back as set (2 ease entries per side) |
| `307-key-fillcolor-bezier.aep` | `keyframes.aep` | `307-key-fillcolor-bezier` | `ADBE Fill` added; Color keys t=0 [1,0,0,1], t=2 [0,0,1,1] (value at t=1 read back [0.5,0,0.5,1]); both keys then set_interpolation inType/outType bezier (temporalContinuous/AutoBezier false). AE read-back ease: speed 0 / influence 0 on all four sides (colour has 1 ease entry, AE reports influence 0, not the 16.67 default) |
| `309-solid-100x100-mask-rect.aep` | `masks.aep` | `309-solid-100x100-mask-rect` | 308 + `mask.add` shape rect size [60,40] centre [50,50], mode Add; AE read-back path vertices [20,30],[80,30],[80,70],[20,70], all tangents 0 |
| `310-solid-100x100-pointcontrol.aep` | `layers-comps.aep` | `310-solid-100x100-pointcontrol` | 308 (NOT 309) + effect `ADBE Point Control`; AE read-back of the default Point = **[50,50]** = centre of the 100x100 layer (a 1920x1080 layer would give [960,540]; compare 074) |
| `311-position-default-explicit.aep` | `layers-comps.aep` | `311-position-default-explicit` | property.set Transform/Position [960,540,0] (was [960,540,0]) |
| `316-layer-stretch50.aep` | `keyframes.aep` | `316-layer-stretch50` | layer.set_timing stretch 100 -> 50 (AE: out point 5 -> 2.5, in 0, start 0) |
| `317-layer-stretch150.aep` | `keyframes.aep` | `317-layer-stretch150` | stretch 100 -> 150 (out point 7.5) |
| `318-layer-inpoint-0.3333.aep` | `layers-comps.aep` | `318-layer-inpoint-0.3333` | inPoint 0 -> 0.3333 (AE read-back: inPoint 0.33328125, outPoint 5.33328125, start 0, stretch 100; the requested 0.3333 was quantised by AE) |
| `319-precomp-timeremap.aep` | `footage-precomp.aep` | `319-precomp-timeremap` | SKIPPED on the solid (AE: "Can not set timeRemapEnabled ... canSetTimeRemapEnabled" for solids). Instead: L precomposed (moveAll) into `Pre` as in 124 (layer `Pre`, label 15) AND timeRemapEnabled = true on layer `Pre`; two variables vs base, one vs 124. AE read-back: Time Remap keys t=0 value 0 and t=5 value 5, linear/linear |
| `320-fx-layercontrol-self-explicit.aep` | `effects.aep` | `320-fx-layercontrol-self-explicit` | `ADBE Layer Control` added (default Layer read back 1) + Layer set explicitly to 1 (no-op) |
| `321-fx-layercontrol-none.aep` | `effects.aep` | `321-fx-layercontrol-none` | FROM 320: Layer 1 -> 0 (None; read back 0) |
| `323-fx-dropdown-5items.aep` | `effects.aep` | `323-fx-dropdown-5items` | `ADBE Dropdown Control` added (AE reports the effect matchName as `Pseudo/@@UNgGeIbLTy24Y7LB8Oar1Q`, display name `Dropdown Menu Control`), effect.set_dropdown_items ["Alpha","Beta","Gamma","Delta","Epsilon"]; read back value 1 / "Alpha" |
| `324-fx-dropdown-5items-select3.aep` | `effects.aep` | `324-fx-dropdown-5items-select3` | FROM 323: Menu set to 3 (read back value 3, valueText "Gamma"); NOTE the property matchName after the re-creation is `Pseudo/@@KbKT0rCPQi2A0ytuyGLWSw-0001` |
| `325-comp-pixelaspect-0.9091.aep` | `layers-comps.aep` | `325-comp-pixelaspect-0.9091` | pixelAspect 1 -> 0.9091 (AE read-back 0.90909090909091 = 10/11) |
| `326-comp-shutterphase-m90.aep` | `layers-comps.aep` | `326-comp-shutterphase-m90` | shutterPhase 0 -> -90 (read back -90; shutterAngle stays 180) |
| `327-comp-displaystartframe-100.aep` | `layers-comps.aep` | `327-comp-displaystartframe-100` | displayStartFrame 0 -> 100 (accepted without warning; comp.info does not report it, but the cdta bytes in the .aepx change vs 326: a (value,scale) pair 00000190 / 00000064 (= 400/100 = 4 s = 100 frames at 25 fps) appears in the tail, and the shutter phase `ffffffa6` of 326 is back to 0) |
| `328-mask-two-ellipse-rect.aep` | `masks.aep` | `328-mask-two-ellipse-rect` | mask.add ellipse 800x400 centre [960,540] (Mask 1, vertices as 232) + mask.add rect 400x300 centre [700,500] (Mask 2, vertices [500,350],[900,350],[900,650],[500,650] with float noise 499.999969482422 etc.); both mode Add (default) |
| `329-mask-ellipse-mode-none.aep` | `masks.aep` | `329-mask-ellipse-mode-none` | mask.add ellipse 800x400 centre [960,540] with mode None (compare 232 = same path, mode Add); AE offers no read-back of the mode via property.get (Mask Mode is not a listed property) |
| `330-shape-polystar-star-5-50-100.aep` | `shapes.aep` | `330-shape-polystar-star-5-50-100` | Polystar Path 1 starType star, Points 5, Outer Radius 100, Inner Radius 50 (Points/Inner/Outer read back as set; Type not read), roundness/rotation/position left default + Fill [0,1,0,1] |
| `331-shape-polystar-polygon-5-100.aep` | `shapes.aep` | `331-shape-polystar-polygon-5-100` | Polystar Path 1 starType polygon (Type read back = 2), Points 5, Outer Radius 100 + Fill [0,1,0,1] |
| `332-shape-gradient-fill-radial.aep` | `shapes.aep` | `332-shape-gradient-fill-radial` | Rectangle Path 400x300 + Gradient Fill 1 `ADBE Vector Graphic - G-Fill`, gradientType radial (Type read back 2), Start Point [0,0], End Point [200,0], Highlight Length/Angle 0, Scale [100,100], Rotation 0; colour stops default (not scriptable); compare 241 (linear, type 1) |
| `333-shape-group-two-rects.aep` | `shapes.aep` | `333-shape-group-two-rects` | Group 1 contents: Rectangle Path 1 size [400,300] + Rectangle Path 2 size [100,100] position [300,0] + Fill 1 [0,1,0,1] (order rect, rect, fill) |
| `334-text-box-right-align.aep` | `text.aep` | `334-text-box-right-align` | paragraph (box) text `T` "Hello", boxSize [400,200] (boxTextPos [-200,-100]), justification right (AE justification enum 7414; compare 245: left, 246: center) |
| `335-text-point-fauxbold.aep` | `text.aep` | `335-text-point-fauxbold` | point text "Hello" with fauxBold = true (fontStyle read back still "Regular"; font TimesNewRomanPSMT) |
| `336-text-point-fauxitalic.aep` | `text.aep` | `336-text-point-fauxitalic` | point text "Hello" (vs 244) with fauxItalic = true |
| `337-text-point-allcaps.aep` | `text.aep` | `337-text-point-allcaps` | point text "Hello" with allCaps = true (fontCapsOption) |
| `338-text-point-smallcaps.aep` | `text.aep` | `338-text-point-smallcaps` | point text "Hello" with smallCaps = true |
| `339-text-point-leading60.aep` | `text.aep` | `339-text-point-leading60` | point text "Hello" with leading 60 (autoLeading default read back leading 98 -> 60; read back 60; justification 7413 = left) |
| `340-text-range-two-styles.aep` | `styles.aep` | `340-text-range-two-styles` | point text "Hello" with two range styles in one call: characters [1,3) ("el") fill [1,0,0]; characters [3,5) ("lo") fill [0,0,1] and fontSize 60 (compare 248 = one range) |
| `341-camera-zoom-2000.aep` | `3d.aep` | `341-camera-zoom-2000` | camera layer `Camera 1` (default 50 mm; default Zoom read back 2666.6666666), Camera Options/Zoom set to 2000 (read back 2000) |
| `342-camera-dof-800-30.aep` | `3d.aep` | `342-camera-dof-800-30` | camera layer `Camera 1`, Camera Options/Depth of Field 0 -> 1, Focus Distance -> 800, Aperture -> 30 (all read back as set; Zoom stays default) |
| `343-light-spot-color-red.aep` | `3d.aep` | `343-light-spot-color-red` | spot light `Light 1` (defaults read back: Color [1,1,1,1], Cone Angle 90, Cone Feather 50) with Light Options/Color [1,0,0,1] |
| `344-light-spot-coneangle-60.aep` | `3d.aep` | `344-light-spot-coneangle-60` | spot light `Light 1`, Cone Angle 90 -> 60 (Color stays white; the spot light was created once as step 0 and kept for 343-345, each change undone before the next) |
| `345-light-spot-conefeather-30.aep` | `3d.aep` | `345-light-spot-conefeather-30` | spot light `Light 1`, Cone Feather 50 -> 30 |
| `347-marker-layer-label3.aep` | `markers.aep` | `347-marker-layer-label3` | marker.add_layer label 3; read back: label 3, eventCuePoint true, duration 0, strings empty, params {} |
| `348-marker-layer-navigation-cue.aep` | `markers.aep` | `348-marker-layer-navigation-cue` | cuePointName `CueN`, eventCuePoint = false (navigation cue); read back label 0, eventCuePoint false |
| `349-marker-layer-event-cue-params.aep` | `markers.aep` | `349-marker-layer-event-cue-params` | cuePointName `CueE`, eventCuePoint = true, params {"speaker":"A","n":"2"}; read back identical |
| `350-footage-wav-imported.aep` | `footage-precomp.aep` | `350-footage-wav-imported` | project.import_file test-tone.wav (name `test-tone.wav`, new footage item id 32, AE: width 0, height 0, duration 1, numItems 4); no layer |
| `351-footage-wav-as-layer.aep` | `footage-precomp.aep` | `351-footage-wav-as-layer` | FROM 350: layer.create_footage -> audio layer `test-tone.wav` on top of L in C (hasAudio true, hasVideo false, in 0, out 1, label 7); audio group not reported by the summary |
| `352-footage-pngseq-imported.aep` | `footage-precomp.aep` | `352-footage-pngseq-imported` | project.import_file seq_001.png with sequence=true -> footage item `seq_[001-003].png` (id 34, 64x64, duration 0.1 s = 3 frames at AE's default 30 fps); no layer |
| `354-footage-pngseq-timeremap.aep` | `footage-precomp.aep` | `354-footage-pngseq-timeremap` | FROM 353: timeRemapEnabled = true on the sequence layer; read back Time Remap keys t=0 value 0, t=0.1 value 0.1, linear/linear (this is the time-remap case that works on real footage; the solid in 319 cannot, so 319 uses a precomp) |
| `356-fx-tint-default.aep` | `effects.aep` | `356-fx-tint-default` | add `ADBE Tint` (default name "Tint", all parameters default) |
| `357-fx-tint-black-0.2-0.4-0.6.aep` | `effects.aep` | `357-fx-tint-black-0.2-0.4-0.6` | FROM 356: Map Black To [0,0,0] -> [0.2,0.4,0.6] (read back [0.20000000298023,0.40000000596046,0.60000002384186,1]) |
| `361-fx-tint-amount-0.aep` | `effects.aep` | `361-fx-tint-amount-0` | FROM 356: Amount to Tint 100 -> 0 |
| `363-fx-tint-amount-2key.aep` | `effects.aep` | `363-fx-tint-amount-2key` | FROM 356: Amount to Tint keyed t=0 -> 20, t=2 -> 80 (linear; value at t=1 read back 50) |
| `364-fx-tint-white-2key.aep` | `effects.aep` | `364-fx-tint-white-2key` | FROM 356: Map White To keyed t=0 -> [1,1,0], t=2 -> [0,0,1] (linear; value at t=1 read back [0.5,0.5,0.5,1]) |
| `366-fx-blur-then-tint.aep` | `effects.aep` | `366-fx-blur-then-tint` | FROM 365: effect.move Gaussian Blur 2 -> 1 (stack Gaussian Blur, Tint; read back order ["Gaussian Blur","Tint"]) |
| `368-fx-ramp-default.aep` | `effects.aep` | `368-fx-ramp-default` | add `ADBE Ramp` (default name "Gradient Ramp", all parameters default) |
| `369-fx-ramp-start-100-200.aep` | `effects.aep` | `369-fx-ramp-start-100-200` | FROM 368: Start of Ramp [960,0] -> [100,200] |
| `371-fx-ramp-startcolor-red.aep` | `effects.aep` | `371-fx-ramp-startcolor-red` | FROM 368: Start Color [0,0,0] -> [1,0,0]. |
| `374-fx-ramp-end-2000-m100.aep` | `effects.aep` | `374-fx-ramp-end-2000-m100` | FROM 368: End of Ramp [960,1080] -> [2000,-100] (outside the layer) |
| `377-fx-ramp-shape-radial.aep` | `effects.aep` | `377-fx-ramp-shape-radial` | FROM 368: Ramp Shape 1 -> 2 (Radial Ramp; read back 2) |
| `378-fx-ramp-scatter-12.aep` | `effects.aep` | `378-fx-ramp-scatter-12` | FROM 368: Ramp Scatter 0 -> 12 |
| `380-fx-ramp-blend-25pct.aep` | `effects.aep` | `380-fx-ramp-blend-25pct` | FROM 368: Blend With Original 0 -> 0.25 (= 25 %; a first attempt with 25 was rejected by AE and changed nothing) |
| `382-fx-ramp-start-2key.aep` | `effects.aep` | `382-fx-ramp-start-2key` | FROM 368: Start of Ramp keyed t=0 -> [100,100], t=2 -> [1800,900] (linear; value at t=1 read back [950,500]) |
| `383-fx-ramp-on-100x100-start-10-20.aep` | `effects.aep` | `383-fx-ramp-on-100x100-start-10-20` | FROM 368 (L keeps its DEFAULT Gradient Ramp): TWO changes in one call: NEW solid layer `S100` 100x100 white [1,1,1] on top (new footage item `S100`, layer index 1) AND a Gradient Ramp on S100 with Start of Ramp -> [10,20]; AE read-back of the S100 ramp's default End of Ramp = [50,100] (relative to the 100x100 layer). Two Ramp instances of the same type on two layers |
| `385-text-anchor-10-20.aep` | `text.aep` | `385-text-anchor-10-20` | FROM 384: text layer T Anchor Point -> [10,20]. Stored as cdat f64 pixels [10, 20] (not a fraction of a source size): confirms the text-anchor rule (was H) |
| `386-text-etx-A-B.aep` | `text.aep` | `386-text-etx-A-B` | FROM 384 (anchor undone): T text -> "A" U+0003 "B". Stored as UTF-16 U+0003. AE text.measure: 2 composed lines, 2 paragraphs, baselines at y 0 and 98 – exactly the same layout as 387 (CR): AE treats U+0003 as a line break |
| `389-fx-exposure-default.aep` | `effects.aep` | `389-fx-exposure-default` | add `ADBE Exposure2` (default name "Exposure", all parameters default) |
| `390-fx-exposure-channels-individual.aep` | `effects.aep` | `390-fx-exposure-channels-individual` | FROM 389: Channels 1 -> 2 (Individual Channels; read back 2) |
| `391-fx-exposure-master-1.5.aep` | `effects.aep` | `391-fx-exposure-master-1.5` | FROM 389: Exposure 0 -> 1.5 (Master Exposure `-0003`) |
| `393-fx-exposure-offset-0.1.aep` | `effects.aep` | `393-fx-exposure-offset-0.1` | FROM 389: Offset 0 -> 0.1 (Master Offset `-0004`; read back 0.10000000149012) |
| `394-fx-exposure-gamma-2.2.aep` | `effects.aep` | `394-fx-exposure-gamma-2.2` | FROM 389: Gamma Correction 1 -> 2.2 (Master `-0005`; read back 2.20000004768372) |
| `395-fx-exposure-individual-red-1.aep` | `effects.aep` | `395-fx-exposure-individual-red-1` | FROM 389: TWO changes in one call: Channels 1 -> 2 AND Red Exposure 0 -> 1 (`-0008`) |
| `396-fx-exposure-bypass-on.aep` | `effects.aep` | `396-fx-exposure-bypass-on` | FROM 389: Bypass Linear Light Conversion 0 -> 1 (`-0022`) |
| `397-fx-exposure-master-2key.aep` | `effects.aep` | `397-fx-exposure-master-2key` | FROM 389: Exposure keyed t=0 -> -1, t=2 -> 2 (linear; value at t=1 read back 0.5) |
| `400-text-autoleading-on.aep` | `text.aep` | `400-text-autoleading-on` | FROM 399: T (text "A" CR "B", size 100, explicit leading 98) Auto Leading -> ON. AE text.measure: second baseline 120 px below the first (= 1.2 x size 100), was 98 in 387/399 |
| `403-matte-L-alpha-M.aep` | `layers-comps.aep` | `403-matte-L-alpha-M` | FROM 402: L (index 2) track matte = layer M, type alpha (`AVLayer.setTrackMatte`); AE switched M's video off by itself (comp.info: M enabled false) |
| `404-matte-L-alphainv-M.aep` | `layers-comps.aep` | `404-matte-L-alphainv-M` | FROM 402: L track matte = M, alpha inverted (M video off by AE) |
| `405-matte-L-luma-M.aep` | `layers-comps.aep` | `405-matte-L-luma-M` | FROM 402: L track matte = M, luma (M video off by AE) |
| `406-matte-L-lumainv-M.aep` | `layers-comps.aep` | `406-matte-L-lumainv-M` | FROM 402: L track matte = M, luma inverted (M video off by AE) |
| `407-matte-M-alpha-L-below.aep` | `layers-comps.aep` | `407-matte-M-alpha-L-below` | FROM 402: M (index 1) track matte = L (index 2, BELOW the target), alpha (L video off by AE) |
| `408-matte-L-alpha-M-visible.aep` | `layers-comps.aep` | `408-matte-L-alpha-M-visible` | FROM 402: TWO changes in one call: L track matte = M alpha AND M video switch back on (comp.info: M enabled true) |
| `410-fx-invert-channel-2.aep` | `effects.aep` | `410-fx-invert-channel-2` | FROM 409: Channel 1 -> 2 |
| `411-fx-invert-blend-50.aep` | `effects.aep` | `411-fx-invert-blend-50` | FROM 409: Blend With Original 0 -> 50 (percent; accepted as 50) |
| `413-fx-fastbox-radius-20.aep` | `effects.aep` | `413-fx-fastbox-radius-20` | FROM 412: Blur Radius 0 -> 20 |
| `414-fx-fastbox-iterations-1.aep` | `effects.aep` | `414-fx-fastbox-iterations-1` | FROM 412: Iterations 3 -> 1 |
| `416-fx-fastbox-repeatedge-off.aep` | `effects.aep` | `416-fx-fastbox-repeatedge-off` | FROM 412: Repeat Edge Pixels 1 -> 0 |
| `418-fx-gaussian-dimensions-3.aep` | `effects.aep` | `418-fx-gaussian-dimensions-3` | FROM 417: Blur Dimensions 1 -> 3 |
| `419-fx-gaussian-repeatedge-off.aep` | `effects.aep` | `419-fx-gaussian-repeatedge-off` | FROM 417: Repeat Edge Pixels 1 -> 0 |
| `422-fx-dropshadow-opacity-204.aep` | `effects.aep` | `422-fx-dropshadow-opacity-204` | FROM 420: Opacity 127.5 -> 204 (scripting scale 0..255; 204 = 80 %) |
| `426-fx-dropshadow-shadowonly-on.aep` | `effects.aep` | `426-fx-dropshadow-shadowonly-on` | FROM 420: Shadow Only 0 -> 1 |
| `427-fx-glow-default.aep` | `effects.aep` | `427-fx-glow-default` | (Drop Shadow removed) add `ADBE Glo2` "Glow" (defaults read back: Glow Based On 2, Glow Threshold 153, Glow Radius 10, Glow Intensity 1, Composite Original 2, Glow Operation 3, Glow Colors 1, Color Looping 3, Color Loops 1, Color Phase 0, A & B Midpoint 0.5, Color A [1,1,1,1], Color B [0,0,0,1], Glow Dimensions 1) |
| `429-fx-glow-threshold-76.5.aep` | `effects.aep` | `429-fx-glow-threshold-76.5` | FROM 427: Glow Threshold 153 -> 76.5 (scripting scale 0..255) |
| `438-fx-glow-midpoint-0.25.aep` | `effects.aep` | `438-fx-glow-midpoint-0.25` | FROM 427: A & B Midpoint 0.5 -> 0.25 (scripting scale 0..1) |
| `444-fx-huesat-hue-90.aep` | `effects.aep` | `444-fx-huesat-hue-90` | FROM 443: Master Hue 0 -> 90 (the undo afterwards did NOT revert it; 445-450 were each made on a fresh reopen of a copy of 443, verified by property.get) |
| `446-fx-huesat-light-m30.aep` | `effects.aep` | `446-fx-huesat-light-m30` | FROM 443 (reopened): Master Lightness 0 -> -30 |
| `448-fx-huesat-colorizehue-120.aep` | `effects.aep` | `448-fx-huesat-colorizehue-120` | FROM 443 (reopened): Colorize Hue 0 -> 120 |
| `451-shape-ellipse-400x300-fill.aep` | `shapes.aep` | `451-shape-ellipse-400x300-fill` | NEW shape layer `S` on top: Group 1 = Ellipse Path 1 (`ADBE Vector Shape - Ellipse`, Size [400,300], Position default [0,0]) + Fill 1 colour [0,1,0,1]; NOT undone: base of 452-484 |
| `457-shape-group-scale-50-80.aep` | `shapes.aep` | `457-shape-group-scale-50-80` | FROM 451: Group 1 Transform Scale [100,100] -> [50,80] |
| `462-shape-layer-anchor-10-20.aep` | `shapes.aep` | `462-shape-layer-anchor-10-20` | FROM 451: layer S Transform Anchor Point [0,0,0] -> [10,20] (read back [10,20,0]) |
| `464-shape-stroke-opacity-50.aep` | `shapes.aep` | `464-shape-stroke-opacity-50` | FROM 463: Stroke Opacity 100 -> 50 |
| `467-shape-trim-end-70.aep` | `shapes.aep` | `467-shape-trim-end-70` | FROM 465: Trim End 100 -> 70 |
| `469-shape-trim-type-2.aep` | `shapes.aep` | `469-shape-trim-type-2` | FROM 465: Trim Multiple Shapes 1 -> 2 |
| `471-shape-rect-roundness-30.aep` | `shapes.aep` | `471-shape-rect-roundness-30` | FROM 470: Rect Roundness 0 -> 30 |
| `473-shape-star-points-6.aep` | `shapes.aep` | `473-shape-star-points-6` | FROM 472: Points 5 -> 6 |
| `482-shape-two-groups.aep` | `shapes.aep` | `482-shape-two-groups` | FROM 451: NEW Group 2 (top level) = Rectangle Path 1 [200,100] + Fill 1 [0,0,1,1] (one call) |
| `483-shape-nested-group-rect.aep` | `shapes.aep` | `483-shape-nested-group-rect` | FROM 451: TWO calls: a Group added INSIDE Group 1 (after Fill 1, named "Group 1") and a Rectangle Path 1 [100,50] inside it |
| `485-layer-3d-on.aep` | `3d.aep` | `485-layer-3d-on` | FROM base: L threeDLayer on (compare 015); NOT undone: base of 486-488 |
| `486-layer-3d-rotx-30.aep` | `3d.aep` | `486-layer-3d-rotx-30` | FROM 485: X Rotation 0 -> 30 |
| `487-layer-3d-roty-45.aep` | `3d.aep` | `487-layer-3d-roty-45` | FROM 485: Y Rotation 0 -> 45 |
| `488-layer-3d-orientation-10-20-30.aep` | `3d.aep` | `488-layer-3d-orientation-10-20-30` | FROM 485: Orientation [0,0,0] -> [10,20,30] |
| `509-marker-comp-two.aep` | `markers.aep` | `509-marker-comp-two` | FROM base: TWO comp markers in one call: t=1 s comment `M1` label 2; t=2.5 s comment `M2` duration 0.5 (read back as set) |
| `510-marker-layer-0.52-dur0.3.aep` | `markers.aep` | `510-marker-layer-0.52-dur0.3` | FROM base (509 undone, comp markers 0): layer marker on L at t=0.52 s, comment `LM`, duration 0.3 s (read back 0.52 / 0.3) |
| `512-fx-levels-inblack-0.1.aep` | `effects.aep` | `512-fx-levels-inblack-0.1` | FROM 511: Input Black 0 -> 0.1 (read back 0.10000000149012); the undo did NOT revert it; 513-516 were each made on a fresh reopen of a copy of 511 |
| `514-fx-levels-gamma-2.aep` | `effects.aep` | `514-fx-levels-gamma-2` | FROM 511 (reopened): Gamma 1 -> 2 |
| `516-fx-levels-outwhite-0.9.aep` | `effects.aep` | `516-fx-levels-outwhite-0.9` | FROM 511 (reopened): Output White 1 -> 0.9 (read back 0.89999997615814) |
| `517-text-box-600x400-wrap.aep` | `text.aep` | `517-text-box-600x400-wrap` | FROM base: NEW box text layer `T`, box [600,400] at [-300,-200], text `The quick brown fox jumps over the lazy dog and keeps running far away` (Times New Roman, default style). AE text.measure: 4 composed lines `The quick brown fox ` / `jumps over the lazy dog ` / `and keeps running far ` / `away`, baselines y -163.80, -65.80, 32.20, 130.20 (left x -300), no overflow |
| `519-shape-all-items-default.aep` | `shapes.aep` | `519-shape-all-items-default` | NEW shape layer `S`: Group 1 with, in this order, `property.add` of Rectangle Path, Ellipse Path, Polystar Path, Fill, Stroke, Gradient Fill, Gradient Stroke, Trim Paths, Round Corners, nothing set. AE read-back of the defaults: Rect Size [100,100], Position [0,0], Roundness 0, Shape Direction 1; Ellipse Size [100,100], Position [0,0]; Star Type 1, Points 5, Position [0,0], Rotation 0, Inner Radius 50, Outer Radius 100, Inner/Outer Roundness 0; Fill Blend Mode 1, Composite 1, Fill Rule 1, Color [1,0,0,1], Opacity 100; Stroke Color [1,1,1,1], Opacity 100, Width 2, Line Cap 1, Line Join 1, Miter Limit 4, Dashes Dash/Gap 1-3 = 10, Offset 0, Taper Length Units 1, lengths/widths/eases 0, Wave Amount 0, Units 1, Wavelength 100, Cycles 10, Phase 0; Gradient Fill/Stroke Type 1, Start Point [0,0], End Point [100,0], Highlight Length/Angle 0, Scale [100,100], Rotation 0, Colors NO_VALUE, Opacity 100 (stroke width 2, cap/join 1, miter 4); Trim Start 0, End 100, Offset 0, Trim Multiple Shapes 1; Round Corners Radius 10; Group Blend Mode 1, Transform Anchor/Position [0,0], Scale [100,100], Skew/Skew Axis/Rotation 0, Opacity 100; layer Anchor [0,0,0], Position [960,540,0] |
| `526-text-point-HHHH-default.aep` | `text.aep` | `526-text-point-HHHH-default` | NEW point text layer `T` `HHHH` (layer.create_text, nothing else set: 100 px, the default character state). AE: style slot /13 = 1 (superscript); text.measure width 168.4 px, baseline -33.3 (58.3 % size, 33.3 % shift) |
| `527-text-point-HHHH-baseline-normal.aep` | `text.aep` | `527-text-point-HHHH-baseline-normal` | T fontBaselineOption = normal (text.set_style): slot /13 = 0 (the only changed slot); width 288.9 px, baseline 0 |
| `528-text-point-HHHH-baseline-subscript.aep` | `text.aep` | `528-text-point-HHHH-baseline-subscript` | T fontBaselineOption = subscript (text.set_style): slot /13 = 2; width 168.4 px, baseline +33.3 |
| `529-fx-timewarp-default.aep` | `effects.aep` | `529-fx-timewarp-default` | Timewarp (`ADBE Timewarp`) on L at its defaults; AE read back Method 3 (Pixel Motion), Adjust Time By 1 (Speed), Speed 50, Source Frame 0; NOT undone: base of 530-533 |
| `530-fx-timewarp-speed-25.aep` | `effects.aep` | `530-fx-timewarp-speed-25` | Speed 50 -> 25 (read back 25); undone |
| `531-fx-timewarp-speed-keyed-50-200.aep` | `effects.aep` | `531-fx-timewarp-speed-keyed-50-200` | Speed keys 50 at 0 s and 200 at 2 s (linear; read back 125 at 1 s); undone |
| `532-fx-timewarp-method-1.aep` | `effects.aep` | `532-fx-timewarp-method-1` | Method 3 -> 1 (Whole Frames); undone |
| `533-fx-timewarp-sourceframe-12.aep` | `effects.aep` | `533-fx-timewarp-sourceframe-12` | Adjust Time By 2 (Source Frame) and Source Frame 12 (one batch); undone, and the Timewarp undone |
| `534-fx-slider-expression-time10.aep` | `effects.aep` | `534-fx-slider-expression-time10` | Slider Control on L, expression `time*10` on Slider (read back 20 at 2 s); undone |
| `535-camera-position-on-3d-rotx.aep` | `3d.aep` | `535-camera-position-on-3d-rotx` | NEW camera `K` (layer.create_camera, two-node), Position [100,200,-1000] (Point of Interest read back [960,540,0], Zoom 2666.67) |
| `536-camera-one-node-position-on-3d-rotx.aep` | `3d.aep` | `536-camera-one-node-position-on-3d-rotx` | K autoOrient off (one-node) |
| `537-camera-default-on-3d-rotx.aep` | `3d.aep` | `537-camera-default-on-3d-rotx` | NEW camera `K` at its defaults (Position read back [0,0,-2666.67]); 255 (POI [960,540,0], Position [0,0,-1333.33]) |
| `538-text-point-HHHH-normal-ref.aep` | `text.aep` | `538-text-point-HHHH-normal-ref` | NEW point text `T` `HHHH` (layer.create_text) + fontBaselineOption normal in one batch (= the 527 state); noise reference of S17, NOT undone: base of 539-578 |
| `539-text-hscale-0.9.aep` | `text.aep` | `539-text-hscale-0.9` | horizontalScale 0.9: style /6 1.0 -> 0.9 |
| `540-text-vscale-1.5.aep` | `text.aep` | `540-text-vscale-1.5` | verticalScale 1.5: style /7 -> 1.5 |
| `541-text-baselineshift-41.aep` | `text.aep` | `541-text-baselineshift-41` | baselineShift 41: style /9 0.0 -> 41.0 |
| `542-text-autokern-none.aep` | `text.aep` | `542-text-autokern-none` | autoKernType none: style /11 1 -> 0 |
| `543-text-autokern-optical.aep` | `text.aep` | `543-text-autokern-optical` | autoKernType optical: style /11 1 -> 2 (1 = metrics, the default) |
| `544-text-applystroke-on.aep` | `text.aep` | `544-text-applystroke-on` | applyStroke true: style /57 false -> true |
| `545-text-strokewidth-5.aep` | `text.aep` | `545-text-strokewidth-5` | strokeWidth 5: style /63 1.0 -> 5.0 |
| `546-text-applyfill-off.aep` | `text.aep` | `546-text-applyfill-off` | applyFill false: style /56 true -> false |
| `548-text-linejoin-round.aep` | `text.aep` | `548-text-linejoin-round` | lineJoinType round: style /62 0 -> 1 |
| `550-text-strokeoverfill-off.aep` | `text.aep` | `550-text-strokeoverfill-off` | strokeOverFill false: style /58 true -> false |
| `552-text-nobreak-on.aep` | `text.aep` | `552-text-nobreak-on` | noBreak true: style /52 -> true |
| `553-text-tsume-0.5.aep` | `text.aep` | `553-text-tsume-0.5` | tsume 0.5: style /36 0.0 -> 0.5 |
| `554-text-kerning-50.aep` | `text.aep` | `554-text-kerning-50` | kerning 50: style /11 1 -> 0 and the run gets a kern list `RUN/0/8/0[i]` = << /0 << /0 50 >> /1 1 >> per character (`RUN/0/7` = 50) |
| `555-text-ligature-on.aep` | `text.aep` | `555-text-ligature-on` | ligature true: style /18 -> true |
| `556-text-autohyphenate-off.aep` | `text.aep` | `556-text-autohyphenate-off` | autoHyphenate false: paragraph /9 true -> false |
| `558-text-hangingroman-on.aep` | `text.aep` | `558-text-hangingroman-on` | hangingRoman true: paragraph /21 -> true |
| `559-text-everyline-on.aep` | `text.aep` | `559-text-everyline-on` | everyLineComposer true: paragraph /29 false -> true |
| `560-text-firstlineindent-20.aep` | `text.aep` | `560-text-firstlineindent-20` | firstLineIndent 20: paragraph /1 -> 20.0 |
| `561-text-startindent-30.aep` | `text.aep` | `561-text-startindent-30` | startIndent 30: paragraph /2 -> 30.0 |
| `562-text-endindent-40.aep` | `text.aep` | `562-text-endindent-40` | endIndent 40: paragraph /3 -> 40.0 |
| `563-text-spacebefore-10.aep` | `text.aep` | `563-text-spacebefore-10` | spaceBefore 10: paragraph /4 -> 10.0 |
| `564-text-spaceafter-12.aep` | `text.aep` | `564-text-spaceafter-12` | spaceAfter 12: paragraph /5 -> 12.0 |
| `565-text-justify-fullleft.aep` | `text.aep` | `565-text-justify-fullleft` | justification fullLeft: paragraph /0 0 -> 3 |
| `566-text-justify-fullcenter.aep` | `text.aep` | `566-text-justify-fullcenter` | fullCenter: /0 -> 5 |
| `567-text-justify-fullright.aep` | `text.aep` | `567-text-justify-fullright` | fullRight: /0 -> 4 |
| `568-text-justify-fullall.aep` | `text.aep` | `568-text-justify-fullall` | fullLastLineFull: /0 -> 6 |
| `569-text-direction-rtl.aep` | `text.aep` | `569-text-direction-rtl` | direction rightToLeft: paragraph /33 0 -> 1 |
| `571-text-digitset-arabic.aep` | `text.aep` | `571-text-digitset-arabic` | digitSet arabic: style /70 0 -> 1. Same session, not saved: text `1234` has the same layer.bounds with digitSet default and arabic (left 11.72, width 184.81, top -67.58, height 68.75); undone |
| `572-text-leadingtype-japanese.aep` | `text.aep` | `572-text-leadingtype-japanese` | leadingType japanese: paragraph /8 0 -> 1 |
| `573-text-baselinedir-rotated.aep` | `text.aep` | `573-text-baselinedir-rotated` | baselineDirection verticalRotated: style /35 1 -> 2 |
| `575-text-vertical-rtl.aep` | `text.aep` | `575-text-vertical-rtl` | lineOrientation verticalRtl: document `/0/8/0[0]/0/2/1` -> 2 (absent before) |
| `576-text-baselinedir-crossstream.aep` | `text.aep` | `576-text-baselinedir-crossstream` | baselineDirection verticalCrossStream: style /35 -> 3 |
| `578-text-digitset-hindi.aep` | `text.aep` | `578-text-digitset-hindi` | digitSet hindi: style /70 -> 2 |
| `579-textanim-position-0-m50.aep` | `text.aep` | `579-textanim-position-0-m50` | (538) text.add_animator `Animator 1` with Position 3D [0,-50,0], range selector at its defaults; NOT undone: base of 580-591 |
| `580-textanim-start-25.aep` | `text.aep` | `580-textanim-start-25` | Range Selector 1 Start (ADBE Text Percent Start) 25 |
| `581-textanim-end-75.aep` | `text.aep` | `581-textanim-end-75` | End 75 |
| `582-textanim-offset-10.aep` | `text.aep` | `582-textanim-offset-10` | Offset 10 |
| `583-textanim-units-index.aep` | `text.aep` | `583-textanim-units-index` | Advanced Units 2 (Index); read back Index Start 0, Index End 4 (the character count) |
| `584-textanim-basedon-3-words.aep` | `text.aep` | `584-textanim-basedon-3-words` | Based On (ADBE Text Range Type2) 3 |
| `585-textanim-mode-2-subtract.aep` | `text.aep` | `585-textanim-mode-2-subtract` | Mode 2 |
| `586-textanim-amount-50.aep` | `text.aep` | `586-textanim-amount-50` | Amount (ADBE Text Selector Max Amount) 50 |
| `587-textanim-shape-2-rampup.aep` | `text.aep` | `587-textanim-shape-2-rampup` | Shape 2 |
| `588-textanim-smoothness-50.aep` | `text.aep` | `588-textanim-smoothness-50` | Smoothness 50 |
| `589-textanim-easehigh-30.aep` | `text.aep` | `589-textanim-easehigh-30` | Ease High (ADBE Text Levels Max Ease) 30 |
| `590-textanim-easelow-40.aep` | `text.aep` | `590-textanim-easelow-40` | Ease Low (ADBE Text Levels Min Ease) 40 |
| `591-textanim-randomize-seed-7.aep` | `text.aep` | `591-textanim-randomize-seed-7` | Randomize Order 1 + Random Seed 7 (one batch) |
| `592-textanim-many-props.aep` | `text.aep` | `592-textanim-many-props` | FROM 579: second animator `Many`: Anchor Point 3D [3,4,0], Scale 3D [150,120,100], Skew 10, Skew Axis 20, Rotation 45, Opacity 37, Fill Color [0,1,0], Stroke Color [0,0,1], Stroke Width 3, Tracking Amount 20 (AE added Track Type itself; setting it failed), Line Spacing [10,20], Blur [5,6] (read back) |
| `593-textanim-start-keyed-ease-0-100.aep` | `text.aep` | `593-textanim-start-keyed-ease-0-100` | FROM 592: Animator 1 Start keys 0 at 0 s, 100 at 2 s, interp ease (keyframe.apply) |
| `594-textanim-position-start-keyed-ease.aep` | `text.aep` | `594-textanim-position-start-keyed-ease` | 593 with animator `Many` removed (Animator 1 only: Position [0,-50,0], Start 0 -> 100 eased over 0..2 s) |
| `595-text-stroke-scale-shift-combined.aep` | `text.aep` | `595-text-stroke-scale-shift-combined` | 538 state (Animator 1 removed) + applyStroke, strokeWidth 5, strokeColor blue, horizontalScale 0.9, verticalScale 1.5, baselineShift 41 (one call) |
| `596-text-combined-fill-over-stroke.aep` | `text.aep` | `596-text-combined-fill-over-stroke` | 595 + strokeOverFill false |
| `597-key-anchor-ease-out50-40-in30-60.aep` | `keyframes.aep` | `597-key-anchor-ease-out50-40-in30-60` | L Anchor Point keys [960,540] at 0 s (out speed 50, influence 40) and [1160,640] at 2 s (in speed 30, influence 60), keyframe.apply ease; read back (re-applied in the same session): 0.5 s [1004.4121, 562.2061], 1 s [1084.8353, 602.4177], 1.5 s [1137.1339, 628.5670] |
| `598-key-ramp-point-ease-color-bezier.aep` | `keyframes.aep` | `598-key-ramp-point-ease-color-bezier` | Gradient Ramp on L: Start of Ramp keys [100,200] at 0 s (out 50 / 40) and [500,400] at 2 s (in 30 / 60): read back 0.5 s [178.4012, 239.2006], 1 s [353.0563, 326.5281], 1.5 s [462.9131, 381.4566]; Start Color keys red at 0 s and blue at 2 s switched to bezier by keyframe.set_interpolation (a custom colour ease is refused by AE: "Value array does not have 1 elements"): read back 0.5 s [0.75,0,0.25], 1 s [0.5,0,0.5], 1.5 s [0.25,0,0.75] |
| `599-key-mask-path-ease-infl75.aep` | `masks.aep` | `599-key-mask-path-ease-infl75` | L rect mask, path keys 200x200 at 0 s and 600x400 at 2 s (both centred), ease speed 0, out influence 75 on key 1, in influence 75 on key 2; first vertex read back 0.5 s [849.1606, 434.5803], 1 s [760.0, 390.0], 1.5 s [670.8394, 345.4197] |
| `601-precomp-two-comps-in-C.aep` | `footage-precomp.aep` | `601-precomp-two-comps-in-C` | FROM 600: new comp `Q` 320x240, 25 fps, 2 s with a blue 320x240 solid `B320`, Q added as a layer on top in C (C now shows P30 and Q) |
| `603-footage-exrseq-0101-as-layer.aep` | `footage-precomp.aep` | `603-footage-exrseq-0101-as-layer` | project.import_file `test-media\exrseq\shot_0101.exr` sequence=true -> item `shot_[0101-0103].exr` (64x48, 0.1 s = 3 frames at 30 fps) + layer on top of L in C |
| `610-fx-tint-named-My-Tint.aep` | `effects.aep` | `610-fx-tint-named-My-Tint` | effect.add `ADBE Tint` on L with name `My Tint` (effect.list_on_layer: name `My Tint`) |
| `621-settings-bpc-8.aep` | `settings-a.aep` | `621-settings-bpc-8` | project.set_settings bitsPerChannel 8 |
| `622-settings-bpc-16.aep` | `settings-c.aep` | `622-settings-bpc-16` | bitsPerChannel 16 |
| `623-settings-workingspace-none.aep` | `settings-a.aep` | `623-settings-workingspace-none` | workingSpace '' (read back None) |
| `625-settings-gamma-2.4.aep` | `settings-a.aep` | `625-settings-gamma-2.4` | workingGamma 2.4 |
| `628-settings-scene-compensation-off.aep` | `settings-a.aep` | `628-settings-scene-compensation-off` | compensateForSceneReferredProfiles false |
| `629-settings-time-display-frames.aep` | `settings-a.aep` | `629-settings-time-display-frames` | timeDisplayType frames |
| `630-settings-frame-start-1.aep` | `settings-a.aep` | `630-settings-frame-start-1` | displayStartFrame 1 |
| `632-settings-linearize-and-blend-linear.aep` | `settings-b.aep` | `632-settings-linearize-and-blend-linear` | linearizeWorkingSpace + linearBlending true |
| `633-settings-feet-frames-35.aep` | `settings-b.aep` | `633-settings-feet-frames-35` | timeDisplayType frames + framesUseFeetFrames true (film type mm35, read back) |
| `634-settings-feet-frames-16.aep` | `settings-c.aep` | `634-settings-feet-frames-16` | FROM 633 (same session, not reopened): feetFramesFilmType mm16 |
| `641-stretch-200-keys-position-1s-2s.aep` | `keyframes.aep` | `641-stretch-200-keys-position-1s-2s` | layer.set_timing stretch 200 on L, then the same two keys at comp 1 s and 2 s (read back: out 10, keys at 1 and 2) |
| `642-stretch-50-keys-position-1s-2s.aep` | `keyframes.aep` | `642-stretch-50-keys-position-1s-2s` | stretch 50 (out 2.5), keys at comp 1 s and 2 s |
| `643-stretch-200-start-1-keys-position-2s-3s.aep` | `keyframes.aep` | `643-stretch-200-start-1-keys-position-2s-3s` | startTime 1 + stretch 200 (in 1, out 11), keys at comp 2 s and 3 s |
| `645-footage-mp4-conform-30.aep` | `footage-precomp.aep` | `645-footage-mp4-conform-30` | FROM 644: footage.interpret conformFrameRate 30 on clip.mp4 (25 fps native; duration 1 -> 0.8333 s) |
| `650-footage-tga-still-as-layer.aep` | `footage-precomp.aep` | `650-footage-tga-still-as-layer` | (fresh base) import `test-media\still.tga` (64x48, PIL from still.png) + layer in C |
| `651-footage-psd-flat-as-layer.aep` | `footage-precomp.aep` | `651-footage-psd-flat-as-layer` | import `test-media\still.psd` (flat RGB PSD written by hand) importAs footage + layer in C |
| `652-footage-ai-as-layer.aep` | `footage-precomp.aep` | `652-footage-ai-as-layer` | import `test-media\still.ai` (hand-written one-page PDF named .ai, 64x48 pt) importAs footage + layer in C |
| `653-footage-eps-as-layer.aep` | `footage-precomp.aep` | `653-footage-eps-as-layer` | import `test-media\still.eps` (hand-written EPS, 64x48 pt) + layer in C |
| `700-key-mask-path-ease-out20-in50.aep` | `masks.aep` | `700-key-mask-path-ease-out20-in50` | from 599: out influence 20 on key 1, in influence 50 on key 2 (speed 0); first vertex 0.5 s [803.9844, 411.9922], 1 s [727.6194, 373.8097], 1.5 s [676.9510, 348.4755] |
| `701-light-parallel-int80-color.aep` | `3d.aep` | `701-light-parallel-int80-color` | NEW parallel light `P`, Intensity 80, Color [1,0.5,0.25] |
| `702-light-ambient-int50-color.aep` | `3d.aep` | `702-light-ambient-int50-color` | NEW ambient light `A`, Intensity 50, Color [0.25,0.5,1] |
| `703-key-orientation-0-to-10-20-30-linear.aep` | `3d.aep` | `703-key-orientation-0-to-10-20-30-linear` | L 3D, Orientation keys [0,0,0] at 0 s and [10,20,30] at 2 s (linear): read back 0.5 s [3.4341, 4.4691, 7.7129], 1 s [6.2643, 9.3531, 15.2190], 1.5 s [8.4650, 14.5598, 22.6095] (not per-component linear) |
| `704-light-environment-default.aep` | `3d.aep` | `704-light-environment-default` | NEW environment light `E` at its defaults |
| `705-mask-on-text-rect-40-m70-160-10.aep` | `text.aep` | `705-mask-on-text-rect-40-m70-160-10` | NEW point text `T` `HHHH` (normal baseline) with a rect mask (mask.add centre [100,-30], size [120,80]): vertices read back [40,-70] [160,-70] [160,10] [40,10] (layer space) |
| `706-mask-on-shape-rect-0-m150-100-150.aep` | `masks.aep` | `706-mask-on-shape-rect-0-m150-100-150` | NEW shape layer `S` (Group 1: Rectangle 400x200, Fill green) with a rect mask centre [50,0] size [100,300]: vertices [0,-150] [100,-150] [100,150] [0,150] |
| `707-shape-merge-subtract-rect-ellipse.aep` | `shapes.aep` | `707-shape-merge-subtract-rect-ellipse` | S without the mask: Rectangle, Ellipse 200x200, Merge Paths mode subtract (read back Merge Type 3), Fill (moved last) |
| `708-shape-merge-intersect-rect-ellipse.aep` | `shapes.aep` | `708-shape-merge-intersect-rect-ellipse` | 707 with Merge Type 4 |
| `709-shape-repeater-3-pos150-60-rot10-scale90-80-op40.aep` | `shapes.aep` | `709-shape-repeater-3-pos150-60-rot10-scale90-80-op40` | S: Rectangle, Fill, Repeater (Copies 3, Position [150,60], Rotation 10, Scale [90,80], End Opacity 40) |
| `710-shape-offset-paths-20-round.aep` | `shapes.aep` | `710-shape-offset-paths-20-round` | S: Rectangle, Offset Paths (Amount 20, Line Join round), Fill |
| `711-fx-directional-blur-30-40-on-M.aep` | `effects.aep` | `711-fx-directional-blur-30-40-on-M` | Directional Blur (ADBE Motion Blur) on M: Direction 30, Blur Length 40 |
| `712-fx-eleven-effects-defaults-on-M.aep` | `effects.aep` | `712-fx-eleven-effects-defaults-on-M` | M with, in this order, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker, Transform (ADBE Geometry2), Set Matte (ADBE Set Matte3), all at their defaults |
| `713-fx-radial-blur-zoom-20-on-M.aep` | `effects.aep` | `713-fx-radial-blur-zoom-20-on-M` | Radial Blur: Amount 20, Center [600,300], Type 2 (Zoom), Antialiasing 2 (High) |
| `714-fx-ccradial-type2-30-60-on-M.aep` | `effects.aep` | `714-fx-ccradial-type2-30-60-on-M` | CC Radial Blur: Type 2, Amount 30, Quality 60, Center [400,200] |
| `715-fx-venetian-40-30-50-5-on-M.aep` | `effects.aep` | `715-fx-venetian-40-30-50-5-on-M` | Venetian Blinds: Completion 40, Direction 30, Width 50, Feather 5 |
| `716-fx-channel-blur-5-10-15-20-edge-horiz-on-M.aep` | `effects.aep` | `716-fx-channel-blur-5-10-15-20-edge-horiz-on-M` | Channel Blur: R 5, G 10, B 15, A 20, Edge Behavior (Repeat Edge Pixels) 1, Blur Dimensions 2 |
| `717-fx-blackwhite-set-tint-on-L.aep` | `effects.aep` | `717-fx-blackwhite-set-tint-on-L` | Black & White on L: Reds 10, Yellows 70, Greens 30, Cyans 50, Blues 90, Magentas 20, Tint 1, Tint Color [1,0.5,0] |
| `718-fx-tritone-set-blend25-on-L.aep` | `effects.aep` | `718-fx-tritone-set-blend25-on-L` | Tritone on L: Highlights [1,1,0.8], Midtones [0.6,0.2,0.2], Shadows [0,0,0.3], Blend With Original 25 |
| `719-fx-lumakey-darker-140-20-1-2.5-on-M.aep` | `effects.aep` | `719-fx-lumakey-darker-140-20-1-2.5-on-M` | Luma Key on M: Key Type 2, Threshold 140, Tolerance 20, Edge Thin 1, Edge Feather 2.5 |
| `720-fx-simplechoker-3.5-on-M.aep` | `effects.aep` | `720-fx-simplechoker-3.5-on-M` | Simple Choker: Choke Matte 3.5 |
| `721-fx-simplechoker-3.5-view-matte-on-M.aep` | `effects.aep` | `721-fx-simplechoker-3.5-view-matte-on-M` | 720 + View 2 |
| `722-fx-mattechoker-set-on-M.aep` | `effects.aep` | `722-fx-mattechoker-set-on-M` | Matte Choker: Geometric Softness 1 6, Choke 1 50, Geometric Softness 2 2, Choke 2 -10, Iterations 3 (Gray Level Softness 1 / 2 refused by AE: "Unable to call setValue", left at their defaults) |
| `723-fx-transform-set-on-M.aep` | `effects.aep` | `723-fx-transform-set-on-M` | Transform: Anchor [400,200], Position [500,300], Uniform Scale 0, Scale Height 80, Scale Width 120, Skew 10, Skew Axis 20, Rotation 30, Opacity 70, Use Composition's Shutter Angle 0, Shutter Angle 90, Sampling 2 |
| `725-text-point-HHHH-normal-ref-S18.aep` | `text.aep` | `725-text-point-HHHH-normal-ref-S18` | (fresh base) point text `T` `HHHH`, baseline normal: reference of S18 (= 538) |
| `727-text-reset-paragraph.aep` | `text.aep` | `727-text-reset-paragraph` | (726 undone) text.reset_style paragraph: ONLY paragraph /34 0 -> 7. Same session, not saved: a 600x400 box text of 88 characters, justified (fullLeft), lays out identically before and after a paragraph reset (text.measure: 4 lines, the same breaks and baselines -130.50 / -32.50 / 65.50 / 163.50; layer.bounds identical) |
| `728-textanim-character-offset-3.aep` | `text.aep` | `728-textanim-character-offset-3` | 727 + text.add_animator `Off` with Character Offset 3; AE adds Character Alignment (ADBE Text Character Change Type) 1 and Character Range 1 with it (read back); setting Character Range to 2 is refused by AE ("Can not set value") |
| `730-key-anchor-ease-on-400x800-solid.aep` | `keyframes.aep` | `730-key-anchor-ease-on-400x800-solid` | NEW blue solid `P` 400x800, Anchor Point keys [200,400] at 0 s (out speed 50, influence 40) and [300,500] at 2 s (in speed 30, influence 60); stored speeds 0.0625 / 0.0375 = 50 / 800 and 30 / 800 (597: 50 / 1080 on the 1920x1080 L), so a stored spatial speed is pixels per second divided by the layer height; read back 0.5 s [225.2343, 425.2343], 1 s [261.4341, 461.4341], 1.5 s [286.0550, 486.0550] |
| `731-shape-merge-offset-repeater-defaults.aep` | `shapes.aep` | `731-shape-merge-offset-repeater-defaults` | NEW shape layer `S`: Group 1 with Rectangle 400x200, then property.add of Merge Paths, Offset Paths, Repeater, nothing set; read back: Merge Type 1; Offset Amount 10, Line Join 1, Miter Limit 4, Copies 1, Copy Offset 1; Repeater Copies 1, Offset 0, Composite 1, Anchor [0,0], Position [0,0], Scale [100,100], Rotation 0, Start / End Opacity 100 / 100 (the values of a property without a record; the UI's Add menu and shape.add_repeater store their own) |
| `732-text-box-byteedit-para24-0.aep` | `text.aep` | `732-text-box-byteedit-para24-0` | 517 with paragraph `/23 true /24 1` -> `/24 0` (the run's paragraph); layout identical to 517 (4 lines, baselines -163.80 / -65.80 / 32.20 / 130.20, bounds 563.61 x 347.06); 732r-resaved keeps `/24 0` |
| `733-text-box-byteedit-para35-0.aep` | `text.aep` | `733-text-box-byteedit-para35-0` | 517 with paragraph `/34 0 /35 1` -> `/35 0`; layout identical (line ends within 1e-4 px); 733r-resaved keeps `/35 0` |
| `734-text-box-byteedit-style68-1.aep` | `styles.aep` | `734-text-box-byteedit-style68-1` | 517 with style `/68 0 /69 0` -> `/68 1` (3 occurrences: style sheet and runs); layout identical; 734r-resaved keeps `/68 1` |
| `828-shape-offset-paths-20-copies3-copyoffset1.5-stroke.aep` | `shapes.aep` | `828-shape-offset-paths-20-copies3-copyoffset1.5-stroke` | shape `S`: Rectangle 400x200, Offset Paths Amount 20, Stroke 2 px green: Copies 1 / Copy Offset 0 -> ring at the path, Copies 3 / Copy Offset 0 -> offsets 0, 20, 40, Copies 3 / Copy Offset 1.5 -> 30, 50, 70: offset of copy i = Amount x (i + Copy Offset) |
| `851-shape-key-trim-end-0-100-linear.aep` | `shapes.aep` | `851-shape-key-trim-end-0-100-linear` | Trim End keys 0 at 0 s, 100 at 2 s, linear (keyframe.apply); undone |
| `852-shape-key-trim-end-bezier-out0-60-in20-30.aep` | `shapes.aep` | `852-shape-key-trim-end-bezier-out0-60-in20-30` | Trim End keys 0 at 0 s (bezier, out speed 0 / influence 60) and 100 at 2 s (bezier, in speed 20 / influence 30); read back in ease of key 1 0 / 33, out of key 2 0 / 33; undone |
| `853-shape-key-group-position-0-200-100-linear.aep` | `shapes.aep` | `853-shape-key-group-position-0-200-100-linear` | Group 1 Transform Position keys [0,0] at 0 s, [200,100] at 2 s, linear; undone |
| `854-shape-key-fill-color-red-blue-linear.aep` | `shapes.aep` | `854-shape-key-fill-color-red-blue-linear` | Fill Color keys red at 0 s, blue at 2 s, linear; undone |
| `855-shape-key-trim-offset-0-90-hold.aep` | `shapes.aep` | `855-shape-key-trim-offset-0-90-hold` | Trim Offset keys 0 at 0 s (linear), 90 at 2 s (hold); undone |
| `856-shape-trim-end-expression-time50.aep` | `shapes.aep` | `856-shape-trim-end-expression-time50` | Trim End expression `time*50` (no keys); undone |
| `857-shape-key-group-scale-100-50-150-linear.aep` | `shapes.aep` | `857-shape-key-group-scale-100-50-150-linear` | Group 1 Transform Scale keys [100,100] at 0 s, [50,150] at 2 s, linear; undone (base state verified by layer.info) |
| `900-mask-added-no-path.aep` | `masks.aep` | `900-mask-added-no-path` | property.add `ADBE Mask Atom` on L, nothing set: the file stores the atom WITHOUT an `ADBE Mask Shape` entry (only `ADBE Group End`); read back (also after reopening) Mask Path closed [[0,0],[0,1080],[1920,1080],[1920,0]], tangents 0 = the layer's source rectangle |
| `901-mask-no-path-expansion-m100.aep` | `masks.aep` | `901-mask-no-path-expansion-m100` | from 900: Mask Expansion -100 (only `ADBE Mask Offset` stored) |
| `902-settings-rec709-16bpc-steps-png-grey-solid.aep` | `settings-c.aep` | `902-settings-rec709-16bpc-steps-png-grey-solid` | from 901: mask removed, project 16 bpc + working space Rec.709 Gamma 2.4; footage `test-media\steps.png` (sRGB PNG, no profile; top bands 0,16,32,64,96,128,160,192,224,255 grey, bottom (v, v/2, 255-v)) as layer `S`, grey 0.5 solid `G` 400x200 at [1600,900] on top |
| `905-fx-24-effects-set-one-comp.aep` | `effects.aep` | `905-fx-24-effects-set-one-comp` | the 24 effects and values of 904 in ONE comp `C` (L deleted): `R` = grey 0.5 solid with Gradient Ramp, video off, at the bottom (id 30); 24 layers E01..E24 = steps.png, each with the one effect of the 904 comp of the same name (E24 on top); the layer parameters of E22-E24 name R. Made as a smaller fixture than 904 (0.6 MB against 2 MB); no |
| `906-blendmodes-13-solids-on-steps.aep` | `layers-comps.aep` | `906-blendmodes-13-solids-on-steps` | L deleted; `S` = steps.png; 13 solids 300x300 [0.9,0.5,0.2] (named by mode) at a 320 x 360 px grid, each with layer.set_blend_mode normal, add, multiply, screen, overlay, softLight, hardLight, difference, exclusion, colorDodge, colorBurn, darken, lighten: `ldta`@99 = 2, 4, 5, 6, 7, 8, 9, 26, 25, 27, 28, 10, 11 |
| `951-styles-all-nine-defaults-on-B.aep` | `styles.aep` | `951-styles-all-nine-defaults-on-B` | from 950: on B `command.execute` 9000, 9001, 9002, 9003, 9004, 9005, 9006, 9007, 9008 (one call each), nothing set. AE read-back of the defaults (property.get): Drop Shadow mode2 5, color [0,0,0,1], opacity 75, useGlobalAngle 0, localLightingAngle 120, distance 5, chokeMatte 0, blur 5, noise 0, layerConceals 1; Inner Shadow mode2 5, color [0,0,0,1], opacity 75, useGlobalAngle 0, angle 120, distance 5, chokeMatte 0, blur 5, noise 0; Outer Glow mode2 11, opacity 75, noise 0, AEColorChoice 1, color [1,1,0.74509803921569,1], gradientSmoothness 100, glowTechnique 1, chokeMatte 0, blur 5, inputRange 50, shadingNoise 0; Inner Glow as Outer Glow plus innerGlowSource 1; Bevel and Emboss bevelStyle 2, bevelTechnique 1, strengthRatio 100, bevelDirection 1, blur 5, softness 0, useGlobalAngle 0, angle 120, altitude 30, highlightMode 11, highlightColor [1,1,1,1], highlightOpacity 75, shadowMode 5, shadowColor [0,0,0,1], shadowOpacity 75; Satin (chromeFX) mode2 5, color [0,0,0,1], opacity 50, angle 19, distance 11, blur 14, invert 1; Color Overlay (solidFill) mode2 1, color [1,0,0,1], opacity 100; Gradient Overlay mode2 1, opacity 100, gradientSmoothness 100, angle 90, type 1, reverse 0, align 1, scale 100, offset [0,0] (gradient not read); Stroke (frameFX) mode2 1, color [1,0,0,1], size 3, opacity 100, style 1; Blending Options Global Light Angle 120, Altitude 30, Fill Opacity 100, R/G/B Channel Blend 1, Blend Interior 0, Blend Ranges 1 |
| `963-curves-red-mid-down-on-S.aep` | `styles.aep` | `963-curves-red-mid-down-on-S` | from 984: apply `curves-red-mid-down.ffx` (Red curve: middle point dragged down). AE read-back: Channel: 1 (RGB, default; the editor channel Red is not the Channel parameter), Curves not readable. File: Red curve (0,0) (128,44) (255,255) |
| `964-curves-rgb-s-curve-on-S.aep` | `styles.aep` | `964-curves-rgb-s-curve-on-S` | from 984: apply `curves-rgb-two-points.ffx` (RGB S-curve: a point at about 1/4 dragged down, one at 3/4 up). AE read-back: Channel: 1, Curves not readable. File: RGB curve (0,0) (62,24) (194,230) (255,255) |
| `966-style-drop-shadow-opacity50-distance20.aep` | `styles.aep` | `966-style-drop-shadow-opacity50-distance20` | from 952 (opened): dropShadow/opacity 75 -> 50, dropShadow/distance 5 -> 20 (read back 50, 20) |
| `970-style-stroke-size10-color-green.aep` | `styles.aep` | `970-style-stroke-size10-color-green` | from 960: frameFX/size 3 -> 10, frameFX/color [1,0,0,1] -> [0,1,0,1] (read back 10, [0,1,0,1]) |
| `974-style-gradient-overlay-angle45-scale150.aep` | `styles.aep` | `974-style-gradient-overlay-angle45-scale150` | from 959: gradientFill/angle 90 -> 45, gradientFill/scale 100 -> 150 (read back 45, 150); the gradient colours were not touched |
| `975-style-fill-opacity0-with-drop-shadow.aep` | `styles.aep` | `975-style-fill-opacity0-with-drop-shadow` | from 952: ADBE Layer Fill Opacity2 100 -> 0 (Layer Styles > Blending Options > Advanced Blending > Fill Opacity; read back 0) |
| `976-style-drop-shadow-opacity-keyed-100-20-linear.aep` | `styles.aep` | `976-style-drop-shadow-opacity-keyed-100-20-linear` | from 952: dropShadow/opacity keys t=0 -> 100, t=2 -> 20, linear (keyframe.apply); read back 100 / 60 / 20 at 0 / 1 / 2 s |
| `977-styles-all-params-changed.aep` | `styles.aep` | `977-styles-all-params-changed` | on B every settable parameter of the nine styles and Blending Options set by `property.set` (one batch): Global Angle2 45, Global Altitude2 40, Fill Opacity2 80, R Channel Blend 0, Blend Interior 1, Blend Ranges 0; dropShadow mode2 1, color [0,0,1], opacity 60, useGlobalAngle 1, localLightingAngle 30, distance 12, chokeMatte 10, blur 8, noise 5, layerConceals 0; innerShadow mode2 1, color [0,1,0], opacity 55, useGlobalAngle 1, localLightingAngle 60, distance 7, chokeMatte 15, blur 9, noise 3; outerGlow mode2 1, opacity 65, noise 2, AEColorChoice 2, color [1,0,0], gradientSmoothness 80, glowTechnique 2, chokeMatte 12, blur 20, inputRange 40, shadingNoise 10; innerGlow mode2 1, opacity 45, noise 4, AEColorChoice 2, color [0,1,0], gradientSmoothness 70, glowTechnique 2, innerGlowSource 2, chokeMatte 8, blur 15, inputRange 30, shadingNoise 20; bevelEmboss bevelStyle 1, bevelTechnique 2, strengthRatio 150, bevelDirection 2, blur 10, softness 3, useGlobalAngle 1, localLightingAngle 70, localLightingAltitude 50, highlightMode 1, highlightColor [1,1,0], highlightOpacity 60, shadowMode 1, shadowColor [0,0,1], shadowOpacity 40; chromeFX mode2 1, color [1,0,1], opacity 70, localLightingAngle 45, distance 20, blur 10, invert 0; solidFill mode2 5, color [0,1,1], opacity 50; gradientFill mode2 5, opacity 70, gradientSmoothness 50, angle 30, type 2, reverse 1, align 0, scale 120, offset [10,20]; frameFX mode2 5, color [0,0,1], size 6, opacity 80, style 2. (Values equal to the default, e.g. dropShadow mode2 1 is not: default 5.) Purpose: one record of every parameter type. property.list read the exact match names (inner shadow / satin angle = `localLightingAngle`; Blending Options = `ADBE Global Angle2`, `ADBE Global Altitude2`, Adv Blend `ADBE Layer Fill Opacity2`, `ADBE R/G/B Channel Blend`, `ADBE Blend Interior`, `ADBE Blend Ranges`; no Knockout) |
| `979-style-inner-glow-source-2.aep` | `styles.aep` | `979-style-inner-glow-source-2` | innerGlow/innerGlowSource 1 -> 2; 955 centre unchanged 51,102,204) -> 1 = Edge, 2 = Center |
| `981-layer-stretch-minus100-start5.aep` | `keyframes.aep` | `981-layer-stretch-minus100-start5` | L: layer.set_timing stretch -100, then startTime 5; AE reads startTime 5, inPoint 4.99967, outPoint -0.00033, stretch -100 |
| `982-layer-stretch-minus100-opacity-keys.aep` | `keyframes.aep` | `982-layer-stretch-minus100-opacity-keys` | from 981 (not undone): Opacity keys added at comp time 0 -> 100 and comp 4 -> 20 (keyframe.add); AE lists the keys at 4.00002 (20) and 0.00002 (100), reads 80 at comp 1 s, 40 at 3 s |
| `983-layer-stretch-minus50-opacity-keys.aep` | `keyframes.aep` | `983-layer-stretch-minus50-opacity-keys` | from 982: stretch -100 -> -50 (keys kept); AE: inPoint 4.99983, outPoint 2.49983, keys at comp 4.5 (20) and 2.5 (100) |
| `985-meshwarp-3x3-vertex-moved-on-S.aep` | `styles.aep` | `985-meshwarp-3x3-vertex-moved-on-S` | from 984: apply `meshwarp-3x3-center-right.ffx` (Rows 3, Columns 3 = 3x3 cells, 4x4 vertices; the contributor dragged the LOWER-RIGHT INNER vertex (row 2, column 2, 0-based) to the right, its tangents moved with it). AE read-back: Rows 3, Columns 3, Quality 8, Distortion Mesh not readable. File: that vertex at (0.73542, 0.66481) of the layer = +132 px, -2 px; the instance mesh is byte-identical to the one in the user's `presets\presets-reference.aep` |
| `986-shape-fill-switched-off-green.aep` | `shapes.aep` | `986-shape-fill-switched-off-green` | from 850: the Fill group's `tdsb` 1 -> 0 patched in a copy (the item eye switch is not scriptable), opened with project.open, Fill Color set to green by property.set, saved by After Effects (it keeps `tdsb` 0); centre 255,0,0 = the solid L) |
| `988-style-drop-shadow-switched-off.aep` | `styles.aep` | `988-style-drop-shadow-switched-off` | from 952: the `dropShadow/enabled` group `tdsb` 1 -> 0 patched in a copy (the style eye is not scriptable), opened with project.open (AE lists the style, Opacity 75),; Layer Styles and Blending Options stay 1) |
+31
View File
@@ -0,0 +1,31 @@
# Pinned After Effects test corpus for `crates/aep` (see the crate README, "Tests").
#
# repo where the corpus lives
# commit the exact commit to fetch (40 hex digits; a branch or tag name is not accepted)
# <sha256> <path> the SHA-256 of every file the tests use, relative to the corpus root
#
# The hashes are kept here, not read from the fetched repository, so a changed corpus
# cannot vouch for itself. To move the pin: change `commit`, then copy the new SHA256SUMS lines.
repo https://github.com/storytold/effectcraft-corpus.git
commit 97262276f625afdeeb61787e4cbb74b3f17af510
4a51318c4b37fa95e2c02682183d3982fdfbe1870dc50ba729b776d1826f982e aep/3d.aep
da8ba17d095ddb1576db658ad28a3966d7231244cf0391f77d71d7aa68c6e085 aep/aepx-pair.aep
59e79c1621de108a4960d2bb6b14bc54e39df658f459af777b50fa95f2b7b32b aep/aepx-pair.aepx
2e1a59562b52eb97ce32ccc7810a54f0671eae567d1d9869041b391d3cc4a20c aep/effects.aep
1e10b8ee47f43c5cd6e19710fbab28f498f8b73dbfa1a8f830ae41ad3b1c19ef aep/empty.aep
b4ee29ebd0d46b6013efc05c0f8cce4be61ce2d5b8bc38c5a814b86bceeee286 aep/footage-precomp.aep
7e162f536d422daffbe909b50fdd83d7160c6b150ce6c34216c65dba46ab87cb aep/fx-switch.aep
f6ce60a8ed0fa786625078f61995e1184ef0b016efaeeb0b4ae6337831697821 aep/inputs/curves-red-mid-down.ffx
e3992190150366b01859e32adcb9bbe2e0ef492bd2259a8b7e85b571afeca24f aep/inputs/curves-rgb-two-points.ffx
4a0cd5a0e52d8d14ee0f895b0a3e054199d399094b410a7b2a620eb484d5cba8 aep/inputs/meshwarp-3x3-center-right.ffx
baad5a326f255797c03b3cc0a776524b7eabfb217fbc301b0596ac3e4e97d71b aep/keyframes.aep
57184fec75ec8892ac6c8ac360274fdaa4fc4ed39093f969f30a45fbf2afaf9e aep/layers-comps.aep
fca73b3e4f5398a0ab686b74d8eb3e1c2dd37c7db0e8a31b2e0f45ba0bb3c8ff aep/markers.aep
93d6a9f2a2980d999bcb628a4e7220d1922b1c535d535663f69043778322d72f aep/masks.aep
c3255249dd29279cc6a14c156a0acb82b0bc255a0be77c0178a9c4bc891206a5 aep/settings-a.aep
b4a61e988743b0f6b5a7ad6875f958ccf173fcf0d7d6097c441a0aa71c5e1fd7 aep/settings-b.aep
71ba74dade2ef411026a55a945d573cf059ff03aeb2d527fe2c6833e13174df3 aep/settings-c.aep
9035039df7c34f04c33337719a2fef5ba93db5d2317434eb3476906571654d3b aep/shapes.aep
5fe35e08d05e72583fdd19e02878cc974136736e39090fab9d84d132fb2b4d35 aep/styles.aep
fded434b54532f9001c53a3482deed0c157f76ee067b354a801ec9c2747002db aep/text.aep
+381
View File
@@ -0,0 +1,381 @@
//! The old single-case fixture names and the combined test project that holds each case (as
//! the composition named like the file without its extension). Generated from the family
//! partition of the cases (`tests/fixtures/CASES.md`).
/// `(old file name, combined file)`, sorted by name.
pub const CASES: &[(&str, &str)] = &[
("000-base.aep", "layers-comps.aep"),
("000-base.aepx", "aepx-pair.aepx"),
("001-empty.aep", "empty.aep"),
("010-layer-name.aep", "layers-comps.aep"),
("012-layer-shy.aep", "layers-comps.aep"),
("013-layer-locked.aep", "layers-comps.aep"),
("014-layer-solo.aep", "layers-comps.aep"),
("015-layer-3d.aep", "3d.aep"),
("016-layer-blend-multiply.aep", "layers-comps.aep"),
("017-layer-motionblur.aep", "layers-comps.aep"),
("018-layer-stretch200.aep", "keyframes.aep"),
("019-layer-inpoint1.aep", "layers-comps.aep"),
("021-layer-starttime0.5.aep", "layers-comps.aep"),
("022-layer-parent-null.aep", "layers-comps.aep"),
("023-layer-quality-draft.aep", "layers-comps.aep"),
("024-layer-collapse.aep", "layers-comps.aep"),
("025-layer-adjustment.aep", "layers-comps.aep"),
("026-layer-guide.aep", "layers-comps.aep"),
("030-comp-size-1280x720.aep", "layers-comps.aep"),
("031-comp-fps30.aep", "layers-comps.aep"),
("032-comp-duration10.aep", "layers-comps.aep"),
("033-comp-bg-green.aep", "layers-comps.aep"),
("034-comp-shutter90.aep", "layers-comps.aep"),
("035-comp-workarea-1-2.aep", "layers-comps.aep"),
("037-comp-pixelaspect2.aep", "layers-comps.aep"),
("038-comp-motionblur.aep", "layers-comps.aep"),
("039-comp-renderer-advanced3d.aep", "3d.aep"),
("040-static-position-100-200.aep", "layers-comps.aep"),
("041-static-scale-50.aep", "layers-comps.aep"),
("042-static-rotation-45.aep", "layers-comps.aep"),
("043-static-opacity-25.aep", "layers-comps.aep"),
("044-static-anchor-10-20.aep", "layers-comps.aep"),
("052-key-position-2key-ease.aep", "keyframes.aep"),
("053-key-position-2key-hold-key1.aep", "keyframes.aep"),
("054-key-position-2key-spatial-bezier.aep", "keyframes.aep"),
("055-key-position-3key-inserted-t2.5.aep", "keyframes.aep"),
("056-key-position-3key-roving-key2.aep", "keyframes.aep"),
("057-key-position-3key-label9-key2.aep", "keyframes.aep"),
("058-key-opacity-2key.aep", "keyframes.aep"),
("058-key-opacity-2key.aepx", "aepx-pair.aepx"),
("060-expr-opacity-wiggle.aep", "keyframes.aep"),
("060-expr-opacity-wiggle.aepx", "aepx-pair.aepx"),
("071-fx-slider-value77.aep", "effects.aep"),
("073-fx-color-0.2-0.6-1.aep", "effects.aep"),
("077-fx-dropdown-default.aep", "effects.aep"),
("080-fx-dropshadow-default.aep", "effects.aep"),
("090-mask-rect.aep", "masks.aep"),
("091-mask-rect-props.aep", "masks.aep"),
("093-mask-path-2keys.aep", "masks.aep"),
("110-text-A.aep", "text.aep"),
("110-text-A.aepx", "aepx-pair.aepx"),
("113-text-Hello-size60-fillorange.aep", "text.aep"),
("114-text-animator-opacity.aep", "text.aep"),
("122-marker-comp-1s.aep", "markers.aep"),
("123-marker-layer-1s.aep", "markers.aep"),
("124-precomp-Pre.aep", "footage-precomp.aep"),
("124-precomp-Pre.aepx", "aepx-pair.aepx"),
("126-footage-png-layer.aep", "footage-precomp.aep"),
("202-key-out-hold-in-linear.aep", "keyframes.aep"),
("203-key-in-hold-out-linear.aep", "keyframes.aep"),
("204-key-ease-asymmetric.aep", "keyframes.aep"),
("205-key-opacity-ease-asymmetric.aep", "keyframes.aep"),
("206-key-scale-2key-linear.aep", "keyframes.aep"),
("208-key-mask-feather-2key-linear.aep", "masks.aep"),
("210-key-fill-color-2key-linear.aep", "keyframes.aep"),
("211-anchor-100x100-solid-10-20.aep", "layers-comps.aep"),
("212-anchor-400x300-solid-100-50.aep", "layers-comps.aep"),
("213-expr-opacity-wiggle-disabled.aep", "keyframes.aep"),
("214-fx-gaussianblur-default.aep", "effects.aep"),
("215-fx-fill-default.aep", "effects.aep"),
("216-fx-gaussianblur-40.aep", "effects.aep"),
("217-fx-checkbox-on.aep", "effects.aep"),
("218-fx-point-111-222.aep", "effects.aep"),
("219-fx-angle-90.aep", "effects.aep"),
("220-fx-layercontrol-to-layer1.aep", "effects.aep"),
("221-fx-slider-2key.aep", "effects.aep"),
("222-layer-video-off.aep", "layers-comps.aep"),
("223-layer-audio-off.aep", "layers-comps.aep"),
("224-layer-effects-off.aep", "layers-comps.aep"),
("225-layer-blend-screen.aep", "layers-comps.aep"),
("226-layer-blend-add.aep", "layers-comps.aep"),
("227-layer-blend-overlay.aep", "layers-comps.aep"),
("228-layer-blend-difference.aep", "layers-comps.aep"),
("229-comp-fps-29.97.aep", "layers-comps.aep"),
("230-comp-fps-23.976.aep", "layers-comps.aep"),
("231-comp-bg-grey-0.5.aep", "layers-comps.aep"),
("232-mask-ellipse.aep", "masks.aep"),
("233-mask-open-path.aep", "masks.aep"),
("234-mask-mode-intersect.aep", "masks.aep"),
("235-mask-mode-lighten.aep", "masks.aep"),
("236-mask-mode-darken.aep", "masks.aep"),
("237-mask-mode-difference.aep", "masks.aep"),
("238-shape-rect-rounded-corners.aep", "shapes.aep"),
("239-shape-stroke-green-w8-round.aep", "shapes.aep"),
("240-shape-custom-path-tangents.aep", "shapes.aep"),
("241-shape-gradient-fill-linear.aep", "shapes.aep"),
("242-shape-group-position-50-50.aep", "shapes.aep"),
("243-text-multiline-A-CR-B.aep", "text.aep"),
("245-text-box-400x200-Hello.aep", "text.aep"),
("246-text-box-center-align.aep", "text.aep"),
("247-text-tracking-100.aep", "text.aep"),
("248-text-range-fill-red-1-3.aep", "text.aep"),
("249-marker-layer-full.aep", "markers.aep"),
("251-camera-one-node.aep", "3d.aep"),
("252-light-point.aep", "3d.aep"),
("253-camera-position-100-200-m1000.aep", "3d.aep"),
("254-light-spot-intensity-50.aep", "3d.aep"),
("256-camera-two-node-default.aep", "3d.aep"),
("259-solid-blue-0-0-1.aep", "layers-comps.aep"),
("299-save-noise.aep", "layers-comps.aep"),
("300-fx-gaussianblur-0-explicit.aep", "effects.aep"),
("301-fx-gaussianblur-40-then-25.aep", "effects.aep"),
("302-fx-fill-opacity-100-explicit.aep", "effects.aep"),
("303-fx-fill-opacity-50-then-100.aep", "effects.aep"),
("304-fx-slider-0-explicit.aep", "effects.aep"),
("305-key-scale-bezier-ease.aep", "keyframes.aep"),
("306-key-maskfeather-bezier-ease.aep", "masks.aep"),
("307-key-fillcolor-bezier.aep", "keyframes.aep"),
("309-solid-100x100-mask-rect.aep", "masks.aep"),
("310-solid-100x100-pointcontrol.aep", "layers-comps.aep"),
("311-position-default-explicit.aep", "layers-comps.aep"),
("316-layer-stretch50.aep", "keyframes.aep"),
("317-layer-stretch150.aep", "keyframes.aep"),
("318-layer-inpoint-0.3333.aep", "layers-comps.aep"),
("319-precomp-timeremap.aep", "footage-precomp.aep"),
("320-fx-layercontrol-self-explicit.aep", "effects.aep"),
("321-fx-layercontrol-none.aep", "effects.aep"),
("323-fx-dropdown-5items.aep", "effects.aep"),
("324-fx-dropdown-5items-select3.aep", "effects.aep"),
("325-comp-pixelaspect-0.9091.aep", "layers-comps.aep"),
("326-comp-shutterphase-m90.aep", "layers-comps.aep"),
("327-comp-displaystartframe-100.aep", "layers-comps.aep"),
("328-mask-two-ellipse-rect.aep", "masks.aep"),
("329-mask-ellipse-mode-none.aep", "masks.aep"),
("330-shape-polystar-star-5-50-100.aep", "shapes.aep"),
("331-shape-polystar-polygon-5-100.aep", "shapes.aep"),
("332-shape-gradient-fill-radial.aep", "shapes.aep"),
("333-shape-group-two-rects.aep", "shapes.aep"),
("334-text-box-right-align.aep", "text.aep"),
("335-text-point-fauxbold.aep", "text.aep"),
("336-text-point-fauxitalic.aep", "text.aep"),
("337-text-point-allcaps.aep", "text.aep"),
("338-text-point-smallcaps.aep", "text.aep"),
("339-text-point-leading60.aep", "text.aep"),
("340-text-range-two-styles.aep", "styles.aep"),
("341-camera-zoom-2000.aep", "3d.aep"),
("342-camera-dof-800-30.aep", "3d.aep"),
("343-light-spot-color-red.aep", "3d.aep"),
("344-light-spot-coneangle-60.aep", "3d.aep"),
("345-light-spot-conefeather-30.aep", "3d.aep"),
("347-marker-layer-label3.aep", "markers.aep"),
("348-marker-layer-navigation-cue.aep", "markers.aep"),
("349-marker-layer-event-cue-params.aep", "markers.aep"),
("350-footage-wav-imported.aep", "footage-precomp.aep"),
("351-footage-wav-as-layer.aep", "footage-precomp.aep"),
("352-footage-pngseq-imported.aep", "footage-precomp.aep"),
("354-footage-pngseq-timeremap.aep", "footage-precomp.aep"),
("356-fx-tint-default.aep", "effects.aep"),
("357-fx-tint-black-0.2-0.4-0.6.aep", "effects.aep"),
("361-fx-tint-amount-0.aep", "effects.aep"),
("363-fx-tint-amount-2key.aep", "effects.aep"),
("364-fx-tint-white-2key.aep", "effects.aep"),
("366-fx-blur-then-tint.aep", "effects.aep"),
("368-fx-ramp-default.aep", "effects.aep"),
("369-fx-ramp-start-100-200.aep", "effects.aep"),
("371-fx-ramp-startcolor-red.aep", "effects.aep"),
("374-fx-ramp-end-2000-m100.aep", "effects.aep"),
("377-fx-ramp-shape-radial.aep", "effects.aep"),
("378-fx-ramp-scatter-12.aep", "effects.aep"),
("380-fx-ramp-blend-25pct.aep", "effects.aep"),
("382-fx-ramp-start-2key.aep", "effects.aep"),
("383-fx-ramp-on-100x100-start-10-20.aep", "effects.aep"),
("385-text-anchor-10-20.aep", "text.aep"),
("386-text-etx-A-B.aep", "text.aep"),
("389-fx-exposure-default.aep", "effects.aep"),
("390-fx-exposure-channels-individual.aep", "effects.aep"),
("391-fx-exposure-master-1.5.aep", "effects.aep"),
("393-fx-exposure-offset-0.1.aep", "effects.aep"),
("394-fx-exposure-gamma-2.2.aep", "effects.aep"),
("395-fx-exposure-individual-red-1.aep", "effects.aep"),
("396-fx-exposure-bypass-on.aep", "effects.aep"),
("397-fx-exposure-master-2key.aep", "effects.aep"),
("400-text-autoleading-on.aep", "text.aep"),
("403-matte-L-alpha-M.aep", "layers-comps.aep"),
("404-matte-L-alphainv-M.aep", "layers-comps.aep"),
("405-matte-L-luma-M.aep", "layers-comps.aep"),
("406-matte-L-lumainv-M.aep", "layers-comps.aep"),
("407-matte-M-alpha-L-below.aep", "layers-comps.aep"),
("408-matte-L-alpha-M-visible.aep", "layers-comps.aep"),
("410-fx-invert-channel-2.aep", "effects.aep"),
("411-fx-invert-blend-50.aep", "effects.aep"),
("413-fx-fastbox-radius-20.aep", "effects.aep"),
("414-fx-fastbox-iterations-1.aep", "effects.aep"),
("416-fx-fastbox-repeatedge-off.aep", "effects.aep"),
("418-fx-gaussian-dimensions-3.aep", "effects.aep"),
("419-fx-gaussian-repeatedge-off.aep", "effects.aep"),
("422-fx-dropshadow-opacity-204.aep", "effects.aep"),
("426-fx-dropshadow-shadowonly-on.aep", "effects.aep"),
("427-fx-glow-default.aep", "effects.aep"),
("429-fx-glow-threshold-76.5.aep", "effects.aep"),
("438-fx-glow-midpoint-0.25.aep", "effects.aep"),
("444-fx-huesat-hue-90.aep", "effects.aep"),
("446-fx-huesat-light-m30.aep", "effects.aep"),
("448-fx-huesat-colorizehue-120.aep", "effects.aep"),
("451-shape-ellipse-400x300-fill.aep", "shapes.aep"),
("457-shape-group-scale-50-80.aep", "shapes.aep"),
("462-shape-layer-anchor-10-20.aep", "shapes.aep"),
("464-shape-stroke-opacity-50.aep", "shapes.aep"),
("467-shape-trim-end-70.aep", "shapes.aep"),
("469-shape-trim-type-2.aep", "shapes.aep"),
("471-shape-rect-roundness-30.aep", "shapes.aep"),
("473-shape-star-points-6.aep", "shapes.aep"),
("482-shape-two-groups.aep", "shapes.aep"),
("483-shape-nested-group-rect.aep", "shapes.aep"),
("485-layer-3d-on.aep", "3d.aep"),
("486-layer-3d-rotx-30.aep", "3d.aep"),
("487-layer-3d-roty-45.aep", "3d.aep"),
("488-layer-3d-orientation-10-20-30.aep", "3d.aep"),
("509-marker-comp-two.aep", "markers.aep"),
("510-marker-layer-0.52-dur0.3.aep", "markers.aep"),
("512-fx-levels-inblack-0.1.aep", "effects.aep"),
("514-fx-levels-gamma-2.aep", "effects.aep"),
("516-fx-levels-outwhite-0.9.aep", "effects.aep"),
("517-text-box-600x400-wrap.aep", "text.aep"),
("519-shape-all-items-default.aep", "shapes.aep"),
("526-text-point-HHHH-default.aep", "text.aep"),
("527-text-point-HHHH-baseline-normal.aep", "text.aep"),
("528-text-point-HHHH-baseline-subscript.aep", "text.aep"),
("529-fx-timewarp-default.aep", "effects.aep"),
("530-fx-timewarp-speed-25.aep", "effects.aep"),
("531-fx-timewarp-speed-keyed-50-200.aep", "effects.aep"),
("532-fx-timewarp-method-1.aep", "effects.aep"),
("533-fx-timewarp-sourceframe-12.aep", "effects.aep"),
("534-fx-slider-expression-time10.aep", "effects.aep"),
("535-camera-position-on-3d-rotx.aep", "3d.aep"),
("536-camera-one-node-position-on-3d-rotx.aep", "3d.aep"),
("537-camera-default-on-3d-rotx.aep", "3d.aep"),
("538-text-point-HHHH-normal-ref.aep", "text.aep"),
("539-text-hscale-0.9.aep", "text.aep"),
("540-text-vscale-1.5.aep", "text.aep"),
("541-text-baselineshift-41.aep", "text.aep"),
("542-text-autokern-none.aep", "text.aep"),
("543-text-autokern-optical.aep", "text.aep"),
("544-text-applystroke-on.aep", "text.aep"),
("545-text-strokewidth-5.aep", "text.aep"),
("546-text-applyfill-off.aep", "text.aep"),
("548-text-linejoin-round.aep", "text.aep"),
("550-text-strokeoverfill-off.aep", "text.aep"),
("552-text-nobreak-on.aep", "text.aep"),
("553-text-tsume-0.5.aep", "text.aep"),
("554-text-kerning-50.aep", "text.aep"),
("555-text-ligature-on.aep", "text.aep"),
("556-text-autohyphenate-off.aep", "text.aep"),
("558-text-hangingroman-on.aep", "text.aep"),
("559-text-everyline-on.aep", "text.aep"),
("560-text-firstlineindent-20.aep", "text.aep"),
("561-text-startindent-30.aep", "text.aep"),
("562-text-endindent-40.aep", "text.aep"),
("563-text-spacebefore-10.aep", "text.aep"),
("564-text-spaceafter-12.aep", "text.aep"),
("565-text-justify-fullleft.aep", "text.aep"),
("566-text-justify-fullcenter.aep", "text.aep"),
("567-text-justify-fullright.aep", "text.aep"),
("568-text-justify-fullall.aep", "text.aep"),
("569-text-direction-rtl.aep", "text.aep"),
("571-text-digitset-arabic.aep", "text.aep"),
("572-text-leadingtype-japanese.aep", "text.aep"),
("573-text-baselinedir-rotated.aep", "text.aep"),
("575-text-vertical-rtl.aep", "text.aep"),
("576-text-baselinedir-crossstream.aep", "text.aep"),
("578-text-digitset-hindi.aep", "text.aep"),
("579-textanim-position-0-m50.aep", "text.aep"),
("580-textanim-start-25.aep", "text.aep"),
("581-textanim-end-75.aep", "text.aep"),
("582-textanim-offset-10.aep", "text.aep"),
("583-textanim-units-index.aep", "text.aep"),
("584-textanim-basedon-3-words.aep", "text.aep"),
("585-textanim-mode-2-subtract.aep", "text.aep"),
("586-textanim-amount-50.aep", "text.aep"),
("587-textanim-shape-2-rampup.aep", "text.aep"),
("588-textanim-smoothness-50.aep", "text.aep"),
("589-textanim-easehigh-30.aep", "text.aep"),
("590-textanim-easelow-40.aep", "text.aep"),
("591-textanim-randomize-seed-7.aep", "text.aep"),
("592-textanim-many-props.aep", "text.aep"),
("593-textanim-start-keyed-ease-0-100.aep", "text.aep"),
("594-textanim-position-start-keyed-ease.aep", "text.aep"),
("595-text-stroke-scale-shift-combined.aep", "text.aep"),
("596-text-combined-fill-over-stroke.aep", "text.aep"),
("597-key-anchor-ease-out50-40-in30-60.aep", "keyframes.aep"),
("598-key-ramp-point-ease-color-bezier.aep", "keyframes.aep"),
("599-key-mask-path-ease-infl75.aep", "masks.aep"),
("601-precomp-two-comps-in-C.aep", "footage-precomp.aep"),
("603-footage-exrseq-0101-as-layer.aep", "footage-precomp.aep"),
("610-fx-tint-named-My-Tint.aep", "effects.aep"),
("621-settings-bpc-8.aep", "settings-a.aep"),
("622-settings-bpc-16.aep", "settings-c.aep"),
("623-settings-workingspace-none.aep", "settings-a.aep"),
("625-settings-gamma-2.4.aep", "settings-a.aep"),
("628-settings-scene-compensation-off.aep", "settings-a.aep"),
("629-settings-time-display-frames.aep", "settings-a.aep"),
("630-settings-frame-start-1.aep", "settings-a.aep"),
("632-settings-linearize-and-blend-linear.aep", "settings-b.aep"),
("633-settings-feet-frames-35.aep", "settings-b.aep"),
("634-settings-feet-frames-16.aep", "settings-c.aep"),
("641-stretch-200-keys-position-1s-2s.aep", "keyframes.aep"),
("642-stretch-50-keys-position-1s-2s.aep", "keyframes.aep"),
("643-stretch-200-start-1-keys-position-2s-3s.aep", "keyframes.aep"),
("645-footage-mp4-conform-30.aep", "footage-precomp.aep"),
("650-footage-tga-still-as-layer.aep", "footage-precomp.aep"),
("651-footage-psd-flat-as-layer.aep", "footage-precomp.aep"),
("652-footage-ai-as-layer.aep", "footage-precomp.aep"),
("653-footage-eps-as-layer.aep", "footage-precomp.aep"),
("700-key-mask-path-ease-out20-in50.aep", "masks.aep"),
("701-light-parallel-int80-color.aep", "3d.aep"),
("702-light-ambient-int50-color.aep", "3d.aep"),
("703-key-orientation-0-to-10-20-30-linear.aep", "3d.aep"),
("704-light-environment-default.aep", "3d.aep"),
("705-mask-on-text-rect-40-m70-160-10.aep", "text.aep"),
("706-mask-on-shape-rect-0-m150-100-150.aep", "masks.aep"),
("707-shape-merge-subtract-rect-ellipse.aep", "shapes.aep"),
("708-shape-merge-intersect-rect-ellipse.aep", "shapes.aep"),
("709-shape-repeater-3-pos150-60-rot10-scale90-80-op40.aep", "shapes.aep"),
("710-shape-offset-paths-20-round.aep", "shapes.aep"),
("711-fx-directional-blur-30-40-on-M.aep", "effects.aep"),
("712-fx-eleven-effects-defaults-on-M.aep", "effects.aep"),
("713-fx-radial-blur-zoom-20-on-M.aep", "effects.aep"),
("714-fx-ccradial-type2-30-60-on-M.aep", "effects.aep"),
("715-fx-venetian-40-30-50-5-on-M.aep", "effects.aep"),
("716-fx-channel-blur-5-10-15-20-edge-horiz-on-M.aep", "effects.aep"),
("717-fx-blackwhite-set-tint-on-L.aep", "effects.aep"),
("718-fx-tritone-set-blend25-on-L.aep", "effects.aep"),
("719-fx-lumakey-darker-140-20-1-2.5-on-M.aep", "effects.aep"),
("720-fx-simplechoker-3.5-on-M.aep", "effects.aep"),
("721-fx-simplechoker-3.5-view-matte-on-M.aep", "effects.aep"),
("722-fx-mattechoker-set-on-M.aep", "effects.aep"),
("723-fx-transform-set-on-M.aep", "effects.aep"),
("725-text-point-HHHH-normal-ref-S18.aep", "text.aep"),
("727-text-reset-paragraph.aep", "text.aep"),
("728-textanim-character-offset-3.aep", "text.aep"),
("730-key-anchor-ease-on-400x800-solid.aep", "keyframes.aep"),
("731-shape-merge-offset-repeater-defaults.aep", "shapes.aep"),
("732-text-box-byteedit-para24-0.aep", "text.aep"),
("733-text-box-byteedit-para35-0.aep", "text.aep"),
("734-text-box-byteedit-style68-1.aep", "styles.aep"),
("828-shape-offset-paths-20-copies3-copyoffset1.5-stroke.aep", "shapes.aep"),
("851-shape-key-trim-end-0-100-linear.aep", "shapes.aep"),
("852-shape-key-trim-end-bezier-out0-60-in20-30.aep", "shapes.aep"),
("853-shape-key-group-position-0-200-100-linear.aep", "shapes.aep"),
("854-shape-key-fill-color-red-blue-linear.aep", "shapes.aep"),
("855-shape-key-trim-offset-0-90-hold.aep", "shapes.aep"),
("856-shape-trim-end-expression-time50.aep", "shapes.aep"),
("857-shape-key-group-scale-100-50-150-linear.aep", "shapes.aep"),
("900-mask-added-no-path.aep", "masks.aep"),
("901-mask-no-path-expansion-m100.aep", "masks.aep"),
("902-settings-rec709-16bpc-steps-png-grey-solid.aep", "settings-c.aep"),
("905-fx-24-effects-set-one-comp.aep", "effects.aep"),
("906-blendmodes-13-solids-on-steps.aep", "layers-comps.aep"),
("951-styles-all-nine-defaults-on-B.aep", "styles.aep"),
("963-curves-red-mid-down-on-S.aep", "styles.aep"),
("964-curves-rgb-s-curve-on-S.aep", "styles.aep"),
("966-style-drop-shadow-opacity50-distance20.aep", "styles.aep"),
("970-style-stroke-size10-color-green.aep", "styles.aep"),
("974-style-gradient-overlay-angle45-scale150.aep", "styles.aep"),
("975-style-fill-opacity0-with-drop-shadow.aep", "styles.aep"),
("976-style-drop-shadow-opacity-keyed-100-20-linear.aep", "styles.aep"),
("977-styles-all-params-changed.aep", "styles.aep"),
("979-style-inner-glow-source-2.aep", "styles.aep"),
("981-layer-stretch-minus100-start5.aep", "keyframes.aep"),
("982-layer-stretch-minus100-opacity-keys.aep", "keyframes.aep"),
("983-layer-stretch-minus50-opacity-keys.aep", "keyframes.aep"),
("985-meshwarp-3x3-vertex-moved-on-S.aep", "styles.aep"),
("986-shape-fill-switched-off-green.aep", "shapes.aep"),
("988-style-drop-shadow-switched-off.aep", "styles.aep"),
];
+342
View File
@@ -0,0 +1,342 @@
//! The one place the tests reach the generated `.aep` / `.aepx` test projects.
//!
//! Every test addresses a case by its case name, the name of the single-case file it was first
//! written against (`"058-key-opacity-2key.aep"`). The cases now live in a few combined projects
//! (`tests/fixtures/CASES.md`): each case is the composition named like the case without its
//! extension (`058-key-opacity-2key`), built like the single-case file's composition `C` (plus
//! the compositions it uses). [`try_fixture`] hands a test the case as a project of its own: the
//! combined file with every project item removed that the case composition does not use
//! (directly or through precomposition layers), written back with [`craft_aep::write`].
//! The case composition is renamed `C` as in the single-case files; everything else of the file
//! (project settings, the effect definitions, the XMP packet) stays, and the layers and items keep
//! the ids they have in the combined file.
//!
//! A case name that is a file of its own in the directory (an old single-case fixture or a
//! combined file's own name) is read as it is. When the file is not
//! there the test prints `SKIPPED: fixture <name> missing` and returns without failing (the
//! macros below), so the suite runs without the projects. The directory is the one in the
//! `CRAFT_AEP_FIXTURES` environment variable (which may also hold the old single-case
//! files); without it every such test skips. With `CRAFT_AEP_FIXTURES_REQUIRED` set (to
//! anything but an empty string) a missing project fails the test instead, so a run against the
//! corpus cannot pass by skipping.
#![allow(dead_code, unused_macros)]
mod cases;
use std::collections::{BTreeSet, HashMap};
use std::path::PathBuf;
use std::sync::{Arc, Mutex, OnceLock};
use craft_aep::{AepFile, Body, Chunk, ItemKind, Project};
pub use cases::CASES;
/// The directory the test projects are read from, or `None` when `CRAFT_AEP_FIXTURES` is
/// not set (the projects are opt-in).
pub fn dir() -> Option<PathBuf> {
std::env::var_os("CRAFT_AEP_FIXTURES").filter(|d| !d.is_empty()).map(PathBuf::from)
}
/// The combined files the cases live in (and the empty project, a file of its own), sorted.
pub const FILES: &[&str] = &[
"3d.aep",
"aepx-pair.aep",
"aepx-pair.aepx",
"effects.aep",
"empty.aep",
"footage-precomp.aep",
"fx-switch.aep",
"keyframes.aep",
"layers-comps.aep",
"markers.aep",
"masks.aep",
"settings-a.aep",
"settings-b.aep",
"settings-c.aep",
"shapes.aep",
"styles.aep",
"text.aep",
];
/// Where a case is read from.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Source {
/// A file of its own, read as it is.
File(PathBuf),
/// The composition `comp` of the combined project `file`.
Case { file: PathBuf, comp: String },
}
impl Source {
/// The file the case is in.
pub fn path(&self) -> &PathBuf {
match self {
Source::File(p) | Source::Case { file: p, .. } => p,
}
}
}
/// The combined file of a case name (`None` for a name that is not a case).
pub fn combined_file(name: &str) -> Option<&'static str> {
CASES.binary_search_by(|(n, _)| n.cmp(&name)).ok().and_then(|i| CASES.get(i)).map(|(_, f)| *f)
}
/// The name of the case's composition: the case name without its extension.
pub fn case_comp(name: &str) -> &str {
name.rsplit_once('.').map_or(name, |(stem, _)| stem)
}
/// Whether `path` is a file. Only a missing path is `false`: any other error (no permission, a
/// broken folder) fails the test, so a fixture that is there but unreadable never turns into a skip.
fn is_fixture(path: &std::path::Path) -> bool {
match std::fs::metadata(path) {
Ok(m) if m.is_file() => true,
Ok(_) => panic!("{}: not a file", path.display()),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => false,
Err(e) => panic!("{}: {e}", path.display()),
}
}
/// Where a case is, or `None` (after printing the skip line) when its file is missing.
pub fn locate(name: &str) -> Option<Source> {
let Some(dir) = dir() else {
skipped(name);
return None;
};
let own = dir.join(name);
if is_fixture(&own) {
return Some(Source::File(own));
}
let Some(file) = combined_file(name) else {
skipped(name);
return None;
};
let path = dir.join(file);
if !is_fixture(&path) {
skipped(name);
return None;
}
// The empty project is a whole file: it has no composition.
if file == "empty.aep" {
return Some(Source::File(path));
}
Some(Source::Case { file: path, comp: case_comp(name).to_string() })
}
/// The file a case is in (the combined project for a case in one), or `None` when it is missing.
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: &craft_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)? {
Source::File(path) => Some(std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()))),
Source::Case { file, comp } => Some(case_bytes(&file, &comp).as_ref().clone()),
}
}
/// The bytes of a whole file of the directory (a combined project), or `None` when it is missing.
pub fn try_file(file: &str) -> Option<Vec<u8>> {
let path = dir()?.join(file);
if is_fixture(&path) {
Some(std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())))
} else {
skipped(file);
None
}
}
/// The case names with this extension (sorted), or `None` when there are none: the cases of
/// [`CASES`] whose file (of its own or combined) is there, else the files with that extension.
pub fn names(ext: &str) -> Option<Vec<String>> {
let Some(dir) = dir() else {
skipped(&format!("*.{ext}"));
return None;
};
let mut v: Vec<String> = CASES
.iter()
.filter(|(n, f)| std::path::Path::new(n).extension().is_some_and(|x| x == ext) && (is_fixture(&dir.join(n)) || is_fixture(&dir.join(f))))
.map(|(n, _)| n.to_string())
.collect();
if v.is_empty() {
let entries = match std::fs::read_dir(&dir) {
Ok(entries) => entries.map(|e| e.unwrap_or_else(|e| panic!("{}: {e}", dir.display()))).collect(),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Vec::new(),
Err(e) => panic!("{}: {e}", dir.display()),
};
v = entries
.into_iter()
.filter_map(|e| e.file_name().into_string().ok())
.filter(|n| std::path::Path::new(n).extension().is_some_and(|x| x == ext))
.collect();
}
v.sort();
if v.is_empty() {
skipped(&format!("*.{ext}"));
None
} else {
Some(v)
}
}
pub fn skipped(name: &str) {
assert!(
std::env::var_os("CRAFT_AEP_FIXTURES_REQUIRED").is_none_or(|v| v.is_empty()),
"fixture {name} missing (CRAFT_AEP_FIXTURES_REQUIRED is set; CRAFT_AEP_FIXTURES = {:?})",
std::env::var_os("CRAFT_AEP_FIXTURES")
);
println!("SKIPPED: fixture {name} missing");
}
/// A parsed combined file, read once per test binary.
fn parsed(file: &PathBuf) -> &'static AepFile<'static> {
static FILES: OnceLock<Mutex<HashMap<PathBuf, &'static AepFile<'static>>>> = OnceLock::new();
let mut files = FILES.get_or_init(Default::default).lock().unwrap_or_else(|e| e.into_inner());
files.entry(file.clone()).or_insert_with(|| {
let bytes: &'static [u8] = Box::leak(std::fs::read(file).unwrap_or_else(|e| panic!("{}: {e}", file.display())).into_boxed_slice());
Box::leak(Box::new(craft_aep::parse_any(bytes).unwrap_or_else(|e| panic!("{}: {e}", file.display()))))
})
}
/// The single-case project of composition `comp` in `file`, made once per test binary.
fn case_bytes(file: &PathBuf, comp: &str) -> Arc<Vec<u8>> {
static CASES_MADE: OnceLock<Mutex<HashMap<(PathBuf, String), Arc<Vec<u8>>>>> = OnceLock::new();
let key = (file.clone(), comp.to_string());
if let Some(b) = CASES_MADE.get_or_init(Default::default).lock().unwrap_or_else(|e| e.into_inner()).get(&key) {
return b.clone();
}
let bytes = Arc::new(isolate(parsed(file), comp).unwrap_or_else(|e| panic!("{}: case {comp}: {e}", file.display())));
CASES_MADE.get_or_init(Default::default).lock().unwrap_or_else(|e| e.into_inner()).insert(key, bytes.clone());
bytes
}
/// The item id of an `Item` list (`idta` byte 16).
fn item_id(item: &Chunk<'_>) -> Option<u32> {
let idta = item.child(b"idta")?.bytes()?;
Some(u32::from_be_bytes(idta.get(16..20)?.try_into().ok()?))
}
/// The cases that import a footage file without using it in their composition, and how to find
/// that item: it stays with the case.
const UNUSED_FOOTAGE: &[(&str, &str, fn(&craft_aep::Item<'_, '_>) -> bool)] = &[
("350-footage-wav-imported", "the WAV", |i| i.footage().and_then(|f| f.path).is_some_and(|p| p.ends_with("test-tone.wav"))),
("352-footage-pngseq-imported", "the png sequence", |i| i.sequence_info().is_some_and(|s| s.prefix == "seq_" && s.suffix == ".png")),
];
/// `file` with only the composition `comp` and the project items it uses (layer sources,
/// transitively), and the folders that hold them; the composition is renamed `C`.
pub fn isolate(file: &AepFile<'_>, comp: &str) -> Result<Vec<u8>, String> {
let project = Project::new(file).ok_or("no project")?;
let items = project.all_items();
let case = items
.iter()
.find(|i| i.kind() == Some(ItemKind::Composition) && i.name().as_deref() == Some(comp))
.ok_or_else(|| format!("no composition {comp}"))?;
let mut keep = BTreeSet::new();
let mut todo = vec![case.id().ok_or("case without id")?];
for (_, what, is) in UNUSED_FOOTAGE.iter().filter(|(c, _, _)| *c == comp) {
todo.push(items.iter().find(|i| is(i)).and_then(|i| i.id()).ok_or_else(|| format!("no item {what}"))?);
}
while let Some(id) = todo.pop() {
if !keep.insert(id) {
continue;
}
let Some(item) = items.iter().find(|i| i.id() == Some(id)) else { continue };
if let Some(c) = item.comp() {
todo.extend(c.layers().filter_map(|l| l.header()?.source_id));
}
}
let mut out = file.clone();
let fold = out.chunks.iter_mut().find(|c| c.is_list(b"Fold")).ok_or("no LIST Fold")?;
prune(fold, &keep);
rename(fold, case.id().ok_or("case without id")?, "C");
craft_aep::write(&out).map_err(|e| e.to_string())
}
/// Removes the items of `list` (and of its folders) that are not kept; a folder stays while it
/// holds a kept item.
fn prune(list: &mut Chunk<'_>, keep: &BTreeSet<u32>) {
let Body::List { children, .. } = &mut list.body else { return };
children.retain_mut(|c| {
if !c.is_list(b"Item") {
return true;
}
if let Body::List { children: inner, .. } = &mut c.body
&& let Some(sfdr) = inner.iter_mut().find(|x| x.is_list(b"Sfdr"))
{
prune(sfdr, keep);
let holds = sfdr.children().iter().any(|x| x.is_list(b"Item"));
return holds || item_id(c).is_some_and(|id| keep.contains(&id));
}
item_id(c).is_some_and(|id| keep.contains(&id))
});
}
/// Renames the item with this id (searching folders too).
fn rename(list: &mut Chunk<'_>, id: u32, name: &str) -> bool {
let Body::List { children, .. } = &mut list.body else { return false };
for c in children.iter_mut().filter(|c| c.is_list(b"Item")) {
if item_id(c) == Some(id) {
let Body::List { children: inner, .. } = &mut c.body else { return false };
let Some(utf8) = inner.iter_mut().find(|x| x.is(b"Utf8")) else { return false };
*utf8 = Chunk::data(*b"Utf8", name.as_bytes().to_vec());
return true;
}
if let Body::List { children: inner, .. } = &mut c.body
&& let Some(sfdr) = inner.iter_mut().find(|x| x.is_list(b"Sfdr"))
&& rename(sfdr, id, name)
{
return true;
}
}
false
}
/// The bytes of a case; returns from the calling test when it is missing.
macro_rules! fixture {
($name:expr) => {
match $crate::common::try_fixture(&$name) {
Some(bytes) => bytes,
None => return,
}
};
}
/// The path of a case's file; returns from the calling test when it is missing.
macro_rules! fixture_path {
($name:expr) => {
match $crate::common::resolve(&$name) {
Some(path) => path,
None => return,
}
};
}
/// The case names with this extension; returns from the calling test when there are none.
macro_rules! fixture_names {
($ext:expr) => {
match $crate::common::names($ext) {
Some(names) => names,
None => return,
}
};
}
/// The value of a helper that returns `None` for a missing case; returns from the calling test
/// then (the helper has printed the skip line).
macro_rules! skip {
($e:expr) => {
match $e {
Some(value) => value,
None => return,
}
};
}
+30
View File
@@ -0,0 +1,30 @@
//! container tests of craft-aep.
#[macro_use]
mod helpers;
mod aepx;
mod batch3_core;
mod batch3_objects;
mod batch5;
mod cases_600;
mod ease_round2;
mod effects;
mod effects_batch4;
mod effects_batch5;
mod effects_exposure;
mod header;
mod keyframes;
mod layer_switches;
mod masks;
mod matte;
mod odd_cases;
mod robustness;
mod roundtrip;
mod shapes;
mod text_fields;
mod text_markers_footage;
mod text_style_slots;
mod tree_index;
mod typed;
mod values;
+174
View File
@@ -0,0 +1,174 @@
//! `.aepx` (the XML form) read into the chunk tree, compared with the `.aep` of the same project.
//!
//! The pair `aepx-pair` (cases 000, 058, 060, 110 and 124, one composition each) was saved by
//! After Effects from the same state, the `.aepx` right after the `.aep`.
//! The trees are identical except for two documented differences: the save counter (`head`
//! `u32` at byte 16) is one higher in the `.aepx`, and pad bytes are not written in XML (an odd
//! body gets a zero pad byte). The XMP packet of the fixtures is the base packet in both forms.
use craft_aep::{AepError, AepFile, Body, Chunk, Limits, Project, is_aepx, parse, parse_any, read_aepx, read_aepx_with_limits, write};
/// The `.aepx` fixtures; each has the `.aep` of the same name.
const PAIRS: &[&str] = &["aepx-pair"];
/// The `.aep` tree with the differences an `.aepx` of the next save has removed: the `head` save
/// counter is taken from `other`.
fn with_head_of(mut file: AepFile<'static>, other: &AepFile<'_>) -> AepFile<'static> {
if let (Some(h), Some(src)) = (file.chunks.iter_mut().find(|c| c.is(b"head")), other.chunk(b"head")) {
*h = src.clone().into_owned();
}
file
}
/// The first difference of two chunk sequences, as a path, ignoring pad bytes.
fn first_difference(a: &[Chunk<'_>], b: &[Chunk<'_>], path: &str) -> Option<String> {
if a.len() != b.len() {
return Some(format!("{path}: {} chunks against {}", a.len(), b.len()));
}
for (i, (x, y)) in a.iter().zip(b).enumerate() {
let name = String::from_utf8_lossy(&x.list_type().unwrap_or(x.id)).into_owned();
let here = format!("{path}/{i}:{name}");
if x.id != y.id || x.list_type() != y.list_type() {
return Some(format!("{here}: id differs"));
}
match (&x.body, &y.body) {
(Body::Data(p), Body::Data(q)) | (Body::OpaqueList { data: p, .. }, Body::OpaqueList { data: q, .. }) => {
if p != q {
return Some(format!("{here}: body differs"));
}
}
(Body::Chunks(p), Body::Chunks(q)) | (Body::List { children: p, .. }, Body::List { children: q, .. }) => {
if let Some(d) = first_difference(p, q, &here) {
return Some(d);
}
}
_ => return Some(format!("{here}: body kind differs")),
}
}
None
}
fn head_counter(file: &AepFile<'_>) -> u32 {
let h = file.chunk(b"head").and_then(Chunk::bytes).expect("head");
u32::from_be_bytes([h[16], h[17], h[18], h[19]])
}
#[test]
fn every_pair_gives_the_same_chunk_tree() {
for name in PAIRS {
let aep = skip!(crate::common::try_file(&format!("{name}.aep")));
let aepx = skip!(crate::common::try_file(&format!("{name}.aepx")));
assert!(is_aepx(&aepx) && !is_aepx(&aep), "{name}");
let bin = parse(&aep).unwrap();
let xml = read_aepx(&aepx).unwrap_or_else(|e| panic!("{name}: {e}"));
// The save counter is the only difference in the container.
assert_eq!(head_counter(&xml), head_counter(&bin) + 1, "{name}");
let same = with_head_of(bin.clone().into_owned(), &xml);
assert_eq!(first_difference(&same.chunks, &xml.chunks, ""), None, "{name}");
assert_eq!(xml.trailer, bin.trailer, "{name}: XMP packet");
// Even the bytes agree: written as an `.aep`, the tree is the `.aep` with the next save counter.
assert!(write(&xml).unwrap() == write(&same).unwrap(), "{name}: written bytes differ");
// And the content sniffer picks the right reader for both.
assert_eq!(parse_any(&aepx).unwrap(), xml, "{name}");
assert_eq!(parse_any(&aep).unwrap(), bin, "{name}");
}
}
#[test]
fn the_typed_view_reads_the_same_values() {
for name in PAIRS {
let aep = skip!(crate::common::try_file(&format!("{name}.aep")));
let aepx = skip!(crate::common::try_file(&format!("{name}.aepx")));
let bin = parse(&aep).unwrap();
let xml = read_aepx(&aepx).unwrap();
let (pb, px) = (Project::new(&bin).unwrap(), Project::new(&xml).unwrap());
let items = |p: &Project<'_, '_>| p.all_items().iter().map(|i| (i.kind(), i.display_name(), i.id())).collect::<Vec<_>>();
assert_eq!(items(&pb), items(&px), "{name}");
for (cb, cx) in pb.all_items().iter().filter_map(|i| i.comp()).zip(px.all_items().iter().filter_map(|i| i.comp())) {
assert_eq!(cb.header(), cx.header(), "{name}");
let layers = |c: &craft_aep::Comp<'_, '_>| c.layers().map(|l| (l.name(), l.header(), l.transform(1920, 1080))).collect::<Vec<_>>();
assert_eq!(layers(&cb), layers(&cx), "{name}");
}
}
// Spot checks against the values the cases were made with (060's expression, 110's text).
let aepx = skip!(crate::common::try_file("aepx-pair.aepx"));
let xml = read_aepx(&aepx).unwrap();
assert!(xml.walk().any(|(_, c)| c.is(b"Utf8") && c.bytes() == Some(&b"wiggle(1,10)"[..])));
assert!(xml.walk().any(|(_, c)| c.is_list(b"btdk") && matches!(c.body, Body::OpaqueList { .. })));
let names: Vec<_> = Project::new(&xml).unwrap().all_items().iter().filter(|i| i.comp().is_some()).filter_map(|i| i.name()).collect();
assert_eq!(names, ["000-base", "058-key-opacity-2key", "060-expr-opacity-wiggle", "110-text-A", "124-precomp-Pre", "Pre"]);
}
#[test]
fn damaged_aepx_is_an_error_or_a_tree_never_a_panic() {
let aepx = skip!(crate::common::try_file("aepx-pair.aepx"));
// Truncation at about 160 points.
for cut in (0..aepx.len()).step_by(aepx.len() / 160) {
let _ = read_aepx(&aepx[..cut]);
}
assert!(read_aepx(&aepx[..aepx.len() / 2]).is_err());
// Byte flips: each result is an error or a tree that writes and reads back.
let mut state = 0x2545_f491_u32;
for _ in 0..400 {
let mut damaged = aepx.clone();
for _ in 0..4 {
state ^= state << 13;
state ^= state >> 17;
state ^= state << 5;
let at = state as usize % damaged.len();
damaged[at] ^= 1 << (state % 8);
}
if let Ok(file) = read_aepx(&damaged) {
let bytes = write(&file).unwrap();
let _ = Project::new(&parse(&bytes).unwrap()).map(|p| p.all_items().len());
}
}
// Invalid hex and a damaged entity are errors.
let text = String::from_utf8(aepx.clone()).unwrap();
let odd = text.replacen("bdata=\"00", "bdata=\"0", 1);
assert!(matches!(read_aepx(odd.as_bytes()), Err(AepError::Xml { .. })));
let nonhex = text.replacen("bdata=\"00", "bdata=\"0g", 1);
assert!(matches!(read_aepx(nonhex.as_bytes()), Err(AepError::Xml { .. })));
// Deep nesting is refused at the limit; many elements are bounded.
let deep = format!("<AfterEffectsProject>{}</AfterEffectsProject>", "<Fold>".repeat(1_000_000));
assert_eq!(read_aepx(deep.as_bytes()), Err(AepError::TooDeep));
assert_eq!(read_aepx_with_limits(&aepx, Limits { max_depth: 64, max_chunks: 100 }), Err(AepError::TooManyChunks));
assert_eq!(read_aepx_with_limits(&aepx, Limits { max_depth: 3, max_chunks: 10_000_000 }), Err(AepError::TooDeep));
// A huge hex body is bounded by the input: nothing is allocated from a declared size.
let huge = format!("<AfterEffectsProject><cdat bdata=\"{}\"/></AfterEffectsProject>", "ab".repeat(1 << 20));
assert_eq!(read_aepx(huge.as_bytes()).unwrap().chunks[0].bytes().map(<[u8]>::len), Some(1 << 20));
}
/// Every pair of the local corpus (not in the repository): `AEP_CORPUS=<folder> cargo test
/// --release -p craft-aep --test it container::aepx:: -- --ignored --nocapture`.
#[test]
#[ignore = "needs the local corpus (AEP_CORPUS)"]
fn every_corpus_pair_gives_the_same_chunk_tree() {
let Ok(dir) = std::env::var("AEP_CORPUS") else { return };
let mut names: Vec<_> =
std::fs::read_dir(&dir).unwrap().filter_map(|e| e.ok()).map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "aepx")).collect();
names.sort();
let (mut same, mut differ) = (0, Vec::new());
for x in &names {
let aepx = std::fs::read(x).unwrap();
let aep = std::fs::read(x.with_extension("aep")).unwrap();
let bin = parse(&aep).unwrap();
let xml = match read_aepx(&aepx) {
Ok(f) => f,
Err(e) => {
differ.push(format!("{}: {e}", x.display()));
continue;
}
};
let fixed = with_head_of(bin.clone().into_owned(), &xml);
match first_difference(&fixed.chunks, &xml.chunks, "") {
None if write(&xml).unwrap() == write(&AepFile { trailer: xml.trailer.clone(), ..fixed }).unwrap() => same += 1,
None => differ.push(format!("{}: bytes differ", x.display())),
Some(d) => differ.push(format!("{}: {d}", x.display())),
}
}
println!("{same} of {} pairs give the same chunk tree", names.len());
for d in &differ {
println!("{d}");
}
}
@@ -0,0 +1,377 @@
//! Batch 3 (core): explicit defaults, multi-component bezier ease, colour key distance, exact time
//! stretch and in / out points, Time Remapping, composition aspect / shutter phase / display start.
//! Every expected value is the value the corpus case was made with (its MANIFEST).
use crate::container::helpers::{assert_near, base_layer, first_comp, layer_shown_as, layer_with_id, near, open, without_layer_id};
use craft_aep::{Interpolation, KeyEase, KeyframeKind, LayerHeader, ParamValue, Project, PropNode, Property, Rational, ValueSource};
const L: u32 = 0x1b;
fn with_layer<R>(name: &str, id: u32, f: impl FnOnce(&Project<'_, '_>, &craft_aep::Layer<'_, '_>) -> R) -> Option<R> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
// `L` names the base solid, whatever its id in the case.
let layer = if id == L { base_layer(&comp) } else { layer_with_id(&comp, id) };
f(&project, &layer)
})
}
fn header(name: &str) -> Option<LayerHeader> {
with_layer(name, L, |_, l| l.header().unwrap())
}
fn rat(num: i64, den: i64) -> Rational {
Rational { num, den }
}
fn ease(in_speed: f64, in_influence: f64, out_speed: f64, out_influence: f64) -> KeyEase {
KeyEase { in_speed, in_influence, out_speed, out_influence }
}
fn same_ease(a: &KeyEase, b: &KeyEase) -> bool {
near(a.in_speed, b.in_speed, 1e-9)
&& near(a.in_influence, b.in_influence, 1e-9)
&& near(a.out_speed, b.out_speed, 1e-9)
&& near(a.out_influence, b.out_influence, 1e-9)
}
/// The property at a path of match names below a layer.
fn with_property<R>(name: &str, id: u32, path: &[&str], f: impl FnOnce(&Property<'_, '_>) -> R) -> Option<R> {
Some({
with_layer(name, id, |_, layer| {
let Some(PropNode::Property(p)) = layer.properties().unwrap().find(path) else { panic!("{name}: no property {path:?}") };
f(&p)
})?
})
}
// ------------------------------------------------------------------ explicit defaults (300-304, 311)
fn blur_param(name: &str) -> Option<(Option<ParamValue>, Option<ParamValue>, Option<bool>, ParamValue, bool)> {
Some({
with_layer(name, L, |project, layer| {
let effects = layer.effects();
assert_eq!(effects.len(), 1, "{name}");
let p = project.effect_params(&effects[0]).into_iter().find(|p| p.name == "Blurriness").unwrap();
(p.stored_value(), p.pard_default(), p.is_default(), p.value().unwrap(), p.stored().is_some())
})?
})
}
#[test]
fn an_explicit_zero_blurriness_is_a_value_record_and_25_is_the_default() {
// 300: a fresh Gaussian Blur reads back Blurriness 25 (the MANIFEST row 214 "0" was wrong);
// Blurriness set explicitly to 0 writes a record, the default in pard stays 25.
let (stored, default, is_default, value, has_record) = skip!(blur_param("300-fx-gaussianblur-0-explicit.aep"));
assert_eq!((stored, default, value, has_record), (Some(ParamValue::Number(0.0)), Some(ParamValue::Number(25.0)), ParamValue::Number(0.0), true));
assert_eq!(is_default, Some(false));
// 301: 25 -> 40 -> 25: the record is removed again, the effective value is the default 25.
let (stored, default, is_default, value, has_record) = skip!(blur_param("301-fx-gaussianblur-40-then-25.aep"));
assert_eq!((stored, default, value, has_record), (None, Some(ParamValue::Number(25.0)), ParamValue::Number(25.0), false));
assert_eq!(is_default, Some(true));
// 216 (Blurriness 40): a record, default still 25.
let (stored, default, is_default, value, _) = skip!(blur_param("216-fx-gaussianblur-40.aep"));
assert_eq!((stored, default, value), (Some(ParamValue::Number(40.0)), Some(ParamValue::Number(25.0)), ParamValue::Number(40.0)));
assert_eq!(is_default, Some(false));
}
#[test]
fn setting_a_parameter_back_to_its_default_leaves_no_record() {
// 303: Fill Opacity 1 -> 0.5 -> 1 and 302: Opacity set to 1 explicitly: no record, value 1.0 (100 %).
for name in ["302-fx-fill-opacity-100-explicit.aep", "303-fx-fill-opacity-50-then-100.aep"] {
skip!(with_layer(name, L, |project, layer| {
let p = project.effect_params(&layer.effects()[0]).into_iter().find(|p| p.name == "Opacity").unwrap();
assert!(p.stored().is_none(), "{name}");
assert_eq!((p.value(), p.is_default()), (Some(ParamValue::Number(1.0)), Some(true)), "{name}");
}));
}
// 304: Slider set to 0 explicitly: no record, value 0.
skip!(with_layer("304-fx-slider-0-explicit.aep", L, |project, layer| {
let p = project.effect_params(&layer.effects()[0]).into_iter().find(|p| p.name == "Slider").unwrap();
assert!(p.stored().is_none());
assert_eq!((p.value(), p.is_default()), (Some(ParamValue::Number(0.0)), Some(true)));
}));
// The implicit input layer and the built-in entry are not "at default" questions.
skip!(with_layer("304-fx-slider-0-explicit.aep", L, |project, layer| {
let params = project.effect_params(&layer.effects()[0]);
assert_eq!(params.len(), 3);
assert_eq!(params[0].is_default(), None);
}));
// 071 (Slider 77) is a record that differs from the default.
skip!(with_layer("071-fx-slider-value77.aep", L, |project, layer| {
let p = project.effect_params(&layer.effects()[0]).into_iter().find(|p| p.name == "Slider").unwrap();
assert_eq!((p.value(), p.is_default()), (Some(ParamValue::Number(77.0)), Some(false)));
}));
}
#[test]
fn a_transform_set_to_its_default_adds_no_record() {
// 311: Position set to the value it already had ([960,540,0]): the layer tree is the tree of the
// unedited 299 (which equals the base layer except for the session), no ADBE Position record.
skip!(with_layer("311-position-default-explicit.aep", L, |_, layer| {
let t = layer.transform(1920, 1080).unwrap();
assert_eq!((t.position.value, t.position.source), ([960.0, 540.0, 0.0], ValueSource::Default));
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().to_chunk());
skip!(with_layer("299-save-noise.aep", L, |_, other| assert_eq!(a, without_layer_id(&other.chunk().to_chunk()))));
}));
}
// ------------------------------------------------------------------ bezier ease layouts (305-307)
#[test]
fn scale_keys_keep_their_ease_type_major() {
// 305: Scale keys t=0 [100,100,100] and t=2 [200,150,100]; key1 in speed 0 / influence 33, out
// speed 20 / influence 66; key2 in speed 10 / influence 66, out speed 0 / influence 33. The
// stored speed is a fraction per second (percent / 100), the influence a fraction.
skip!(with_property("305-key-scale-bezier-ease.aep", L, &["ADBE Transform Group", "ADBE Scale"], |p| {
let keys: Vec<_> = p.keys().unwrap().keyframes().collect();
assert_eq!(keys.len(), 2);
let scale = p.time_scale().unwrap();
assert_eq!(keys.iter().map(|k| k.seconds(scale).unwrap()).collect::<Vec<_>>(), [0.0, 2.0]);
for k in &keys {
assert_eq!(k.kind(), KeyframeKind::Plain { components: 3 });
assert_eq!((k.interpolation_in(), k.interpolation_out()), (Some(Interpolation::Bezier), Some(Interpolation::Bezier)));
}
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 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);
}));
}
#[test]
fn mask_feather_keys_keep_their_ease_type_major() {
// 306: Mask Feather keys t=0 [0,0], t=2 [50,30]; key1 in 0/33, out 15/66; key2 in 8/66, out 0/33
// (speed in pixels per second).
skip!(with_layer("306-key-maskfeather-bezier-ease.aep", L, |_, layer| {
let masks = layer.masks();
assert_eq!(masks.len(), 1);
assert_eq!(masks[0].feather.source, ValueSource::Keyframed);
assert_eq!(masks[0].feather.value, [0.0, 0.0]);
}));
skip!(with_property("306-key-maskfeather-bezier-ease.aep", L, &["ADBE Mask Parade", "ADBE Mask Atom", "ADBE Mask Feather"], |p| {
let keys: Vec<_> = p.keys().unwrap().keyframes().collect();
assert_eq!(keys.len(), 2);
for k in &keys {
assert_eq!(k.kind(), KeyframeKind::Plain { components: 2 });
assert_eq!((k.interpolation_in(), k.interpolation_out()), (Some(Interpolation::Bezier), Some(Interpolation::Bezier)));
}
assert_near(&keys[0].value().unwrap(), &[0.0, 0.0], 1e-9);
assert_near(&keys[1].value().unwrap(), &[50.0, 30.0], 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}");
}
assert!(keys[1].ease_component(2).is_none());
}));
}
#[test]
fn one_component_and_position_ease_through_the_component_accessor() {
// 205 (Opacity, n = 1): in 0.05 / 0.2, out 0.2 / 0.8; 204 (Position): the single entry.
skip!(with_property("205-key-opacity-ease-asymmetric.aep", L, &["ADBE Transform Group", "ADBE Opacity"], |p| {
let k = p.keys().unwrap().keyframes().next().unwrap();
assert_eq!(k.ease_component(0), k.ease());
assert!(same_ease(&k.ease_component(0).unwrap(), &ease(0.05, 0.2, 0.2, 0.8)));
assert!(k.ease_component(1).is_none());
}));
skip!(with_property("204-key-ease-asymmetric.aep", L, &["ADBE Transform Group", "ADBE Position"], |p| {
let k = p.keys().unwrap().keyframes().next().unwrap();
assert_eq!(k.ease_component(0), k.ease());
assert!(k.ease_component(1).is_none());
assert_eq!(k.ease_components().unwrap().len(), 1);
}));
}
#[test]
fn bezier_colour_keys_carry_the_distance_to_the_next_key() {
// 307: Fill Color keys t=0 [1,0,0,1] and t=2 [0,0,1,1], both bezier; ease 0/0; f64@16 = the
// ARGB distance 255 sqrt(2) = 360.6245 on key 1 and 0 on the last key. The linear keys of 210 have 0.
skip!(with_layer("307-key-fillcolor-bezier.aep", L, |project, layer| {
let p = project.effect_params(&layer.effects()[0]).into_iter().find(|p| p.name == "Color").unwrap();
let keys: Vec<_> = p.stored().unwrap().keys().unwrap().keyframes().collect();
assert_eq!(keys.len(), 2);
assert_eq!(keys[0].kind(), KeyframeKind::Spatial { components: 4 });
assert_near(&keys[0].value().unwrap(), &[255.0, 255.0, 0.0, 0.0], 1e-9);
assert_near(&keys[1].value().unwrap(), &[255.0, 0.0, 0.0, 255.0], 1e-9);
for k in &keys {
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)));
}
let distance = |k: &craft_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.spatial().unwrap().segment_length, 0.0);
}));
}
// ------------------------------------------------------------------ time stretch and in / out points (316-318, 351, 353)
fn stretch_facts(name: &str) -> Option<(LayerHeader, Option<Rational>, Option<Rational>, u32)> {
Some({
with_layer(name, L, |_, layer| {
let h = layer.header().unwrap();
let Some(PropNode::Property(p)) = layer.properties().unwrap().get("ADBE Time Remapping") else { panic!("no time remap property") };
(h.clone(), h.in_point(), h.out_point(), p.time_scale().unwrap())
})?
})
}
#[test]
fn time_stretch_is_an_exact_ratio() {
// 316: stretch 100 -> 50 %: 1/2; the stored out point stays 5 s, the layer ends at 2.5 s; the
// property time scale stays 25600.
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.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!((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_ratio()), (1, 1, Some(rat(1, 1))));
assert_eq!((out_p, scale), (Some(rat(5, 1)), 25600));
}
#[test]
fn fractional_times_are_exact_multiples_of_one_over_25600() {
// 318: inPoint 0.3333 s became 8532/25600 = 0.33328125 s; the out point moved with it (duration
// kept): 136532/25600 = 5.33328125 s; start stays 0.
let h = skip!(header("318-layer-inpoint-0.3333.aep"));
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.out_point(), Some(rat(34133, 6400)));
assert_eq!(h.stretch_ratio(), Some(rat(1, 1)));
}
#[test]
fn footage_layers_use_the_footage_time_base_as_out_point_denominator() {
// 351: the audio layer's out point is 48000/48000 (the sample rate as denominator), start and
// in point keep 25600; the layer copies the item's label 7 and shows the item's name.
let bytes = fixture!("351-footage-wav-as-layer.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = comp.layers().find(|l| project.layer_source(l).and_then(|s| s.footage()).is_some_and(|f| f.file_type == "WAVE")).unwrap();
let h = layer.header().unwrap();
assert_eq!(h.out_relative, rat(48000, 48000));
assert_eq!((h.start.den, h.in_relative.den), (25600, 25600));
assert_eq!(h.out_point(), Some(rat(1, 1)));
// The source is the WAV item (item id 0x20 in the single-case file).
assert_eq!(h.label, 7);
assert!(layer.name().is_none());
assert!(h.is_video_enabled(), "the video switch stays set on an audio-only layer (flag byte 39 = 07)");
// 354: the image sequence layer: out point 3/30 = 0.1 s (the frame rate as denominator), label 3,
// the layer has no name of its own and shows the first file name.
let bytes = fixture!("354-footage-pngseq-timeremap.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = layer_shown_as(&project, &comp, "seq_001.png");
let h = layer.header().unwrap();
assert_eq!(h.out_relative, rat(3, 30));
assert_eq!(h.out_point(), Some(rat(1, 10)));
assert_eq!((h.label, h.start.den), (3, 25600));
// The source is the sequence item (item id 0x22 in the single-case file).
assert!(project.layer_source(&layer).and_then(|s| s.footage()).is_some_and(|f| f.is_sequence));
}
// ------------------------------------------------------------------ Time Remapping (319, 354)
#[test]
fn time_remapping_is_an_inert_property_until_enabled() {
// Every layer has an inert ADBE Time Remapping property (tdsb 3, static 0, no keys).
skip!(with_layer("000-base.aep", L, |_, layer| {
let t = layer.time_remap().unwrap();
assert!(!t.enabled && t.keys.is_empty());
let Some(PropNode::Property(p)) = layer.properties().unwrap().get("ADBE Time Remapping") else { panic!() };
assert_eq!((p.flags(), p.is_animated(), p.static_value()), (Some(3), false, Some(vec![0.0])));
}));
// 319: the precomp layer `Pre` with the remap on: keyed (tdsb 1), two keys 0 s -> 0 and 5 s -> 5;
// the layer inside Pre and the other layers stay inert.
let bytes = fixture!("319-precomp-timeremap.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = layer_shown_as(&project, &comp, "Pre");
let t = layer.time_remap().unwrap();
assert!(t.enabled);
assert_eq!(t.keys.len(), 2);
assert_eq!((t.keys[0].time_seconds, t.keys[0].value_seconds), (Some(0.0), 0.0));
assert_eq!((t.keys[1].time_seconds, t.keys[1].value_seconds), (Some(5.0), 5.0));
assert_eq!(t.keys[1].time_units, 128000);
let Some(PropNode::Property(p)) = layer.properties().unwrap().get("ADBE Time Remapping") else { panic!() };
assert_eq!((p.flags(), p.is_animated(), p.static_value()), (Some(1), true, None));
let pre = project.all_items().into_iter().find(|i| i.name().as_deref() == Some("Pre")).unwrap().comp().unwrap();
assert!(pre.layers().all(|l| !l.time_remap().unwrap().enabled));
// 354: on a footage layer: keys 0 s -> 0 and 0.1 s -> 0.1.
let bytes = fixture!("354-footage-pngseq-timeremap.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = layer_shown_as(&project, &comp, "seq_001.png");
let t = layer.time_remap().unwrap();
assert!(t.enabled);
assert_eq!(t.keys.len(), 2);
assert_eq!((t.keys[0].time_units, t.keys[0].value_seconds), (0, 0.0));
assert!(near(t.keys[1].time_seconds.unwrap(), 0.1, 1e-6) && near(t.keys[1].value_seconds, 0.1, 1e-6), "{t:?}");
assert!(!base_layer(&comp).time_remap().unwrap().enabled);
}
// ------------------------------------------------------------------ composition (325-327)
fn comp_header(name: &str) -> Option<craft_aep::CompHeader> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
first_comp(&Project::new(&file).unwrap()).header().unwrap()
})
}
#[test]
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)));
// 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.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.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 = craft_aep::CompHeader::parse(&bytes).unwrap();
assert_eq!((h.shutter_phase, h.display_start.map(|r| r.den)), (None, Some(0)));
}
@@ -0,0 +1,487 @@
//! Batch 3 (objects): Point / Layer / Dropdown controls, masks, shape items, text styles, camera,
//! light, marker data and footage items. Every expected value is the value the corpus case was
//! made with (its MANIFEST).
use crate::container::helpers::{assert_near, base_layer, first_comp, layer_named, layer_of_type, layer_shown_as, near, open};
use craft_aep::{
Caps, CueType, GradientType, ItemKind, Justification, LayerRef, LayerType, MaskMode, ParamKind, ParamValue, PolystarType, Project, PropNode,
Rational, ShapeDetail, ShapeItem, TextDocument, ValueSource,
};
fn rat(num: i64, den: i64) -> Rational {
Rational { num, den }
}
// ------------------------------------------------------------------ Point control (310, 218)
#[test]
fn the_point_default_is_a_fraction_of_the_layer() {
// 310: the default Point of a Point Control on a 100x100 solid reads back [50, 50]: the default is
// two 16.16 fractions 0.5 in pard, relative to the layer, not pixels.
let bytes = fixture!("310-solid-100x100-pointcontrol.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = layer_shown_as(&project, &comp, "S100");
assert_eq!(project.layer_source_size(&layer), Some((100, 100)));
let effects = layer.effects();
assert_eq!(effects.len(), 1);
let p = effects[0].params().into_iter().find(|p| p.kind == ParamKind::Point).unwrap();
assert!(p.stored().is_none());
assert_eq!(p.pard_default(), Some(ParamValue::Point([0.5, 0.5])));
assert_eq!((p.value(), p.is_default()), (Some(ParamValue::Point([0.5, 0.5])), Some(true)));
assert_eq!(p.point_px(100.0, 100.0), Some([50.0, 50.0]));
assert_eq!(&p.pard()[56..64], &[0, 0, 0x80, 0, 0, 0, 0x80, 0], "two 16.16 fractions 0.5");
// 218: an explicit [111, 222] on the 1920x1080 solid is [111/1920, 222/1080] of the layer.
let bytes = fixture!("218-fx-point-111-222.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = base_layer(&first_comp(&project));
let p = layer.effects()[0].params().into_iter().find(|p| p.kind == ParamKind::Point).unwrap();
assert_eq!(p.is_default(), Some(false));
let px = p.point_px(1920.0, 1080.0).unwrap();
assert_near(&px, &[111.0, 222.0], 1e-9);
assert!(p.point_px(f64::NAN, 1.0).is_some());
let other = layer.effects()[0].params().into_iter().find(|p| p.kind == ParamKind::Layer).unwrap();
assert_eq!(other.point_px(1.0, 1.0), None);
}
// ------------------------------------------------------------------ Layer Control (320, 321, 220)
/// The Layer Control's reference, the input layer's stored value and reference, the id of `L`
/// (the owner) and the id of the top layer.
#[allow(clippy::type_complexity)]
fn layer_ref(name: &str) -> Option<(Option<LayerRef>, Option<ParamValue>, Option<LayerRef>, u32, u32)> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = base_layer(&comp);
let owner = layer.id().unwrap();
let effects = layer.effects();
assert_eq!(effects.len(), 1, "{name}");
assert_eq!(effects[0].match_name(), "ADBE Layer Control");
let params = project.effect_params(&effects[0]);
let p = params.iter().find(|p| p.kind == ParamKind::Layer && p.index == 1).unwrap();
// The implicit input layer is not a layer reference.
(p.layer_ref(owner), params[0].stored_value(), params[0].layer_ref(owner), owner, comp.layers().next().unwrap().id().unwrap())
})
}
#[test]
fn layer_control_self_versus_none() {
// 320: Layer set explicitly to 1 = the layer itself: tdpi = the owning layer's id.
let (r, input, input_ref, owner, _) = skip!(layer_ref("320-fx-layercontrol-self-explicit.aep"));
assert_eq!((r, input, input_ref), (Some(LayerRef::This), Some(ParamValue::Layer(owner)), None));
// 321: None: tdpi = 0.
let (r, input, input_ref, owner, _) = skip!(layer_ref("321-fx-layercontrol-none.aep"));
assert_eq!((r, input, input_ref), (Some(LayerRef::Nothing), Some(ParamValue::Layer(owner)), None));
// 220: Layer 1 of a new Null layer (the top layer).
let (r, _, _, owner, top) = skip!(layer_ref("220-fx-layercontrol-to-layer1.aep"));
assert_ne!(top, owner);
assert_eq!(r, Some(LayerRef::Layer(top)));
}
// ------------------------------------------------------------------ Dropdown (323, 324, 077)
#[test]
fn dropdown_items_selection_and_count() {
for (name, selected, text, is_default) in
[("323-fx-dropdown-5items.aep", 1, "Alpha", Some(true)), ("324-fx-dropdown-5items-select3.aep", 3, "Gamma", Some(false))]
{
let bytes = fixture!(name);
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = base_layer(&first_comp(&project));
let effects = layer.effects();
assert_eq!(effects.len(), 1);
// set_dropdown_items re-creates the effect definition under a new match name.
assert!(effects[0].match_name().starts_with("Pseudo/@@") && effects[0].match_name().len() == 31, "{name}");
assert_eq!(effects[0].name().as_deref(), Some("Dropdown Menu Control"));
let p = effects[0].params().into_iter().find(|p| p.kind == ParamKind::Popup).unwrap();
assert_eq!(p.items.as_deref(), Some(&["Alpha", "Beta", "Gamma", "Delta", "Epsilon"].map(String::from)[..]), "{name}");
assert_eq!(p.popup_item_count(), Some(5), "{name}");
assert_eq!((p.popup_selected_index(), p.popup_selected_item()), (Some(selected), Some(text)), "{name}");
assert_eq!(p.is_default(), is_default, "{name}");
assert_eq!(p.stored().is_some(), selected != 1, "{name}");
if selected == 3 {
// The selection is a value record and also overwrites pard@56.
assert_eq!(p.stored_value(), Some(ParamValue::Index(3)));
assert_eq!(p.pard_default(), Some(ParamValue::Index(3)));
} else {
assert_eq!(p.stored_value(), None);
assert_eq!(p.pard_default(), Some(ParamValue::Index(1)));
}
}
// 077: the default dropdown with three items.
let bytes = fixture!("077-fx-dropdown-default.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = base_layer(&first_comp(&project));
let p = layer.effects()[0].params().into_iter().find(|p| p.kind == ParamKind::Popup).unwrap();
assert_eq!((p.popup_item_count(), p.popup_selected_item()), (Some(3), Some("Item 1")));
let no_data = layer.effects()[0].params().into_iter().find(|p| p.kind == ParamKind::NoData).unwrap();
assert_eq!((no_data.popup_item_count(), no_data.popup_selected_index(), no_data.popup_selected_item()), (None, None, None));
}
// ------------------------------------------------------------------ masks (309, 328, 329)
fn ellipse_vertices() -> [[f64; 2]; 4] {
[[960.0, 340.0], [1360.0, 540.0], [960.0, 740.0], [560.0, 540.0]]
}
#[test]
fn a_mask_box_is_normalised_to_the_layer_size() {
// 309: a 60x40 rectangle at [50,50] on a 100x100 solid: box 0.2, 0.3, 0.8, 0.7 of the LAYER;
// vertices [20,30] [80,30] [80,70] [20,70].
let bytes = fixture!("309-solid-100x100-mask-rect.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let comp = first_comp(&project);
let layer = layer_shown_as(&project, &comp, "S100");
let masks = layer.masks();
assert_eq!(masks.len(), 1);
let m = &masks[0];
assert_eq!((m.mode, m.inverted, m.counter), (Some(MaskMode::Add), Some(false), Some(1)));
let want_box = [0.2, 0.3, 0.8, 0.7];
for (got, want) in m.shapes[0].bbox.iter().zip(want_box) {
assert!(near(f64::from(*got), want, 1e-6), "{:?}", m.shapes[0].bbox);
}
// 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 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.layer_source_size(&shape).is_none());
}
#[test]
fn one_mkif_per_mask_and_the_mode_none() {
// 328: ellipse 800x400 at [960,540] (Mask 1) and rectangle 400x300 at [700,500] (Mask 2), both Add;
// the per-layer counter gives 1 and 2.
let bytes = fixture!("328-mask-two-ellipse-rect.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = base_layer(&first_comp(&project));
let masks = layer.masks();
assert_eq!(masks.len(), 2);
assert_eq!(masks.iter().map(|m| m.name.as_deref()).collect::<Vec<_>>(), [Some("Mask 1"), Some("Mask 2")]);
for (m, counter) in masks.iter().zip([1, 2]) {
assert_eq!((m.mode, m.inverted, m.counter), (Some(MaskMode::Add), Some(false), Some(counter)));
assert_eq!(m.shapes.len(), 1);
}
let (w, h) = project.layer_source_size(&layer).unwrap();
let px = |m: &craft_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 = 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);
}
assert_eq!(v2[0].len(), 4);
// 329: the same ellipse as 232 with the mode None (0). The layer's mask counter is 1: the case is the first mask on its layer.
let bytes = fixture!("329-mask-ellipse-mode-none.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let none = base_layer(&first_comp(&project)).masks();
assert_eq!(none.len(), 1);
assert_eq!((none[0].mode, none[0].counter), (Some(MaskMode::None), Some(1)));
assert_eq!(MaskMode::from_id(0), MaskMode::None);
let bytes = fixture!("232-mask-ellipse.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let add = base_layer(&first_comp(&project)).masks();
assert_eq!(add[0].mode, Some(MaskMode::Add));
assert_eq!(add[0].shapes, none[0].shapes, "329 is 232 with another mode");
}
// ------------------------------------------------------------------ shapes (330-333)
fn shape_group(name: &str) -> Option<craft_aep::ShapeGroup> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = layer_named(&first_comp(&project), "Shape");
let h = layer.header().unwrap();
assert_eq!((h.layer_type, h.label), (LayerType::Shape, 8), "{name}");
let mut groups = layer.shape_groups();
assert_eq!(groups.len(), 1, "{name}");
groups.remove(0)
})
}
fn other_name(item: &ShapeItem) -> &str {
match item {
ShapeItem::Other { match_name, .. } => match_name,
_ => "",
}
}
#[test]
fn polystar_defaults_and_polygon() {
// 330: star, 5 points, outer 100, inner 50 = the defaults: no property record at all.
let g = skip!(shape_group("330-shape-polystar-star-5-50-100.aep"));
assert_eq!(g.name.as_deref(), Some("Group 1"));
assert_eq!(g.items.len(), 2);
assert_eq!(other_name(&g.items[0]), "ADBE Vector Shape - Star");
assert!(matches!(&g.items[1], ShapeItem::Fill { color: Some(c), .. } if c.value == [1.0, 0.0, 1.0, 0.0]));
let [ShapeDetail::Polystar { item_index, star_type, outer_radius, inner_radius, inner_roundness }] = &g.details[..] else {
panic!("{:?}", g.details)
};
assert_eq!(*item_index, 0);
assert_eq!((star_type.value, star_type.source), (PolystarType::Star, ValueSource::Default));
assert_eq!((outer_radius.value, outer_radius.source), (100.0, ValueSource::Default));
assert_eq!((inner_radius.value, inner_radius.source), (50.0, ValueSource::Default));
assert!(inner_roundness.is_none());
// 331: polygon (type 2): the type record, plus Inner Radius 50 and Inner Roundess 0 in their default state.
let g = skip!(shape_group("331-shape-polystar-polygon-5-100.aep"));
let [ShapeDetail::Polystar { star_type, outer_radius, inner_radius, inner_roundness, .. }] = &g.details[..] else { panic!("{:?}", g.details) };
assert_eq!((star_type.value, star_type.source), (PolystarType::Polygon, ValueSource::Stored));
assert_eq!((outer_radius.value, outer_radius.source), (100.0, ValueSource::Default));
assert_eq!((inner_radius.value, inner_radius.source), (50.0, ValueSource::Stored));
let r = inner_roundness.unwrap();
assert_eq!((r.value, r.source), (0.0, ValueSource::Stored));
// The tdsb states: the type is a written record (1), the other two are default-state records (3).
let bytes = fixture!("331-shape-polystar-polygon-5-100.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = layer_named(&first_comp(&project), "Shape");
let base = ["ADBE Root Vectors Group", "ADBE Vector Group", "ADBE Vectors Group", "ADBE Vector Shape - Star"];
for (prop, flags) in [("ADBE Vector Star Type", 1), ("ADBE Vector Star Inner Radius", 3), ("ADBE Vector Star Inner Roundess", 3)] {
let path: Vec<&str> = base.iter().copied().chain([prop]).collect();
let Some(PropNode::Property(p)) = layer.properties().unwrap().find(&path) else { panic!("{prop}") };
assert_eq!(p.flags(), Some(flags), "{prop}");
}
}
#[test]
fn radial_gradient_extra_records() {
// 332: Rectangle Path 400x300 + Gradient Fill, radial (type 2), Start [0,0] = default (absent),
// End [200,0], Highlight Length / Angle 0 written as records.
let g = skip!(shape_group("332-shape-gradient-fill-radial.aep"));
assert_eq!(g.items.len(), 2);
let ShapeItem::GradientFill { start, end, .. } = &g.items[1] else { panic!("{:?}", g.items[1]) };
assert!(start.is_none());
assert_eq!(end.map(|e| (e.value, e.source)), Some(([200.0, 0.0], ValueSource::Stored)));
let gradient = g.details.iter().find_map(|d| match d {
ShapeDetail::Gradient { item_index, gradient_type, highlight_length, highlight_angle } => {
Some((*item_index, *gradient_type, *highlight_length, *highlight_angle))
}
_ => None,
});
let (index, kind, length, angle) = gradient.unwrap();
assert_eq!(index, 1);
assert_eq!((kind.value, kind.source), (GradientType::Radial, ValueSource::Stored));
assert_eq!(length.map(|t| (t.value, t.source)), Some((0.0, ValueSource::Stored)));
assert_eq!(angle.map(|t| (t.value, t.source)), Some((0.0, ValueSource::Stored)));
// 241 (linear): the type is the default and the highlight records are absent.
let bytes = fixture!("241-shape-gradient-fill-linear.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let layer = layer_named(&first_comp(&project), "S");
let g = layer.shape_groups().remove(0);
let linear = g.details.iter().find_map(|d| match d {
ShapeDetail::Gradient { gradient_type, highlight_length, highlight_angle, .. } => Some((*gradient_type, *highlight_length, *highlight_angle)),
_ => None,
});
let (kind, length, angle) = linear.unwrap();
assert_eq!((kind.value, kind.source), (GradientType::Linear, ValueSource::Default));
assert!(length.is_none() && angle.is_none());
}
#[test]
fn two_rectangles_in_one_group_are_two_items() {
// 333: Rectangle Path 1 [400,300], Rectangle Path 2 [100,100] (= default, no Size record) at
// position [300,0], Fill 1 (order: rect, rect, fill).
let g = skip!(shape_group("333-shape-group-two-rects.aep"));
assert_eq!(g.items.len(), 3);
let ShapeItem::Rect { name: n1, size: s1 } = &g.items[0] else { panic!() };
let ShapeItem::Rect { name: n2, size: s2 } = &g.items[1] else { panic!() };
assert_eq!((n1.as_deref(), n2.as_deref()), (Some("Rectangle Path 1"), Some("Rectangle Path 2")));
assert_eq!(s1.map(|s| s.value), Some([400.0, 300.0]));
assert!(s2.is_none(), "[100, 100] is the default size");
assert!(matches!(&g.items[2], ShapeItem::Fill { color: Some(c), .. } if c.value == [1.0, 0.0, 1.0, 0.0]));
let positions: Vec<_> = g
.details
.iter()
.filter_map(|d| match d {
ShapeDetail::RectPosition { item_index, position } => Some((*item_index, position.value, position.source)),
_ => None,
})
.collect();
assert_eq!(positions, [(0, [0.0, 0.0], ValueSource::Default), (1, [300.0, 0.0], ValueSource::Stored)]);
}
// ------------------------------------------------------------------ text (334-340)
fn text(name: &str, layer: &str) -> Option<TextDocument> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).unwrap();
layer_named(&first_comp(&project), layer).text_document().unwrap_or_else(|| panic!("{name}: no text document"))
})
}
#[test]
fn right_justification_in_box_text() {
// 334: box text "Hello" in a 400x200 box at [-200,-100], right aligned (stored 1; compare 245: 0, 246: 2).
let t = skip!(text("334-text-box-right-align.aep", "T"));
assert_eq!(t.text, "Hello");
assert_eq!((t.paragraphs.len(), t.paragraphs[0].length, t.paragraphs[0].justification), (1, 6, Justification::Right));
let b = t.text_box.unwrap();
assert_eq!((b.x, b.y, b.width, b.height), (-200.0, -100.0, 400.0, 200.0));
assert_eq!(skip!(text("245-text-box-400x200-Hello.aep", "T")).paragraphs[0].justification, Justification::Left);
assert_eq!(skip!(text("246-text-box-center-align.aep", "T")).paragraphs[0].justification, Justification::Center);
}
#[test]
fn faux_styles_caps_and_leading() {
// The reference style: no faux styles, normal caps, auto leading (stored 98), the font list of four.
let t = skip!(text("337-text-point-allcaps.aep", "T"));
assert_eq!(t.style_runs.len(), 1);
let plain = t.style_runs[0];
assert_eq!((plain.faux_bold, plain.faux_italic, plain.leading, plain.font_index), (false, false, Some(98.0), 0));
assert_eq!((plain.caps, t.fonts.len()), (Caps::All, 4));
// 335 / 336: faux bold / italic; the font list gains a first entry (4 -> 5) and the style uses font 1.
for (name, bold, italic) in [("335-text-point-fauxbold.aep", true, false), ("336-text-point-fauxitalic.aep", false, true)] {
let t = skip!(text(name, "T"));
let s = t.style_runs[0];
assert_eq!((s.faux_bold, s.faux_italic, s.caps), (bold, italic, Caps::Normal), "{name}");
assert_eq!((t.fonts.len(), s.font_index, t.font_index), (5, 1, 1), "{name}");
assert_eq!((t.fonts[0].as_str(), t.fonts[1].as_str()), ("TimesNewRomanPSMT", "TimesNewRomanPSMT"), "{name}");
assert_eq!(t.font.as_deref(), Some("TimesNewRomanPSMT"));
}
// 338: small caps; 337: all caps.
assert_eq!(skip!(text("338-text-point-smallcaps.aep", "T")).style_runs[0].caps, Caps::Small);
// 339: leading 60.
let s = skip!(text("339-text-point-leading60.aep", "T")).style_runs[0];
assert_eq!((s.leading, s.caps, s.faux_bold), (Some(60.0), Caps::Normal, false));
}
#[test]
fn the_last_style_run_absorbs_the_final_carriage_return() {
// 340: "el" red, "lo" blue and size 60 on "Hello": runs of 1, 2 and 3 characters (the last one
// includes the \r), fills white / red / blue, sizes 100 / 100 / 60.
let t = skip!(text("340-text-range-two-styles.aep", "T"));
assert_eq!(t.raw_text, "Hello\r");
assert_eq!(t.style_runs.iter().map(|r| r.length).collect::<Vec<_>>(), [1, 2, 3]);
assert_eq!(t.style_runs.iter().map(|r| r.length).sum::<usize>(), t.raw_text.chars().count());
assert_eq!(t.style_runs.iter().map(|r| r.fill_argb).collect::<Vec<_>>(), [[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 0.0, 0.0], [1.0, 0.0, 0.0, 1.0]]);
assert_eq!(t.style_runs.iter().map(|r| r.font_size).collect::<Vec<_>>(), [100.0, 100.0, 60.0]);
assert_eq!(t.paragraphs.iter().map(|p| p.length).collect::<Vec<_>>(), [6]);
}
// ------------------------------------------------------------------ camera and light (341-345)
/// Camera zoom keeps the auto position.
#[test]
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::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)
fn layer_markers(name: &str) -> Option<Vec<craft_aep::Marker>> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).unwrap();
base_layer(&first_comp(&project)).markers()
})
}
#[test]
fn marker_label_cue_type_and_parameters() {
// 347: marker at 1 s, comment M, label 3 (event cue by default, no parameters).
let m = skip!(layer_markers("347-marker-layer-label3.aep"));
assert_eq!(m.len(), 1);
assert_eq!((m[0].seconds, m[0].comment.as_str(), m[0].label, m[0].cue_type), (Some(1.0), "M", Some(3), Some(CueType::Event)));
assert_eq!((m[0].duration_seconds, m[0].cue_point_name.as_str(), m[0].cue_params.len()), (Some(0.0), "", 0));
// 348: cue point name CueN, navigation cue (5).
let m = skip!(layer_markers("348-marker-layer-navigation-cue.aep"));
assert_eq!((m[0].cue_type, m[0].cue_point_name.as_str(), m[0].label), (Some(CueType::Navigation), "CueN", Some(0)));
// 349: CueE, event cue, parameters speaker = A and n = 2.
let m = skip!(layer_markers("349-marker-layer-event-cue-params.aep"));
assert_eq!((m[0].cue_type, m[0].cue_point_name.as_str(), m[0].comment.as_str()), (Some(CueType::Event), "CueE", "M"));
assert_eq!(m[0].cue_params, [("speaker".to_string(), "A".to_string()), ("n".to_string(), "2".to_string())]);
assert_eq!((m[0].chapter.as_str(), m[0].url.as_str(), m[0].frame_target.as_str()), ("", "", ""));
// 249 (batch 2): duration 1 s, the five strings, event cue, no parameters, label 0.
let m = skip!(layer_markers("249-marker-layer-full.aep"));
assert_eq!((m[0].cue_type, m[0].label, m[0].duration_seconds, m[0].cue_params.len()), (Some(CueType::Event), Some(0), Some(1.0), 0));
}
// ------------------------------------------------------------------ footage items (126, 350, 352, 354)
#[test]
fn audio_footage_item() {
let bytes = fixture!("350-footage-wav-imported.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
// The solid L and the WAV (item id 32 in the single-case file): the WAV is not used in a layer.
let footage: Vec<_> = project.all_items().into_iter().filter(|i| i.kind() == Some(ItemKind::Footage)).collect();
assert_eq!(footage.len(), 2);
let item = footage.iter().find(|i| i.footage().is_some_and(|f| !f.is_solid)).unwrap();
let f = item.footage().unwrap();
assert_eq!(f.file_type, "WAVE");
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 && 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));
assert!(f.path.as_deref().is_some_and(|p| p.ends_with("test-tone.wav")));
// The solid has no sample rate.
let solid = footage.iter().find(|i| i.footage().is_some_and(|f| f.is_solid)).unwrap().footage().unwrap();
assert_eq!((solid.audio_sample_rate, solid.duration.map(|d| d.num), solid.file_size), (None, Some(0), 0));
}
#[test]
fn image_sequence_is_one_item() {
for name in ["352-footage-pngseq-imported.aep", "354-footage-pngseq-timeremap.aep"] {
let bytes = fixture!(name);
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let footage: Vec<_> = project.all_items().into_iter().filter(|i| i.kind() == Some(ItemKind::Footage)).collect();
assert_eq!(footage.len(), 2, "{name}: the solid and ONE sequence item");
let item = footage.iter().find(|i| i.footage().is_some_and(|f| !f.is_solid)).unwrap();
let f = item.footage().unwrap();
assert_eq!((f.width, f.height, f.is_solid), (64, 64, false), "{name}");
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!(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}");
assert_eq!(item.label(), Some(3), "{name}");
}
// The single png still (126): 32 bits per pixel, 149 bytes, not a sequence, duration 0.
let bytes = fixture!("126-footage-png-layer.aep");
let file = open(&bytes);
let project = Project::new(&file).unwrap();
let f = project.all_items().into_iter().filter_map(|i| i.footage()).find(|f| !f.is_solid).unwrap();
assert_eq!((f.bits_per_pixel, f.file_size, f.native_frame_rate, f.is_sequence), (32, 149, 0, false));
assert_eq!(f.duration.map(|d| d.num), Some(0));
}
+170
View File
@@ -0,0 +1,170 @@
//! Batch 5 checks of fields decoded before (markers with several entries and fractional
//! durations, 509 and 510).
use crate::container::helpers::{first_comp, open};
use craft_aep::Project;
#[test]
fn two_composition_markers_in_time_order_with_label_and_duration() {
let bytes = fixture!("509-marker-comp-two.aep");
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let m = first_comp(&project).markers();
let got: Vec<_> = m.iter().map(|m| (m.time_units, m.comment.as_str(), m.duration_seconds, m.label)).collect();
assert_eq!(got, vec![(25_600, "M1", Some(0.0), Some(2)), (64_000, "M2", Some(0.5), Some(0))]);
}
#[test]
fn a_fractional_marker_time_and_duration() {
let bytes = fixture!("510-marker-layer-0.52-dur0.3.aep");
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let comp = first_comp(&project);
let layer = comp.layers().next().expect("L");
let m = layer.markers();
assert_eq!(m.len(), 1);
// 0.52 s = 13 312 / 25 600; 0.3 s = 180 / 600.
assert_eq!((m[0].time_units, m[0].comment.as_str()), (13_312, "LM"));
assert!((m[0].duration_seconds.expect("duration") - 0.3).abs() < 1e-12);
}
/// The stored value of the property at `path` (match names) of the first layer.
fn shape_value(name: &str, path: &[&str]) -> Option<Option<Vec<f64>>> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let comp = first_comp(&project);
let layer = comp.layers().next().expect("S");
match layer.properties()?.find(path)? {
craft_aep::PropNode::Property(p) => p.static_value(),
_ => None,
}
})
}
const G1: [&str; 2] = ["ADBE Root Vectors Group", "ADBE Vector Group"];
#[test]
fn shape_values_are_stored_as_shown() {
let at = |rest: &[&'static str]| -> Vec<&'static str> { G1.iter().chain(rest.iter()).copied().collect() };
assert_eq!(
skip!(shape_value(
"451-shape-ellipse-400x300-fill.aep",
&at(&["ADBE Vectors Group", "ADBE Vector Shape - Ellipse", "ADBE Vector Ellipse Size"])
)),
Some(vec![400.0, 300.0])
);
assert_eq!(
skip!(shape_value(
"451-shape-ellipse-400x300-fill.aep",
&at(&["ADBE Vectors Group", "ADBE Vector Graphic - Fill", "ADBE Vector Fill Color"])
)),
Some(vec![255.0, 0.0, 255.0, 0.0])
);
// Group scale in percent, not a fraction.
assert_eq!(
skip!(shape_value("457-shape-group-scale-50-80.aep", &at(&["ADBE Vector Transform Group", "ADBE Vector Scale"]))),
Some(vec![50.0, 80.0])
);
assert_eq!(
skip!(shape_value(
"464-shape-stroke-opacity-50.aep",
&at(&["ADBE Vectors Group", "ADBE Vector Graphic - Stroke", "ADBE Vector Stroke Opacity"])
)),
Some(vec![50.0])
);
assert_eq!(
skip!(shape_value("467-shape-trim-end-70.aep", &at(&["ADBE Vectors Group", "ADBE Vector Filter - Trim", "ADBE Vector Trim End"]))),
Some(vec![70.0])
);
assert_eq!(
skip!(shape_value("469-shape-trim-type-2.aep", &at(&["ADBE Vectors Group", "ADBE Vector Filter - Trim", "ADBE Vector Trim Type"]))),
Some(vec![2.0])
);
assert_eq!(
skip!(shape_value("471-shape-rect-roundness-30.aep", &at(&["ADBE Vectors Group", "ADBE Vector Shape - Rect", "ADBE Vector Rect Roundness"]))),
Some(vec![30.0])
);
assert_eq!(
skip!(shape_value("473-shape-star-points-6.aep", &at(&["ADBE Vectors Group", "ADBE Vector Shape - Star", "ADBE Vector Star Points"]))),
Some(vec![6.0])
);
// The shape layer's own anchor: pixels as stored.
assert_eq!(skip!(shape_value("462-shape-layer-anchor-10-20.aep", &["ADBE Transform Group", "ADBE Anchor Point"])), Some(vec![10.0, 20.0, 0.0]));
// A new Trim Paths and every default item of 519 have no record.
for item in [
"ADBE Vector Shape - Rect",
"ADBE Vector Shape - Ellipse",
"ADBE Vector Shape - Star",
"ADBE Vector Graphic - Fill",
"ADBE Vector Filter - Trim",
] {
let bytes = fixture!("519-shape-all-items-default.aep");
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let comp = first_comp(&project);
let layer = comp.layers().next().expect("S");
let Some(craft_aep::PropNode::Group(g)) = layer.properties().and_then(|p| p.find(&at(&["ADBE Vectors Group", item]))) else {
panic!("{item}")
};
assert!(g.entries().iter().all(|e| !matches!(e.node, craft_aep::PropNode::Property(p) if p.flags() == Some(1))), "{item} has a value record");
}
}
/// The baseline option of the first style run of the first text layer.
fn script_of(name: &str) -> Option<craft_aep::FontBaseline> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let comp = first_comp(&project);
let layer = comp.layers().find(|l| l.text_document().is_some()).expect("a text layer");
let doc = layer.text_document().expect("document");
assert!(doc.undecoded_style_fields.is_empty(), "{name}: {:?}", doc.undecoded_style_fields);
doc.style_runs.first().expect("a run").baseline
})
}
#[test]
fn superscript_and_subscript_are_style_slot_13() {
use craft_aep::FontBaseline;
// The character state the corpus was made in is superscript (526, and 243, 517).
assert_eq!(skip!(script_of("526-text-point-HHHH-default.aep")), FontBaseline::Superscript);
assert_eq!(skip!(script_of("243-text-multiline-A-CR-B.aep")), FontBaseline::Superscript);
assert_eq!(skip!(script_of("527-text-point-HHHH-baseline-normal.aep")), FontBaseline::Normal);
assert_eq!(skip!(script_of("528-text-point-HHHH-baseline-subscript.aep")), FontBaseline::Subscript);
}
#[test]
fn a_wrapping_box_text() {
let bytes = fixture!("517-text-box-600x400-wrap.aep");
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let comp = first_comp(&project);
let doc = comp.layers().find_map(|l| l.text_document()).expect("text");
let b = doc.text_box.expect("box text");
assert_eq!((b.x, b.y, b.width, b.height), (-300.0, -200.0, 600.0, 400.0));
assert_eq!(doc.raw_text, "The quick brown fox jumps over the lazy dog and keeps running far away\r");
assert_eq!(doc.style_runs[0].font_size, 100.0);
}
fn layer_l<T>(name: &str, f: impl Fn(&craft_aep::Layer<'_, '_>) -> T) -> Option<T> {
Some({
let bytes = crate::common::try_fixture(name)?;
let file = open(&bytes);
let project = Project::new(&file).expect("project");
let comp = first_comp(&project);
let layer = comp.layers().next().expect("the solid L, the only layer");
f(&layer)
})
}
#[test]
fn orientation_is_otst_otda() {
let o = skip!(layer_l("488-layer-3d-orientation-10-20-30.aep", |l| l.orientation())).expect("orientation");
assert_eq!((o.degrees, o.animated, o.has_expression), ([10.0, 20.0, 30.0], false, false));
for name in ["485-layer-3d-on.aep", "486-layer-3d-rotx-30.aep", "487-layer-3d-roty-45.aep"] {
assert_eq!(skip!(layer_l(name, |l| l.orientation())), None, "{name}: absent at the default");
}
}

Some files were not shown because too many files have changed in this diff Show More