mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge remote-tracking branch 'origin/main' into HEAD
# Conflicts: # crates/ui-egui/tests/it/variables_data_sets.rs
This commit is contained in:
commit
79db3f0acb
255 files changed
+5825
-2763
No files matched your search
@@ -33,6 +33,12 @@ test-group = 'gpu'
|
||||
fail-fast = false
|
||||
slow-timeout = { period = "60s", terminate-after = 10 }
|
||||
failure-output = "immediate-final"
|
||||
# The gate's shards run the tests from a nextest archive (`cargo xtask ci archive`) and start them
|
||||
# with the xtask binary the archive carries, so a shard builds nothing. Only one of the two exists.
|
||||
archive.include = [
|
||||
{ path = "debug/xtask", relative-to = "target", depth = 0, on-missing = "ignore" },
|
||||
{ path = "debug/xtask.exe", relative-to = "target", depth = 0, on-missing = "ignore" },
|
||||
]
|
||||
|
||||
# Keep phase timings for the remaining expensive Windows GPU regressions visible. This does
|
||||
# not relax their timeout, isolate failures differently or remove any test cases.
|
||||
|
||||
+87
-32
@@ -2,10 +2,14 @@ name: CI
|
||||
|
||||
# Quality gates for every push to main and every pull request. The Linux and Windows tests run
|
||||
# through the suite's shared gate workflow in craft-common-actions (`cargo xtask ci`, split over the
|
||||
# gate's jobs); the test variant and the corpus, web and fuzz jobs are PhotoCraft's own.
|
||||
# gate's jobs); the test variant and the corpus, web and fuzz jobs are PhotoCraft's own. Every night
|
||||
# the Linux gate alone runs a cold build: the safety net for the workspace crates it keeps between
|
||||
# runs (`cache-workspace-crates`), and a fresh start for that cache entry.
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "11 3 * * *"
|
||||
pull_request:
|
||||
# `labeled` so that adding `full-ci` to an open PR starts a run with Windows in it.
|
||||
types: [opened, synchronize, reopened, labeled]
|
||||
@@ -70,7 +74,7 @@ concurrency:
|
||||
jobs:
|
||||
# Git dependencies come from github.com/storytold, and Cargo.lock is complete and up to date.
|
||||
git-sources:
|
||||
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
|
||||
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
|
||||
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
|
||||
uses: storytold/craft-common-actions/.github/workflows/git-sources.yml@main
|
||||
|
||||
@@ -86,7 +90,7 @@ jobs:
|
||||
# `windows_skip`: the platform-neutral packages whose Windows tests a pull request skips because nothing it
|
||||
# changes reaches them (same script); empty on main and `full-ci`.
|
||||
platforms:
|
||||
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
|
||||
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
|
||||
timeout-minutes: 10
|
||||
name: select platforms
|
||||
runs-on: ubuntu-latest
|
||||
@@ -145,13 +149,17 @@ jobs:
|
||||
fi
|
||||
|
||||
# The Linux gate (craft-common-actions gate.yml). Its `lint` leg runs the checks that need no test
|
||||
# build; four test shards each build the tests from the restored cache and run their share
|
||||
# (scripts/ci-test-shard.sh). Shard 1 runs nextest's `gpu` group alone, on lavapipe, and fails on
|
||||
# a skipped GPU comparison (scripts/ci-gpu-lavapipe.py); shards 2-4 split the other tests, and
|
||||
# shard 2 runs the doctests. The `gpu` group is ~2400 test-seconds on 4 slots (~12 min with its
|
||||
# slowest test, ~8 once the five slow UI tests are fixed); the other ~5900 test-seconds over 3
|
||||
# shards are ~8 min each, so a fifth shard would not shorten the gate. Its rust-cache entry is
|
||||
# the one `test (without heif)` restores.
|
||||
# build. The `build` job builds the tests once into a nextest archive (`cargo xtask ci archive`),
|
||||
# uploads it and then runs the doctests; four test shards download the archive and run their
|
||||
# share (scripts/ci-test-shard.sh). Shard 1 runs nextest's `gpu` group alone, on lavapipe, and
|
||||
# fails on a skipped GPU comparison (scripts/ci-gpu-lavapipe.py); shards 2-4 split the other
|
||||
# tests. The `gpu` group is ~840 test-seconds on 4 slots (~3.5 min); the other ~6900
|
||||
# test-seconds over 3 shards are ~8.5-10.5 min each.
|
||||
# The build keeps the compiled workspace crates between runs (`cache-workspace-crates`), so a
|
||||
# pull request rebuilds only the crates its changes reach. Each main run's build job saves a
|
||||
# rolling entry of its own, which `test (without heif)` restores too; `gate-cache-prune` keeps
|
||||
# the newest one. The lint legs keep no cache (`lint-cache: false`): a cold lint leg costs
|
||||
# minutes, and their entries (~1 GB per OS) would not fit the 10 GB cache budget.
|
||||
gate:
|
||||
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
|
||||
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
|
||||
@@ -164,36 +172,39 @@ jobs:
|
||||
# The tests build with the optional craft-fonts input (crates/text/build.rs), so the
|
||||
# Japanese font tests that skip without it run. Same commit as release.yml.
|
||||
craft-fonts-ref: cc9269cd8d8258785dac603fba3122e5d2556795
|
||||
# Cargo.toml's dev profile already keeps line tables only.
|
||||
dev-debug: ""
|
||||
# CI test binaries carry no debuginfo and no symbols (CARGO_PROFILE_TEST_STRIP below): a
|
||||
# test build drops from ~19 to ~6.5 GB. A panic still names its file and line; only
|
||||
# backtrace frames lose names and lines. Local builds keep Cargo.toml's line tables.
|
||||
dev-debug: "0"
|
||||
cache-version: v2
|
||||
env: |
|
||||
PHOTOCRAFT_FULL_SWEEP=${{ inputs.full_sweep && '1' || '0' }}
|
||||
PHOTOCRAFT_NO_PRINT=1
|
||||
LPDEST=photocraft-no-such-printer
|
||||
CARGO_PROFILE_TEST_STRIP=symbols
|
||||
timeout-minutes: 100
|
||||
# On main, a `cache warm` leg builds xtask and the tests, as each shard does, and saves the
|
||||
# dependency cache as soon as the build succeeds; the shards then only restore, so a failing
|
||||
# test cannot keep the entry from being saved (craft-common-actions#270). The lint leg keeps
|
||||
# its own entry.
|
||||
warm-command: cargo xtask ci build
|
||||
cache-workspace-crates: true
|
||||
lint-cache: false
|
||||
cold-build: ${{ github.event_name == 'schedule' }}
|
||||
# fmt, egui-fork, clippy, layers, panel-commands, scorecard, the wasm32 check and the
|
||||
# missing-translations report (`cargo xtask ci lint`, xtask/src/main.rs), and the CI scripts'
|
||||
# own tests.
|
||||
lint-command: python3 scripts/test-ci-gpu-lavapipe.py && python3 scripts/test-ci-windows-gpu-tests.py && cargo xtask ci lint
|
||||
archive-command: cargo xtask ci archive
|
||||
after-archive-command: cargo xtask ci doctest
|
||||
test-shards: 4
|
||||
# The tests and panic_hunt with `--locked --features heif` (TEST_TARGETS in xtask/src/main.rs).
|
||||
shard-command: bash scripts/ci-test-shard.sh --gpu-shard
|
||||
|
||||
# The Windows tests and Clippy on the same gate, when `platforms` says the run needs them: a
|
||||
# `lint` leg runs Clippy, and six shards each build the tests and run their hash partition;
|
||||
# shard 1 also runs the doctests. Windows runs the tests ~1.75x slower than Linux: ~55 min on
|
||||
# one runner, ~9 min per shard. A seventh shard would not shorten the slowest one while its
|
||||
# slowest test alone takes ~9.6 min (the shortcut-dispatch UI test). The browser apps are wasm
|
||||
# targets, so their native tests are left out;
|
||||
# pull requests also leave out photocraft-gpu and the platform-neutral packages nothing they change
|
||||
# reaches (`windows_gpu`, `windows_skip`). The `cache warm` leg (main only) builds what main's
|
||||
# build job builds.
|
||||
# `lint` leg runs Clippy, the `build` job builds the tests once into a nextest archive and then
|
||||
# runs the doctests, and six shards run their slice of the tests from the archive. Windows runs
|
||||
# the tests ~1.75x slower than Linux: ~55 min on one runner, ~9 min per shard. A seventh shard
|
||||
# would not shorten the slowest one while its slowest test alone takes ~9.6 min (the
|
||||
# shortcut-dispatch UI test). The browser apps are wasm targets, so their native tests are left
|
||||
# out; pull requests also leave out photocraft-gpu and the platform-neutral packages nothing they
|
||||
# change reaches (`windows_gpu`, `windows_skip`). Windows keeps a dependency-only cache entry:
|
||||
# its workspace crates would not fit the repository's cache budget beside Linux's.
|
||||
windows:
|
||||
needs: platforms
|
||||
if: needs.platforms.outputs.windows == 'true'
|
||||
@@ -201,6 +212,7 @@ jobs:
|
||||
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
|
||||
with:
|
||||
os: '["windows-latest"]'
|
||||
lint-cache: false
|
||||
# The all-language UI tests shape real Japanese, Chinese, Korean and Devanagari labels with
|
||||
# kittest's strict `MissingGlyphPolicy::Panic`, and a hosted Windows image has no guaranteed
|
||||
# Japanese or Simplified Chinese system font. Same pinned central fonts as Linux and release.
|
||||
@@ -226,17 +238,57 @@ jobs:
|
||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS=-Clink-arg=/OPT:NOICF -Clink-arg=/DEBUG:NONE
|
||||
PHOTOCRAFT_CI_EXCLUDE=photocraft-web photocraft-web-boot ${{ needs.platforms.outputs.windows_gpu == 'false' && 'photocraft-gpu' || '' }} ${{ needs.platforms.outputs.windows_skip }}
|
||||
timeout-minutes: 100
|
||||
warm-command: cargo xtask ci build
|
||||
lint-command: cargo xtask ci clippy
|
||||
archive-command: cargo xtask ci archive
|
||||
after-archive-command: cargo xtask ci doctest
|
||||
test-shards: 6
|
||||
shard-command: bash scripts/ci-test-shard.sh
|
||||
|
||||
# The Linux gate's build job saves a rolling cache entry of its own on every main and nightly run
|
||||
# (`cache-workspace-crates`), about 3.8 GB, and every run restores only the newest. This deletes
|
||||
# the older ones at once instead of leaving them to the 10 GB budget's eviction, which would
|
||||
# evict other entries too.
|
||||
gate-cache-prune:
|
||||
needs: gate
|
||||
if: ${{ !cancelled() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
|
||||
timeout-minutes: 5
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
- name: Delete all but the newest rolling entry of each job and runner
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# `<version>-rust-<profile>-<job>-crates-<os>-<arch>-<run>-<attempt>-...`, newest first.
|
||||
gh cache list --repo "$REPO" --ref refs/heads/main --limit 100 --sort created_at --order desc --json id,key \
|
||||
--jq '.[] | "\(.id) \(.key)"' > "$RUNNER_TEMP/caches"
|
||||
declare -A kept
|
||||
while read -r id key; do
|
||||
[[ "$key" =~ ^.+-rust-[0-9a-f]{64}-(.+-crates-[A-Za-z_]+-[a-z0-9]+)-[0-9]+-[0-9]+- ]] || continue
|
||||
entry=${BASH_REMATCH[1]}
|
||||
if [ -n "${kept[$entry]:-}" ]; then
|
||||
echo "delete $key"
|
||||
gh cache delete "$id" --repo "$REPO"
|
||||
else
|
||||
kept[$entry]=1
|
||||
echo "keep $key"
|
||||
fi
|
||||
done < "$RUNNER_TEMP/caches"
|
||||
|
||||
# The same codecs without the optional decoder: HEIC must stay a clear "not in this build" error
|
||||
# for distributors who leave it out. Runs beside the gate and restores the gate's dependency
|
||||
# cache without saving one: the dependencies are the same, and the 10 GB cache budget is tight
|
||||
# (#2688).
|
||||
# for distributors who leave it out. Runs beside the gate and restores the gate's newest rolling
|
||||
# cache entry without saving one: the dependencies are the same, and the 10 GB cache budget is
|
||||
# tight (#2688). Its sources keep their checkout mtimes, so the workspace crates it builds are
|
||||
# rebuilt.
|
||||
test-without-heif:
|
||||
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
|
||||
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
|
||||
timeout-minutes: 60
|
||||
name: test (without heif)
|
||||
# The gate's runner: its cache entry is keyed on the OS.
|
||||
@@ -245,6 +297,8 @@ jobs:
|
||||
# The gate sets these; rust-cache hashes CARGO_* and RUST* variables into its key.
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
CARGO_PROFILE_DEV_DEBUG: "0"
|
||||
CARGO_PROFILE_TEST_STRIP: symbols
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
@@ -272,11 +326,12 @@ jobs:
|
||||
|
||||
# The gate's own key (the shared action computes it), restore only. The toolchain action
|
||||
# exports CARGO_HOME, which the gate's legs do not have; align-environment leaves it out of
|
||||
# the key.
|
||||
# the cache paths.
|
||||
- uses: storytold/craft-common-actions/actions/rust-cache@main
|
||||
with:
|
||||
cache-version: v2
|
||||
job: gate
|
||||
cache-workspace-crates: "true"
|
||||
align-environment: "true"
|
||||
|
||||
- uses: step-security/taiki-e-install-action@76747d22a7567cc4438546a84f11bdf18e670ab8 # v2.87.32
|
||||
@@ -287,7 +342,7 @@ jobs:
|
||||
run: cargo nextest run -p photocraft-io --locked --profile ci
|
||||
|
||||
corpus:
|
||||
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
|
||||
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
|
||||
timeout-minutes: 30
|
||||
# Real-file corpus tests (cargo feature `corpus`), on every PR and on main. The corpora are
|
||||
# pinned in xtask/src/corpus_pins.rs and sha256-verified (xtask/*.sha256) after both a cache
|
||||
|
||||
@@ -21,4 +21,6 @@ jobs:
|
||||
with:
|
||||
timeout-minutes: 120
|
||||
fonts-ref: cc9269cd8d8258785dac603fba3122e5d2556795
|
||||
# The coverage build's ~1.3 GB cache would not fit the repository's 10 GB cache budget.
|
||||
build-cache: false
|
||||
secrets: inherit
|
||||
Generated
+223
-115
@@ -1365,7 +1365,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-automation",
|
||||
"craft-behavior",
|
||||
@@ -1404,7 +1404,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-affinity"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
@@ -1425,7 +1425,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-atomic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"rustix 1.1.5",
|
||||
]
|
||||
@@ -1433,7 +1433,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-automation"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"craft-ai-agents",
|
||||
@@ -1459,7 +1459,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-behavior"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"bitflags 2.13.2",
|
||||
@@ -1475,7 +1475,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-browse"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-docpath",
|
||||
@@ -1493,7 +1493,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cloud-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"egui",
|
||||
]
|
||||
@@ -1501,7 +1501,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cms"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"md-5",
|
||||
"rayon",
|
||||
@@ -1510,7 +1510,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-color-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-cms",
|
||||
@@ -1530,17 +1530,17 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-crs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-metadata",
|
||||
"craft-xml",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-crw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1548,7 +1548,15 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
@@ -1556,7 +1564,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dialogs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"craft-atomic",
|
||||
@@ -1579,7 +1587,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1587,7 +1595,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-draw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1606,21 +1614,21 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
|
||||
[[package]]
|
||||
name = "craft-file-formats"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"craft-idml",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-kra",
|
||||
"craft-ora",
|
||||
"craft-pcraft-bundle",
|
||||
"craft-raw",
|
||||
"craft-svg",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-zip",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1629,7 +1637,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-flags"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"dirs",
|
||||
@@ -1639,7 +1647,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-catalog"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"fontique",
|
||||
"harfrust 0.13.3",
|
||||
@@ -1654,7 +1662,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-manager"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -1673,7 +1681,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"cap-primitives",
|
||||
"craft-atomic",
|
||||
@@ -1694,12 +1702,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
|
||||
[[package]]
|
||||
name = "craft-heif"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"heic-rs",
|
||||
"rayon",
|
||||
@@ -1708,7 +1716,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-host"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-i18n",
|
||||
@@ -1721,7 +1729,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"fixed_decimal",
|
||||
@@ -1749,9 +1757,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-idml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-zip",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1759,13 +1767,40 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-dds",
|
||||
"craft-dds 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-heif",
|
||||
"craft-jpeg",
|
||||
"craft-metadata",
|
||||
"craft-tiff",
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"crc32fast",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
"hayro-jpeg2000",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-encoder",
|
||||
"png 0.18.1",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"craft-dds 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"crc32fast",
|
||||
"exr",
|
||||
"flate2",
|
||||
@@ -1787,7 +1822,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-imaging"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1802,10 +1837,23 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-ipp"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e7873217287876f76a045550369c90a541693c33#e7873217287876f76a045550369c90a541693c33"
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1813,11 +1861,11 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-keymap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"egui",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1826,9 +1874,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-kra"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-zip",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1836,7 +1884,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-layers"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-i18n",
|
||||
@@ -1850,7 +1898,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-menu"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -1868,11 +1916,23 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.2",
|
||||
"chrono",
|
||||
"craft-tiff",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.2",
|
||||
"chrono",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
]
|
||||
@@ -1880,9 +1940,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ora"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-zip",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1890,7 +1950,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pages"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-text",
|
||||
@@ -1904,7 +1964,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-bundle"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-atomic",
|
||||
@@ -1917,7 +1977,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"serde",
|
||||
@@ -1928,7 +1988,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"flate2",
|
||||
@@ -1943,7 +2003,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdn"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1952,7 +2012,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-platform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-io",
|
||||
@@ -1978,7 +2038,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-plist"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1986,7 +2046,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-print"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-ui",
|
||||
@@ -2004,7 +2064,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -2015,7 +2075,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -2026,12 +2086,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-raw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-crw",
|
||||
"craft-metadata",
|
||||
"craft-tiff",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"jxl-oxide",
|
||||
"miniz_oxide 0.9.1",
|
||||
"rayon",
|
||||
@@ -2044,7 +2104,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-review"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2061,7 +2121,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-settings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-host",
|
||||
@@ -2075,12 +2135,31 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"flate2",
|
||||
"kurbo 0.13.1",
|
||||
"quick-xml 0.41.0",
|
||||
"resvg 0.48.1",
|
||||
"roxmltree 0.21.2",
|
||||
"thiserror 2.0.21",
|
||||
"usvg 0.48.1",
|
||||
"vectorcraft-geom",
|
||||
"vectorcraft-pathops",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"data-url",
|
||||
"flate2",
|
||||
"gif",
|
||||
"image-webp",
|
||||
"kurbo 0.13.1",
|
||||
"quick-xml 0.41.0",
|
||||
"resvg 0.48.1",
|
||||
@@ -2094,7 +2173,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-table"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2106,7 +2185,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-text"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-manager",
|
||||
@@ -2129,7 +2208,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"ecolor",
|
||||
@@ -2142,7 +2221,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-editor"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-theme",
|
||||
@@ -2153,7 +2232,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-behavior",
|
||||
@@ -2168,7 +2247,16 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2177,7 +2265,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-time"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2186,7 +2274,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-timeline"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2201,7 +2289,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-cloud-ui",
|
||||
"craft-ui-canvas",
|
||||
@@ -2215,7 +2303,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-canvas"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-i18n",
|
||||
@@ -2231,7 +2319,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-contract"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"craft-behavior",
|
||||
@@ -2243,7 +2331,7 @@ dependencies = [
|
||||
"craft-platform",
|
||||
"craft-quit",
|
||||
"craft-settings",
|
||||
"craft-svg",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-theme",
|
||||
"craft-ui-macros",
|
||||
"craft-window",
|
||||
@@ -2265,7 +2353,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2276,7 +2364,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-panels"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2294,7 +2382,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-patterns"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2315,13 +2403,13 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-shell"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
"craft-platform",
|
||||
"craft-svg",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-theme",
|
||||
"craft-ui-macros",
|
||||
"craft-ui-panels",
|
||||
@@ -2334,7 +2422,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-widgets"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2351,7 +2439,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-host",
|
||||
@@ -2380,7 +2468,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-win32"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"winsafe",
|
||||
]
|
||||
@@ -2388,7 +2476,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-window"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-behavior",
|
||||
@@ -2418,7 +2506,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xcf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2427,7 +2515,17 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be#7b8c1eccea0c695a495ab279c9523e6efcc9b8be"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
@@ -2437,7 +2535,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -3900,7 +3998,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"hayro-interpret",
|
||||
@@ -3930,7 +4028,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-interpret"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"hayro-cmap",
|
||||
@@ -3948,7 +4046,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"fearless_simd",
|
||||
"hayro-ccitt",
|
||||
@@ -3972,7 +4070,7 @@ checksum = "bc2d80da85f31c3fdc0366431f44cfd645a9da1e242ed1f4a61f213d9765660f"
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hayro-ccitt",
|
||||
@@ -5056,7 +5154,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4"
|
||||
[[package]]
|
||||
name = "linesweeper"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"kurbo 0.13.1",
|
||||
@@ -6273,10 +6371,10 @@ dependencies = [
|
||||
"core-graphics2",
|
||||
"craft",
|
||||
"craft-cms",
|
||||
"craft-image-codecs",
|
||||
"craft-svg",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"craft-update",
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"eframe",
|
||||
"egui",
|
||||
"egui_kittest",
|
||||
@@ -6320,7 +6418,7 @@ name = "photocraft-algo"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"craft",
|
||||
"craft-metadata",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"criterion",
|
||||
"photocraft-color",
|
||||
"photocraft-geom",
|
||||
@@ -6340,7 +6438,7 @@ dependencies = [
|
||||
"cap-std",
|
||||
"clap",
|
||||
"craft",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-psd",
|
||||
"getrandom 0.3.4",
|
||||
"photocraft-color",
|
||||
@@ -6373,7 +6471,7 @@ dependencies = [
|
||||
"clap_mangen",
|
||||
"craft",
|
||||
"craft-cms",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-psd",
|
||||
"photocraft-automation",
|
||||
"photocraft-doc",
|
||||
@@ -6437,11 +6535,11 @@ dependencies = [
|
||||
"craft-affinity",
|
||||
"craft-cms",
|
||||
"craft-file-formats",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-pcraft-format",
|
||||
"craft-print",
|
||||
"craft-psd",
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"exr",
|
||||
"flate2",
|
||||
"photocraft-algo",
|
||||
@@ -6477,8 +6575,7 @@ name = "photocraft-format"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-file-formats",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-pcraft-bundle",
|
||||
"craft-pcraft-format",
|
||||
"craft-zip",
|
||||
@@ -6538,16 +6635,16 @@ dependencies = [
|
||||
"craft-crs",
|
||||
"craft-docpath",
|
||||
"craft-file-formats",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-kra",
|
||||
"craft-ora",
|
||||
"craft-pdf",
|
||||
"craft-pdn",
|
||||
"craft-psd",
|
||||
"craft-svg",
|
||||
"craft-tiff",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b8c1eccea0c695a495ab279c9523e6efcc9b8be)",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-xcf",
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"kurbo 0.13.1",
|
||||
@@ -6576,6 +6673,17 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "photocraft-ipp"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"craft-ipp",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-oil-round-proof"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"photocraft-algo",
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-ops"
|
||||
@@ -6635,7 +6743,7 @@ dependencies = [
|
||||
name = "photocraft-raw"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-raw",
|
||||
"flate2",
|
||||
"image",
|
||||
@@ -6697,7 +6805,7 @@ dependencies = [
|
||||
"craft",
|
||||
"craft-file-formats",
|
||||
"craft-i18n",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-print",
|
||||
"craft-psd",
|
||||
"eframe",
|
||||
@@ -6746,7 +6854,7 @@ dependencies = [
|
||||
name = "photocraft-web"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee)",
|
||||
"craft-psd",
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -11116,14 +11224,14 @@ source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1c
|
||||
[[patch.unused]]
|
||||
name = "hayro-cmap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "hayro-postscript"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "krilla"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=18ffc07519b15f5ef39e752aa0f405261fec8ebb#18ffc07519b15f5ef39e752aa0f405261fec8ebb"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=04ba41419b99967e4d2b990cdfe5d80184be64ee#04ba41419b99967e4d2b990cdfe5d80184be64ee"
|
||||
+54
-40
@@ -12,19 +12,19 @@ rust-version = "1.95"
|
||||
[workspace.dependencies]
|
||||
# The craft framework through its facade (`craft::ui::…`). The egui `[patch]` below must match
|
||||
# `craft::egui_fork::REV` (checked by `cargo xtask ci`).
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb", default-features = false }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee", default-features = false }
|
||||
# internal
|
||||
photocraft-geom = { path = "crates/geom" }
|
||||
photocraft-color = { path = "crates/color" }
|
||||
photocraft-raster = { path = "crates/raster" }
|
||||
photocraft-doc = { path = "crates/doc" }
|
||||
photocraft-ops = { path = "crates/ops" }
|
||||
craft-plist = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
|
||||
craft-plist = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
|
||||
photocraft-raw = { path = "crates/raw" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
photocraft-compose = { path = "crates/compose" }
|
||||
photocraft-gpu = { path = "crates/gpu" }
|
||||
photocraft-paint = { path = "crates/paint" }
|
||||
@@ -43,33 +43,34 @@ photocraft-ipp = { path = "crates/ipp" }
|
||||
|
||||
# external
|
||||
# ICC colour management: the shared crate (replaces crates/cms; craft-libs#779).
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
# HEIC/HEIF: the shared decoder (replaces crates/heif; craft-libs#784).
|
||||
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb", features = ["raster", "write-raster"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee", features = ["raster", "write-raster"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
# Keep the shared embedded-image validation API until the framework revision includes it.
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "7b8c1eccea0c695a495ab279c9523e6efcc9b8be", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
# Camera-field EXIF reader/writer, shared prerequisite craft-libs#1563.
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
# Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n
|
||||
# catalogs that `crates/ui-egui/build.rs` embeds from `CRAFT_I18N_DIR` (storytold/craft-i18n, at
|
||||
# the commit in `craft-i18n.rev`). Already in the tree through craft.
|
||||
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb", features = ["ui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee", features = ["ui"] }
|
||||
thiserror = "2"
|
||||
serde = { version = "1", features = ["derive", "rc"] }
|
||||
serde_json = "1"
|
||||
@@ -168,16 +169,29 @@ debug = "line-tables-only"
|
||||
[profile.test.package.photocraft-ui-egui]
|
||||
opt-level = 0
|
||||
|
||||
# Test builds compile the engine without optimization. Every test job compiles it, and at 0 its
|
||||
# test build is about 20% shorter on both Linux and Windows, while its tests run 7-8% longer
|
||||
# (measured against crates the setting doesn't touch). Its pixel-heavy neighbours (algo) stay at
|
||||
# the dev profile's 1.
|
||||
[profile.test.package.photocraft-engine]
|
||||
opt-level = 0
|
||||
|
||||
# Only the exhaustive rounding proof needs maximum optimization; algo stays at its usual level.
|
||||
[profile.test.package.photocraft-oil-round-proof]
|
||||
opt-level = 3
|
||||
|
||||
# Test builds compile the craft UI framework (the `craft` facade and the craft-libs crates behind
|
||||
# it) below the opt-level 2 of `package."*"` above. The workspace unifies the facade's features, so
|
||||
# every crate that uses `craft`, photocraft-text included, waits for the whole framework. At 2 the
|
||||
# chain from craft-host to the facade took 38 of the 77 build minutes of the Windows unit leg, and
|
||||
# rustc shares no generic instantiations across crates at 2 (it does at 0 and 1).
|
||||
# With the whole framework at 0, ten more photocraft-ui-egui tests overflowed their 2 MiB stack on
|
||||
# Windows, so the runtime every frame passes through (contract, shell, canvas, panels, widgets,
|
||||
# host) builds at 1, as do the crates with per-frame or per-pixel code (theme, behavior, imaging,
|
||||
# text, font loading). The panels, tools and services around them build at 0, as in craft-libs.
|
||||
# `cargo run` and `cargo build` use the dev profile and are unaffected.
|
||||
# The runtime every frame passes through (contract, shell, canvas, panels, widgets, host) builds at
|
||||
# 1, as do the crates with per-frame or per-pixel code (theme, behavior, imaging, text, font
|
||||
# loading). At 0 the whole-app UI tests ran about 60% longer on Linux and 30% longer on Windows,
|
||||
# measured against crates the setting doesn't touch, while the framework comes from the CI cache
|
||||
# and compiles only when the craft-libs pin moves (7 of 290 main merges in the week to 19 Nov).
|
||||
# The panels, tools and services around the runtime build at 0, as in craft-libs. `cargo run` and
|
||||
# `cargo build` use the dev profile and are unaffected.
|
||||
[profile.test.package.craft]
|
||||
opt-level = 1
|
||||
[profile.test.package.craft-ui]
|
||||
@@ -321,14 +335,14 @@ opt-level = 3
|
||||
# Keep the complete egui family and native event bridge on reviewed fork commits.
|
||||
|
||||
[patch.crates-io]
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
|
||||
@@ -10,7 +10,10 @@ const PRINT_ONLY: [&str; 2] = ["windows.data.pdf.dll", "prntvpt.dll"];
|
||||
/// The built exe names each print-only DLL in its delay-load table, never its import table.
|
||||
#[test]
|
||||
fn print_only_system_dlls_are_delay_loaded() {
|
||||
let exe = std::fs::read(env!("CARGO_BIN_EXE_photocraft")).unwrap();
|
||||
// The run-time variable first: a run from a nextest archive points it at the extracted exe,
|
||||
// while the compile-time path names the directory the archive was built in.
|
||||
let path = std::env::var("CARGO_BIN_EXE_photocraft").unwrap_or_else(|_| env!("CARGO_BIN_EXE_photocraft").to_string());
|
||||
let exe = std::fs::read(path).unwrap();
|
||||
let pe = Pe::parse(&exe);
|
||||
let imports = pe.dll_names(1, 20, 12);
|
||||
let delayed = pe.dll_names(13, 32, 4);
|
||||
|
||||
@@ -241,8 +241,9 @@ fn layer_box_blurs_match_direct_convolution_at_any_radius() {
|
||||
];
|
||||
let params = [
|
||||
FilterParams::GaussianBlur { radius: 4.5 },
|
||||
// 9.3 already reaches past the layer's height with three boxes (edges repeated); a larger radius takes the same
|
||||
// running sums and only made the direct-convolution oracle slow (#15652).
|
||||
FilterParams::GaussianBlur { radius: 9.3 },
|
||||
FilterParams::GaussianBlur { radius: 40.0 },
|
||||
FilterParams::BoxBlur { radius: 5.0 },
|
||||
FilterParams::BoxBlur { radius: 70.0 },
|
||||
];
|
||||
@@ -254,7 +255,11 @@ fn layer_box_blurs_match_direct_convolution_at_any_radius() {
|
||||
SampleType::U16 => 1.0 / 65535.0,
|
||||
_ => 0.0,
|
||||
} + 2e-5;
|
||||
for p in ¶ms {
|
||||
// Each format sees both blur modes; each radius is covered across formats.
|
||||
for (pi, p) in params.iter().enumerate() {
|
||||
if pi % 2 != i % 2 {
|
||||
continue;
|
||||
}
|
||||
let boxes = box_widths(p).expect("a box-pass blur");
|
||||
let reach: i32 = boxes.iter().map(|w| (w / 2) as i32).sum();
|
||||
let area = crate::output_area(p, s.content_bounds(), canvas, None);
|
||||
|
||||
@@ -102,26 +102,23 @@ fn exact(a: &[f32], b: &[f32], what: &str) {
|
||||
|
||||
#[test]
|
||||
fn offset_fast_path_matches_the_per_channel_oracle() {
|
||||
let mut layouts: Vec<(ColorMode, usize, bool)> = vec![
|
||||
(ColorMode::Rgb, 3, false),
|
||||
(ColorMode::Rgb, 4, true),
|
||||
(ColorMode::Grayscale, 1, false),
|
||||
(ColorMode::Grayscale, 2, true),
|
||||
(ColorMode::Cmyk, 4, false),
|
||||
(ColorMode::Cmyk, 5, true),
|
||||
(ColorMode::Lab, 4, true),
|
||||
];
|
||||
layouts.extend((1..=MAXC).flat_map(|n| [(ColorMode::Multichannel, n, false), (ColorMode::Multichannel, n, true)]));
|
||||
// The fast path dispatches on the channel count and alpha (`smart_blur`'s `smart_rows` arms, generic code past
|
||||
// five); the colour mode reaches it only through the native white and black, which the oracle computes the same
|
||||
// way. So every count with and without alpha covers every arm, whatever the mode is called (#15652).
|
||||
let layouts: Vec<(ColorMode, usize, bool)> = (1..=MAXC).flat_map(|n| [(ColorMode::Multichannel, n, false), (ColorMode::Multichannel, n, true)]).collect();
|
||||
let win = Rect::new(-7, -4, 33, 30);
|
||||
for (mode, n, alpha) in layouts {
|
||||
let src = image(win, n, alpha);
|
||||
let ctx = Ctx { bounds: win, mode, alpha };
|
||||
for radius in [0.1f32, 1.0, 3.0, 12.0, 17.5] {
|
||||
// Centre only, unit stride, and a coarse stride for both qualities. At 13 the inner
|
||||
// rectangle still has pixels, so coarse offsets exercise the fast path too.
|
||||
for radius in [0.1f32, 3.0, 13.0] {
|
||||
let ri = f32::ceil(radius) as i32;
|
||||
// The usual tile (the window less the halo), the whole window, and one sticking out of it.
|
||||
let inner = Rect::new(win.x0 + ri, win.y0 + ri, win.x1 - ri, win.y1 - ri);
|
||||
for out in [inner, win, Rect::new(-12, -9, 10, 8), Rect::EMPTY] {
|
||||
for quality in [BlurQuality::Low, BlurQuality::Medium, BlurQuality::High] {
|
||||
// Quality selects the offset stride; both paths are compared to the oracle.
|
||||
for quality in [BlurQuality::Low, BlurQuality::High] {
|
||||
for sm in [SmartBlurMode::Normal, SmartBlurMode::EdgeOnly, SmartBlurMode::OverlayEdge] {
|
||||
for threshold in [8.0, 60.0] {
|
||||
let what = format!("{mode:?} n={n} alpha={alpha} r={radius} {out:?} {quality:?} {sm:?} t={threshold}");
|
||||
|
||||
@@ -149,9 +149,13 @@ fn iris_depths_models_selection_tiles_and_cancellation() {
|
||||
let mut selection = Surface::new(PixelFormat::GRAY8);
|
||||
selection.fill_rect(bounds, &[0.4]);
|
||||
selection.fill_rect(Rect::new(3, 19, 35, 44), &[1.0]);
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab] {
|
||||
for sample in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for alpha in [false, true] {
|
||||
// Cover every mode/sample pair and both alpha values for each mode and sample.
|
||||
for (mi, mode) in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab].into_iter().enumerate() {
|
||||
for (si, sample) in [SampleType::U8, SampleType::U16, SampleType::F32].into_iter().enumerate() {
|
||||
for (ai, alpha) in [false, true].into_iter().enumerate() {
|
||||
if (mi + si) % 2 != ai {
|
||||
continue;
|
||||
}
|
||||
let fmt = PixelFormat::new(mode, sample, alpha);
|
||||
let mut surface = Surface::new(fmt);
|
||||
surface.write_region(bounds, &image(bounds, fmt.channels()).data);
|
||||
|
||||
@@ -186,10 +186,10 @@ fn a_hole_is_as_thick_as_it_is_through_not_along() {
|
||||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn thin_holes_are_filled_the_same_on_any_number_of_threads() {
|
||||
let (w, h) = (300, 200);
|
||||
let (w, h) = (150, 100);
|
||||
let img = busy(w, h, 3, 5);
|
||||
// A wavy line 6 px thick across the image.
|
||||
let hole: Vec<bool> = (0..w * h).map(|i| (((i % w) as f32 * 0.05).sin() * 30.0 + 100.0 - (i / w) as f32).abs() < 3.0).collect();
|
||||
let hole: Vec<bool> = (0..w * h).map(|i| (((i % w) as f32 * 0.05).sin() * 15.0 + 50.0 - (i / w) as f32).abs() < 3.0).collect();
|
||||
let px = roles(w, h, &hole);
|
||||
let run = |threads: usize| {
|
||||
let pool = rayon::ThreadPoolBuilder::new().num_threads(threads).build().unwrap();
|
||||
|
||||
+2
-30
@@ -30,16 +30,8 @@ fn stroke_len(stylization: f32) -> f32 {
|
||||
1.5 + stylization.clamp(0.1, 10.0) * 2.0
|
||||
}
|
||||
|
||||
/// `f32::round` (half away from zero) as an integer, without the `roundf` call `f32::round`
|
||||
/// makes on the baseline x86-64 target. The sum is taken in `f64`, where `v ± 0.5` is exact for
|
||||
/// every `f32` the cast does not saturate (an `f32` sum is not: `0.49999997 + 0.5` rounds up to
|
||||
/// `1.0`), so the result equals `v.round() as i32` for every `f32`, NaN (0) and the saturating
|
||||
/// ends included.
|
||||
#[inline]
|
||||
fn round_i32(v: f32) -> i32 {
|
||||
let v = f64::from(v);
|
||||
(v + 0.5f64.copysign(v)) as i32
|
||||
}
|
||||
mod round;
|
||||
use round::round_i32;
|
||||
|
||||
/// [`round_i32`] clamped into `0..n`.
|
||||
#[inline]
|
||||
@@ -250,24 +242,4 @@ mod tests {
|
||||
assert_eq!(round_index(f32::INFINITY, n), ((n - 1) as f32) as usize);
|
||||
}
|
||||
}
|
||||
|
||||
/// Every `f32` bit pattern in [-4096, 4096] (both signs, about 2.3e9 values, split across
|
||||
/// threads) rounds exactly like `f32::round`.
|
||||
#[test]
|
||||
fn rounding_matches_the_standard_library_for_every_f32_up_to_4096() {
|
||||
use rayon::prelude::*;
|
||||
let last = 4096.0f32.to_bits();
|
||||
let bad = (0..=last >> 20)
|
||||
.into_par_iter()
|
||||
.filter_map(|hi| {
|
||||
let lo = hi << 20;
|
||||
let hi_end = (lo | 0xf_ffff).min(last);
|
||||
(lo..=hi_end).find_map(|bits| {
|
||||
let v = f32::from_bits(bits);
|
||||
[v, -v].into_iter().find(|v| round_i32(*v) != v.round() as i32)
|
||||
})
|
||||
})
|
||||
.min_by(|a, b| a.abs().total_cmp(&b.abs()));
|
||||
assert_eq!(bad, None, "round_i32 differs from f32::round");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/// `f32::round` (half away from zero) as an integer, without the `roundf` call `f32::round`
|
||||
/// makes on the baseline x86-64 target. The sum is taken in `f64`, where `v ± 0.5` is exact for
|
||||
/// every `f32` the cast does not saturate (an `f32` sum is not: `0.49999997 + 0.5` rounds up to
|
||||
/// `1.0`), so the result equals `v.round() as i32` for every `f32`, NaN (0) and the saturating
|
||||
/// ends included.
|
||||
#[inline]
|
||||
pub(super) fn round_i32(v: f32) -> i32 {
|
||||
let v = f64::from(v);
|
||||
(v + 0.5f64.copysign(v)) as i32
|
||||
}
|
||||
@@ -361,18 +361,27 @@ fn multiband_matches_the_serial_code() {
|
||||
assert_eq!(multiband(9, 7, &[], &[], 3).unwrap().0.len(), ref_multiband(9, 7, &[], &[], 3).0.len());
|
||||
}
|
||||
|
||||
/// Batching the bands (#7758) changes when they are built, not the result. Budgets from none
|
||||
/// (one image per batch) up to everything in steps of a fifth pass through every split of the
|
||||
/// three images.
|
||||
/// Batching the bands (#7758) changes when they are built, not the result. The batching adds the
|
||||
/// next image while the batch's band cost stays within the budget, so its split changes only where
|
||||
/// the budget crosses the cost of a run of consecutive images: each such sum and one below it, plus
|
||||
/// none and everything, pass through every split the images can have (#15652; it swept 47 budgets).
|
||||
#[test]
|
||||
fn multiband_batches_match_the_serial_code() {
|
||||
let budgets: Vec<usize> =
|
||||
std::iter::successors(Some(1024.0f64), |b| Some(b * 1.2)).take_while(|b| *b < 4e6).map(|b| b as usize).chain([0, usize::MAX]).collect();
|
||||
for (n, &(w, h)) in [(40usize, 30usize), (97, 61), (201, 129)].iter().enumerate() {
|
||||
for (n, &(w, h)) in [(40usize, 30usize), (97, 61)].iter().enumerate() {
|
||||
for ch in [1usize, 3] {
|
||||
let (imgs, wts) = rois(w, h, ch, n as u64 * 17 + ch as u64);
|
||||
for levels in [1usize, 3, 5] {
|
||||
let want = ref_multiband(w, h, &imgs, &wts, levels);
|
||||
let costs: Vec<usize> = imgs.iter().map(|im| blend::band_cost(im, w, h, ch, levels)).collect();
|
||||
let mut budgets = vec![0, usize::MAX];
|
||||
for start in 0..costs.len() {
|
||||
for end in start + 1..=costs.len() {
|
||||
let run: usize = costs[start..end].iter().sum();
|
||||
budgets.extend([run.saturating_sub(1), run]);
|
||||
}
|
||||
}
|
||||
budgets.sort_unstable();
|
||||
budgets.dedup();
|
||||
for &budget in &budgets {
|
||||
let got = try_multiband_batched(w, h, &imgs, &wts, levels, budget, None).unwrap();
|
||||
assert_eq!(bits(&got.0), bits(&want.0), "colours {w}x{h}x{ch} levels {levels} budget {budget}");
|
||||
|
||||
@@ -127,9 +127,13 @@ fn halftone_unusual_coordinates_and_params_keep_direct_semantics() {
|
||||
fn tiled_filters_match_scalar_at_all_depths_with_soft_selection() {
|
||||
use crate::{FilterParams, apply_tiled};
|
||||
let bounds = Rect::new(-17, -9, 26, 24);
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab] {
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for alpha in [false, true] {
|
||||
// Every mode/depth pair and both alpha values for each mode and depth.
|
||||
for (mi, mode) in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab].into_iter().enumerate() {
|
||||
for (di, depth) in [SampleType::U8, SampleType::U16, SampleType::F32].into_iter().enumerate() {
|
||||
for (ai, alpha) in [false, true].into_iter().enumerate() {
|
||||
if (mi + di) % 2 != ai {
|
||||
continue;
|
||||
}
|
||||
let ctx = Ctx { bounds, mode, alpha };
|
||||
let src = fixture(bounds, &ctx, 2);
|
||||
let mut surface = Surface::new(PixelFormat::new(mode, depth, alpha));
|
||||
@@ -195,15 +199,22 @@ fn facet_scratch_rejects_large_or_incomplete_storage() {
|
||||
#[test]
|
||||
fn cell_filters_match_scalar_models_edges_and_fractional_cells() {
|
||||
let bounds = Rect::new(-19, -13, 32, 29);
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab, ColorMode::Multichannel] {
|
||||
for alpha in [false, true] {
|
||||
// The cell filters see the mode only as a channel count, CMYK's ink direction (`subtractive`) and the native
|
||||
// background, so Lab adds nothing to RGB; cells of 100 and 300 are both past every `out`, and the seed has no
|
||||
// branch (0 and u32::MAX keep the wrapping ends) (#15652).
|
||||
for (mi, mode) in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Multichannel].into_iter().enumerate() {
|
||||
for (ai, alpha) in [false, true].into_iter().enumerate() {
|
||||
let ctx = Ctx { bounds, mode, alpha };
|
||||
for pattern in 0..5 {
|
||||
for halo in [0, 7] {
|
||||
let src = fixture(bounds.inflate(halo), &ctx, pattern);
|
||||
for out in [bounds, Rect::new(-23, -15, 37, 31), Rect::new(-7, 2, 18, 13)] {
|
||||
for cell in [2.0, 3.75, 10.0, 100.0, 300.0] {
|
||||
for seed in [0, 37, u32::MAX] {
|
||||
// Retain every mode/alpha pair and all four cell sizes for each mode.
|
||||
for (ci, cell) in [2.0, 3.75, 10.0, 300.0].into_iter().enumerate() {
|
||||
if ci % 2 != (mi + ai) % 2 {
|
||||
continue;
|
||||
}
|
||||
for seed in [0, u32::MAX] {
|
||||
let got = cells::crystallize(&src, out, &ctx, cell, seed).unwrap();
|
||||
assert_bits(&got, &crystallize_direct(&src, out, &ctx, cell, seed));
|
||||
for bg in [[1.0; 4], [0.1, 0.8, 0.4, 0.25]] {
|
||||
@@ -257,7 +268,9 @@ fn cell_filters_tiled_storage_matches_scalar_with_soft_selection() {
|
||||
crate::mix_selection(&mut expected_data, bounds, &selection, &image, ctx.alpha);
|
||||
let mut expected = surface.clone();
|
||||
expected.write_region(bounds, &expected_data);
|
||||
for tile in [1, 7, 17, 256] {
|
||||
// Tile 7 has dense edge tiles, sparse inner ones and a partial last one; 17 makes 1-pixel-wide and
|
||||
// 2-row tiles. Tile 1 sent every edge pixel through the dense fallback (#15652).
|
||||
for tile in [7, 17, 256] {
|
||||
let got = apply_tiled(&surface, ¶ms, bounds, bounds, Some(&selection), tile, extent);
|
||||
assert_bits(&got.read_region(bounds), &expected.read_region(bounds));
|
||||
}
|
||||
|
||||
+23
-15
@@ -150,6 +150,11 @@ fn read_rgba(src: &Image, ctx: &Ctx, x: i32, y: i32) -> [f32; 4] {
|
||||
|
||||
/// Relight `out` of `src`. Identity when `intensity` is 0 (or not finite).
|
||||
pub(crate) fn relight(src: &Image, out: Rect, ctx: &Ctx, p: Params) -> Vec<f32> {
|
||||
relight_with_luma_budget(src, out, ctx, p, MAX_LUMA_PIXELS)
|
||||
}
|
||||
|
||||
/// Relight with a bound on the luma field allocated by each band.
|
||||
fn relight_with_luma_budget(src: &Image, out: Rect, ctx: &Ctx, p: Params, max_luma_pixels: usize) -> Vec<f32> {
|
||||
let n = src.ch;
|
||||
if out.is_empty() || n == 0 {
|
||||
return src.crop(out);
|
||||
@@ -160,14 +165,14 @@ pub(crate) fn relight(src: &Image, out: Rect, ctx: &Ctx, p: Params) -> Vec<f32>
|
||||
let sig = sigma(p.softness, ctx.bounds);
|
||||
let step = step_for_sigma(sig);
|
||||
let reach = read_radius(sig);
|
||||
if let Some(band_h) = luma_band_rows(out, reach) {
|
||||
if let Some(band_h) = luma_band_rows(out, reach, max_luma_pixels) {
|
||||
return relight_bands(src, out, ctx, p, sig, step, band_h);
|
||||
}
|
||||
relight_rect(src, out, ctx, p, sig, step)
|
||||
}
|
||||
|
||||
/// Horizontal strip height so the inflated luma field stays within [`MAX_LUMA_PIXELS`].
|
||||
fn luma_band_rows(out: Rect, reach: i32) -> Option<i32> {
|
||||
fn luma_band_rows(out: Rect, reach: i32, max_luma_pixels: usize) -> Option<i32> {
|
||||
let margin = 2usize.saturating_mul(reach.max(0) as usize);
|
||||
let yw = (out.width() as usize).saturating_add(margin);
|
||||
let yh = (out.height() as usize).saturating_add(margin);
|
||||
@@ -179,10 +184,10 @@ fn luma_band_rows(out: Rect, reach: i32) -> Option<i32> {
|
||||
Some(_) => return None,
|
||||
None => usize::MAX,
|
||||
};
|
||||
if n <= MAX_LUMA_PIXELS {
|
||||
if n <= max_luma_pixels {
|
||||
return None;
|
||||
}
|
||||
let max_yh = (MAX_LUMA_PIXELS / yw).max(1);
|
||||
let max_yh = (max_luma_pixels / yw).max(1);
|
||||
let inner = max_yh.saturating_sub(margin).max(1).min(i32::MAX as usize) as i32;
|
||||
if inner >= out.height() as i32 { None } else { Some(inner.max(1)) }
|
||||
}
|
||||
@@ -534,10 +539,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layers_above_8mp_are_relit() {
|
||||
// 4096×2048 = 8.39 MP. A single full-frame kernel call inflates past 8 MP of luma,
|
||||
// which used to return the input unchanged. Force one tile so that path is taken.
|
||||
let (w, h) = (4096, 2048);
|
||||
fn layers_above_the_luma_budget_are_relit() {
|
||||
// A small budget exercises the same banding path as an 8 MP luma field.
|
||||
let (w, h) = (256, 128);
|
||||
let bounds = Rect::new(0, 0, w, h);
|
||||
let mut s = Surface::new(PixelFormat::RGBA8);
|
||||
let bytes: Vec<u8> = (0..h)
|
||||
@@ -550,15 +554,19 @@ mod tests {
|
||||
})
|
||||
.collect();
|
||||
s.write_interleaved(bounds, &bytes);
|
||||
let p = relight_p(180.0, 30.0, 90.0, 12.0, 0.0, 25.0);
|
||||
let area = output_area(&p, s.content_bounds(), bounds, None);
|
||||
let p = Params { angle: 180.0, elevation: 30.0, intensity: 90.0, ambient: 12.0, warmth: 0.0, softness: 25.0 };
|
||||
let reach = read_radius(sigma(p.softness, bounds));
|
||||
assert!(luma_band_rows(bounds, reach, 20_000).is_some());
|
||||
let src = Image::read_clamped(&s, bounds.inflate(reach), bounds);
|
||||
let ctx = Ctx { bounds, mode: ColorMode::Rgb, alpha: true };
|
||||
let before = s.pixel(w / 2, h / 2);
|
||||
let out = apply_tiled(&s, &p, area, bounds, None, 8192, None);
|
||||
let after = out.pixel(w / 2, h / 2);
|
||||
let out = relight_with_luma_budget(&src, bounds, &ctx, p, 20_000);
|
||||
let pixel = |x: i32, y: i32| &out[((y * w + x) * 4) as usize..][..4];
|
||||
let after = pixel(w / 2, h / 2);
|
||||
assert!(after.iter().all(|c| c.is_finite()), "{after:?}");
|
||||
let d = max_diff(&before, &after);
|
||||
assert!(d > 1e-4, "8 MP+ layer was left unchanged (max diff {d})");
|
||||
assert!(max_diff(&s.pixel(8, 8), &out.pixel(8, 8)) > 1e-4);
|
||||
let d = max_diff(&before, after);
|
||||
assert!(d > 1e-4, "over-budget layer was left unchanged (max diff {d})");
|
||||
assert!(max_diff(&s.pixel(8, 8), pixel(8, 8)) > 1e-4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -273,6 +273,10 @@ mod tests {
|
||||
let fmt = PixelFormat::new(mode, depth, true);
|
||||
for (w, h) in [(512, 512), (900, 240), (2400, 1200)] {
|
||||
for seed in [0, 3, 7, 18916] {
|
||||
// One seed exercises the large canvas; all seeds still run at both smaller sizes.
|
||||
if w == 2400 && seed != 0 {
|
||||
continue;
|
||||
}
|
||||
let px = render(fmt, w, h, seed, (BLACK, WHITE), None);
|
||||
let v: Vec<f32> = px.chunks_exact(fmt.channels()).map(|p| p[0]).collect();
|
||||
let n = v.len() as f32;
|
||||
|
||||
@@ -297,23 +297,23 @@ fn canvas_edges_repeat_instead_of_fading() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Two tiles in opposite corners of a 100000 px square: the content bounds are huge but
|
||||
/// Two tiles in opposite corners of a 20096 px square: the content bounds are huge but
|
||||
/// almost nothing is stored. Shrinking it to one pixel must neither allocate a window
|
||||
/// proportional to the scale (#713) nor read the empty middle.
|
||||
#[test]
|
||||
fn tiny_target_of_a_huge_sparse_source() {
|
||||
let mut s = Surface::new(PixelFormat::RGBA32F);
|
||||
s.fill_rect(Rect::new(0, 0, 256, 256), &[1.0, 1.0, 1.0, 1.0]);
|
||||
s.fill_rect(Rect::new(99_840, 99_840, 100_096, 100_096), &[1.0, 1.0, 1.0, 1.0]);
|
||||
let k = 1.0 / 100_096.0;
|
||||
s.fill_rect(Rect::new(19_840, 19_840, 20_096, 20_096), &[1.0, 1.0, 1.0, 1.0]);
|
||||
let k = 1.0 / 20_096.0;
|
||||
let o = resize_surface(&s, k, k, Resample::Bicubic);
|
||||
assert_eq!(o.content_bounds(), Rect::new(0, 0, 1, 1));
|
||||
let p = o.pixel(0, 0);
|
||||
// Two 256² tiles out of 100096²: nearly transparent, and white where it isn't.
|
||||
// Two 256² tiles out of 20096²: nearly transparent, and white where it isn't.
|
||||
assert!(p[3] >= 0.0 && p[3] < 1e-3 && p.iter().all(|v| v.is_finite()), "{p:?}");
|
||||
// Squashed to one row but kept wide: the whole height feeds one band of output rows,
|
||||
// which must not hold a full-height intermediate.
|
||||
let o = resize_surface(&s, 1000.0 / 100_096.0, k, Resample::Bicubic);
|
||||
let o = resize_surface(&s, 1000.0 / 20_096.0, k, Resample::Bicubic);
|
||||
let b = o.content_bounds();
|
||||
assert!(b.height() == 1 && (1000..=1001).contains(&b.width()), "{b:?}");
|
||||
assert!(o.pixel(0, 0)[3] > 0.0 && o.pixel(500, 0)[3] == 0.0, "{:?} {:?}", o.pixel(0, 0), o.pixel(500, 0));
|
||||
|
||||
@@ -82,16 +82,16 @@ fn quick_selection_workflow_release_comparison() {
|
||||
|
||||
#[test]
|
||||
fn quick_selection_preserves_textures_low_contrast_and_thin_features() {
|
||||
let (w, h) = (360usize, 280usize);
|
||||
let (w, h) = (180usize, 140usize);
|
||||
let canvas = Rect::new(0, 0, w as i32, h as i32);
|
||||
for kind in 0..6 {
|
||||
let img = RgbImage::from_fn(w, h, |x, y| {
|
||||
let inside = if kind == 2 {
|
||||
(x as f32 - 180.0).hypot(y as f32 - 140.0) < 72.0
|
||||
(x as f32 - 90.0).hypot(y as f32 - 70.0) < 36.0
|
||||
} else if kind == 3 {
|
||||
y > 130 && y < 145
|
||||
y > 65 && y < 73
|
||||
} else {
|
||||
x > 60 && x < 300 && y > 60 && y < 220
|
||||
x > 30 && x < 150 && y > 30 && y < 110
|
||||
};
|
||||
let t = ((x * 23 + y * 19) % 101) as f32 / 100.0;
|
||||
match kind {
|
||||
@@ -102,7 +102,7 @@ fn quick_selection_preserves_textures_low_contrast_and_thin_features() {
|
||||
[0.4, 0.3 + t * 0.1, 0.2]
|
||||
}
|
||||
}
|
||||
1 => [0.4 + x as f32 / 1800.0, 0.3 + y as f32 / 1400.0, t * 0.02],
|
||||
1 => [0.4 + x as f32 / 900.0, 0.3 + y as f32 / 700.0, t * 0.02],
|
||||
4 => [t, ((x * 7 + y * 31) % 79) as f32 / 78.0, 0.4],
|
||||
5 => [0.4; 3],
|
||||
_ => {
|
||||
@@ -115,8 +115,9 @@ fn quick_selection_preserves_textures_low_contrast_and_thin_features() {
|
||||
}
|
||||
});
|
||||
let sampler = ImageSampler { img: &img, origin: (0, 0) };
|
||||
for (points, brush) in [(vec![(180.0, 140.0)], 12.0), (vec![(90.0, 140.0), (270.0, 140.0)], 40.0), (vec![(1.0, 1.0), (160.0, 130.0)], 64.0)] {
|
||||
for direct_px in [10_000, 300_000] {
|
||||
for (points, brush) in [(vec![(90.0, 70.0)], 6.0), (vec![(45.0, 70.0), (135.0, 70.0)], 20.0), (vec![(1.0, 1.0), (80.0, 65.0)], 32.0)] {
|
||||
// Scale the coarse-cut threshold with the canvas area; the second case stays direct.
|
||||
for direct_px in [2_500, 300_000] {
|
||||
let tune = quick::Tuning { direct_px, ..quick::Tuning::default() };
|
||||
let old = quick::quick_select_using::<false>(&sampler, canvas, &points, brush, &tune);
|
||||
let new = quick::quick_select_using::<true>(&sampler, canvas, &points, brush, &tune);
|
||||
|
||||
@@ -113,13 +113,13 @@ fn fft_cancellation_discards_partial_work_and_bounds_scratch() {
|
||||
#[test]
|
||||
fn positive_threshold_dispatch_retains_exact_pixel_decisions() {
|
||||
let area = Rect::new(-3, 2, 253, 258);
|
||||
for depth in SampleType::ALL {
|
||||
let s = source(area, PixelFormat::new(ColorMode::Rgb, depth, true));
|
||||
let p = FilterParams::UnsharpMask { amount: 500.0, radius: 64.0, threshold: 8.0 };
|
||||
let expected = crate::sharpen::tests::apply_reference(&s, &p, area, area, None, Some(area), 256);
|
||||
let actual = crate::apply_in(&s, &p, area, area, None, area);
|
||||
assert_eq!(expected.to_interleaved(area), actual.to_interleaved(area));
|
||||
}
|
||||
// The FFT gate has no depth branch; only the positive threshold turns it away here. The exact kernel at every
|
||||
// depth is `sharpen::tests::exact_tiled_selected_outputs_and_cancellation` (#15652).
|
||||
let s = source(area, PixelFormat::new(ColorMode::Rgb, SampleType::U8, true));
|
||||
let p = FilterParams::UnsharpMask { amount: 500.0, radius: 64.0, threshold: 8.0 };
|
||||
let expected = crate::sharpen::tests::apply_reference(&s, &p, area, area, None, Some(area), 256);
|
||||
let actual = crate::apply_in(&s, &p, area, area, None, area);
|
||||
assert_eq!(expected.to_interleaved(area), actual.to_interleaved(area));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -183,13 +183,17 @@ fn exact_tiled_selected_outputs_and_cancellation() {
|
||||
let mut sel = Surface::new(PixelFormat::GRAY8);
|
||||
sel.fill_rect(area, &[0.4]);
|
||||
sel.fill_rect(Rect::new(250, 250, 270, 265), &[1.0]);
|
||||
for depth in SampleType::ALL {
|
||||
for (di, depth) in SampleType::ALL.into_iter().enumerate() {
|
||||
let surface = source(bounds, PixelFormat::new(ColorMode::Rgb, depth, true));
|
||||
for radius in [0.6, 3.0, 10.0] {
|
||||
for (ri, radius) in [0.6, 3.0, 10.0].into_iter().enumerate() {
|
||||
let p = crate::FilterParams::UnsharpMask { amount: 150.0, radius, threshold: 8.0 };
|
||||
for extent in [None, Some(bounds)] {
|
||||
let expected = apply_reference(&surface, &p, area, bounds, Some(&sel), extent, 256);
|
||||
for tile in [63, 256, 512] {
|
||||
// Keep every depth/radius, depth/tile and radius/tile pair, with both extents.
|
||||
for (ti, tile) in [63, 256, 512].into_iter().enumerate() {
|
||||
if ti != (di + ri) % 3 {
|
||||
continue;
|
||||
}
|
||||
let actual = crate::apply_tiled(&surface, &p, area, bounds, Some(&sel), tile, extent);
|
||||
assert_eq!(expected.to_interleaved(bounds), actual.to_interleaved(bounds));
|
||||
}
|
||||
|
||||
@@ -44,8 +44,11 @@ fn swept_blocks_match_the_pixel_search_part(part: u64) {
|
||||
let repeat = !seen.insert((n, alpha, mode == ColorMode::Cmyk));
|
||||
for kind in 0..5 {
|
||||
let src = image(bounds.inflate(20), n, kind);
|
||||
for (size, depth) in [(2.0, 0.0), (2.0, 255.0), (3.5, 190.0), (8.0, 64.0), (22.0, 255.0), (255.0, 100.0)] {
|
||||
for flags in (0..8).filter(|f| !repeat || f & 1 != 0) {
|
||||
for (si, (size, depth)) in [(2.0, 0.0), (2.0, 255.0), (3.5, 190.0), (8.0, 64.0), (22.0, 255.0), (255.0, 100.0)].into_iter().enumerate() {
|
||||
// For distinct channel layouts each kind and size sees every flag
|
||||
// combination. Repeated layouts keep one level-based case per pair.
|
||||
let first = (kind + si) % 8;
|
||||
for flags in (0..8).filter(|f| (!repeat || f & 1 != 0) && (*f == first || *f == (first + 3) % 8)) {
|
||||
case += 1;
|
||||
if !sweep.includes(case) {
|
||||
continue;
|
||||
|
||||
@@ -34,6 +34,7 @@ impl BandRenderer for QueuedDiagnosticsRenderer {
|
||||
|
||||
#[test]
|
||||
fn native_save_refuses_previews_rendered_from_unreadable_scratch() {
|
||||
photocraft_raster::spill::use_test_volume_space();
|
||||
let dir = std::env::temp_dir().join(format!("photocraft-automation-scratch-save-{}", std::process::id()));
|
||||
spill::configure(Some(&dir), 1).unwrap();
|
||||
let mut doc = Document::new("Scratch", Size::new(512, 256), ColorMode::Rgb, SampleType::U8);
|
||||
|
||||
@@ -46,7 +46,70 @@ pub enum BlendMode {
|
||||
PaintNetColorDodge,
|
||||
}
|
||||
|
||||
/// Parse legacy command names and labels, retaining their case and punctuation tolerance.
|
||||
pub fn parse_blend(s: &str) -> Option<BlendMode> {
|
||||
fn normalize(value: &str) -> String {
|
||||
value.to_ascii_lowercase().replace([' ', '_', '-', '(', ')'], "")
|
||||
}
|
||||
static ALIASES: std::sync::OnceLock<std::collections::HashMap<String, BlendMode>> = std::sync::OnceLock::new();
|
||||
let aliases = ALIASES.get_or_init(|| {
|
||||
let mut aliases = std::collections::HashMap::new();
|
||||
for mode in std::iter::once(BlendMode::PassThrough).chain(BlendMode::layer_modes()) {
|
||||
aliases.entry(normalize(mode.label())).or_insert(mode);
|
||||
aliases.entry(normalize(&format!("{mode:?}"))).or_insert(mode);
|
||||
}
|
||||
aliases
|
||||
});
|
||||
aliases.get(&normalize(s)).copied()
|
||||
}
|
||||
|
||||
impl BlendMode {
|
||||
/// Stable key used by the Layers panel.
|
||||
pub fn key(self) -> &'static str {
|
||||
match self {
|
||||
Self::PassThrough => "passthrough",
|
||||
Self::Normal => "normal",
|
||||
Self::Dissolve => "dissolve",
|
||||
Self::Darken => "darken",
|
||||
Self::Multiply => "multiply",
|
||||
Self::ColorBurn => "colorburn",
|
||||
Self::LinearBurn => "linearburn",
|
||||
Self::DarkerColor => "darkercolor",
|
||||
Self::Lighten => "lighten",
|
||||
Self::Screen => "screen",
|
||||
Self::ColorDodge => "colordodge",
|
||||
Self::LinearDodge => "lineardodgeadd",
|
||||
Self::LighterColor => "lightercolor",
|
||||
Self::Overlay => "overlay",
|
||||
Self::SoftLight => "softlight",
|
||||
Self::HardLight => "hardlight",
|
||||
Self::VividLight => "vividlight",
|
||||
Self::LinearLight => "linearlight",
|
||||
Self::PinLight => "pinlight",
|
||||
Self::HardMix => "hardmix",
|
||||
Self::Difference => "difference",
|
||||
Self::Exclusion => "exclusion",
|
||||
Self::Subtract => "subtract",
|
||||
Self::Divide => "divide",
|
||||
Self::Hue => "hue",
|
||||
Self::Saturation => "saturation",
|
||||
Self::Color => "color",
|
||||
Self::Luminosity => "luminosity",
|
||||
Self::Reflect => "reflect",
|
||||
Self::Glow => "glow",
|
||||
Self::Negation => "negation",
|
||||
Self::Xor => "xor",
|
||||
Self::PaintNetColorBurn => "colorburnpaint.net",
|
||||
Self::PaintNetColorDodge => "colordodgepaint.net",
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve a canonical Layers panel key.
|
||||
pub fn from_key(key: &str) -> Option<Self> {
|
||||
static MODES: std::sync::OnceLock<std::collections::HashMap<&'static str, BlendMode>> = std::sync::OnceLock::new();
|
||||
MODES.get_or_init(|| std::iter::once(Self::PassThrough).chain(Self::layer_modes()).map(|mode| (mode.key(), mode)).collect()).get(key).copied()
|
||||
}
|
||||
|
||||
/// Paint.NET modes without an exact Photoshop equivalent.
|
||||
pub const PAINT_NET_MODES: [BlendMode; 6] = [Self::Reflect, Self::Glow, Self::Negation, Self::Xor, Self::PaintNetColorBurn, Self::PaintNetColorDodge];
|
||||
|
||||
@@ -623,3 +686,37 @@ pub fn composite_atop(mode: BlendMode, backdrop: [f32; 4], source: [f32; 4], opa
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod key_tests {
|
||||
use super::BlendMode;
|
||||
|
||||
#[test]
|
||||
fn parser_preserves_legacy_names_and_normalization() {
|
||||
let normalize = |s: &str| s.to_ascii_lowercase().replace([' ', '_', '-', '(', ')'], "");
|
||||
let legacy = |s: &str| {
|
||||
let wanted = normalize(s);
|
||||
std::iter::once(BlendMode::PassThrough)
|
||||
.chain(BlendMode::layer_modes())
|
||||
.find(|mode| normalize(mode.label()) == wanted || normalize(&format!("{mode:?}")) == wanted)
|
||||
};
|
||||
for mode in std::iter::once(BlendMode::PassThrough).chain(BlendMode::layer_modes()) {
|
||||
for name in [mode.label().to_owned(), format!("{mode:?}"), mode.label().to_ascii_uppercase().replace(' ', "_-")] {
|
||||
assert_eq!(super::parse_blend(&name), legacy(&name), "{name}");
|
||||
}
|
||||
}
|
||||
for name in ["", "not a mode", "color.burn", "é"] {
|
||||
assert_eq!(super::parse_blend(name), legacy(name), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canonical_keys_match_legacy_panel_names_and_round_trip() {
|
||||
for mode in std::iter::once(BlendMode::PassThrough).chain(BlendMode::layer_modes()) {
|
||||
let old = mode.label().to_ascii_lowercase().replace([' ', '_', '-', '(', ')'], "");
|
||||
assert_eq!(mode.key(), old);
|
||||
assert_eq!(BlendMode::from_key(&old), Some(mode));
|
||||
}
|
||||
assert_eq!(BlendMode::from_key("no-such-mode"), None);
|
||||
}
|
||||
}
|
||||
@@ -1704,7 +1704,8 @@ fn normal_onto_nothing_is_exact() {
|
||||
};
|
||||
let mut d = doc(4, 6);
|
||||
d.layers =
|
||||
vec![build(&LayerSpec::Group { children: vec![shape, inv], pass_through: false, blend: BlendMode::Normal, opacity: 1.0, fill: 1.0, mask: None })];
|
||||
vec![build(&LayerSpec::Group { children: vec![shape, inv], pass_through: false, blend: BlendMode::Normal, opacity: 1.0, fill: 1.0, mask: None })]
|
||||
.into();
|
||||
assert_matches_reference(&d);
|
||||
assert_eq!(render1(&d, 0, 0)[..4], [0.0; 4]);
|
||||
}
|
||||
|
||||
@@ -624,7 +624,8 @@ fn chisel_fields_do_not_depend_on_the_threads() {
|
||||
for (k, m) in maps.iter().enumerate() {
|
||||
for reach in [3.0f32, 12.0] {
|
||||
let one = with_threads(1, || (sharp_edges(m), distance_field_of(m, reach)));
|
||||
for threads in [2, 5, 16] {
|
||||
// 2 threads give groups of several units with a short last one, 16 one unit a group: the two ways `par_units` splits work (#15652).
|
||||
for threads in [2, 16] {
|
||||
let many = with_threads(threads, || (sharp_edges(m), distance_field_of(m, reach)));
|
||||
assert_eq!(one.0.slot, many.0.slot, "map {k} sharp slots on {threads} threads");
|
||||
let edges = |s: &SharpEdges| {
|
||||
@@ -675,7 +676,8 @@ fn bevel_maps_do_not_depend_on_the_threads() {
|
||||
}
|
||||
let run = || bevel_maps(shape, &b, &light, &tex, &PreparedPatterns::new(&pats, PREPARED_PATTERN_BYTES)).0;
|
||||
let one = with_threads(1, run);
|
||||
for threads in [2, 5, 16] {
|
||||
// 2 threads give groups of several units with a short last one, 16 one unit a group: the two ways `par_units` splits work (#15652).
|
||||
for threads in [2, 16] {
|
||||
let many = with_threads(threads, run);
|
||||
assert_eq!(one.len(), many.len());
|
||||
for (j, (a, m)) in one.iter().zip(&many).enumerate() {
|
||||
|
||||
@@ -170,10 +170,10 @@ fn a_stroked_shapes_mask_applies_to_fill_and_stroke_together() {
|
||||
assert!(close4(p, [0.0, 1.0, 0.0, 0.5]), "{p:?}");
|
||||
// With effects too.
|
||||
l.effects.items = vec![Effect::ColorOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), color: Color::rgb(1.0, 1.0, 1.0) }];
|
||||
d.layers = vec![l.clone()];
|
||||
d.layers = vec![l.clone()].into();
|
||||
let p = px(&d, 12, 20);
|
||||
assert!(close4(p, [0.0, 1.0, 0.0, 0.5]), "without clipped layers: {p:?}");
|
||||
d.layers = vec![l, clip];
|
||||
d.layers = vec![l, clip].into();
|
||||
let p = px(&d, 12, 20);
|
||||
assert!(close4(p, [0.0, 1.0, 0.0, 0.5]), "{p:?}");
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ fn every_blend_mode_matches_reference_on_opaque_pixels() {
|
||||
let mut top = Layer::raster("t", PixelFormat::RGBA32F);
|
||||
top.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 2, 2), &source);
|
||||
top.blend = mode;
|
||||
d.layers = vec![bottom, top];
|
||||
d.layers = vec![bottom, top].into();
|
||||
let got = px(&d, 0, 0);
|
||||
// A 32-bit document: Add / Divide don't clip at 1 (Divide gives 0.6 / 0.2 = 3 in red).
|
||||
psblend::HDR.with(|h| h.set(true));
|
||||
@@ -434,7 +434,7 @@ fn full_coverage_adjustment_keeps_its_result_over_huge_hdr_values() {
|
||||
dither: false,
|
||||
source: None,
|
||||
};
|
||||
d.layers = vec![base, Layer::new("look", LayerContent::Adjustment(look))];
|
||||
d.layers = vec![base, Layer::new("look", LayerContent::Adjustment(look))].into();
|
||||
let got = px(&d, 0, 0);
|
||||
for c in &got[..3] {
|
||||
assert!((c - 0.5).abs() < 1e-6, "{v}: {got:?}");
|
||||
@@ -479,7 +479,7 @@ fn blend_px(depth: SampleType, mode: BlendMode, bottom: [f32; 3], top: [f32; 3])
|
||||
let mut t = Layer::raster("t", fmt);
|
||||
t.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 1, 1), &photocraft_raster::from_rgba(&fmt, [top[0], top[1], top[2], 1.0]));
|
||||
t.blend = mode;
|
||||
d.layers = vec![b, t];
|
||||
d.layers = vec![b, t].into();
|
||||
px(&d, 0, 0)
|
||||
}
|
||||
|
||||
@@ -3294,7 +3294,7 @@ fn exposure_scales_32_bit_samples_as_stored() {
|
||||
let mut d = Document::new("e", Size::new(1, 1), ColorMode::Rgb, depth);
|
||||
let mut l = Layer::raster("px", fmt);
|
||||
l.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 1, 1), &[0.2, 0.2, 0.2, 1.0]);
|
||||
d.layers = vec![l, Layer::new("exp", LayerContent::Adjustment(plus_one_stop.clone()))];
|
||||
d.layers = vec![l, Layer::new("exp", LayerContent::Adjustment(plus_one_stop.clone()))].into();
|
||||
let got = px(&d, 0, 0)[0];
|
||||
assert!((got - want).abs() < 2e-3, "{depth:?}: {got}");
|
||||
}
|
||||
@@ -3384,7 +3384,7 @@ fn float_adjustments_preserve_hdr_range() {
|
||||
let mut d = Document::new("HDR", Size::new(1, 1), ColorMode::Rgb, SampleType::F32);
|
||||
let mut l = Layer::raster("pixels", PixelFormat::RGBA32F);
|
||||
l.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 1, 1), &[4.0, 2.0, 0.5, 0.75]);
|
||||
d.layers = vec![l, Layer::new("adjustment", LayerContent::Adjustment(adj.clone()))];
|
||||
d.layers = vec![l, Layer::new("adjustment", LayerContent::Adjustment(adj.clone()))].into();
|
||||
let got = px(&d, 0, 0);
|
||||
for (a, b) in got[..3].iter().zip(want) {
|
||||
assert!((a - b).abs() < 1e-5, "{adj:?}: {got:?} vs {want:?}");
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::io::{Read, Seek, SeekFrom, Write};
|
||||
|
||||
#[test]
|
||||
fn failed_effect_build_is_not_reused_after_original_pixels_recover() {
|
||||
photocraft_raster::spill::use_test_volume_space();
|
||||
let dir = std::env::temp_dir().join(format!("photocraft-compose-scratch-retry-{}", std::process::id()));
|
||||
spill::configure(Some(&dir), 1).unwrap();
|
||||
let mut doc = Document::new("Shadow", Size::new(64, 64), ColorMode::Rgb, SampleType::U8);
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
//! The document's layer stack with a lazily built id index.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use crate::{Layer, LayerId, LayerPath};
|
||||
|
||||
/// Where a layer sits in the stack.
|
||||
#[derive(Clone, Debug)]
|
||||
struct Entry {
|
||||
path: LayerPath,
|
||||
parent: Option<LayerId>,
|
||||
}
|
||||
|
||||
/// Id to position for every layer, nested ones included.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct LayerIndex {
|
||||
entries: HashMap<LayerId, Entry>,
|
||||
serial: u64,
|
||||
}
|
||||
|
||||
static SERIAL: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
|
||||
|
||||
impl LayerIndex {
|
||||
fn build(layers: &[Layer]) -> Self {
|
||||
fn rec(layers: &[Layer], parent: Option<LayerId>, path: &mut LayerPath, out: &mut HashMap<LayerId, Entry>) {
|
||||
for (i, l) in layers.iter().enumerate() {
|
||||
path.push(i);
|
||||
out.entry(l.id).or_insert_with(|| Entry { path: path.clone(), parent });
|
||||
if let Some(ch) = l.children() {
|
||||
rec(ch, Some(l.id), path, out);
|
||||
}
|
||||
path.pop();
|
||||
}
|
||||
}
|
||||
let mut entries = HashMap::with_capacity(layers.len());
|
||||
rec(layers, None, &mut Vec::new(), &mut entries);
|
||||
Self { entries, serial: SERIAL.fetch_add(1, std::sync::atomic::Ordering::Relaxed) }
|
||||
}
|
||||
|
||||
/// The layer's path from the root. Paths order layers bottom-to-top as the depth-first walk does.
|
||||
pub fn path(&self, id: LayerId) -> Option<&[usize]> {
|
||||
self.entries.get(&id).map(|e| e.path.as_slice())
|
||||
}
|
||||
|
||||
/// The group holding the layer; `None` at the root or for an unknown id.
|
||||
pub fn parent(&self, id: LayerId) -> Option<LayerId> {
|
||||
self.entries.get(&id)?.parent
|
||||
}
|
||||
|
||||
/// Nesting depth: 0 at the root.
|
||||
pub fn depth(&self, id: LayerId) -> Option<usize> {
|
||||
self.entries.get(&id).map(|e| e.path.len() - 1)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.entries.is_empty()
|
||||
}
|
||||
|
||||
/// A number unique to this build: it differs between two builds, so equal serials mean the
|
||||
/// same index (tests count rebuilds with it).
|
||||
pub fn serial(&self) -> u64 {
|
||||
self.serial
|
||||
}
|
||||
}
|
||||
|
||||
/// The layer stack, bottom-to-top, with an index from layer id to position built on the first
|
||||
/// lookup.
|
||||
///
|
||||
/// The stack is a public vector that code edits in place, nested groups included, so no mutator
|
||||
/// method can be the place that drops the index. Every route to a `&mut Layer` or `&mut Vec`
|
||||
/// goes through `DerefMut`, so the reset lives there: any write drops the index, and the next
|
||||
/// lookup rebuilds it once. `Clone` starts without an index.
|
||||
#[derive(Default)]
|
||||
pub struct LayerTree {
|
||||
layers: Vec<Layer>,
|
||||
index: OnceLock<LayerIndex>,
|
||||
}
|
||||
|
||||
impl LayerTree {
|
||||
/// The id index, built on first use after the last write.
|
||||
pub fn index(&self) -> &LayerIndex {
|
||||
self.index.get_or_init(|| LayerIndex::build(&self.layers))
|
||||
}
|
||||
}
|
||||
|
||||
/// `Vec` methods that callers pass `&document` into (`doc.layers.push(make(&doc))`): as methods
|
||||
/// on the tree the receiver borrow is two-phase, which it is not through `DerefMut`.
|
||||
impl LayerTree {
|
||||
pub fn push(&mut self, layer: Layer) {
|
||||
self.deref_mut().push(layer);
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, at: usize, layer: Layer) {
|
||||
self.deref_mut().insert(at, layer);
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LayerTree {
|
||||
type Target = Vec<Layer>;
|
||||
fn deref(&self) -> &Vec<Layer> {
|
||||
&self.layers
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for LayerTree {
|
||||
fn deref_mut(&mut self) -> &mut Vec<Layer> {
|
||||
self.index = OnceLock::new();
|
||||
&mut self.layers
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for LayerTree {
|
||||
fn clone(&self) -> Self {
|
||||
Self { layers: self.layers.clone(), index: OnceLock::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for LayerTree {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.layers == other.layers
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for LayerTree {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.layers.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<Layer>> for LayerTree {
|
||||
fn from(layers: Vec<Layer>) -> Self {
|
||||
Self { layers, index: OnceLock::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a LayerTree {
|
||||
type Item = &'a Layer;
|
||||
type IntoIter = std::slice::Iter<'a, Layer>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.layers.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a mut LayerTree {
|
||||
type Item = &'a mut Layer;
|
||||
type IntoIter = std::slice::IterMut<'a, Layer>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.deref_mut().iter_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<Layer> for LayerTree {
|
||||
fn from_iter<I: IntoIterator<Item = Layer>>(iter: I) -> Self {
|
||||
iter.into_iter().collect::<Vec<_>>().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for LayerTree {
|
||||
type Item = Layer;
|
||||
type IntoIter = std::vec::IntoIter<Layer>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.layers.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::PixelFormat;
|
||||
|
||||
fn layers(n: usize) -> LayerTree {
|
||||
(0..n).map(|i| Layer::raster(format!("l{i}"), PixelFormat::RGBA8)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_builds_once_per_edit() {
|
||||
let mut t = layers(200);
|
||||
let id = t[150].id;
|
||||
let first = t.index().serial();
|
||||
for _ in 0..100 {
|
||||
assert_eq!(t.index().path(id), Some(&[150][..]));
|
||||
}
|
||||
assert_eq!(t.index().serial(), first, "lookups reuse the index");
|
||||
t.push(Layer::raster("new", PixelFormat::RGBA8));
|
||||
let second = t.index().serial();
|
||||
assert_ne!(second, first, "an edit rebuilds it");
|
||||
assert_eq!(t.index().serial(), second);
|
||||
let _ = &mut t[3];
|
||||
assert_ne!(t.index().serial(), second, "any mutable access drops it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clone_after_edit_does_not_reuse_the_index() {
|
||||
let mut t = layers(5);
|
||||
let old = t.index().serial();
|
||||
let new_id = {
|
||||
t.insert(0, Layer::raster("below", PixelFormat::RGBA8));
|
||||
t[0].id
|
||||
};
|
||||
let c = t.clone();
|
||||
assert_ne!(c.index().serial(), old);
|
||||
assert_eq!(c.index().path(new_id), Some(&[0][..]));
|
||||
assert_eq!(t.index().path(new_id), Some(&[0][..]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_edits_reset_and_paths_follow_walk_order() {
|
||||
let inner = Layer::raster("in", PixelFormat::RGBA8);
|
||||
let inner_id = inner.id;
|
||||
let group = Layer::group("g", vec![inner]);
|
||||
let group_id = group.id;
|
||||
let mut t: LayerTree = vec![Layer::raster("a", PixelFormat::RGBA8), group].into();
|
||||
assert_eq!(t.index().path(inner_id), Some(&[1, 0][..]));
|
||||
assert_eq!(t.index().parent(inner_id), Some(group_id));
|
||||
assert_eq!(t.index().depth(inner_id), Some(1));
|
||||
let before = t.index().serial();
|
||||
t[1].children_mut().unwrap().insert(0, Layer::raster("x", PixelFormat::RGBA8));
|
||||
assert_eq!(t.index().path(inner_id), Some(&[1, 1][..]));
|
||||
assert_ne!(t.index().serial(), before);
|
||||
}
|
||||
}
|
||||
+31
-18
@@ -16,6 +16,7 @@ pub mod comps;
|
||||
pub mod effects;
|
||||
pub mod frame;
|
||||
pub mod import_conversion;
|
||||
pub mod layer_tree;
|
||||
pub mod mode;
|
||||
pub mod pattern;
|
||||
pub mod slices;
|
||||
@@ -901,7 +902,7 @@ pub struct Document {
|
||||
pub depth: SampleType,
|
||||
pub icc_profile: Option<Arc<Vec<u8>>>,
|
||||
/// Bottom-to-top.
|
||||
pub layers: Vec<Layer>,
|
||||
pub layers: layer_tree::LayerTree,
|
||||
pub channels: Vec<AlphaChannel>,
|
||||
pub guides: Guides,
|
||||
/// The rulers' zero point in document pixels (`[x, y]`), dragged from the ruler corner. The
|
||||
@@ -1004,7 +1005,7 @@ impl Document {
|
||||
mode,
|
||||
depth,
|
||||
icc_profile: None,
|
||||
layers: Vec::new(),
|
||||
layers: Default::default(),
|
||||
channels: Vec::new(),
|
||||
guides: Guides::default(),
|
||||
ruler_origin: [0.0, 0.0],
|
||||
@@ -1161,18 +1162,7 @@ impl Document {
|
||||
}
|
||||
|
||||
pub fn path_of(&self, id: LayerId) -> Option<LayerPath> {
|
||||
fn rec(layers: &[Layer], id: LayerId, path: &mut LayerPath) -> bool {
|
||||
for (i, l) in layers.iter().enumerate() {
|
||||
path.push(i);
|
||||
if l.id == id || l.children().is_some_and(|ch| rec(ch, id, path)) {
|
||||
return true;
|
||||
}
|
||||
path.pop();
|
||||
}
|
||||
false
|
||||
}
|
||||
let mut path = Vec::new();
|
||||
rec(&self.layers, id, &mut path).then_some(path)
|
||||
self.layers.index().path(id).map(<[usize]>::to_vec)
|
||||
}
|
||||
|
||||
/// The locks in force on the layer at `path`: its own and those of every group around it,
|
||||
@@ -1211,10 +1201,7 @@ impl Document {
|
||||
}
|
||||
|
||||
pub fn layer(&self, id: LayerId) -> Option<&Layer> {
|
||||
fn rec(layers: &[Layer], id: LayerId) -> Option<&Layer> {
|
||||
layers.iter().find_map(|l| if l.id == id { Some(l) } else { l.children().and_then(|ch| rec(ch, id)) })
|
||||
}
|
||||
rec(&self.layers, id)
|
||||
self.layer_at(self.layers.index().path(id)?)
|
||||
}
|
||||
|
||||
pub fn layer_mut(&mut self, id: LayerId) -> Option<&mut Layer> {
|
||||
@@ -1394,6 +1381,32 @@ mod tests {
|
||||
assert_eq!(d.unused_link_group(), Some(3));
|
||||
}
|
||||
|
||||
/// Id lookups share one index per document state: 100 lookups on 200 layers build it once,
|
||||
/// an edit builds it once more, and a clone built after the edit has its own.
|
||||
#[test]
|
||||
fn layer_lookups_share_one_index_per_state() {
|
||||
let mut d = doc();
|
||||
for i in 0..199 {
|
||||
d.layers.push(Layer::raster(format!("l{i}"), PixelFormat::RGBA8));
|
||||
}
|
||||
let ids: Vec<LayerId> = d.layers.iter().map(|l| l.id).collect();
|
||||
let first = d.layers.index().serial();
|
||||
for i in 0..100 {
|
||||
let id = ids[i * 2];
|
||||
assert_eq!(d.layer(id).unwrap().id, id);
|
||||
assert_eq!(d.path_of(id), Some(vec![i * 2]));
|
||||
}
|
||||
assert_eq!(d.layers.index().serial(), first);
|
||||
assert!(d.shift(ids[10], 1));
|
||||
assert_eq!(d.path_of(ids[10]), Some(vec![11]));
|
||||
let second = d.layers.index().serial();
|
||||
assert_ne!(second, first);
|
||||
d.layer_mut(ids[3]).unwrap().name = "x".into();
|
||||
let copy = d.clone();
|
||||
assert_ne!(copy.layers.index().serial(), d.layers.index().serial());
|
||||
assert_eq!(copy.layer(ids[3]).unwrap().name, "x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_document_has_locked_background() {
|
||||
let d = doc();
|
||||
|
||||
@@ -16,7 +16,7 @@ photocraft-geom = { workspace = true }
|
||||
photocraft-color = { workspace = true }
|
||||
craft-cms = { workspace = true }
|
||||
# PCTIP codec from craft-libs#1564; isolated pin until the shared revision is adopted workspace-wide.
|
||||
craft-pcraft-tip = { package = "craft-pcraft-format", git = "https://github.com/storytold/craft-libs", rev = "18ffc07519b15f5ef39e752aa0f405261fec8ebb" }
|
||||
craft-pcraft-tip = { package = "craft-pcraft-format", git = "https://github.com/storytold/craft-libs", rev = "04ba41419b99967e4d2b990cdfe5d80184be64ee" }
|
||||
photocraft-raster = { workspace = true }
|
||||
photocraft-doc = { workspace = true }
|
||||
photocraft-ops = { workspace = true }
|
||||
|
||||
@@ -52,7 +52,7 @@ fn library_tip_bytes(s: &Session) -> (usize, u64, u64) {
|
||||
previews += g.data.len() as u64 * 2;
|
||||
}
|
||||
};
|
||||
for p in &s.tools.presets {
|
||||
for p in s.tools.presets.iter() {
|
||||
let b = &p.brush;
|
||||
for t in [&b.tip, &b.dual_brush.tip] {
|
||||
match t {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The command registry. Ids follow Photoshop's menu structure (see the parity checklist).
|
||||
|
||||
use photocraft_color::{BlendMode, Color, ColorMode, SampleType};
|
||||
use photocraft_color::{Color, ColorMode, SampleType};
|
||||
use photocraft_doc::{Adjustment, Document, Fill, Layer, LayerContent, LayerId, LayerMask, Size};
|
||||
use photocraft_geom::{Rect, TILE_SIZE};
|
||||
use photocraft_raster::Surface;
|
||||
@@ -189,13 +189,13 @@ use adjust_params::{adjust_mode, destructive_adjust, doc_mode, new_adjustment};
|
||||
pub use adjust_params::{adjustment_from_params, adjustment_kind};
|
||||
pub(crate) use enabled::{always, check_all_unlocked, check_pixels_unlocked, has_paintable, is_mask_target, paint_surface};
|
||||
use enabled::{can_redo, can_undo, has_doc, has_layer, has_pixel_or_channel, has_selection};
|
||||
pub use layer_params::blend_from_str;
|
||||
pub(crate) use layer_params::{NEW_LAYER_PATH, explicit_layer, layer_listing, layer_panel_option, layer_param, mask_at_depth, mask_new_layer, selection_mask};
|
||||
pub(crate) use layer_references::{recorded_drop, recorded_layer};
|
||||
use ops::{arrange, merge_group, move_mask, set_mask, set_mask_and_deselect};
|
||||
pub(crate) use ops::{layer_copy, translate_layer, translate_layer_wrapped};
|
||||
use params::{bad, set_clipped};
|
||||
pub(crate) use params::{check_f32_values, cmyk_param, color_param, int, int_i32, parse_hex, u32_id, u32_id_param};
|
||||
pub use photocraft_color::blend::parse_blend;
|
||||
|
||||
pub fn command_specs() -> &'static [CommandSpec] {
|
||||
®istry().specs
|
||||
@@ -726,7 +726,7 @@ fn build() -> Vec<CommandSpec> {
|
||||
// The Background has no opacity, fill or blend mode: like Photoshop, setting
|
||||
// one that changes its look turns it into a normal layer ("Layer 0") first.
|
||||
let num = |k: &str| p.get(k).and_then(Value::as_f64).is_some_and(|v| v < 1.0);
|
||||
let blends = p.get("blend").and_then(Value::as_str).and_then(blend_from_str).is_some_and(|b| b != photocraft_color::BlendMode::Normal);
|
||||
let blends = p.get("blend").and_then(Value::as_str).and_then(parse_blend).is_some_and(|b| b != photocraft_color::BlendMode::Normal);
|
||||
for &id in &ids {
|
||||
if num("opacity") || num("fill") || blends {
|
||||
crate::extra_cmds::background_to_layer(doc, id);
|
||||
@@ -745,7 +745,7 @@ fn build() -> Vec<CommandSpec> {
|
||||
l.fill_opacity = v;
|
||||
}
|
||||
if let Some(v) = p.get("blend").and_then(Value::as_str) {
|
||||
let b = blend_from_str(v).ok_or_else(|| bad("layer.setProps", format!("unknown blend mode `{v}`")))?;
|
||||
let b = parse_blend(v).ok_or_else(|| bad("layer.setProps", format!("unknown blend mode `{v}`")))?;
|
||||
// Pass Through is a group's mode only, as in Photoshop.
|
||||
if b == photocraft_color::BlendMode::PassThrough && !l.is_group() {
|
||||
return Err(bad("layer.setProps", format!("Pass Through applies to groups only; layer {} isn't one", l.id.0)));
|
||||
@@ -894,7 +894,7 @@ fn build() -> Vec<CommandSpec> {
|
||||
bg.locks.position = true;
|
||||
*crate::pixels_mut(&mut bg)? = photocraft_compose::flatten_to_surface(doc, fmt, Some([1.0, 1.0, 1.0]));
|
||||
*active = Some(bg.id);
|
||||
doc.layers = vec![bg];
|
||||
doc.layers = vec![bg].into();
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(Value::Null)
|
||||
|
||||
@@ -652,7 +652,7 @@ fn hdr_toning(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
bg.locks.position = true;
|
||||
crate::pixels_mut(&mut bg)?.write_region(doc.bounds(), &data);
|
||||
*active = Some(bg.id);
|
||||
doc.layers = vec![bg];
|
||||
doc.layers = vec![bg].into();
|
||||
doc.selection = None;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -24,7 +24,7 @@ pub(super) fn new_adjustment(s: &mut Session, adj: Adjustment, p: &Value, cmd: &
|
||||
None | Some(Value::Null) => BlendMode::Normal,
|
||||
Some(v) => {
|
||||
let m = v.as_str().ok_or_else(|| bad("`mode` must be a blend mode name".into()))?;
|
||||
crate::commands::blend_from_str(m).filter(|b| *b != BlendMode::PassThrough).ok_or_else(|| bad(format!("unknown layer blend mode `{m}`")))?
|
||||
crate::commands::parse_blend(m).filter(|b| *b != BlendMode::PassThrough).ok_or_else(|| bad(format!("unknown layer blend mode `{m}`")))?
|
||||
}
|
||||
};
|
||||
let clip = match p.get("clipToPrevious") {
|
||||
|
||||
@@ -643,7 +643,7 @@ pub fn artboard_document(doc: &Document, id: LayerId) -> Result<Option<Document>
|
||||
let mut one = doc.clone();
|
||||
one.name = l.name.clone();
|
||||
one.size = Size::new(r.width(), r.height());
|
||||
one.layers = vec![group];
|
||||
one.layers = vec![group].into();
|
||||
one.channels.clear();
|
||||
one.selection = None;
|
||||
one.quick_mask = None;
|
||||
@@ -659,10 +659,126 @@ pub fn artboard_document(doc: &Document, id: LayerId) -> Result<Option<Document>
|
||||
Ok(Some(one))
|
||||
}
|
||||
|
||||
/// Include Overlapping Areas: each visible artboard stacked above board `id` that overlaps it, as
|
||||
/// the reference application writes it into the board's file: a plain group (no longer an
|
||||
/// artboard) holding its layers over a new pixel layer "Background for <board>" filled with the
|
||||
/// board's background where the two boards overlap, in source coordinates and bottom to top. A
|
||||
/// group whose layers reach past its own board (effects, pixels outside the board, adjustments)
|
||||
/// gets a hard mask to its board, which the artboard clipped them to.
|
||||
///
|
||||
/// The artboard painted its background beneath the group and then composited the group (its
|
||||
/// blend mode, opacity, effects and masks) over it. A board with any of those keeps them on a
|
||||
/// group of its own inside the plain group, above the background, so they still apply to its
|
||||
/// layers only and its own mask keeps its feather and Layer Mask Hides Effects setting; the plain
|
||||
/// group then carries nothing but the board clip.
|
||||
fn overlapping_boards(doc: &Document, id: LayerId, rect: Rect) -> Vec<Layer> {
|
||||
let above = doc.layers.iter().skip_while(|l| l.id != id).skip(1);
|
||||
let mut out = Vec::new();
|
||||
for l in above.filter(|l| l.visible) {
|
||||
let Some(ab) = l.artboard().cloned() else { continue };
|
||||
let overlap = ab.rect.intersect(&rect);
|
||||
if overlap.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut board = l.clone();
|
||||
if let LayerContent::Group(g) = &mut board.content {
|
||||
g.artboard = None;
|
||||
cut_pixels(&mut g.children, overlap, 0);
|
||||
}
|
||||
let bg = ab.background.rgba();
|
||||
let mut group = if stacks_like_its_layers(&board) {
|
||||
board
|
||||
} else {
|
||||
board.clipped = false;
|
||||
let mut plain = Layer::group(l.name.clone(), vec![board]);
|
||||
plain.label = l.label;
|
||||
plain
|
||||
};
|
||||
if let (Some(bg), Some(children)) = (bg, group.children_mut()) {
|
||||
let fmt = doc.pixel_format();
|
||||
let mut surf = Surface::new(fmt);
|
||||
surf.fill_rect(overlap, &photocraft_raster::from_rgba(&fmt, bg));
|
||||
children.insert(0, Layer::new(format!("Background for {}", l.name), LayerContent::Raster(surf)));
|
||||
}
|
||||
// With the background in place: its pixels widen what the group's layers can reach.
|
||||
let reach = photocraft_compose::change_bounds(&group, doc.bounds());
|
||||
if reach.is_none_or(|r| !ab.rect.contains_rect(&r)) {
|
||||
let mut mask = photocraft_doc::LayerMask::reveal_all();
|
||||
mask.surface = Surface::with_default(PixelFormat::GRAY8, &[0.0]);
|
||||
mask.surface.fill_rect(ab.rect, &[1.0]);
|
||||
group.mask = Some(mask);
|
||||
}
|
||||
out.push(group);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether artboard `board` (already a plain group) composites over its background exactly as
|
||||
/// its layers stacked over that background in one pass-through group do: pass-through (a Normal
|
||||
/// group renders its layers on their own first, so a Multiply or Screen layer in it never blends
|
||||
/// with the background), and no effects, masks, opacity, Blend If or other blending options of
|
||||
/// its own, nor a mask the board clip would replace.
|
||||
fn stacks_like_its_layers(board: &Layer) -> bool {
|
||||
board.blend == photocraft_color::BlendMode::PassThrough
|
||||
&& board.opacity >= 1.0
|
||||
&& board.fill_opacity >= 1.0
|
||||
&& board.mask.is_none()
|
||||
&& board.vector_mask.is_none()
|
||||
&& board.frame.is_none()
|
||||
&& board.excluded_channels == 0
|
||||
&& board.blend_if == photocraft_doc::BlendIf::default()
|
||||
&& board.advanced == photocraft_doc::AdvancedBlending::default()
|
||||
&& !photocraft_compose::effects::has_effects(board)
|
||||
}
|
||||
|
||||
/// Cuts the pixel layers in `layers` (and in groups inside them, `depth` levels down so far) to
|
||||
/// `keep`, as the reference application cuts an overlapping board's layers to the file. Layers
|
||||
/// whose pixels can't be cut stay whole; the group's mask still hides what lies past its board.
|
||||
/// A layer with effects, or inside a group with effects, stays whole too: pixels outside `keep`
|
||||
/// can cast a shadow or glow into it.
|
||||
fn cut_pixels(layers: &mut [Layer], keep: Rect, depth: usize) {
|
||||
const MAX_DEPTH: usize = 64;
|
||||
for l in layers {
|
||||
if photocraft_compose::effects::has_effects(l) {
|
||||
continue;
|
||||
}
|
||||
match &mut l.content {
|
||||
LayerContent::Group(g) if depth < MAX_DEPTH => cut_pixels(&mut g.children, keep, depth + 1),
|
||||
LayerContent::Raster(surf) => {
|
||||
let r = surf.content_bounds().intersect(&keep);
|
||||
let mut cut = Surface::with_default(surf.format(), &surf.default_pixel());
|
||||
if !r.is_empty() {
|
||||
let Ok(px) = surf.try_read_region(r) else { continue };
|
||||
if cut.try_write_region(r, &px).is_err() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*surf = cut;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// [`artboard_document`] for each chosen board, all built before any file is written so a
|
||||
/// board that can't be exported fails the export without leaving a partial set behind.
|
||||
fn chosen_documents(doc: &Document, p: &Value) -> Result<Vec<Document>> {
|
||||
chosen_artboards(doc, p).into_iter().filter_map(|id| artboard_document(doc, id).transpose()).collect()
|
||||
/// board that can't be exported fails the export without leaving a partial set behind. With
|
||||
/// `overlapping`, each file also holds the boards above that overlap it ([`overlapping_boards`]).
|
||||
fn chosen_documents(doc: &Document, p: &Value, overlapping: bool) -> Result<Vec<Document>> {
|
||||
let mut out = Vec::new();
|
||||
for id in chosen_artboards(doc, p) {
|
||||
let Some(mut one) = artboard_document(doc, id)? else { continue };
|
||||
if overlapping && let Some(r) = doc.layer(id).and_then(|l| l.artboard()).map(|a| a.rect) {
|
||||
// `artboard_document` has checked that the board's origin negates.
|
||||
let (dx, dy) = (r.x0.saturating_neg(), r.y0.saturating_neg());
|
||||
for mut group in overlapping_boards(doc, id, r) {
|
||||
crate::commands::translate_layer(doc, &mut group, dx, dy);
|
||||
crate::vector_cmds::translate_vectors(doc, &mut group, f64::from(dx), f64::from(dy));
|
||||
one.layers.push(group);
|
||||
}
|
||||
}
|
||||
out.push(one);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The artboards an export covers: `"artboards": [ids]`, else all, top of the Layers panel first.
|
||||
@@ -735,8 +851,16 @@ fn artboards_to_files(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let save = SaveOpts::from_params(s, p, cmd)?;
|
||||
let d = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let prefix = p.get("prefix").and_then(Value::as_str).map(str::to_string).unwrap_or_else(|| stem(&d.doc.name));
|
||||
let overlapping = match p.get("content") {
|
||||
None | Some(Value::Null) => true,
|
||||
Some(v) => match v.as_str() {
|
||||
Some("overlapping") => true,
|
||||
Some("artboard") => false,
|
||||
_ => return Err(bad(cmd, format!("`content` must be \"overlapping\" or \"artboard\", not {v}"))),
|
||||
},
|
||||
};
|
||||
let doc = d.doc.clone();
|
||||
let boards = chosen_documents(&doc, p)?;
|
||||
let boards = chosen_documents(&doc, p, overlapping)?;
|
||||
let names: Vec<&str> = boards.iter().map(|one| one.name.as_str()).collect();
|
||||
let mut files = Vec::new();
|
||||
for (one, name) in boards.iter().zip(artboard_file_stems(&prefix, &names, HYPHENATED_FORMATS.contains(&format.as_str()))) {
|
||||
@@ -806,7 +930,7 @@ fn artboards_to_pdf(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut pages = Vec::new();
|
||||
// Pages go bottom artboard of the Layers panel first, as in the reference application (#13643);
|
||||
// `chosen_documents` lists them top first, the order Artboards to Files keeps.
|
||||
for one in chosen_documents(&doc, p)?.into_iter().rev() {
|
||||
for one in chosen_documents(&doc, p, false)?.into_iter().rev() {
|
||||
let buf = photocraft_compose::flatten(&one).over_background([1.0, 1.0, 1.0]);
|
||||
let fmt = PixelFormat::new(ColorMode::Rgb, SampleType::U8, true);
|
||||
let mut flat = Document::new(&one.name, one.size, ColorMode::Rgb, SampleType::U8);
|
||||
@@ -883,7 +1007,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"file.export.artboardsToFiles",
|
||||
"Artboards to Files…",
|
||||
&["File", "Export"],
|
||||
r##"{"dir":folder,"format":"png|jpg|psd|tiff|…"="png","prefix":str=document name ("" = none),"artboards":[id]? (default all),"quality":0..12?} → {files} (one "<prefix><artboard name>.<format>" per board, no separator or index added: spaces become "-" in PNG, JPEG, BMP, Targa and TIFF and stay in PSD and other formats, characters a file name can't hold become "_", and a name an earlier board already took, ignoring case, gets "-2", "-3"…)"##,
|
||||
r##"{"dir":folder,"format":"png|jpg|psd|tiff|…"="png","prefix":str=document name ("" = none),"content":"overlapping|artboard"="overlapping" (Include Overlapping Areas: a board's file also shows the visible boards above it where they overlap it, each as a plain group with a \"Background for <board>\" layer; artboard: Artboard Content Only),"artboards":[id]? (default all),"quality":0..12?} → {files} (one "<prefix><artboard name>.<format>" per board, no separator or index added: spaces become "-" in PNG, JPEG, BMP, Targa and TIFF and stay in PSD and other formats, characters a file name can't hold become "_", and a name an earlier board already took, ignoring case, gets "-2", "-3"…)"##,
|
||||
export_artboards,
|
||||
artboards_to_files
|
||||
),
|
||||
@@ -905,6 +1029,9 @@ mod file_names_tests;
|
||||
#[path = "artboard_cmds/first_board_background_tests.rs"]
|
||||
mod first_board_background_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "artboard_cmds/overlapping_areas_tests.rs"]
|
||||
mod overlapping_areas_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "artboard_cmds/pdf_page_order_tests.rs"]
|
||||
mod pdf_page_order_tests;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
//! Artboards to Files › Include Overlapping Areas / Artboard Content Only (#13629): the boards
|
||||
//! stacked above an exported board that overlap it show in its file (PNG pixels, PSD structure),
|
||||
//! boards below never do, and the source document is left alone.
|
||||
|
||||
use super::*;
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
const RED: [u8; 3] = [220, 30, 30];
|
||||
const BLUE: [u8; 3] = [30, 30, 220];
|
||||
const WHITE: [u8; 3] = [255, 255, 255];
|
||||
|
||||
/// The measured test document: 800 x 400, transparent, bottom to top `Red Board` 0,0-200,150
|
||||
/// (pixel layer `Red` at 20,20-120,100), `Blue Board` 120,30-320,230 (pixel layer `Blue` at
|
||||
/// 130,40-230,140) and `Empty Board` 600,0-700,100, all with white backgrounds.
|
||||
fn session(depth: u32) -> (Session, [u64; 3]) {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 800, "height": 400, "depth": depth, "background": "transparent"})).unwrap();
|
||||
let board =
|
||||
|s: &mut Session, name: &str, rect: [i64; 4]| s.execute("layer.new.artboard", json!({"rect": rect, "name": name})).unwrap()["layer"].as_u64().unwrap();
|
||||
let red = board(&mut s, "Red Board", [0, 0, 200, 150]);
|
||||
let blue = board(&mut s, "Blue Board", [120, 30, 200, 200]);
|
||||
let empty = board(&mut s, "Empty Board", [600, 0, 100, 100]);
|
||||
paint(&mut s, red, "Red", Rect::new(20, 20, 120, 100), RED);
|
||||
paint(&mut s, blue, "Blue", Rect::new(130, 40, 230, 140), BLUE);
|
||||
(s, [red, blue, empty])
|
||||
}
|
||||
|
||||
/// A pixel layer `name` of `color` over `rect`, on top of board `board`'s layers.
|
||||
fn paint(s: &mut Session, board: u64, name: &str, rect: Rect, color: [u8; 3]) {
|
||||
s.edit(name, |doc, _| {
|
||||
let fmt = doc.pixel_format();
|
||||
let mut l = Layer::raster(name, fmt);
|
||||
let [r, g, b] = color.map(|c| f32::from(c) / 255.0);
|
||||
l.surface_mut().unwrap().fill_rect(rect, &photocraft_raster::from_rgba(&fmt, [r, g, b, 1.0]));
|
||||
doc.layer_mut(LayerId(board)).unwrap().children_mut().unwrap().push(l);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
struct Out(std::path::PathBuf);
|
||||
|
||||
impl Out {
|
||||
fn new(tag: &str) -> Self {
|
||||
let dir = std::env::temp_dir().join(format!("photocraft-overlap-{tag}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
Out(dir)
|
||||
}
|
||||
fn dir(&self) -> String {
|
||||
self.0.to_string_lossy().into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Out {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Exports board `board` with `extra` params and reads the one file back.
|
||||
fn export(s: &mut Session, out: &Out, board: u64, extra: Value) -> Document {
|
||||
let mut p = json!({"dir": out.dir(), "prefix": "", "artboards": [board]});
|
||||
for (k, v) in extra.as_object().unwrap() {
|
||||
p[k] = v.clone();
|
||||
}
|
||||
let format = p.get("format").and_then(Value::as_str).unwrap_or("png").to_string();
|
||||
let r = s.execute("file.export.artboardsToFiles", p).unwrap();
|
||||
let files = r["files"].as_array().unwrap();
|
||||
assert_eq!(files.len(), 1, "{r}");
|
||||
let path = files[0].as_str().unwrap();
|
||||
photocraft_io::import(&format!("x.{format}"), &std::fs::read(path).unwrap()).unwrap().document
|
||||
}
|
||||
|
||||
/// The file's composite pixel at (x, y) as 8-bit RGBA.
|
||||
fn px(d: &Document, x: i32, y: i32) -> [u8; 4] {
|
||||
let flat = photocraft_compose::flatten(d);
|
||||
let w = d.size.width as usize;
|
||||
flat.px[y as usize * w + x as usize].map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8)
|
||||
}
|
||||
|
||||
fn rgb(p: [u8; 4]) -> [u8; 3] {
|
||||
[p[0], p[1], p[2]]
|
||||
}
|
||||
|
||||
fn names(layers: &[Layer]) -> Vec<&str> {
|
||||
layers.iter().map(|l| l.name.as_str()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn include_overlapping_areas_is_the_default_and_shows_the_board_above() {
|
||||
for depth in [8, 16] {
|
||||
let (mut s, [red, _, _]) = session(depth);
|
||||
let out = Out::new(&format!("default-{depth}"));
|
||||
for extra in [json!({}), json!({"content": "overlapping"})] {
|
||||
let f = export(&mut s, &out, red, extra.clone());
|
||||
assert_eq!((f.size.width, f.size.height), (200, 150), "{depth} bit {extra}");
|
||||
assert_eq!(rgb(px(&f, 150, 60)), BLUE, "{depth} bit {extra}: Blue's pixels");
|
||||
assert_eq!(rgb(px(&f, 125, 35)), WHITE, "{depth} bit {extra}: Blue Board's background");
|
||||
assert_eq!(rgb(px(&f, 125, 50)), WHITE, "{depth} bit {extra}: Blue Board's background");
|
||||
assert_eq!(rgb(px(&f, 110, 50)), RED, "{depth} bit {extra}: Red stays red");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn artboard_content_only_keeps_the_board_on_its_own() {
|
||||
let (mut s, [red, _, _]) = session(8);
|
||||
let out = Out::new("content-only");
|
||||
let f = export(&mut s, &out, red, json!({"content": "artboard"}));
|
||||
assert_eq!(rgb(px(&f, 150, 60)), WHITE, "nothing of Blue Board");
|
||||
assert_eq!(rgb(px(&f, 110, 50)), RED);
|
||||
let psd = export(&mut s, &out, red, json!({"content": "artboard", "format": "psd"}));
|
||||
assert_eq!(names(&psd.layers), ["Red Board"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_overlapping_psd_holds_the_board_above_as_a_plain_group_with_its_background() {
|
||||
let (mut s, [red, _, _]) = session(8);
|
||||
let out = Out::new("psd");
|
||||
let psd = export(&mut s, &out, red, json!({"format": "psd"}));
|
||||
assert_eq!((psd.size.width, psd.size.height), (200, 150));
|
||||
// Bottom to top: the exported artboard, then the overlapping board as a plain group.
|
||||
assert_eq!(names(&psd.layers), ["Red Board", "Blue Board"]);
|
||||
let [board, group] = [&psd.layers[0], &psd.layers[1]];
|
||||
assert_eq!(board.artboard().map(|a| a.rect), Some(Rect::new(0, 0, 200, 150)));
|
||||
assert_eq!(names(board.children().unwrap()), ["Red"]);
|
||||
assert!(matches!(&group.content, LayerContent::Group(g) if g.artboard.is_none()), "no longer an artboard");
|
||||
let kids = group.children().unwrap();
|
||||
assert_eq!(names(kids), ["Background for Blue Board", "Blue"]);
|
||||
// Blue (130,40-230,140 in the source) is cut to the file: 130,40-200,140.
|
||||
let blue = photocraft_compose::bounds::content_bounds(kids[1].surface().unwrap());
|
||||
assert_eq!(blue, Rect::new(130, 40, 200, 140));
|
||||
// The background covers where the boards overlap: 120..200 x 30..150.
|
||||
let bg = photocraft_compose::bounds::content_bounds(kids[0].surface().unwrap());
|
||||
assert_eq!(bg, Rect::new(120, 30, 200, 150));
|
||||
assert_eq!(rgb(px(&psd, 150, 60)), BLUE);
|
||||
assert_eq!(rgb(px(&psd, 125, 35)), WHITE);
|
||||
assert_eq!(rgb(px(&psd, 110, 50)), RED);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boards_below_do_not_show_in_either_mode() {
|
||||
let (mut s, [_, blue, _]) = session(8);
|
||||
// A transparent Blue Board shows whatever leaks in from Red Board's white background below.
|
||||
s.execute("layer.artboard.set", json!({"layer": blue, "background": "transparent"})).unwrap();
|
||||
let out = Out::new("below");
|
||||
for content in ["overlapping", "artboard"] {
|
||||
let f = export(&mut s, &out, blue, json!({"content": content}));
|
||||
assert_eq!((f.size.width, f.size.height), (200, 200), "{content}");
|
||||
// Source (125,35): Red Board's background, outside Blue's pixels.
|
||||
assert_eq!(px(&f, 5, 5)[3], 0, "{content}: nothing of Red Board");
|
||||
assert_eq!(rgb(px(&f, 30, 30)), BLUE, "{content}");
|
||||
let psd = export(&mut s, &out, blue, json!({"content": content, "format": "psd"}));
|
||||
assert_eq!(names(&psd.layers), ["Blue Board"], "{content}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_source_document_is_unchanged_and_gets_no_history_entry() {
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
let out = Out::new("source");
|
||||
for content in ["overlapping", "artboard"] {
|
||||
for board in [red, blue] {
|
||||
let d = s.active().unwrap();
|
||||
let (before, rev, past) = (d.doc.clone(), d.revision, d.history.past_len());
|
||||
export(&mut s, &out, board, json!({"content": content, "format": "psd"}));
|
||||
let d = s.active().unwrap();
|
||||
assert!(d.doc == before, "{content} changed the document");
|
||||
assert_eq!((d.revision, d.history.past_len()), (rev, past), "{content}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The artboard clipped its layers to the board; as a plain group in the file they still stop
|
||||
/// at the board's edge, so Blue pixels outside Blue Board never cover Red Board.
|
||||
#[test]
|
||||
fn the_layers_of_the_board_above_stay_inside_their_board() {
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
paint(&mut s, blue, "Spill", Rect::new(100, 45, 125, 55), BLUE);
|
||||
let out = Out::new("spill");
|
||||
for format in ["png", "psd"] {
|
||||
let f = export(&mut s, &out, red, json!({"format": format}));
|
||||
assert_eq!(rgb(px(&f, 110, 50)), RED, "{format}: outside Blue Board");
|
||||
assert_eq!(rgb(px(&f, 122, 50)), BLUE, "{format}: inside Blue Board");
|
||||
assert_eq!(rgb(px(&f, 150, 60)), BLUE, "{format}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A layer that covers the whole canvas (a solid colour fill) in the board above is clipped to
|
||||
/// that board by a mask on the group, so it can't paint over the rest of the exported board.
|
||||
#[test]
|
||||
fn a_fill_layer_in_the_board_above_stays_inside_its_board() {
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
s.edit("Fill", |doc, _| {
|
||||
let fill = Layer::new("Green", LayerContent::Fill(photocraft_doc::Fill::Solid(Color::rgb(0.0, 1.0, 0.0))));
|
||||
doc.layer_mut(LayerId(blue)).unwrap().children_mut().unwrap().push(fill);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let out = Out::new("fill");
|
||||
for format in ["png", "psd"] {
|
||||
let f = export(&mut s, &out, red, json!({"format": format}));
|
||||
assert_eq!(rgb(px(&f, 110, 50)), RED, "{format}: outside Blue Board");
|
||||
assert_eq!(rgb(px(&f, 10, 140)), WHITE, "{format}: outside Blue Board");
|
||||
assert_eq!(rgb(px(&f, 150, 60)), [0, 255, 0], "{format}: inside Blue Board");
|
||||
}
|
||||
}
|
||||
|
||||
/// A layer of the board above that lies outside the exported board still casts its drop shadow
|
||||
/// into it, as it does in the document: its pixels are not cut away before the effect is built.
|
||||
#[test]
|
||||
fn a_shadow_cast_into_the_exported_board_from_outside_it_still_shows() {
|
||||
use photocraft_doc::effects::{Contour, FxCommon, Shadow};
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
// Caster at 210..240 x 160..180 (in Blue Board, outside Red Board); its shadow, 40 px up and
|
||||
// to the left, falls on 170..200 x 120..140, inside Red Board.
|
||||
paint(&mut s, blue, "Caster", Rect::new(210, 160, 240, 180), [0, 160, 0]);
|
||||
s.edit("Shadow", |doc, _| {
|
||||
let caster = doc.layer_mut(LayerId(blue)).unwrap().children_mut().unwrap().last_mut().unwrap();
|
||||
caster.effects.items.push(photocraft_doc::Effect::DropShadow(Shadow {
|
||||
common: FxCommon::new(photocraft_color::BlendMode::Normal, 1.0),
|
||||
color: Color::rgb(0.0, 0.0, 0.0),
|
||||
angle: -45.0,
|
||||
use_global_light: false,
|
||||
distance: 40.0_f32.hypot(40.0),
|
||||
spread: 0.0,
|
||||
size: 0.0,
|
||||
contour: Contour::Linear,
|
||||
anti_alias: false,
|
||||
noise: 0.0,
|
||||
knocks_out: true,
|
||||
}));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let source = px(&s.active().unwrap().doc, 185, 130);
|
||||
assert_eq!(rgb(source), [0, 0, 0], "the shadow lands there in the document");
|
||||
let out = Out::new("shadow");
|
||||
for format in ["png", "psd"] {
|
||||
let f = export(&mut s, &out, red, json!({"format": format}));
|
||||
assert_eq!(px(&f, 185, 130), source, "{format}");
|
||||
assert_eq!(rgb(px(&f, 110, 50)), RED, "{format}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Not measured (keeps today's behaviour): a hidden board above shows nothing.
|
||||
#[test]
|
||||
fn a_hidden_board_above_does_not_show() {
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
s.edit("Hide", |doc, _| {
|
||||
doc.layer_mut(LayerId(blue)).unwrap().visible = false;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let out = Out::new("hidden");
|
||||
let f = export(&mut s, &out, red, json!({}));
|
||||
assert_eq!(rgb(px(&f, 150, 60)), WHITE);
|
||||
let psd = export(&mut s, &out, red, json!({"format": "psd"}));
|
||||
assert_eq!(names(&psd.layers), ["Red Board"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_bad_content_value_is_rejected_without_writing_anything() {
|
||||
let (mut s, _) = session(8);
|
||||
let out = Out::new("bad");
|
||||
for bad in [json!("both"), json!(""), json!(1), json!(true), json!(["overlapping"])] {
|
||||
let d = s.active().unwrap();
|
||||
let (before, past) = (d.doc.clone(), d.history.past_len());
|
||||
let err = s.execute("file.export.artboardsToFiles", json!({"dir": out.dir(), "content": bad})).unwrap_err();
|
||||
assert!(matches!(err, EngineError::BadParams { .. }), "{bad}: {err}");
|
||||
let d = s.active().unwrap();
|
||||
assert!(d.doc == before && d.history.past_len() == past, "{bad}");
|
||||
assert_eq!(std::fs::read_dir(&out.0).unwrap().count(), 0, "{bad}: nothing written");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_params_doc_names_the_option() {
|
||||
let spec = specs().into_iter().find(|c| c.id == "file.export.artboardsToFiles").unwrap();
|
||||
assert!(spec.params.contains(r#""content":"overlapping|artboard"="overlapping""#), "{}", spec.params);
|
||||
}
|
||||
|
||||
/// The source document's composite pixel at (x, y); Red Board sits at the canvas origin, so its
|
||||
/// file pixels line up with these.
|
||||
fn source_px(s: &Session, x: i32, y: i32) -> [u8; 4] {
|
||||
px(&s.active().unwrap().doc, x, y)
|
||||
}
|
||||
|
||||
/// A mask on the board above keeps hiding what it hid when the export clips that board to its
|
||||
/// rect: the board clip is added beside it instead of replacing it.
|
||||
#[test]
|
||||
fn a_mask_on_the_board_above_still_hides_its_part() {
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
s.edit("Mask", |doc, _| {
|
||||
let board = doc.layer_mut(LayerId(blue)).unwrap();
|
||||
// A canvas-wide fill reaches past the board, so the export clips the board to its rect.
|
||||
let fill = Layer::new("Green", LayerContent::Fill(photocraft_doc::Fill::Solid(Color::rgb(0.0, 1.0, 0.0))));
|
||||
board.children_mut().unwrap().insert(0, fill);
|
||||
let mut mask = photocraft_doc::LayerMask::reveal_all();
|
||||
mask.surface.fill_rect(Rect::new(140, 50, 160, 70), &[0.0]);
|
||||
board.mask = Some(mask);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(rgb(source_px(&s, 150, 60)), WHITE, "the mask shows Blue Board's background there");
|
||||
let out = Out::new("board-mask");
|
||||
for format in ["png", "psd"] {
|
||||
let f = export(&mut s, &out, red, json!({"format": format}));
|
||||
for (x, y) in [(150, 60), (145, 55), (170, 60), (125, 140), (110, 50), (10, 140)] {
|
||||
assert_eq!(px(&f, x, y), source_px(&s, x, y), "{format} at ({x},{y})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A Normal board renders its layers on their own before they go over its background, so a
|
||||
/// Multiply layer in it does not blend with that background; the export keeps the board as a
|
||||
/// group of its own above the background layer instead of stacking its layers on it.
|
||||
#[test]
|
||||
fn a_multiply_layer_in_a_normal_board_above_does_not_blend_with_its_background() {
|
||||
let (mut s, [red, blue, _]) = session(8);
|
||||
s.edit("Normal", |doc, _| {
|
||||
let board = doc.layer_mut(LayerId(blue)).unwrap();
|
||||
board.blend = photocraft_color::BlendMode::Normal;
|
||||
if let LayerContent::Group(g) = &mut board.content {
|
||||
g.artboard.as_mut().unwrap().background = photocraft_doc::ArtboardBackground::Custom(Color::rgb(0.0, 1.0, 0.0));
|
||||
}
|
||||
board.children_mut().unwrap().last_mut().unwrap().blend = photocraft_color::BlendMode::Multiply;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(rgb(source_px(&s, 150, 60)), BLUE, "Blue, rendered on its own, covers the green background");
|
||||
let out = Out::new("normal-multiply");
|
||||
for format in ["png", "psd"] {
|
||||
let f = export(&mut s, &out, red, json!({"format": format}));
|
||||
for (x, y) in [(150, 60), (125, 35), (110, 50)] {
|
||||
assert_eq!(px(&f, x, y), source_px(&s, x, y), "{format} at ({x},{y})");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -892,7 +892,7 @@ fn adjustment_layer_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => {
|
||||
let label = v.as_str()?;
|
||||
if crate::commands::blend_from_str(label)? == photocraft_doc::BlendMode::PassThrough {
|
||||
if crate::commands::parse_blend(label)? == photocraft_doc::BlendMode::PassThrough {
|
||||
return None;
|
||||
}
|
||||
Some(blend_ps(label)?)
|
||||
|
||||
@@ -56,7 +56,7 @@ pub(super) fn blend_label(ps: &str) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
pub(super) fn blend_ps(label: &str) -> Option<&'static str> {
|
||||
crate::commands::blend_from_str(label).and_then(|m| BLEND_MODES.iter().find(|(_, v)| crate::commands::blend_from_str(v) == Some(m))).map(|(k, _)| *k)
|
||||
crate::commands::parse_blend(label).and_then(|m| BLEND_MODES.iter().find(|(_, v)| crate::commands::parse_blend(v) == Some(m))).map(|(k, _)| *k)
|
||||
}
|
||||
|
||||
/// Photoshop ↔ PhotoCraft value tables; Photoshop codes compare without their space padding.
|
||||
|
||||
@@ -69,7 +69,7 @@ fn background_from_layer(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
only.clipped = false;
|
||||
let visible = l.visible;
|
||||
let fmt = doc.pixel_format();
|
||||
let rest = std::mem::replace(&mut doc.layers, vec![only]);
|
||||
let rest = std::mem::replace(&mut doc.layers, vec![only].into());
|
||||
let pixels = photocraft_compose::flatten_to_surface(doc, fmt, Some([bg[0], bg[1], bg[2]]));
|
||||
doc.layers = rest;
|
||||
let mut out = Layer::raster("Background", fmt);
|
||||
|
||||
@@ -448,7 +448,7 @@ fn with_blend_mode(mut b: BrushSettings, p: &Value) -> BrushSettings {
|
||||
} else if p.get("mode").and_then(Value::as_str).is_some_and(|m| m.eq_ignore_ascii_case("behind")) {
|
||||
b.mode = photocraft_color::BlendMode::Normal;
|
||||
b.behind = true;
|
||||
} else if let Some(m) = p.get("mode").and_then(Value::as_str).and_then(crate::commands::blend_from_str) {
|
||||
} else if let Some(m) = p.get("mode").and_then(Value::as_str).and_then(crate::commands::parse_blend) {
|
||||
b.mode = m;
|
||||
b.behind = false;
|
||||
}
|
||||
@@ -980,9 +980,9 @@ fn name_param(p: &Value, cmd: &str) -> Result<String> {
|
||||
|
||||
/// Replace the preset of that name, or append it at the end of the list.
|
||||
fn upsert(s: &mut Session, preset: BrushPreset) {
|
||||
match s.tools.presets.iter_mut().find(|x| x.name.eq_ignore_ascii_case(&preset.name)) {
|
||||
match std::sync::Arc::make_mut(&mut s.tools.presets).iter_mut().find(|x| x.name.eq_ignore_ascii_case(&preset.name)) {
|
||||
Some(x) => *x = preset,
|
||||
None => s.tools.presets.push(preset),
|
||||
None => std::sync::Arc::make_mut(&mut s.tools.presets).push(preset),
|
||||
}
|
||||
s.brush_presets_changed();
|
||||
}
|
||||
@@ -1010,7 +1010,7 @@ fn presets_delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "brush.presets.delete";
|
||||
let name = name_param(p, cmd)?;
|
||||
let before = s.tools.presets.len();
|
||||
s.tools.presets.retain(|x| !x.name.eq_ignore_ascii_case(&name));
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).retain(|x| !x.name.eq_ignore_ascii_case(&name));
|
||||
if s.tools.presets.len() == before {
|
||||
return Err(bad(cmd, format!("no brush preset named `{name}`")));
|
||||
}
|
||||
@@ -1043,7 +1043,10 @@ fn presets_update(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Some(patch) => merge_brush(&s.tools.brush, patch, cmd)?,
|
||||
None => s.tools.brush.clone(),
|
||||
};
|
||||
let pr = s.tools.presets.iter_mut().find(|x| x.name.eq_ignore_ascii_case(&name)).ok_or_else(|| bad(cmd, format!("no brush preset named `{name}`")))?;
|
||||
let pr = std::sync::Arc::make_mut(&mut s.tools.presets)
|
||||
.iter_mut()
|
||||
.find(|x| x.name.eq_ignore_ascii_case(&name))
|
||||
.ok_or_else(|| bad(cmd, format!("no brush preset named `{name}`")))?;
|
||||
pr.brush = brush;
|
||||
pr.builtin = false;
|
||||
let (name, group) = (pr.name.clone(), pr.group.clone());
|
||||
|
||||
@@ -263,7 +263,7 @@ mod tests {
|
||||
#[test]
|
||||
fn previous_and_next_brush_walk_the_presets_and_wrap() {
|
||||
let mut s = Session::new();
|
||||
s.tools.presets = vec![preset("One", "", &[], 11.0), preset("Two", "", &[], 22.0), preset("Three", "", &[], 33.0)];
|
||||
s.tools.presets = std::sync::Arc::new(vec![preset("One", "", &[], 11.0), preset("Two", "", &[], 22.0), preset("Three", "", &[], 33.0)]);
|
||||
s.tools.current_preset = None;
|
||||
let picked = |s: &Session| (s.tools.current_preset.clone().unwrap_or_default(), s.tools.brush.size);
|
||||
s.execute("tools.nextBrush", Value::Null).unwrap();
|
||||
@@ -284,7 +284,7 @@ mod tests {
|
||||
[Some(","), Some("."), Some("Shift+,"), Some("Shift+.")]
|
||||
);
|
||||
// No presets: an error, and the brush and the current preset stay as they were.
|
||||
s.tools.presets.clear();
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).clear();
|
||||
let (brush, current) = (s.tools.brush.clone(), s.tools.current_preset.clone());
|
||||
for id in ["tools.previousBrush", "tools.nextBrush", "tools.firstBrush", "tools.lastBrush"] {
|
||||
assert!(s.execute(id, Value::Null).is_err(), "{id}");
|
||||
|
||||
@@ -120,7 +120,7 @@ pub(crate) fn rename_at(s: &mut Session, i: usize, new: &str, cmd: &str) -> Resu
|
||||
if index_of(&s.tools.presets, new).is_some_and(|j| j != i) {
|
||||
return Err(bad(cmd, format!("a brush preset named `{new}` already exists")));
|
||||
}
|
||||
let pr = s.tools.presets.get_mut(i).ok_or_else(|| bad(cmd, "no such preset"))?;
|
||||
let pr = std::sync::Arc::make_mut(&mut s.tools.presets).get_mut(i).ok_or_else(|| bad(cmd, "no such preset"))?;
|
||||
if pr.name != new {
|
||||
let was_current = s.tools.current_preset.as_ref().is_some_and(|c| c.eq_ignore_ascii_case(&pr.name));
|
||||
pr.name = new.to_string();
|
||||
@@ -153,7 +153,7 @@ fn move_preset(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
let folder = folder_param(p, cmd)?;
|
||||
let group = group_param(p, "group", cmd)?;
|
||||
let lib = &mut s.tools.presets;
|
||||
let lib = std::sync::Arc::make_mut(&mut s.tools.presets);
|
||||
let (Some(moving), before_pr) = (lib.get(i), before.and_then(|b| lib.get(b))) else {
|
||||
return Err(bad(cmd, "no such preset"));
|
||||
};
|
||||
@@ -233,7 +233,7 @@ fn move_folder(s: &mut Session, p: &Value, g: String, f: Vec<String>, cmd: &str)
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => Some(v.as_u64().ok_or_else(|| bad(cmd, "`index` must be a non-negative integer"))?),
|
||||
};
|
||||
let lib = std::mem::take(&mut s.tools.presets);
|
||||
let lib = std::sync::Arc::unwrap_or_clone(std::mem::take(&mut s.tools.presets));
|
||||
// Where the block sits among the other presets (its place when nothing else is in the parent).
|
||||
let start = lib.iter().position(|x| in_folder(x, &g, &f)).unwrap_or(0);
|
||||
let (block, mut rest): (Vec<BrushPreset>, Vec<BrushPreset>) = lib.into_iter().partition(|x| in_folder(x, &g, &f));
|
||||
@@ -252,7 +252,7 @@ fn move_folder(s: &mut Session, p: &Value, g: String, f: Vec<String>, cmd: &str)
|
||||
let tail = rest.split_off(pos.min(rest.len()));
|
||||
rest.extend(block);
|
||||
rest.extend(tail);
|
||||
s.tools.presets = rest;
|
||||
s.tools.presets = std::sync::Arc::new(rest);
|
||||
s.brush_presets_changed();
|
||||
let at = subfolder_order(&s.tools.presets, &g, parent).iter().position(|x| x == leaf).unwrap_or(0);
|
||||
Ok(json!({ "group": g, "folder": f, "index": at }))
|
||||
@@ -332,7 +332,7 @@ fn move_into(s: &mut Session, p: &Value, g: String, f: Vec<String>, dest: Dest,
|
||||
if deepest > MAX_FOLDER_DEPTH {
|
||||
return Err(bad(cmd, format!("folders can be nested at most {MAX_FOLDER_DEPTH} deep")));
|
||||
}
|
||||
let lib = std::mem::take(&mut s.tools.presets);
|
||||
let lib = std::sync::Arc::unwrap_or_clone(std::mem::take(&mut s.tools.presets));
|
||||
let (mut block, mut rest): (Vec<BrushPreset>, Vec<BrushPreset>) = lib.into_iter().partition(|x| in_folder(x, &g, &f));
|
||||
for x in &mut block {
|
||||
let tail = rest_of(x);
|
||||
@@ -352,7 +352,7 @@ fn move_into(s: &mut Session, p: &Value, g: String, f: Vec<String>, dest: Dest,
|
||||
let tail = rest.split_off(pos.unwrap_or(rest.len()).min(rest.len()));
|
||||
rest.extend(block);
|
||||
rest.extend(tail);
|
||||
s.tools.presets = rest;
|
||||
s.tools.presets = std::sync::Arc::new(rest);
|
||||
s.brush_presets_changed();
|
||||
let folder = new_prefix.get(..new_prefix.len().saturating_sub(1)).unwrap_or_default();
|
||||
let at = match &dest {
|
||||
@@ -382,7 +382,7 @@ fn move_group(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => Some(v.as_u64().ok_or_else(|| bad(cmd, "`index` must be a non-negative integer"))?),
|
||||
};
|
||||
let lib = std::mem::take(&mut s.tools.presets);
|
||||
let lib = std::sync::Arc::unwrap_or_clone(std::mem::take(&mut s.tools.presets));
|
||||
let (block, mut rest): (Vec<BrushPreset>, Vec<BrushPreset>) = lib.into_iter().partition(|x| x.group == g);
|
||||
let order = group_order(&rest);
|
||||
let first = |name: &str, rest: &[BrushPreset]| rest.iter().position(|x| x.group == name).unwrap_or(rest.len());
|
||||
@@ -394,7 +394,7 @@ fn move_group(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let tail = rest.split_off(pos.min(rest.len()));
|
||||
rest.extend(block);
|
||||
rest.extend(tail);
|
||||
s.tools.presets = rest;
|
||||
s.tools.presets = std::sync::Arc::new(rest);
|
||||
s.brush_presets_changed();
|
||||
let at = group_order(&s.tools.presets).iter().position(|x| *x == g).unwrap_or(0);
|
||||
Ok(json!({ "group": g, "index": at }))
|
||||
@@ -410,7 +410,7 @@ fn rename_group(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(bad(cmd, format!("a folder named `{new}` already exists there")));
|
||||
}
|
||||
let depth = parent.len();
|
||||
for x in s.tools.presets.iter_mut().filter(|x| in_folder(x, &g, &f)) {
|
||||
for x in std::sync::Arc::make_mut(&mut s.tools.presets).iter_mut().filter(|x| in_folder(x, &g, &f)) {
|
||||
if let Some(n) = x.folder.get_mut(depth) {
|
||||
n.clone_from(&new);
|
||||
}
|
||||
@@ -426,7 +426,7 @@ fn rename_group(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(bad(cmd, format!("a group named `{new}` already exists")));
|
||||
}
|
||||
if new != g {
|
||||
for x in s.tools.presets.iter_mut().filter(|x| x.group == g) {
|
||||
for x in std::sync::Arc::make_mut(&mut s.tools.presets).iter_mut().filter(|x| x.group == g) {
|
||||
x.group = new.clone();
|
||||
x.builtin = false;
|
||||
}
|
||||
@@ -439,7 +439,7 @@ fn delete_group(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "brush.presets.deleteGroup";
|
||||
let (g, f) = target_folder(s, p, cmd)?;
|
||||
let before = s.tools.presets.len();
|
||||
s.tools.presets.retain(|x| !in_folder(x, &g, &f));
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).retain(|x| !in_folder(x, &g, &f));
|
||||
if s.tools.current_preset.as_ref().is_some_and(|c| !s.tools.presets.iter().any(|x| x.name.eq_ignore_ascii_case(c))) {
|
||||
s.tools.current_preset = None;
|
||||
s.tools.brush_changed();
|
||||
|
||||
@@ -7,7 +7,7 @@ fn names(s: &Session, g: &str) -> Vec<String> {
|
||||
fn with_groups() -> Session {
|
||||
let mut s = Session::new();
|
||||
for (n, g) in [("A1", "Alpha"), ("A2", "Alpha"), ("A3", "Alpha"), ("B1", "Beta"), ("B2", "Beta")] {
|
||||
s.tools.presets.push(BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(BrushPreset {
|
||||
name: n.into(),
|
||||
brush: Default::default(),
|
||||
builtin: false,
|
||||
@@ -119,7 +119,7 @@ fn with_folders() -> Session {
|
||||
let mut s = Session::new();
|
||||
for (n, f) in [("S0", &[][..]), ("I1", &["Ink"][..]), ("F1", &["Ink", "Fine"][..]), ("I2", &["Ink"][..]), ("D1", &["Dry"][..])] {
|
||||
let folder = f.iter().map(|x| x.to_string()).collect();
|
||||
s.tools.presets.push(BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(BrushPreset {
|
||||
name: n.into(),
|
||||
brush: Default::default(),
|
||||
builtin: false,
|
||||
@@ -226,7 +226,7 @@ fn with_two_groups() -> Session {
|
||||
let mut s = with_folders();
|
||||
for (n, f) in [("O1", &[][..]), ("B1", &["Box"][..])] {
|
||||
let folder = f.iter().map(|x| x.to_string()).collect();
|
||||
s.tools.presets.push(BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(BrushPreset {
|
||||
name: n.into(),
|
||||
brush: Default::default(),
|
||||
builtin: false,
|
||||
@@ -266,7 +266,7 @@ fn bad_moves_into_folders_fail_without_changes() {
|
||||
let mut s = with_two_groups();
|
||||
// A chain 31 deep under Set/Deep.
|
||||
let deep: Vec<String> = std::iter::once("Deep".to_string()).chain((0..30).map(|i| format!("d{i}"))).collect();
|
||||
s.tools.presets.push(BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(BrushPreset {
|
||||
name: "Z".into(),
|
||||
brush: Default::default(),
|
||||
builtin: false,
|
||||
@@ -274,7 +274,7 @@ fn bad_moves_into_folders_fail_without_changes() {
|
||||
folder: deep.clone(),
|
||||
captures: Default::default(),
|
||||
});
|
||||
s.tools.presets.push(BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(BrushPreset {
|
||||
name: "Y".into(),
|
||||
brush: Default::default(),
|
||||
builtin: false,
|
||||
@@ -314,7 +314,7 @@ fn bad_moves_into_folders_fail_without_changes() {
|
||||
s.execute("brush.presets.moveGroup", json!({"group": "Set", "folder": ["Ink", "Fine"], "into": {"group": "Set"}})).unwrap();
|
||||
assert_eq!(folder_of(&s, "F1"), ["Fine"]);
|
||||
// An ungrouped preset's group can't move.
|
||||
s.tools.presets.push(BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(BrushPreset {
|
||||
name: "U".into(),
|
||||
brush: Default::default(),
|
||||
builtin: false,
|
||||
|
||||
@@ -314,7 +314,7 @@ impl Blending {
|
||||
match name.to_ascii_lowercase().as_str() {
|
||||
"add" => Ok(Blending::Add { scale, offset }),
|
||||
"subtract" => Ok(Blending::Subtract { scale, offset }),
|
||||
other => match crate::commands::blend_from_str(other) {
|
||||
other => match crate::commands::parse_blend(other) {
|
||||
Some(m) if m.is_separable() && !matches!(m, BlendMode::Dissolve | BlendMode::PassThrough) => Ok(Blending::Mode(m)),
|
||||
_ => Err(format!("unsupported blending `{other}`")),
|
||||
},
|
||||
|
||||
@@ -43,7 +43,7 @@ pub(super) fn merge_spot(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
sf.prune();
|
||||
}
|
||||
let id = bg.id;
|
||||
doc.layers = vec![bg];
|
||||
doc.layers = vec![bg].into();
|
||||
doc.channels.remove(i);
|
||||
*active = Some(id);
|
||||
Ok(())
|
||||
|
||||
@@ -1259,7 +1259,7 @@ fn split_refuses_an_image_with_more_than_one_layer() {
|
||||
assert_eq!(s.execute("channel.split", json!({})).unwrap()["documents"].as_array().unwrap().len(), 3);
|
||||
// A lone group is a layer the split would lose.
|
||||
let mut s = session();
|
||||
std::sync::Arc::make_mut(&mut s.active_mut().unwrap().doc).layers = vec![Layer::group("Group 1", vec![])];
|
||||
std::sync::Arc::make_mut(&mut s.active_mut().unwrap().doc).layers = vec![Layer::group("Group 1", vec![])].into();
|
||||
assert!(!s.is_enabled("channel.split"));
|
||||
assert!(s.execute("channel.split", json!({})).is_err());
|
||||
assert_eq!(s.documents().len(), 1);
|
||||
|
||||
@@ -1116,7 +1116,7 @@ fn flatten_for_profile(doc: &mut Document, active: &mut Option<photocraft_doc::L
|
||||
background.locks.position = true;
|
||||
*crate::pixels_mut(&mut background)? = surface;
|
||||
*active = Some(background.id);
|
||||
doc.layers = vec![background];
|
||||
doc.layers = vec![background].into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -789,7 +789,7 @@ fn merge_visible(s: &mut Session) -> Result<Value> {
|
||||
out.push(l);
|
||||
}
|
||||
}
|
||||
doc.layers = out;
|
||||
doc.layers = out.into();
|
||||
*active = Some(mid);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::channel_cmds::Target;
|
||||
use crate::commands::{CommandSpec, blend_from_str, int, layer_param};
|
||||
use crate::commands::{CommandSpec, int, layer_param, parse_blend};
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
// ------------------------------------------------------------------ state
|
||||
@@ -314,9 +314,9 @@ fn export_import(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// absurd tree).
|
||||
b.folder.retain(|f| !f.trim().is_empty());
|
||||
b.folder.truncate(crate::brush_preset_cmds::MAX_FOLDER_DEPTH);
|
||||
match s.tools.presets.iter_mut().find(|x| x.name == b.name) {
|
||||
match std::sync::Arc::make_mut(&mut s.tools.presets).iter_mut().find(|x| x.name == b.name) {
|
||||
Some(x) => *x = b,
|
||||
None => s.tools.presets.push(b),
|
||||
None => std::sync::Arc::make_mut(&mut s.tools.presets).push(b),
|
||||
}
|
||||
nb += 1;
|
||||
}
|
||||
@@ -460,6 +460,10 @@ pub fn custom_shapes(s: &Session) -> &[CustomShape] {
|
||||
&s.edit_state.custom_shapes
|
||||
}
|
||||
|
||||
/// Serialize tests that intentionally purge or seed the global smart caches.
|
||||
#[cfg(test)]
|
||||
pub(crate) static PURGE_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "edit_menu_cmds/tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
BlendMode, Document, EngineError, FadeSource, FadeTarget, Rect, Result, Session, Surface, Value, bad, blend_from_str, f32_or, from_rgba_into, json, str_or,
|
||||
BlendMode, Document, EngineError, FadeSource, FadeTarget, Rect, Result, Session, Surface, Value, bad, f32_or, from_rgba_into, json, parse_blend, str_or,
|
||||
surface_of, surface_of_mut, to_rgba,
|
||||
};
|
||||
|
||||
@@ -103,7 +103,7 @@ fn fade_job(s: &Session, p: &Value) -> Result<FadeJob> {
|
||||
let cmd = "edit.fade";
|
||||
let src = s.edit_state.fade.clone().ok_or_else(|| bad(cmd, "nothing to fade"))?;
|
||||
let opacity = f32_or(p, "opacity", 100.0).clamp(0.0, 100.0) / 100.0;
|
||||
let mode = blend_from_str(str_or(p, "mode", "normal")).ok_or_else(|| bad(cmd, "unknown blend mode"))?;
|
||||
let mode = parse_blend(str_or(p, "mode", "normal")).ok_or_else(|| bad(cmd, "unknown blend mode"))?;
|
||||
let st = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let prev = before_state(st, &src).ok_or_else(|| bad(cmd, "no previous state"))?;
|
||||
let before = surface_of(&prev, src.target).cloned().ok_or_else(|| EngineError::Other("the layer or channel did not exist before this step".into()))?;
|
||||
|
||||
@@ -114,7 +114,7 @@ pub(super) fn preset_manager(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
"delete" => match kind.as_str() {
|
||||
"brushes" => {
|
||||
let gone = s.tools.presets.remove(i);
|
||||
let gone = std::sync::Arc::make_mut(&mut s.tools.presets).remove(i);
|
||||
crate::brush_cmds::forget_deleted_preset(s, &gone.name);
|
||||
}
|
||||
"patterns" => drop(s.patterns.items.remove(i)),
|
||||
@@ -123,7 +123,7 @@ pub(super) fn preset_manager(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
"move" => {
|
||||
let to = p.get("to").and_then(Value::as_u64).ok_or_else(|| bad(cmd, "missing `to`"))? as usize;
|
||||
match kind.as_str() {
|
||||
"brushes" => crate::move_item(&mut s.tools.presets, i, to),
|
||||
"brushes" => crate::move_item(std::sync::Arc::make_mut(&mut s.tools.presets), i, to),
|
||||
"patterns" => crate::move_item(&mut s.patterns.items, i, to),
|
||||
_ => crate::move_item(&mut s.edit_state.custom_shapes, i, to),
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use super::*;
|
||||
use photocraft_doc::vector::Subpath;
|
||||
|
||||
static PURGE_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
fn session(depth: u32) -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth, "background": "white"})).unwrap();
|
||||
|
||||
@@ -147,7 +147,7 @@ fn stroke(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let picked = s.tools.picked_cmyk([color[0], color[1], color[2]]);
|
||||
let mode = match p.get("mode") {
|
||||
None | Some(Value::Null) => photocraft_color::BlendMode::Normal,
|
||||
Some(Value::String(m)) => crate::commands::blend_from_str(m)
|
||||
Some(Value::String(m)) => crate::commands::parse_blend(m)
|
||||
.filter(|m| *m != photocraft_color::BlendMode::PassThrough)
|
||||
.ok_or_else(|| EngineError::BadParams { cmd: "edit.stroke".into(), msg: format!("unknown blend mode `{m}`") })?,
|
||||
Some(v) => return Err(EngineError::BadParams { cmd: "edit.stroke".into(), msg: format!("mode must be a blend mode name, not {v}") }),
|
||||
|
||||
@@ -77,7 +77,7 @@ pub fn export_layers_report_with(s: &Session, p: &Value, mut write: impl FnMut(&
|
||||
let mut only = l.clone();
|
||||
only.visible = true;
|
||||
only.clipped = false;
|
||||
one.layers = vec![only];
|
||||
one.layers = vec![only].into();
|
||||
if trim {
|
||||
let mut bounds = Rect::EMPTY;
|
||||
let _ = photocraft_compose::render_bands(&one, one.bounds(), 0, |band| -> std::result::Result<(), ()> {
|
||||
|
||||
@@ -304,9 +304,9 @@ pub(super) fn load_files_into_stack(s: &mut Session, p: &Value) -> Result<Value>
|
||||
// "Create Smart Object after Loading Layers": the layers go inside one smart object, ready
|
||||
// for Layer › Smart Objects › Stack Mode. Like Photoshop, they sit at the top level of the
|
||||
// contents, with no wrapper group.
|
||||
let layers = std::mem::take(&mut stack.layers);
|
||||
let layers = std::mem::take(&mut *stack.layers);
|
||||
let smart = crate::smart_cmds::layers_to_smart(&stack, &smart_name, layers)?;
|
||||
stack.layers = vec![smart];
|
||||
stack.layers = vec![smart].into();
|
||||
}
|
||||
let i = s.add_document(stack, None);
|
||||
if align {
|
||||
@@ -314,10 +314,10 @@ pub(super) fn load_files_into_stack(s: &mut Session, p: &Value) -> Result<Value>
|
||||
s.execute("edit.autoAlignLayers", json!({"projection": "auto"}))?;
|
||||
if smart {
|
||||
s.edit("Convert to Smart Object", |doc, active| {
|
||||
let layers = std::mem::take(&mut doc.layers);
|
||||
let layers = std::mem::take(&mut *doc.layers);
|
||||
let smart = crate::smart_cmds::layers_to_smart(doc, &smart_name, layers)?;
|
||||
*active = Some(smart.id);
|
||||
doc.layers = vec![smart];
|
||||
doc.layers = vec![smart].into();
|
||||
Ok(())
|
||||
})?;
|
||||
if let Some(st) = s.active_mut() {
|
||||
|
||||
@@ -312,7 +312,7 @@ pub(super) fn save_a_copy(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// "Layers" unchecked in Save a Copy: write the flattened image.
|
||||
let fmt = doc.pixel_format();
|
||||
let px = flattened_checked(&doc, fmt, "file.saveACopy")?;
|
||||
doc.layers = vec![Layer::new("Background", LayerContent::Raster(px))];
|
||||
doc.layers = vec![Layer::new("Background", LayerContent::Raster(px))].into();
|
||||
}
|
||||
let warnings = save_doc(&doc, &path, SaveOpts::from_params(s, p, "file.saveACopy")?)?;
|
||||
Ok(json!({"path": path, "warnings": warnings}))
|
||||
|
||||
@@ -11,7 +11,7 @@ use photocraft_geom::{Rect, TILE_SIZE};
|
||||
use photocraft_raster::{Surface, from_rgba_into, to_rgba};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::commands::{blend_from_str, color_param, layer_param};
|
||||
use crate::commands::{color_param, layer_param, parse_blend};
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
const CMD: &str = "edit.fill";
|
||||
@@ -66,7 +66,7 @@ fn contents(p: &Value) -> Result<&str> {
|
||||
fn mode(p: &Value) -> Result<BlendMode> {
|
||||
match p.get("mode") {
|
||||
None | Some(Value::Null) => Ok(BlendMode::Normal),
|
||||
Some(Value::String(m)) => blend_from_str(m).filter(|m| *m != BlendMode::PassThrough).ok_or_else(|| bad(format!("unknown blend mode `{m}`"))),
|
||||
Some(Value::String(m)) => parse_blend(m).filter(|m| *m != BlendMode::PassThrough).ok_or_else(|| bad(format!("unknown blend mode `{m}`"))),
|
||||
Some(v) => Err(bad(format!("`mode` must be a blend mode name, not {v}"))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use photocraft_doc::{Document, Fill, GradientStyle, Layer, LayerContent, LayerId
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::commands::{CommandSpec, blend_from_str, check_pixels_unlocked, layer_param};
|
||||
use crate::commands::{CommandSpec, check_pixels_unlocked, layer_param, parse_blend};
|
||||
use crate::presets::gradients::{GradientPreset, transparency_param};
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
@@ -300,7 +300,7 @@ pub fn new_layer(s: &Session, doc: &Document, p: &Value) -> Result<Layer> {
|
||||
let opacity = num(p, "opacity").unwrap_or(100.0).clamp(0.0, 100.0) / 100.0;
|
||||
let blend = match p.get("mode").and_then(Value::as_str) {
|
||||
None | Some("") => photocraft_color::BlendMode::Normal,
|
||||
Some(m) => blend_from_str(m).ok_or_else(|| bad(CMD, format!("unknown blend mode `{m}`")))?,
|
||||
Some(m) => parse_blend(m).ok_or_else(|| bad(CMD, format!("unknown blend mode `{m}`")))?,
|
||||
};
|
||||
let canvas = doc.bounds();
|
||||
if canvas.is_empty() {
|
||||
|
||||
@@ -145,7 +145,7 @@ fn new_snapshot(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let one_layer = |doc: &Document, layer: Layer| {
|
||||
let mut doc = doc.clone();
|
||||
let id = layer.id;
|
||||
doc.layers = vec![layer];
|
||||
doc.layers = vec![layer].into();
|
||||
(Arc::new(doc), LayerTarget { active: Some(id), selected: vec![id] })
|
||||
};
|
||||
let (doc, layers) = match from {
|
||||
@@ -525,7 +525,7 @@ mod tests {
|
||||
assert_eq!(st.memory_bytes(), base + flat);
|
||||
// Room for the document's tiles and four fill tiles.
|
||||
let cur = tile_bytes(&st.doc);
|
||||
let fill = tile_bytes(&Document { layers: st.doc.layers[1..].to_vec(), ..(*st.doc).clone() });
|
||||
let fill = tile_bytes(&Document { layers: st.doc.layers[1..].to_vec().into(), ..(*st.doc).clone() });
|
||||
assert!(flat <= fill, "the flattened tile is no bigger than a fill's");
|
||||
let budget = cur + 4 * fill;
|
||||
for s in [&mut with, &mut without] {
|
||||
@@ -549,7 +549,7 @@ mod tests {
|
||||
s.execute("edit.fill", json!({"color": "#0000ff"})).unwrap();
|
||||
let st = s.active().unwrap();
|
||||
// The snapshot's green layer tile, now only in it and the last state.
|
||||
let shared = tile_bytes(&Document { layers: st.snapshots.last().unwrap().doc.layers[1..].to_vec(), ..(*st.doc).clone() });
|
||||
let shared = tile_bytes(&Document { layers: st.snapshots.last().unwrap().doc.layers[1..].to_vec().into(), ..(*st.doc).clone() });
|
||||
let all = st.history.unique_bytes(&st.doc);
|
||||
let r = s.execute("edit.purge.histories", json!({})).unwrap();
|
||||
assert_eq!(r["bytes"], json!(all - shared), "the green tile stays with the snapshot");
|
||||
|
||||
@@ -1213,7 +1213,7 @@ fn duplicate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut merged = Layer::new(if has_background { "Background" } else { "Layer 1" }, LayerContent::Raster(surf));
|
||||
merged.locks.transparency = has_background;
|
||||
merged.locks.position = has_background;
|
||||
doc.layers = vec![merged];
|
||||
doc.layers = vec![merged].into();
|
||||
// A merged-only copy has no original layers for saved comps to restore.
|
||||
// Don't carry dangling comp state into a single-layer flattened document.
|
||||
doc.layer_comps.clear();
|
||||
|
||||
@@ -798,16 +798,18 @@ fn crop_at_a_small_angle_keeps_the_frame_size_in_every_mode() {
|
||||
#[test]
|
||||
fn turned_crop_deleting_pixels_matches_turning_the_whole_canvas() {
|
||||
use photocraft_color::PixelFormat;
|
||||
let pixels = || (0..500).flat_map(|y| (0..700).map(move |x| (x, y)));
|
||||
for depth in [8, 16, 32] {
|
||||
for angle in [3.0, -7.5, 33.0, 181.0] {
|
||||
let (w, h) = if depth == 8 && angle == 33.0 { (700, 500) } else { (140, 100) };
|
||||
let scale = w / 140;
|
||||
let pixels = || (0..h).flat_map(|y| (0..w).map(move |x| (x, y)));
|
||||
let mut sessions = [true, false].map(|delete| {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 700, "height": 500, "depth": depth, "background": "white"})).unwrap();
|
||||
s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "background": "white"})).unwrap();
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.edit("paint", |doc, active| {
|
||||
let wave = |x: i32, y: i32, k: i32| ((x * 7 + y * 13 + k * 31) % 97) as f32 / 96.0;
|
||||
let all = Rect::new(0, 0, 700, 500);
|
||||
let all = Rect::new(0, 0, w, h);
|
||||
let rgba: Vec<f32> = pixels().flat_map(|(x, y)| [wave(x, y, 0), wave(x, y, 1), wave(x, y, 2), wave(y, x, 3)]).collect();
|
||||
let gray: Vec<f32> = pixels().map(|(x, y)| wave(y, x, 4)).collect();
|
||||
let l = doc.layer_mut(active.unwrap()).unwrap();
|
||||
@@ -824,7 +826,7 @@ fn turned_crop_deleting_pixels_matches_turning_the_whole_canvas() {
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let p = json!({"x": 150, "y": 120, "width": 330, "height": 290, "angle": angle, "deleteCroppedPixels": delete});
|
||||
let p = json!({"x": 30 * scale, "y": 24 * scale, "width": 66 * scale, "height": 58 * scale, "angle": angle, "deleteCroppedPixels": delete});
|
||||
s.execute("image.crop", p).unwrap();
|
||||
s
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ fn fixture(depth: u8) -> (Session, [LayerId; 4]) {
|
||||
let outer_id = outer.id;
|
||||
let other = Layer::raster("Other", doc.pixel_format());
|
||||
let other_id = other.id;
|
||||
doc.layers = vec![outer, other];
|
||||
doc.layers = vec![outer, other].into();
|
||||
Ok([outer_id, inner_id, leaf_id, other_id])
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -525,7 +525,7 @@ fn blending_options(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "layer.layerStyle.blendingOptions";
|
||||
let id = layer_param(s, p)?;
|
||||
let blend = match p.get("blend").and_then(Value::as_str) {
|
||||
Some(b) => Some(crate::commands::blend_from_str(b).ok_or_else(|| bad(CMD, format!("unknown blend mode `{b}`")))?),
|
||||
Some(b) => Some(crate::commands::parse_blend(b).ok_or_else(|| bad(CMD, format!("unknown blend mode `{b}`")))?),
|
||||
None => None,
|
||||
};
|
||||
let opacity = p.get("opacity").and_then(Value::as_f64).map(|v| (v as f32 / 100.0).clamp(0.0, 1.0));
|
||||
@@ -876,7 +876,7 @@ fn create_layer(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut tmp = Document::new("fx", doc.size, doc.mode, doc.depth);
|
||||
tmp.global_light = light;
|
||||
tmp.patterns = doc.patterns.clone();
|
||||
tmp.layers = vec![alone];
|
||||
tmp.layers = vec![alone].into();
|
||||
let buf = photocraft_compose::render(&tmp, area);
|
||||
let mut surf = Surface::new(fmt);
|
||||
let data: Vec<f32> = buf.px.iter().flat_map(|q| photocraft_raster::from_rgba(&fmt, *q)).collect();
|
||||
@@ -952,7 +952,7 @@ pub fn layer_document(doc: &Document, id: LayerId) -> Result<Document> {
|
||||
alone.blend = if alone.is_group() { BlendMode::PassThrough } else { BlendMode::Normal };
|
||||
alone.clipped = false;
|
||||
let mut tmp = doc.clone();
|
||||
tmp.layers = vec![alone];
|
||||
tmp.layers = vec![alone].into();
|
||||
tmp.selection = None;
|
||||
let area = doc.bounds();
|
||||
let buf = photocraft_compose::render(&tmp, area);
|
||||
|
||||
@@ -548,7 +548,7 @@ fn stack_modes_render_from_the_nested_layers() {
|
||||
let g = Layer::new("stack", LayerContent::Group(photocraft_doc::Group { children: kids, expanded: true, artboard: None, frame_stroke: None }));
|
||||
let smart = crate::smart_cmds::layer_to_smart(doc, &g)?;
|
||||
let id = smart.id;
|
||||
doc.layers = vec![smart];
|
||||
doc.layers = vec![smart].into();
|
||||
*active = Some(id);
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::params::bad;
|
||||
use super::{BlendMode, Document, EngineError, Layer, LayerId, LayerMask, Result, SampleType, Session, Value};
|
||||
use super::{Document, EngineError, Layer, LayerId, LayerMask, Result, SampleType, Session, Value};
|
||||
|
||||
/// The layer a command's `"layer"` param names: an id, or a name (the topmost layer of that
|
||||
/// name, as Photoshop's "select layer by name" action step finds it, so a loaded action replays
|
||||
@@ -72,12 +72,6 @@ pub(crate) fn layer_param(s: &Session, p: &Value) -> Result<LayerId> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn blend_from_str(s: &str) -> Option<BlendMode> {
|
||||
let norm = |x: &str| x.to_ascii_lowercase().replace([' ', '_', '-', '(', ')'], "");
|
||||
let want = norm(s);
|
||||
std::iter::once(BlendMode::PassThrough).chain(BlendMode::layer_modes()).find(|m| norm(m.label()) == want || norm(&format!("{m:?}")) == want)
|
||||
}
|
||||
|
||||
/// The active selection as the mask of a layer being created, or None without a selection.
|
||||
/// Photoshop masks a new adjustment or fill layer with the selection, so the adjustment acts on
|
||||
/// the selected area only (#1250). [`mask_new_layer`] then drops the selection (#8801).
|
||||
|
||||
@@ -11,7 +11,7 @@ fn fixture(depth: u8) -> (Session, LayerId, LayerId) {
|
||||
let a = Layer::raster("A", doc.pixel_format());
|
||||
let b = Layer::group("B", vec![Layer::raster("Child", doc.pixel_format())]);
|
||||
let ids = (a.id, b.id);
|
||||
doc.layers = vec![a, b];
|
||||
doc.layers = vec![a, b].into();
|
||||
Ok(ids)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -241,7 +241,7 @@ fn single_layer_surface(doc: &mut Document, active: &mut Option<LayerId>, mode:
|
||||
*surf = pixels;
|
||||
}
|
||||
*active = Some(l.id);
|
||||
doc.layers = vec![l];
|
||||
doc.layers = vec![l].into();
|
||||
for ch in doc.channels.iter_mut() {
|
||||
let f = PixelFormat::new(ColorMode::Grayscale, SampleType::U8, false);
|
||||
ch.surface = ch.surface.convert(PixelFormat { alpha: ch.surface.format().alpha, ..f });
|
||||
@@ -600,6 +600,11 @@ fn custom_pattern_map(s: &Session, cmd: &str, p: &Value) -> Result<(Vec<f32>, us
|
||||
}
|
||||
|
||||
fn bitmap(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
bitmap_in_bands(s, p, 0)
|
||||
}
|
||||
|
||||
/// Convert with the requested compositor band height (zero chooses its normal budget).
|
||||
fn bitmap_in_bands(s: &mut Session, p: &Value, band_rows: i32) -> Result<Value> {
|
||||
const CMD: &str = "image.mode.bitmap";
|
||||
let d = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let input = f64::from(d.doc.resolution_dpi.max(1.0));
|
||||
@@ -674,7 +679,7 @@ fn bitmap(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let n = fmt.channels();
|
||||
let mut out = Surface::new(fmt);
|
||||
let (mut gray, mut data) = (Vec::new(), Vec::new());
|
||||
let _ = photocraft_compose::render_bands(doc, doc.bounds(), 0, |band| -> std::result::Result<(), std::convert::Infallible> {
|
||||
let _ = photocraft_compose::render_bands(doc, doc.bounds(), band_rows, |band| -> std::result::Result<(), std::convert::Infallible> {
|
||||
gray.clear();
|
||||
gray.extend(band.px.iter().map(|q| {
|
||||
// Over white, as the flattened image.
|
||||
|
||||
@@ -860,13 +860,13 @@ fn bitmap_pixels(d: &Document) -> Vec<f32> {
|
||||
|
||||
#[test]
|
||||
fn bitmap_in_bands_matches_one_full_canvas_conversion() {
|
||||
// #8477: the composite is converted in bands (32768 px wide: 256 rows each, so 300 rows are
|
||||
// two). Diffusion carries its error across the band edge, and pattern, halftone and custom
|
||||
// #8477: 300 rows cross a 256-row compositor band. Diffusion carries its error across the
|
||||
// band edge, and pattern, halftone and custom
|
||||
// pattern stay anchored to the image's rows: the result equals one full-canvas conversion.
|
||||
let (w, h) = (32_768u32, 300u32);
|
||||
let (w, h) = (64u32, 300u32);
|
||||
let mut s = session(w, h, 8, "grayscale");
|
||||
paint(&mut s, |x, y| {
|
||||
let v = ((x % 509) as f32 / 509.0 * 0.6 + (y as f32 / 300.0) * 0.4).fract();
|
||||
let v = ((x % 61) as f32 / 61.0 * 0.6 + (y as f32 / 300.0) * 0.4).fract();
|
||||
[v, v, v, 1.0]
|
||||
});
|
||||
add_pattern(&mut s, "Cells", 3, 2, &[10, 200, 90, 250, 150, 40]);
|
||||
@@ -888,7 +888,7 @@ fn bitmap_in_bands_matches_one_full_canvas_conversion() {
|
||||
if method == "customPattern" {
|
||||
p["pattern"] = json!("Cells");
|
||||
}
|
||||
s.execute("image.mode.bitmap", p.clone()).unwrap();
|
||||
bitmap_in_bands(&mut s, &p, 256).unwrap();
|
||||
let want = match method {
|
||||
"halftone" => {
|
||||
let cell = (before.resolution_dpi / 53.0).max(2.0);
|
||||
@@ -902,6 +902,9 @@ fn bitmap_in_bands_matches_one_full_canvas_conversion() {
|
||||
};
|
||||
// Grayscale stores 0/1 the way `from_rgba` turns the old RGBA output into gray.
|
||||
let want: Vec<f32> = want.iter().map(|g| photocraft_raster::from_rgba(&storage_format(ColorMode::Bitmap), [*g, *g, *g, 1.0])[0]).collect();
|
||||
if method == "threshold" {
|
||||
assert!(want.contains(&0.0) && want.contains(&1.0), "the gradient crosses the threshold");
|
||||
}
|
||||
let got = bitmap_pixels(doc(&s));
|
||||
let diff = got.iter().zip(&want).filter(|(a, b)| (**a - **b).abs() > 1e-6).count();
|
||||
assert_eq!(diff, 0, "{method}: {diff} of {} pixels differ", got.len());
|
||||
|
||||
@@ -246,7 +246,7 @@ pub(crate) fn convert_from(s: &mut Session, mode: ColorMode, _p: &Value) -> Resu
|
||||
bg.locks.transparency = true;
|
||||
bg.locks.position = true;
|
||||
*active = Some(bg.id);
|
||||
doc.layers = vec![bg];
|
||||
doc.layers = vec![bg].into();
|
||||
doc.channels = others;
|
||||
Ok(if reinterpret { "channels" } else { "appearance" })
|
||||
})?;
|
||||
|
||||
@@ -246,7 +246,7 @@ pub(super) fn merge_group(s: &mut Session, id: LayerId) -> Result<Value> {
|
||||
solo.blend = photocraft_doc::BlendMode::Normal;
|
||||
solo.clipped = false;
|
||||
let mut tmp = doc.clone();
|
||||
tmp.layers = vec![solo];
|
||||
tmp.layers = vec![solo].into();
|
||||
let mut merged = Layer::new(group.name.clone(), LayerContent::Raster(pixels::composite_layers_uncropped(&tmp, fmt)));
|
||||
merged.id = group.id;
|
||||
merged.opacity = group.opacity;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use photocraft_algo::paint::{FillMode, GradientShape, bucket_fill_inks, bucket_fill_region_inks, paint_gradient};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::commands::{CommandSpec, blend_from_str};
|
||||
use crate::commands::{CommandSpec, parse_blend};
|
||||
use crate::presets::gradients;
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
@@ -47,7 +47,7 @@ fn fill_mode(p: &Value) -> Result<FillMode> {
|
||||
match p.get("mode") {
|
||||
None | Some(Value::Null) => Ok(FillMode::Blend(photocraft_color::BlendMode::Normal)),
|
||||
Some(Value::String(m)) if m.eq_ignore_ascii_case("clear") => Ok(FillMode::Clear),
|
||||
Some(Value::String(m)) => blend_from_str(m)
|
||||
Some(Value::String(m)) => parse_blend(m)
|
||||
.filter(|m| *m != photocraft_color::BlendMode::PassThrough)
|
||||
.map(FillMode::Blend)
|
||||
.ok_or_else(|| bad(format!("unknown blend mode `{m}`"))),
|
||||
@@ -186,7 +186,7 @@ fn gradient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
let reverse = b(p, "reverse", false);
|
||||
let opacity = opacity(p, "paint.gradient")?;
|
||||
let blend = p.get("mode").and_then(Value::as_str).and_then(blend_from_str).unwrap_or(photocraft_color::BlendMode::Normal);
|
||||
let blend = p.get("mode").and_then(Value::as_str).and_then(parse_blend).unwrap_or(photocraft_color::BlendMode::Normal);
|
||||
let dither = b(p, "dither", true); // Photoshop dithers gradients by default (reduces banding).
|
||||
let layer = if p.get("layer").is_some() { Some(crate::commands::layer_param(s, p)?) } else { s.active().and_then(|st| st.active_layer) };
|
||||
s.edit("Gradient", |doc, _| {
|
||||
|
||||
@@ -325,6 +325,12 @@ pub fn default_name(s: &Session) -> String {
|
||||
const MAX_DEFINE_EDGE: u32 = 8000;
|
||||
|
||||
fn define(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let sample = s.active().ok_or(EngineError::NoDocument)?.doc.pixel_format().sample;
|
||||
define_with_max_pixels(s, p, photocraft_doc::pattern::max_paint_pixels(sample))
|
||||
}
|
||||
|
||||
/// Define a pattern with a bound on its pixel count.
|
||||
fn define_with_max_pixels(s: &mut Session, p: &Value, max_px: u64) -> Result<Value> {
|
||||
let cmd = "edit.definePattern";
|
||||
let st = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let doc = &st.doc;
|
||||
@@ -345,7 +351,6 @@ fn define(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// A pattern the compositor could not hold would define but paint nothing: 8 bits go to the
|
||||
// edge limit, 16-bit documents to 33,554,432 px in all, float to 16,777,216 (4096 × 4096).
|
||||
let sample = doc.pixel_format().sample;
|
||||
let max_px = photocraft_doc::pattern::max_paint_pixels(sample);
|
||||
if u64::from(r.width()) * u64::from(r.height()) > max_px {
|
||||
return Err(bad(cmd, format!("patterns in a {}-bit document are limited to {max_px} px in all", sample.bytes() * 8)));
|
||||
}
|
||||
@@ -762,17 +767,22 @@ mod tests {
|
||||
assert!(e.contains("16-bit") && e.contains("33554432"), "{e}");
|
||||
}
|
||||
|
||||
/// A pattern of the largest area Define Pattern accepts at 8 bits is paintable: held at 4
|
||||
/// bytes a pixel, 256 MB, as the compositor's cap allows, and it renders.
|
||||
/// A pattern at the area limit is paintable and renders; production permits 8000×8000 at 8 bits.
|
||||
#[test]
|
||||
fn an_8000_by_8000_pattern_is_defined_and_paints() {
|
||||
fn a_pattern_at_the_area_limit_is_defined_and_paints() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 8000, "height": 8000, "depth": 8})).unwrap();
|
||||
assert_eq!(MAX_DEFINE_EDGE, 8000);
|
||||
assert!(photocraft_doc::pattern::max_paint_pixels(SampleType::U8) >= 8000 * 8000);
|
||||
assert_eq!(photocraft_doc::pattern::working_bytes_for(8000 * 8000, SampleType::U8), 8000 * 8000 * 4);
|
||||
let (side, max_px) = (80, 80 * 80);
|
||||
s.execute("file.new", json!({"width": side, "height": side, "depth": 8})).unwrap();
|
||||
s.execute("edit.fill", json!({"color": "#336699"})).unwrap();
|
||||
s.execute("edit.definePattern", json!({"name": "Largest"})).unwrap();
|
||||
assert!(define_with_max_pixels(&mut s, &json!({"name": "Too large"}), max_px - 1).is_err());
|
||||
define_with_max_pixels(&mut s, &json!({"name": "Largest"}), max_px).unwrap();
|
||||
let p = s.patterns.items.iter().find(|p| p.name == "Largest").unwrap();
|
||||
assert_eq!((p.width, p.height), (8000, 8000));
|
||||
assert!(p.is_paintable() && p.working_bytes() == 256_000_000);
|
||||
assert_eq!((p.width, p.height), (side, side));
|
||||
// A small pattern uses the expanded float representation, unlike the largest 8-bit one.
|
||||
assert!(p.is_paintable() && p.working_bytes() == max_px * 16);
|
||||
s.execute("file.new", json!({"width": 40, "height": 30, "depth": 8})).unwrap();
|
||||
s.execute("layer.newFillLayer.pattern", json!({"pattern": "Largest"})).unwrap();
|
||||
let [r, g, b, a] = pixel(&s, 5, 5);
|
||||
|
||||
@@ -155,7 +155,7 @@ fn add_abr_presets(s: &mut Session, p: &Value, group: String, imp: photocraft_io
|
||||
// in Photoshop, unless `replace` asks to drop that group's own presets first: the group name
|
||||
// is only the file name, and the library is outside document history (#10640).
|
||||
let group = if p.get("replace").and_then(Value::as_bool).unwrap_or(false) {
|
||||
s.tools.presets.retain(|x| x.builtin || x.group != group);
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).retain(|x| x.builtin || x.group != group);
|
||||
group
|
||||
} else {
|
||||
// One pass over the library, not one per numbered candidate.
|
||||
@@ -168,7 +168,7 @@ fn add_abr_presets(s: &mut Session, p: &Value, group: String, imp: photocraft_io
|
||||
preset.group.clone_from(&group);
|
||||
preset.name = taken.unique(&preset.name);
|
||||
names.push(preset.name.clone());
|
||||
s.tools.presets.push(preset);
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(preset);
|
||||
}
|
||||
s.brush_presets_changed();
|
||||
if p.get("select").and_then(Value::as_bool).unwrap_or(false)
|
||||
@@ -262,7 +262,7 @@ fn import_image(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (v, w, h) = image_paint(&doc, cmd)?;
|
||||
let (brush, tw, th) = crate::brush_cmds::sampled_brush(cmd, &v, w, h)?;
|
||||
let name = UniqueNames::new(s.tools.presets.iter().map(|x| x.name.as_str())).unique(&name);
|
||||
s.tools.presets.push(photocraft_paint::BrushPreset {
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(photocraft_paint::BrushPreset {
|
||||
name: name.clone(),
|
||||
brush: brush.clone(),
|
||||
builtin: false,
|
||||
@@ -541,7 +541,7 @@ mod tests {
|
||||
// The user's own brush moved into the group.
|
||||
let mut own = s.tools.presets.iter().find(|p| p.group == "Kit").unwrap().clone();
|
||||
own.name = "My Ink".into();
|
||||
s.tools.presets.push(own);
|
||||
std::sync::Arc::make_mut(&mut s.tools.presets).push(own);
|
||||
let r = s.execute("brush.presets.importAbr", json!({"data": data, "group": "Kit"})).unwrap();
|
||||
assert_eq!(r["group"], "Kit (2)");
|
||||
let in_group = |s: &Session, g: &str| s.tools.presets.iter().filter(|p| p.group == g).count();
|
||||
|
||||
@@ -64,7 +64,7 @@ fn bake_one(s: &mut Session, id: LayerId, key: &str) -> Result<bool> {
|
||||
if !area.is_empty() {
|
||||
// Render the layer on its own with the document's settings (mode, depth, global
|
||||
// light, patterns), then put the real stack back.
|
||||
let stack = std::mem::replace(&mut doc.layers, vec![alone]);
|
||||
let stack = std::mem::replace(&mut doc.layers, vec![alone].into());
|
||||
let buf = photocraft_compose::render(doc, area);
|
||||
doc.layers = stack;
|
||||
let n = fmt.channels();
|
||||
|
||||
@@ -22,7 +22,7 @@ use photocraft_raster::{Surface, from_rgba_into, to_rgba};
|
||||
use rayon::prelude::*;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::commands::{CommandSpec, blend_from_str};
|
||||
use crate::commands::{CommandSpec, parse_blend};
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
mod art_history;
|
||||
@@ -411,7 +411,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
menu: &[],
|
||||
shortcut: None,
|
||||
params: brush_params!(
|
||||
r#","state":row (a History panel row, as history.setSource),"snapshot":id (a history.newSnapshot id; default: the History panel's source, as paint.historyBrush; a source of another canvas size or colour mode is an error),"style":"tightShort|tightMedium|tightLong|looseMedium|looseLong|dab|tightCurl|looseCurl"="tightShort","area":0..100=50,"tolerance":0..100=0,"opacity":0..100=100 (overrides the common 1..100: how strongly the history state is painted; 0 changes nothing; no flow, mode is Normal)"#
|
||||
r#","state":row (a History panel row, as history.setSource),"snapshot":id (a history.newSnapshot id; default: the History panel's source, as paint.historyBrush; a source of another canvas size or colour mode is an error),"style":"tightShort|tightMedium|tightLong|looseMedium|looseLong|dab|tightCurl|looseCurl"="tightShort","area":0..500=50,"tolerance":0..100=0,"opacity":0..100=100 (overrides the common 1..100: how strongly the history state is painted; 0 changes nothing; no flow, mode is Normal)"#
|
||||
),
|
||||
enabled: has_pixel_layer,
|
||||
run: art_history::run,
|
||||
|
||||
@@ -204,7 +204,8 @@ pub fn run(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let hardness = ranged(p, "hardness", s.tools.brush.hardness * 100.0, 0.0, 100.0)? / 100.0;
|
||||
let opacity = ranged(p, "opacity", 100.0, 0.0, 100.0)? / 100.0;
|
||||
let flow = ranged(p, "flow", 100.0, 0.0, 100.0)? / 100.0;
|
||||
let area = ranged(p, "area", 50.0, 0.0, 100.0)?;
|
||||
// Area takes 0..500 px, as the reference's field does (#12630).
|
||||
let area = ranged(p, "area", 50.0, 0.0, 500.0)?;
|
||||
// Percent of the channel range; 0 (paint everywhere) is the default, as in Photoshop.
|
||||
let tolerance = ranged(p, "tolerance", 0.0, 0.0, 100.0)? / 100.0;
|
||||
let style = style_of(p)?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::heal::history_source;
|
||||
use super::sampling::{SampleLayers, sample_layers};
|
||||
use super::{
|
||||
BlendMode, BrushSettings, Document, EngineError, LayerId, PixelFormat, Rect, Region, Result, SampleType, Session, Stroke, StrokePoint, Surface, Value,
|
||||
alpha_index, apply_coverage, bad, blend_from_str, coverage, damage_json, flag, has_pixel_layer, json, parse_brush, pattern_stamp, periodic, point,
|
||||
alpha_index, apply_coverage, bad, coverage, damage_json, flag, has_pixel_layer, json, parse_blend, parse_brush, pattern_stamp, periodic, point,
|
||||
reject_huge_stroke, run_stroke, to_rgba,
|
||||
};
|
||||
|
||||
@@ -212,7 +212,7 @@ pub(super) fn clone_result(dmg: Rect, off: (i32, i32), aligned: bool, p: &Value,
|
||||
pub(super) fn blend_param(p: &Value, cmd: &str) -> Result<BlendMode> {
|
||||
match p.get("mode").and_then(Value::as_str) {
|
||||
None => Ok(BlendMode::Normal),
|
||||
Some(m) => blend_from_str(m).ok_or_else(|| bad(cmd, format!("unknown blend mode `{m}`"))),
|
||||
Some(m) => parse_blend(m).ok_or_else(|| bad(cmd, format!("unknown blend mode `{m}`"))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -696,12 +696,18 @@ impl ContentAwarePreview {
|
||||
/// Prepare the preview of `paint.contentAwareMove` with params `p` on the active document. Errors
|
||||
/// as the command does (bad params, nothing to move, a selection larger than the command takes).
|
||||
pub fn preview(s: &Session, p: &Value) -> Result<ContentAwarePreview> {
|
||||
preview_with_pixel_budget(s, p, PREVIEW_MAX_PIXELS)
|
||||
}
|
||||
|
||||
/// Prepare a preview with a bound on the number of pixels solved at full resolution.
|
||||
pub(crate) fn preview_with_pixel_budget(s: &Session, p: &Value, max_pixels: u64) -> Result<ContentAwarePreview> {
|
||||
let captured = crate::channel_cmds::inject_target(s, CMD, p.clone());
|
||||
let p = &captured;
|
||||
let plan = plan(s, p, PREVIEW_MARGIN)?;
|
||||
let px = |r: Rect| u64::from(r.width()) * u64::from(r.height());
|
||||
let pixels = px(plan.area).max(px(plan.dest));
|
||||
let scale = if pixels > PREVIEW_MAX_PIXELS { (PREVIEW_MAX_PIXELS as f64 / pixels as f64).sqrt() } else { 1.0 };
|
||||
let max_pixels = max_pixels.max(1);
|
||||
let scale = if pixels > max_pixels { (max_pixels as f64 / pixels as f64).sqrt() } else { 1.0 };
|
||||
let d = s.active().ok_or(EngineError::NoDocument)?;
|
||||
Ok(ContentAwarePreview { colors: crate::color_channels::target(s, p)?, doc: d.doc.clone(), plan, params: p.clone(), scale })
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::sampling::{AllLayers, sample_all_layers};
|
||||
use super::{
|
||||
BlendMode, BrushSettings, Document, EngineError, Footprint, IndexedParallelIterator, LayerId, ParallelIterator, ParallelSliceMut, PixelFormat, Rect,
|
||||
Region, Result, Session, Smudge, Stroke, StrokePoint, Surface, ToneRange, Value, alpha_index, apply_dab_stroke, bad, blend_from_str, damage_json,
|
||||
dodge_burn, flag, from_rgba_into, has_pixel_layer, json, local_blur, local_sharpen, num, parse_brush, run_stroke, sponge, string, to_rgba,
|
||||
Region, Result, Session, Smudge, Stroke, StrokePoint, Surface, ToneRange, Value, alpha_index, apply_dab_stroke, bad, damage_json, dodge_burn, flag,
|
||||
from_rgba_into, has_pixel_layer, json, local_blur, local_sharpen, num, parse_blend, parse_brush, run_stroke, sponge, string, to_rgba,
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -206,7 +206,7 @@ pub(super) enum DabTool {
|
||||
fn smudge_mode(p: &Value, cmd: &str) -> Result<BlendMode> {
|
||||
use BlendMode::{Color, Darken, Hue, Lighten, Luminosity, Normal, Saturation};
|
||||
let Some(v) = p.get("mode") else { return Ok(Normal) };
|
||||
let named = v.as_str().and_then(blend_from_str).filter(|m| matches!(m, Normal | Darken | Lighten | Hue | Saturation | Color | Luminosity));
|
||||
let named = v.as_str().and_then(parse_blend).filter(|m| matches!(m, Normal | Darken | Lighten | Hue | Saturation | Color | Luminosity));
|
||||
named.ok_or_else(|| {
|
||||
let given = v.as_str().map_or_else(|| v.to_string(), str::to_owned);
|
||||
bad(cmd, format!("unknown mode `{given}` (normal|darken|lighten|hue|saturation|color|luminosity)"))
|
||||
|
||||
@@ -1650,10 +1650,11 @@ fn large_move(depth: u64) -> Session {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_aware_move_previews_large_selections_coarse_then_exact_at_all_depths() {
|
||||
fn content_aware_move_previews_large_selections_coarse_then_exact() {
|
||||
use crate::jobs::JobCtx;
|
||||
let p = json!({"offset": [250, 60]});
|
||||
for depth in DEPTHS {
|
||||
// The small move test covers all depths; the preview sequence needs one.
|
||||
for depth in [8] {
|
||||
let mut s = large_move(depth);
|
||||
let before = s.active().unwrap().revision;
|
||||
let job = content_aware_move_preview(&s, &p).unwrap();
|
||||
@@ -1684,9 +1685,6 @@ fn content_aware_move_previews_large_selections_coarse_then_exact_at_all_depths(
|
||||
let fine = job.refine().unwrap();
|
||||
assert!(!fine.is_coarse() && fine.refine().is_none());
|
||||
assert!(matches!(fine.run(&ctx), Err(EngineError::Cancelled)), "depth {depth}");
|
||||
if depth != 8 {
|
||||
continue;
|
||||
}
|
||||
// The refined preview is the command's result, bit for bit.
|
||||
let (exact, _) = fine.run(&JobCtx::new()).unwrap();
|
||||
assert_eq!(s.active().unwrap().revision, before);
|
||||
@@ -1700,15 +1698,21 @@ fn content_aware_move_previews_large_selections_coarse_then_exact_at_all_depths(
|
||||
#[test]
|
||||
fn content_aware_move_coarse_preview_handles_transform_extend_and_limits() {
|
||||
use crate::jobs::JobCtx;
|
||||
let s = large_move(8);
|
||||
let mut s = session(128, 64, 8, "rgb");
|
||||
paint_layer(&mut s, with_object(20, 26));
|
||||
s.execute("select.rect", json!({"x": 16, "y": 22, "width": 20, "height": 20})).unwrap();
|
||||
let px = |d: &Document, x, y| d.layers[0].surface().unwrap().rgba(x, y);
|
||||
// Transform On Drop: turned 90° about the selection's centre (210, 160), then moved; the
|
||||
// object sits at the centre, so it lands at (460, 220) either way.
|
||||
let (turned, _) = content_aware_move_preview(&s, &json!({"offset": [250, 60], "rotate": 90})).unwrap().run(&JobCtx::new()).unwrap();
|
||||
assert!(is_object(px(&turned, 460, 220)) && !is_object(px(&turned, 210, 160)));
|
||||
// A 400-pixel selection is just over the preview budget. It turns about its centre and moves.
|
||||
let preview = |p: &Value| content_aware_move::preview_with_pixel_budget(&s, p, 399);
|
||||
let job = preview(&json!({"offset": [70, 0], "rotate": 90})).unwrap();
|
||||
assert!(job.is_coarse());
|
||||
let (turned, _) = job.run(&JobCtx::new()).unwrap();
|
||||
assert!(is_object(px(&turned, 96, 32)) && !is_object(px(&turned, 26, 32)));
|
||||
// Extend keeps the original.
|
||||
let (extended, _) = content_aware_move_preview(&s, &json!({"offset": [250, 60], "mode": "extend"})).unwrap().run(&JobCtx::new()).unwrap();
|
||||
assert!(is_object(px(&extended, 460, 220)) && is_object(px(&extended, 210, 160)));
|
||||
let job = preview(&json!({"offset": [70, 0], "mode": "extend"})).unwrap();
|
||||
assert!(job.is_coarse());
|
||||
let (extended, _) = job.run(&JobCtx::new()).unwrap();
|
||||
assert!(is_object(px(&extended, 96, 32)) && is_object(px(&extended, 26, 32)));
|
||||
// Off the canvas, or past the command's own limit, is still an error.
|
||||
assert!(content_aware_move_preview(&s, &json!({"offset": [400, 0]})).is_err());
|
||||
let mut big = session(5000, 4000, 8, "rgb");
|
||||
@@ -2302,7 +2306,9 @@ fn live_dab_strokes_commit_their_pixels_and_they_are_the_commands() {
|
||||
fn live_dab_batches_match_the_accumulating_renderer() {
|
||||
use photocraft_paint::{GrayTile, StrokeRenderer, TipShape};
|
||||
|
||||
for depth in DEPTHS {
|
||||
// 8 bits (integers, and the measured Smudge mode only 8-bit RGB gets in `dab.rs`) and 32 bits (floats): 16 bits
|
||||
// differs from 8 only in the raster's shared encode, which the live and the reference renderer both use (#15652).
|
||||
for depth in [8, 32] {
|
||||
let mut s = session(200, 90, depth, "rgb");
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
paint_layer(&mut s, |x, y| {
|
||||
|
||||
@@ -158,7 +158,7 @@ fn sampled_document(doc: &Document, active: Option<LayerId>, which: SampleLayers
|
||||
layer.fill_opacity = 1.0;
|
||||
layer.blend = photocraft_color::BlendMode::Normal;
|
||||
let mut solo = doc.clone();
|
||||
solo.layers = vec![layer];
|
||||
solo.layers = vec![layer].into();
|
||||
return Some(Cow::Owned(solo));
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -34,7 +34,7 @@ use photocraft_raster::Surface;
|
||||
use serde_json::{Value, json};
|
||||
use stack_cache::{Stage, StageKey};
|
||||
|
||||
use crate::commands::{CommandSpec, blend_from_str, layer_param};
|
||||
use crate::commands::{CommandSpec, layer_param, parse_blend};
|
||||
use crate::jobs::JobCtx;
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
@@ -70,7 +70,12 @@ pub fn encode_source(doc: &Document) -> Result<Vec<u8>> {
|
||||
|
||||
/// Decodes smart-object contents (a `.pcraft` bundle, PSD/PSB, or any flat image format).
|
||||
pub fn decode_source(file_name: &str, bytes: &[u8]) -> Result<Document> {
|
||||
if photocraft_io::svg::is_svg(bytes) {
|
||||
decode_source_classified(file_name, bytes, photocraft_io::svg::is_svg(bytes))
|
||||
}
|
||||
|
||||
/// Reuse the central format decision made by this render operation.
|
||||
fn decode_source_classified(file_name: &str, bytes: &[u8], svg: bool) -> Result<Document> {
|
||||
if svg {
|
||||
// This API has no warning channel. Stack/source caches and contents edits must not
|
||||
// turn a partial SVG import into silently complete smart-object contents.
|
||||
return photocraft_io::svg::import_svg_bounded_images_strict(file_name, bytes, 24_000_000)
|
||||
@@ -197,13 +202,13 @@ pub(crate) use placing::detach_psd;
|
||||
pub(crate) use placing::{affine_homography, set_placement, shift_smart, transform_placement};
|
||||
use placing::{convert, reset_transform, shift_layer, via_copy};
|
||||
pub use placing::{layer_to_smart, layers_to_smart, placement};
|
||||
#[cfg(test)]
|
||||
pub(crate) use rendering::DISPLAY_NATIVE_HASH_BYTES;
|
||||
use rendering::refresh_or_fail;
|
||||
#[cfg(test)]
|
||||
pub(crate) use rendering::{DISPLAY_NATIVE_HASH_BYTES, WARNING_SOURCE_DECODES, WARNING_SOURCE_LIMIT};
|
||||
#[cfg(test)]
|
||||
use rendering::{NativeDigests, blend_surfaces, place, render_in};
|
||||
pub(crate) use rendering::{WarningRenderSources, render_with_warnings, render_with_warnings_using, source_box};
|
||||
pub use rendering::{apply_smart_filters, purge_stack_cache, refresh, refresh_layer, render, render_below_filter, stack_cache_bytes, stack_image};
|
||||
pub(crate) use rendering::{render_with_warnings, source_box};
|
||||
#[cfg(test)]
|
||||
use source::svg_source_image_in;
|
||||
pub use source::{SourceImage, purge_source_cache, source_bytes, source_cache_bytes, source_decode_count, source_image, svg_source_image};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::rendering::{refresh_or_fail, refresh_or_fail_in};
|
||||
use super::source::source_bytes;
|
||||
use super::{
|
||||
BlendMode, Document, EngineError, Layer, LayerContent, LayerId, LayerMask, Result, Session, SmartObject, Surface, Value, bad, blend_from_str, json,
|
||||
layer_param, other,
|
||||
BlendMode, Document, EngineError, Layer, LayerContent, LayerId, LayerMask, Result, Session, SmartObject, Surface, Value, bad, json, layer_param, other,
|
||||
parse_blend,
|
||||
};
|
||||
|
||||
pub(super) fn smart(doc: &Document, id: LayerId) -> Result<&SmartObject> {
|
||||
@@ -241,7 +241,7 @@ pub(super) fn set_filter_params(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
pub(super) fn blending_options(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "layer.smartFilter.blendingOptions";
|
||||
let blend = match p.get("blend").and_then(Value::as_str) {
|
||||
Some(b) => Some(blend_from_str(b).filter(|m| *m != BlendMode::PassThrough).ok_or_else(|| bad(CMD, format!("unknown blend mode `{b}`")))?),
|
||||
Some(b) => Some(parse_blend(b).filter(|m| *m != BlendMode::PassThrough).ok_or_else(|| bad(CMD, format!("unknown blend mode `{b}`")))?),
|
||||
None => None,
|
||||
};
|
||||
let opacity = p.get("opacity").and_then(Value::as_f64).map(|o| if o > 1.0 { o / 100.0 } else { o } as f32);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::rendering::{refresh_or_fail, unapplied_filters};
|
||||
use super::source::{SourceImage, buffer_to_surface, cache_key, cache_put, source_bytes};
|
||||
use super::source::{SourceImage, buffer_to_surface, cache_put, source_bytes, source_cache_key};
|
||||
use super::{
|
||||
Affine, Arc, BlendMode, Document, EngineError, Homography, Layer, LayerContent, LayerId, PLACED_KEYS, Rect, Result, Session, Size, SmartContentsId,
|
||||
SmartObject, SmartSource, Surface, Value, encode_source, json, layer_param, other, source_box, translate_surface,
|
||||
@@ -236,7 +236,7 @@ pub fn layers_to_smart(doc: &Document, name: &str, layers: Vec<Layer>) -> Result
|
||||
}
|
||||
let has_fx = layers.iter().any(|l| any_layer(l, &|x| x.effects.enabled && !x.effects.items.is_empty()));
|
||||
let region = layers.iter().map(|l| subtree_bounds(l, canvas)).fold(canvas, |a, b| a.union(&b)).inflate(if has_fx { 256 } else { 0 });
|
||||
sub.layers = layers;
|
||||
sub.layers = layers.into();
|
||||
|
||||
let buf = photocraft_compose::render(&sub, region);
|
||||
let w = region.width() as usize;
|
||||
@@ -258,8 +258,11 @@ pub fn layers_to_smart(doc: &Document, name: &str, layers: Vec<Layer>) -> Result
|
||||
sub.layers.iter_mut().for_each(|l| shift_layer(l, -b.x0, -b.y0));
|
||||
sub.size = Size::new(b.width(), b.height());
|
||||
let bytes = encode_source(&sub)?;
|
||||
// Seed the decode cache with the composite we already have.
|
||||
cache_put(cache_key(&bytes, fmt), SourceImage { surface: Arc::new(translate_surface(&cache, -b.x0, -b.y0)), bounds: sub.bounds() });
|
||||
// The encoded native document is non-SVG; match the classified render/bounds path.
|
||||
cache_put(
|
||||
source_cache_key(&sub.name, &bytes, fmt, Some(false)),
|
||||
SourceImage { surface: Arc::new(translate_surface(&cache, -b.x0, -b.y0)), bounds: sub.bounds() },
|
||||
);
|
||||
|
||||
let source = SmartSource::Embedded { file_name: sub.name.clone(), bytes: Arc::new(bytes) };
|
||||
Ok(Layer::new(name, LayerContent::Smart(SmartObject::new(source, Affine::translate(b.x0 as f64, b.y0 as f64), Some(cache)))))
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
use super::filters::smart;
|
||||
use super::source::{
|
||||
SourceImage, cache_get, cache_key, cache_put, convert_svg_source, source_bytes, source_image, source_surface_from_buffer, svg_source_image_in, vector_scale,
|
||||
SourceImage, cache_get, cache_key, cache_put, convert_svg_source, source_bytes, source_surface_from_buffer, svg_source_image_in, vector_scale,
|
||||
};
|
||||
use super::{
|
||||
Affine, Arc, BlendMode, Document, EngineError, Homography, JobCtx, Layer, LayerContent, LayerId, PixelFormat, Rect, Result, SmartFilter, SmartObject,
|
||||
SmartSource, Stage, StageKey, Surface, Value, affine_homography, decode_source, other, placement, stack_cache,
|
||||
SmartSource, Stage, StageKey, Surface, Value, affine_homography, other, placement, stack_cache,
|
||||
};
|
||||
use std::sync::Mutex;
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::{Mutex, Weak};
|
||||
|
||||
/// Layer › Smart Objects › Stack Mode: the source's layers (or, when it holds a single group, the
|
||||
/// group's layers) combined per pixel with `mode`. Cached like [`source_image`], keyed by mode.
|
||||
/// group's layers) combined per pixel with `mode`. Cached like [`super::source_image`], keyed by mode.
|
||||
pub fn stack_image(file_name: &str, bytes: &[u8], fmt: PixelFormat, mode: photocraft_doc::StackMode) -> Result<SourceImage> {
|
||||
stack_image_classified(file_name, bytes, fmt, mode, None)
|
||||
}
|
||||
|
||||
fn stack_image_classified(file_name: &str, bytes: &[u8], fmt: PixelFormat, mode: photocraft_doc::StackMode, svg: Option<bool>) -> Result<SourceImage> {
|
||||
use photocraft_algo::stack::Stat;
|
||||
let mut key = cache_key(bytes, fmt);
|
||||
key.0 = *blake3::hash(&[&key.0[..], b"stack:", mode.id().as_bytes()].concat()).as_bytes();
|
||||
// Keep the filename in the key because fallback import uses it to choose a format.
|
||||
// Use a separate domain from entries that predate plain SVG completeness checks.
|
||||
key.0 = *blake3::hash(&[&key.0[..], b"stack-source-v3:", blake3::hash(file_name.as_bytes()).as_bytes(), mode.id().as_bytes()].concat()).as_bytes();
|
||||
if let Some(img) = cache_get(&key) {
|
||||
return Ok(img);
|
||||
}
|
||||
let doc = decode_source(file_name, bytes)?;
|
||||
let svg = svg.unwrap_or_else(|| photocraft_io::svg::is_svg(bytes));
|
||||
let doc = super::decode_source_classified(file_name, bytes, svg)?;
|
||||
let layers: &[Layer] = match doc.layers.as_slice() {
|
||||
[only] if only.is_group() => only.children().unwrap_or_default(),
|
||||
all => all,
|
||||
@@ -25,7 +33,7 @@ pub fn stack_image(file_name: &str, bytes: &[u8], fmt: PixelFormat, mode: photoc
|
||||
let bounds = doc.bounds();
|
||||
// An SVG opens with one layer per shape, and every visible one gets its own float frame:
|
||||
// they may take 1 GiB together, the SVG import's own budget, before any is rendered.
|
||||
if photocraft_io::svg::is_svg(bytes) {
|
||||
if svg {
|
||||
let visible = u64::try_from(layers.iter().filter(|l| l.visible).count()).unwrap_or(u64::MAX);
|
||||
let frame_bytes = doc.size.area().saturating_mul(16);
|
||||
if visible.saturating_mul(frame_bytes) > 1 << 30 {
|
||||
@@ -173,16 +181,24 @@ fn apply_smart_filter(f: &SmartFilter, sm: &SmartObject, cur: &Surface, canvas:
|
||||
if f.blend == BlendMode::Normal && f.opacity >= 1.0 { Ok(out) } else { Ok(blend_surfaces(cur, &out, f.blend, f.opacity.clamp(0.0, 1.0))) }
|
||||
}
|
||||
|
||||
/// The source placed in document pixels, before any smart filter.
|
||||
/// The source placed in document pixels, before any smart filter (uncached test oracle).
|
||||
#[cfg(test)]
|
||||
pub(super) fn place(name: &str, bytes: &[u8], doc: &Document, sm: &SmartObject) -> Result<Surface> {
|
||||
place_with_svg(name, bytes, doc, sm, &mut |bytes, scale| svg_source_image_in(bytes, doc, scale))
|
||||
place_with_svg(name, bytes, doc, sm, photocraft_io::svg::is_svg(bytes), &mut |bytes, scale| svg_source_image_in(bytes, doc, scale))
|
||||
}
|
||||
|
||||
fn place_with_svg(name: &str, bytes: &[u8], doc: &Document, sm: &SmartObject, svg: &mut impl FnMut(&[u8], f64) -> Result<SourceImage>) -> Result<Surface> {
|
||||
fn place_with_svg(
|
||||
name: &str,
|
||||
bytes: &[u8],
|
||||
doc: &Document,
|
||||
sm: &SmartObject,
|
||||
is_svg: bool,
|
||||
svg: &mut impl FnMut(&[u8], f64) -> Result<SourceImage>,
|
||||
) -> Result<Surface> {
|
||||
let fmt = doc.pixel_format();
|
||||
// A vector source is rendered at the placement's scale, and the placement is divided by
|
||||
// that scale so the rendered pixels land where the source units would.
|
||||
if sm.stack_mode.is_none() && sm.warp.is_none() && photocraft_io::svg::is_svg(bytes) {
|
||||
if sm.stack_mode.is_none() && sm.warp.is_none() && is_svg {
|
||||
let k = vector_scale(sm);
|
||||
let img = svg(bytes, k)?;
|
||||
return Ok(match &sm.perspective {
|
||||
@@ -201,10 +217,10 @@ fn place_with_svg(name: &str, bytes: &[u8], doc: &Document, sm: &SmartObject, sv
|
||||
});
|
||||
}
|
||||
let img = match sm.stack_mode {
|
||||
Some(mode) if photocraft_io::svg::is_svg(bytes) => convert_svg_source(stack_image(name, bytes, PixelFormat::RGBA32F, mode)?, doc)?,
|
||||
None if photocraft_io::svg::is_svg(bytes) => svg(bytes, 1.0)?,
|
||||
Some(mode) => stack_image(name, bytes, fmt, mode)?,
|
||||
None => source_image(name, bytes, fmt)?,
|
||||
Some(mode) if is_svg => convert_svg_source(stack_image_classified(name, bytes, PixelFormat::RGBA32F, mode, Some(is_svg))?, doc)?,
|
||||
None if is_svg => svg(bytes, 1.0)?,
|
||||
Some(mode) => stack_image_classified(name, bytes, fmt, mode, Some(is_svg))?,
|
||||
None => super::source::source_image_classified(name, bytes, fmt, is_svg)?,
|
||||
};
|
||||
// The placed stage is unclipped: a large enough placement (an image scaled to fill a huge
|
||||
// frame) would otherwise fill memory before any allocation could fail.
|
||||
@@ -312,7 +328,7 @@ pub(crate) fn source_box(doc: &Document, sm: &SmartObject) -> Option<[f64; 4]> {
|
||||
let r = match sm.stack_mode {
|
||||
None if photocraft_io::svg::is_svg(&bytes) => photocraft_io::svg::bounded_canvas_bounds(&bytes, 24_000_000).ok()?,
|
||||
Some(mode) => stack_image(&name, &bytes, fmt, mode).ok()?.bounds,
|
||||
None => source_image(&name, &bytes, fmt).ok()?.bounds,
|
||||
None => super::source::source_image(&name, &bytes, fmt).ok()?.bounds,
|
||||
};
|
||||
Some([f64::from(r.x0), f64::from(r.y0), f64::from(r.x1), f64::from(r.y1)])
|
||||
}
|
||||
@@ -324,28 +340,143 @@ pub fn render(doc: &Document, sm: &SmartObject) -> Result<Option<Surface>> {
|
||||
}
|
||||
|
||||
/// Command-only rendering that retains usable SVG artwork and reports omitted embedded images.
|
||||
/// It deliberately bypasses both source and filter-stage caches: a later warningless render
|
||||
/// must not accidentally reuse an incomplete surface. Native previews remain strict.
|
||||
/// Its local source cache never enters the strict process-wide source/filter caches.
|
||||
pub(crate) fn render_with_warnings(doc: &Document, sm: &SmartObject) -> Result<(Option<Surface>, Vec<String>)> {
|
||||
let Some((name, bytes)) = source_bytes(&doc.metadata, &sm.source) else { return Ok((None, Vec::new())) };
|
||||
if !photocraft_io::svg::is_svg(&bytes) || sm.vector_preview.is_some() || sm.stack_mode.is_some() {
|
||||
render_with_warnings_using(sm, &mut WarningRenderSources::new(doc))
|
||||
}
|
||||
|
||||
struct WarningSource {
|
||||
source: Weak<Vec<u8>>,
|
||||
name: [u8; 32],
|
||||
scale: u64,
|
||||
image: SourceImage,
|
||||
warnings: Vec<String>,
|
||||
bytes: usize,
|
||||
}
|
||||
|
||||
/// One command's bounded source-space renders. Placement, warp, filters and masks
|
||||
/// are instance-specific and must never be cached here. Weak identity pins only the
|
||||
/// allocation header; the borrowed document owns encoded bytes throughout the command.
|
||||
pub(crate) struct WarningRenderSources<'a> {
|
||||
document: &'a Document,
|
||||
srgb: Option<bool>,
|
||||
entries: VecDeque<WarningSource>,
|
||||
budget: usize,
|
||||
limit: usize,
|
||||
bytes: usize,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
pub(crate) static WARNING_SOURCE_DECODES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
pub(crate) static WARNING_SOURCE_LIMIT: std::cell::Cell<Option<usize>> = const { std::cell::Cell::new(None) };
|
||||
}
|
||||
|
||||
impl<'a> WarningRenderSources<'a> {
|
||||
pub(crate) fn new(document: &'a Document) -> Self {
|
||||
#[cfg(test)]
|
||||
let limit = WARNING_SOURCE_LIMIT.with(|limit| limit.get().unwrap_or(32));
|
||||
#[cfg(not(test))]
|
||||
let limit = 32;
|
||||
Self { document, srgb: None, entries: VecDeque::new(), budget: if cfg!(target_arch = "wasm32") { 128 << 20 } else { 384 << 20 }, limit, bytes: 0 }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn with_limits(document: &'a Document, budget: usize, limit: usize) -> Self {
|
||||
Self { budget, limit, ..Self::new(document) }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn profile_initialized(&self) -> bool {
|
||||
self.srgb.is_some()
|
||||
}
|
||||
|
||||
fn image(&mut self, bytes: &Arc<Vec<u8>>, scale: f64, name: [u8; 32]) -> Result<(SourceImage, Vec<String>)> {
|
||||
let doc = self.document;
|
||||
// Non-SVG and unavailable sources keep their old fast path without
|
||||
// materializing ICC bytes. This immutable document needs the context once.
|
||||
let key = scale.to_bits();
|
||||
if let Some(index) =
|
||||
self.entries.iter().position(|entry| entry.scale == key && entry.name == name && std::ptr::eq(entry.source.as_ptr(), Arc::as_ptr(bytes)))
|
||||
&& let Some(entry) = self.entries.remove(index)
|
||||
{
|
||||
let result = (entry.image.clone(), entry.warnings.clone());
|
||||
self.entries.push_back(entry);
|
||||
return Ok(result);
|
||||
}
|
||||
// Only the exact sRGB fast path needs this lazy, immutable document context.
|
||||
// Pixel format/profile do not belong in each entry's key: the document is borrowed.
|
||||
let srgb = *self.srgb.get_or_insert_with(|| {
|
||||
doc.mode == photocraft_color::ColorMode::Rgb
|
||||
&& crate::color_cmds::document_profile(doc).to_bytes().as_ref() == craft_cms::Builtin::Srgb.profile().to_bytes().as_ref()
|
||||
});
|
||||
#[cfg(test)]
|
||||
WARNING_SOURCE_DECODES.with(|count| count.set(count.get().saturating_add(1)));
|
||||
let (buf, warnings) = photocraft_io::svg::rasterize_bounded_with_warnings(bytes, scale as f32, 24_000_000)
|
||||
.map_err(|e| other(format!("can't render the SVG smart object: {e}")))?;
|
||||
// Charge owned native tiles, entry and warning storage, not borrowed encoded bytes.
|
||||
// This is a soft memo budget: oversize entries retain the existing uncached path.
|
||||
let cost = usize::try_from(photocraft_raster::tile_storage_bytes(buf.rect, &doc.pixel_format()))
|
||||
.unwrap_or(usize::MAX)
|
||||
.saturating_add(std::mem::size_of::<WarningSource>())
|
||||
.saturating_add(warnings.capacity().saturating_mul(std::mem::size_of::<String>()))
|
||||
.saturating_add(warnings.iter().fold(0usize, |total, warning| total.saturating_add(warning.capacity())));
|
||||
let admitted = self.limit != 0 && cost <= self.budget;
|
||||
if admitted {
|
||||
while self.entries.len() >= self.limit || self.bytes > self.budget - cost {
|
||||
let Some(entry) = self.entries.pop_front() else {
|
||||
// Recover conservatively if accounting ever outlives an empty queue.
|
||||
self.bytes = 0;
|
||||
break;
|
||||
};
|
||||
self.bytes = self.bytes.saturating_sub(entry.bytes);
|
||||
}
|
||||
}
|
||||
// Preserve the normal renderer's exact built-in sRGB fast path.
|
||||
// A full memo is optional. Let the placement proceed uncached if the
|
||||
// browser cannot afford retaining these tiles along with prior renders.
|
||||
let admitted = admitted && crate::memory_gate::ensure("retain the SVG source for this update", cost as u64).is_ok();
|
||||
let image = if srgb {
|
||||
SourceImage { surface: Arc::new(super::source::buffer_to_surface(&buf, doc.pixel_format())), bounds: buf.rect }
|
||||
} else {
|
||||
let source = SourceImage { surface: Arc::new(super::source::buffer_to_surface(&buf, PixelFormat::RGBA32F)), bounds: buf.rect };
|
||||
convert_svg_source(source, doc)?
|
||||
};
|
||||
if admitted && self.entries.try_reserve(1).is_ok() {
|
||||
self.bytes += cost; // cost was admitted against budget - bytes above.
|
||||
self.entries.push_back(WarningSource {
|
||||
source: Arc::downgrade(bytes),
|
||||
name,
|
||||
scale: key,
|
||||
image: image.clone(),
|
||||
warnings: warnings.clone(),
|
||||
bytes: cost,
|
||||
});
|
||||
}
|
||||
Ok((image, warnings))
|
||||
}
|
||||
}
|
||||
|
||||
/// Reuse only warning-aware source pixels during one shared-content update.
|
||||
pub(crate) fn render_with_warnings_using(sm: &SmartObject, sources: &mut WarningRenderSources<'_>) -> Result<(Option<Surface>, Vec<String>)> {
|
||||
let doc = sources.document;
|
||||
if sm.vector_preview.is_some() || sm.stack_mode.is_some() {
|
||||
return render(doc, sm).map(|surface| (surface, Vec::new()));
|
||||
}
|
||||
let Some((name, bytes)) = source_bytes(&doc.metadata, &sm.source) else { return Ok((None, Vec::new())) };
|
||||
if !photocraft_io::svg::is_svg(&bytes) {
|
||||
// Keep the same source snapshot for fallback, including authorized linked reads.
|
||||
return render_in_with_source(doc, sm, &JobCtx::new(), Some((name, bytes))).map(|surface| (surface, Vec::new()));
|
||||
}
|
||||
let name_key = *blake3::hash(name.as_bytes()).as_bytes();
|
||||
if !unapplied_filters(sm).is_empty() {
|
||||
return Err(other("the smart object has unsupported visible filters"));
|
||||
}
|
||||
let mut warnings = Vec::new();
|
||||
let placed = place_with_svg(&name, &bytes, doc, sm, &mut |bytes, scale| {
|
||||
let (buf, omitted) = photocraft_io::svg::rasterize_bounded_with_warnings(bytes, scale as f32, 24_000_000)
|
||||
.map_err(|e| other(format!("can't render the SVG smart object: {e}")))?;
|
||||
let placed = place_with_svg(&name, &bytes, doc, sm, true, &mut |_, scale| {
|
||||
let (image, omitted) = sources.image(&bytes, scale, name_key)?;
|
||||
warnings.extend(omitted);
|
||||
// Preserve the normal renderer's exact built-in sRGB fast path.
|
||||
let profile = crate::color_cmds::document_profile(doc);
|
||||
if doc.mode == photocraft_color::ColorMode::Rgb && profile.to_bytes().as_ref() == craft_cms::Builtin::Srgb.profile().to_bytes().as_ref() {
|
||||
return Ok(SourceImage { surface: Arc::new(super::source::buffer_to_surface(&buf, doc.pixel_format())), bounds: buf.rect });
|
||||
}
|
||||
let source = SourceImage { surface: Arc::new(super::source::buffer_to_surface(&buf, PixelFormat::RGBA32F)), bounds: buf.rect };
|
||||
convert_svg_source(source, doc)
|
||||
Ok(image)
|
||||
})?;
|
||||
Ok((Some(apply_smart_filters(&placed, sm, doc.bounds())?), warnings))
|
||||
}
|
||||
@@ -354,27 +485,33 @@ pub(crate) fn render_with_warnings(doc: &Document, sm: &SmartObject) -> Result<(
|
||||
/// is cancelled. Gives the same pixels as [`apply_smart_filters`] on the placed source, but
|
||||
/// starts from the deepest stage of the stack already rendered (see [`stack_cache`]).
|
||||
pub(super) fn render_in(doc: &Document, sm: &SmartObject, ctx: &JobCtx) -> Result<Option<Surface>> {
|
||||
// Stored filters can come from a file or another layer. Check before looking up cached
|
||||
// stages too: a trusted UI render may have populated this process-wide cache earlier.
|
||||
render_in_with_source(doc, sm, ctx, None)
|
||||
}
|
||||
|
||||
fn render_in_with_source(doc: &Document, sm: &SmartObject, ctx: &JobCtx, snapshot: Option<(String, Arc<Vec<u8>>)>) -> Result<Option<Surface>> {
|
||||
// A trusted UI render may have populated these stages. Check authority even on a hit.
|
||||
for filter in sm.smart_filters.iter().filter(|f| sm.filters_enabled && f.visible) {
|
||||
crate::jobs::authorize_render_command(&filter.command, &filter.params)?;
|
||||
}
|
||||
let Some((name, bytes)) = source_bytes(&doc.metadata, &sm.source) else { return Ok(None) };
|
||||
let bytes = display_source(sm, &bytes);
|
||||
let Some((name, original)) = snapshot.or_else(|| source_bytes(&doc.metadata, &sm.source)) else { return Ok(None) };
|
||||
let bytes = display_source(sm, &original);
|
||||
let (fmt, canvas) = (doc.pixel_format(), doc.bounds());
|
||||
let mut placed_key = stack_cache::placed_key(&bytes, fmt, sm, canvas);
|
||||
if photocraft_io::svg::is_svg(&bytes) {
|
||||
let mut h = blake3::Hasher::new();
|
||||
h.update(&placed_key);
|
||||
// Plain SVG uses the original strict vector path. Gzip sources use ordinary
|
||||
// file import and native-size pixels, as existing saved objects expect.
|
||||
let is_svg = photocraft_io::svg::is_svg(&bytes);
|
||||
let mut h = blake3::Hasher::new();
|
||||
h.update(b"smart-placement-v3:");
|
||||
h.update(&stack_cache::placed_key(&bytes, fmt, sm, canvas));
|
||||
h.update(blake3::hash(name.as_bytes()).as_bytes());
|
||||
if is_svg {
|
||||
h.update(&crate::color_cmds::document_profile(doc).to_bytes());
|
||||
placed_key = *h.finalize().as_bytes();
|
||||
}
|
||||
let placed_key: StageKey = *h.finalize().as_bytes();
|
||||
let placed = || -> Result<Stage> {
|
||||
if let Some(stage) = stack_cache::get(&placed_key) {
|
||||
return Ok(stage);
|
||||
}
|
||||
let surface = place(&name, &bytes, doc, sm)?;
|
||||
// Edge pixels repeat at the canvas ∪ placed-content edge, as for layer filters.
|
||||
let surface = place_with_svg(&name, &bytes, doc, sm, is_svg, &mut |bytes, scale| svg_source_image_in(bytes, doc, scale))?;
|
||||
let stage = Stage { extent: canvas.union(&surface.content_bounds()), surface };
|
||||
stack_cache::put(placed_key, &stage);
|
||||
Ok(stage)
|
||||
@@ -497,3 +634,7 @@ pub(super) fn refresh_or_fail_in(doc: &mut Document, id: LayerId, ctx: &JobCtx)
|
||||
}
|
||||
Err(other("the smart object's contents are unavailable (missing linked file?), so it can't be re-rendered"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/source_work.rs"]
|
||||
mod source_work_tests;
|
||||
@@ -70,7 +70,7 @@ pub struct SourceImage {
|
||||
pub bounds: Rect,
|
||||
}
|
||||
|
||||
type CacheKey = ([u8; 32], PixelFormat);
|
||||
pub(super) type CacheKey = ([u8; 32], PixelFormat, Option<[u8; 32]>);
|
||||
|
||||
struct CacheEntry {
|
||||
key: CacheKey,
|
||||
@@ -100,7 +100,23 @@ fn cache() -> std::sync::MutexGuard<'static, Vec<CacheEntry>> {
|
||||
}
|
||||
|
||||
pub(super) fn cache_key(bytes: &[u8], fmt: PixelFormat) -> CacheKey {
|
||||
(*blake3::hash(bytes).as_bytes(), fmt)
|
||||
(*blake3::hash(bytes).as_bytes(), fmt, None)
|
||||
}
|
||||
|
||||
/// Keep automatic recognition and caller-supplied classifications separate. The filename
|
||||
/// also selects extension-sensitive importers. Neither decision may be bypassed by a hit.
|
||||
pub(super) fn source_cache_key(file_name: &str, bytes: &[u8], fmt: PixelFormat, svg: Option<bool>) -> CacheKey {
|
||||
let mut key = cache_key(bytes, fmt);
|
||||
let mut context = blake3::Hasher::new();
|
||||
context.update(b"source-decode-context-v1\0");
|
||||
context.update(&[match svg {
|
||||
None => 0,
|
||||
Some(false) => 1,
|
||||
Some(true) => 2,
|
||||
}]);
|
||||
context.update(file_name.as_bytes());
|
||||
key.2 = Some(*context.finalize().as_bytes());
|
||||
key
|
||||
}
|
||||
|
||||
pub(super) fn cache_get(key: &CacheKey) -> Option<SourceImage> {
|
||||
@@ -136,7 +152,7 @@ fn cache_put_within(key: CacheKey, image: SourceImage, limit: usize) {
|
||||
/// How many times these contents were decoded at this pixel format (0 = never / evicted).
|
||||
pub fn source_decode_count(bytes: &[u8], fmt: PixelFormat) -> u32 {
|
||||
let key = cache_key(bytes, fmt);
|
||||
cache().iter().find(|e| e.key == key).map(|e| e.decodes).unwrap_or(0)
|
||||
cache().iter().filter(|e| e.key.0 == key.0 && e.key.1 == fmt).fold(0u32, |total, e| total.saturating_add(e.decodes))
|
||||
}
|
||||
|
||||
/// Bytes held by cached source composites.
|
||||
@@ -269,7 +285,7 @@ fn convert_source(src: &Document, fmt: PixelFormat, raster: impl FnOnce(PixelFor
|
||||
}
|
||||
let mut doc = Document::new(src.name.clone(), src.size, src.mode, src.depth);
|
||||
doc.icc_profile = src.icc_profile.clone();
|
||||
doc.layers = vec![Layer::new("source", LayerContent::Raster(raster(src.pixel_format())))];
|
||||
doc.layers = vec![Layer::new("source", LayerContent::Raster(raster(src.pixel_format())))].into();
|
||||
if gray {
|
||||
let gray_profile = crate::color_cmds::working_profile(ColorMode::Grayscale);
|
||||
crate::color_cmds::convert_document(&mut doc, &gray_profile, craft_cms::Intent::RelativeColorimetric, true)?;
|
||||
@@ -291,7 +307,7 @@ pub fn svg_source_image(bytes: &[u8], fmt: PixelFormat, scale: f64) -> Result<So
|
||||
let mut h = blake3::Hasher::new();
|
||||
h.update(bytes);
|
||||
h.update(&scale.to_bits().to_le_bytes());
|
||||
let key = (*h.finalize().as_bytes(), fmt);
|
||||
let key = (*h.finalize().as_bytes(), fmt, None);
|
||||
if let Some(img) = cache_get(&key) {
|
||||
return Ok(img);
|
||||
}
|
||||
@@ -318,7 +334,7 @@ pub(super) fn svg_source_image_in(bytes: &[u8], doc: &Document, scale: f64) -> R
|
||||
h.update(bytes);
|
||||
h.update(&scale.to_bits().to_le_bytes());
|
||||
h.update(&profile.to_bytes());
|
||||
let key = (*h.finalize().as_bytes(), fmt);
|
||||
let key = (*h.finalize().as_bytes(), fmt, None);
|
||||
if let Some(image) = cache_get(&key) {
|
||||
return Ok(image);
|
||||
}
|
||||
@@ -353,12 +369,23 @@ pub(crate) fn vector_scale(sm: &SmartObject) -> f64 {
|
||||
|
||||
/// The composited source image of `bytes` in pixel format `fmt` (decoded once, then cached).
|
||||
pub fn source_image(file_name: &str, bytes: &[u8], fmt: PixelFormat) -> Result<SourceImage> {
|
||||
let key = cache_key(bytes, fmt);
|
||||
source_image_inner(file_name, bytes, fmt, None)
|
||||
}
|
||||
|
||||
pub(super) fn source_image_classified(file_name: &str, bytes: &[u8], fmt: PixelFormat, svg: bool) -> Result<SourceImage> {
|
||||
source_image_inner(file_name, bytes, fmt, Some(svg))
|
||||
}
|
||||
|
||||
fn source_image_inner(file_name: &str, bytes: &[u8], fmt: PixelFormat, svg: Option<bool>) -> Result<SourceImage> {
|
||||
let key = source_cache_key(file_name, bytes, fmt, svg);
|
||||
if let Some(img) = cache_get(&key) {
|
||||
return Ok(img);
|
||||
}
|
||||
crate::memory_gate::ensure(&format!("render the smart object \u{201c}{file_name}\u{201d}"), crate::memory_gate::smart_render_need(bytes))?;
|
||||
let doc = decode_source(file_name, bytes)?;
|
||||
let doc = match svg {
|
||||
Some(svg) => super::decode_source_classified(file_name, bytes, svg)?,
|
||||
None => decode_source(file_name, bytes)?,
|
||||
};
|
||||
let img = SourceImage { surface: Arc::new(flattened_source(&doc, fmt)?), bounds: doc.bounds() };
|
||||
cache_put(key, img.clone());
|
||||
Ok(img)
|
||||
@@ -368,6 +395,36 @@ pub fn source_image(file_name: &str, bytes: &[u8], fmt: PixelFormat) -> Result<S
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn source_cache_keys_preserve_filename_and_classification() {
|
||||
let bytes = b"source context regression";
|
||||
let fmt = PixelFormat::RGBA8;
|
||||
let keys = [
|
||||
source_cache_key("source.png", bytes, fmt, None),
|
||||
source_cache_key("source.dat", bytes, fmt, None),
|
||||
source_cache_key("source.png", bytes, fmt, Some(false)),
|
||||
source_cache_key("source.png", bytes, fmt, Some(true)),
|
||||
cache_key(bytes, fmt),
|
||||
];
|
||||
for (i, key) in keys.iter().enumerate() {
|
||||
for other in &keys[i + 1..] {
|
||||
assert_ne!(key, other);
|
||||
}
|
||||
}
|
||||
assert_eq!(keys[0], source_cache_key("source.png", bytes, fmt, None));
|
||||
assert_ne!(keys[0], source_cache_key("source.png", bytes, PixelFormat::RGBA32F, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warm_raster_source_cannot_bypass_svg_classification() {
|
||||
let raster = photocraft_codecs::Image::from_u8(1, 1, photocraft_codecs::ChannelLayout::Rgb, vec![13, 47, 91]).unwrap();
|
||||
let png = photocraft_codecs::encode(&raster, photocraft_codecs::Format::Png, &Default::default()).unwrap();
|
||||
let name = "source-classification-regression.png";
|
||||
let first = source_image_classified(name, &png, PixelFormat::RGBA8, false).unwrap();
|
||||
assert_eq!(first.bounds, Rect::new(0, 0, 1, 1));
|
||||
assert!(source_image_classified(name, &png, PixelFormat::RGBA8, true).is_err(), "a warm raster hit must not skip strict SVG decoding");
|
||||
assert!(source_image(name, &png, PixelFormat::RGBA8).is_ok());
|
||||
}
|
||||
fn image(side: i32) -> SourceImage {
|
||||
let mut s = Surface::new(PixelFormat::RGBA8);
|
||||
s.fill_rect(Rect::new(0, 0, side, side), &[0.2, 0.4, 0.6, 1.0]);
|
||||
|
||||
@@ -5,6 +5,7 @@ mod selection;
|
||||
mod source_flatten;
|
||||
mod stack_cache;
|
||||
mod svg_profile;
|
||||
mod svg_stack_completeness;
|
||||
|
||||
const DEPTHS: [u64; 3] = [8, 16, 32];
|
||||
const W: i32 = 64;
|
||||
|
||||
@@ -45,7 +45,7 @@ fn selected_pixels_become_one_editable_smart_object_in_every_mode_and_depth() {
|
||||
let mut hidden = pixel(&doc, "Hidden", Rect::new(50, 40, 58, 44), [0.2, 0.9, 0.3, 1.0]);
|
||||
hidden.visible = false;
|
||||
let ids = [a.id, b.id, hidden.id];
|
||||
doc.layers = vec![a, b, hidden];
|
||||
doc.layers = vec![a, b, hidden].into();
|
||||
let mut selection = Surface::new(PixelFormat::GRAY8);
|
||||
selection.fill_rect(Rect::new(0, 0, 12, 12), &[0.5]);
|
||||
doc.selection = Some(selection);
|
||||
@@ -99,7 +99,7 @@ fn selected_group_and_descendant_are_embedded_once() {
|
||||
let group_id = group.id;
|
||||
let b = pixel(&doc, "Outside", Rect::new(16, 0, 32, 16), [0.0, 0.0, 1.0, 1.0]);
|
||||
let b_id = b.id;
|
||||
doc.layers = vec![group, b];
|
||||
doc.layers = vec![group, b].into();
|
||||
let mut s = selected_session(doc, &[group_id, a_id, b_id]);
|
||||
convert(&mut s);
|
||||
assert_eq!(s.active().unwrap().doc.layers.len(), 1);
|
||||
@@ -120,7 +120,7 @@ fn mixed_parent_selection_keeps_unselected_siblings_and_uses_the_top_selected_pa
|
||||
let lower = Layer::group("Lower parent", vec![a, keep_a.clone()]);
|
||||
let upper = Layer::group("Upper parent", vec![b, keep_b.clone()]);
|
||||
let (lower_id, upper_id) = (lower.id, upper.id);
|
||||
doc.layers = vec![lower, upper];
|
||||
doc.layers = vec![lower, upper].into();
|
||||
let original = doc.clone();
|
||||
let mut s = selected_session(doc, &[b_id, a_id]);
|
||||
let before = flat(&s);
|
||||
@@ -144,7 +144,7 @@ fn explicit_layer_converts_only_that_layer_despite_multi_selection() {
|
||||
let a = pixel(&doc, "A", Rect::new(0, 0, 8, 8), [1.0, 0.0, 0.0, 1.0]);
|
||||
let b = pixel(&doc, "B", Rect::new(8, 0, 16, 8), [0.0, 0.0, 1.0, 1.0]);
|
||||
let (a_id, b_id) = (a.id, b.id);
|
||||
doc.layers = vec![a, b.clone()];
|
||||
doc.layers = vec![a, b.clone()].into();
|
||||
let mut s = selected_session(doc, &[a_id, b_id]);
|
||||
s.execute("layer.smartObjects.convertToSmartObject", json!({"layer": a_id.0})).unwrap();
|
||||
assert_eq!(s.active().unwrap().doc.layers.len(), 2);
|
||||
@@ -160,7 +160,7 @@ fn combined_contents_survive_native_and_psd_save_open() {
|
||||
let a = pixel(&doc, "Bottom", Rect::new(-2, 4, 20, 20), [1.0, 0.0, 0.0, 1.0]);
|
||||
let b = pixel(&doc, "Top", Rect::new(10, 8, 24, 24), [0.0, 0.0, 1.0, 1.0]);
|
||||
let ids = [a.id, b.id];
|
||||
doc.layers = vec![a, b];
|
||||
doc.layers = vec![a, b].into();
|
||||
let mut s = selected_session(doc, &ids);
|
||||
let id = LayerId(convert(&mut s));
|
||||
let original = s.active().unwrap().doc.clone();
|
||||
@@ -189,7 +189,7 @@ fn selected_ancestor_in_another_parent_cannot_remove_the_new_smart_object() {
|
||||
let lower = Layer::group("Selected parent", vec![a]);
|
||||
let upper = Layer::group("Unselected parent", vec![b, keep]);
|
||||
let (lower_id, upper_id) = (lower.id, upper.id);
|
||||
doc.layers = vec![lower, upper];
|
||||
doc.layers = vec![lower, upper].into();
|
||||
let mut s = selected_session(doc, &[lower_id, a_id, b_id]);
|
||||
let so = LayerId(convert(&mut s));
|
||||
let outer = &s.active().unwrap().doc;
|
||||
@@ -210,7 +210,7 @@ fn an_all_hidden_selection_is_rejected_without_changing_document_selection_or_hi
|
||||
a.visible = false;
|
||||
b.visible = false;
|
||||
let ids = [a.id, b.id];
|
||||
doc.layers = vec![a, b];
|
||||
doc.layers = vec![a, b].into();
|
||||
let original = doc.clone();
|
||||
let mut s = selected_session(doc, &ids);
|
||||
let err = s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap_err();
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::cmd::smart_cmds::source::{flattened_source, source_surface_from_buffe
|
||||
/// A source document of `mode`/`depth` with a textured, partly transparent block on a layer.
|
||||
fn source(mode: ColorMode, depth: SampleType) -> Document {
|
||||
let mut doc = Document::new("source", Size::new(W as u32, H as u32), mode, depth);
|
||||
doc.layers = vec![Layer::new("block", LayerContent::Raster(block(&doc.pixel_format(), Rect::new(4, 3, 50, 40))))];
|
||||
doc.layers = vec![Layer::new("block", LayerContent::Raster(block(&doc.pixel_format(), Rect::new(4, 3, 50, 40))))].into();
|
||||
doc
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ fn effects_across_block_edges_match() {
|
||||
let mut mask = LayerMask::reveal_all();
|
||||
mask.surface.fill_rect(Rect::new(0, 240, width as i32, 270), &[0.3]);
|
||||
base.mask = Some(mask);
|
||||
doc.layers = vec![base];
|
||||
doc.layers = vec![base].into();
|
||||
same(&format!("blocks {width} {depth:?}"), &doc, fmt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
use super::*;
|
||||
use photocraft_color::{ColorMode, SampleType};
|
||||
use photocraft_geom::Size;
|
||||
use std::io::Write;
|
||||
|
||||
fn drawing(label: &str, omitted: bool) -> Vec<u8> {
|
||||
let image = if omitted { r#"<image width="1" height="1" href="data:image/png;base64,A"/>"# } else { "" };
|
||||
format!(r#"<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><!--{label}--><rect width="8" height="8" fill="red"/>{image}</svg>"#).into_bytes()
|
||||
}
|
||||
|
||||
fn gzip(bytes: &[u8]) -> Vec<u8> {
|
||||
let mut encoder = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::default());
|
||||
encoder.write_all(bytes).unwrap();
|
||||
encoder.finish().unwrap()
|
||||
}
|
||||
|
||||
fn document() -> Document {
|
||||
Document::new("Source work", Size::new(8, 8), ColorMode::Rgb, SampleType::U8)
|
||||
}
|
||||
fn object(name: &str, bytes: Arc<Vec<u8>>) -> SmartObject {
|
||||
SmartObject::new(SmartSource::Embedded { file_name: name.into(), bytes }, Affine::IDENTITY, None)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_svgz_refresh_keeps_native_size_pixels_and_place_reports_omissions() {
|
||||
// The fractional edge distinguishes native-size import and resampling from
|
||||
// rasterizing the vector again at the enlarged placement resolution.
|
||||
let svg = br#"<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect x=".35" width="5.4" height="8" fill="red"/><image width="1" height="1" href="data:image/png;base64,A"/></svg>"#;
|
||||
let encoded = gzip(svg);
|
||||
let name = "saved-refresh.svgz";
|
||||
let mut session = crate::Session::new();
|
||||
session.execute("file.new", serde_json::json!({"width":32,"height":32})).unwrap();
|
||||
let placed = crate::file_cmds::place_bytes(&mut session, name, encoded.clone(), None, &serde_json::json!({"smartObject":true,"scale":175})).unwrap();
|
||||
let warnings = placed["warnings"].as_array().unwrap();
|
||||
assert!(warnings.iter().any(|warning| warning.as_str().is_some_and(|warning| warning.contains("embedded image was omitted"))));
|
||||
let state = session.active().unwrap();
|
||||
let layer = state.active_layer.unwrap();
|
||||
let saved = photocraft_format::save_to_bytes(&state.doc, &Default::default()).unwrap();
|
||||
let mut doc = photocraft_format::load_from_bytes(&saved).unwrap();
|
||||
let format = doc.pixel_format();
|
||||
let mut changed = doc.layer(layer).unwrap().clone();
|
||||
let LayerContent::Smart(sm) = &mut changed.content else { panic!("saved SVGZ smart object") };
|
||||
sm.transform.m[4] += 1.;
|
||||
sm.cache = None;
|
||||
|
||||
// Independent oracle for the previous route: ordinary file import at source
|
||||
// size, then the same image placement used for other raster sources.
|
||||
let source = crate::file_cmds::import(name, &encoded).unwrap();
|
||||
let bounds = source.bounds();
|
||||
let source = super::super::source::flattened_source(&source, format).unwrap();
|
||||
let expected = photocraft_algo::warp::place_source(&source, bounds, &sm.transform, None).unwrap();
|
||||
assert_eq!(source_box(&doc, sm), Some([0., 0., 8., 8.]));
|
||||
assert!(refresh_layer(&doc, &mut changed).unwrap());
|
||||
let LayerContent::Smart(sm) = &mut changed.content else { panic!("refreshed SVGZ smart object") };
|
||||
assert_eq!(sm.cache.as_ref(), Some(&expected));
|
||||
|
||||
sm.smart_filters.push(SmartFilter {
|
||||
command: "image.adjustments.invert".into(),
|
||||
params: serde_json::json!({}),
|
||||
blend: BlendMode::Normal,
|
||||
opacity: 1.,
|
||||
visible: true,
|
||||
});
|
||||
let filtered = apply_smart_filters(&expected, sm, doc.bounds()).unwrap();
|
||||
*doc.layer_mut(layer).unwrap() = changed;
|
||||
assert!(refresh(&mut doc, layer).unwrap());
|
||||
let LayerContent::Smart(sm) = &doc.layer(layer).unwrap().content else { panic!("filtered SVGZ smart object") };
|
||||
assert_eq!(sm.cache.as_ref(), Some(&filtered));
|
||||
|
||||
let plain = object("saved-refresh.svg", Arc::new(svg.to_vec()));
|
||||
assert!(render(&doc, &plain).is_err(), "plain SVG refresh still requires complete pixels");
|
||||
let (pixels, warnings) = render_with_warnings(&doc, &plain).unwrap();
|
||||
assert!(pixels.is_some());
|
||||
assert_eq!(warnings.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memo_prices_owned_output_and_does_not_retain_encoded_capacity() {
|
||||
let doc = document();
|
||||
let data = drawing("reserved encoded capacity", false);
|
||||
let mut reserved = Vec::with_capacity(1 << 20);
|
||||
reserved.extend_from_slice(&data);
|
||||
let bytes = Arc::new(reserved);
|
||||
let weak = Arc::downgrade(&bytes);
|
||||
let sm = object("reserved.svg", bytes);
|
||||
let tile = photocraft_raster::tile_storage_bytes(doc.bounds(), &doc.pixel_format()) as usize;
|
||||
let mut memo = WarningRenderSources::with_limits(&doc, tile + 4096, 32);
|
||||
WARNING_SOURCE_DECODES.with(|value| value.set(0));
|
||||
let first = render_with_warnings_using(&sm, &mut memo).unwrap();
|
||||
assert!(first.1.is_empty());
|
||||
assert_eq!(memo.entries.len(), 1, "encoded spare capacity is borrowed, not retained memo storage");
|
||||
assert!(memo.bytes <= tile + 4096);
|
||||
assert_eq!(render_with_warnings_using(&sm, &mut memo).unwrap(), first);
|
||||
assert_eq!(WARNING_SOURCE_DECODES.with(std::cell::Cell::get), 1);
|
||||
assert_eq!(weak.strong_count(), 1, "only the caller owns its source allocation");
|
||||
drop(sm);
|
||||
assert!(weak.upgrade().is_none(), "the memo must not pin an encoded body after its owner drops it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_memo_with_stale_accounting_recovers_without_panicking() {
|
||||
let doc = document();
|
||||
let data = Arc::new(drawing("empty accounting", false));
|
||||
let mut memo = WarningRenderSources::new(&doc);
|
||||
memo.bytes = memo.budget;
|
||||
let (image, warnings) = memo.image(&data, 1., *blake3::hash(b"empty.svg").as_bytes()).unwrap();
|
||||
assert!(warnings.is_empty());
|
||||
assert_eq!(image.surface.rgba(3, 3), [1., 0., 0., 1.]);
|
||||
assert_eq!(memo.entries.len(), 1);
|
||||
assert!(memo.bytes <= memo.budget);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raster_named_svg_keeps_the_ordinary_import_path() {
|
||||
let image = photocraft_codecs::Image::from_u8(1, 1, photocraft_codecs::ChannelLayout::Rgb, vec![0, 255, 0]).unwrap();
|
||||
let png = photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &Default::default()).unwrap();
|
||||
let doc = document();
|
||||
let sm = object("renamed.svg", Arc::new(png));
|
||||
let rendered = render(&doc, &sm).unwrap().unwrap();
|
||||
assert_eq!(rendered.rgba(0, 0), [0., 1., 0., 1.]);
|
||||
let (reported, warnings) = render_with_warnings_using(&sm, &mut WarningRenderSources::new(&doc)).unwrap();
|
||||
assert_eq!(reported.unwrap(), rendered);
|
||||
assert!(warnings.is_empty());
|
||||
}
|
||||
@@ -92,16 +92,23 @@ fn convert_to_layers_unpacks_full_canvas_shapes_in_a_4k_document() {
|
||||
/// and renders the rest of the drawing, as it did before the bounded render.
|
||||
#[test]
|
||||
fn svg_with_an_unreadable_embedded_image_still_places() {
|
||||
let svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"8\" height=\"8\"><image width=\"4\" height=\"4\" href=\"data:image/x-foo,abc\"/><rect x=\"4\" width=\"4\" height=\"8\" fill=\"#ff0000\"/></svg>";
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
|
||||
let placed = crate::file_cmds::place_bytes(&mut s, "Logo.svg", svg.as_bytes().to_vec(), None, &json!({"smartObject": true})).unwrap();
|
||||
assert!(placed["warnings"].as_array().unwrap().iter().any(|w| w.as_str().unwrap().contains("embedded image was omitted")));
|
||||
let doc = &s.active().unwrap().doc;
|
||||
let LayerContent::Smart(sm) = &doc.layer(LayerId(placed["layer"].as_u64().unwrap())).unwrap().content else { panic!("smart") };
|
||||
assert_eq!(sm.cache.as_ref().unwrap().rgba(6, 4), [1.0, 0.0, 0.0, 1.0]);
|
||||
// A warning-bearing command must not poison the strict source/filter caches.
|
||||
assert!(render(doc, sm).is_err());
|
||||
for href in ["data:image/x-foo,abc", "data:image/png;base64,A"] {
|
||||
let svg = format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"8\" height=\"8\"><image width=\"4\" height=\"4\" href=\"{href}\"/><rect x=\"4\" width=\"4\" height=\"8\" fill=\"#ff0000\"/></svg>"
|
||||
);
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
|
||||
let placed = crate::file_cmds::place_bytes(&mut s, "Logo.svg", svg.as_bytes().to_vec(), None, &json!({"smartObject": true})).unwrap();
|
||||
let warnings = placed["warnings"].as_array().unwrap();
|
||||
assert_eq!(warnings.len(), 1, "{href}: {warnings:?}");
|
||||
assert!(warnings[0].as_str().unwrap().contains("embedded image was omitted"));
|
||||
let doc = &s.active().unwrap().doc;
|
||||
let LayerContent::Smart(sm) = &doc.layer(LayerId(placed["layer"].as_u64().unwrap())).unwrap().content else { panic!("smart") };
|
||||
assert_eq!(sm.cache.as_ref().unwrap().rgba(6, 4), [1.0, 0.0, 0.0, 1.0]);
|
||||
assert!(matches!(&sm.source, SmartSource::Embedded { file_name, bytes } if file_name == "Logo.svg" && bytes.as_slice() == svg.as_bytes()));
|
||||
// The warning render must neither repair the original bytes nor populate strict caches.
|
||||
assert!(render(doc, sm).is_err(), "{href}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Warp setup needs only the source frame, found with the bounded parse and the exact canvas
|
||||
@@ -166,7 +173,7 @@ fn svg_smart_render_cache_tracks_destination_profile_and_transform() {
|
||||
assert!(warnings.is_empty());
|
||||
assert_eq!(reported.unwrap(), warped, "warning-bearing warp parity");
|
||||
assert!((warped.pixel(10, 8)[0] - corrected.pixel(3, 3)[0]).abs() < 0.01, "warp must keep corrected colours");
|
||||
linear.layers = vec![Layer::new("Saved SVG", LayerContent::Smart(smart.clone()))];
|
||||
linear.layers = vec![Layer::new("Saved SVG", LayerContent::Smart(smart.clone()))].into();
|
||||
let saved = encode_source(&linear).unwrap();
|
||||
let reopened = decode_source("saved.pcraft", &saved).unwrap();
|
||||
let LayerContent::Smart(restored) = &reopened.layers[0].content else { panic!("smart object lost on save") };
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
use super::super::{source, stack_cache};
|
||||
use super::*;
|
||||
|
||||
fn incomplete_svg() -> Vec<u8> {
|
||||
let image = photocraft_codecs::Image::from_u8(1, 1, photocraft_codecs::ChannelLayout::Rgba, vec![0, 255, 0, 255]).unwrap();
|
||||
let mut png = photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &Default::default()).unwrap();
|
||||
let idat = png.windows(4).position(|bytes| bytes == b"IDAT").unwrap();
|
||||
// Keep the complete IHDR and dimensions, but damage actual compressed pixels.
|
||||
*png.get_mut(idat + 4).unwrap() ^= 0xff;
|
||||
assert_eq!(photocraft_codecs::probe_allocation_size(&png).unwrap(), (1, 1));
|
||||
let data = png.iter().map(|byte| format!("%{byte:02X}")).collect::<String>();
|
||||
format!("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"2\" height=\"2\"><!--stack-completeness-review--><rect width=\"2\" height=\"2\" fill=\"red\"/><image width=\"2\" height=\"2\" href=\"data:image/png,{data}\"/></svg>").into_bytes()
|
||||
}
|
||||
|
||||
fn smart_svg(bytes: Vec<u8>) -> SmartObject {
|
||||
SmartObject::new(SmartSource::Embedded { file_name: "Stack completeness.svg".into(), bytes: Arc::new(bytes) }, Affine::IDENTITY, None)
|
||||
}
|
||||
|
||||
fn old_stack_key(bytes: &[u8], fmt: PixelFormat, mode: photocraft_doc::StackMode) -> source::CacheKey {
|
||||
let mut key = source::cache_key(bytes, fmt);
|
||||
key.0 = *blake3::hash(&[&key.0[..], b"stack:", mode.id().as_bytes()].concat()).as_bytes();
|
||||
key
|
||||
}
|
||||
|
||||
fn old_placed_key(bytes: &[u8], doc: &Document, smart: &SmartObject) -> StageKey {
|
||||
let key = stack_cache::placed_key(bytes, doc.pixel_format(), smart, doc.bounds());
|
||||
let mut hash = blake3::Hasher::new();
|
||||
hash.update(&key);
|
||||
hash.update(&crate::color_cmds::document_profile(doc).to_bytes());
|
||||
*hash.finalize().as_bytes()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gzipped_svg_stack_retains_ordinary_import_for_misnamed_sources() {
|
||||
use std::io::Write;
|
||||
let mut encoder = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::default());
|
||||
encoder.write_all(&incomplete_svg()).unwrap();
|
||||
let bytes = Arc::new(encoder.finish().unwrap());
|
||||
let session = session(8);
|
||||
let doc = &session.active().unwrap().doc;
|
||||
for name in ["logo.gz", "without-extension"] {
|
||||
let mut smart = SmartObject::new(SmartSource::Embedded { file_name: name.into(), bytes: bytes.clone() }, Affine::IDENTITY, None);
|
||||
assert!(decode_source(name, &bytes).is_ok());
|
||||
smart.stack_mode = Some(photocraft_doc::StackMode::Mean);
|
||||
let rendered = render(doc, &smart).unwrap().unwrap();
|
||||
assert_eq!(rendered.rgba(1, 1), [1., 0., 0., 1.]);
|
||||
assert_eq!(source_box(doc, &smart), Some([0., 0., 2., 2.]));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_stack_rejects_incomplete_pixels_repeatedly_but_ordinary_placement_keeps_warnings() {
|
||||
let session = session(8);
|
||||
let doc = &session.active().unwrap().doc;
|
||||
let bytes = incomplete_svg();
|
||||
let mut smart = smart_svg(bytes.clone());
|
||||
let (ordinary, warnings) = render_with_warnings(doc, &smart).unwrap();
|
||||
assert_eq!(ordinary.unwrap().rgba(1, 1), [1., 0., 0., 1.]);
|
||||
assert_eq!(warnings.len(), 1);
|
||||
assert!(warnings[0].contains("embedded image was omitted"));
|
||||
smart.stack_mode = Some(photocraft_doc::StackMode::Mean);
|
||||
for _ in 0..2 {
|
||||
assert!(stack_image("Stack completeness.svg", &bytes, PixelFormat::RGBA32F, photocraft_doc::StackMode::Mean).is_err());
|
||||
assert!(render(doc, &smart).is_err());
|
||||
assert!(render_with_warnings(doc, &smart).is_err());
|
||||
assert_eq!(source_box(doc, &smart), None);
|
||||
assert!(smart.cache.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_stack_does_not_reuse_incomplete_legacy_source_or_filter_stages() {
|
||||
let _cache = crate::edit_menu_cmds::PURGE_TEST_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let session = session(8);
|
||||
let doc = &session.active().unwrap().doc;
|
||||
let bytes = incomplete_svg();
|
||||
let mut smart = smart_svg(bytes.clone());
|
||||
smart.stack_mode = Some(photocraft_doc::StackMode::Mean);
|
||||
let mut poisoned = Surface::new(PixelFormat::RGBA32F);
|
||||
poisoned.fill_rect(Rect::new(0, 0, 2, 2), &[0., 1., 0., 1.]);
|
||||
let key = old_stack_key(&bytes, PixelFormat::RGBA32F, photocraft_doc::StackMode::Mean);
|
||||
source::cache_put(key, source::SourceImage { surface: Arc::new(poisoned), bounds: Rect::new(0, 0, 2, 2) });
|
||||
assert!(stack_image("Stack completeness.svg", &bytes, PixelFormat::RGBA32F, photocraft_doc::StackMode::Mean).is_err());
|
||||
|
||||
let mut poisoned = Surface::new(doc.pixel_format());
|
||||
poisoned.fill_rect(Rect::new(0, 0, 2, 2), &[0., 1., 0., 1.]);
|
||||
let stage = Stage { surface: poisoned, extent: doc.bounds() };
|
||||
let placed = old_placed_key(&bytes, doc, &smart);
|
||||
stack_cache::put(placed, &stage);
|
||||
assert!(render(doc, &smart).is_err(), "old placed pixels must not bypass strict decoding");
|
||||
smart.smart_filters.push(SmartFilter {
|
||||
command: "filter.blur.gaussianBlur".into(),
|
||||
params: json!({"radius": 1}),
|
||||
blend: BlendMode::Normal,
|
||||
opacity: 1.,
|
||||
visible: true,
|
||||
});
|
||||
let filtered = stack_cache::filter_key(&placed, &smart.smart_filters[0], None);
|
||||
stack_cache::put(filtered, &stage);
|
||||
assert!(render(doc, &smart).is_err(), "old deepest filter stages must not bypass strict decoding");
|
||||
assert!(render_with_warnings(doc, &smart).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complete_svg_stack_keeps_mean_pixels_across_source_stage_and_warning_render_caches() {
|
||||
let bytes = br#"<svg xmlns="http://www.w3.org/2000/svg" width="2" height="2"><!--complete-stack-review--><rect width="2" height="2" fill="red"/><rect width="2" height="2" fill="blue"/></svg>"#;
|
||||
let session = session(32);
|
||||
let mut doc = (*session.active().unwrap().doc).clone();
|
||||
doc.icc_profile = Some(craft_cms::Builtin::Srgb.profile().to_bytes());
|
||||
let mut smart = smart_svg(bytes.to_vec());
|
||||
smart.stack_mode = Some(photocraft_doc::StackMode::Mean);
|
||||
// The red/blue Mean is 0.5 in the SVG's U8 encoding. Existing source
|
||||
// conversion rounds it to 128/255 before widening and decoding the sRGB
|
||||
// transfer for F32. The explicit sRGB destination keeps the rendered result
|
||||
// within ICC roundoff of that value (the matrix path is not bit-exact).
|
||||
let expected = photocraft_color::convert::srgb_to_linear(128.0 / 255.0);
|
||||
let check_mean = |pixel: [f32; 4]| {
|
||||
assert!((pixel[0] - expected).abs() < 3e-5, "red Mean: {pixel:?}");
|
||||
assert!(pixel[1].abs() < 1e-6, "green Mean: {pixel:?}");
|
||||
assert!((pixel[2] - expected).abs() < 3e-5, "blue Mean: {pixel:?}");
|
||||
assert_eq!(pixel[3], 1.0);
|
||||
};
|
||||
for _ in 0..2 {
|
||||
let source = stack_image("Complete.svg", bytes, PixelFormat::RGBA32F, photocraft_doc::StackMode::Mean).unwrap();
|
||||
check_mean(source.surface.rgba(1, 1));
|
||||
let strict = render(&doc, &smart).unwrap().unwrap();
|
||||
check_mean(strict.rgba(1, 1));
|
||||
let (reported, warnings) = render_with_warnings(&doc, &smart).unwrap();
|
||||
assert_eq!(reported.unwrap(), strict);
|
||||
assert!(warnings.is_empty());
|
||||
assert_eq!(source_box(&doc, &smart), Some([0., 0., 2., 2.]));
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ fn contents(s: &Session, doc: &Document, sm: &SmartObject, intent: Intent, bpc:
|
||||
crate::image_cmds::convert_layers_depth(&mut src.layers, doc.depth);
|
||||
}
|
||||
let background_id = src.background().map(|l| l.id);
|
||||
let mut layers = std::mem::take(&mut src.layers);
|
||||
let mut layers = std::mem::take(&mut *src.layers);
|
||||
for l in &mut layers {
|
||||
if Some(l.id) == background_id {
|
||||
l.name = "Layer 0".into();
|
||||
|
||||
@@ -385,6 +385,7 @@ fn update_contents_with_frame_budget(s: &mut Session, p: &Value, native: bool, f
|
||||
replacements.push(replacement);
|
||||
}
|
||||
// Finish every fallible render before committing any document state.
|
||||
let mut sources = crate::smart_cmds::WarningRenderSources::new(doc);
|
||||
for replacement in &mut replacements {
|
||||
if let Some(preview) = vector_preview.as_ref() {
|
||||
// This exact SVG was fully validated above. Render only a disposable display
|
||||
@@ -402,7 +403,7 @@ fn update_contents_with_frame_budget(s: &mut Session, p: &Value, native: bool, f
|
||||
sm.cache = rendered.cache;
|
||||
} else {
|
||||
let LayerContent::Smart(sm) = &mut replacement.content else { return Err(EngineError::NoLayer(replacement.id)) };
|
||||
let (surface, omitted) = crate::smart_cmds::render_with_warnings(doc, sm)?;
|
||||
let (surface, omitted) = crate::smart_cmds::render_with_warnings_using(sm, &mut sources)?;
|
||||
sm.cache = Some(surface.ok_or_else(|| bad(UPDATE, "SVG contents could not be rendered"))?);
|
||||
for warning in omitted {
|
||||
if !warnings.contains(&warning) {
|
||||
@@ -412,6 +413,7 @@ fn update_contents_with_frame_budget(s: &mut Session, p: &Value, native: bool, f
|
||||
}
|
||||
crate::smart_cmds::detach_psd(replacement);
|
||||
}
|
||||
drop(sources);
|
||||
s.edit(if native { "Update Vector Contents" } else { "Update SVG Contents" }, |doc, _| {
|
||||
for replacement in replacements {
|
||||
let id = replacement.id;
|
||||
@@ -459,5 +461,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod source_cache_tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,306 @@
|
||||
use super::*;
|
||||
use crate::smart_cmds::{WARNING_SOURCE_DECODES, WARNING_SOURCE_LIMIT, WarningRenderSources, render_with_warnings_using};
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_doc::SmartFilter;
|
||||
use photocraft_geom::Affine;
|
||||
|
||||
fn artwork(width: u32, height: u32) -> String {
|
||||
let image = photocraft_codecs::Image::from_u8(width, height, photocraft_codecs::ChannelLayout::Rgb, [0, 255, 0].repeat((width * height) as usize)).unwrap();
|
||||
let png = photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &Default::default()).unwrap();
|
||||
let encoded = base64::engine::general_purpose::STANDARD.encode(png);
|
||||
format!(
|
||||
r##"<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><image width="8" height="16" preserveAspectRatio="none" href="data:image/png;base64,{encoded}"/><rect x="8" width="8" height="16" fill="#808080"/><image width="1" height="1" href="data:image/png;base64,A"/></svg>"##
|
||||
)
|
||||
}
|
||||
|
||||
fn object(svg: &str) -> SmartObject {
|
||||
SmartObject::new(SmartSource::Embedded { file_name: "Memo.svg".into(), bytes: Arc::new(svg.as_bytes().to_vec()) }, Affine::IDENTITY, None)
|
||||
}
|
||||
|
||||
fn count() -> usize {
|
||||
WARNING_SOURCE_DECODES.with(std::cell::Cell::get)
|
||||
}
|
||||
|
||||
fn reset() {
|
||||
WARNING_SOURCE_DECODES.with(|count| count.set(0));
|
||||
}
|
||||
|
||||
fn assert_update_warnings(result: &Value) {
|
||||
let warnings = result["warnings"].as_array().unwrap();
|
||||
let omitted = "SVG: 1 embedded image was omitted";
|
||||
assert_eq!(warnings.iter().filter(|warning| warning.as_str().unwrap().starts_with(omitted)).count(), 1);
|
||||
assert!(warnings.len() <= 2, "at most one omission and one image-layer information notice: {warnings:?}");
|
||||
assert!(warnings.iter().all(|warning| {
|
||||
let warning = warning.as_str().unwrap();
|
||||
warning.starts_with(omitted) || warning == "SVG: embedded images are pixel layers"
|
||||
}));
|
||||
}
|
||||
|
||||
fn draw(sources: &mut WarningRenderSources<'_>, sm: &SmartObject) -> photocraft_raster::Surface {
|
||||
let (surface, warnings) = render_with_warnings_using(sm, sources).unwrap();
|
||||
assert_eq!(warnings.len(), 1);
|
||||
surface.unwrap()
|
||||
}
|
||||
|
||||
fn shared_session(instances: usize) -> (Session, LayerId) {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width":32,"height":32})).unwrap();
|
||||
let original = br#"<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16" fill="red"/></svg>"#;
|
||||
let placed = crate::file_cmds::place_bytes(&mut s, "Shared.svg", original.to_vec(), None, &json!({"smartObject":true})).unwrap();
|
||||
let id = LayerId(placed["layer"].as_u64().unwrap());
|
||||
let first = s.active().unwrap().doc.layer(id).unwrap().clone();
|
||||
let doc = Arc::make_mut(&mut s.active_mut().unwrap().doc);
|
||||
for index in 1..instances {
|
||||
let mut layer = first.duplicate();
|
||||
let LayerContent::Smart(sm) = &mut layer.content else { panic!("smart") };
|
||||
sm.transform = Affine::translate((index % 4) as f64, (index % 3) as f64);
|
||||
layer.opacity = 0.5;
|
||||
doc.layers.push(layer);
|
||||
}
|
||||
(s, id)
|
||||
}
|
||||
|
||||
fn request(s: &mut Session, id: LayerId, svg: &str) -> Value {
|
||||
let handoff = s.execute(EXPORT, json!({"layer":id.0})).unwrap();
|
||||
json!({"document":handoff["document"],"layer":id.0,"contentsId":handoff["contentsId"],"fingerprint":handoff["fingerprint"],"svg":svg})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warning_source_profile_context_stays_lazy_for_non_svg_and_missing_sources() {
|
||||
let doc = Document::new("Raster", Size::new(8, 8), ColorMode::Rgb, SampleType::U8);
|
||||
let image = photocraft_codecs::Image::from_u8(2, 2, photocraft_codecs::ChannelLayout::Rgb, [0, 255, 0].repeat(4)).unwrap();
|
||||
let png = photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &Default::default()).unwrap();
|
||||
let sm = SmartObject::new(SmartSource::Embedded { file_name: "Raster.png".into(), bytes: Arc::new(png) }, Affine::IDENTITY, None);
|
||||
let expected = crate::smart_cmds::render(&doc, &sm).unwrap();
|
||||
let mut sources = WarningRenderSources::new(&doc);
|
||||
assert!(!sources.profile_initialized());
|
||||
reset();
|
||||
let (surface, warnings) = render_with_warnings_using(&sm, &mut sources).unwrap();
|
||||
assert_eq!(surface, expected);
|
||||
assert!(warnings.is_empty());
|
||||
assert!(!sources.profile_initialized(), "a strict non-SVG cache hit needs no SVG color context");
|
||||
let missing = SmartObject::new(SmartSource::Linked { path: String::new() }, Affine::IDENTITY, None);
|
||||
let (surface, warnings) = render_with_warnings_using(&missing, &mut sources).unwrap();
|
||||
assert!(surface.is_none());
|
||||
assert!(warnings.is_empty());
|
||||
assert!(!sources.profile_initialized());
|
||||
assert_eq!(count(), 0);
|
||||
draw(&mut sources, &object(&artwork(4, 4)));
|
||||
assert!(sources.profile_initialized());
|
||||
assert_eq!(count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_svg_update_decodes_one_source_for_equal_scale_and_keeps_warning_caches_private() {
|
||||
let (mut s, id) = shared_session(100);
|
||||
let before = s.active().unwrap().doc.clone();
|
||||
let svg = artwork(8, 8);
|
||||
let params = request(&mut s, id, &svg);
|
||||
reset();
|
||||
let result = s.execute(UPDATE, params).unwrap();
|
||||
assert_eq!(count(), 1, "each placement must reuse the update's source-space render");
|
||||
assert_update_warnings(&result);
|
||||
let doc = &s.active().unwrap().doc;
|
||||
let instances: Vec<_> = doc.layers.iter().filter(|layer| matches!(&layer.content, LayerContent::Smart(_))).collect();
|
||||
assert_eq!(instances.len(), 100);
|
||||
for layer in instances {
|
||||
let sm = smart(doc, layer.id).unwrap();
|
||||
let previous = before.layer(layer.id).unwrap();
|
||||
assert_eq!(layer.opacity, previous.opacity);
|
||||
assert_eq!(sm.transform, smart(&before, layer.id).unwrap().transform);
|
||||
assert_eq!(embedded(doc, sm).unwrap().1, svg.as_bytes());
|
||||
let x = sm.transform.m[4] as i32;
|
||||
let y = sm.transform.m[5] as i32;
|
||||
assert_eq!(sm.cache.as_ref().unwrap().rgba(x + 3, y + 3), [0., 1., 0., 1.]);
|
||||
}
|
||||
let sm = smart(doc, id).unwrap();
|
||||
assert!(crate::smart_cmds::render(doc, sm).is_err(), "strict global cache must remain unpoisoned");
|
||||
let mut stack = sm.clone();
|
||||
stack.stack_mode = Some(photocraft_doc::StackMode::Mean);
|
||||
assert!(crate::smart_cmds::render(doc, &stack).is_err(), "Stack Mode still requires complete artwork");
|
||||
assert!(s.undo());
|
||||
assert_eq!(s.active().unwrap().doc, before);
|
||||
assert!(s.redo());
|
||||
assert_eq!(embedded(&s.active().unwrap().doc, smart(&s.active().unwrap().doc, id).unwrap()).unwrap().1, svg.as_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_svg_sources_separate_scale_and_profile_but_keep_instance_filters_and_placement() {
|
||||
let mut doc = Document::new("Profile", Size::new(64, 64), ColorMode::Rgb, SampleType::F32);
|
||||
doc.icc_profile = Some(craft_cms::Builtin::Srgb.profile().to_bytes());
|
||||
let mut linear = doc.clone();
|
||||
linear.icc_profile = Some(craft_cms::Builtin::LinearSrgb.profile().to_bytes());
|
||||
let first = object(&artwork(4, 4));
|
||||
let mut moved = first.clone();
|
||||
moved.transform = Affine::translate(20., 0.);
|
||||
moved.smart_filters.push(SmartFilter {
|
||||
command: "image.adjustments.invert".into(),
|
||||
params: json!({}),
|
||||
blend: photocraft_color::BlendMode::Normal,
|
||||
opacity: 0.5,
|
||||
visible: true,
|
||||
});
|
||||
let mut sources = WarningRenderSources::new(&doc);
|
||||
reset();
|
||||
let a = draw(&mut sources, &first);
|
||||
let b = draw(&mut sources, &moved);
|
||||
assert_eq!(count(), 1);
|
||||
assert_eq!(a.rgba(3, 3), [0., 1., 0., 1.]);
|
||||
assert_eq!(b.rgba(3, 3), [0.; 4]);
|
||||
assert!(b.rgba(23, 3).iter().take(3).all(|value| (*value - 0.5).abs() < 0.01));
|
||||
let mut scaled = first.clone();
|
||||
scaled.transform = Affine { m: [2., 0., 0., 2., 0., 0.] };
|
||||
draw(&mut sources, &scaled);
|
||||
assert_eq!(count(), 2, "different raster scales require different source renders");
|
||||
let corrected = draw(&mut WarningRenderSources::new(&linear), &first);
|
||||
assert_eq!(count(), 3, "a different document interpretation cannot reuse the earlier source");
|
||||
assert!((a.rgba(12, 3)[0] - 0.502).abs() < 0.01);
|
||||
assert!((corrected.rgba(12, 3)[0] - 0.216).abs() < 0.01);
|
||||
assert_eq!(draw(&mut sources, &first), a);
|
||||
assert_eq!(count(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_svg_source_memo_evicts_and_oversize_entries_render_without_retention() {
|
||||
let mut doc = Document::new("Budget", Size::new(64, 64), ColorMode::Rgb, SampleType::U8);
|
||||
doc.icc_profile = Some(craft_cms::Builtin::Srgb.profile().to_bytes());
|
||||
let first = object(&artwork(4, 4));
|
||||
let mut scaled = first.clone();
|
||||
scaled.transform = Affine { m: [2., 0., 0., 2., 0., 0.] };
|
||||
let tile = photocraft_raster::tile_storage_bytes(Rect::new(0, 0, 32, 32), &PixelFormat::RGBA8) as usize;
|
||||
for (budget, limit) in [(tile + 4096, 32), (usize::MAX, 1)] {
|
||||
let mut sources = WarningRenderSources::with_limits(&doc, budget, limit);
|
||||
reset();
|
||||
let expected = draw(&mut sources, &first);
|
||||
draw(&mut sources, &scaled);
|
||||
assert_eq!(draw(&mut sources, &first), expected);
|
||||
assert_eq!(count(), 3, "byte and entry limits both evict the old scale");
|
||||
}
|
||||
let huge_source = artwork(4, 4).replace("</svg>", &format!("<!--{}--></svg>", " ".repeat(tile + 8192)));
|
||||
let encoded = object(&huge_source);
|
||||
let mut sources = WarningRenderSources::with_limits(&doc, tile + 4096, 32);
|
||||
reset();
|
||||
let expected = draw(&mut sources, &encoded);
|
||||
assert_eq!(draw(&mut sources, &encoded), expected);
|
||||
assert_eq!(count(), 1, "the immutable document owns encoded bytes; only rendered output belongs to the memo budget");
|
||||
let mut output_too_large = WarningRenderSources::with_limits(&doc, tile - 1, 32);
|
||||
reset();
|
||||
let expected = draw(&mut output_too_large, &first);
|
||||
assert_eq!(draw(&mut output_too_large, &first), expected);
|
||||
assert_eq!(count(), 2, "oversize rendered output remains an uncached success");
|
||||
let mut disabled = WarningRenderSources::with_limits(&doc, 0, 0);
|
||||
assert_eq!(draw(&mut disabled, &first), draw(&mut WarningRenderSources::new(&doc), &first));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_svg_update_render_failure_and_cancelled_authorization_preserve_document_history() {
|
||||
for cancel in [false, true] {
|
||||
let (mut s, id) = shared_session(2);
|
||||
let doc = Arc::make_mut(&mut s.active_mut().unwrap().doc);
|
||||
let LayerContent::Smart(sm) = &mut doc.layers.last_mut().unwrap().content else { panic!("smart") };
|
||||
sm.smart_filters.push(SmartFilter {
|
||||
command: if cancel { "image.adjustments.invert" } else { "unsupported.persisted.filter" }.into(),
|
||||
params: json!({}),
|
||||
blend: photocraft_color::BlendMode::Normal,
|
||||
opacity: 1.,
|
||||
visible: true,
|
||||
});
|
||||
if cancel {
|
||||
s.authorize = Some(|command, _| if command == "image.adjustments.invert" { Err(EngineError::Cancelled) } else { Ok(()) });
|
||||
}
|
||||
let before = s.active().unwrap().doc.clone();
|
||||
let history = s.active().unwrap().history.entries();
|
||||
let revision = s.active().unwrap().revision;
|
||||
let params = request(&mut s, id, &artwork(4, 4));
|
||||
reset();
|
||||
let error = s.execute(UPDATE, params).unwrap_err();
|
||||
if cancel {
|
||||
assert!(matches!(error, EngineError::Cancelled), "expected the authority cancellation, got {error}");
|
||||
} else {
|
||||
assert!(error.to_string().contains("unsupported visible filters"), "{error}");
|
||||
}
|
||||
assert_eq!(s.active().unwrap().doc, before);
|
||||
assert_eq!(s.active().unwrap().history.entries(), history);
|
||||
assert_eq!(s.active().unwrap().revision, revision);
|
||||
assert_eq!(count(), if cancel { 0 } else { 1 });
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_svg_update_keeps_the_existing_placed_pixel_budget_atomic() {
|
||||
let (mut s, id) = shared_session(2);
|
||||
let LayerContent::Smart(sm) = &mut Arc::make_mut(&mut s.active_mut().unwrap().doc).layers.last_mut().unwrap().content else { panic!("smart") };
|
||||
sm.transform = Affine { m: [1000., 0., 0., 1000., 0., 0.] };
|
||||
let before = s.active().unwrap().doc.clone();
|
||||
let history = s.active().unwrap().history.entries();
|
||||
let revision = s.active().unwrap().revision;
|
||||
let params = request(&mut s, id, &artwork(4, 4));
|
||||
reset();
|
||||
assert!(s.execute(UPDATE, params).is_err());
|
||||
assert_eq!(count(), 0, "placed-frame admission precedes source rendering");
|
||||
assert_eq!(s.active().unwrap().doc, before);
|
||||
assert_eq!(s.active().unwrap().history.entries(), history);
|
||||
assert_eq!(s.active().unwrap().revision, revision);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "24MP embedded PNG / 100 shared instances; run once in release for performance qualification"]
|
||||
fn shared_svg_update_24mp_source_timing() {
|
||||
struct MemoLimit(Option<usize>);
|
||||
impl MemoLimit {
|
||||
fn set(limit: usize) -> Self {
|
||||
Self(WARNING_SOURCE_LIMIT.with(|current| current.replace(Some(limit))))
|
||||
}
|
||||
}
|
||||
impl Drop for MemoLimit {
|
||||
fn drop(&mut self) {
|
||||
WARNING_SOURCE_LIMIT.with(|current| current.set(self.0));
|
||||
}
|
||||
}
|
||||
let previous_limit = WARNING_SOURCE_LIMIT.with(std::cell::Cell::get);
|
||||
// Encode once. Each pass builds the same initial document and handoff outside
|
||||
// the clock; UPDATE includes its normal import and all instance rendering.
|
||||
let svg = artwork(6000, 4000);
|
||||
let mut expected = None;
|
||||
let mut timings = Vec::new();
|
||||
for (label, limit, decodes) in [("optimized-before", 32, 1), ("memo-off", 0, 100), ("optimized-after", 32, 1)] {
|
||||
let (mut s, id) = shared_session(100);
|
||||
let params = request(&mut s, id, &svg);
|
||||
let _restore = MemoLimit::set(limit);
|
||||
reset();
|
||||
let start = std::time::Instant::now();
|
||||
let result = s.execute(UPDATE, params).unwrap();
|
||||
let elapsed = start.elapsed().as_secs_f64() * 1000.;
|
||||
assert_eq!(count(), decodes, "{label}");
|
||||
assert_update_warnings(&result);
|
||||
let doc = &s.active().unwrap().doc;
|
||||
let mut pixels = blake3::Hasher::new();
|
||||
let mut sources = blake3::Hasher::new();
|
||||
let mut samples = Vec::new();
|
||||
for layer in doc.layers.iter().filter(|layer| matches!(&layer.content, LayerContent::Smart(_))) {
|
||||
let sm = smart(doc, layer.id).unwrap();
|
||||
let source = embedded(doc, sm).unwrap().1;
|
||||
assert_eq!(source, svg.as_bytes());
|
||||
sources.update(blake3::hash(source).as_bytes());
|
||||
let cache = sm.cache.as_ref().unwrap();
|
||||
for value in cache.read_region(doc.bounds()) {
|
||||
pixels.update(&value.to_bits().to_le_bytes());
|
||||
}
|
||||
let (x, y) = (sm.transform.m[4] as i32, sm.transform.m[5] as i32);
|
||||
let sample = cache.rgba(x + 3, y + 3);
|
||||
assert_eq!(sample, [0., 1., 0., 1.]);
|
||||
samples.push(sample);
|
||||
}
|
||||
assert_eq!(samples.len(), 100);
|
||||
let signature = (*pixels.finalize().as_bytes(), *sources.finalize().as_bytes(), samples, result["warnings"].clone());
|
||||
if let Some(expected) = &expected {
|
||||
assert_eq!(&signature, expected, "pixels, samples, encoded sources and warnings must match: {label}");
|
||||
} else {
|
||||
expected = Some(signature);
|
||||
}
|
||||
eprintln!("24MP PNG / 16x16 SVG / 100 shared instances: {label}: {elapsed:.3} ms, {decodes} source renders");
|
||||
timings.push(elapsed);
|
||||
}
|
||||
eprintln!("optimized median of two: {:.3} ms; memo-off: {:.3} ms", (timings[0] + timings[2]) / 2., timings[1]);
|
||||
assert_eq!(WARNING_SOURCE_LIMIT.with(std::cell::Cell::get), previous_limit, "test override restored");
|
||||
}
|
||||
@@ -419,13 +419,24 @@ fn original_vector_formats_save_atomically_and_survive_undo_and_persistence() {
|
||||
/// is accepted with that image left out, as placing the same SVG is.
|
||||
#[test]
|
||||
fn saved_svg_with_an_unreadable_embedded_image_still_updates() {
|
||||
let (mut s, id) = session(8);
|
||||
let edited = r#"<svg xmlns="http://www.w3.org/2000/svg" width="8" height="6"><image width="4" height="6" href="data:image/bmp,BM"/><rect x="4" width="4" height="6" fill="blue"/></svg>"#;
|
||||
let params = request(&mut s, id, edited);
|
||||
let result = s.execute(UPDATE, params).unwrap();
|
||||
assert_eq!(result["updated"], true);
|
||||
assert!(result["warnings"].as_array().unwrap().iter().any(|w| w.as_str().unwrap().contains("embedded image was omitted")));
|
||||
assert_eq!(source(&s, id), edited.as_bytes());
|
||||
for href in ["data:image/bmp,BM", "data:image/png;base64,A"] {
|
||||
let (mut s, id) = session(8);
|
||||
let edited = format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" width="8" height="6"><image width="4" height="6" href="{href}"/><rect x="4" width="4" height="6" fill="blue"/></svg>"#
|
||||
);
|
||||
let params = request(&mut s, id, &edited);
|
||||
let result = s.execute(UPDATE, params).unwrap();
|
||||
assert_eq!(result["updated"], true);
|
||||
let warnings = result["warnings"].as_array().unwrap();
|
||||
assert_eq!(warnings.len(), 1, "{href}: {warnings:?}");
|
||||
assert!(warnings[0].as_str().unwrap().contains("embedded image was omitted"));
|
||||
assert_eq!(source(&s, id), edited.as_bytes());
|
||||
let doc = &s.active().unwrap().doc;
|
||||
let sm = smart(doc, id).unwrap();
|
||||
assert_eq!(sm.cache.as_ref().unwrap().rgba(18, 11), [0.0, 0.0, 1.0, 1.0]);
|
||||
assert!(crate::smart_cmds::render(doc, sm).is_err(), "warning-bearing save must not populate strict caches: {href}");
|
||||
assert_eq!(source(&s, id), edited.as_bytes(), "strict refusal must leave the unrepaired source intact");
|
||||
}
|
||||
}
|
||||
|
||||
/// updateSvg replaces SVG contents only: it never turns an AI, PDF or EPS source into SVG.
|
||||
|
||||
@@ -130,7 +130,7 @@ fn stamp_down(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut tmp = doc.clone();
|
||||
let mut base = lower.clone();
|
||||
base.visible = true;
|
||||
tmp.layers = vec![base, upper];
|
||||
tmp.layers = vec![base, upper].into();
|
||||
let fmt = doc.pixel_format();
|
||||
let fmt = if lower.locks.transparency { fmt } else { PixelFormat::new(fmt.mode, fmt.sample, true) };
|
||||
let surf = photocraft_compose::flatten_to_surface(&tmp, fmt, None);
|
||||
|
||||
@@ -278,11 +278,35 @@ fn apply_data_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (set, idx) = resolve_set(s, p, "image.applyDataSet")?;
|
||||
let vars = s.active().ok_or(EngineError::NoDocument)?.doc.variables.clone();
|
||||
authorize_pixel_paths(s, &set)?;
|
||||
s.edit("Apply Data Set", |doc, _| apply_to_doc(doc, &vars, &set))?;
|
||||
// One history state named exactly "Apply Data Set", whatever the set is called (#14498).
|
||||
let label = "Apply Data Set";
|
||||
if replaces_locked_text(&s.active().ok_or(EngineError::NoDocument)?.doc, &vars, &set) {
|
||||
// As in the reference application, nothing of the set is applied, but the attempt is
|
||||
// still a history state (one that changes nothing), and the alert names no layer (#14499).
|
||||
s.edit(label, |_, _| Ok(()))?;
|
||||
return Err(EngineError::Other(DATA_SET_LAYER_LOCKED.into()));
|
||||
}
|
||||
s.edit(label, |doc, _| apply_to_doc(doc, &vars, &set))?;
|
||||
set_vars(s, |v| v.active = Some(idx))?;
|
||||
Ok(json!({"applied": set.name, "index": idx}))
|
||||
}
|
||||
|
||||
/// The reference application's alert when Apply Data Set would replace the text of a layer
|
||||
/// under Lock All.
|
||||
pub const DATA_SET_LAYER_LOCKED: &str = "Could not apply data set because the layer is locked.";
|
||||
|
||||
/// Whether `set` has a Text value for a type layer with its own Lock All. Visibility and Pixel
|
||||
/// Replacement values still apply to locked layers, as in the reference application; partial
|
||||
/// locks and a locked group were not measured and keep applying (#14499).
|
||||
fn replaces_locked_text(doc: &Document, vars: &Variables, set: &DataSet) -> bool {
|
||||
set.values.iter().any(|dv| {
|
||||
matches!(dv.value, VarValue::Text(_))
|
||||
&& vars.def(&dv.variable).is_some_and(|def| {
|
||||
matches!(def.kind, VarKind::TextReplacement) && doc.layer(def.layer).is_some_and(|l| l.locks.all && matches!(l.content, LayerContent::Text(_)))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Resolve a data set from `{name}` or `{index}`.
|
||||
fn resolve_set(s: &Session, p: &Value, cmd: &str) -> Result<(DataSet, usize)> {
|
||||
let vars = &s.active().ok_or(EngineError::NoDocument)?.doc.variables;
|
||||
@@ -575,5 +599,8 @@ mod tests;
|
||||
#[cfg(test)]
|
||||
mod import_enabled_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod locked_text_layer_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod apply_history_name_tests;
|
||||
@@ -0,0 +1,208 @@
|
||||
//! #14499: Apply Data Set refuses with the reference application's alert when a Text value would
|
||||
//! replace the text of a type layer under Lock All. Nothing of the set is applied, but one history
|
||||
//! state that changes nothing is still added. Visibility and Pixel Replacement values keep
|
||||
//! applying to locked layers; partial locks and Data Sets as Files keep today's behaviour.
|
||||
|
||||
use super::*;
|
||||
use photocraft_doc::{Layer, Locks, TextLayer};
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
const APPLY: &str = "image.applyDataSet";
|
||||
|
||||
/// A document with a raster layer "photo", a red raster "badge" and a text layer "title", bound
|
||||
/// to the variables `photo` (pixels), `showBadge`, `showTitle` (visibility) and `headline` (text).
|
||||
fn session() -> (Session, LayerId, LayerId, LayerId) {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
let (photo, badge, title) = s
|
||||
.edit("setup", |doc, _| {
|
||||
let fmt = doc.pixel_format();
|
||||
let mut photo = Layer::raster("photo", fmt);
|
||||
photo.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 64, 48), &photocraft_raster::from_rgba(&fmt, [0.5, 0.5, 0.5, 1.0]));
|
||||
let mut badge = Layer::raster("badge", fmt);
|
||||
badge.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 10, 10), &photocraft_raster::from_rgba(&fmt, [1.0, 0.0, 0.0, 1.0]));
|
||||
let title = Layer::new("title", LayerContent::Text(TextLayer { text: "Old".into(), ..Default::default() }));
|
||||
let ids = (photo.id, badge.id, title.id);
|
||||
doc.layers.extend([photo, badge, title]);
|
||||
Ok(ids)
|
||||
})
|
||||
.unwrap();
|
||||
s.execute(
|
||||
"image.variables.define",
|
||||
json!({"defs": [
|
||||
{"name": "photo", "layer": photo.0, "type": "pixelReplacement", "method": "conform"},
|
||||
{"name": "showBadge", "layer": badge.0, "type": "visibility"},
|
||||
{"name": "showTitle", "layer": title.0, "type": "visibility"},
|
||||
{"name": "headline", "layer": title.0, "type": "textReplacement"},
|
||||
]}),
|
||||
)
|
||||
.unwrap();
|
||||
(s, photo, badge, title)
|
||||
}
|
||||
|
||||
/// A blue 8x8 PNG for the `photo` variable.
|
||||
fn blue_png(name: &str) -> (String, String) {
|
||||
let dir = std::env::temp_dir().join(format!("pc-vars-{}-locked-{name}", std::process::id()));
|
||||
let _ = std::fs::create_dir_all(&dir);
|
||||
let png = dir.join("blue.png");
|
||||
let mut src = Session::new();
|
||||
src.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap();
|
||||
let bytes = photocraft_io::export(&src.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes;
|
||||
std::fs::write(&png, bytes).unwrap();
|
||||
(dir.to_string_lossy().into_owned(), png.to_string_lossy().into_owned())
|
||||
}
|
||||
|
||||
fn data_sets(s: &mut Session, sets: Value) {
|
||||
s.execute("image.variables.dataSets", json!({ "dataSets": sets })).unwrap();
|
||||
}
|
||||
|
||||
fn lock(s: &mut Session, id: LayerId, locks: Locks) {
|
||||
s.edit("lock", |doc, _| {
|
||||
doc.layer_mut(id).unwrap().locks = locks;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn all() -> Locks {
|
||||
Locks { all: true, ..Locks::default() }
|
||||
}
|
||||
|
||||
fn doc(s: &Session) -> &Document {
|
||||
&s.active().unwrap().doc
|
||||
}
|
||||
|
||||
fn text_of(s: &Session, id: LayerId) -> String {
|
||||
match &doc(s).layer(id).unwrap().content {
|
||||
LayerContent::Text(t) => t.text.clone(),
|
||||
_ => panic!("not a text layer"),
|
||||
}
|
||||
}
|
||||
|
||||
fn visible(s: &Session, id: LayerId) -> bool {
|
||||
doc(s).layer(id).unwrap().visible
|
||||
}
|
||||
|
||||
fn pixel(s: &Session, id: LayerId) -> Vec<f32> {
|
||||
doc(s).layer(id).unwrap().surface().unwrap().pixel(32, 24)
|
||||
}
|
||||
|
||||
fn history(s: &Session) -> (usize, Option<String>) {
|
||||
let h = &s.active().unwrap().history;
|
||||
(h.past_len(), h.entries().last().map(|e| e.to_string()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_text_value_for_a_locked_type_layer_applies_nothing_and_alerts() {
|
||||
let (mut s, photo, badge, title) = session();
|
||||
let (dir, png) = blue_png("refuse");
|
||||
data_sets(
|
||||
&mut s,
|
||||
json!([{"name": "Zed", "values": [
|
||||
{"variable": "photo", "kind": "pixels", "value": png},
|
||||
{"variable": "showBadge", "kind": "visibility", "value": false},
|
||||
{"variable": "showTitle", "kind": "visibility", "value": false},
|
||||
{"variable": "headline", "kind": "text", "value": "Alpha\rLine2"},
|
||||
]}]),
|
||||
);
|
||||
lock(&mut s, title, all());
|
||||
let photo_before = pixel(&s, photo);
|
||||
let (n, _) = history(&s);
|
||||
|
||||
let r = s.execute(APPLY, json!({"name": "Zed"}));
|
||||
assert!(matches!(&r, Err(EngineError::Other(m)) if m == DATA_SET_LAYER_LOCKED), "{r:?}");
|
||||
assert_eq!(DATA_SET_LAYER_LOCKED, "Could not apply data set because the layer is locked.");
|
||||
|
||||
// Nothing of the set: the text, both visibilities and the photo's pixels stay.
|
||||
assert_eq!(text_of(&s, title), "Old");
|
||||
assert!(visible(&s, title) && visible(&s, badge));
|
||||
assert_eq!(pixel(&s, photo), photo_before);
|
||||
assert_eq!(doc(&s).variables.active, None, "the set did not become the applied one");
|
||||
|
||||
// One history state for the attempt, which changes nothing.
|
||||
let (after, label) = history(&s);
|
||||
assert_eq!(after, n + 1);
|
||||
assert!(label.as_deref().is_some_and(|l| l.starts_with("Apply Data Set")), "{label:?}");
|
||||
let applied = doc(&s).clone();
|
||||
assert!(s.undo());
|
||||
assert_eq!(history(&s).0, n);
|
||||
assert_eq!(text_of(&s, title), "Old");
|
||||
assert!(s.redo());
|
||||
assert_eq!(doc(&s).layers, applied.layers, "the state changes nothing");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_same_set_applies_once_the_layer_is_unlocked() {
|
||||
let (mut s, _photo, badge, title) = session();
|
||||
data_sets(
|
||||
&mut s,
|
||||
json!([{"name": "Zed", "values": [
|
||||
{"variable": "showBadge", "kind": "visibility", "value": false},
|
||||
{"variable": "headline", "kind": "text", "value": "Alpha"},
|
||||
]}]),
|
||||
);
|
||||
lock(&mut s, title, all());
|
||||
assert!(s.execute(APPLY, json!({"name": "Zed"})).is_err());
|
||||
lock(&mut s, title, Locks::default());
|
||||
s.execute(APPLY, json!({"name": "Zed"})).unwrap();
|
||||
assert_eq!(text_of(&s, title), "Alpha");
|
||||
assert!(!visible(&s, badge));
|
||||
assert_eq!(doc(&s).variables.active, Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visibility_values_still_apply_to_locked_layers() {
|
||||
let (mut s, _photo, badge, title) = session();
|
||||
data_sets(
|
||||
&mut s,
|
||||
json!([{"name": "Hide", "values": [
|
||||
{"variable": "showBadge", "kind": "visibility", "value": false},
|
||||
{"variable": "showTitle", "kind": "visibility", "value": false},
|
||||
]}]),
|
||||
);
|
||||
lock(&mut s, badge, all());
|
||||
lock(&mut s, title, all());
|
||||
s.execute(APPLY, json!({"name": "Hide"})).unwrap();
|
||||
assert!(!visible(&s, badge) && !visible(&s, title));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pixel_replacement_still_applies_to_a_locked_pixel_layer() {
|
||||
let (mut s, photo, _badge, _title) = session();
|
||||
let (dir, png) = blue_png("pixels");
|
||||
data_sets(&mut s, json!([{"name": "Blue", "values": [{"variable": "photo", "kind": "pixels", "value": png}]}]));
|
||||
lock(&mut s, photo, all());
|
||||
s.execute(APPLY, json!({"name": "Blue"})).unwrap();
|
||||
assert_eq!(pixel(&s, photo), vec![0.0, 0.0, 1.0, 1.0]);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_locks_keep_applying_text() {
|
||||
let partial = [
|
||||
Locks { transparency: true, ..Locks::default() },
|
||||
Locks { pixels: true, ..Locks::default() },
|
||||
Locks { position: true, ..Locks::default() },
|
||||
Locks { transparency: true, pixels: true, position: true, artboard: true, all: false },
|
||||
];
|
||||
for locks in partial {
|
||||
let (mut s, _photo, _badge, title) = session();
|
||||
data_sets(&mut s, json!([{"name": "T", "values": [{"variable": "headline", "kind": "text", "value": "New"}]}]));
|
||||
lock(&mut s, title, locks);
|
||||
s.execute(APPLY, json!({"name": "T"})).unwrap_or_else(|e| panic!("{locks:?}: {e}"));
|
||||
assert_eq!(text_of(&s, title), "New", "{locks:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_sets_as_files_keeps_exporting_a_locked_type_layer() {
|
||||
let (mut s, _photo, _badge, title) = session();
|
||||
data_sets(&mut s, json!([{"name": "T", "values": [{"variable": "headline", "kind": "text", "value": "New"}]}]));
|
||||
lock(&mut s, title, all());
|
||||
let dir = std::env::temp_dir().join(format!("pc-vars-{}-locked-export", std::process::id()));
|
||||
let out = s.execute("file.export.dataSetsAsFiles", json!({"dir": dir.to_string_lossy(), "format": "png"})).unwrap();
|
||||
assert_eq!(out["files"].as_array().map(Vec::len), Some(1), "{out}");
|
||||
assert_eq!(text_of(&s, title), "Old", "the export leaves the document alone");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
Loaded 100 of 255 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user