Resolve merge conflicts with main
No files matched your search
@@ -434,7 +434,12 @@ test linux photocraft-ui-egui 1.88 dialog_title_ellipsis_tests::dialog_titles_dr
|
||||
test linux photocraft-ui-egui 1.37 dialogs::adjust_editors::ui_tests::black_white_auto_button_sets_the_weights
|
||||
test linux photocraft-ui-egui 2.19 dialogs::adjust_editors::ui_tests::color_balance_properties_history_and_reset_like_photoshop
|
||||
test linux photocraft-ui-egui 1.64 dialogs::adjust_editors::ui_tests::color_lookup_picker_cycles_luts_with_the_mouse_wheel
|
||||
test linux photocraft-ui-egui 65.85 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties
|
||||
test linux photocraft-ui-egui 10.97 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::cmyk_8
|
||||
test linux photocraft-ui-egui 10.97 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::gray_8
|
||||
test linux photocraft-ui-egui 10.97 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::lab_16
|
||||
test linux photocraft-ui-egui 10.97 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::rgb_16
|
||||
test linux photocraft-ui-egui 10.97 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::rgb_32
|
||||
test linux photocraft-ui-egui 10.97 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::rgb_8
|
||||
test linux photocraft-ui-egui 2.05 dialogs::adjust_editors::ui_tests::gradient_map_stop_picker_closed_without_a_colour_changes_nothing
|
||||
test linux photocraft-ui-egui 2.31 dialogs::adjust_editors::ui_tests::photo_filter_colour_picker_previews_live_cancel_restores_and_ok_is_one_step
|
||||
test linux photocraft-ui-egui 2.10 dialogs::adjust_editors::ui_tests::properties_white_point_eyedropper_edits_the_layer
|
||||
@@ -1703,7 +1708,12 @@ test windows photocraft-ui-egui 3.52 dialog_title_ellipsis_tests::dialog_titles_
|
||||
test windows photocraft-ui-egui 1.55 dialogs::adjust_editors::ui_tests::black_white_auto_button_sets_the_weights
|
||||
test windows photocraft-ui-egui 2.65 dialogs::adjust_editors::ui_tests::color_balance_properties_history_and_reset_like_photoshop
|
||||
test windows photocraft-ui-egui 1.93 dialogs::adjust_editors::ui_tests::color_lookup_picker_cycles_luts_with_the_mouse_wheel
|
||||
test windows photocraft-ui-egui 39.08 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties
|
||||
test windows photocraft-ui-egui 6.51 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::cmyk_8
|
||||
test windows photocraft-ui-egui 6.51 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::gray_8
|
||||
test windows photocraft-ui-egui 6.51 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::lab_16
|
||||
test windows photocraft-ui-egui 6.51 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::rgb_16
|
||||
test windows photocraft-ui-egui 6.51 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::rgb_32
|
||||
test windows photocraft-ui-egui 6.51 dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::rgb_8
|
||||
test windows photocraft-ui-egui 2.39 dialogs::adjust_editors::ui_tests::gradient_map_stop_picker_closed_without_a_colour_changes_nothing
|
||||
test windows photocraft-ui-egui 2.88 dialogs::adjust_editors::ui_tests::photo_filter_colour_picker_previews_live_cancel_restores_and_ok_is_one_step
|
||||
test windows photocraft-ui-egui 2.35 dialogs::adjust_editors::ui_tests::properties_white_point_eyedropper_edits_the_layer
|
||||
|
||||
|
@@ -63,7 +63,7 @@ archive.include = [
|
||||
# warning still comes at 15 s; a run past 90 s is terminated.
|
||||
[[profile.ci.overrides]]
|
||||
filter = 'binary(panic_hunt)'
|
||||
slow-timeout = { period = "15s", terminate-after = 6 }
|
||||
slow-timeout = { period = "15s", terminate-after = 12 }
|
||||
|
||||
# Content-Aware Move solves on rayon across every core. On the Windows runner the GPU tests draw
|
||||
# on the CPU-backed adapter, so two of these beside a GPU test starve it until its device poll
|
||||
@@ -73,6 +73,15 @@ platform = 'cfg(target_os = "windows")'
|
||||
filter = '(package(photocraft-engine-core) | package(photocraft-engine-paint) | package(photocraft-engine)) & test(/content_aware_move/)'
|
||||
threads-required = "num-test-threads"
|
||||
|
||||
# The agent link tests start a link over a fresh folder, so it creates its token file. On Windows
|
||||
# craft-libs makes that file through whoami and PowerShell and gives up after 10 s, and on a
|
||||
# loaded runner PowerShell alone took longer: nothing listened and all three failed (#19378).
|
||||
# Each runs alone there; no case or limit changes.
|
||||
[[profile.ci.overrides]]
|
||||
platform = 'cfg(target_os = "windows")'
|
||||
filter = 'package(photocraft-ui-egui) & test(/^prefs::prefs_ui::agents_tests::/)'
|
||||
threads-required = "num-test-threads"
|
||||
|
||||
# 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.
|
||||
# Page eviction and budget borrowing redraw multi-effect documents. On the Windows
|
||||
@@ -112,7 +121,7 @@ filter = '''
|
||||
(package(photocraft-ui-egui) & test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is)) |
|
||||
(package(photocraft-ui-egui) & test(=tone_targets::review_mask_action_context_matches_the_addressed_layer)) |
|
||||
(package(photocraft-ui-egui) & test(=tone_targets::grayscale_picker_controls_sample_the_plane_and_change_the_visible_curve)) |
|
||||
(package(photocraft-ui-egui) & test(=dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties)) |
|
||||
(package(photocraft-ui-egui) & test(/^dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties::/)) |
|
||||
(package(photocraft-ui-egui) & test(=tone_targets::filter_mask_tone_dialogs_preserve_the_target_and_sample_its_own_levels))
|
||||
'''
|
||||
priority = 100
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
"repository_id": 1398080271,
|
||||
"producer_workflow_id": 428462603,
|
||||
"producer_workflow_path": ".github/workflows/nightly.yml",
|
||||
"producer_tooling_revision": "8389cad8b849ea6bdb5e15fbce16772c3457565a",
|
||||
"producer_workflow_ref": "storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@8389cad8b849ea6bdb5e15fbce16772c3457565a",
|
||||
"producer_tooling_revision": "main",
|
||||
"producer_workflow_ref": "storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@main",
|
||||
"signer_workflow_path": ".github/workflows/nightly-sign.yml",
|
||||
"signer_tooling_revision": "8389cad8b849ea6bdb5e15fbce16772c3457565a",
|
||||
"signer_tooling_revision": "main",
|
||||
"release_branch": "nightly-signer",
|
||||
"manual_actors": [
|
||||
"aiongg",
|
||||
"bflatastic",
|
||||
"dylanmtaylor",
|
||||
"echelon",
|
||||
@@ -186,14 +187,6 @@
|
||||
"severity": "MAJOR",
|
||||
"hash": "487390be64dd83ce33912f980c863775"
|
||||
},
|
||||
{
|
||||
"key": "AaH2uKhnARfBzs_vH5to",
|
||||
"rule": "pythonsecurity:S2083",
|
||||
"component": "storytold_photocraft:scripts/ci-test-times.py",
|
||||
"type": "VULNERABILITY",
|
||||
"severity": "BLOCKER",
|
||||
"hash": "49be67b6e92adfd1925fe265def3f32f"
|
||||
},
|
||||
{
|
||||
"key": "AaH2uKhnARfBzs_vH5tp",
|
||||
"rule": "pythonsecurity:S8705",
|
||||
@@ -294,7 +287,9 @@
|
||||
}
|
||||
},
|
||||
"max_artifact_bytes": 2147483648,
|
||||
"automatic_signer_actors": [],
|
||||
"automatic_signer_actors": [
|
||||
"github-actions[bot]"
|
||||
],
|
||||
"platforms": {
|
||||
"windows-x86_64": {
|
||||
"unsigned_artifact_name": "nightly-unsigned-windows-x86_64",
|
||||
@@ -306,7 +301,15 @@
|
||||
"unsigned_artifact_name": "nightly-unsigned-linux-x86_64",
|
||||
"trust": {
|
||||
"fingerprint": "2B76741B414AAD6CD33E631213A005C0B9D7C3ED"
|
||||
}
|
||||
},
|
||||
"package_formats": [
|
||||
"appimage",
|
||||
"arch",
|
||||
"deb",
|
||||
"flatpak",
|
||||
"oci",
|
||||
"rpm"
|
||||
]
|
||||
},
|
||||
"macos-aarch64": {
|
||||
"unsigned_artifact_name": "nightly-unsigned-macos-aarch64",
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
# A fork's pull request from a branch named main also matches `branches`.
|
||||
if: github.event.workflow_run.event != 'pull_request'
|
||||
timeout-minutes: 10
|
||||
runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-main' || 'ubuntu-24.04' }}
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
|
||||
@@ -97,7 +97,7 @@ jobs:
|
||||
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
|
||||
timeout-minutes: 10
|
||||
name: select platforms
|
||||
runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-main' || 'ubuntu-latest' }}
|
||||
runs-on: ubuntu-24.04
|
||||
outputs:
|
||||
windows: ${{ steps.pick.outputs.windows }}
|
||||
windows_gpu: ${{ steps.pick.outputs.windows_gpu }}
|
||||
@@ -206,6 +206,7 @@ jobs:
|
||||
CARGO_PROFILE_TEST_STRIP=symbols
|
||||
PHOTOCRAFT_CI_EXCLUDE=${{ needs.platforms.outputs.linux_skip }}
|
||||
PHOTOCRAFT_CORPUS_TESTS=1
|
||||
RAYON_NUM_THREADS=4
|
||||
timeout-minutes: 100
|
||||
cache-workspace-crates: true
|
||||
lint-cache: false
|
||||
@@ -264,7 +265,7 @@ 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
|
||||
lint-command: cargo xtask ci clippy
|
||||
lint-command: cargo xtask-gate clippy
|
||||
archive-command: cargo xtask-gate archive
|
||||
after-archive-command: cargo xtask-gate doctest
|
||||
test-shards: 6
|
||||
@@ -286,7 +287,7 @@ jobs:
|
||||
# A cold Windows build takes about an hour, and the watch ends when it does; `watch-minutes`
|
||||
# ends it before this limit.
|
||||
timeout-minutes: 120
|
||||
runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-main' || 'ubuntu-24.04' }}
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
@@ -347,6 +348,7 @@ jobs:
|
||||
CARGO_NET_RETRY: 10
|
||||
CARGO_PROFILE_DEV_DEBUG: "0"
|
||||
CARGO_PROFILE_TEST_STRIP: symbols
|
||||
RAYON_NUM_THREADS: "4"
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
@@ -369,7 +371,7 @@ jobs:
|
||||
libgtk-3-dev
|
||||
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -417,7 +419,7 @@ jobs:
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
||||
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -542,7 +544,7 @@ jobs:
|
||||
libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev
|
||||
libgtk-3-dev
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -579,7 +581,7 @@ jobs:
|
||||
libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev
|
||||
libgtk-3-dev
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -615,7 +617,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -652,7 +654,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -679,17 +681,17 @@ jobs:
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
path: after
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
ref: ${{ inputs.brush_tip_base }}
|
||||
path: before
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -711,7 +713,7 @@ jobs:
|
||||
done
|
||||
done
|
||||
done
|
||||
- uses: actions/upload-artifact@v7
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
if: always()
|
||||
with:
|
||||
name: brush-tip-performance
|
||||
@@ -744,7 +746,7 @@ jobs:
|
||||
mkdir -p "$RUNNER_TEMP/photocraft-baseline/crates/engine/examples"
|
||||
cp crates/engine/examples/bench_dry_mixer.rs "$RUNNER_TEMP/photocraft-baseline/crates/engine/examples/bench_dry_mixer.rs"
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
|
||||
@@ -11,9 +11,8 @@ permissions: {}
|
||||
|
||||
jobs:
|
||||
dispatch:
|
||||
# SOURCE PREPARATION: literal off until immutable shared tooling and policy qualification.
|
||||
if: >-
|
||||
false && github.repository == 'storytold/photocraft' &&
|
||||
github.repository == 'storytold/photocraft' &&
|
||||
github.event_name == 'workflow_run'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
|
||||
@@ -44,12 +44,12 @@ jobs:
|
||||
persist-credentials: false
|
||||
# The release's pin (release.yml craft-fonts-ref), so the bundle's notices match a shipped build.
|
||||
- name: Check out craft-fonts
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main
|
||||
with:
|
||||
ref: cc9269cd8d8258785dac603fba3122e5d2556795
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
with:
|
||||
targets: aarch64-apple-darwin
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
|
||||
@@ -35,12 +35,25 @@ jobs:
|
||||
checks: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@main
|
||||
with:
|
||||
tooling-revision: 8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
tooling-revision: main
|
||||
app-name: photocraft
|
||||
producer_run_id: ${{ inputs.producer_run_id }}
|
||||
producer_run_attempt: ${{ inputs.producer_run_attempt }}
|
||||
# No secrets: inherit or raw platform values in this caller. Only the isolated native
|
||||
# callee job may bind the existing release environment (which trusts release and
|
||||
# nightly-signer) and export keys in its signing step.
|
||||
# Declare only same-name inputs required by the reusable signer. Only native callee
|
||||
# signing jobs bind the release environment; do not copy credentials to caller scope.
|
||||
secrets:
|
||||
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
|
||||
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
|
||||
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
|
||||
APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
|
||||
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
||||
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
|
||||
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
|
||||
AZURE_SIGNING_ENDPOINT: ${{ secrets.AZURE_SIGNING_ENDPOINT }}
|
||||
AZURE_SIGNING_ACCOUNT: ${{ secrets.AZURE_SIGNING_ACCOUNT }}
|
||||
AZURE_CERT_PROFILE: ${{ secrets.AZURE_CERT_PROFILE }}
|
||||
LINUX_SIGNING_KEY: ${{ secrets.LINUX_SIGNING_KEY }}
|
||||
@@ -1,8 +1,9 @@
|
||||
name: PhotoCraft unsigned nightly
|
||||
|
||||
# Enabled for supervised manual runs by the reviewed manual actor only; no schedule yet.
|
||||
# A later explicit opt-in may add a cadence (and turn on nightly-dispatch.yml with it).
|
||||
# Automated scheduled nightly builds at 05:00 UTC plus manual runs by the reviewed manual actors.
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 5 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
@@ -22,12 +23,13 @@ jobs:
|
||||
actions: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@main
|
||||
with:
|
||||
tooling-revision: 8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
tooling-revision: main
|
||||
app-name: photocraft
|
||||
manual-actors: '["bflatastic","dylanmtaylor","echelon","FredApps","skylartaylor"]'
|
||||
manual-actors: '["aiongg","bflatastic","dylanmtaylor","echelon","FredApps","skylartaylor"]'
|
||||
craft-fonts-ref: cc9269cd8d8258785dac603fba3122e5d2556795
|
||||
# One producer run builds every listed platform for one all-or-nothing release. The pin is the
|
||||
# craft-common-actions main commit that merged #371 (built-commit Sonar admission), on #370.
|
||||
platforms: '["windows-x86_64","linux-x86_64","macos-aarch64"]'
|
||||
linux-package-formats: '["deb","rpm","appimage","flatpak","oci","arch"]'
|
||||
@@ -47,12 +47,12 @@ jobs:
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- id: rust
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
uses: storytold/craft-common-actions/actions/rust-channel@main
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: ${{ steps.rust.outputs.toolchain }}
|
||||
@@ -87,7 +87,7 @@ jobs:
|
||||
|
||||
- name: Upload results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v7
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: perf-results
|
||||
path: |
|
||||
@@ -98,7 +98,7 @@ jobs:
|
||||
|
||||
- name: Upload baseline
|
||||
if: always() && inputs.update_baseline
|
||||
uses: actions/upload-artifact@v7
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: perf-baseline
|
||||
path: perf/baseline.json
|
||||
|
||||
@@ -10,7 +10,7 @@ permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: sonarcloud-${{ github.ref }}
|
||||
group: ${{ github.ref == 'refs/heads/main' && format('sonarcloud-main-{0}', github.sha) || format('sonarcloud-{0}', github.ref) }}
|
||||
# A push to main is the run that publishes coverage; superseded runs there would never finish.
|
||||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
||||
|
||||
|
||||
@@ -17,14 +17,19 @@ next to them.
|
||||
| `assets/icons/{arrow-left-right,circle-dashed,ellipsis,file-plus,folder-plus,grid-2x2,house,link-2,message-square,panel-left,pipette,rectangle-horizontal,rectangle-vertical,redo-2,share,square-dashed,square-dashed-mouse-pointer,triangle-alert,type,x}.svg` | Lucide icons | Lucide Icons and Contributors | <https://github.com/lucide-icons/lucide> (`icons/<name>.svg`) | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
| `assets/icons/{link-2,type,x}.svg` | Lucide icons derived from Feather (subset of the row above) | Cole Bemis (Feather), Lucide Contributors | <https://github.com/feathericons/feather> via Lucide | MIT (Feather) and ISC (Lucide), [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
| `assets/icons/vector-shape.svg` | Vector path shape-layer glyph with four anchor points | @superplay2021 | Original work for PhotoCraft | MIT OR Apache-2.0 |
|
||||
| `assets/icons/gradient-tool.svg` | Gradient tool glyph with a horizontal opacity ramp | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/spirit-level.svg` | Straighten tool glyph: a spirit level with its vial and bubble under a dotted arc | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/type-vertical.svg` | Vertical Type tool glyph: Lucide `type`'s T, drawn narrower to make room for a downward arrow of our own at its left | Lucide Icons and Contributors; arrow by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/type.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
| `assets/icons/quick-mask-{off,masked-areas,selected-areas}.svg` | Quick Mask toolbar glyphs showing the inactive mode and the two overlay meanings | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/path-op-{new-layer,combine,subtract,intersect,exclude,merge}.svg` | Path Operations glyphs (Pen options bar): a single square for New Layer, and two overlapping squares showing the area each operation keeps (union, back minus front, overlap, everything but the overlap, the merged outline), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/arrange-{tile-all-vertically,tile-all-horizontally,two-up-horizontal,two-up-vertical,three-up-horizontal,three-up-vertical,three-up-stacked,four-up,six-up,consolidate-all-to-tabs}.svg` | Window › Arrange layout glyphs: a window outline split into the panes each entry lays out (columns, rows, the n-up splits, and one window with a tab row for Consolidate All to Tabs), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/history-brush.svg` | History Brush tool glyph: Lucide `brush` plus counter-clockwise history rewind arrow | Lucide Icons and Contributors; arrow by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/brush.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
| `assets/dict/en_US-scowl-50.txt.gz` | English word list for Check Spelling (SCOWL 2020.12.07, size 50, en_US; 72,403 words) | Kevin Atkinson and the SCOWL contributors | <http://wordlist.aspell.net/> | SCOWL license (permissive, keep the notice), [`assets/dict/LICENSE-SCOWL.txt`](assets/dict/LICENSE-SCOWL.txt), which also has the build recipe |
|
||||
| `assets/app-icon/` (all files) | PhotoCraft app icon (nine-tailed kitsune) | The project owner (drawn in ArtCraft, vectorised) | Original work, see [`assets/app-icon/README.md`](assets/app-icon/README.md) | MIT OR Apache-2.0, [`assets/app-icon/LICENSE.txt`](assets/app-icon/LICENSE.txt) |
|
||||
| `assets/app-icon/photocraft-nightly.png`, `photocraft-nightly-1024.png`, `photocraft-nightly.ico`, `photocraft-nightly.icns` | PhotoCraft nightly deep-background derivatives | @skylartaylor | Original project-owned256 and padded1024 masters at the revision and hashes in [`nightly-provenance.json`](assets/app-icon/nightly-provenance.json); code-generated background-contribution change only, preserving foreground/alpha; no badge or crescent | MIT OR Apache-2.0, [`assets/app-icon/LICENSE.txt`](assets/app-icon/LICENSE.txt) |
|
||||
| `packaging/nightly-archive-tests.py` (runtime-generated temporary files) | Synthetic flat-archive inventory and exclusive-output fixtures; regular-file payloads, not real image/executable validity | @skylartaylor | Original test-generated strings/files and symlinks from the committed script; no external media or user documents | MIT OR Apache-2.0 |
|
||||
| `packaging/macos/dmg/` (all files) | PhotoCraft DMG window background and layout | @XusBadia, from the PhotoCraft app icon | Original work, see [`packaging/macos/dmg/README.md`](packaging/macos/dmg/README.md) | MIT OR Apache-2.0, like the code |
|
||||
| `crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs` | Built-in Black & White tonal and filter mixes | PhotoCraft contributors (@Bobderto) | Original weights chosen to produce the named tonal and color-filter effects, from [PhotoCraft `2b1afe637`](https://github.com/storytold/photocraft/commit/2b1afe637cabe3eba622c8edd3e92b279aa8dfe4) | MIT OR Apache-2.0 |
|
||||
| `crates/ui-egui/src/theme.rs` (Solarized Dark palette) | Solarized colour scheme used by the Solarized Dark theme | Ethan Schoonover | <https://ethanschoonover.com/solarized/> | MIT, [`LICENSE-solarized.txt`](crates/ui-egui/src/LICENSE-solarized.txt) |
|
||||
| `crates/ui-egui/src/theme.rs` (Breeze Light and Breeze Dark themes) | The Breeze Light and Breeze Dark themes are original colour values on PhotoCraft's Studio layout, chosen to look close to KDE Plasma's Breeze (cool blue-greys, blue accent, 5 px frame radius) so the app blends into a Plasma desktop. None of Breeze's colour values, files or code are copied; the values are a few levels away from its schemes and tuned for text contrast | PhotoCraft contributors | Inspired by the look of KDE Breeze, <https://invent.kde.org/plasma/breeze> (its colour schemes are LGPL-2.0-or-later) | Original work |
|
||||
| `crates/ui-egui/src/theme.rs` (Soft Dark and Soft Light themes) | Original colour values and radii for two low-contrast themes on PhotoCraft's Studio layout; no third-party palette, file or code is used | PhotoCraft contributors | Original | Original work |
|
||||
|
||||
@@ -777,6 +777,17 @@ dependencies = [
|
||||
"brotli-decompressor 5.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brotli"
|
||||
version = "9.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9071f285ed78f04f37d675abaaef5de7689e2f30a216c8dc6795465d81910a13"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib 3.0.0",
|
||||
"alloc-stdlib 0.3.0",
|
||||
"brotli-decompressor 6.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brotli-decompressor"
|
||||
version = "5.0.3"
|
||||
@@ -1380,7 +1391,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-automation",
|
||||
"craft-behavior",
|
||||
@@ -1421,7 +1432,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-affinity"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
@@ -1442,18 +1453,19 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-appkit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"objc2 0.6.5",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-core-graphics",
|
||||
"objc2-foundation 0.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-atomic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"rustix 1.1.6",
|
||||
]
|
||||
@@ -1461,7 +1473,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-automation"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -1486,7 +1498,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-behavior"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"bitflags 2.13.2",
|
||||
@@ -1504,7 +1516,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-browse"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-docpath",
|
||||
@@ -1522,7 +1534,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cloud-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"egui",
|
||||
]
|
||||
@@ -1530,7 +1542,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cms"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"md-5",
|
||||
"rayon",
|
||||
@@ -1539,12 +1551,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-codepage"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-color"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1552,7 +1564,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-color-transform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-cms",
|
||||
"craft-color",
|
||||
@@ -1562,10 +1574,11 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-color-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-cms",
|
||||
"craft-drawingml",
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
"craft-keymap",
|
||||
@@ -1582,7 +1595,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-ai-agents",
|
||||
"craft-atomic",
|
||||
@@ -1590,7 +1603,6 @@ dependencies = [
|
||||
"craft-flags",
|
||||
"craft-platform",
|
||||
"dirs",
|
||||
"getrandom 0.3.4",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1599,8 +1611,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control-protocol"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
"serde_json",
|
||||
"subtle",
|
||||
]
|
||||
@@ -1608,7 +1621,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-crs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-metadata",
|
||||
"craft-xml",
|
||||
@@ -1618,7 +1631,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-crw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1626,7 +1639,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
@@ -1634,7 +1647,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-develop"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-color",
|
||||
"craft-color-transform",
|
||||
@@ -1649,7 +1662,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-develop-model"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-geom",
|
||||
"craft-metadata",
|
||||
@@ -1661,7 +1674,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dialogs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"craft-appkit",
|
||||
@@ -1687,7 +1700,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1695,7 +1708,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-draw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1711,15 +1724,27 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-drawingml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-xml",
|
||||
"kurbo 0.13.1",
|
||||
"log",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-file-formats"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"craft-idml",
|
||||
@@ -1737,7 +1762,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-flags"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"dirs",
|
||||
@@ -1747,7 +1772,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-catalog"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"fontique",
|
||||
"harfrust 0.13.3",
|
||||
@@ -1762,7 +1787,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-manager"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -1782,7 +1807,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-os-windows"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"windows-registry",
|
||||
"windows-sys 0.61.2",
|
||||
@@ -1791,7 +1816,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"cap-primitives",
|
||||
"craft-atomic",
|
||||
@@ -1814,12 +1839,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-geom"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1827,7 +1852,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-heif"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"heic-rs",
|
||||
"rayon",
|
||||
@@ -1836,7 +1861,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-host"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-i18n",
|
||||
@@ -1849,8 +1874,10 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.2",
|
||||
"chrono",
|
||||
"fixed_decimal",
|
||||
"icu_calendar",
|
||||
@@ -1877,7 +1904,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-idml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -1887,7 +1914,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-dds",
|
||||
"craft-heif",
|
||||
@@ -1915,7 +1942,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-imaging"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1933,12 +1960,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ipp"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1946,7 +1973,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-keymap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
@@ -1961,7 +1988,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-kra"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -1971,7 +1998,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-layers"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-i18n",
|
||||
@@ -1985,7 +2012,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-menu"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2003,7 +2030,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.2",
|
||||
"chrono",
|
||||
@@ -2012,10 +2039,19 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-nightly"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"uds_windows",
|
||||
"winsafe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-ora"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -2025,7 +2061,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pages"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2041,7 +2077,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-bundle"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-atomic",
|
||||
@@ -2054,7 +2090,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"serde",
|
||||
@@ -2065,7 +2101,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"flate2",
|
||||
@@ -2080,7 +2116,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdn"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2089,12 +2125,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-platform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-io",
|
||||
"async-process",
|
||||
"core-graphics2",
|
||||
"craft-appkit",
|
||||
"craft-atomic",
|
||||
"craft-docpath",
|
||||
"craft-host",
|
||||
@@ -2104,6 +2140,8 @@ dependencies = [
|
||||
"js-sys",
|
||||
"log",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
"rfd",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -2120,7 +2158,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-plist"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -2128,7 +2166,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-print"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2152,7 +2190,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -2163,7 +2201,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -2176,7 +2214,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-raw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-crw",
|
||||
@@ -2194,7 +2232,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-review"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -2213,7 +2251,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-settings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-host",
|
||||
@@ -2230,7 +2268,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-xml",
|
||||
@@ -2251,7 +2289,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-table"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2263,15 +2301,17 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-testkit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"rustix 1.1.6",
|
||||
"tempfile",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-text"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-manager",
|
||||
@@ -2294,7 +2334,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-tracked",
|
||||
@@ -2309,7 +2349,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-editor"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-theme",
|
||||
@@ -2320,7 +2360,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-behavior",
|
||||
@@ -2335,7 +2375,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2345,7 +2385,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-time"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2354,7 +2394,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-timeline"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2369,7 +2409,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tracked"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -2377,7 +2417,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-cloud-ui",
|
||||
"craft-ui-canvas",
|
||||
@@ -2391,9 +2431,10 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-canvas"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
"craft-i18n",
|
||||
"craft-keymap",
|
||||
"craft-theme",
|
||||
@@ -2407,7 +2448,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-contract"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"craft-behavior",
|
||||
@@ -2449,7 +2490,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2460,7 +2501,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-panels"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2478,7 +2519,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-patterns"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2499,7 +2540,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-shell"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2519,7 +2560,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-widgets"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2538,7 +2579,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
@@ -2570,7 +2611,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-win32"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"winsafe",
|
||||
]
|
||||
@@ -2578,7 +2619,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-window"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-appkit",
|
||||
"craft-atomic",
|
||||
@@ -2610,7 +2651,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xcf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2619,7 +2660,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
@@ -2629,7 +2670,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -3046,7 +3087,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
@@ -3080,7 +3121,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -3117,7 +3158,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
@@ -3138,7 +3179,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-wgpu"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -3157,7 +3198,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-winit"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"accesskit_winit",
|
||||
"arboard",
|
||||
@@ -3183,7 +3224,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_extras"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"egui",
|
||||
@@ -3197,7 +3238,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui",
|
||||
@@ -3210,7 +3251,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_kittest"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"dify",
|
||||
"eframe",
|
||||
@@ -3236,7 +3277,7 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"serde",
|
||||
@@ -3329,7 +3370,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -3356,7 +3397,11 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
@@ -4149,7 +4194,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"hayro-interpret",
|
||||
@@ -4172,14 +4217,14 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a14afde3344be69225fec4f6f44f6a219a3a492f9d8301eb25ef608fe4b7014c"
|
||||
dependencies = [
|
||||
"brotli",
|
||||
"brotli 8.0.4",
|
||||
"hayro-postscript",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hayro-interpret"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"hayro-cmap",
|
||||
@@ -4197,7 +4242,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"fearless_simd",
|
||||
"hayro-ccitt",
|
||||
@@ -4221,7 +4266,7 @@ checksum = "bc2d80da85f31c3fdc0366431f44cfd645a9da1e242ed1f4a61f213d9765660f"
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hayro-ccitt",
|
||||
@@ -5330,7 +5375,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4"
|
||||
[[package]]
|
||||
name = "linesweeper"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"kurbo 0.13.1",
|
||||
@@ -6558,6 +6603,7 @@ dependencies = [
|
||||
"craft",
|
||||
"craft-cms",
|
||||
"craft-image-codecs",
|
||||
"craft-nightly",
|
||||
"craft-svg",
|
||||
"craft-update",
|
||||
"craft-xml",
|
||||
@@ -6925,6 +6971,7 @@ dependencies = [
|
||||
"craft-xcf",
|
||||
"craft-xml",
|
||||
"crc32fast",
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
"kurbo 0.13.1",
|
||||
"lopdf",
|
||||
@@ -7089,6 +7136,7 @@ version = "0.23.1"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"chrono",
|
||||
"core-graphics",
|
||||
"craft",
|
||||
"craft-file-formats",
|
||||
"craft-i18n",
|
||||
@@ -7119,6 +7167,7 @@ dependencies = [
|
||||
"photocraft-vector",
|
||||
"rayon",
|
||||
"robius-share",
|
||||
"roxmltree 0.21.2",
|
||||
"rustc-hash 2.1.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -7127,6 +7176,7 @@ dependencies = [
|
||||
"toml",
|
||||
"web-time",
|
||||
"winsafe",
|
||||
"x11rb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -9877,7 +9927,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "vello_common"
|
||||
version = "0.0.8"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"fearless_simd",
|
||||
@@ -9925,7 +9975,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "vello_cpu"
|
||||
version = "0.0.8"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"glifo 0.1.1",
|
||||
@@ -11675,29 +11725,29 @@ dependencies = [
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=932a73b28560acb1a695533307b2cd0d66a42081#932a73b28560acb1a695533307b2cd0d66a42081"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "hayro-cmap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "hayro-postscript"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "krilla"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=3eb5b528b08211844bc5c95c5a4fd169894d52ff#3eb5b528b08211844bc5c95c5a4fd169894d52ff"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
@@ -12,21 +12,21 @@ 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff", default-features = false }
|
||||
craft-tracked = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-ui-macros = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", default-features = false }
|
||||
craft-tracked = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-ui-macros = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
|
||||
craft-plist = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-compose = { path = "crates/compose" }
|
||||
photocraft-gpu = { path = "crates/gpu" }
|
||||
photocraft-paint = { path = "crates/paint" }
|
||||
@@ -48,36 +48,38 @@ 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# HEIC/HEIF: the shared decoder (replaces crates/heif; craft-libs#784).
|
||||
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff", features = ["raster", "write-raster"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["raster", "write-raster"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# Keep the shared embedded-image validation API until the framework revision includes it.
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# Camera-field EXIF reader/writer, shared prerequisite craft-libs#1563.
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff", features = ["ui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["ui"] }
|
||||
# Self-contained nightly profile isolation, launch protocol, and security fence.
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
thiserror = "2"
|
||||
serde = { version = "1", features = ["derive", "rc"] }
|
||||
serde_json = "1"
|
||||
@@ -350,28 +352,28 @@ 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 = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
vello_common = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
vello_cpu = { git = "https://github.com/storytold/craft-libs", rev = "3eb5b528b08211844bc5c95c5a4fd169894d52ff" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "932a73b28560acb1a695533307b2cd0d66a42081" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
vello_common = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
vello_cpu = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "f8b490f135ea439dd31aae100bb5591c63cb076f" }
|
||||
@@ -22,7 +22,8 @@ fn same_dir(a: &Path, b: &Path) -> bool {
|
||||
|
||||
pub(crate) fn is_input(p: &Path) -> bool {
|
||||
let known = |e: &str| {
|
||||
matches!(e, "pcraft" | "psd" | "psb" | "pdn" | "ora" | "kra" | "krz" | "af" | "afdesign" | "afphoto" | "afpub" | "xcf" | "xcfgz")
|
||||
// `.tx` textures are TIFFs the codecs read but deliberately don't list (they can't write one).
|
||||
matches!(e, "pcraft" | "psd" | "psb" | "pdn" | "ora" | "kra" | "krz" | "af" | "afdesign" | "afphoto" | "afpub" | "xcf" | "xcfgz" | "tx")
|
||||
|| photocraft_codecs::from_extension(e).is_some_and(|f| photocraft_codecs::caps(f).read)
|
||||
};
|
||||
// Only GIMP's compound suffix is an image; an arbitrary .gz is not a batch input.
|
||||
@@ -221,6 +222,29 @@ mod batch_action_set_tests {
|
||||
use crate::test_support::{Invoke, invoke};
|
||||
use serde_json::Value;
|
||||
|
||||
/// A folder of `.tx` textures (tiled MIP-mapped TIFFs the codecs read but can't write) is picked
|
||||
/// up by `batch`, and each one is written in the format asked for.
|
||||
#[test]
|
||||
fn batch_picks_up_tx_textures_and_writes_the_chosen_format() {
|
||||
let dir = std::env::temp_dir().join(format!("photocraft-cli-tx-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let path = |name: &str| dir.join(name).to_string_lossy().to_string();
|
||||
std::fs::create_dir_all(dir.join("in")).unwrap();
|
||||
let Invoke { code, stderr, .. } = invoke(&["run", "--new", r#"{"width":8,"height":6}"#, "--out", &path("in/wall.tif")]);
|
||||
assert_eq!(code, 0, "{stderr}");
|
||||
std::fs::rename(dir.join("in/wall.tif"), dir.join("in/wall.tx")).unwrap();
|
||||
std::fs::write(dir.join("steps.json"), r#"["image.adjustments.invert"]"#).unwrap();
|
||||
let Invoke { code, stdout, stderr } =
|
||||
invoke(&["batch", "--actions", &path("steps.json"), "--in", &path("in"), "--out", &path("out"), "--format", "png"]);
|
||||
assert_eq!(code, 0, "{stdout}{stderr}");
|
||||
assert!(dir.join("out/wall.png").is_file(), "{stdout}{stderr}");
|
||||
// Without `--format` a texture is saved as PSD, as other formats PhotoCraft only reads.
|
||||
let Invoke { code, stdout, stderr } = invoke(&["batch", "--actions", &path("steps.json"), "--in", &path("in"), "--out", &path("same")]);
|
||||
assert_eq!(code, 0, "{stdout}{stderr}");
|
||||
assert!(dir.join("same/wall.psd").is_file(), "{stdout}{stderr}");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A batched action that plays another action of its set finds it in every file's session; a
|
||||
/// failure inside the called action fails the file, and a self-call stops instead of looping.
|
||||
#[test]
|
||||
|
||||
@@ -2112,7 +2112,7 @@ fn mcp_session(args: &[&str], env: &[(&str, &std::ffi::OsStr)], calls: &[(&str,
|
||||
}
|
||||
|
||||
/// Plain `mcp` without the person's consent works headless, as it always did: commands run, UI
|
||||
/// tools say they need the open app. `--headless` too, and it doesn't read a PHOTOCRAFT_CONTROL_PORT
|
||||
/// tools are not offered. `--headless` too, and it doesn't read a PHOTOCRAFT_CONTROL_PORT
|
||||
/// exported for another tool (here not even a port).
|
||||
#[test]
|
||||
fn mcp_without_consent_works_headless() {
|
||||
@@ -2124,8 +2124,8 @@ fn mcp_without_consent_works_headless() {
|
||||
let calls = [("command_list", json!({})), ("ui_inspect", json!({}))];
|
||||
let r = mcp_session(&["mcp", "--when-closed", "error"], &env, &calls);
|
||||
assert_ne!(r[0]["isError"], true, "headless commands run: {}", r[0]);
|
||||
assert_eq!(r[1]["isError"], true, "{}", r[1]);
|
||||
assert!(r[1]["content"][0]["text"].as_str().unwrap().contains("bridge"), "{}", r[1]);
|
||||
// An unknown tool is a protocol error, so the reply has no `result`.
|
||||
assert!(r[1].is_null(), "headless mcp offers no ui_* tools: {}", r[1]);
|
||||
let mut env = env.to_vec();
|
||||
env.push(("PHOTOCRAFT_CONTROL_PORT", std::ffi::OsStr::new("not-a-port")));
|
||||
let r = mcp_session(&["mcp", "--headless"], &env, &calls[..1]);
|
||||
|
||||
@@ -142,6 +142,11 @@ fn orientation_6_jpeg_converts_upright_and_rotates_back() {
|
||||
for v in [&mut ia, &mut ib] {
|
||||
v.as_object_mut().unwrap().remove("name");
|
||||
v["snapshots"][0].as_object_mut().unwrap().remove("name");
|
||||
// The History Brush's default source names the open snapshot, which carries the document's
|
||||
// own name as well (#12845); its shape still has to match.
|
||||
if let Some(source) = v["historySource"].as_object_mut() {
|
||||
source.remove("name");
|
||||
}
|
||||
}
|
||||
assert_eq!(ia, ib);
|
||||
let (pa, pb) = (d.join("a.png"), d.join("b.png"));
|
||||
|
||||
@@ -22,9 +22,9 @@ type PlaceInbox = photocraft_ui_egui::PlaceInbox;
|
||||
/// Everything File › Open reads: PhotoCraft, Photoshop, OpenRaster, Krita and Affinity documents, flat images, and
|
||||
/// Photoshop brushes (.abr), gradients (.grd), layer styles (.asl) and swatches (.aco, .act, .ase), which go to the preset libraries.
|
||||
const OPEN_EXTS: &[&str] = &[
|
||||
"pcraft", "pdn", "ora", "xcf", "xcfgz", "gz", "kra", "krz", "psd", "psb", "psdt", "png", "jpg", "jpeg", "tif", "tiff", "webp", "gif", "bmp", "tga", "ico",
|
||||
"qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam", "pfm", "dds", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "iff", "lbm", "ilbm", "heic",
|
||||
"heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "asl", "svg", "svgz", "aco", "act", "ase", "af",
|
||||
"pcraft", "pdn", "ora", "xcf", "xcfgz", "gz", "kra", "krz", "psd", "psb", "psdt", "png", "jpg", "jpeg", "tif", "tiff", "tx", "webp", "gif", "bmp", "tga",
|
||||
"ico", "qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam", "pfm", "dds", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "iff", "lbm", "ilbm",
|
||||
"heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "asl", "svg", "svgz", "aco", "act", "ase", "af",
|
||||
"afdesign", "afphoto", "afpub",
|
||||
];
|
||||
const SVG_EXTS: &[&str] = &["svg", "svgz"];
|
||||
|
||||
@@ -32,6 +32,7 @@ photocraft-tablet = { workspace = true }
|
||||
# The framework facade: `craft::host` (Wake, window services), `craft::menu` (the macOS menu bar)
|
||||
# and `craft::automation` (the control server, the agent link and the launcher's agents switch).
|
||||
craft = { workspace = true, features = ["ui", "menu", "automation-agents", "control-agents"] }
|
||||
craft-nightly = { workspace = true }
|
||||
eframe = { workspace = true, features = ["wgpu", "accesskit", "wayland", "x11", "persistence", "clipboard"] }
|
||||
egui = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -1,31 +1,18 @@
|
||||
//! Build-time channel is distinct from a launch selector. A runtime environment cannot promote a stable build.
|
||||
use crate::launch_profile::Profile;
|
||||
use std::ffi::OsString;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum BuildFlavor {
|
||||
Stable,
|
||||
NightlyV1,
|
||||
}
|
||||
pub use craft_nightly::BuildFlavor;
|
||||
|
||||
pub const COMPILED: BuildFlavor = if cfg!(photocraft_nightly_v1) { BuildFlavor::NightlyV1 } else { BuildFlavor::Stable };
|
||||
|
||||
pub fn require_profile(flavor: BuildFlavor, profile: &Profile) -> Result<(), String> {
|
||||
match (flavor, profile.is_nightly()) {
|
||||
(BuildFlavor::NightlyV1, false) => Err("Open PhotoCraft Nightly from ArtCraft Launcher".into()),
|
||||
(BuildFlavor::Stable, true) => Err("This is a stable PhotoCraft build; nightly-v1 requires the nightly build".into()),
|
||||
_ => Ok(()),
|
||||
}
|
||||
/// The packaging/version probe must work even when no profile location can be resolved.
|
||||
pub fn version_query(args: &[std::ffi::OsString]) -> bool {
|
||||
matches!(args, [arg] if arg == "--version" || arg == "-V")
|
||||
}
|
||||
|
||||
pub fn needs_native_error(flavor: BuildFlavor, desktop_session: bool) -> bool {
|
||||
desktop_session && flavor == BuildFlavor::NightlyV1
|
||||
}
|
||||
|
||||
pub fn version_query(args: &[OsString]) -> bool {
|
||||
matches!(args, [arg] if arg == "--version" || arg == "-V")
|
||||
}
|
||||
|
||||
pub fn version(flavor: BuildFlavor, stable: &str) -> String {
|
||||
match flavor {
|
||||
BuildFlavor::Stable => stable.to_owned(),
|
||||
@@ -36,6 +23,23 @@ pub fn version(flavor: BuildFlavor, stable: &str) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::launch_profile;
|
||||
use craft_nightly::{Profile, ProfileError};
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn absolute_root() -> PathBuf {
|
||||
if cfg!(windows) { PathBuf::from(r"C:\NightlyData\profiles\photocraft") } else { PathBuf::from("/nightly-data/profiles/photocraft") }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_version_queries_are_unambiguous() {
|
||||
assert!(super::version_query(&["--version".into()]));
|
||||
assert!(super::version_query(&["-V".into()]));
|
||||
assert!(!super::version_query(&["--".into(), "--version".into()]));
|
||||
assert!(!super::version_query(&["--version".into(), "example".into()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_nightly_desktop_refusal_requests_a_native_dialog() {
|
||||
assert!(needs_native_error(BuildFlavor::NightlyV1, true));
|
||||
@@ -45,26 +49,46 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nightly_build_without_a_profile_is_refused_before_startup() {
|
||||
let started = std::cell::Cell::new(false);
|
||||
let result = require_profile(BuildFlavor::NightlyV1, &Profile::Stable).map(|()| started.set(true));
|
||||
assert!(result.unwrap_err().contains("ArtCraft Launcher"));
|
||||
assert!(!started.get());
|
||||
fn nightly_build_direct_launch_resolves_canonical_isolated_profile_root() {
|
||||
let spec = launch_profile::profile_spec_with_extra(Vec::new());
|
||||
let expected = craft_nightly::canonical_profile_root(spec.app_id).expect("canonical nightly profile root");
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, [OsString::from("photo.pcraft")], &launch_profile::startup_options())
|
||||
.expect("direct nightly launch should succeed");
|
||||
assert_eq!(launch.profile, Profile::NightlyV1(expected));
|
||||
assert!(launch.profile.is_nightly());
|
||||
assert_eq!(launch.passthrough_args, vec![OsString::from("photo.pcraft")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_and_nightly_flavors_accept_only_their_own_profile() {
|
||||
let nightly = Profile::NightlyV1(std::path::PathBuf::from("already validated root"));
|
||||
assert!(require_profile(BuildFlavor::Stable, &Profile::Stable).is_ok());
|
||||
assert!(require_profile(BuildFlavor::Stable, &nightly).is_err());
|
||||
assert!(require_profile(BuildFlavor::NightlyV1, &nightly).is_ok());
|
||||
let spec = launch_profile::profile_spec_with_extra(Vec::new());
|
||||
let options = launch_profile::startup_options();
|
||||
let root = absolute_root();
|
||||
let nightly_args = craft_nightly::launch_arguments(&root, &[]);
|
||||
|
||||
let stable = craft_nightly::parse_startup(BuildFlavor::Stable, &spec, Vec::new(), &options).expect("stable launch");
|
||||
assert_eq!(stable.profile, Profile::Stable);
|
||||
|
||||
let stable_with_nightly = craft_nightly::parse_startup(BuildFlavor::Stable, &spec, nightly_args.clone(), &options);
|
||||
assert!(matches!(stable_with_nightly, Err(ProfileError::NightlyFlagsInStableBuild)));
|
||||
|
||||
let nightly = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, nightly_args, &options).expect("nightly launch");
|
||||
assert_eq!(nightly.profile, Profile::NightlyV1(root));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nightly_version_query_is_unambiguous_and_never_reinterprets_file_arguments() {
|
||||
let spec = launch_profile::profile_spec_with_extra(Vec::new());
|
||||
let options = launch_profile::startup_options();
|
||||
assert_eq!(version(BuildFlavor::Stable, "0.23.1"), "0.23.1");
|
||||
assert_eq!(version(BuildFlavor::NightlyV1, "0.23.1"), "0.23.1 (nightly-v1)");
|
||||
assert!(version_query(&["--version".into()]));
|
||||
assert!(version_query(&["-V".into()]));
|
||||
assert!(!version_query(&["--".into(), "--version".into()]));
|
||||
assert!(!version_query(&[]));
|
||||
assert!(craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, [OsString::from("--version")], &options).unwrap().is_version_query());
|
||||
assert!(craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, [OsString::from("-V")], &options).unwrap().is_version_query());
|
||||
assert!(
|
||||
!craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, [OsString::from("--"), OsString::from("--version")], &options)
|
||||
.unwrap()
|
||||
.is_version_query()
|
||||
);
|
||||
assert!(!craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, Vec::new(), &options).unwrap().is_version_query());
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,10 @@ mod tests {
|
||||
let mut address = String::new();
|
||||
std::io::BufReader::new(child.stdout.take().unwrap()).read_line(&mut address).unwrap();
|
||||
let server = zbus::blocking::connection::Builder::address(address.trim()).unwrap().name("org.freedesktop.portal.Desktop").unwrap().build().unwrap();
|
||||
let client = zbus::blocking::connection::Builder::address(address.trim()).unwrap().method_timeout(Duration::from_secs(2)).build().unwrap();
|
||||
// The timeout only bounds a broken test. The fake portal answers OpenFile after reading
|
||||
// the shared file on its own thread; on a loaded CI pod that took over 2 s (run
|
||||
// 46849499194), so a short timeout failed a working call.
|
||||
let client = zbus::blocking::connection::Builder::address(address.trim()).unwrap().method_timeout(Duration::from_secs(60)).build().unwrap();
|
||||
(Bus(child), server, client)
|
||||
}
|
||||
|
||||
@@ -139,7 +142,8 @@ mod tests {
|
||||
panic!("OpenFile was not called");
|
||||
});
|
||||
let (_stop, stopped) = mpsc::channel();
|
||||
assert_eq!(open_on(&client, &owned, &stopped).is_ok(), code == 0);
|
||||
let opened = open_on(&client, &owned, &stopped);
|
||||
assert_eq!(opened.is_ok(), code == 0, "response {code}: {opened:?}");
|
||||
let _server = worker.join().unwrap();
|
||||
assert_eq!(std::fs::read(&owned.file).unwrap(), if code == 0 { b"<svg >" } else { b"<svg/>" });
|
||||
}
|
||||
|
||||
@@ -1,249 +1,223 @@
|
||||
//! Launcher-owned nightly-v1 bootstrap. Selected before logging, updates, fonts or saved state.
|
||||
//! Stable launches retain their original arguments and directory policy. No environment mutation.
|
||||
//! Nightly-v1 bootstrap backed by `craft-nightly`. Selected before logging, updates, fonts or
|
||||
//! saved state. Stable launches retain their original arguments and directory policy.
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::OnceLock;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const VERSION: &str = "nightly-v1";
|
||||
pub use craft_nightly::Profile;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Profile {
|
||||
Stable,
|
||||
NightlyV1(PathBuf),
|
||||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn is_nightly(&self) -> bool {
|
||||
matches!(self, Self::NightlyV1(_))
|
||||
}
|
||||
|
||||
pub fn root(&self) -> Option<&Path> {
|
||||
match self {
|
||||
Self::Stable => None,
|
||||
Self::NightlyV1(root) => Some(root),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Launch {
|
||||
pub profile: Profile,
|
||||
pub args: Vec<OsString>,
|
||||
}
|
||||
|
||||
static PROFILE: OnceLock<Profile> = OnceLock::new();
|
||||
const APP_ID: &str = "photocraft";
|
||||
const STABLE_DIR_NAMES: &[&str] = &["photocraft", "Photocraft", "PhotoCraft"];
|
||||
const FORBIDDEN_ENV_VARS: &[&str] = &["PHOTOCRAFT_CONFIG_DIR"];
|
||||
pub(crate) const FOLDER_ONLY_ENTRIES: &[&str] = &["Recovery", "AgentFiles", "Presets", "logs"];
|
||||
const LEADING_FLAGS: &[&str] = &["--safe-gpu"];
|
||||
|
||||
pub fn current() -> &'static Profile {
|
||||
PROFILE.get().unwrap_or(&Profile::Stable)
|
||||
craft_nightly::current().unwrap_or(&Profile::Stable)
|
||||
}
|
||||
|
||||
pub fn install(profile: Profile) -> Result<(), String> {
|
||||
PROFILE.set(profile).map_err(|_| "the launch profile was already selected".into())
|
||||
pub fn startup_options() -> craft_nightly::StartupOptions {
|
||||
craft_nightly::StartupOptions::with_leading_flags(LEADING_FLAGS)
|
||||
}
|
||||
|
||||
/// Recognize only the agreed literal selector/root pair before `--`. Everything after it is
|
||||
/// a file, even when it looks like a profile flag. No filesystem or startup hook runs here.
|
||||
pub fn parse(args: Vec<OsString>) -> Result<Launch, String> {
|
||||
let mut selector = None;
|
||||
let mut root = None;
|
||||
let mut other = Vec::new();
|
||||
let mut files = Vec::new();
|
||||
let mut iter = args.iter();
|
||||
let mut delimiter = false;
|
||||
while let Some(arg) = iter.next() {
|
||||
if arg == "--" {
|
||||
delimiter = true;
|
||||
files.extend(iter.cloned());
|
||||
break;
|
||||
pub fn profile_spec() -> craft_nightly::AppProfileSpec {
|
||||
let mut roots = extra_install_roots(|key| std::env::var_os(key));
|
||||
roots.extend(craft::control::agents::default_folder(crate::AGENT_APP_NAME));
|
||||
profile_spec_with_extra(roots)
|
||||
}
|
||||
|
||||
/// App-specific stable installation and platform state paths that were fenced by the prior
|
||||
/// PhotoCraft validator, in addition to the shared config/data/cache directory names.
|
||||
fn extra_install_roots(env: impl Fn(&str) -> Option<OsString>) -> Vec<PathBuf> {
|
||||
let absolute = |key: &str| env(key).map(PathBuf::from).filter(|path| path.is_absolute());
|
||||
let mut roots = Vec::new();
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if let Some(local) = absolute("LOCALAPPDATA") {
|
||||
roots.push(local.join("Programs/ArtCraft/PhotoCraft"));
|
||||
}
|
||||
if arg == "--launch-profile" || arg == "--profile-root" {
|
||||
let slot = if arg == "--launch-profile" { &mut selector } else { &mut root };
|
||||
if slot.is_some() {
|
||||
return Err("the profile selector and root must each occur exactly once".into());
|
||||
for key in ["ProgramW6432", "ProgramFiles", "ProgramFiles(x86)"] {
|
||||
if let Some(base) = absolute(key) {
|
||||
roots.push(base.join("ArtCraft/PhotoCraft"));
|
||||
}
|
||||
let value = iter.next().filter(|v| !v.is_empty()).ok_or("the profile selector/root needs a value")?;
|
||||
if value.to_string_lossy().starts_with("--") {
|
||||
return Err("the profile selector/root needs a value".into());
|
||||
}
|
||||
*slot = Some(value.clone());
|
||||
} else if arg.to_string_lossy().starts_with("--launch-profile=") || arg.to_string_lossy().starts_with("--profile-root=") {
|
||||
return Err("the nightly protocol requires separate literal selector/root argument tokens".into());
|
||||
} else {
|
||||
other.push(arg.clone());
|
||||
}
|
||||
}
|
||||
match (selector, root) {
|
||||
(None, None) => Ok(Launch { profile: Profile::Stable, args }),
|
||||
(Some(version), Some(root)) if version == VERSION => {
|
||||
if !delimiter || !other.is_empty() {
|
||||
return Err("nightly-v1 accepts only its selector/root followed by -- and file names".into());
|
||||
}
|
||||
let root = PathBuf::from(root);
|
||||
if !root.is_absolute() || root.components().any(|c| matches!(c, Component::ParentDir)) {
|
||||
return Err("the nightly profile root must be absolute and contain no parent traversal".into());
|
||||
}
|
||||
Ok(Launch { profile: Profile::NightlyV1(root), args: std::iter::once(OsString::from("--")).chain(files).collect() })
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
{
|
||||
roots.extend(["/usr/bin/photocraft", "/usr/local/bin/photocraft", "/opt/photocraft"].map(PathBuf::from));
|
||||
if let Some(home) = absolute("HOME") {
|
||||
roots.push(home.join(".var/app/ai.storyteller.photocraft"));
|
||||
}
|
||||
(Some(_), Some(_)) => Err("unsupported launch profile (expected nightly-v1)".into()),
|
||||
_ => Err("--launch-profile and --profile-root must be supplied together".into()),
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
roots.push(PathBuf::from("/Applications/PhotoCraft.app"));
|
||||
if let Some(home) = absolute("HOME") {
|
||||
roots.push(home.join("Applications/PhotoCraft.app"));
|
||||
roots.push(home.join("Library/Preferences/ai.storyteller.photocraft.plist"));
|
||||
roots.push(home.join("Library/Saved Application State/ai.storyteller.photocraft.savedState"));
|
||||
}
|
||||
}
|
||||
roots
|
||||
}
|
||||
|
||||
pub fn profile_spec_with_extra(extra_forbidden_roots: Vec<PathBuf>) -> craft_nightly::AppProfileSpec {
|
||||
craft_nightly::AppProfileSpec {
|
||||
app_id: APP_ID,
|
||||
display_name: "PhotoCraft",
|
||||
stable_dir_names: STABLE_DIR_NAMES,
|
||||
stable_package_id: "ai.storyteller.photocraft",
|
||||
nightly_package_id: "ai.storyteller.photocraft.nightly",
|
||||
profile_root_env: None,
|
||||
forbidden_env_vars: FORBIDDEN_ENV_VARS,
|
||||
portable_markers: &photocraft_automation::app_dirs::PORTABLE_MARKERS,
|
||||
folder_only_entries: FOLDER_ONLY_ENTRIES,
|
||||
extra_forbidden_roots,
|
||||
}
|
||||
}
|
||||
|
||||
/// The Launcher's version check: the selector/root pair followed by exactly `--version` (or `-V`),
|
||||
/// answered like a plain version query. Only [`parse`]'s lexical checks apply; the root is never
|
||||
/// validated or touched, and `-- --version` stays a file name.
|
||||
pub fn version_query(args: &[OsString]) -> bool {
|
||||
let Some((last, pair)) = args.split_last() else { return false };
|
||||
if last != "--version" && last != "-V" {
|
||||
return false;
|
||||
}
|
||||
let lexical = pair.iter().cloned().chain(std::iter::once(OsString::from("--"))).collect();
|
||||
matches!(parse(lexical), Ok(Launch { profile: Profile::NightlyV1(_), args }) if args.len() == 1)
|
||||
}
|
||||
|
||||
/// The existing renderer retry is signalled by its process-local failure marker. Ordinary
|
||||
/// Launcher calls still use the strict selector/root protocol; this is not authentication.
|
||||
pub fn parse_startup(args: Vec<OsString>, compatibility_retry: bool) -> Result<Launch, String> {
|
||||
if !compatibility_retry || args.first().is_none_or(|arg| arg != "--safe-gpu") {
|
||||
return parse(args);
|
||||
}
|
||||
let mut launch = parse(args[1..].to_vec())?;
|
||||
if launch.profile.is_nightly() {
|
||||
launch.args.insert(0, OsString::from("--safe-gpu"));
|
||||
Ok(launch)
|
||||
} else {
|
||||
// Stable's argument order and parser remain unchanged.
|
||||
parse(args)
|
||||
}
|
||||
}
|
||||
|
||||
/// Validation finishes before the caller's first startup effect. Stable never calls the nightly
|
||||
/// root validator, so its old portable/config resolution stays unchanged.
|
||||
pub fn prepare(mut launch: Launch, validate: impl FnOnce(&Path) -> Result<PathBuf, String>) -> Result<Launch, String> {
|
||||
if let Profile::NightlyV1(root) = &launch.profile {
|
||||
launch.profile = Profile::NightlyV1(validate(root)?);
|
||||
}
|
||||
Ok(launch)
|
||||
}
|
||||
|
||||
/// Resolve the selected private root before the caller's first startup effect.
|
||||
pub fn validate_root(root: &Path, env: impl Fn(&str) -> Option<OsString>, exe: Option<&Path>) -> Result<PathBuf, String> {
|
||||
let stable_agent = craft::control::agents::default_folder(crate::AGENT_APP_NAME);
|
||||
crate::profile_root::validate(root, env, exe, stable_agent.as_deref(), photocraft_automation::app_dirs::ensure_writable)
|
||||
pub fn app_args(launch: craft_nightly::Launch) -> Vec<OsString> {
|
||||
let mut args = launch.leading_flags;
|
||||
args.extend(launch.passthrough_args);
|
||||
args
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::cell::Cell;
|
||||
use craft_nightly::{BuildFlavor, NIGHTLY_V1_CONTRACT};
|
||||
use std::path::Path;
|
||||
|
||||
fn args(values: &[&str]) -> Vec<OsString> {
|
||||
values.iter().map(OsString::from).collect()
|
||||
}
|
||||
|
||||
fn absolute() -> &'static str {
|
||||
if cfg!(windows) { r"C:\NightlyData\profiles\photocraft" } else { "/nightly-data/profiles/photocraft" }
|
||||
}
|
||||
|
||||
fn nightly() -> Vec<OsString> {
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--"])
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photo_install_roots_retain_platform_specific_locations() {
|
||||
let base = PathBuf::from(absolute());
|
||||
let roots = extra_install_roots(|_| Some(base.clone().into_os_string()));
|
||||
#[cfg(windows)]
|
||||
{
|
||||
assert!(roots.contains(&base.join("Programs/ArtCraft/PhotoCraft")));
|
||||
assert!(roots.contains(&base.join("ArtCraft/PhotoCraft")));
|
||||
}
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
{
|
||||
assert!(roots.contains(&PathBuf::from("/opt/photocraft")));
|
||||
assert!(roots.contains(&base.join(".var/app/ai.storyteller.photocraft")));
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
assert!(roots.contains(&PathBuf::from("/Applications/PhotoCraft.app")));
|
||||
assert!(roots.contains(&base.join("Library/Preferences/ai.storyteller.photocraft.plist")));
|
||||
assert!(roots.contains(&base.join("Library/Saved Application State/ai.storyteller.photocraft.savedState")));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_cpu_retry_preserves_the_nightly_root_and_literal_files() {
|
||||
let spec = profile_spec_with_extra(Vec::new());
|
||||
let mut argv = args(&["--safe-gpu"]);
|
||||
argv.extend(nightly());
|
||||
argv.extend(args(&["document with spaces.psd", "--safe-gpu", "--profile-root"]));
|
||||
let launch = parse_startup(argv.clone(), true).unwrap();
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, argv.clone(), &startup_options()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::NightlyV1(PathBuf::from(absolute())));
|
||||
assert_eq!(launch.args, args(&["--safe-gpu", "--", "document with spaces.psd", "--safe-gpu", "--profile-root"]));
|
||||
assert!(parse_startup(argv, false).is_err(), "an ordinary invocation must not gain extra protocol flags");
|
||||
assert_eq!(launch.leading_flags, args(&["--safe-gpu"]));
|
||||
assert_eq!(launch.passthrough_args, args(&["document with spaces.psd", "--safe-gpu", "--profile-root"]));
|
||||
assert_eq!(app_args(launch), args(&["--safe-gpu", "document with spaces.psd", "--safe-gpu", "--profile-root"]));
|
||||
assert!(
|
||||
craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, argv, &craft_nightly::StartupOptions::default()).is_err(),
|
||||
"without leading flags configured, --safe-gpu before --launch-profile is rejected"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retry_cannot_bypass_invalid_profiles_or_change_stable_arguments() {
|
||||
let stable = args(&["--safe-gpu", "--new-instance", "stable.psd"]);
|
||||
assert_eq!(parse_startup(stable.clone(), true).unwrap(), Launch { profile: Profile::Stable, args: stable });
|
||||
let mut duplicate = args(&["--safe-gpu", "--safe-gpu"]);
|
||||
duplicate.extend(nightly());
|
||||
assert!(parse_startup(duplicate, true).is_err());
|
||||
assert!(parse_startup(args(&["--safe-gpu", "--launch-profile", VERSION, "--profile-root", "relative", "--"]), true).is_err());
|
||||
fn direct_nightly_launch_resolves_canonical_root_and_preserves_user_arguments() {
|
||||
let spec = profile_spec_with_extra(Vec::new());
|
||||
let expected = craft_nightly::canonical_profile_root(APP_ID).expect("canonical nightly root");
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, args(&["--safe-gpu", "document.psd"]), &startup_options()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::NightlyV1(expected));
|
||||
assert_eq!(app_args(launch), args(&["--safe-gpu", "document.psd"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_arguments_and_directory_policy_are_unchanged() {
|
||||
for argv in [args(&[]), args(&["--new-instance", "a.psd"]), args(&["--", "--launch-profile", "file.psd"])] {
|
||||
let launch = prepare(parse(argv.clone()).unwrap(), |_| panic!("stable must never validate a nightly root")).unwrap();
|
||||
assert_eq!(launch, Launch { profile: Profile::Stable, args: argv });
|
||||
let spec = profile_spec_with_extra(Vec::new());
|
||||
for argv in [
|
||||
args(&[]),
|
||||
args(&["--new-instance", "a.psd"]),
|
||||
args(&["--safe-gpu", "--new-instance", "stable.psd"]),
|
||||
args(&["--", "--launch-profile", "file.psd"]),
|
||||
] {
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::Stable, &spec, argv.clone(), &startup_options()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::Stable);
|
||||
assert_eq!(app_args(launch), argv);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_version_and_root_are_parsed_without_reinterpreting_file_names() {
|
||||
let spec = profile_spec_with_extra(Vec::new());
|
||||
let mut argv = nightly();
|
||||
argv.extend(args(&["--profile-root", "image with spaces.psd"]));
|
||||
let launch = parse(argv).unwrap();
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, argv, &startup_options()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::NightlyV1(PathBuf::from(absolute())));
|
||||
assert_eq!(launch.args, args(&["--", "--profile-root", "image with spaces.psd"]));
|
||||
assert_eq!(launch.passthrough_args, args(&["--profile-root", "image with spaces.psd"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_duplicate_unknown_and_conflicting_profile_arguments_are_refused() {
|
||||
fn missing_duplicate_and_unknown_profile_arguments_are_refused() {
|
||||
let spec = profile_spec_with_extra(Vec::new());
|
||||
for argv in [
|
||||
args(&["--launch-profile", VERSION]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT]),
|
||||
args(&["--profile-root", absolute()]),
|
||||
args(&["--launch-profile", "future-v2", "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", VERSION, "--launch-profile", VERSION, "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", "relative", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", "", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--new-instance", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute()]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", "", "--"]),
|
||||
] {
|
||||
assert!(parse(argv).is_err());
|
||||
assert!(craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, argv, &startup_options()).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_launcher_version_check_is_a_version_query_only_in_its_exact_form() {
|
||||
let pair = &["--launch-profile", VERSION, "--profile-root", absolute()];
|
||||
let reversed = &["--profile-root", absolute(), "--launch-profile", VERSION];
|
||||
fn the_launcher_version_check_is_recognized_as_a_version_query() {
|
||||
let spec = profile_spec_with_extra(Vec::new());
|
||||
let pair = &["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute()];
|
||||
let reversed = &["--profile-root", absolute(), "--launch-profile", NIGHTLY_V1_CONTRACT];
|
||||
for flag in ["--version", "-V"] {
|
||||
for form in [pair, reversed] {
|
||||
let mut argv = args(form);
|
||||
argv.push(flag.into());
|
||||
assert!(version_query(&argv), "{argv:?}");
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, argv.clone(), &startup_options()).unwrap();
|
||||
assert!(launch.is_version_query(), "{argv:?}");
|
||||
}
|
||||
let via_helper = craft_nightly::launch_arguments(Path::new(absolute()), &[OsString::from(flag)]);
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, via_helper, &startup_options()).unwrap();
|
||||
assert!(launch.is_version_query());
|
||||
}
|
||||
for argv in [
|
||||
args(&["--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--", "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--version", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--new-instance", "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--version", "--version"]),
|
||||
args(&["--version", "--launch-profile", VERSION, "--profile-root", absolute()]),
|
||||
args(&["--launch-profile", "future-v2", "--profile-root", absolute(), "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", "relative", "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--help"]),
|
||||
] {
|
||||
assert!(!version_query(&argv), "{argv:?}");
|
||||
}
|
||||
// Outside the query the strict protocol still refuses the version flag.
|
||||
assert!(parse(args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--version"])).is_err());
|
||||
let non_version = craft_nightly::launch_arguments(Path::new(absolute()), &[OsString::from("--help")]);
|
||||
let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, non_version, &startup_options()).unwrap();
|
||||
assert!(!launch.is_version_query());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_root_validation_never_reaches_startup_or_falls_back_to_stable() {
|
||||
let reached = Cell::new(false);
|
||||
let result = prepare(parse(nightly()).unwrap(), |_| Err("read-only or unsafe profile".into())).map(|_| reached.set(true));
|
||||
assert!(result.is_err());
|
||||
assert!(!reached.get());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn successful_root_validation_keeps_the_persistent_root_not_the_binary_tag() {
|
||||
let checked = PathBuf::from(absolute()).join("checked");
|
||||
let launch = prepare(parse(nightly()).unwrap(), |_| Ok(checked.clone())).unwrap();
|
||||
assert_eq!(launch.profile.root(), Some(checked.as_path()));
|
||||
assert!(launch.profile.is_nightly());
|
||||
fn photocraft_spec_preserves_required_fencing_configuration() {
|
||||
let agent = PathBuf::from(absolute()).join("stable-agent");
|
||||
let spec = profile_spec_with_extra(vec![agent.clone()]);
|
||||
assert_eq!(spec.app_id, "photocraft");
|
||||
assert_eq!(spec.stable_dir_names, &["photocraft", "Photocraft", "PhotoCraft"]);
|
||||
assert_eq!(spec.forbidden_env_vars, &["PHOTOCRAFT_CONFIG_DIR"]);
|
||||
assert_eq!(spec.portable_markers, &photocraft_automation::app_dirs::PORTABLE_MARKERS);
|
||||
assert_eq!(spec.folder_only_entries, &["Recovery", "AgentFiles", "Presets", "logs"]);
|
||||
assert_eq!(spec.extra_forbidden_roots, vec![agent]);
|
||||
}
|
||||
}
|
||||
@@ -258,6 +258,8 @@ fn claim_single_instance(
|
||||
// launch that sets only `PHOTOCRAFT_PRESENT_MODE` (say) has per-process options too, so it
|
||||
// keeps its own process instead of handing its files over and being ignored.
|
||||
launch_options.extend_from_slice(&single_instance::env_launch_options());
|
||||
// The CPU-compatibility relaunch's `--safe-gpu` is not a person's: it takes part.
|
||||
let launch_options = single_instance::without_relaunch_safe_gpu(launch_options, std::env::var_os("PHOTOCRAFT_GPU_STARTUP_FAILURE").as_deref());
|
||||
let context = single_instance::LaunchContext {
|
||||
per_user_settings: launch_profile::current().is_nightly() || app_dirs::current().mode == app_dirs::Mode::Platform,
|
||||
new_instance_flag: new_instance && !nightly,
|
||||
@@ -451,35 +453,38 @@ fn report_launch_profile_error(error: &str) {
|
||||
|
||||
/// Select the immutable launch profile before any startup service or side effect.
|
||||
fn prepare_launch() -> Option<Vec<std::ffi::OsString>> {
|
||||
// The trusted Launcher protocol is decided before logger/crash/update/font/prefs access.
|
||||
// The trusted Launcher protocol and direct nightly self-isolation are decided before
|
||||
// logger/crash/update/font/prefs access.
|
||||
let argv: Vec<_> = std::env::args_os().skip(1).collect();
|
||||
// Plain `--version`, or the Launcher's `--launch-profile nightly-v1 --profile-root <dir>
|
||||
// --version`: answered before root validation, process identity, IPC or any window.
|
||||
if build_flavor::COMPILED == build_flavor::BuildFlavor::NightlyV1 && (build_flavor::version_query(&argv) || launch_profile::version_query(&argv)) {
|
||||
if build_flavor::COMPILED == build_flavor::BuildFlavor::NightlyV1 && build_flavor::version_query(&argv) {
|
||||
use std::io::Write as _;
|
||||
let _ = writeln!(std::io::stdout(), "PhotoCraft {}", build_flavor::version(build_flavor::COMPILED, env!("PHOTOCRAFT_BUILT_VERSION")));
|
||||
return None;
|
||||
}
|
||||
let early = launch_profile::parse_startup(argv, std::env::var_os("PHOTOCRAFT_GPU_STARTUP_FAILURE").is_some())
|
||||
.and_then(|launch| {
|
||||
build_flavor::require_profile(build_flavor::COMPILED, &launch.profile)?;
|
||||
initialize_nightly_process_identity().map_err(|error| error.to_string())?;
|
||||
Ok(launch)
|
||||
})
|
||||
.and_then(|launch| {
|
||||
launch_profile::prepare(launch, |root| launch_profile::validate_root(root, |key| std::env::var_os(key), std::env::current_exe().ok().as_deref()))
|
||||
})
|
||||
.unwrap_or_else(|error| {
|
||||
report_launch_profile_error(&error);
|
||||
std::process::exit(2)
|
||||
});
|
||||
let spec = launch_profile::profile_spec();
|
||||
let options = launch_profile::startup_options();
|
||||
let early = craft_nightly::prepare_launch(build_flavor::COMPILED, &spec, argv, &options).unwrap_or_else(|error| {
|
||||
report_launch_profile_error(&error.to_string());
|
||||
std::process::exit(2)
|
||||
});
|
||||
// Plain `--version`, or the Launcher's `--launch-profile nightly-v1 --profile-root <dir>
|
||||
// --version`: answered before process identity, IPC or any window.
|
||||
if build_flavor::COMPILED == build_flavor::BuildFlavor::NightlyV1 && early.is_version_query() {
|
||||
use std::io::Write as _;
|
||||
let _ = writeln!(std::io::stdout(), "PhotoCraft {}", build_flavor::version(build_flavor::COMPILED, env!("PHOTOCRAFT_BUILT_VERSION")));
|
||||
return None;
|
||||
}
|
||||
if let Err(error) = initialize_nightly_process_identity() {
|
||||
report_launch_profile_error(&error.to_string());
|
||||
std::process::exit(2);
|
||||
}
|
||||
let identity = if early.profile.is_nightly() { os_window::LaunchIdentity::NightlyV1 } else { os_window::LaunchIdentity::Stable };
|
||||
if let Err(error) = launch_profile::install(early.profile).and_then(|()| os_window::select_identity(identity)) {
|
||||
if let Err(error) = os_window::select_identity(identity) {
|
||||
report_launch_profile_error(&error);
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
Some(early.args)
|
||||
Some(launch_profile::app_args(early))
|
||||
}
|
||||
|
||||
/// The allocator on Windows: mimalloc instead of the system heap. The UI builds and frees many small values every
|
||||
|
||||
@@ -1,32 +1,7 @@
|
||||
//! App-owned nightly profile fences; no stable fallback, migration or process environment changes.
|
||||
//! App-specific nightly profile helpers. The core nightly profile fence lives in `craft-nightly`.
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
use photocraft_automation::app_dirs::{PORTABLE_DATA_DIR, portable_marker};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Platform {
|
||||
Windows,
|
||||
Linux,
|
||||
Mac,
|
||||
}
|
||||
|
||||
impl Platform {
|
||||
fn current() -> Result<Self, String> {
|
||||
match std::env::consts::OS {
|
||||
"windows" => Ok(Self::Windows),
|
||||
"linux" => Ok(Self::Linux),
|
||||
"macos" => Ok(Self::Mac),
|
||||
_ => Err("nightly-v1 is not defined for this operating system".into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn ignores_case(self) -> bool {
|
||||
self != Self::Linux
|
||||
}
|
||||
}
|
||||
|
||||
fn absolute(path: PathBuf, label: &str) -> Result<PathBuf, String> {
|
||||
if !path.is_absolute() || path.components().any(|c| matches!(c, Component::ParentDir)) {
|
||||
return Err(format!("{label} must be absolute and contain no parent traversal"));
|
||||
@@ -34,18 +9,6 @@ fn absolute(path: PathBuf, label: &str) -> Result<PathBuf, String> {
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn required_base(env: &impl Fn(&str) -> Option<OsString>, key: &str) -> Result<PathBuf, String> {
|
||||
let value = env(key).filter(|v| !v.is_empty()).ok_or_else(|| format!("cannot establish the stable {key} boundary"))?;
|
||||
absolute(PathBuf::from(value), key)
|
||||
}
|
||||
|
||||
fn xdg_base(env: &impl Fn(&str) -> Option<OsString>, key: &str, fallback: &str) -> Result<PathBuf, String> {
|
||||
match env(key).filter(|v| !v.is_empty()) {
|
||||
Some(value) => absolute(PathBuf::from(value), key),
|
||||
None => Ok(required_base(env, "HOME")?.join(fallback)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve existing ancestors before creating anything. A dangling link or inaccessible ancestor
|
||||
/// is not a missing directory that may be replaced or followed later.
|
||||
fn canonical_future(path: &Path) -> Result<PathBuf, String> {
|
||||
@@ -68,73 +31,19 @@ fn canonical_future(path: &Path) -> Result<PathBuf, String> {
|
||||
Ok(resolved)
|
||||
}
|
||||
|
||||
fn overlaps(a: &Path, b: &Path, platform: Platform) -> bool {
|
||||
let parts = |p: &Path| {
|
||||
p.components()
|
||||
.map(|c| {
|
||||
let value = c.as_os_str().to_string_lossy().into_owned();
|
||||
if platform.ignores_case() { value.to_lowercase() } else { value }
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let (a, b) = (parts(a), parts(b));
|
||||
a.starts_with(&b) || b.starts_with(&a)
|
||||
}
|
||||
|
||||
fn installation_boundary(platform: Platform, exe: &Path) -> Result<PathBuf, String> {
|
||||
let parent = exe.parent().ok_or("cannot establish the installation boundary")?;
|
||||
if platform == Platform::Mac {
|
||||
// A profile in Resources is still inside the versioned install, not beside MacOS.
|
||||
if let Some(bundle) = exe.ancestors().find(|p| p.extension().is_some_and(|ext| ext.eq_ignore_ascii_case("app"))) {
|
||||
return Ok(bundle.to_path_buf());
|
||||
}
|
||||
fn private_subdirectory(root: &Path, name: impl AsRef<Path>, label: &str) -> Result<PathBuf, String> {
|
||||
let chosen = canonical_future(&absolute(root.to_path_buf(), "the nightly profile root")?)?;
|
||||
let child = canonical_future(&chosen.join(name))?;
|
||||
if child == chosen || !child.starts_with(&chosen) {
|
||||
return Err(format!("the nightly {label} must stay inside its selected profile"));
|
||||
}
|
||||
Ok(parent.to_path_buf())
|
||||
}
|
||||
|
||||
fn forbidden_roots(platform: Platform, env: &impl Fn(&str) -> Option<OsString>, exe: &Path) -> Result<Vec<PathBuf>, String> {
|
||||
let mut roots = match platform {
|
||||
Platform::Windows => {
|
||||
let mut roots =
|
||||
["APPDATA", "LOCALAPPDATA"].into_iter().map(|key| required_base(env, key).map(|p| p.join("Photocraft"))).collect::<Result<Vec<_>, _>>()?;
|
||||
// The MSI's default per-user and per-machine folders (install-policy.wxi). A custom
|
||||
// install folder is not known here; the executable's own folder is fenced below.
|
||||
roots.push(required_base(env, "LOCALAPPDATA")?.join("Programs").join("ArtCraft").join("PhotoCraft"));
|
||||
for key in ["ProgramW6432", "ProgramFiles", "ProgramFiles(x86)"] {
|
||||
if let Some(base) = env(key).filter(|v| !v.is_empty()) {
|
||||
roots.push(absolute(PathBuf::from(base), key)?.join("ArtCraft").join("PhotoCraft"));
|
||||
}
|
||||
}
|
||||
roots
|
||||
}
|
||||
Platform::Linux => {
|
||||
let mut roots =
|
||||
[("XDG_CONFIG_HOME", ".config"), ("XDG_DATA_HOME", ".local/share"), ("XDG_CACHE_HOME", ".cache"), ("XDG_STATE_HOME", ".local/state")]
|
||||
.into_iter()
|
||||
.map(|(key, fallback)| xdg_base(env, key, fallback).map(|p| p.join("photocraft")))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
roots.extend(["/usr/bin/photocraft", "/usr/local/bin/photocraft", "/opt/photocraft"].map(PathBuf::from));
|
||||
// The stable Flatpak keeps its data in its own per-app folder.
|
||||
roots.push(required_base(env, "HOME")?.join(".var/app/ai.storyteller.photocraft"));
|
||||
roots
|
||||
}
|
||||
Platform::Mac => {
|
||||
let home = required_base(env, "HOME")?;
|
||||
let library = home.join("Library");
|
||||
vec![
|
||||
library.join("Application Support/Photocraft"),
|
||||
library.join("Caches/Photocraft"),
|
||||
library.join("Caches/ai.storyteller.photocraft"),
|
||||
library.join("Preferences/Photocraft"),
|
||||
library.join("Preferences/ai.storyteller.photocraft.plist"),
|
||||
library.join("Saved Application State/ai.storyteller.photocraft.savedState"),
|
||||
home.join("Applications/PhotoCraft.app"),
|
||||
PathBuf::from("/Applications/PhotoCraft.app"),
|
||||
]
|
||||
}
|
||||
};
|
||||
roots.push(installation_boundary(platform, exe)?);
|
||||
roots.into_iter().map(|p| canonical_future(&p)).collect()
|
||||
match std::fs::symlink_metadata(&child) {
|
||||
Ok(metadata) if !metadata.is_dir() => return Err(format!("the nightly {label} must be a directory")),
|
||||
Ok(_) => {}
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
|
||||
Err(error) => return Err(format!("cannot inspect the nightly {label}: {error}")),
|
||||
}
|
||||
Ok(child)
|
||||
}
|
||||
|
||||
/// The nightly fallback for files made by agents. Resolving it never creates a directory and
|
||||
@@ -144,123 +53,15 @@ pub fn agent_directory(root: &Path) -> Result<PathBuf, String> {
|
||||
private_subdirectory(root, "AgentFiles", "default agent folder")
|
||||
}
|
||||
|
||||
fn private_subdirectory(root: &Path, name: impl AsRef<Path>, label: &str) -> Result<PathBuf, String> {
|
||||
let chosen = canonical_future(&absolute(root.to_path_buf(), "the nightly profile root")?)?;
|
||||
let child = canonical_future(&chosen.join(name))?;
|
||||
if child == chosen || !child.starts_with(&chosen) {
|
||||
return Err(format!("the nightly {label} must stay inside its selected profile"));
|
||||
}
|
||||
Ok(child)
|
||||
}
|
||||
|
||||
/// Every existing entry directly in the profile (Presets, logs, settings and so on) must resolve
|
||||
/// inside it, so a link there cannot point Nightly's writes at another app's data.
|
||||
fn entries_stay_inside(root: &Path) -> Result<(), String> {
|
||||
let entries = match std::fs::read_dir(root) {
|
||||
Ok(entries) => entries,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(()),
|
||||
Err(error) => return Err(format!("cannot inspect the nightly profile: {error}")),
|
||||
};
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|e| format!("cannot inspect the nightly profile: {e}"))?;
|
||||
private_subdirectory(root, entry.file_name(), "profile entry")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Recognise the shared portable data namespace in both the supplied and resolved path.
|
||||
/// This is not an inventory of arbitrary custom Stable overrides or a Launcher ownership proof.
|
||||
fn is_portable_layout(path: &Path, platform: Platform) -> bool {
|
||||
// A folder under a portable copy belongs to that copy too. Above the chosen folder itself, a
|
||||
// marker only counts beside a PhotoCraft executable, so an unrelated portable.txt higher up
|
||||
// (in a user folder or at a drive root) does not refuse the profile.
|
||||
path.ancestors().enumerate().any(|(depth, ancestor)| {
|
||||
portable_marker(ancestor).is_some() && (depth == 0 || ["photocraft.exe", "photocraft"].iter().any(|exe| ancestor.join(exe).is_file()))
|
||||
}) || path.components().any(|component| match component {
|
||||
Component::Normal(name) if platform.ignores_case() => name.to_string_lossy().eq_ignore_ascii_case(PORTABLE_DATA_DIR),
|
||||
Component::Normal(name) => name == PORTABLE_DATA_DIR,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
/// The writable hook is the app's existing exclusive probe. Keeping it injected lets filesystem
|
||||
/// boundary tests exercise the real policy without starting the app or changing global state.
|
||||
pub fn validate(
|
||||
root: &Path,
|
||||
env: impl Fn(&str) -> Option<OsString>,
|
||||
exe: Option<&Path>,
|
||||
stable_agent: Option<&Path>,
|
||||
writable: impl FnOnce(&Path) -> std::io::Result<()>,
|
||||
) -> Result<PathBuf, String> {
|
||||
validate_for(Platform::current()?, root, env, exe, stable_agent, writable)
|
||||
}
|
||||
|
||||
fn validate_for(
|
||||
platform: Platform,
|
||||
root: &Path,
|
||||
env: impl Fn(&str) -> Option<OsString>,
|
||||
exe: Option<&Path>,
|
||||
stable_agent: Option<&Path>,
|
||||
writable: impl FnOnce(&Path) -> std::io::Result<()>,
|
||||
) -> Result<PathBuf, String> {
|
||||
absolute(root.to_path_buf(), "the nightly profile root")?;
|
||||
if env("PHOTOCRAFT_CONFIG_DIR").is_some_and(|v| !v.is_empty()) {
|
||||
return Err("nightly-v1 cannot be combined with PHOTOCRAFT_CONFIG_DIR".into());
|
||||
}
|
||||
if platform != Platform::Windows && env("FLATPAK_ID").is_some_and(|v| !v.is_empty()) {
|
||||
// These rows are native tar/app-bundle launches, not a Flatpak package. Inheriting its
|
||||
// runtime socket namespace could point another profile at the stable app's socket.
|
||||
return Err("nightly-v1 native packages cannot inherit a Flatpak instance; launch through the native Launcher".into());
|
||||
}
|
||||
let chosen = canonical_future(root)?;
|
||||
if is_portable_layout(root, platform) || is_portable_layout(&chosen, platform) {
|
||||
return Err("the nightly root must not use a portable PhotoCraft installation or its PhotoCraftData settings folder".into());
|
||||
}
|
||||
let exe = absolute(exe.ok_or("cannot establish the installation boundary")?.to_path_buf(), "the executable")?;
|
||||
let mut forbidden = forbidden_roots(platform, &env, &exe)?;
|
||||
if let Some(agent) = stable_agent {
|
||||
// Use the SDK-resolved Documents/known-folder location, including redirected Documents.
|
||||
// Do not reconstruct it from HOME or create it just to establish the boundary.
|
||||
forbidden.push(canonical_future(&absolute(agent.to_path_buf(), "the stable default agent folder")?)?);
|
||||
}
|
||||
if forbidden.iter().any(|stable| overlaps(&chosen, stable, platform)) {
|
||||
return Err("the nightly root must not overlap stable data or an installation".into());
|
||||
}
|
||||
// Existing aliases under the profile must not redirect the default agent workspace elsewhere.
|
||||
agent_directory(&chosen)?;
|
||||
entries_stay_inside(&chosen)?;
|
||||
// Recovery can read, adopt, overwrite and sweep entries. Never let its alias leave this
|
||||
// private profile, including toward a Stable portable directory not in our known roots.
|
||||
private_subdirectory(&chosen, "Recovery", "recovery folder")?;
|
||||
let mut create = std::fs::DirBuilder::new();
|
||||
create.recursive(true);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::DirBuilderExt as _;
|
||||
create.mode(0o700);
|
||||
}
|
||||
create.create(&chosen).map_err(|e| format!("cannot create the nightly profile: {e}"))?;
|
||||
let confirmed = std::fs::canonicalize(&chosen).map_err(|e| format!("cannot resolve the created nightly profile: {e}"))?;
|
||||
if confirmed != chosen || forbidden.iter().any(|stable| overlaps(&confirmed, stable, platform)) {
|
||||
return Err("the nightly profile changed while it was being validated".into());
|
||||
}
|
||||
agent_directory(&confirmed)?;
|
||||
private_subdirectory(&confirmed, "Recovery", "recovery folder")?;
|
||||
entries_stay_inside(&confirmed)?;
|
||||
writable(&confirmed).map_err(|e| format!("the nightly profile is not writable: {e}"))?;
|
||||
Ok(confirmed)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::BTreeMap;
|
||||
use crate::launch_profile;
|
||||
use craft_nightly::ProfileError;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
struct Fixture {
|
||||
root: PathBuf,
|
||||
env: BTreeMap<String, OsString>,
|
||||
exe: PathBuf,
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
@@ -274,136 +75,24 @@ mod tests {
|
||||
Err(error) => panic!("cannot create owned fixture: {error}"),
|
||||
}
|
||||
};
|
||||
let home = root.join("home");
|
||||
let exe = root.join("install/photocraft");
|
||||
std::fs::create_dir_all(&home).unwrap();
|
||||
std::fs::create_dir_all(exe.parent().unwrap()).unwrap();
|
||||
std::fs::write(&exe, b"fixture executable, never run").unwrap();
|
||||
let env = [("HOME", home), ("APPDATA", root.join("roaming")), ("LOCALAPPDATA", root.join("local"))]
|
||||
.into_iter()
|
||||
.map(|(key, value)| (key.into(), value.into_os_string()))
|
||||
.collect();
|
||||
Self { root, env, exe }
|
||||
}
|
||||
|
||||
fn get(&self, key: &str) -> Option<OsString> {
|
||||
self.env.get(key).cloned()
|
||||
}
|
||||
|
||||
fn check(&self, platform: Platform, root: &Path) -> Result<PathBuf, String> {
|
||||
validate_for(
|
||||
platform,
|
||||
root,
|
||||
|key| self.get(key),
|
||||
Some(&self.exe),
|
||||
None,
|
||||
|dir| {
|
||||
let probe = dir.join("exclusive-test-probe");
|
||||
let file = std::fs::OpenOptions::new().write(true).create_new(true).open(&probe)?;
|
||||
drop(file);
|
||||
std::fs::remove_file(probe)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn home(&self) -> PathBuf {
|
||||
PathBuf::from(self.get("HOME").unwrap())
|
||||
Self { root }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Fixture {
|
||||
fn drop(&mut self) {
|
||||
// Only the directory successfully created by this fixture is owned for removal.
|
||||
std::fs::remove_dir_all(&self.root).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn portable_settings_from_another_install_are_refused_before_any_probe() {
|
||||
let fixture = Fixture::new();
|
||||
let stable_install = fixture.root.join("stable portable install");
|
||||
let stable_data = stable_install.join(photocraft_automation::app_dirs::PORTABLE_DATA_DIR);
|
||||
std::fs::create_dir_all(&stable_data).unwrap();
|
||||
std::fs::write(stable_install.join("portable.txt"), b"owned portable fixture").unwrap();
|
||||
std::fs::write(stable_data.join("settings.json"), b"stable settings must not change").unwrap();
|
||||
for platform in [Platform::Windows, Platform::Linux, Platform::Mac] {
|
||||
for candidate in [&stable_data, &stable_data.join("nested nightly")] {
|
||||
let probed = std::cell::Cell::new(false);
|
||||
let result = validate_for(
|
||||
platform,
|
||||
candidate,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
None,
|
||||
|_| {
|
||||
probed.set(true);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
assert!(result.is_err(), "a different portable install is not a private Nightly profile");
|
||||
assert!(!probed.get(), "reject portable data before a writable probe");
|
||||
assert!(!stable_data.join("nested nightly").exists());
|
||||
assert_eq!(std::fs::read(stable_data.join("settings.json")).unwrap(), b"stable settings must not change");
|
||||
assert_eq!(std::fs::read_dir(&stable_data).unwrap().count(), 1);
|
||||
}
|
||||
}
|
||||
let private = fixture.root.join("PhotoCraftData-backup-name/nightly");
|
||||
assert!(fixture.check(Platform::Linux, &private).is_ok(), "a merely similar name is not a portable settings component");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn recovery_aliases_cannot_redirect_to_stable_missing_or_profile_root_data() {
|
||||
let fixture = Fixture::new();
|
||||
let stable = fixture.home().join(".local/state/photocraft/Recovery");
|
||||
std::fs::create_dir_all(&stable).unwrap();
|
||||
std::fs::write(stable.join("stable-autosave"), b"stable recovery bytes").unwrap();
|
||||
for (index, target) in [stable.clone(), fixture.root.join("missing recovery target")].into_iter().enumerate() {
|
||||
let private = fixture.root.join(format!("nightly-{index}"));
|
||||
std::fs::create_dir(&private).unwrap();
|
||||
std::os::unix::fs::symlink(&target, private.join("Recovery")).unwrap();
|
||||
let probed = std::cell::Cell::new(false);
|
||||
let result = validate_for(
|
||||
Platform::Linux,
|
||||
&private,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
None,
|
||||
|_| {
|
||||
probed.set(true);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
assert!(result.is_err(), "Recovery must not escape the private profile or follow a dangling alias");
|
||||
assert!(!probed.get());
|
||||
}
|
||||
let private = fixture.root.join("nightly-self");
|
||||
std::fs::create_dir(&private).unwrap();
|
||||
std::os::unix::fs::symlink(&private, private.join("Recovery")).unwrap();
|
||||
assert!(fixture.check(Platform::Linux, &private).is_err(), "Recovery cannot treat all profile settings as recovery entries");
|
||||
assert_eq!(std::fs::read(stable.join("stable-autosave")).unwrap(), b"stable recovery bytes");
|
||||
assert_eq!(std::fs::read_dir(stable).unwrap().count(), 1);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn recovery_alias_to_a_private_subfolder_keeps_the_profile_usable() {
|
||||
let fixture = Fixture::new();
|
||||
let private = fixture.root.join("nightly-private");
|
||||
let recovery = private.join("private-recovery");
|
||||
std::fs::create_dir_all(&recovery).unwrap();
|
||||
std::os::unix::fs::symlink(&recovery, private.join("Recovery")).unwrap();
|
||||
assert!(fixture.check(Platform::Linux, &private).is_ok());
|
||||
assert_eq!(std::fs::canonicalize(private.join("Recovery")).unwrap(), recovery);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn agent_default_is_private_lazy_and_preserves_stable_documents() {
|
||||
let fixture = Fixture::new();
|
||||
let stable = fixture.home().join("Documents/ArtCraft/Agents/PhotoCraft");
|
||||
let stable = fixture.root.join("Documents/ArtCraft/Agents/PhotoCraft");
|
||||
std::fs::create_dir_all(&stable).unwrap();
|
||||
std::fs::write(stable.join("existing-document"), b"stable document bytes").unwrap();
|
||||
let private = fixture.check(Platform::Linux, &fixture.home().join("nightly-profile")).unwrap();
|
||||
let spec = launch_profile::profile_spec_with_extra(vec![stable.clone()]);
|
||||
let private = craft_nightly::validate_and_prepare_root(&fixture.root.join("nightly-profile"), &spec).unwrap();
|
||||
let agent = agent_directory(&private).unwrap();
|
||||
assert!(agent.starts_with(&private) && agent != private);
|
||||
assert!(!agent.exists(), "resolving the fallback must not create it before use");
|
||||
@@ -415,29 +104,15 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_agent_known_folder_and_overlaps_refuse_before_writable_probe() {
|
||||
fn stable_agent_known_folder_and_overlaps_refuse() {
|
||||
let fixture = Fixture::new();
|
||||
// Models redirected Documents/known folders: not assumed to be beneath HOME.
|
||||
let stable = fixture.root.join("redirected documents/ArtCraft/Agents/PhotoCraft");
|
||||
std::fs::create_dir_all(&stable).unwrap();
|
||||
std::fs::write(stable.join("existing-document"), b"stable document bytes").unwrap();
|
||||
for platform in [Platform::Windows, Platform::Linux, Platform::Mac] {
|
||||
for root in [stable.clone(), stable.join("nightly"), stable.parent().unwrap().to_path_buf()] {
|
||||
let calls = std::cell::Cell::new(0);
|
||||
let result = validate_for(
|
||||
platform,
|
||||
&root,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
Some(&stable),
|
||||
|_| {
|
||||
calls.set(calls.get() + 1);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
assert!(result.unwrap_err().contains("overlap"));
|
||||
assert_eq!(calls.get(), 0);
|
||||
}
|
||||
let spec = launch_profile::profile_spec_with_extra(vec![stable.clone()]);
|
||||
for root in [stable.clone(), stable.join("nightly"), stable.parent().unwrap().to_path_buf()] {
|
||||
let result = craft_nightly::validate_and_prepare_root(&root, &spec);
|
||||
assert!(matches!(result, Err(ProfileError::ForbiddenRootOverlap { .. })), "{root:?}: {result:?}");
|
||||
}
|
||||
assert_eq!(std::fs::read(stable.join("existing-document")).unwrap(), b"stable document bytes");
|
||||
assert_eq!(std::fs::read_dir(&stable).unwrap().count(), 1);
|
||||
@@ -447,31 +122,17 @@ mod tests {
|
||||
#[cfg(unix)]
|
||||
fn agent_default_rejects_existing_and_dangling_escape_aliases_before_writes() {
|
||||
let fixture = Fixture::new();
|
||||
let private = fixture.home().join("nightly-profile");
|
||||
let outside = fixture.home().join("stable-agent-files");
|
||||
let private = fixture.root.join("nightly-profile");
|
||||
let outside = fixture.root.join("stable-agent-files");
|
||||
std::fs::create_dir_all(&private).unwrap();
|
||||
std::fs::create_dir_all(&outside).unwrap();
|
||||
std::fs::write(outside.join("existing-document"), b"stable document bytes").unwrap();
|
||||
let spec = launch_profile::profile_spec_with_extra(vec![outside.clone()]);
|
||||
for target in [&outside, &outside.join("missing")] {
|
||||
let alias = private.join("AgentFiles");
|
||||
std::os::unix::fs::symlink(target, &alias).unwrap();
|
||||
assert!(agent_directory(&private).is_err());
|
||||
let calls = std::cell::Cell::new(0);
|
||||
assert!(
|
||||
validate_for(
|
||||
Platform::Linux,
|
||||
&private,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
Some(&outside),
|
||||
|_| {
|
||||
calls.set(calls.get() + 1);
|
||||
Ok(())
|
||||
}
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(calls.get(), 0);
|
||||
assert!(craft_nightly::validate_and_prepare_root(&private, &spec).is_err());
|
||||
assert_eq!(std::fs::read_dir(&outside).unwrap().count(), 1);
|
||||
std::fs::remove_file(alias).unwrap();
|
||||
}
|
||||
@@ -479,230 +140,41 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlap_check_handles_ancestor_descendant_and_prefix_lookalikes() {
|
||||
fn failed_profile_preparation_does_not_start_with_stable() {
|
||||
let fixture = Fixture::new();
|
||||
let root = fixture.home().join("nightly/profiles/photocraft");
|
||||
for platform in [Platform::Windows, Platform::Linux, Platform::Mac] {
|
||||
assert!(overlaps(&root, &root.join("Recovery"), platform));
|
||||
assert!(overlaps(&root.join("Recovery"), &root, platform));
|
||||
assert!(!overlaps(&root, &root.with_file_name("photocraft-other"), platform));
|
||||
}
|
||||
let root = fixture.root.join("not-a-directory");
|
||||
std::fs::write(&root, b"an ordinary file").unwrap();
|
||||
let argv = craft_nightly::launch_arguments(&root, &[]);
|
||||
let spec = launch_profile::profile_spec_with_extra(Vec::new());
|
||||
let result = craft_nightly::prepare_launch(craft_nightly::BuildFlavor::NightlyV1, &spec, argv, &launch_profile::startup_options());
|
||||
assert!(matches!(result, Err(ProfileError::NotADirectory(_))));
|
||||
assert_eq!(std::fs::read(&root).unwrap(), b"an ordinary file");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_fences_app_xdg_subtrees_but_allows_launcher_sibling() {
|
||||
let mut fixture = Fixture::new();
|
||||
for key in ["XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_STATE_HOME"] {
|
||||
fixture.env.insert(key.into(), fixture.root.join(key).into_os_string());
|
||||
}
|
||||
for key in ["XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_STATE_HOME"] {
|
||||
let stable = PathBuf::from(fixture.get(key).unwrap()).join("photocraft");
|
||||
std::fs::create_dir_all(&stable).unwrap();
|
||||
std::fs::write(stable.join("stable-sentinel"), b"stable bytes").unwrap();
|
||||
for candidate in [stable.clone(), stable.join("nightly"), stable.parent().unwrap().to_path_buf()] {
|
||||
assert!(fixture.check(Platform::Linux, &candidate).unwrap_err().contains("overlap"));
|
||||
}
|
||||
assert_eq!(std::fs::read(stable.join("stable-sentinel")).unwrap(), b"stable bytes");
|
||||
}
|
||||
let data = PathBuf::from(fixture.get("XDG_DATA_HOME").unwrap());
|
||||
let nightly = data.join("ArtCraftLauncher/nightly/profiles/photocraft");
|
||||
assert_eq!(fixture.check(Platform::Linux, &nightly).unwrap(), nightly);
|
||||
assert_eq!(std::fs::read_dir(nightly).unwrap().count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mac_fences_only_app_library_subtrees_and_the_entire_bundle() {
|
||||
let mut fixture = Fixture::new();
|
||||
fixture.exe = fixture.root.join("install/PhotoCraft Nightly.app/Contents/MacOS/PhotoCraft");
|
||||
std::fs::create_dir_all(fixture.exe.parent().unwrap()).unwrap();
|
||||
std::fs::write(&fixture.exe, b"fixture executable, never run").unwrap();
|
||||
let library = fixture.home().join("Library");
|
||||
for suffix in [
|
||||
"Application Support/Photocraft",
|
||||
"Caches/Photocraft",
|
||||
"Caches/ai.storyteller.photocraft",
|
||||
"Preferences/Photocraft",
|
||||
"Saved Application State/ai.storyteller.photocraft.savedState",
|
||||
] {
|
||||
let stable = library.join(suffix);
|
||||
assert!(fixture.check(Platform::Mac, &stable.join("nightly")).unwrap_err().contains("overlap"));
|
||||
assert!(!stable.exists());
|
||||
}
|
||||
let inside_resources = fixture.exe.parent().unwrap().parent().unwrap().join("Resources/profile");
|
||||
assert!(fixture.check(Platform::Mac, &inside_resources).unwrap_err().contains("overlap"));
|
||||
assert!(!inside_resources.exists());
|
||||
let valid = library.join("Application Support/ArtCraftLauncher/nightly/profiles/photocraft");
|
||||
assert_eq!(fixture.check(Platform::Mac, &valid).unwrap(), valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_roaming_local_and_install_fences_remain_active() {
|
||||
fn nightly_profile_reopens_after_saving_settings_and_session_state() {
|
||||
let fixture = Fixture::new();
|
||||
for key in ["APPDATA", "LOCALAPPDATA"] {
|
||||
let stable = PathBuf::from(fixture.get(key).unwrap()).join("Photocraft");
|
||||
assert!(fixture.check(Platform::Windows, &stable.join("nightly")).unwrap_err().contains("overlap"));
|
||||
assert!(!stable.exists());
|
||||
let spec = launch_profile::profile_spec_with_extra(Vec::new());
|
||||
let private = fixture.root.join("nightly-reopen");
|
||||
assert_eq!(craft_nightly::validate_and_prepare_root(&private, &spec).unwrap(), private);
|
||||
for name in ["ui.ron", "settings.json", "nightly-session.lock", "nightly-session.json"] {
|
||||
std::fs::write(private.join(name), b"saved profile data").unwrap();
|
||||
}
|
||||
assert!(fixture.check(Platform::Windows, &fixture.exe.parent().unwrap().join("profile")).is_err());
|
||||
assert!(fixture.check(Platform::Windows, &fixture.root.join("Launcher/profiles/photocraft")).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_default_msi_install_folders_are_fenced() {
|
||||
let mut fixture = Fixture::new();
|
||||
let local = PathBuf::from(fixture.get("LOCALAPPDATA").unwrap());
|
||||
let per_user = local.join("Programs").join("ArtCraft").join("PhotoCraft");
|
||||
assert!(fixture.check(Platform::Windows, &per_user.join("nightly")).unwrap_err().contains("overlap"));
|
||||
for key in ["ProgramW6432", "ProgramFiles", "ProgramFiles(x86)"] {
|
||||
let base = fixture.root.join(format!("machine {key}"));
|
||||
fixture.env.insert(key.into(), base.clone().into_os_string());
|
||||
let machine = base.join("ArtCraft").join("PhotoCraft");
|
||||
assert!(fixture.check(Platform::Windows, &machine.join("nightly")).unwrap_err().contains("overlap"));
|
||||
assert!(!machine.exists());
|
||||
for name in launch_profile::FOLDER_ONLY_ENTRIES {
|
||||
std::fs::create_dir(private.join(name)).unwrap();
|
||||
}
|
||||
let sibling = local.join("Programs").join("ArtCraft").join("ArtCraftLauncher").join("nightly").join("photocraft");
|
||||
assert!(fixture.check(Platform::Windows, &sibling).is_ok(), "the Launcher's own Programs sibling is not PhotoCraft's install");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folders_under_a_stable_portable_copy_are_refused_before_any_probe() {
|
||||
let fixture = Fixture::new();
|
||||
let portable = fixture.root.join("D/PC");
|
||||
std::fs::create_dir_all(&portable).unwrap();
|
||||
std::fs::write(portable.join("portable.txt"), b"stable portable copy").unwrap();
|
||||
std::fs::write(portable.join("photocraft.exe"), b"stable portable executable, never run").unwrap();
|
||||
for platform in [Platform::Windows, Platform::Linux, Platform::Mac] {
|
||||
for candidate in [portable.join("nightly"), portable.join("deeper/nightly")] {
|
||||
let probed = std::cell::Cell::new(false);
|
||||
let result = validate_for(
|
||||
platform,
|
||||
&candidate,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
None,
|
||||
|_| {
|
||||
probed.set(true);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
assert!(result.unwrap_err().contains("portable"));
|
||||
assert!(!probed.get());
|
||||
assert!(!candidate.exists());
|
||||
}
|
||||
}
|
||||
// A portable.txt that no PhotoCraft executable sits beside is someone else's file.
|
||||
let unrelated = fixture.root.join("user folder");
|
||||
std::fs::create_dir_all(&unrelated).unwrap();
|
||||
std::fs::write(unrelated.join("portable.txt"), b"another app's marker").unwrap();
|
||||
assert!(fixture.check(Platform::Windows, &unrelated.join("Launcher/nightly/photocraft")).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_fences_the_stable_flatpak_data_folder() {
|
||||
let fixture = Fixture::new();
|
||||
let flatpak = fixture.home().join(".var/app/ai.storyteller.photocraft");
|
||||
for candidate in [flatpak.clone(), flatpak.join("data/nightly")] {
|
||||
assert!(fixture.check(Platform::Linux, &candidate).unwrap_err().contains("overlap"));
|
||||
}
|
||||
assert!(!flatpak.exists());
|
||||
assert!(fixture.check(Platform::Linux, &fixture.home().join(".var/app/ai.storyteller.launcher/nightly")).is_ok());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn any_profile_entry_alias_must_stay_inside_the_profile() {
|
||||
let fixture = Fixture::new();
|
||||
let stable = fixture.home().join(".config/photocraft/Presets");
|
||||
std::fs::create_dir_all(&stable).unwrap();
|
||||
std::fs::write(stable.join("stable-preset"), b"stable preset bytes").unwrap();
|
||||
for name in ["Presets", "logs", "settings.json"] {
|
||||
let private = fixture.root.join(format!("nightly-{name}"));
|
||||
std::fs::create_dir(&private).unwrap();
|
||||
std::os::unix::fs::symlink(&stable, private.join(name)).unwrap();
|
||||
let probed = std::cell::Cell::new(false);
|
||||
let result = validate_for(
|
||||
Platform::Linux,
|
||||
&private,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
None,
|
||||
|_| {
|
||||
probed.set(true);
|
||||
Ok(())
|
||||
},
|
||||
assert_eq!(craft_nightly::validate_and_prepare_root(&private, &spec).unwrap(), private);
|
||||
assert_eq!(std::fs::read(private.join("ui.ron")).unwrap(), b"saved profile data");
|
||||
for name in launch_profile::FOLDER_ONLY_ENTRIES {
|
||||
let path = private.join(name);
|
||||
std::fs::remove_dir(&path).unwrap();
|
||||
std::fs::write(&path, b"not a directory").unwrap();
|
||||
assert!(
|
||||
matches!(craft_nightly::validate_and_prepare_root(&private, &spec), Err(ProfileError::ExpectedDirectoryEntry(_))),
|
||||
"{name} must stay a directory"
|
||||
);
|
||||
assert!(result.is_err(), "{name} must not lead outside the profile");
|
||||
assert!(!probed.get());
|
||||
std::fs::remove_file(&path).unwrap();
|
||||
std::fs::create_dir(&path).unwrap();
|
||||
}
|
||||
let private = fixture.root.join("nightly-inside");
|
||||
std::fs::create_dir_all(private.join("real-presets")).unwrap();
|
||||
std::fs::write(private.join("settings.json"), b"{}").unwrap();
|
||||
std::os::unix::fs::symlink(private.join("real-presets"), private.join("Presets")).unwrap();
|
||||
assert!(fixture.check(Platform::Linux, &private).is_ok(), "regular files and links that stay inside are fine");
|
||||
assert_eq!(std::fs::read(stable.join("stable-preset")).unwrap(), b"stable preset bytes");
|
||||
assert_eq!(std::fs::read_dir(&stable).unwrap().count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ambiguous_environment_and_non_native_sandbox_are_refused_before_creation() {
|
||||
let mut fixture = Fixture::new();
|
||||
let candidate = fixture.home().join("nightly/profiles/photocraft");
|
||||
fixture.env.insert("XDG_CACHE_HOME".into(), "relative/cache".into());
|
||||
assert!(fixture.check(Platform::Linux, &candidate).unwrap_err().contains("absolute"));
|
||||
fixture.env.remove("XDG_CACHE_HOME");
|
||||
fixture.env.insert("PHOTOCRAFT_CONFIG_DIR".into(), fixture.home().join("custom-stable").into_os_string());
|
||||
assert!(fixture.check(Platform::Linux, &candidate).unwrap_err().contains("PHOTOCRAFT_CONFIG_DIR"));
|
||||
fixture.env.remove("PHOTOCRAFT_CONFIG_DIR");
|
||||
fixture.env.insert("FLATPAK_ID".into(), "ai.storyteller.photocraft".into());
|
||||
assert!(fixture.check(Platform::Linux, &candidate).unwrap_err().contains("Flatpak"));
|
||||
fixture.env.remove("FLATPAK_ID");
|
||||
fixture.env.remove("HOME");
|
||||
assert!(fixture.check(Platform::Linux, &candidate).unwrap_err().contains("HOME"));
|
||||
assert!(!candidate.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_directory_and_failed_write_probe_never_fall_back_to_stable() {
|
||||
let fixture = Fixture::new();
|
||||
let file = fixture.home().join("not-a-directory");
|
||||
std::fs::write(&file, b"do not replace me").unwrap();
|
||||
assert!(fixture.check(Platform::Linux, &file).is_err());
|
||||
assert_eq!(std::fs::read(file).unwrap(), b"do not replace me");
|
||||
let candidate = fixture.home().join("nightly");
|
||||
let calls = std::cell::Cell::new(0);
|
||||
let result = validate_for(
|
||||
Platform::Linux,
|
||||
&candidate,
|
||||
|key| fixture.get(key),
|
||||
Some(&fixture.exe),
|
||||
None,
|
||||
|_| {
|
||||
calls.set(calls.get() + 1);
|
||||
Err(std::io::Error::new(std::io::ErrorKind::PermissionDenied, "injected write refusal"))
|
||||
},
|
||||
);
|
||||
assert!(result.unwrap_err().contains("not writable"));
|
||||
assert_eq!(calls.get(), 1);
|
||||
assert!(!fixture.home().join(".config/photocraft").exists());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn symlink_and_dangling_aliases_cannot_create_or_modify_stable_data() {
|
||||
use std::os::unix::fs::symlink;
|
||||
let fixture = Fixture::new();
|
||||
let stable = fixture.home().join(".config/photocraft");
|
||||
std::fs::create_dir_all(&stable).unwrap();
|
||||
std::fs::write(stable.join("sentinel"), b"untouched").unwrap();
|
||||
let alias = fixture.home().join("alias");
|
||||
symlink(&stable, &alias).unwrap();
|
||||
assert!(fixture.check(Platform::Linux, &alias.join("nightly")).unwrap_err().contains("overlap"));
|
||||
let missing = fixture.home().join("missing-target");
|
||||
let dangling = fixture.home().join("dangling");
|
||||
symlink(&missing, &dangling).unwrap();
|
||||
assert!(fixture.check(Platform::Linux, &dangling.join("nightly")).is_err());
|
||||
assert!(!missing.exists());
|
||||
assert!(!stable.join("nightly").exists());
|
||||
assert_eq!(std::fs::read(stable.join("sentinel")).unwrap(), b"untouched");
|
||||
}
|
||||
}
|
||||
@@ -101,8 +101,8 @@ fn recovery_dir() -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
/// Write `bytes` crash-safely (temp file beside the target, fsync, rename, directory fsync; see
|
||||
/// [`photocraft_format::atomic`]). Every document write (Save, Save As, Export, Save for Web) and
|
||||
/// the preferences go through here, so a failed or interrupted save never destroys the old file.
|
||||
/// [`photocraft_format::atomic`]). Save, Save As, overwriting exports and preferences use this so
|
||||
/// a failed or interrupted write never destroys the old file.
|
||||
fn write_atomic(path: &Path, bytes: &[u8]) -> Result<(), String> {
|
||||
photocraft_format::atomic_write(path, bytes).map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -602,6 +602,7 @@ pub fn native(automation: Option<photocraft_automation::AuthorizedWorkspace>, wa
|
||||
file_panels: Some(file_panels),
|
||||
settings: Some(settings_store()),
|
||||
write: Some(Box::new(|path: &str, bytes: &[u8]| write_atomic(Path::new(path), bytes))),
|
||||
write_new: Some(Box::new(|path, bytes| photocraft_format::write_noreplace(Path::new(path), bytes).map_err(|e| format!("{path}: {e}")))),
|
||||
file_stamp: Some(Box::new(|path: &str| {
|
||||
// Follows a symlink, as Save writes through it to the file it points at.
|
||||
let meta = std::fs::metadata(path).ok()?;
|
||||
|
||||
@@ -29,9 +29,7 @@ use std::io::{BufReader, Read, Write};
|
||||
use std::net::{Ipv4Addr, SocketAddr, TcpListener, TcpStream};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::path::Path;
|
||||
#[cfg(unix)]
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::{SyncSender, sync_channel};
|
||||
use std::sync::{Arc, Mutex, PoisonError};
|
||||
@@ -181,6 +179,22 @@ fn env_launch_options_from(get: impl Fn(&str) -> Option<std::ffi::OsString>) ->
|
||||
ENV_LAUNCH_OPTIONS.iter().filter(|(name, _, is_on)| get(name).is_some_and(|v| is_on(&v.to_string_lossy()))).map(|(_, option, _)| *option).collect()
|
||||
}
|
||||
|
||||
/// Whether `--safe-gpu` keeps a launch out of single-instance. It does when a person passes it, but
|
||||
/// not for the CPU-compatibility relaunch (which sets `PHOTOCRAFT_GPU_STARTUP_FAILURE`): that one
|
||||
/// takes the place of a launch that has already shut its instance down.
|
||||
pub fn safe_gpu_is_launch_option(gpu_startup_failure: Option<&std::ffi::OsStr>) -> bool {
|
||||
gpu_startup_failure.is_none()
|
||||
}
|
||||
|
||||
/// `options` without the `--safe-gpu` the CPU-compatibility relaunch adds; a person's stays
|
||||
/// ([`safe_gpu_is_launch_option`]). Every other option is kept.
|
||||
pub fn without_relaunch_safe_gpu(mut options: Vec<PerProcess>, gpu_startup_failure: Option<&std::ffi::OsStr>) -> Vec<PerProcess> {
|
||||
if !safe_gpu_is_launch_option(gpu_startup_failure) {
|
||||
options.retain(|option| *option != PerProcess::SafeGpu);
|
||||
}
|
||||
options
|
||||
}
|
||||
|
||||
/// Why this launch runs as its own instance, or `None` to take part in single-instance.
|
||||
pub fn skip_reason(c: &LaunchContext) -> Option<String> {
|
||||
if !c.per_user_settings {
|
||||
@@ -210,6 +224,8 @@ pub struct Primary {
|
||||
/// then, so the second call (`Drop`) can't remove the socket the next primary has bound.
|
||||
#[cfg(unix)]
|
||||
socket: Mutex<Option<PathBuf>>,
|
||||
/// Where `instance.json` is, removed on [`Primary::shutdown`].
|
||||
dir: PathBuf,
|
||||
}
|
||||
|
||||
struct Shared {
|
||||
@@ -255,7 +271,13 @@ impl Primary {
|
||||
if let Some(path) = self.socket.lock().unwrap_or_else(PoisonError::into_inner).take() {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
drop(self.lock.lock().unwrap_or_else(PoisonError::into_inner).take());
|
||||
let mut lock = self.lock.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
if let Some(file) = lock.take() {
|
||||
// Before the lock goes, so the file can only be ours: a later launch never reads an
|
||||
// endpoint that has since been freed (or taken by another program).
|
||||
remove_info(&self.dir);
|
||||
drop(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,11 +346,11 @@ pub fn claim_with(dir: &Path, paths: &[String], timing: Timing) -> Launch {
|
||||
/// once a quitting or crashed primary is gone) and then the running primary, wherever
|
||||
/// `instance.json` says it listens.
|
||||
pub fn claim_in(dir: &Path, paths: &[String], timing: Timing, transport: &Transport) -> Launch {
|
||||
if let Err(e) = std::fs::create_dir_all(dir) {
|
||||
if let Err(e) = create_private_dir(dir) {
|
||||
return Launch::Standalone(format!("{}: {e}", dir.display()));
|
||||
}
|
||||
let lock_path = dir.join(LOCK_FILE);
|
||||
let lock = match OpenOptions::new().read(true).write(true).create(true).truncate(false).open(&lock_path) {
|
||||
let lock = match open_lock(&lock_path) {
|
||||
Ok(lock) => lock,
|
||||
Err(e) => return Launch::Standalone(format!("{}: {e}", lock_path.display())),
|
||||
};
|
||||
@@ -407,9 +429,39 @@ fn serve(dir: &Path, lock: File, timing: Timing, transport: &Transport) -> Resul
|
||||
shared,
|
||||
#[cfg(unix)]
|
||||
socket: Mutex::new(socket),
|
||||
dir: dir.to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
/// The settings folder, the user's alone (0700) on Unix when this is the first to create it.
|
||||
fn create_private_dir(dir: &Path) -> std::io::Result<()> {
|
||||
let mut builder = std::fs::DirBuilder::new();
|
||||
builder.recursive(true);
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::DirBuilderExt::mode(&mut builder, 0o700);
|
||||
builder.create(dir)
|
||||
}
|
||||
|
||||
/// `instance.lock`, the user's alone (0600) on Unix: another local user who could open it could
|
||||
/// hold the lock, and every launch would then wait out its hand-off time and start on its own.
|
||||
fn open_lock(path: &Path) -> std::io::Result<File> {
|
||||
let mut options = OpenOptions::new();
|
||||
options.read(true).write(true).create(true).truncate(false);
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o600);
|
||||
let lock = options.open(path)?;
|
||||
// The mode applies only on create: narrow a lock file an earlier version left readable.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let wide = lock.metadata().is_ok_and(|m| m.permissions().mode() & 0o077 != 0);
|
||||
if wide && let Err(e) = lock.set_permissions(std::fs::Permissions::from_mode(0o600)) {
|
||||
log::warn!("{}: couldn't make it private: {e}", path.display());
|
||||
}
|
||||
}
|
||||
Ok(lock)
|
||||
}
|
||||
|
||||
/// The primary's listener on either transport.
|
||||
enum Listener {
|
||||
Tcp(TcpListener),
|
||||
@@ -574,6 +626,15 @@ fn write_info(dir: &Path, endpoint: &Endpoint, token: &str) -> Result<(), String
|
||||
})
|
||||
}
|
||||
|
||||
/// Remove `instance.json` if this process wrote it.
|
||||
fn remove_info(dir: &Path) {
|
||||
let path = dir.join(INFO_FILE);
|
||||
let pid = std::fs::read(&path).ok().and_then(|b| serde_json::from_slice::<Value>(&b).ok()).and_then(|v| v.get("pid")?.as_u64());
|
||||
if pid == Some(u64::from(std::process::id())) {
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_info(dir: &Path) -> Option<(Endpoint, String)> {
|
||||
let v: Value = serde_json::from_slice(&std::fs::read(dir.join(INFO_FILE)).ok()?).ok()?;
|
||||
let token = v.get("token")?.as_str()?.to_string();
|
||||
|
||||
@@ -133,9 +133,10 @@ fn a_launch_waiting_on_a_closing_instance_takes_over() {
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
primary.shutdown();
|
||||
assert!(matches!(waiting.join().unwrap(), Launch::Primary(_)), "the waiting launch becomes the primary");
|
||||
// After shutdown new connections are refused too.
|
||||
let Launch::Primary(next) = waiting.join().unwrap() else { panic!("the waiting launch becomes the primary") };
|
||||
// After shutdown new connections are refused too. (Read before the drop, which removes the file.)
|
||||
let (endpoint, token) = read_info(&dir).unwrap();
|
||||
drop(next);
|
||||
drop(primary);
|
||||
let short = Instant::now() + Duration::from_millis(300);
|
||||
assert!(send(&endpoint, &token, &["b.psd".into()], short).is_err());
|
||||
@@ -227,6 +228,82 @@ fn the_token_file_is_private_to_the_user() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Follow-up to #3755, point 1: another local user can't open the lock, so can't hold it.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn the_lock_file_and_a_new_settings_folder_are_private_to_the_user() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let mode = |p: &Path| std::fs::metadata(p).unwrap().permissions().mode() & 0o777;
|
||||
let dir = temp_dir("lock-mode").join("photocraft");
|
||||
let first = primary(&dir);
|
||||
assert_eq!((mode(&dir), mode(&dir.join(LOCK_FILE))), (0o700, 0o600));
|
||||
drop(first);
|
||||
// A lock file an earlier version created 0644 is narrowed on the next start.
|
||||
std::fs::set_permissions(dir.join(LOCK_FILE), std::fs::Permissions::from_mode(0o644)).unwrap();
|
||||
let second = primary(&dir);
|
||||
assert_eq!(mode(&dir.join(LOCK_FILE)), 0o600);
|
||||
drop(second);
|
||||
let _ = std::fs::remove_dir_all(dir.parent().unwrap());
|
||||
}
|
||||
|
||||
/// Follow-up to #3755, point 3: a primary that shuts down takes its `instance.json` with it,
|
||||
/// and a second `shutdown` (the drop) leaves the next primary's alone.
|
||||
#[test]
|
||||
fn shutdown_removes_the_instance_file_but_not_the_next_ones() {
|
||||
let dir = temp_dir("info-cleanup");
|
||||
let first = primary(&dir);
|
||||
assert!(read_info(&dir).is_some());
|
||||
first.shutdown();
|
||||
assert!(read_info(&dir).is_none(), "no endpoint left behind for a later launch");
|
||||
let second = primary(&dir);
|
||||
let port = port_of(&dir);
|
||||
drop(first);
|
||||
assert_eq!(port_of(&dir), port, "the running primary's file stays");
|
||||
drop(second);
|
||||
assert!(read_info(&dir).is_none());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Follow-up to #3755, point 2: the CPU-compatibility relaunch takes part in single-instance;
|
||||
/// `--safe-gpu` given by a person still gets its own process.
|
||||
#[test]
|
||||
fn the_cpu_relaunch_takes_part_in_single_instance() {
|
||||
assert!(safe_gpu_is_launch_option(None));
|
||||
assert!(!safe_gpu_is_launch_option(Some(std::ffi::OsStr::new("wgpu: no adapter"))));
|
||||
// The relaunch sets the reason even when it is empty.
|
||||
assert!(!safe_gpu_is_launch_option(Some(std::ffi::OsStr::new(""))));
|
||||
}
|
||||
|
||||
/// The filtering `claim_single_instance` applies, through to `skip_reason`: the relaunch's own
|
||||
/// `--safe-gpu` takes part, a person's stays separate, and the relaunch keeps any other option.
|
||||
#[test]
|
||||
fn the_cpu_relaunch_filter_decides_who_takes_part() {
|
||||
let check = |options: &[PerProcess], failure: Option<&str>| {
|
||||
let launch_options = without_relaunch_safe_gpu(options.to_vec(), failure.map(std::ffi::OsStr::new));
|
||||
let context = LaunchContext {
|
||||
per_user_settings: true,
|
||||
new_instance_flag: false,
|
||||
new_instance_env: None,
|
||||
control: false,
|
||||
unreadable_paths: false,
|
||||
launch_options: &launch_options,
|
||||
};
|
||||
(launch_options.clone(), skip_reason(&context))
|
||||
};
|
||||
// The CPU relaunch with no other options takes part, whatever its reason says.
|
||||
for failure in ["wgpu: no adapter", ""] {
|
||||
assert_eq!(check(&[PerProcess::SafeGpu], Some(failure)), (vec![], None));
|
||||
}
|
||||
// A person's `--safe-gpu` keeps its own process.
|
||||
let (kept, reason) = check(&[PerProcess::SafeGpu], None);
|
||||
assert_eq!(kept, [PerProcess::SafeGpu]);
|
||||
assert!(reason.is_some());
|
||||
// The relaunch drops only its own `--safe-gpu`: another option still keeps it separate.
|
||||
let (kept, reason) = check(&[PerProcess::SafeGpu, PerProcess::GpuAdapterEnv], Some("wgpu: no adapter"));
|
||||
assert_eq!(kept, [PerProcess::GpuAdapterEnv]);
|
||||
assert!(reason.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unreachable_instance_falls_back_to_a_standalone_launch() {
|
||||
let dir = temp_dir("unreachable");
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M3 9h18" />
|
||||
<path d="M9 4v5" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 306 B |
@@ -0,0 +1,15 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M12 4v16" />
|
||||
<path d="M3 12h18" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 309 B |
@@ -0,0 +1,16 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M9 4v16" />
|
||||
<path d="M15 4v16" />
|
||||
<path d="M3 12h18" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 332 B |
@@ -0,0 +1,15 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M3 9.33h18" />
|
||||
<path d="M3 14.67h18" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 314 B |
@@ -0,0 +1,15 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M12 4v16" />
|
||||
<path d="M12 12h9" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 309 B |
@@ -0,0 +1,15 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M9 4v16" />
|
||||
<path d="M15 4v16" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 308 B |
@@ -0,0 +1,16 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M3 8h18" />
|
||||
<path d="M3 12h18" />
|
||||
<path d="M3 16h18" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 332 B |
@@ -0,0 +1,16 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M7.5 4v16" />
|
||||
<path d="M12 4v16" />
|
||||
<path d="M16.5 4v16" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 336 B |
@@ -0,0 +1,14 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M3 12h18" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 285 B |
@@ -0,0 +1,14 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M12 4v16" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 285 B |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<defs>
|
||||
<!-- The toolbar tints the alpha mask: reveal its background at left and the icon colour at right. -->
|
||||
<linearGradient id="ramp" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0" stop-color="#000" stop-opacity="0"/>
|
||||
<stop offset="1" stop-color="#000"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="3" y="5" width="18" height="14" rx="2" fill="url(#ramp)" stroke="#000" stroke-width="2"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 485 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M6 3h12a4 4 0 0 1 4 4v10a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V7a4 4 0 0 1 4-4Zm6 3-6 6 6 6 6-6-6-6Z" fill-rule="evenodd" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 239 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="3" y="4" width="18" height="16" rx="3" />
|
||||
<path d="m12 7 1.5 1.5m2 2 1.5 1.5-1.5 1.5m-2 2L12 17l-1.5-1.5m-2-2L7 12l1.5-1.5m2-2L12 7" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 338 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round">
|
||||
<rect x="3" y="4" width="18" height="16" rx="3" />
|
||||
<path d="m12 7 5 5-5 5-5-5Z" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 287 B |
@@ -0,0 +1,17 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M12 6V5a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v1" />
|
||||
<path d="M16.5 5v15" />
|
||||
<path d="M14 20h5" />
|
||||
<path d="M5 8v9" />
|
||||
<path d="M2.5 14.5 5 17l2.5-2.5" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 373 B |
@@ -306,6 +306,9 @@ sync_github_name = false
|
||||
real_name = "Jason DeBoever"
|
||||
sync_github_name = true
|
||||
|
||||
[people.yadser]
|
||||
real_name = "Sergey Yadryshnikov"
|
||||
|
||||
[people.dylanmtaylor]
|
||||
sync_github_name = true
|
||||
|
||||
@@ -329,6 +332,9 @@ sync_github_name = false
|
||||
real_name = "David Vanhoucke"
|
||||
sync_github_name = true
|
||||
|
||||
[people.kobaltgit]
|
||||
sync_github_name = true
|
||||
|
||||
[people.Luis-0508]
|
||||
sync_github_name = true
|
||||
|
||||
@@ -356,5 +362,13 @@ real_name = "Sven Lafebre"
|
||||
[people.kirubhakaran12]
|
||||
sync_github_name = true
|
||||
|
||||
[people.qvest-ssels]
|
||||
real_name = "Stefan Sels"
|
||||
display_name = "tronicum"
|
||||
sync_github_name = false
|
||||
|
||||
[people.MMexicann]
|
||||
display_name = "mexicann"
|
||||
|
||||
[people.webglobepl]
|
||||
real_name = "Maciej Malinowski"
|
||||
@@ -585,17 +585,16 @@ fn dab_intersects(dab: &Dab, tile: (i32, i32, i32, i32)) -> bool {
|
||||
/// Radius, in pixels, of the neighbourhood around a stroke's start that Tolerance measures.
|
||||
const START_RADIUS: f32 = 2.5;
|
||||
|
||||
/// Difference, in working-space units, that 100 % Tolerance asks for. The reference application
|
||||
/// starts strokes on a 20-level change (about 8 %) at Tolerance 10 but not 20, and on red over grey
|
||||
/// (about 50 %) at 80 but not 90, which a linear threshold of `0.6 × Tolerance` reproduces.
|
||||
/// Keep the existing alpha threshold in working-space units. Colour distances use this same
|
||||
/// scale, so their threshold is equivalent to Euclidean distance greater than Tolerance.
|
||||
const TOLERANCE_SCALE: f32 = 0.6;
|
||||
|
||||
/// Mean difference between `src` and `dest` around the dab's centre, where its stroke starts
|
||||
/// (working-space peak is 1). Per pixel it is the larger of the mean colour change and the alpha
|
||||
/// change: an opaque pixel's unchanged alpha must not water a colour change down, and the Eraser
|
||||
/// keeps the colour and lowers only the alpha. Fully transparent source samples are left out; a
|
||||
/// start whose samples are all transparent has a mean of `0.0`. `None` if nothing is there.
|
||||
fn start_diff(p: &StampParams<'_>, dab: &Dab) -> Option<f32> {
|
||||
/// (working-space peak is 1). Per pixel it is the larger of the scaled Euclidean colour distance
|
||||
/// and the alpha change. The flag records whether colour contributes to the mean, requiring a
|
||||
/// strict threshold while alpha-only changes keep their inclusive threshold. Fully transparent
|
||||
/// source samples are left out; an entirely transparent start has a mean of `0.0`.
|
||||
fn start_diff(p: &StampParams<'_>, dab: &Dab) -> Option<(f32, bool)> {
|
||||
if !(dab.x.is_finite() && dab.y.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
@@ -604,9 +603,11 @@ fn start_diff(p: &StampParams<'_>, dab: &Dab) -> Option<f32> {
|
||||
let x1 = floor_i32(dab.x + START_RADIUS).saturating_add(1);
|
||||
let y1 = floor_i32(dab.y + START_RADIUS).saturating_add(1);
|
||||
let mut sampled = vec![0.0f32; p.ch];
|
||||
let mut sum = 0.0f32;
|
||||
// Avoid summation drift turning equal per-pixel distances into a larger neighbourhood mean.
|
||||
let mut sum = 0.0f64;
|
||||
let mut count = 0u32;
|
||||
let mut transparent = 0u32;
|
||||
let mut colour_contributes = false;
|
||||
for y in y0..y1 {
|
||||
for x in x0..x1 {
|
||||
// The history state at the same position, not the dab's rotated read.
|
||||
@@ -627,27 +628,27 @@ fn start_diff(p: &StampParams<'_>, dab: &Dab) -> Option<f32> {
|
||||
transparent = transparent.saturating_add(1);
|
||||
continue;
|
||||
}
|
||||
let (mut colour, mut colours, mut alpha) = (0.0f32, 0u32, 0.0f32);
|
||||
let (mut colour, mut alpha) = (0.0f32, 0.0f32);
|
||||
for i in 0..nch {
|
||||
let Some((&s, &d)) = sampled.get(i).zip(dst.get(i)) else { continue };
|
||||
if p.alpha == Some(i) {
|
||||
alpha = (s - d).abs();
|
||||
} else {
|
||||
colour += (s - d).abs();
|
||||
colours += 1;
|
||||
colour += (s - d) * (s - d);
|
||||
}
|
||||
}
|
||||
let colour = if colours == 0 { 0.0 } else { colour / colours as f32 };
|
||||
sum += colour.max(alpha);
|
||||
let colour = colour.sqrt() * TOLERANCE_SCALE;
|
||||
colour_contributes |= colour > alpha;
|
||||
sum += f64::from(colour.max(alpha));
|
||||
count = count.saturating_add(1);
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
// Stamping a fully transparent sample leaves the pixel as it is.
|
||||
return (transparent > 0).then_some(0.0);
|
||||
return (transparent > 0).then_some((0.0, false));
|
||||
}
|
||||
let mean = sum / count as f32;
|
||||
mean.is_finite().then_some(mean)
|
||||
let mean = (sum / f64::from(count)) as f32;
|
||||
mean.is_finite().then_some((mean, colour_contributes))
|
||||
}
|
||||
|
||||
/// Stamp posed dabs into `dest`, tile by tile, reading `src` at each dab's rotated positions.
|
||||
@@ -674,7 +675,7 @@ pub fn stamp(p: &mut StampParams<'_>) -> Result<u32, StampError> {
|
||||
let threshold = p.tolerance * TOLERANCE_SCALE;
|
||||
for dab in &dabs {
|
||||
let Some(bounds) = dab_bounds(dab) else { continue };
|
||||
if p.tolerance > 0.0 && start_diff(p, dab).is_some_and(|m| m < threshold) {
|
||||
if p.tolerance > 0.0 && start_diff(p, dab).is_some_and(|(m, colour)| m < threshold || (colour && m == threshold)) {
|
||||
continue;
|
||||
}
|
||||
let overlapping: Vec<(i32, i32, i32, i32)> = tiles.iter().copied().filter(|t| dab_intersects(dab, *t)).collect();
|
||||
@@ -696,4 +697,6 @@ pub fn stamp(p: &mut StampParams<'_>) -> Result<u32, StampError> {
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(test)]
|
||||
mod tolerance_distance_tests;
|
||||
#[cfg(test)]
|
||||
mod tolerance_tests;
|
||||
@@ -0,0 +1,83 @@
|
||||
//! #18227: per-stroke Tolerance measures Euclidean colour distance.
|
||||
|
||||
use super::*;
|
||||
|
||||
fn written(source: [f32; 4], current: [f32; 4], tolerance: f32) -> u32 {
|
||||
let source = source.repeat(16 * 16);
|
||||
let mut dest = current.repeat(16 * 16);
|
||||
let dab = Dab { x: 8.5, y: 8.5, theta: 0.0, radius: 1.0, pressure: 1.0 };
|
||||
stamp(&mut StampParams {
|
||||
dest: &mut dest,
|
||||
dest_w: 16,
|
||||
dest_h: 16,
|
||||
dest_origin: (0, 0),
|
||||
src: &source,
|
||||
src_w: 16,
|
||||
src_h: 16,
|
||||
src_origin: (0, 0),
|
||||
ch: 4,
|
||||
dabs: std::slice::from_ref(&dab),
|
||||
hardness: 1.0,
|
||||
opacity: 1.0,
|
||||
flow: 1.0,
|
||||
tolerance,
|
||||
tile: 0,
|
||||
selection: None,
|
||||
lock_transparent: false,
|
||||
alpha: Some(3),
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn grey(value: f32) -> [f32; 4] {
|
||||
[value, value, value, 1.0]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_changed_channel_has_the_same_weight_in_rgb() {
|
||||
let source = grey(128.0 / 255.0);
|
||||
for channel in 0..3 {
|
||||
for (delta, tolerance, paints) in
|
||||
[(20.0, 0.05, true), (28.0, 0.10, true), (56.0, 0.20, true), (80.0, 0.30, true), (104.0, 0.40, true), (96.0, 0.40, false)]
|
||||
{
|
||||
let mut current = source;
|
||||
current[channel] += delta / 255.0;
|
||||
assert_eq!(written(source, current, tolerance) > 0, paints, "channel {channel}, delta {delta}, Tolerance {tolerance}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn measured_greys_and_red_cross_the_euclidean_threshold() {
|
||||
let source = grey(128.0 / 255.0);
|
||||
for (levels, tolerance, paints) in
|
||||
[(188.0, 0.40, true), (68.0, 0.40, true), (184.0, 0.40, false), (72.0, 0.40, false), (1.0, 0.80, true), (1.0, 0.90, false)]
|
||||
{
|
||||
assert_eq!(written(source, grey(levels / 255.0), tolerance) > 0, paints, "grey {levels}, Tolerance {tolerance}");
|
||||
}
|
||||
assert!(written(source, [1.0, 0.0, 0.0, 1.0], 0.86) > 0);
|
||||
assert_eq!(written(source, [1.0, 0.0, 0.0, 1.0], 0.87), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colour_requires_strictly_more_than_tolerance_and_zero_always_starts() {
|
||||
let source = grey(0.0);
|
||||
assert_eq!(written(source, [0.5, 0.0, 0.0, 1.0], 0.5), 0);
|
||||
assert!(written(source, [0.5, 0.0, 0.0, 1.0], 0.49) > 0);
|
||||
assert!(written(source, source, 0.0) > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alpha_keeps_its_existing_scale_and_inclusive_threshold() {
|
||||
let source = grey(0.5);
|
||||
assert!(written(source, [0.5, 0.5, 0.5, 0.4], 1.0) > 0);
|
||||
assert!(written(source, [0.5, 0.5, 0.5, 0.6], 0.5) > 0);
|
||||
assert_eq!(written(source, [0.5, 0.5, 0.5, 0.8], 0.5), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fully_transparent_source_samples_still_do_not_paint() {
|
||||
for tolerance in [0.0, 0.1, 1.0] {
|
||||
assert_eq!(written([1.0, 0.0, 0.0, 0.0], grey(0.0), tolerance), 0);
|
||||
}
|
||||
}
|
||||
@@ -1168,7 +1168,8 @@ fn apply_sketch(e: &GalleryEffect, win: &mut Win, ctx: &Ctx) -> bool {
|
||||
let mut l = win.lum();
|
||||
blur1(&mut l, w, h, 0.3 + g("smoothness") * 0.3);
|
||||
for i in 0..win.c.len() {
|
||||
win.c[i] = mix(bg, fg, smoothstep(bal + 0.02, bal - 0.02, l[i]));
|
||||
// Smooth the shapes without introducing colors between the ink and paper.
|
||||
win.c[i] = if l[i] < bal { fg } else { bg };
|
||||
}
|
||||
}
|
||||
F::TornEdges => {
|
||||
|
||||
@@ -4,12 +4,27 @@
|
||||
//! Works in the surface's own channels at any depth and in any colour model: only the alpha
|
||||
//! channel changes (or, under a transparency lock, the colour channels move toward `lock_color`).
|
||||
|
||||
use photocraft_color::{read_sample, write_sample};
|
||||
use photocraft_color::{ColorMode, SampleType, read_sample, write_sample};
|
||||
use photocraft_geom::Rect;
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use crate::selection::Region;
|
||||
|
||||
/// The strength (0–1) the Magic Eraser's Opacity `percent` erases with on a layer of `mode` at `depth`: the
|
||||
/// `amount` of [`magic_erase`].
|
||||
///
|
||||
/// In 8-bit RGB the reference application steps it in 255ths, round(percent × 2.55) / 255, so 50 % is 128/255 and
|
||||
/// three clicks on an opaque pixel leave alpha 127, 63, 31 (#18069). Other depths and colour modes are not measured
|
||||
/// and keep percent / 100.
|
||||
pub fn opacity_strength(percent: f32, mode: ColorMode, depth: SampleType) -> f32 {
|
||||
if mode == ColorMode::Rgb && depth == SampleType::U8 {
|
||||
// × 255 before ÷ 100, so that 50 % is exactly 127.5 and rounds up to the measured 128.
|
||||
(percent * 255.0 / 100.0).round() / 255.0
|
||||
} else {
|
||||
percent / 100.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Erases `region` from `target` at `amount` (0–1, the tool's opacity), weighted by the selection's
|
||||
/// coverage. With `lock_color` (native colour channels, e.g. the background colour converted to the
|
||||
/// surface's model) the pixels are painted toward that colour instead and alpha is kept, as
|
||||
@@ -173,3 +188,7 @@ mod tests {
|
||||
assert!(magic_erase(&mut g, ®ion(Rect::new(0, 0, 4, 4), 255), 1.0, None, None).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "magic_eraser_opacity_strength_tests.rs"]
|
||||
mod magic_eraser_opacity_strength_tests;
|
||||
@@ -2,6 +2,8 @@
|
||||
//! craft-metadata; the raw-date and numeric selection semantics are preserved there.
|
||||
|
||||
pub use craft_metadata::camera_fields::{CameraInfo, read, try_build};
|
||||
// The existing shared reader supplies additional camera tags without another TIFF parser.
|
||||
pub use craft_metadata::{TagRow, file_tag_rows};
|
||||
|
||||
/// Build a TIFF-structured EXIF payload, preserving the existing infallible API.
|
||||
/// Returns an empty payload when the shared writer refuses an oversized value. New callers
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
//! #18662: in CMYK the Gradient tool blends on the inks (`v = 1 − ink`, all four channels), not
|
||||
//! through RGB and a new separation.
|
||||
|
||||
use photocraft_color::blend::{blend_channel, blend_rgb};
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::{BlendMode, FillMode, GradientShape, Rect, paint_gradient};
|
||||
|
||||
const W: i32 = 48;
|
||||
|
||||
/// Base inks, one row each: red, grey, a warm colour, a green, rich black, white paper.
|
||||
const BASES: [[f32; 4]; 6] = [[0.0, 1.0, 1.0, 0.0], [0.4, 0.3, 0.3, 0.1], [0.1, 0.55, 0.8, 0.05], [0.75, 0.1, 0.65, 0.2], [0.7, 0.6, 0.5, 0.9], [0.0; 4]];
|
||||
|
||||
fn format(sample: SampleType) -> PixelFormat {
|
||||
PixelFormat { mode: ColorMode::Cmyk, sample, alpha: true }
|
||||
}
|
||||
|
||||
fn gradient(s: &mut Surface, mode: BlendMode, locked: bool) {
|
||||
let a = [30.0 / 255.0, 120.0 / 255.0, 220.0 / 255.0, 1.0];
|
||||
let b = [240.0 / 255.0, 200.0 / 255.0, 40.0 / 255.0, 1.0];
|
||||
let rows = BASES.len() as i32;
|
||||
paint_gradient(
|
||||
s,
|
||||
Rect::new(0, 0, W, rows),
|
||||
(0.0, 0.0),
|
||||
(W as f32, 0.0),
|
||||
GradientShape::Linear,
|
||||
&[(0.0, a), (1.0, b)],
|
||||
false,
|
||||
1.0,
|
||||
FillMode::Blend(mode),
|
||||
false,
|
||||
None,
|
||||
locked,
|
||||
);
|
||||
}
|
||||
|
||||
fn base(sample: SampleType, alpha: f32) -> Surface {
|
||||
let mut s = Surface::new(format(sample));
|
||||
for (y, inks) in BASES.iter().enumerate() {
|
||||
s.fill_rect(Rect::new(0, y as i32, W, y as i32 + 1), &[inks[0], inks[1], inks[2], inks[3], alpha]);
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// The gradient's own inks: the same gradient laid in Normal on transparency.
|
||||
fn source(sample: SampleType) -> Surface {
|
||||
let mut s = Surface::new(format(sample));
|
||||
gradient(&mut s, BlendMode::Normal, false);
|
||||
s
|
||||
}
|
||||
|
||||
fn inks(s: &Surface, x: i32, y: i32) -> [f32; 4] {
|
||||
let p = s.pixel(x, y);
|
||||
[p[0], p[1], p[2], p[3]]
|
||||
}
|
||||
|
||||
fn v(inks: [f32; 4]) -> [f32; 4] {
|
||||
inks.map(|i| 1.0 - i)
|
||||
}
|
||||
|
||||
fn tolerance(sample: SampleType) -> f32 {
|
||||
if sample == SampleType::U8 { 0.01 } else { 1e-4 }
|
||||
}
|
||||
|
||||
/// Runs `mode` over every base row in 8 and 16 bit and checks each pixel's inks against
|
||||
/// `expected(base v, source v)` (in `v`).
|
||||
fn check(mode: BlendMode, expected: impl Fn([f32; 4], [f32; 4]) -> [f32; 4]) {
|
||||
for sample in [SampleType::U8, SampleType::U16] {
|
||||
let src = source(sample);
|
||||
let before = base(sample, 1.0);
|
||||
let mut out = before.clone();
|
||||
gradient(&mut out, mode, false);
|
||||
for y in 0..BASES.len() as i32 {
|
||||
for x in 0..W {
|
||||
let want = expected(v(inks(&before, x, y)), v(inks(&src, x, y))).map(|c| 1.0 - c.clamp(0.0, 1.0));
|
||||
let got = inks(&out, x, y);
|
||||
for c in 0..4 {
|
||||
assert!((got[c] - want[c]).abs() <= tolerance(sample), "{mode:?} {sample:?} at ({x}, {y}) channel {c}: {got:?}, want {want:?}");
|
||||
}
|
||||
assert_eq!(out.pixel(x, y)[4], 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn separable_modes_use_the_rgb_formula_on_each_ink() {
|
||||
use BlendMode::*;
|
||||
for mode in [
|
||||
Darken,
|
||||
Multiply,
|
||||
ColorBurn,
|
||||
LinearBurn,
|
||||
Lighten,
|
||||
Screen,
|
||||
ColorDodge,
|
||||
LinearDodge,
|
||||
Overlay,
|
||||
SoftLight,
|
||||
HardLight,
|
||||
VividLight,
|
||||
LinearLight,
|
||||
PinLight,
|
||||
Difference,
|
||||
Exclusion,
|
||||
Subtract,
|
||||
Divide,
|
||||
] {
|
||||
check(mode, |b, s| std::array::from_fn(|i| blend_channel(mode, b[i], s[i])));
|
||||
}
|
||||
check(HardMix, |b, s| std::array::from_fn(|i| if b[i] + s[i] > 1.0 + 1e-6 { 1.0 } else { 0.0 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hue_saturation_and_color_keep_the_base_k_and_luminosity_takes_the_source_k() {
|
||||
let cmy = |c: [f32; 4]| [c[0], c[1], c[2]];
|
||||
for mode in [BlendMode::Hue, BlendMode::Saturation, BlendMode::Color, BlendMode::Luminosity] {
|
||||
check(mode, |b, s| {
|
||||
let out = blend_rgb(mode, cmy(b), cmy(s));
|
||||
let k = if mode == BlendMode::Luminosity { s[3] } else { b[3] };
|
||||
[out[0], out[1], out[2], k]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn darker_and_lighter_color_pick_the_whole_pixel_by_ink_luminosity() {
|
||||
let lum = |c: [f32; 4]| (0.30 * c[0] + 0.59 * c[1] + 0.11 * c[2]) * c[3];
|
||||
check(BlendMode::DarkerColor, |b, s| if lum(s) < lum(b) { s } else { b });
|
||||
check(BlendMode::LighterColor, |b, s| if lum(s) > lum(b) { s } else { b });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hard_mix_tie_gives_full_ink_in_16_bit() {
|
||||
let sample = SampleType::U16;
|
||||
let src = source(sample);
|
||||
// Each base pixel is the exact complement of the gradient's inks there: b + s is full in v.
|
||||
let mut out = Surface::new(format(sample));
|
||||
for x in 0..W {
|
||||
let s = inks(&src, x, 0);
|
||||
out.write_pixel(x, 0, &[1.0 - s[0], 1.0 - s[1], 1.0 - s[2], 1.0 - s[3], 1.0]);
|
||||
}
|
||||
gradient(&mut out, BlendMode::HardMix, false);
|
||||
for x in 0..W {
|
||||
assert_eq!(inks(&out, x, 0), [1.0; 4], "at x {x}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Source-over: `(1 − αb) · s + αb · B(b, s)` in v and an opaque result; with Lock Transparent
|
||||
/// Pixels the colour is `B(b, s)` and the alpha stays.
|
||||
#[test]
|
||||
fn half_transparent_base_mixes_the_source_and_the_blend_in_v() {
|
||||
let sample = SampleType::U16;
|
||||
let ab = 0.5;
|
||||
let src = source(sample);
|
||||
for locked in [false, true] {
|
||||
let before = base(sample, ab);
|
||||
let mut out = before.clone();
|
||||
gradient(&mut out, BlendMode::Multiply, locked);
|
||||
let weight = if locked { 1.0 } else { ab };
|
||||
for y in 0..BASES.len() as i32 {
|
||||
for x in 0..W {
|
||||
let (b, s) = (v(inks(&before, x, y)), v(inks(&src, x, y)));
|
||||
let want: [f32; 4] = std::array::from_fn(|i| 1.0 - ((1.0 - weight) * s[i] + weight * b[i] * s[i]));
|
||||
let got = inks(&out, x, y);
|
||||
for c in 0..4 {
|
||||
assert!((got[c] - want[c]).abs() <= 1e-4, "locked {locked} at ({x}, {y}) channel {c}: {got:?}, want {want:?}");
|
||||
}
|
||||
assert_eq!(out.pixel(x, y)[4], if locked { before.pixel(x, y)[4] } else { 1.0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
//! #17544: the Gradient tool's dither adds no noise in 16-bit RGB and Grayscale documents, where
|
||||
//! the reference's dither on and dither off give the same smooth ramp. 8 bit keeps its one-step
|
||||
//! noise, and 32 bit and 16-bit CMYK and Lab keep today's behaviour (not measured).
|
||||
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::{BlendMode, FillMode, GradientShape, Rect, paint_gradient};
|
||||
|
||||
/// A black → white Linear gradient over 800 × 600, from (100, 300) to (700, 300), in `fmt`.
|
||||
fn painted(fmt: PixelFormat, dither: bool) -> Surface {
|
||||
let mut s = Surface::new(fmt);
|
||||
let stops = [(0.0, [0.0, 0.0, 0.0, 1.0]), (1.0, [1.0, 1.0, 1.0, 1.0])];
|
||||
paint_gradient(
|
||||
&mut s,
|
||||
Rect::new(0, 0, 800, 600),
|
||||
(100.0, 300.0),
|
||||
(700.0, 300.0),
|
||||
GradientShape::Linear,
|
||||
&stops,
|
||||
false,
|
||||
1.0,
|
||||
FillMode::Blend(BlendMode::Normal),
|
||||
dither,
|
||||
None,
|
||||
false,
|
||||
);
|
||||
s
|
||||
}
|
||||
|
||||
/// The pixels of a 32 × 32 patch around the ramp's middle, all channels.
|
||||
fn patch(s: &Surface) -> Vec<f32> {
|
||||
(290..322).flat_map(|y| (384..416).flat_map(move |x| s.pixel(x, y))).collect()
|
||||
}
|
||||
|
||||
const RGB16: PixelFormat = PixelFormat::RGBA16;
|
||||
const GRAY16: PixelFormat = PixelFormat { mode: ColorMode::Grayscale, sample: SampleType::U16, alpha: true };
|
||||
const GRAY32: PixelFormat = PixelFormat { mode: ColorMode::Grayscale, sample: SampleType::F32, alpha: true };
|
||||
const CMYK16: PixelFormat = PixelFormat { mode: ColorMode::Cmyk, sample: SampleType::U16, alpha: true };
|
||||
const LAB16: PixelFormat = PixelFormat { mode: ColorMode::Lab, sample: SampleType::U16, alpha: true };
|
||||
|
||||
#[test]
|
||||
fn rgb_16_bit_dither_on_paints_what_dither_off_paints() {
|
||||
assert_eq!(patch(&painted(RGB16, true)), patch(&painted(RGB16, false)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rgb_16_bit_dithered_ramp_is_smooth() {
|
||||
// Along the ramp every step is the same small rise; down a column nothing changes.
|
||||
let s = painted(RGB16, true);
|
||||
let row: Vec<f32> = (400..406).map(|x| s.pixel(x, 300)[0] * 255.0).collect();
|
||||
for w in row.windows(2) {
|
||||
let step = w[1] - w[0];
|
||||
assert!((0.3..0.55).contains(&step), "x row {row:?}");
|
||||
}
|
||||
let col: Vec<f32> = (300..306).map(|y| s.pixel(400, y)[0]).collect();
|
||||
assert!(col.iter().all(|v| *v == col[0]), "column {col:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gray_16_bit_follows_rgb_16_bit() {
|
||||
assert_eq!(patch(&painted(GRAY16, true)), patch(&painted(GRAY16, false)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eight_bit_still_dithers() {
|
||||
for fmt in [PixelFormat::RGBA8, PixelFormat::GRAYA8] {
|
||||
assert_ne!(patch(&painted(fmt, true)), patch(&painted(fmt, false)), "{fmt:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thirty_two_bit_keeps_its_noise() {
|
||||
for fmt in [PixelFormat::RGBA32F, GRAY32] {
|
||||
let (on, off) = (patch(&painted(fmt, true)), patch(&painted(fmt, false)));
|
||||
assert_ne!(on, off, "{fmt:?}");
|
||||
// Today's amplitude: at most half an 8-bit step either way.
|
||||
let most = on.iter().zip(&off).map(|(a, b)| (a - b).abs()).fold(0.0f32, f32::max);
|
||||
assert!(most <= 0.5 / 255.0 + 1e-6, "{fmt:?}: {most}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cmyk_and_lab_16_bit_keep_their_noise() {
|
||||
// Not measured in the issue, so these keep today's dither. The noise is added to the RGB
|
||||
// colour before the conversion, so a channel moves by less than one 8-bit step.
|
||||
for fmt in [CMYK16, LAB16] {
|
||||
let (on, off) = (patch(&painted(fmt, true)), patch(&painted(fmt, false)));
|
||||
assert_ne!(on, off, "{fmt:?}");
|
||||
let most = on.iter().zip(&off).map(|(a, b)| (a - b).abs()).fold(0.0f32, f32::max);
|
||||
assert!(most < 1.0 / 255.0, "{fmt:?}: {most}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
use photocraft_color::{PixelFormat, blend, dither_noise};
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::{BlendMode, FillMode, GradientShape, Rect, paint_gradient, sample_stops, tool_gradient_t};
|
||||
|
||||
const WIDTH: i32 = 2560;
|
||||
const STOPS: [(f32, [f32; 4]); 2] = [(0.0, [0.0, 0.0, 0.0, 1.0]), (1.0, [1.0, 1.0, 1.0, 1.0])];
|
||||
|
||||
fn row(format: PixelFormat, base: u8, mode: BlendMode, dither: bool) -> Surface {
|
||||
let mut surface = Surface::new(format);
|
||||
let area = Rect::new(0, 0, WIDTH, 1);
|
||||
let gray = f32::from(base) / 255.0;
|
||||
surface.fill_rect(area, &[gray, gray, gray, 1.0]);
|
||||
paint_gradient(&mut surface, area, (0.0, 0.0), (WIDTH as f32, 0.0), GradientShape::Linear, &STOPS, false, 1.0, FillMode::Blend(mode), dither, None, false);
|
||||
surface
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gradient_hard_mix_switches_at_the_normal_ramp_byte_boundary() {
|
||||
let normal = row(PixelFormat::RGBA8, 0, BlendMode::Normal, false);
|
||||
for (base, first_white) in [(128, 127), (100, 156)] {
|
||||
let hard_mix = row(PixelFormat::RGBA8, base, BlendMode::HardMix, false);
|
||||
let mut saw = [0usize; 2];
|
||||
for x in 0..WIDTH {
|
||||
let normal_level = (normal.pixel(x, 0)[0] * 255.0).round() as u8;
|
||||
let white = normal_level >= first_white;
|
||||
assert_eq!(hard_mix.pixel(x, 0)[0], f32::from(u8::from(white)), "base {base}, x={x}, normal {normal_level}");
|
||||
if normal_level == first_white - 1 || normal_level == first_white {
|
||||
saw[usize::from(white)] += 1;
|
||||
}
|
||||
}
|
||||
assert!(saw.into_iter().all(|pixels| pixels > 1), "both tested colour runs have more than one pixel");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dithering_deep_rgb_and_other_modes_keep_the_existing_float_composite() {
|
||||
for (format, mode, dither) in [
|
||||
(PixelFormat::RGBA8, BlendMode::HardMix, true),
|
||||
(PixelFormat::RGBA16, BlendMode::HardMix, false),
|
||||
(PixelFormat::RGBA32F, BlendMode::HardMix, false),
|
||||
(PixelFormat::RGBA8, BlendMode::Multiply, false),
|
||||
] {
|
||||
let actual = row(format, 100, mode, dither);
|
||||
let mut expected = Surface::new(format);
|
||||
expected.write_pixel(0, 0, &[100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0, 1.0]);
|
||||
let base = expected.rgba(0, 0);
|
||||
for x in 0..WIDTH {
|
||||
let t = tool_gradient_t(GradientShape::Linear, (0.0, 0.0), (WIDTH as f32, 0.0), x as f32 - 0.5, -0.5);
|
||||
let mut color = sample_stops(&STOPS, t);
|
||||
if dither {
|
||||
let noise = (dither_noise(x, 0) - 0.5) / 255.0;
|
||||
for channel in &mut color[..3] {
|
||||
*channel = (*channel + noise).clamp(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
expected.write_pixel(x, 0, &blend::composite(mode, base, color, 1.0));
|
||||
assert_eq!(actual.pixel(x, 0), expected.pixel(x, 0), "{format:?} {mode:?}, dither={dither}, x={x}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use photocraft_color::PixelFormat;
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::{BlendMode, FillMode, GradientShape, Rect, paint_gradient};
|
||||
|
||||
#[test]
|
||||
fn gradient_hard_mix_matches_all_u8_pairs_and_uses_each_rgb_channel() {
|
||||
let mut surface = Surface::new(PixelFormat::RGBA8);
|
||||
for base in 0..256 {
|
||||
let gray = base as f32 / 255.0;
|
||||
surface.fill_rect(Rect::new(0, base, 256, base + 1), &[gray, gray, gray, 1.0]);
|
||||
}
|
||||
let blue = 200.0 / 255.0;
|
||||
paint_gradient(
|
||||
&mut surface,
|
||||
Rect::new(0, 0, 256, 256),
|
||||
(-0.5, 0.0),
|
||||
(254.5, 0.0),
|
||||
GradientShape::Linear,
|
||||
&[(0.0, [0.0, 1.0, blue, 1.0]), (1.0, [1.0, 0.0, blue, 1.0])],
|
||||
false,
|
||||
1.0,
|
||||
FillMode::Blend(BlendMode::HardMix),
|
||||
false,
|
||||
None,
|
||||
false,
|
||||
);
|
||||
for base in 0..256 {
|
||||
for source in 0..256 {
|
||||
let expected = [source, 255 - source, 200].map(|channel| match (base + channel).cmp(&255) {
|
||||
Ordering::Less => 0.0,
|
||||
Ordering::Greater => 1.0,
|
||||
Ordering::Equal => f32::from(u8::from(channel < 128)),
|
||||
});
|
||||
let actual = surface.pixel(source, base);
|
||||
assert_eq!(actual[..3], expected, "base {base}, red source {source}");
|
||||
assert_eq!(actual[3], 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gradient_hard_mix_preserves_source_over_and_locked_alpha() {
|
||||
for locked in [false, true] {
|
||||
let mut surface = Surface::new(PixelFormat::RGBA8);
|
||||
surface.write_pixel(1, 0, &[127.0 / 255.0, 127.0 / 255.0, 127.0 / 255.0, 128.0 / 255.0]);
|
||||
let color = [128.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 1.0];
|
||||
paint_gradient(
|
||||
&mut surface,
|
||||
Rect::new(0, 0, 2, 1),
|
||||
(0.0, 0.0),
|
||||
(1.0, 0.0),
|
||||
GradientShape::Linear,
|
||||
&[(0.0, color), (1.0, color)],
|
||||
false,
|
||||
0.5,
|
||||
FillMode::Blend(BlendMode::HardMix),
|
||||
false,
|
||||
None,
|
||||
locked,
|
||||
);
|
||||
let byte = |x, channel: usize| (surface.pixel(x, 0)[channel] * 255.0).round() as u8;
|
||||
if locked {
|
||||
assert_eq!(byte(0, 3), 0);
|
||||
assert_eq!((byte(1, 0), byte(1, 3)), (64, 128));
|
||||
} else {
|
||||
assert_eq!((byte(0, 0), byte(0, 3)), (128, 128));
|
||||
assert_eq!((byte(1, 0), byte(1, 3)), (85, 192));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
//! #18069: in 8-bit RGB the Magic Eraser's Opacity percent becomes a strength in 255 steps, round(percent × 2.55) / 255,
|
||||
//! as measured in the reference application. Three clicks at 50 % leave alpha 127, 63, 31, where percent / 100 left
|
||||
//! 128, 64, 32. The values below are the measured ones, with Anti-alias off.
|
||||
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_geom::Rect;
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::{magic_erase, opacity_strength};
|
||||
use crate::selection::Region;
|
||||
|
||||
/// The background colour of the measurements, as 8-bit RGB.
|
||||
const BACKGROUND: [u8; 3] = [0, 255, 128];
|
||||
|
||||
fn block_rect() -> Rect {
|
||||
Rect::new(0, 0, 8, 8)
|
||||
}
|
||||
|
||||
fn unit(v: u8) -> f32 {
|
||||
f32::from(v) / 255.0
|
||||
}
|
||||
|
||||
/// An 8-bit RGB layer whose block is `rgba`.
|
||||
fn block(rgba: [u8; 4]) -> Surface {
|
||||
let mut s = Surface::new(PixelFormat::RGBA8);
|
||||
s.fill_rect(block_rect(), &rgba.map(unit));
|
||||
s
|
||||
}
|
||||
|
||||
/// One click at `percent` Opacity that takes the whole block: the wand's region with Anti-alias off. With `locked`,
|
||||
/// the layer has Lock transparent pixels on and the click paints toward [`BACKGROUND`].
|
||||
fn click(s: &mut Surface, percent: f32, locked: bool) {
|
||||
let region = Region { bbox: block_rect(), mask: vec![255; 64] };
|
||||
let lock = locked.then(|| BACKGROUND.map(unit));
|
||||
let strength = opacity_strength(percent, ColorMode::Rgb, SampleType::U8);
|
||||
magic_erase(s, ®ion, strength, None, lock.as_ref().map(|c| c.as_slice()));
|
||||
}
|
||||
|
||||
/// A pixel of the block, as the layer's bytes.
|
||||
fn pixel(s: &Surface) -> [u8; 4] {
|
||||
let bytes = s.to_interleaved(Rect::new(3, 3, 4, 4));
|
||||
[bytes[0], bytes[1], bytes[2], bytes[3]]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn three_clicks_step_alpha_in_255ths_and_keep_the_colour() {
|
||||
for (percent, alphas) in [(50.0, [127, 63, 31]), (25.0, [191, 143, 107])] {
|
||||
let mut s = block([200, 40, 40, 255]);
|
||||
for (n, alpha) in alphas.into_iter().enumerate() {
|
||||
click(&mut s, percent, false);
|
||||
assert_eq!(pixel(&s), [200, 40, 40, alpha], "Opacity {percent}, click {}", n + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn under_the_lock_the_colour_steps_toward_the_background_and_alpha_stays() {
|
||||
let at_25 = (25.0, [200, 40, 40], [[150, 94, 62], [112, 134, 79], [84, 164, 91]]);
|
||||
let at_50 = (50.0, [220, 30, 30], [[110, 143, 79], [55, 199, 104], [27, 227, 116]]);
|
||||
for (percent, [r, g, b], clicks) in [at_25, at_50] {
|
||||
let mut s = block([r, g, b, 255]);
|
||||
for (n, [r, g, b]) in clicks.into_iter().enumerate() {
|
||||
click(&mut s, percent, true);
|
||||
assert_eq!(pixel(&s), [r, g, b, 255], "Opacity {percent}, click {}", n + 1);
|
||||
}
|
||||
}
|
||||
// A half-transparent pixel keeps its alpha too.
|
||||
let mut s = block([200, 40, 40, 128]);
|
||||
click(&mut s, 50.0, true);
|
||||
assert_eq!(pixel(&s)[3], 128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_opacity_still_erases_to_nothing_or_fills_the_background() {
|
||||
let mut s = block([200, 40, 40, 255]);
|
||||
click(&mut s, 100.0, false);
|
||||
assert_eq!(pixel(&s)[3], 0);
|
||||
let mut s = block([200, 40, 40, 255]);
|
||||
click(&mut s, 100.0, true);
|
||||
let [r, g, b] = BACKGROUND;
|
||||
assert_eq!(pixel(&s), [r, g, b, 255]);
|
||||
}
|
||||
|
||||
/// Only 8-bit RGB is measured: the other depths and colour modes keep the strength they had, percent / 100.
|
||||
#[test]
|
||||
fn unmeasured_depths_and_modes_keep_the_plain_percent() {
|
||||
let unmeasured = [
|
||||
(ColorMode::Rgb, SampleType::U16),
|
||||
(ColorMode::Rgb, SampleType::F32),
|
||||
(ColorMode::Grayscale, SampleType::U8),
|
||||
(ColorMode::Cmyk, SampleType::U8),
|
||||
(ColorMode::Lab, SampleType::U8),
|
||||
];
|
||||
for (mode, depth) in unmeasured {
|
||||
for percent in [25.0, 50.0, 70.0] {
|
||||
assert_eq!(opacity_strength(percent, mode, depth), percent / 100.0, "{mode:?} {depth:?} at {percent}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,18 +32,24 @@ pub(crate) fn add(src: &Image, out: Rect, ctx: &Ctx, amount: f32, dist: Distribu
|
||||
continue;
|
||||
}
|
||||
let (x, y) = (out.x0 + (i % w) as i32, out.y0 + (i / w) as i32);
|
||||
for (c, pv) in px.iter_mut().enumerate().take(cc) {
|
||||
let ch = if mono { 0 } else { c as u32 };
|
||||
let v = match dist {
|
||||
Distribution::Uniform => (hash01(x, y, ch, seed) - 0.5) * 2.0 * a,
|
||||
Distribution::Gaussian => {
|
||||
let u1 = hash01(x, y, ch * 2 + 101, seed).max(1e-7);
|
||||
let u2 = hash01(x, y, ch * 2 + 102, seed);
|
||||
(-2.0 * u1.ln()).sqrt() * (std::f32::consts::TAU * u2).cos() * a * 0.5
|
||||
}
|
||||
};
|
||||
// Integer storage clamps on write; float surfaces keep the value.
|
||||
*pv += v;
|
||||
let value = |ch| match dist {
|
||||
Distribution::Uniform => (hash01(x, y, ch, seed) - 0.5) * 2.0 * a,
|
||||
Distribution::Gaussian => {
|
||||
let u1 = hash01(x, y, ch * 2 + 101, seed).max(1e-7);
|
||||
let u2 = hash01(x, y, ch * 2 + 102, seed);
|
||||
(-2.0 * u1.ln()).sqrt() * (std::f32::consts::TAU * u2).cos() * a * 0.5
|
||||
}
|
||||
};
|
||||
// Integer storage clamps on write; float surfaces keep the value.
|
||||
if mono {
|
||||
let v = value(0);
|
||||
for pv in px.iter_mut().take(cc) {
|
||||
*pv += v;
|
||||
}
|
||||
} else {
|
||||
for (c, pv) in px.iter_mut().enumerate().take(cc) {
|
||||
*pv += value(c as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
res
|
||||
|
||||
@@ -5,12 +5,16 @@ use photocraft_geom::Rect;
|
||||
use photocraft_raster::{Surface, from_rgba_into};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// How a fill lays down its colour: blended with a mode, or Clear, which erases what it covers
|
||||
/// (the Paint Bucket's Mode › Clear).
|
||||
/// How a fill lays down its colour: blended with a mode, Clear, which erases what it covers
|
||||
/// (the Paint Bucket's Mode › Clear), or Behind, which paints only into the pixels' transparency.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum FillMode {
|
||||
Blend(BlendMode),
|
||||
Clear,
|
||||
/// The fill goes under each pixel at `fill α × coverage × (1 − α)`, as the Brush's Behind
|
||||
/// lays it: opaque pixels keep what they have, transparent ones take the fill as in Normal
|
||||
/// (#12531). Locked transparency leaves the layer as it is.
|
||||
Behind,
|
||||
}
|
||||
|
||||
/// Gradient tool shape.
|
||||
@@ -67,6 +71,8 @@ pub fn sample_stops(stops: &[(f32, [f32; 4])], t: f32) -> [f32; 4] {
|
||||
/// zero, `rim(x, y)` (when given) is the strength of a bucket's transparent-seed fringe there: the
|
||||
/// pixel takes the fill at coverage `rim × (1 − α)`, its own transparency (#11354 review; see
|
||||
/// [`bucket_fill_inks`]). Lock Transparent Pixels and Clear ignore it.
|
||||
/// With `on_inks`, a CMYK target blends the modes [`blend::blends_inks`] lists on its inks
|
||||
/// ([`blend::composite_inks`]) instead of through RGB (the Gradient tool, #18662).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn composite_area(
|
||||
s: &mut Surface,
|
||||
@@ -74,14 +80,21 @@ fn composite_area(
|
||||
mode: FillMode,
|
||||
coverage: impl Fn(i32, i32) -> f32 + Sync,
|
||||
color: impl Fn(i32, i32) -> [f32; 4] + Sync,
|
||||
blend_pixel: impl Fn(BlendMode, [f32; 4], [f32; 4], f32, bool) -> [f32; 4] + Sync,
|
||||
lock_transparency: bool,
|
||||
inks: Option<[f32; 4]>,
|
||||
rim: Option<&(dyn Fn(i32, i32) -> f32 + Sync)>,
|
||||
on_inks: bool,
|
||||
) {
|
||||
// Composite tile by tile (in parallel on native); tiles with zero coverage are left untouched,
|
||||
// so their copy-on-write storage (and GPU residency) survives.
|
||||
let fmt = s.format();
|
||||
let n = fmt.channels();
|
||||
let levels = match fmt.sample {
|
||||
photocraft_color::SampleType::U8 => Some(255.0),
|
||||
photocraft_color::SampleType::U16 => Some(65535.0),
|
||||
_ => None,
|
||||
};
|
||||
let tiles: Vec<Rect> = area.tiles().map(|tc| tc.rect().intersect(&area)).filter(|r| !r.is_empty()).collect();
|
||||
let src: &Surface = s;
|
||||
let work = |r: &Rect| -> Option<(Rect, Vec<f32>)> {
|
||||
@@ -93,7 +106,7 @@ fn composite_area(
|
||||
for x in r.x0..r.x1 {
|
||||
let mut k = coverage(x, y);
|
||||
let on_rim = match rim {
|
||||
Some(rim) if k <= 0.0 && !lock_transparency && matches!(mode, FillMode::Blend(_)) => rim(x, y),
|
||||
Some(rim) if k <= 0.0 && !lock_transparency && matches!(mode, FillMode::Blend(_) | FillMode::Behind) => rim(x, y),
|
||||
_ => 0.0,
|
||||
};
|
||||
if k <= 0.0 && on_rim <= 0.0 {
|
||||
@@ -113,18 +126,41 @@ fn composite_area(
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Behind leaves opaque and transparency-locked pixels unchanged; skip the
|
||||
// encode and write, whose CMYK round trip can shift their inks (#12531 review).
|
||||
if mode == FillMode::Behind && (lock_transparency || d[3] >= 1.0) {
|
||||
continue;
|
||||
}
|
||||
// 32-bit CMYK is not measured, so it keeps the RGB path; on 8 and 16 bit the
|
||||
// source is blended as stored samples, so Hard Mix ties are exact.
|
||||
if let FillMode::Blend(m) = mode
|
||||
&& on_inks
|
||||
&& let Some(l) = levels
|
||||
&& blend::blends_inks(m)
|
||||
{
|
||||
let src = color(x, y);
|
||||
from_rgba_into(&fmt, src, &mut enc);
|
||||
let source = [enc[0], enc[1], enc[2], enc[3]].map(|v| (v.clamp(0.0, 1.0) * l).round() / l);
|
||||
let (out, alpha) = blend::composite_inks(m, [px[0], px[1], px[2], px[3]], d[3], source, src[3] * k, lock_transparency);
|
||||
px[..4].copy_from_slice(&out);
|
||||
if fmt.alpha {
|
||||
px[4] = alpha;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let o = match mode {
|
||||
FillMode::Blend(m) if lock_transparency => blend::composite_atop(m, d, color(x, y), k),
|
||||
FillMode::Blend(m) => blend::composite(m, d, color(x, y), k),
|
||||
FillMode::Blend(m) => blend_pixel(m, d, color(x, y), k, lock_transparency),
|
||||
// Locked transparency keeps the alpha, so Clear leaves the pixel as it is.
|
||||
FillMode::Clear if lock_transparency => d,
|
||||
FillMode::Clear => [d[0], d[1], d[2], d[3] * (1.0 - k.min(1.0))],
|
||||
FillMode::Behind if lock_transparency => d,
|
||||
FillMode::Behind => behind(d, color(x, y), k),
|
||||
};
|
||||
from_rgba_into(&fmt, o, &mut enc);
|
||||
// A colour picked as CMYK inks replaces fully covered pixels of a CMYK target as it is.
|
||||
if let Some(i) = inks
|
||||
&& fmt.mode == photocraft_color::ColorMode::Cmyk
|
||||
&& mode == FillMode::Blend(BlendMode::Normal)
|
||||
&& (mode == FillMode::Blend(BlendMode::Normal) || (mode == FillMode::Behind && d[3] <= 0.0))
|
||||
&& k >= 1.0
|
||||
{
|
||||
enc[..4].copy_from_slice(&i);
|
||||
@@ -146,7 +182,25 @@ fn composite_area(
|
||||
}
|
||||
}
|
||||
|
||||
/// Gradient tool over `area` (the selection bounds or canvas).
|
||||
fn composite_blend(mode: BlendMode, backdrop: [f32; 4], source: [f32; 4], coverage: f32, lock_transparency: bool) -> [f32; 4] {
|
||||
if lock_transparency { blend::composite_atop(mode, backdrop, source, coverage) } else { blend::composite(mode, backdrop, source, coverage) }
|
||||
}
|
||||
|
||||
/// [`FillMode::Behind`] for one pixel: `src` laid under `d` at coverage `k`, with the Brush's
|
||||
/// Behind formula (`photocraft_paint`'s render): the fill's share is `src α × k × (1 − d α)`.
|
||||
fn behind(d: [f32; 4], src: [f32; 4], k: f32) -> [f32; 4] {
|
||||
let da = d[3].clamp(0.0, 1.0);
|
||||
let underneath = src[3].clamp(0.0, 1.0) * k.clamp(0.0, 1.0) * (1.0 - da);
|
||||
let alpha = da + underneath;
|
||||
if da >= 1.0 || alpha <= 0.0 || alpha.is_nan() {
|
||||
return d;
|
||||
}
|
||||
let mix = |c: usize| (d[c] * da + src[c] * underneath) / alpha;
|
||||
[mix(0), mix(1), mix(2), alpha]
|
||||
}
|
||||
|
||||
/// Gradient tool over `area` (the selection bounds or canvas), composited by `mode` (a blend
|
||||
/// mode, or Behind, #12011).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn paint_gradient(
|
||||
s: &mut Surface,
|
||||
@@ -157,15 +211,26 @@ pub fn paint_gradient(
|
||||
stops: &[(f32, [f32; 4])],
|
||||
reverse: bool,
|
||||
opacity: f32,
|
||||
blend_mode: BlendMode,
|
||||
mode: FillMode,
|
||||
dither: bool,
|
||||
selection: Option<&Surface>,
|
||||
lock_transparency: bool,
|
||||
) {
|
||||
// 16-bit RGB and Grayscale get no dither noise: the reference's dither on and off give the
|
||||
// same smooth ramp there (#17544). Other 16-bit models (CMYK, Lab) weren't measured and keep
|
||||
// the noise, as do 8 and 32 bit.
|
||||
let fmt = s.format();
|
||||
let smooth_16 =
|
||||
fmt.sample == photocraft_color::SampleType::U16 && matches!(fmt.mode, photocraft_color::ColorMode::Rgb | photocraft_color::ColorMode::Grayscale);
|
||||
let dither = dither && !smooth_16;
|
||||
let hard_mix_rgb8 = mode == FillMode::Blend(BlendMode::HardMix)
|
||||
&& fmt.mode == photocraft_color::ColorMode::Rgb
|
||||
&& fmt.sample == photocraft_color::SampleType::U8
|
||||
&& !dither;
|
||||
composite_area(
|
||||
s,
|
||||
area,
|
||||
FillMode::Blend(blend_mode),
|
||||
mode,
|
||||
|x, y| opacity * selection.map_or(1.0, |m| m.sample_channel(x, y, 0)),
|
||||
|x, y| {
|
||||
// Sampled one pixel up and left of the pixel centre, where the reference application samples (#12018).
|
||||
@@ -180,12 +245,36 @@ pub fn paint_gradient(
|
||||
}
|
||||
c
|
||||
},
|
||||
|mode, backdrop, source, coverage, locked| {
|
||||
if hard_mix_rgb8 {
|
||||
composite_hard_mix_gradient(backdrop, source, coverage, locked)
|
||||
} else {
|
||||
composite_blend(mode, backdrop, source, coverage, locked)
|
||||
}
|
||||
},
|
||||
lock_transparency,
|
||||
None,
|
||||
None,
|
||||
fmt.mode == photocraft_color::ColorMode::Cmyk,
|
||||
);
|
||||
}
|
||||
|
||||
fn composite_hard_mix_gradient(backdrop: [f32; 4], mut source: [f32; 4], coverage: f32, locked: bool) -> [f32; 4] {
|
||||
// Round the comparison exactly as a Normal RGB8 gradient would store it. Equal sums
|
||||
// take white for a dark source and black for a light source.
|
||||
let quantize = |v: f32| (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u16;
|
||||
let blend_weight = if locked { 1.0 } else { backdrop[3] };
|
||||
for (color, base) in source[..3].iter_mut().zip(&backdrop[..3]) {
|
||||
let s = quantize(*color);
|
||||
let sum = quantize(*base) + s;
|
||||
let mixed = if sum > 255 || (sum == 255 && s <= 127) { 1.0 } else { 0.0 };
|
||||
// In source-over, only the overlap uses the blend. The uncovered part keeps the
|
||||
// unblended gradient colour. Normal then applies the existing coverage and alpha math.
|
||||
*color = (1.0 - blend_weight) * *color + blend_weight * mixed;
|
||||
}
|
||||
composite_blend(BlendMode::Normal, backdrop, source, coverage, locked)
|
||||
}
|
||||
|
||||
/// Paint bucket: fills the region similar to the seed pixel (on the layer's
|
||||
/// own pixels) within `area`, respecting the selection.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -244,7 +333,15 @@ pub fn bucket_fill_inks(
|
||||
return false;
|
||||
}
|
||||
let img = crate::selection::rgba8_image(s, area);
|
||||
let Some(region) = crate::selection::wand_region_bucket(&img, area, seed, tolerance, contiguous, anti_alias) else { return false };
|
||||
// #17733 measured unlocked RGB at 8 bits and at exact 8-bit alpha steps in 16 bits.
|
||||
// Keep the previous alpha band for every other mode, depth and locked-transparency fill.
|
||||
let alpha = match (s.format().mode, s.format().sample, lock_transparency) {
|
||||
(photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U8, false) => crate::selection::BucketAlpha::Visible,
|
||||
(photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U16, false) if s.format().alpha => crate::selection::BucketAlpha::Stepped16(s),
|
||||
(photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U16, false) => crate::selection::BucketAlpha::Visible,
|
||||
_ => crate::selection::BucketAlpha::Band,
|
||||
};
|
||||
let Some(region) = crate::selection::wand_region_bucket(&img, area, seed, tolerance, contiguous, anti_alias, alpha) else { return false };
|
||||
// Clicked on transparency with Anti-alias on: the wand's fringe gives the partly transparent
|
||||
// pixels around the flood no coverage (their alpha is measured against the seed's 0), but the
|
||||
// reference application fills each pixel 8-adjacent to the flood at coverage `1 − α`, so the
|
||||
@@ -312,7 +409,7 @@ fn fill_region(
|
||||
// The ring is only ever read for an unlocked Blend fill (see composite_area), and it is
|
||||
// empty when the region covers every pixel, so do not build it in those cases: on a large
|
||||
// canvas it is a bool per pixel plus a full scan of the mask.
|
||||
let use_rim = rim && !lock_transparency && matches!(mode, FillMode::Blend(_)) && region.mask.contains(&0);
|
||||
let use_rim = rim && !lock_transparency && matches!(mode, FillMode::Blend(_) | FillMode::Behind) && region.mask.contains(&0);
|
||||
let ring = if use_rim { rim_ring(region) } else { Vec::new() };
|
||||
let on_ring = |x: i32, y: i32| {
|
||||
let at = usize::try_from(y - b.y0).ok().zip(usize::try_from(x - b.x0).ok()).filter(|_| b.contains(x, y));
|
||||
@@ -320,7 +417,7 @@ fn fill_region(
|
||||
if hit == Some(&true) { strength(x, y) } else { 0.0 }
|
||||
};
|
||||
let rim: Option<&(dyn Fn(i32, i32) -> f32 + Sync)> = if use_rim { Some(&on_ring) } else { None };
|
||||
composite_area(s, b, mode, |x, y| region.at(x, y) * strength(x, y), src, lock_transparency, inks, rim);
|
||||
composite_area(s, b, mode, |x, y| region.at(x, y) * strength(x, y), src, composite_blend, lock_transparency, inks, rim, false);
|
||||
}
|
||||
|
||||
/// Over `region.bbox` (row-major): the pixels the region leaves uncovered that touch one of its
|
||||
@@ -338,10 +435,26 @@ fn rim_ring(region: &crate::selection::Region) -> Vec<bool> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "gradient_dither_16bit_tests.rs"]
|
||||
mod gradient_dither_16bit_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "paint_gradient_sample_tests.rs"]
|
||||
mod paint_gradient_sample_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "gradient_hard_mix_tie_tests.rs"]
|
||||
mod gradient_hard_mix_tie_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "gradient_hard_mix_rounded_source_tests.rs"]
|
||||
mod gradient_hard_mix_rounded_source_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "gradient_cmyk_ink_blend_tests.rs"]
|
||||
mod gradient_cmyk_ink_blend_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -373,7 +486,7 @@ mod tests {
|
||||
&[(0.0, [0.0, 0.0, 0.0, 1.0]), (1.0, [1.0, 1.0, 1.0, 1.0])],
|
||||
false,
|
||||
1.0,
|
||||
BlendMode::Normal,
|
||||
FillMode::Blend(BlendMode::Normal),
|
||||
false,
|
||||
Some(&sel),
|
||||
false,
|
||||
@@ -392,7 +505,20 @@ mod tests {
|
||||
let a = Rect::new(0, 0, 4, 1);
|
||||
s.fill_rect(a, &[1.0, 1.0, 1.0, 0.5]);
|
||||
let black = [0.0, 0.0, 0.0, 1.0];
|
||||
paint_gradient(&mut s, a, (0.0, 0.0), (4.0, 0.0), GradientShape::Linear, &[(0.0, black), (1.0, black)], false, 0.5, mode, false, None, true);
|
||||
paint_gradient(
|
||||
&mut s,
|
||||
a,
|
||||
(0.0, 0.0),
|
||||
(4.0, 0.0),
|
||||
GradientShape::Linear,
|
||||
&[(0.0, black), (1.0, black)],
|
||||
false,
|
||||
0.5,
|
||||
FillMode::Blend(mode),
|
||||
false,
|
||||
None,
|
||||
true,
|
||||
);
|
||||
let p = s.rgba(2, 0);
|
||||
assert!((p[0] - 0.5).abs() < 0.01 && (p[3] - 0.5).abs() < 0.01, "{fmt:?} {mode:?} {p:?}");
|
||||
}
|
||||
@@ -485,6 +611,29 @@ mod tests {
|
||||
assert!(!is_inks(&raw(&s, 3)), "a blended destination keeps its own encoding: {:?}", raw(&s, 3));
|
||||
}
|
||||
|
||||
/// #12531 review: Behind returns an opaque or transparency-locked pixel unchanged, so
|
||||
/// composite_area must not run it through the RGB encode at all — on a CMYK target the
|
||||
/// round trip is lossy and shifts the inks of artwork Behind cannot touch. The stored
|
||||
/// channels stay byte for byte.
|
||||
#[test]
|
||||
fn behind_leaves_opaque_and_locked_cmyk_pixels_as_stored() {
|
||||
let a = Rect::new(0, 0, 8, 1);
|
||||
let green = |_, _| [0.0, 1.0, 0.0, 1.0];
|
||||
// Opaque inks off the conversion lattice: a CMYK -> RGB -> CMYK trip moves them.
|
||||
let mut s = Surface::new(PixelFormat::CMYKA8);
|
||||
s.fill_rect(a, &[0.13, 0.37, 0.71, 0.29, 1.0]);
|
||||
let before = s.read_region(a);
|
||||
assert!(bucket_fill_inks(&mut s, a, (1, 0), 255.0, false, false, 1.0, None, false, green, None, FillMode::Behind));
|
||||
assert_eq!(s.read_region(a), before, "opaque pixels keep their stored inks");
|
||||
|
||||
// Locked transparency: a partly transparent pixel is likewise returned unchanged.
|
||||
let mut s = Surface::new(PixelFormat::CMYKA8);
|
||||
s.fill_rect(a, &[0.13, 0.37, 0.71, 0.29, 0.5]);
|
||||
let before = s.read_region(a);
|
||||
assert!(bucket_fill_inks(&mut s, a, (1, 0), 255.0, false, false, 1.0, None, true, green, None, FillMode::Behind));
|
||||
assert_eq!(s.read_region(a), before, "locked pixels keep their stored inks");
|
||||
}
|
||||
|
||||
/// #11354 review: the soft rim a Clear leaves rises only partly. The reference application
|
||||
/// takes rim alphas 187, 56 and 3 to 204, 211 and 253; the rule here, `α + (1 − α)²`, gives
|
||||
/// 205, 211 and 252, each within one level of it (fit in PR #11354's review round). The rim pixel
|
||||
@@ -518,23 +667,20 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The rule is for a click on transparency only: from an opaque seed the fill is exactly the
|
||||
/// wand region's own fill, fringe included.
|
||||
/// #17733: an opaque seed fills matching visible colours at every alpha, while fully
|
||||
/// transparent neighbours keep zero coverage even with Anti-alias enabled.
|
||||
#[test]
|
||||
fn bucket_on_opaque_pixels_keeps_neighbouring_transparency() {
|
||||
fn bucket_on_opaque_pixels_fills_matching_visible_neighbours() {
|
||||
let a = Rect::new(0, 0, 8, 1);
|
||||
let mut s = Surface::new(PixelFormat::RGBA8);
|
||||
s.fill_rect(Rect::new(0, 0, 4, 1), &[1.0, 1.0, 1.0, 0.5]);
|
||||
s.fill_rect(Rect::new(4, 0, 8, 1), &[1.0, 1.0, 1.0, 1.0]);
|
||||
let mut plain = s.clone();
|
||||
let img = crate::selection::rgba8_image(&plain, a);
|
||||
let region = crate::selection::wand_region(&img, a, (6, 0), 0.0, true, true).unwrap();
|
||||
bucket_fill_region_inks(&mut plain, ®ion, 1.0, None, false, |_, _| [1.0; 4], None, FillMode::Blend(BlendMode::Normal));
|
||||
s.fill_rect(Rect::new(0, 0, 1, 1), &[1.0, 1.0, 1.0, 0.0]);
|
||||
assert!(bucket_fill_inks(&mut s, a, (6, 0), 0.0, true, true, 1.0, None, false, |_, _| [1.0; 4], None, FillMode::Blend(BlendMode::Normal)));
|
||||
for x in 0..8 {
|
||||
assert_eq!(s.rgba(x, 0), plain.rgba(x, 0), "at {x}");
|
||||
assert_eq!(s.rgba(0, 0)[3], 0.0, "alpha-zero neighbour gets no fringe");
|
||||
for x in 1..8 {
|
||||
assert_eq!(s.rgba(x, 0), [1.0; 4], "visible matching pixel at {x}");
|
||||
}
|
||||
assert!((s.rgba(1, 0)[3] - 0.5).abs() < 0.01, "outside the region");
|
||||
}
|
||||
|
||||
/// #12528 (reference application, transparent seed, Tolerance 32, Anti-alias on): a black
|
||||
|
||||
@@ -169,17 +169,14 @@ fn wand_region_still_uses_the_alpha_band() {
|
||||
assert_eq!(r32.at(9, EDGE_Y), 1.0, "alpha 0 is inside it");
|
||||
}
|
||||
|
||||
/// The measured semi-transparent case is one colour at several alphas; a pixel of another
|
||||
/// colour keeps the alpha band the shared rule always had (the issue leaves unmeasured
|
||||
/// cases at today's behaviour). Seed [0, 0, 0, 40] at x = 1: x = 0 is the same-colour
|
||||
/// control [0, 0, 0, 253]; x = 2 is [20, 20, 20, 197] — its RGB distance of 20 passes
|
||||
/// Tolerance 32, but its alpha sits 157 from the seed's, so it is not filled.
|
||||
/// #17733 expands the measured case to nearby colours: a visible pixel within the RGB
|
||||
/// tolerance fills even when its alpha is far from the semi-transparent seed's.
|
||||
#[test]
|
||||
fn semi_transparent_seed_keeps_the_alpha_band_for_other_colours() {
|
||||
fn semi_transparent_seed_matches_other_colours_across_alpha_values() {
|
||||
let img: Vec<[u8; 4]> = vec![[0, 0, 0, 253], [0, 0, 0, 40], [20, 20, 20, 197]];
|
||||
let area = Rect::new(0, 0, 3, 1);
|
||||
let after = fill(&img, area, (1, 0), 32.0, true);
|
||||
let ch = changed(&img, &after);
|
||||
assert!(ch.contains(&0), "same-colour pixel of alpha 253 fills");
|
||||
assert!(!ch.contains(&2), "different-colour pixel of alpha 197 keeps the alpha band");
|
||||
assert!(ch.contains(&2), "different-colour pixel of alpha 197 also fills");
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
use photocraft_color::PixelFormat;
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::{BlendMode, GradientShape, Rect, paint_gradient};
|
||||
use super::{BlendMode, FillMode, GradientShape, Rect, paint_gradient};
|
||||
|
||||
const LINEAR: [f32; 11] = [0.0, 2.0, 17.0, 42.0, 70.0, 99.0, 129.0, 162.0, 196.0, 228.0, 255.0];
|
||||
|
||||
@@ -18,7 +18,7 @@ fn ramp() -> Vec<(f32, [f32; 4])> {
|
||||
/// An 800 × 600 RGB8 gradient from `from` to `to`, dither off.
|
||||
fn painted(shape: GradientShape, from: (f32, f32), to: (f32, f32)) -> Surface {
|
||||
let mut s = Surface::new(PixelFormat::RGBA8);
|
||||
paint_gradient(&mut s, Rect::new(0, 0, 800, 600), from, to, shape, &ramp(), false, 1.0, BlendMode::Normal, false, None, false);
|
||||
paint_gradient(&mut s, Rect::new(0, 0, 800, 600), from, to, shape, &ramp(), false, 1.0, FillMode::Blend(BlendMode::Normal), false, None, false);
|
||||
s
|
||||
}
|
||||
|
||||
|
||||
@@ -532,9 +532,21 @@ mod tests {
|
||||
assert!(read_radius(sigma(25.0, bounds)) > 97);
|
||||
let area = output_area(&p, s.content_bounds(), bounds, None);
|
||||
let full = apply_tiled(&s, &p, area, bounds, None, 4096, None);
|
||||
let tiled = apply_tiled(&s, &p, area, bounds, None, 128, None);
|
||||
let inner = Rect::new(0, 0, size, size);
|
||||
let d = max_diff(&full.read_region(inner), &tiled.read_region(inner));
|
||||
// Keep every tile that contributes checked pixels, including each edge tile's
|
||||
// original rectangle and halo. The remaining tiles lie wholly outside the canvas.
|
||||
let tile = 128;
|
||||
let tile_start = |pixel: i32, origin: i32| origin + (pixel - origin).div_euclid(tile) * tile;
|
||||
let visible_tiles = Rect::new(
|
||||
tile_start(bounds.x0, area.x0),
|
||||
tile_start(bounds.y0, area.y0),
|
||||
tile_start(bounds.x1 - 1, area.x0) + tile,
|
||||
tile_start(bounds.y1 - 1, area.y0) + tile,
|
||||
)
|
||||
.intersect(&area);
|
||||
let tiled = apply_tiled(&s, &p, visible_tiles, bounds, None, tile, None);
|
||||
let center = size / 2;
|
||||
assert!(max_diff(&full.pixel(center, center), &s.pixel(center, center)) > 1e-4, "the full frame must be relit");
|
||||
let d = max_diff(&full.read_region(bounds), &tiled.read_region(bounds));
|
||||
assert!(d <= 1e-4, "tile seam {d}");
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,20 @@ pub fn dodge_burn(c: [f32; 3], e: f32, range: ToneRange, burn: bool, protect_ton
|
||||
}
|
||||
}
|
||||
|
||||
/// The default Midtones Dodge (`burn = false`) or Burn of one grey value `v` (0..1) in a Grayscale
|
||||
/// document or on a layer mask, at Exposure 50 % with Protect Tones on: `v + 0.094·v^0.2·(1 − v)`
|
||||
/// for Dodge and `v − 0.236·v·(1 − v)^1.15` for Burn. Both are fitted to the reference's 8-bit
|
||||
/// single-channel results (#12689, #12675), which differ from what an RGB grey gets; each lands
|
||||
/// within 1 level of the six measured greys. Black and white stay put, tones stay in order, and
|
||||
/// values outside 0..1 are returned as they are.
|
||||
#[inline]
|
||||
pub fn single_channel_midtones(v: f32, burn: bool) -> f32 {
|
||||
if !(v > 0.0 && v < 1.0) {
|
||||
return v;
|
||||
}
|
||||
if burn { v - 0.236 * v * (1.0 - v).powf(1.15) } else { v + 0.094 * v.powf(0.2) * (1.0 - v) }
|
||||
}
|
||||
|
||||
/// HSV-style saturation (chroma / max) of an RGB triple.
|
||||
#[inline]
|
||||
pub fn saturation(c: [f32; 3]) -> f32 {
|
||||
@@ -301,7 +315,12 @@ const PROTECT_DETAIL_LIMIT: f32 = 6.0 / 255.0;
|
||||
/// low halo a few pixels wide, and each difference is soft-limited to `L` = 6 levels:
|
||||
/// `v + amount·d·L/(L + |d|)`. Fine detail is sharpened about as much as without it, while a
|
||||
/// strong edge or a lone bright pixel moves by less than `L` per pass instead of overshooting.
|
||||
/// Uniform areas stay exactly as they are. Alpha is left unchanged.
|
||||
/// Uniform areas stay exactly as they are.
|
||||
///
|
||||
/// Without `protect_detail`, alpha is sharpened by the same rule as colour and clamped to 0..1
|
||||
/// (#12940): a semi-transparent edge gets crisper while the colour stays, since the colour is
|
||||
/// blurred premultiplied. An opaque pixel next to a transparent one stays as it is, because the
|
||||
/// clamp holds both at their limits. With `protect_detail`, alpha is left unchanged (not measured).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn local_sharpen(
|
||||
data: &[f32],
|
||||
@@ -332,7 +351,7 @@ pub fn local_sharpen(
|
||||
for c in 0..ch {
|
||||
let v = data[i + c];
|
||||
if Some(c) == alpha {
|
||||
dst[o + c] = v;
|
||||
dst[o + c] = if protect_detail { v } else { (v + amount * (v - blur_row[o + c])).clamp(0.0, 1.0) };
|
||||
continue;
|
||||
}
|
||||
let d = v - blur_row[o + c];
|
||||
|
||||
@@ -32,6 +32,37 @@ use photocraft_geom::Rect;
|
||||
|
||||
use super::{FREE, HARD_FG, Region, RgbImage, Sampler};
|
||||
|
||||
/// What a transparent pixel reads as for the cut: a colour far outside `0..=1`, so the edge from
|
||||
/// any opaque colour into transparency is as cheap to cut as an edge can be.
|
||||
const TRANSPARENT: f32 = -2.0;
|
||||
|
||||
/// The pixels Quick Selection cuts (#12921). Transparency is an edge: a transparent pixel reads as
|
||||
/// a colour far from every opaque one (partly transparent pixels in proportion), not as the
|
||||
/// mid-grey [`RgbImage::from_rgba`] puts behind it for the other tools. On a layer whose shapes sit
|
||||
/// on transparency, that grey matched mid-tone content (a grey ramp from 100 to 145 brackets it),
|
||||
/// so the shapes' outline was no edge and the cut fell on the ramp's 5-level steps instead. The
|
||||
/// reference application stops at the outline. Opaque pixels read as before. Only the pixels of an 8-bit RGB layer are cut through it: the composite, whose transparent parts keep the grey, groups and other depths are not.
|
||||
pub struct CutSampler<'a>(pub &'a dyn Sampler);
|
||||
|
||||
impl Sampler for CutSampler<'_> {
|
||||
fn rgba(&self, r: Rect) -> Vec<[f32; 4]> {
|
||||
self.0.rgba(r)
|
||||
}
|
||||
|
||||
fn rgb(&self, r: Rect) -> RgbImage {
|
||||
let px = self
|
||||
.0
|
||||
.rgba(r)
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let a = if p[3].is_finite() { p[3].clamp(0.0, 1.0) } else { 0.0 };
|
||||
[0, 1, 2].map(|c| p[c].clamp(0.0, 1.0) * a + TRANSPARENT * (1.0 - a))
|
||||
})
|
||||
.collect();
|
||||
RgbImage { w: r.width() as usize, h: r.height() as usize, px }
|
||||
}
|
||||
}
|
||||
|
||||
/// The model's constants (see the module docs); [`Tuning::default`] is the fit to Photoshop.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Tuning {
|
||||
@@ -364,3 +395,7 @@ pub fn upsample(low: &[bool], lw: usize, lh: usize, step: usize, w: usize, h: us
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "quick_ramp_tests.rs"]
|
||||
mod quick_ramp_tests;
|
||||
@@ -0,0 +1,111 @@
|
||||
//! #12921: on a layer whose shapes sit on transparency, a Quick Selection click or drag on a soft
|
||||
//! grey ramp (ten 40 px blocks, 100 to 145 in 5-level steps) selects the whole ramp, as the
|
||||
//! reference application does and as the composite already did, instead of stopping at the steps.
|
||||
//! Transparency is an edge for the cut. A click on a red rectangle still selects it alone.
|
||||
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
use super::{CutSampler, quick_select};
|
||||
use crate::segment::{Region, Sampler};
|
||||
|
||||
/// The issue's layer: 800 × 600, transparent but for red 1 (100,100–300,250), red 2
|
||||
/// (500,100–600,200) and the grey ramp at y 350–450 (ten 40 px blocks from x 100, values 100,
|
||||
/// 105, …, 145). `composite` puts it over white, as the document's composite reads.
|
||||
struct Layer {
|
||||
composite: bool,
|
||||
}
|
||||
|
||||
const RAMP: Rect = Rect { x0: 100, y0: 350, x1: 500, y1: 450 };
|
||||
const RED1: Rect = Rect { x0: 100, y0: 100, x1: 300, y1: 250 };
|
||||
const RED2: Rect = Rect { x0: 500, y0: 100, x1: 600, y1: 200 };
|
||||
const CANVAS: Rect = Rect { x0: 0, y0: 0, x1: 800, y1: 600 };
|
||||
|
||||
impl Layer {
|
||||
fn px(&self, x: i32, y: i32) -> [f32; 4] {
|
||||
let red = [220.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0, 1.0];
|
||||
if RED1.contains(x, y) || RED2.contains(x, y) {
|
||||
return red;
|
||||
}
|
||||
if RAMP.contains(x, y) {
|
||||
let v = (100 + 5 * ((x - 100) / 40)) as f32 / 255.0;
|
||||
return [v, v, v, 1.0];
|
||||
}
|
||||
if self.composite { [1.0; 4] } else { [0.0; 4] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Sampler for Layer {
|
||||
fn rgba(&self, r: Rect) -> Vec<[f32; 4]> {
|
||||
(r.y0..r.y1).flat_map(|y| (r.x0..r.x1).map(move |x| (x, y))).map(|(x, y)| self.px(x, y)).collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn select(sampler: &dyn Sampler, points: &[(f32, f32)], size: f32) -> Region {
|
||||
quick_select(&CutSampler(sampler), CANVAS, points, size).expect("the stroke is on the canvas")
|
||||
}
|
||||
|
||||
/// Every pixel of the ramp selected: fully, 2 px in from its outline (the outline itself is soft
|
||||
/// at the half resolution an 800 × 600 document is cut at).
|
||||
fn covers_ramp(r: &Region) -> bool {
|
||||
(RAMP.y0 + 2..RAMP.y1 - 2).step_by(3).all(|y| (RAMP.x0 + 2..RAMP.x1 - 2).step_by(3).all(|x| r.at(x, y) == 1.0))
|
||||
}
|
||||
|
||||
/// The whole ramp and nothing a pixel past it.
|
||||
fn is_whole_ramp(r: &Region) -> bool {
|
||||
let inside = covers_ramp(r);
|
||||
let b = r.bbox;
|
||||
inside && (b.x0 - RAMP.x0).abs() <= 1 && (b.y0 - RAMP.y0).abs() <= 1 && (b.x1 - RAMP.x1).abs() <= 1 && (b.y1 - RAMP.y1).abs() <= 1
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_the_first_block_selects_the_whole_ramp() {
|
||||
let r = select(&Layer { composite: false }, &[(120.0, 400.0)], 30.0);
|
||||
assert!(is_whole_ramp(&r), "bounds {:?}", r.bbox);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_the_120_block_selects_the_whole_ramp() {
|
||||
let r = select(&Layer { composite: false }, &[(280.0, 400.0)], 30.0);
|
||||
assert!(is_whole_ramp(&r), "bounds {:?}", r.bbox);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_along_the_ramp_selects_the_whole_ramp() {
|
||||
let drag: Vec<(f32, f32)> = (0..=16).map(|i| (180.0 + 10.0 * i as f32, 400.0)).collect();
|
||||
let r = select(&Layer { composite: false }, &drag, 30.0);
|
||||
assert!(is_whole_ramp(&r), "bounds {:?}", r.bbox);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn size_100_on_the_first_block_selects_the_whole_ramp() {
|
||||
// The whole ramp. The 100 px brush disc also reaches over the ramp's outline onto
|
||||
// transparency, and the footprint is always selected; dropping transparent pixels from the
|
||||
// result is #12918, so here only the ramp and the disc may be selected.
|
||||
let r = select(&Layer { composite: false }, &[(120.0, 400.0)], 100.0);
|
||||
assert!(covers_ramp(&r), "bounds {:?}", r.bbox);
|
||||
// The ramp's outline is soft by a pixel either side.
|
||||
let past = |x: i32, y: i32| r.at(x, y) > 0.0 && !RAMP.inflate(1).contains(x, y);
|
||||
// The footprint is the 50 px radius grown by `grow + grow_frac * radius` working pixels
|
||||
// (about 8.5 document pixels at half resolution), plus the soft half-resolution edge.
|
||||
let disc = |x: i32, y: i32| ((x as f32 - 120.0).powi(2) + (y as f32 - 400.0).powi(2)).sqrt() <= 62.0;
|
||||
assert!((CANVAS.y0..CANVAS.y1).all(|y| (CANVAS.x0..CANVAS.x1).all(|x| !past(x, y) || disc(x, y))), "nothing past the ramp but the brush disc");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_red_1_selects_red_1_alone() {
|
||||
let r = select(&Layer { composite: false }, &[(200.0, 175.0)], 30.0);
|
||||
let b = r.bbox;
|
||||
assert!((b.x0 - RED1.x0).abs() <= 1 && (b.y0 - RED1.y0).abs() <= 1 && (b.x1 - RED1.x1).abs() <= 1 && (b.y1 - RED1.y1).abs() <= 1, "{b:?}");
|
||||
assert_eq!(r.at(550, 150), 0.0, "red 2 stays unselected");
|
||||
assert_eq!(r.at(120, 400), 0.0, "the ramp stays unselected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_composite_reads_as_before() {
|
||||
// Opaque everywhere: the cut sampler changes nothing, the ramp was already whole.
|
||||
let layer = Layer { composite: true };
|
||||
let plain = quick_select(&layer, CANVAS, &[(180.0, 400.0)], 30.0).unwrap();
|
||||
let cut = select(&layer, &[(180.0, 400.0)], 30.0);
|
||||
assert_eq!((plain.bbox, &plain.mask), (cut.bbox, &cut.mask));
|
||||
assert!(is_whole_ramp(&cut));
|
||||
}
|
||||
@@ -170,6 +170,36 @@ pub fn combine(old: Option<&Surface>, new: &[f32], area: Rect, mode: SelectionMo
|
||||
(s.tile_count() > 0).then_some(s)
|
||||
}
|
||||
|
||||
/// [`combine`] for a channel loaded as a selection, with Photoshop's channel arithmetic: where
|
||||
/// coverage is partial, Add screens (`a + b − a·b`), Subtract keeps what `new` leaves
|
||||
/// (`a·(1 − b)`) and Intersect multiplies (`a·b`). Intersecting a luminosity selection with the
|
||||
/// luminosity again so narrows it to brighter tones at every step (a 50% grey goes 50%, 25%,
|
||||
/// 12.5%, … while white stays selected), and Select All minus the lights minus the darks leaves
|
||||
/// the midtones; [`combine`]'s min and max would leave the first unchanged and the second empty.
|
||||
/// Fully selected and unselected pixels combine as in [`combine`]. Source: Greg Benz, "Photoshop
|
||||
/// channel math: add, subtract, intersect" (gregbenzphotography.com, luminosity-masking).
|
||||
pub fn combine_scaled(old: Option<&Surface>, new: &[f32], area: Rect, mode: SelectionMode) -> Option<Surface> {
|
||||
if area.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if mode == SelectionMode::Replace || (old.is_none() && mode == SelectionMode::Add) {
|
||||
return combine(old, new, area, mode);
|
||||
}
|
||||
let old = old?;
|
||||
if old.format() == PixelFormat::GRAY8 {
|
||||
return combine_mask::gray8_with(Some(old), new, area, mode, false, combine_mask::Arithmetic::Scaled);
|
||||
}
|
||||
// Quantized to the 8-bit grid first, as in `combine`, so the float path agrees with the GRAY8 one.
|
||||
let q = |v: f32| f32::from(coverage8(v)) / 255.0;
|
||||
let prev = mask_from_surface(Some(old), area);
|
||||
let s = match mode {
|
||||
SelectionMode::Add => surface_from_masks(area, new, Some(&prev), |p, v| p + q(v) - p * q(v)),
|
||||
SelectionMode::Subtract => surface_from_masks(area, new, Some(&prev), |p, v| p * (1.0 - q(v))),
|
||||
_ => surface_from_masks(area, new, Some(&prev), |p, v| p * q(v)),
|
||||
};
|
||||
(s.tile_count() > 0).then_some(s)
|
||||
}
|
||||
|
||||
fn close(a: [f32; 4], b: [f32; 4], tol: f32) -> bool {
|
||||
(a[3] == 0.0 && b[3] == 0.0) || (0..4).all(|c| (a[c] - b[c]).abs() * 255.0 <= tol + 1e-3)
|
||||
}
|
||||
@@ -279,6 +309,52 @@ pub fn rgba8_image(s: &Surface, area: Rect) -> Vec<[u8; 4]> {
|
||||
img
|
||||
}
|
||||
|
||||
/// The surface's own stored channels over `area` as 0–255 levels: `channels()` bytes per pixel,
|
||||
/// no colour conversion and no reordering. Unlike [`rgba8_image`], which reads the picture as
|
||||
/// RGB, a Lab surface gives its stored Lightness, a and b and a CMYK surface its four inks, the
|
||||
/// alpha last when the surface has one. Read in parallel bands like [`rgba8_image`].
|
||||
///
|
||||
/// The Magic Wand measures a document's Tolerance on these channels for the modes and depths the
|
||||
/// reference measures it there (#11785), where reading the picture as RGB would measure the
|
||||
/// Tolerance in a colour space the document is not in. For an 8-bit surface the levels are the
|
||||
/// stored bytes exactly; a deeper surface is quantized to the 8-bit grid here, so where this is
|
||||
/// the right read stays the caller's decision.
|
||||
/// Band rows for the parallel readers of [`stored_levels_planes`]: `read_region_into` hands back
|
||||
/// f32 samples, so an unrestricted 256-row band stages ~25 MB per worker on a wide multi-channel
|
||||
/// area (6000 px CMYK: 16 workers × ~24 MB of floats before quantizing). Keep one worker's f32
|
||||
/// staging near 2 MB; the u8 output plane is the larger fixed cost either way (#11785 review).
|
||||
fn levels_band_rows(w: usize, ch: usize) -> usize {
|
||||
let per_row = (w * ch * 4).max(1);
|
||||
(2u64 << 20).checked_div(per_row as u64).unwrap_or(256).clamp(16, 256) as usize
|
||||
}
|
||||
|
||||
pub fn stored_levels_planes(s: &Surface, area: Rect) -> Vec<u8> {
|
||||
let (w, h, ch) = (area.width() as usize, area.height() as usize, s.channels());
|
||||
let mut data = vec![0u8; w * h * ch];
|
||||
if w == 0 || h == 0 {
|
||||
return data;
|
||||
}
|
||||
let band = levels_band_rows(w, ch);
|
||||
let q = |v: f32| (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
|
||||
let read = |bi: usize, chunk: &mut [u8]| {
|
||||
let y0 = area.y0 + (bi * band) as i32;
|
||||
let rows = chunk.len() / (w * ch);
|
||||
let mut px = Vec::new();
|
||||
s.read_region_into(Rect::new(area.x0, y0, area.x1, y0 + rows as i32), &mut px);
|
||||
for (d, v) in chunk.iter_mut().zip(px) {
|
||||
*d = q(v);
|
||||
}
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
use rayon::prelude::*;
|
||||
data.par_chunks_mut(w * band * ch).enumerate().for_each(|(bi, c)| read(bi, c));
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
data.chunks_mut(w * band * ch).enumerate().for_each(|(bi, c)| read(bi, c));
|
||||
data
|
||||
}
|
||||
|
||||
/// A selected region: 8-bit coverage over `bbox` (row-major), the bounding box of the pixels
|
||||
/// touched (including the anti-aliased fringe).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -299,6 +375,38 @@ impl Region {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a difference of exactly `tolerance` levels still matches a Magic Wand seed.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum WandBound {
|
||||
/// A difference of at most `tolerance` levels matches (≤). What the tools that sample the
|
||||
/// picture as 8-bit RGBA do, and what their Tolerance has always meant.
|
||||
AtMost,
|
||||
/// A difference of *below* `tolerance` levels matches (<), with Tolerance 0 and 1 both
|
||||
/// meaning "the same colour". The wand uses this on a document's own colour channels, where
|
||||
/// the reference's Tolerance is measured finer than the document's 8-bit grid (#11785: see
|
||||
/// [`wand_region_on`]).
|
||||
Below,
|
||||
}
|
||||
|
||||
/// Integer greatest difference still matching `bound`, in stored levels.
|
||||
fn wand_max_diff(tolerance: f32, bound: WandBound) -> i32 {
|
||||
match bound {
|
||||
WandBound::AtMost => (tolerance + 1e-3).floor().max(0.0) as i32,
|
||||
// `d < tolerance` on whole levels, so Tolerance 5 keeps differences 0..=4. A NaN or a
|
||||
// negative Tolerance keeps exactly the same colour rather than selecting nothing, and a
|
||||
// Tolerance past the scale keeps every difference.
|
||||
WandBound::Below => {
|
||||
if tolerance.is_nan() || tolerance <= 1.0 {
|
||||
0
|
||||
} else if tolerance >= 256.0 {
|
||||
255
|
||||
} else {
|
||||
tolerance.ceil() as i32 - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How a wand-style fill measures how far an 8-bit colour is from the clicked one.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ColorDistance {
|
||||
@@ -320,6 +428,28 @@ impl ColorDistance {
|
||||
}
|
||||
}
|
||||
|
||||
/// The most channels the Magic Wand compares at once: a CMYK document's four inks and an alpha.
|
||||
pub const MAX_WAND_CHANNELS: usize = 5;
|
||||
|
||||
/// The picture the Magic Wand measures its Tolerance on: `channels` stored levels (0–255) per
|
||||
/// pixel over `area`, with `alpha` the index of the alpha channel when the picture has one.
|
||||
/// [`rgba8_image`] reads the picture as RGB; [`stored_levels_planes`] gives a document its own
|
||||
/// colour channels.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct WandPixels<'a> {
|
||||
pub area: Rect,
|
||||
pub data: &'a [u8],
|
||||
pub channels: usize,
|
||||
pub alpha: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> WandPixels<'a> {
|
||||
/// Straight 8-bit RGBA over `area`: what [`rgba8_image`] reads, as `w * h * 4` bytes.
|
||||
pub fn rgba(area: Rect, data: &'a [u8]) -> Self {
|
||||
Self { area, data, channels: 4, alpha: Some(3) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Magic wand on 8-bit pixels: a scanline flood fill (or a global match) that only allocates a
|
||||
/// byte mark per pixel, then anti-aliases just the edges inside the touched bounding box.
|
||||
/// Matches [`magic_wand`] for 8-bit sources. `None` if the seed is outside `area`.
|
||||
@@ -355,37 +485,70 @@ pub fn wand_region_by(
|
||||
within: Option<&[f32]>,
|
||||
distance: ColorDistance,
|
||||
) -> Option<Region> {
|
||||
region_by_rule(img, area, seed, tolerance, contiguous, anti_alias, within, distance, MatchRule::Wand)
|
||||
region_by_rule(img, area, seed, None, tolerance, contiguous, anti_alias, within, distance, MatchRule::Wand)
|
||||
}
|
||||
|
||||
/// [`wand_region_within`] comparing every pixel against `reference` instead of the clicked pixel's
|
||||
/// own colour: the Magic Wand's Sample Size average (#11777). The image stays as it is, so in a
|
||||
/// global match (`contiguous` off) the clicked pixel is taken only when it is within Tolerance of
|
||||
/// `reference` too; a contiguous fill finds nothing when the clicked pixel is not.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn wand_region_with_reference(
|
||||
img: &[[u8; 4]],
|
||||
area: Rect,
|
||||
seed: (i32, i32),
|
||||
reference: [u8; 4],
|
||||
tolerance: f32,
|
||||
contiguous: bool,
|
||||
anti_alias: bool,
|
||||
within: Option<&[f32]>,
|
||||
) -> Option<Region> {
|
||||
region_by_rule(img, area, seed, Some(reference), tolerance, contiguous, anti_alias, within, ColorDistance::LargestChannel, MatchRule::Wand)
|
||||
}
|
||||
|
||||
/// Which Paint Bucket inputs use the measured visible-alpha class (#17733).
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum BucketAlpha<'a> {
|
||||
/// RGB/8 samples: all nonzero alpha values belong to one class.
|
||||
Visible,
|
||||
/// RGB/16: apply the measured rule only to alpha values on the 8-bit step lattice.
|
||||
Stepped16(&'a Surface),
|
||||
/// Unmeasured modes, depths and transparency-locked fills retain their previous alpha band.
|
||||
Band,
|
||||
}
|
||||
|
||||
/// Whether a stored 16-bit alpha is an exact 8-bit step. Intermediate values were not measured
|
||||
/// for #17733, so a match involving one keeps the previous rule without allocating another image.
|
||||
fn alpha_on_8bit_step(surface: &Surface, x: i32, y: i32) -> bool {
|
||||
((surface.sample_channel(x, y, 3) * 65535.0).round() as u32).is_multiple_of(257)
|
||||
}
|
||||
|
||||
/// Which pixels count as "similar" to the clicked one.
|
||||
#[derive(Clone, Copy)]
|
||||
enum MatchRule {
|
||||
enum MatchRule<'a> {
|
||||
/// The Magic Wand / Magic Eraser rule: colour and alpha each within Tolerance, except that
|
||||
/// two fully transparent pixels always match.
|
||||
Wand,
|
||||
/// The Paint Bucket rule, see [`wand_region_bucket`].
|
||||
Bucket,
|
||||
Bucket(BucketAlpha<'a>),
|
||||
}
|
||||
|
||||
/// [`wand_region`] with the Paint Bucket's match rule (measured on the reference, #12529).
|
||||
/// [`wand_region`] with the Paint Bucket's match rule (#12529, #17733).
|
||||
///
|
||||
/// It differs from the wand rule only when the clicked pixel is not opaque. The wand lets any
|
||||
/// pixel whose alpha is within Tolerance of the seed's match, so a bucket click on transparent
|
||||
/// pixels leaked into the anti-aliased edge of a shape and, at Tolerance 255, filled the whole
|
||||
/// layer (#6183). The bucket rule is:
|
||||
/// - seed alpha 0: only pixels with alpha 0 match; Tolerance plays no role;
|
||||
/// - seed alpha 255: unchanged (colour and alpha each within Tolerance);
|
||||
/// - seed alpha in between: a pixel of the seed's own colour matches when its alpha is
|
||||
/// above 0 — there is no alpha band for that case (alpha 40, 197 and 253 of one colour
|
||||
/// were measured to fill together). A pixel of any other colour must also sit within
|
||||
/// Tolerance of the seed's alpha, as before: that case was not measured, and unmeasured
|
||||
/// cases keep today's behaviour. Alpha-0 pixels are never taken.
|
||||
///
|
||||
/// Only that one semi-transparent case was measured; unmeasured cases keep the previous
|
||||
/// behaviour. [`wand_region`] and [`wand_region_within`] are unchanged.
|
||||
pub(crate) fn wand_region_bucket(img: &[[u8; 4]], area: Rect, seed: (i32, i32), tolerance: f32, contiguous: bool, anti_alias: bool) -> Option<Region> {
|
||||
region_by_rule(img, area, seed, tolerance, contiguous, anti_alias, None, ColorDistance::LargestChannel, MatchRule::Bucket)
|
||||
/// A transparent seed matches only alpha-zero pixels, independently of their hidden colour.
|
||||
/// For measured RGB/8 and RGB/16 samples, a visible seed matches every nonzero-alpha pixel
|
||||
/// whose straight colour is within Tolerance. Alpha otherwise plays no part. The caller's
|
||||
/// `alpha` rule preserves the previous alpha band for inputs that were not measured.
|
||||
pub(crate) fn wand_region_bucket(
|
||||
img: &[[u8; 4]],
|
||||
area: Rect,
|
||||
seed: (i32, i32),
|
||||
tolerance: f32,
|
||||
contiguous: bool,
|
||||
anti_alias: bool,
|
||||
alpha: BucketAlpha<'_>,
|
||||
) -> Option<Region> {
|
||||
region_by_rule(img, area, seed, None, tolerance, contiguous, anti_alias, None, ColorDistance::LargestChannel, MatchRule::Bucket(alpha))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -393,12 +556,13 @@ fn region_by_rule(
|
||||
img: &[[u8; 4]],
|
||||
area: Rect,
|
||||
seed: (i32, i32),
|
||||
reference: Option<[u8; 4]>,
|
||||
tolerance: f32,
|
||||
contiguous: bool,
|
||||
anti_alias: bool,
|
||||
within: Option<&[f32]>,
|
||||
distance: ColorDistance,
|
||||
rule: MatchRule,
|
||||
rule: MatchRule<'_>,
|
||||
) -> Option<Region> {
|
||||
if !area.contains(seed.0, seed.1) {
|
||||
return None;
|
||||
@@ -412,18 +576,42 @@ fn region_by_rule(
|
||||
if !inside((seed.1 - area.y0) as usize * w + (seed.0 - area.x0) as usize) {
|
||||
return None;
|
||||
}
|
||||
let target = img[(seed.1 - area.y0) as usize * w + (seed.0 - area.x0) as usize];
|
||||
let seed_px = img[(seed.1 - area.y0) as usize * w + (seed.0 - area.x0) as usize];
|
||||
let target = reference.unwrap_or(seed_px);
|
||||
let tol = (tolerance + 1e-3).floor().max(0.0) as i32;
|
||||
// Copying a selection can leave RGB under zero alpha. Those invisible colours must not
|
||||
// split a transparent region into pieces, as if the copied source were still visible.
|
||||
let similar = |p: [u8; 4]| match rule {
|
||||
MatchRule::Wand => (target[3] == 0 && p[3] == 0) || (distance.rgb(p, target) <= tol && (p[3] as i32 - target[3] as i32).abs() <= tol),
|
||||
MatchRule::Bucket => match target[3] {
|
||||
0 => p[3] == 0,
|
||||
255 => distance.rgb(p, target) <= tol && (p[3] as i32 - 255).abs() <= tol,
|
||||
_ => p[3] != 0 && distance.rgb(p, target) <= tol && (p[..3] == target[..3] || (p[3] as i32 - target[3] as i32).abs() <= tol),
|
||||
},
|
||||
let stepped_seed = match rule {
|
||||
MatchRule::Bucket(BucketAlpha::Stepped16(surface)) => alpha_on_8bit_step(surface, seed.0, seed.1),
|
||||
_ => true,
|
||||
};
|
||||
let similar = |i: usize| {
|
||||
let p = img[i];
|
||||
match rule {
|
||||
MatchRule::Wand => (target[3] == 0 && p[3] == 0) || (distance.rgb(p, target) <= tol && (p[3] as i32 - target[3] as i32).abs() <= tol),
|
||||
MatchRule::Bucket(alpha) => {
|
||||
let visible_class = match alpha {
|
||||
BucketAlpha::Visible => true,
|
||||
BucketAlpha::Stepped16(surface) => stepped_seed && alpha_on_8bit_step(surface, area.x0 + (i % w) as i32, area.y0 + (i / w) as i32),
|
||||
BucketAlpha::Band => false,
|
||||
};
|
||||
if visible_class {
|
||||
if target[3] == 0 { p[3] == 0 } else { p[3] != 0 && distance.rgb(p, target) <= tol }
|
||||
} else {
|
||||
match target[3] {
|
||||
0 => p[3] == 0,
|
||||
255 => distance.rgb(p, target) <= tol && (p[3] as i32 - 255).abs() <= tol,
|
||||
_ => p[3] != 0 && distance.rgb(p, target) <= tol && (p[..3] == target[..3] || (p[3] as i32 - target[3] as i32).abs() <= tol),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// A clicked pixel that is not similar to the reference starts no region. Without a separate
|
||||
// reference it is the reference, so this holds for every rule.
|
||||
if !similar((seed.1 - area.y0) as usize * w + (seed.0 - area.x0) as usize) {
|
||||
return None;
|
||||
}
|
||||
let mut marks = vec![0u8; w * h];
|
||||
let (mut bx0, mut by0, mut bx1, mut by1) = (usize::MAX, usize::MAX, 0usize, 0usize);
|
||||
if contiguous {
|
||||
@@ -435,10 +623,10 @@ fn region_by_rule(
|
||||
continue;
|
||||
}
|
||||
let (mut l, mut r) = (x, x);
|
||||
while l > 0 && marks[row + l - 1] == 0 && similar(img[row + l - 1]) && inside(row + l - 1) {
|
||||
while l > 0 && marks[row + l - 1] == 0 && similar(row + l - 1) && inside(row + l - 1) {
|
||||
l -= 1;
|
||||
}
|
||||
while r + 1 < w && marks[row + r + 1] == 0 && similar(img[row + r + 1]) && inside(row + r + 1) {
|
||||
while r + 1 < w && marks[row + r + 1] == 0 && similar(row + r + 1) && inside(row + r + 1) {
|
||||
r += 1;
|
||||
}
|
||||
marks[row + l..=row + r].fill(255);
|
||||
@@ -450,7 +638,7 @@ fn region_by_rule(
|
||||
let nrow = ny * w;
|
||||
let mut in_run = false;
|
||||
for nx in l..=r {
|
||||
let ok = marks[nrow + nx] == 0 && similar(img[nrow + nx]) && inside(nrow + nx);
|
||||
let ok = marks[nrow + nx] == 0 && similar(nrow + nx) && inside(nrow + nx);
|
||||
if ok && !in_run {
|
||||
stack.push((nx, ny));
|
||||
}
|
||||
@@ -462,7 +650,7 @@ fn region_by_rule(
|
||||
let scan = |y: usize, row: &mut [u8]| -> Option<(usize, usize)> {
|
||||
let mut span: Option<(usize, usize)> = None;
|
||||
for (x, m) in row.iter_mut().enumerate() {
|
||||
if similar(img[y * w + x]) {
|
||||
if similar(y * w + x) {
|
||||
*m = 255;
|
||||
span = Some(span.map_or((x, x), |(a, _)| (a, x)));
|
||||
}
|
||||
@@ -517,6 +705,211 @@ fn region_by_rule(
|
||||
Some(Region { bbox, mask })
|
||||
}
|
||||
|
||||
/// How [`wand_region_on`] matches pixels against the clicked one.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct WandMatch<'a> {
|
||||
pub tolerance: f32,
|
||||
pub contiguous: bool,
|
||||
pub anti_alias: bool,
|
||||
/// Whether a difference of exactly `tolerance` still matches.
|
||||
pub bound: WandBound,
|
||||
/// The selection's coverage over the area, which a contiguous fill stays inside (#11779).
|
||||
pub within: Option<&'a [f32]>,
|
||||
/// How an RGBA picture's colour difference is measured; other pictures compare each channel.
|
||||
pub distance: ColorDistance,
|
||||
/// The colour every pixel is compared against instead of the clicked pixel's, one level per
|
||||
/// channel of the picture (the rest ignored): the Magic Wand's Sample Size average (#11777).
|
||||
/// The clicked pixel must itself be within Tolerance of it, or the fill finds nothing.
|
||||
pub reference: Option<[u8; MAX_WAND_CHANNELS]>,
|
||||
}
|
||||
|
||||
impl WandMatch<'_> {
|
||||
/// A plain match: no selection limit, the largest channel difference.
|
||||
pub fn new(tolerance: f32, contiguous: bool, anti_alias: bool, bound: WandBound) -> Self {
|
||||
Self { tolerance, contiguous, anti_alias, bound, within: None, distance: ColorDistance::LargestChannel, reference: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// [`wand_region`] over any [`WandPixels`] with the Tolerance bound chosen: RGBA with
|
||||
/// [`WandBound::AtMost`] is [`wand_region`] itself; [`WandBound::Below`] is how the Magic Wand
|
||||
/// measures a document's own colour channels (#11785). `None` when the seed is outside the area
|
||||
/// or the picture is not something the wand can compare.
|
||||
///
|
||||
/// Why the document-channel comparison is exclusive at the bound: the reference measures Tolerance
|
||||
/// on the document's channels, finer than an 8-bit document stores them. Its Lab row (8-bit
|
||||
/// document, grey ramp of ten 40 px blocks 100, 105, … 145, click on the 100 block) says
|
||||
/// Tolerance 5 reaches only the 100 block and Tolerance 32 up to the 130 block, while this
|
||||
/// document stores Lightness 108, 113, 118, 124, … 153 (L\* / 100 × 255): steps of 0, 5, 10, 16,
|
||||
/// …, 31, 36 levels, of which 5 (5.2 unrounded) must not match at Tolerance 5 and 31 (30.6) must
|
||||
/// at Tolerance 32. The re-measured dither-free CMYK ramp (same issue, comment 6705983844) has
|
||||
/// largest ink steps of 7, 13, 19, 25, 31, 37 from the seed, and its two required cells —
|
||||
/// Tolerance 5 to x 100-140 and Tolerance 32 to x 100-340 — fall out either way, so the document
|
||||
/// channels share this one bound.
|
||||
pub fn wand_region_on(px: &WandPixels, seed: (i32, i32), how: &WandMatch) -> Option<Region> {
|
||||
// RGBA under the inclusive bound is the RGB Magic Wand: it keeps the Magic Eraser's
|
||||
// shared wand rule. A generic per-channel fill measured 1.2-1.6x slower on a
|
||||
// full 24 MP contiguous fill (#11882 review), so only the document channels take it.
|
||||
if px.channels == 4 && px.alpha == Some(3) && how.bound == WandBound::AtMost {
|
||||
let (img, _) = px.data.as_chunks::<4>();
|
||||
let reference = how.reference.map(|r| [r[0], r[1], r[2], r[3]]);
|
||||
return region_by_rule(img, px.area, seed, reference, how.tolerance, how.contiguous, how.anti_alias, how.within, how.distance, MatchRule::Wand);
|
||||
}
|
||||
if !px.area.contains(seed.0, seed.1) || px.channels == 0 || px.channels > MAX_WAND_CHANNELS {
|
||||
return None;
|
||||
}
|
||||
// One fill per channel count: the comparison runs per pixel over the canvas.
|
||||
match px.channels {
|
||||
1 => wand_fill::<1>(px, seed, how),
|
||||
2 => wand_fill::<2>(px, seed, how),
|
||||
3 => wand_fill::<3>(px, seed, how),
|
||||
4 => wand_fill::<4>(px, seed, how),
|
||||
_ => wand_fill::<5>(px, seed, how),
|
||||
}
|
||||
}
|
||||
|
||||
/// [`wand_region_on`] for `CH` stored channels per pixel, under the wand rule.
|
||||
fn wand_fill<const CH: usize>(px: &WandPixels, seed: (i32, i32), how: &WandMatch) -> Option<Region> {
|
||||
let (contiguous, anti_alias) = (how.contiguous, how.anti_alias);
|
||||
let (w, h) = (px.area.width() as usize, px.area.height() as usize);
|
||||
if w.checked_mul(h).is_none_or(|n| n > px.data.len() / CH) {
|
||||
return None;
|
||||
}
|
||||
let within = how.within.filter(|_| how.contiguous).filter(|m| m.len() >= w * h);
|
||||
let inside = |i: usize| within.is_none_or(|m| m.get(i).is_some_and(|v| *v >= 0.5));
|
||||
let seed_i = (seed.1 - px.area.y0) as usize * w + (seed.0 - px.area.x0) as usize;
|
||||
if !inside(seed_i) {
|
||||
return None;
|
||||
}
|
||||
let so = seed_i * CH;
|
||||
let mut target = [0u8; CH];
|
||||
match how.reference {
|
||||
Some(r) => target.copy_from_slice(&r[..CH]),
|
||||
None => target.copy_from_slice(px.data.get(so..so + CH)?),
|
||||
}
|
||||
let alpha = px.alpha.filter(|&a| a < CH);
|
||||
let tol = wand_max_diff(how.tolerance, how.bound);
|
||||
let rgba = CH == 4 && alpha == Some(3);
|
||||
// How far pixel `i` is from the clicked one in colour (alpha left out), and the lower of the
|
||||
// two opacities (0-255; 255 without an alpha channel).
|
||||
let colour_diff = |i: usize| -> Option<(i32, f32)> {
|
||||
let v = px.data.get(i * CH..i * CH + CH)?;
|
||||
let d = if rgba {
|
||||
how.distance.rgb([v[0], v[1], v[2], v[3]], [target[0], target[1], target[2], target[3]])
|
||||
} else {
|
||||
(0..CH).filter(|&c| Some(c) != alpha).map(|c| (v[c] as i32 - target[c] as i32).abs()).max().unwrap_or(0)
|
||||
};
|
||||
Some((d, alpha.map_or(255.0, |a| f32::from(v[a].min(target[a])))))
|
||||
};
|
||||
// Copying a selection can leave colour under zero alpha. Those invisible colours must not
|
||||
// split a transparent region into pieces, as if the copied source were still visible.
|
||||
let similar = |i: usize| -> bool {
|
||||
let o = i * CH;
|
||||
let Some(v) = px.data.get(o..o + CH) else { return false };
|
||||
let d = colour_diff(i).map_or(i32::MAX, |(d, _)| d);
|
||||
let alpha_ok = alpha.is_none_or(|a| (v[a] as i32 - target[a] as i32).abs() <= tol);
|
||||
alpha.is_some_and(|a| target[a] == 0 && v[a] == 0) || (alpha_ok && d <= tol)
|
||||
};
|
||||
// A clicked pixel that is not similar to the reference starts no region. Without a separate
|
||||
// reference it is the reference, so this only matters for Sample Size.
|
||||
if !similar(seed_i) {
|
||||
return None;
|
||||
}
|
||||
let mut marks = vec![0u8; w * h];
|
||||
let (mut bx0, mut by0, mut bx1, mut by1) = (usize::MAX, usize::MAX, 0usize, 0usize);
|
||||
if contiguous {
|
||||
// Span fill: fill a run, then scan the rows above and below it for new seeds.
|
||||
let mut stack = vec![((seed.0 - px.area.x0) as usize, (seed.1 - px.area.y0) as usize)];
|
||||
while let Some((x, y)) = stack.pop() {
|
||||
let row = y * w;
|
||||
if marks[row + x] != 0 {
|
||||
continue;
|
||||
}
|
||||
let (mut l, mut r) = (x, x);
|
||||
while l > 0 && marks[row + l - 1] == 0 && similar(row + l - 1) && inside(row + l - 1) {
|
||||
l -= 1;
|
||||
}
|
||||
while r + 1 < w && marks[row + r + 1] == 0 && similar(row + r + 1) && inside(row + r + 1) {
|
||||
r += 1;
|
||||
}
|
||||
marks[row + l..=row + r].fill(255);
|
||||
(bx0, bx1, by0, by1) = (bx0.min(l), bx1.max(r), by0.min(y), by1.max(y));
|
||||
for ny in [y.wrapping_sub(1), y + 1] {
|
||||
if ny >= h {
|
||||
continue;
|
||||
}
|
||||
let nrow = ny * w;
|
||||
let mut in_run = false;
|
||||
for nx in l..=r {
|
||||
let ok = marks[nrow + nx] == 0 && similar(nrow + nx) && inside(nrow + nx);
|
||||
if ok && !in_run {
|
||||
stack.push((nx, ny));
|
||||
}
|
||||
in_run = ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let scan = |y: usize, row: &mut [u8]| -> Option<(usize, usize)> {
|
||||
let mut span: Option<(usize, usize)> = None;
|
||||
for (x, m) in row.iter_mut().enumerate() {
|
||||
if similar(y * w + x) {
|
||||
*m = 255;
|
||||
span = Some(span.map_or((x, x), |(a, _)| (a, x)));
|
||||
}
|
||||
}
|
||||
span
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let spans: Vec<Option<(usize, usize)>> = {
|
||||
use rayon::prelude::*;
|
||||
marks.par_chunks_mut(w).enumerate().map(|(y, row)| scan(y, row)).collect()
|
||||
};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let spans: Vec<Option<(usize, usize)>> = marks.chunks_mut(w).enumerate().map(|(y, row)| scan(y, row)).collect();
|
||||
for (y, sp) in spans.iter().enumerate() {
|
||||
if let Some((a, b)) = sp {
|
||||
(bx0, bx1, by0, by1) = (bx0.min(*a), bx1.max(*b), by0.min(y), by1.max(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
if bx0 == usize::MAX {
|
||||
return None;
|
||||
}
|
||||
// One pixel of fringe for anti-aliasing, clamped to the area.
|
||||
let pad = anti_alias as usize;
|
||||
let (x0, y0) = (bx0.saturating_sub(pad), by0.saturating_sub(pad));
|
||||
let (x1, y1) = ((bx1 + 1 + pad).min(w), (by1 + 1 + pad).min(h));
|
||||
let bw = x1 - x0;
|
||||
let at = |x: usize, y: usize| marks[y * w + x];
|
||||
let mut mask = vec![0u8; bw * (y1 - y0)];
|
||||
let fill_row = |yy: usize, out: &mut [u8]| {
|
||||
let y = y0 + yy;
|
||||
for (xx, o) in out.iter_mut().enumerate() {
|
||||
let x = x0 + xx;
|
||||
let v = at(x, y);
|
||||
*o = v;
|
||||
// Same rule as `magic_wand`: the region stays fully selected; a pixel just outside
|
||||
// it gets a fringe by how far its colour is past the tolerance.
|
||||
if anti_alias
|
||||
&& v == 0
|
||||
&& touches_region(x, y, w, h, |nx, ny| at(nx, ny) != 0)
|
||||
&& let Some((d, a)) = colour_diff(y * w + x)
|
||||
{
|
||||
*o = fringe_coverage((d - tol) as f32, a);
|
||||
}
|
||||
}
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
use rayon::prelude::*;
|
||||
mask.par_chunks_mut(bw).enumerate().for_each(|(yy, row)| fill_row(yy, row));
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mask.chunks_mut(bw).enumerate().for_each(|(yy, row)| fill_row(yy, row));
|
||||
let bbox = Rect::new(px.area.x0 + x0 as i32, px.area.y0 + y0 as i32, px.area.x0 + x1 as i32, px.area.y0 + y1 as i32);
|
||||
Some(Region { bbox, mask })
|
||||
}
|
||||
|
||||
/// Combines a [`Region`] with the current selection, touching only the region's box (outside it
|
||||
/// the new mask is zero). Returns `None` when nothing remains selected.
|
||||
pub fn combine_region(old: Option<&Surface>, new: Option<&Region>, mode: SelectionMode) -> Option<Surface> {
|
||||
@@ -1214,3 +1607,7 @@ impl ColorMatcher {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "selection_bucket_alpha_band_tests.rs"]
|
||||
mod bucket_alpha_band_tests;
|
||||
@@ -39,8 +39,45 @@ pub fn combine_band(old: Option<&Surface>, mask: &[f32], band: Rect, mode: Selec
|
||||
(out.tile_count() > 0).then_some(out)
|
||||
}
|
||||
|
||||
/// How two 8-bit coverages meet where both are partial. Fully selected and unselected pixels
|
||||
/// combine the same way under both.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum Arithmetic {
|
||||
/// The selection tools': Add keeps the larger coverage, Subtract takes the clipped
|
||||
/// difference and Intersect keeps the smaller.
|
||||
Extremes,
|
||||
/// A channel loaded as a selection (Photoshop's channel arithmetic): Add screens
|
||||
/// (`a + b − a·b`), Subtract keeps what the new coverage leaves (`a·(1 − b)`) and Intersect
|
||||
/// multiplies (`a·b`). Intersecting a partial selection with itself narrows it.
|
||||
Scaled,
|
||||
}
|
||||
|
||||
impl Arithmetic {
|
||||
pub(super) fn apply(self, mode: SelectionMode, prev: u8, new: u8) -> u8 {
|
||||
match (self, mode) {
|
||||
(_, SelectionMode::Replace) => new,
|
||||
(Arithmetic::Extremes, SelectionMode::Add) => prev.max(new),
|
||||
(Arithmetic::Extremes, SelectionMode::Subtract) => prev.saturating_sub(new),
|
||||
(Arithmetic::Extremes, SelectionMode::Intersect) => prev.min(new),
|
||||
(Arithmetic::Scaled, SelectionMode::Add) => u8::MAX - mul8(u8::MAX - prev, u8::MAX - new),
|
||||
(Arithmetic::Scaled, SelectionMode::Subtract) => mul8(prev, u8::MAX - new),
|
||||
(Arithmetic::Scaled, SelectionMode::Intersect) => mul8(prev, new),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `a·b / 255` rounded to the nearest byte, exactly, for every pair of bytes.
|
||||
pub(super) fn mul8(a: u8, b: u8) -> u8 {
|
||||
let t = u32::from(a) * u32::from(b) + 128;
|
||||
u8::try_from((t + (t >> 8)) >> 8).unwrap_or(u8::MAX)
|
||||
}
|
||||
|
||||
pub(super) fn gray8(old: Option<&Surface>, mask: &[f32], area: Rect, mode: SelectionMode, keep_outside: bool) -> Option<Surface> {
|
||||
build(old, area, mode, keep_outside, |i| coverage8(mask.get(i).copied().unwrap_or(0.0)))
|
||||
gray8_with(old, mask, area, mode, keep_outside, Arithmetic::Extremes)
|
||||
}
|
||||
|
||||
pub(super) fn gray8_with(old: Option<&Surface>, mask: &[f32], area: Rect, mode: SelectionMode, keep_outside: bool, arithmetic: Arithmetic) -> Option<Surface> {
|
||||
build(old, area, mode, keep_outside, arithmetic, |i| coverage8(mask.get(i).copied().unwrap_or(0.0)))
|
||||
}
|
||||
|
||||
pub(super) fn gray8_bytes(old: Option<&Surface>, mask: &[u8], area: Rect, mode: SelectionMode) -> Option<Surface> {
|
||||
@@ -48,10 +85,17 @@ pub(super) fn gray8_bytes(old: Option<&Surface>, mask: &[u8], area: Rect, mode:
|
||||
if area.is_empty() {
|
||||
return if keep { old.cloned().filter(|s| !s.content_bounds().is_empty()) } else { None };
|
||||
}
|
||||
build(old, area, mode, keep, |i| mask.get(i).copied().unwrap_or(0))
|
||||
build(old, area, mode, keep, Arithmetic::Extremes, |i| mask.get(i).copied().unwrap_or(0))
|
||||
}
|
||||
|
||||
fn build(old: Option<&Surface>, area: Rect, mode: SelectionMode, keep_outside: bool, sample: impl Fn(usize) -> u8 + Sync) -> Option<Surface> {
|
||||
fn build(
|
||||
old: Option<&Surface>,
|
||||
area: Rect,
|
||||
mode: SelectionMode,
|
||||
keep_outside: bool,
|
||||
arithmetic: Arithmetic,
|
||||
sample: impl Fn(usize) -> u8 + Sync,
|
||||
) -> Option<Surface> {
|
||||
let mut out = if keep_outside { old.cloned().unwrap_or_else(|| Surface::new(PixelFormat::GRAY8)) } else { Surface::new(PixelFormat::GRAY8) };
|
||||
let default = old.and_then(|s| s.default_bytes().first()).copied().unwrap_or(0);
|
||||
let out_default = out.default_bytes().first().copied().unwrap_or(0);
|
||||
@@ -77,12 +121,7 @@ fn build(old: Option<&Surface>, area: Rect, mode: SelectionMode, keep_outside: b
|
||||
for (i, d) in dst.iter_mut().enumerate() {
|
||||
let new = start.and_then(|j| j.checked_add(i)).map(&sample).unwrap_or(0);
|
||||
let prev = src.and_then(|s| s.get(i)).copied().unwrap_or(default);
|
||||
*d = match mode {
|
||||
SelectionMode::Replace => new,
|
||||
SelectionMode::Add => prev.max(new),
|
||||
SelectionMode::Subtract => prev.saturating_sub(new),
|
||||
SelectionMode::Intersect => prev.min(new),
|
||||
};
|
||||
*d = arithmetic.apply(mode, prev, new);
|
||||
}
|
||||
}
|
||||
let (lo, hi) = tile.bytes().iter().fold((u8::MAX, 0u8), |(lo, hi), b| (lo.min(*b), hi.max(*b)));
|
||||
|
||||
@@ -76,6 +76,37 @@ fn cropped_bands_match_dense_writeback_with_defaults_and_short_masks() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scaled_combining_narrows_partial_coverage_and_keeps_hard_edges() {
|
||||
use crate::selection::combine_scaled;
|
||||
let area = Rect::new(0, 0, 256, 256);
|
||||
let prev: Vec<f32> = (0..65536).map(|i| (i / 256) as f32 / 255.0).collect();
|
||||
let mask: Vec<f32> = (0..65536).map(|i| (i % 256) as f32 / 255.0).collect();
|
||||
let gray8 = crate::selection::mask_to_surface(&prev, area);
|
||||
// An unusual (float) selection surface takes the float path; it must agree with the byte path everywhere.
|
||||
let mut float = Surface::new(PixelFormat::new(ColorMode::Grayscale, SampleType::F32, false));
|
||||
float.write_region(area, &prev);
|
||||
for mode in MODES {
|
||||
let scaled = combine_scaled(Some(&gray8), &mask, area, mode);
|
||||
assert_eq!(scaled, combine_scaled(Some(&float), &mask, area, mode), "{mode:?}: float and byte paths");
|
||||
let scaled = mask_from_surface(scaled.as_ref(), area);
|
||||
let tools = mask_from_surface(combine(Some(&gray8), &mask, area, mode).as_ref(), area);
|
||||
for (i, ((&p, &m), (&s, &t))) in prev.iter().zip(&mask).zip(scaled.iter().zip(&tools)).enumerate() {
|
||||
if m == 0.0 || m == 1.0 {
|
||||
assert_eq!(s, t, "{mode:?} {i}: a fully selected or unselected pixel combines as the tools do");
|
||||
continue;
|
||||
}
|
||||
match mode {
|
||||
SelectionMode::Add => assert!(s >= t, "{mode:?} {i}: adding partial coverage keeps at least the larger one"),
|
||||
SelectionMode::Subtract => assert!(s >= t, "{mode:?} {i}: subtracting scales the selection, never below the difference"),
|
||||
SelectionMode::Intersect if p == m && p > 0.0 => assert!(s < p, "{mode:?} {i}: intersecting a partial selection with itself narrows it"),
|
||||
SelectionMode::Intersect => assert!(s <= t, "{mode:?} {i}: intersecting keeps no more than the smaller one"),
|
||||
SelectionMode::Replace => assert_eq!(s, t),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unusual_selection_formats_keep_their_float_behavior() {
|
||||
let area = Rect::new(-2, -1, 3, 2);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
use crate::selection::{SelectionMode, combine, ellipse_surface, feather, feather_reach, mask_from_surface};
|
||||
|
||||
#[test]
|
||||
fn elliptical_feather_keeps_the_measured_bounds_row_and_area() {
|
||||
let canvas = Rect::new(0, 0, 400, 350);
|
||||
let ellipse = Rect::new(100, 100, 300, 250);
|
||||
let original = ellipse_surface(ellipse, canvas, true);
|
||||
let full_mask = mask_from_surface(Some(&original), canvas);
|
||||
let exact_area = 23561.9;
|
||||
let expected_row = [1_i32, 3, 6, 10, 16, 24, 34, 46, 60, 77, 94, 113, 133];
|
||||
|
||||
for (radius, expected) in [(2.0, [95_i32, 95, 305, 255]), (5.0, [88, 88, 312, 262]), (10.0, [76, 75, 324, 275]), (20.0, [52, 51, 348, 299])] {
|
||||
let feathered = feather(&full_mask, canvas.width() as usize, canvas.height() as usize, radius);
|
||||
let selection = combine(None, &feathered, canvas, SelectionMode::Replace);
|
||||
let Some(selection) = selection else { panic!("radius {radius} lost the selection") };
|
||||
let bounds = selection.content_bounds();
|
||||
let got = [bounds.x0, bounds.y0, bounds.x1, bounds.y1];
|
||||
assert!(got.iter().zip(expected).all(|(a, b)| a.abs_diff(b) <= 1), "radius {radius}: {got:?}, expected {expected:?}");
|
||||
let stored = mask_from_surface(Some(&selection), canvas);
|
||||
let area: f64 = stored.iter().map(|v| f64::from(*v)).sum();
|
||||
assert!((area - exact_area).abs() <= 0.001 * exact_area, "radius {radius} area: {area}");
|
||||
|
||||
if radius == 5.0 {
|
||||
for (x, expected) in (88..).zip(expected_row) {
|
||||
let actual = (selection.sample_channel(x, 175, 0) * 255.0).round() as i32;
|
||||
assert!(actual.abs_diff(expected) <= 5, "x {x}: {actual}, expected {expected}");
|
||||
}
|
||||
}
|
||||
|
||||
// The marquee blurs just its padded shape window. It must store the same selection as
|
||||
// feathering the completed ellipse in a larger window.
|
||||
let margin = i32::try_from(feather_reach(radius)).unwrap_or(i32::MAX).saturating_add(1);
|
||||
let window = ellipse.inflate(margin).intersect(&canvas);
|
||||
let mask = mask_from_surface(Some(&original), window);
|
||||
let feathered = feather(&mask, window.width() as usize, window.height() as usize, radius);
|
||||
let local = combine(None, &feathered, window, SelectionMode::Replace);
|
||||
assert_eq!(mask_from_surface(local.as_ref(), canvas), stored, "radius {radius}: the working window changed coverage");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_fringe_guard_keeps_existing_faint_input_coverage() {
|
||||
let mut mask = vec![0.0; 17 * 17];
|
||||
let center = 8 * 17 + 8;
|
||||
mask[center] = 1.0 / 255.0;
|
||||
let result = feather(&mask, 17, 17, 2.0);
|
||||
assert!(result[center] > 0.0);
|
||||
assert_eq!(result[center + 1], 0.0);
|
||||
}
|
||||
@@ -829,3 +829,14 @@ fn color_matcher_tree_reservation_failure_is_reported() {
|
||||
assert_eq!(tree.nodes.len(), ColorBvh::node_count(n));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stored_levels_bands_bound_the_f32_staging_on_wide_areas() {
|
||||
// #11785 review: one parallel reader's f32 staging stays near 2 MB. A 6000 px CMYK strip
|
||||
// (the Magic Eraser/Wand worst case on 24 MP documents) shrinks from 256 rows to fit;
|
||||
// narrow areas keep full bands; an absurdly wide one clamps to the 16-row floor.
|
||||
let rows = levels_band_rows(6000, 4);
|
||||
assert!(rows >= 16 && 6000 * 4 * 4 * rows <= (2u64 << 20) as usize, "6000 px CMYK band rows: {rows}");
|
||||
assert_eq!(levels_band_rows(1, 1), 256, "narrow areas keep full 256-row bands");
|
||||
assert_eq!(levels_band_rows(100_000, 5), 16, "an extreme width clamps to the floor");
|
||||
}
|
||||
@@ -594,12 +594,32 @@ pub(crate) fn feather(m: &[f32], w: usize, h: usize, radius: f32) -> Vec<f32> {
|
||||
});
|
||||
// Columns, a strip of columns at a time.
|
||||
let rows = Rows { tmp: &tmp, gw, bh: b.h(), off: b.y0 - win.y0, gh };
|
||||
let res = strips(gw, |c0, sw| kv.strip(&rows, c0, sw));
|
||||
let res = strips(gw, |c0, sw| {
|
||||
let mut strip = kv.strip(&rows, c0, sw);
|
||||
if (2.0..=20.0).contains(&radius) {
|
||||
// Remove only the newly spread fringe below roughly one stored selection level.
|
||||
// Keep existing faint input coverage and leave the convolution and its reach intact.
|
||||
const FRINGE: f32 = 0.96 / 255.0;
|
||||
for (y, row) in strip.chunks_exact_mut(sw).enumerate() {
|
||||
let start = (win.y0 + y) * w + win.x0 + c0;
|
||||
for (v, &before) in row.iter_mut().zip(&m[start..start + sw]) {
|
||||
if before == 0.0 && *v < FRINGE {
|
||||
*v = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
strip
|
||||
});
|
||||
drop(tmp);
|
||||
// Rounding residue of the sliding sums is not coverage.
|
||||
assemble(&res, win, w, h, 0.0, |v| if v.abs() < 1e-7 { 0.0 } else { v })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "selection/feather_bounds_tests.rs"]
|
||||
mod feather_bounds_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
use super::{BucketAlpha, ColorDistance, WandBound, WandMatch, WandPixels, wand_region, wand_region_bucket, wand_region_by, wand_region_on};
|
||||
|
||||
const AREA: Rect = Rect { x0: 0, y0: 0, x1: 121, y1: 256 };
|
||||
|
||||
fn grid() -> Vec<[u8; 4]> {
|
||||
(0..256).flat_map(|alpha| (0..121).map(move |x| [(40 + x) as u8, (40 + x) as u8, (40 + x) as u8, alpha as u8])).collect()
|
||||
}
|
||||
|
||||
fn expected(x: i32, y: i32, seed_alpha: i32, tolerance: i32) -> bool {
|
||||
if seed_alpha == 0 { y == 0 } else { y != 0 && (x - 60).abs() <= tolerance }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visible_seeds_cross_all_nonzero_alpha_rows_with_the_same_colour_tolerance() {
|
||||
let pixels = grid();
|
||||
for contiguous in [false, true] {
|
||||
for (alpha, tolerance) in [(1, 32), (40, 32), (128, 32), (255, 32), (1, 0), (128, 0), (128, 1), (128, 255)] {
|
||||
let region = wand_region_bucket(&pixels, AREA, (60, alpha), tolerance as f32, contiguous, false, BucketAlpha::Visible).unwrap();
|
||||
for y in 0..256 {
|
||||
for x in 0..121 {
|
||||
assert_eq!(
|
||||
region.at(x, y) == 1.0,
|
||||
expected(x, y, alpha, tolerance),
|
||||
"seed {alpha}, tolerance {tolerance}, contiguous {contiguous}, ({x}, {y})"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transparent_seeds_keep_their_own_class_at_every_tolerance() {
|
||||
let pixels = grid();
|
||||
for contiguous in [false, true] {
|
||||
for tolerance in [0, 32, 255] {
|
||||
let region = wand_region_bucket(&pixels, AREA, (60, 0), tolerance as f32, contiguous, false, BucketAlpha::Visible).unwrap();
|
||||
for y in 0..256 {
|
||||
for x in 0..121 {
|
||||
assert_eq!(region.at(x, y) == 1.0, y == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn varying_visible_alpha_gives_the_same_colour_cube_region_as_opaque_pixels() {
|
||||
let mut pixels = vec![[61, 200, 91, 60]];
|
||||
for r in [-40, -32, -1, 0, 1, 32, 40] {
|
||||
for g in [-40, -32, -1, 0, 1, 32, 40] {
|
||||
for b in [-40, -32, -1, 0, 1, 32, 40] {
|
||||
let alpha = (pixels.len() * 73 + 19) % 255 + 1;
|
||||
pixels.push([(61 + r) as u8, (200 + g) as u8, (91 + b) as u8, alpha as u8]);
|
||||
}
|
||||
}
|
||||
}
|
||||
let opaque: Vec<_> = pixels.iter().map(|p| [p[0], p[1], p[2], 255]).collect();
|
||||
let area = Rect::new(0, 0, pixels.len() as i32, 1);
|
||||
let region = wand_region_bucket(&pixels, area, (0, 0), 32.0, false, false, BucketAlpha::Visible).unwrap();
|
||||
let opaque_region = wand_region_bucket(&opaque, area, (0, 0), 32.0, false, false, BucketAlpha::Visible).unwrap();
|
||||
assert_eq!(region, opaque_region);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visible_seeds_give_alpha_zero_neighbours_no_antialias_fringe() {
|
||||
let pixels = [[100, 100, 100, 128], [100, 100, 100, 0], [101, 101, 101, 255]];
|
||||
let area = Rect::new(0, 0, 3, 1);
|
||||
for contiguous in [false, true] {
|
||||
for tolerance in [0.0, 32.0, 255.0] {
|
||||
let region = wand_region_bucket(&pixels, area, (0, 0), tolerance, contiguous, true, BucketAlpha::Visible).unwrap();
|
||||
assert_eq!(region.at(0, 0), 1.0);
|
||||
assert_eq!(region.at(1, 0), 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wand_and_magic_eraser_keep_their_alpha_band() {
|
||||
let pixels = [[100, 100, 100, 128], [101, 101, 101, 1], [100, 100, 100, 0]];
|
||||
let area = Rect::new(0, 0, 3, 1);
|
||||
let wand = wand_region(&pixels, area, (0, 0), 32.0, false, false).unwrap();
|
||||
let eraser = wand_region_by(&pixels, area, (0, 0), 32.0, false, false, None, ColorDistance::Spread).unwrap();
|
||||
assert_eq!(wand.at(1, 0), 0.0);
|
||||
assert_eq!(wand.at(2, 0), 0.0);
|
||||
assert_eq!(wand, eraser);
|
||||
assert_eq!(wand_region(&pixels, area, (2, 0), 255.0, false, false).unwrap().at(0, 0), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_channel_generic_wand_keeps_its_alpha_band() {
|
||||
for channels in [2, 5] {
|
||||
let mut data = vec![100; channels * 2];
|
||||
data[channels - 1] = 128;
|
||||
data[channels * 2 - 1] = 1;
|
||||
data[channels] = 101;
|
||||
let pixels = WandPixels { area: Rect::new(0, 0, 2, 1), data: &data, channels, alpha: Some(channels - 1) };
|
||||
let region = wand_region_on(&pixels, (0, 0), &WandMatch::new(32.0, false, false, WandBound::AtMost)).unwrap();
|
||||
assert_eq!(region.at(0, 0), 1.0);
|
||||
assert_eq!(region.at(1, 0), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legacy_bucket_rule_keeps_its_band_and_same_colour_exception() {
|
||||
let pixels = [[100, 100, 100, 40], [120, 120, 120, 197], [100, 100, 100, 253], [120, 120, 120, 50]];
|
||||
let region = wand_region_bucket(&pixels, Rect::new(0, 0, 4, 1), (0, 0), 32.0, false, false, BucketAlpha::Band).unwrap();
|
||||
assert_eq!(region.at(0, 0), 1.0);
|
||||
assert_eq!(region.at(1, 0), 0.0);
|
||||
assert_eq!(region.at(2, 0), 1.0);
|
||||
assert_eq!(region.at(3, 0), 1.0);
|
||||
}
|
||||
|
||||
// Surface-backed checks also exercise bucket_fill_inks and the source-format seam.
|
||||
#[cfg(test)]
|
||||
mod surfaces {
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType, blend::BlendMode};
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
use super::*;
|
||||
use crate::paint::{FillMode, bucket_fill_inks};
|
||||
use crate::selection::rgba8_image;
|
||||
|
||||
fn fill(surface: &mut Surface, area: Rect, seed: (i32, i32), tolerance: f32, contiguous: bool, locked: bool) {
|
||||
assert!(bucket_fill_inks(
|
||||
surface,
|
||||
area,
|
||||
seed,
|
||||
tolerance,
|
||||
contiguous,
|
||||
false,
|
||||
1.0,
|
||||
None,
|
||||
locked,
|
||||
|_, _| [0.0, 1.0, 0.0, 1.0],
|
||||
None,
|
||||
FillMode::Blend(BlendMode::Normal)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eight_and_sixteen_bit_bucket_fills_the_measured_grid_and_keeps_every_other_pixel() {
|
||||
let pixels = grid();
|
||||
let bytes: Vec<u8> = pixels.iter().flatten().copied().collect();
|
||||
let original = Surface::from_interleaved(PixelFormat::RGBA8, AREA, &bytes);
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
for contiguous in [false, true] {
|
||||
for (alpha, tolerance) in [(1, 32), (40, 32), (128, 32), (255, 32), (128, 0), (128, 1), (128, 255), (0, 32), (0, 255)] {
|
||||
let mut surface = original.convert(PixelFormat::new(ColorMode::Rgb, depth, true));
|
||||
fill(&mut surface, AREA, (60, alpha), tolerance as f32, contiguous, false);
|
||||
for (index, pixel) in rgba8_image(&surface, AREA).iter().enumerate() {
|
||||
let (x, y) = ((index % 121) as i32, (index / 121) as i32);
|
||||
let wanted = if expected(x, y, alpha, tolerance) { [0, 255, 0, 255] } else { pixels[index] };
|
||||
assert_eq!(*pixel, wanted, "{depth:?}, seed {alpha}, tolerance {tolerance}, contiguous {contiguous}, ({x}, {y})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intermediate_sixteen_bit_alpha_keeps_the_legacy_match_and_contiguous_barrier() {
|
||||
let area = Rect::new(0, 0, 3, 1);
|
||||
let mut original = Surface::new(PixelFormat::new(ColorMode::Rgb, SampleType::U16, true));
|
||||
original.write_region(
|
||||
area,
|
||||
&[
|
||||
100.0 / 255.0,
|
||||
100.0 / 255.0,
|
||||
100.0 / 255.0,
|
||||
40.0 / 255.0,
|
||||
120.0 / 255.0,
|
||||
120.0 / 255.0,
|
||||
120.0 / 255.0,
|
||||
(197.0 * 257.0 + 1.0) / 65535.0,
|
||||
120.0 / 255.0,
|
||||
120.0 / 255.0,
|
||||
120.0 / 255.0,
|
||||
197.0 / 255.0,
|
||||
],
|
||||
);
|
||||
for contiguous in [false, true] {
|
||||
let mut surface = original.clone();
|
||||
fill(&mut surface, area, (0, 0), 32.0, contiguous, false);
|
||||
assert_eq!(surface.pixel(1, 0), original.pixel(1, 0), "intermediate candidate retains its alpha band");
|
||||
assert_eq!(surface.pixel(2, 0) == vec![0.0, 1.0, 0.0, 1.0], !contiguous);
|
||||
}
|
||||
original.write_pixel(0, 0, &[100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0, (40.0 * 257.0 + 1.0) / 65535.0]);
|
||||
let mut surface = original.clone();
|
||||
fill(&mut surface, area, (0, 0), 32.0, false, false);
|
||||
assert_eq!(surface.pixel(2, 0), original.pixel(2, 0), "intermediate seed retains the alpha band");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unmeasured_modes_float_depth_and_locked_transparency_keep_the_previous_rule() {
|
||||
let area = Rect::new(0, 0, 2, 1);
|
||||
let bytes = [100, 100, 100, 40, 120, 120, 120, 197];
|
||||
let rgb = Surface::from_interleaved(PixelFormat::RGBA8, area, &bytes);
|
||||
for format in [
|
||||
PixelFormat::new(ColorMode::Rgb, SampleType::F32, true),
|
||||
PixelFormat::GRAYA8,
|
||||
PixelFormat::CMYKA8,
|
||||
PixelFormat::new(ColorMode::Lab, SampleType::U16, true),
|
||||
] {
|
||||
let original = rgb.convert(format);
|
||||
let before = rgba8_image(&original, area);
|
||||
assert_ne!(before[0][..3], before[1][..3]);
|
||||
assert!(before[0][..3].iter().zip(&before[1][..3]).all(|(a, b)| a.abs_diff(*b) <= 32));
|
||||
let mut surface = original.clone();
|
||||
fill(&mut surface, area, (0, 0), 32.0, false, false);
|
||||
assert_eq!(surface.pixel(1, 0), original.pixel(1, 0), "{format:?}");
|
||||
}
|
||||
let mut locked = rgb.clone();
|
||||
fill(&mut locked, area, (0, 0), 32.0, false, true);
|
||||
assert_eq!(locked.pixel(1, 0), rgb.pixel(1, 0));
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
//! statistic across N aligned images, e.g. median to remove passers-by or mean to reduce noise.
|
||||
//!
|
||||
//! Inputs are straight RGBA buffers of equal size. Only samples with alpha > 0 contribute; the
|
||||
//! output alpha is the largest input alpha. Moments use the population definitions; skewness and
|
||||
//! output is opaque wherever one does. Moments use the population definitions; skewness and
|
||||
//! kurtosis are standardised (kurtosis is excess-free, a normal sample gives ≈ 3), scaled into
|
||||
//! 0..=1 for display; entropy is the Shannon entropy (bits) of the 8-bit values over log2(N).
|
||||
|
||||
@@ -239,7 +239,6 @@ fn combine_with(layers: &[Vec<[f32; 4]>], f: impl Fn(&mut [f32], &mut EntropyScr
|
||||
for (j, o) in outs.iter_mut().enumerate() {
|
||||
let i = base + j;
|
||||
let mut k = 0;
|
||||
let mut alpha = 0.0f32;
|
||||
for l in layers {
|
||||
if let Some(p) = l.get(i)
|
||||
&& p[3] > 0.0
|
||||
@@ -248,16 +247,15 @@ fn combine_with(layers: &[Vec<[f32; 4]>], f: impl Fn(&mut [f32], &mut EntropyScr
|
||||
samples[c][k] = p[c];
|
||||
}
|
||||
k += 1;
|
||||
alpha = alpha.max(p[3]);
|
||||
}
|
||||
}
|
||||
if alpha <= 0.0 {
|
||||
if k == 0 {
|
||||
continue;
|
||||
}
|
||||
for c in 0..3 {
|
||||
o[c] = f(&mut samples[c][..k], &mut scratch);
|
||||
}
|
||||
o[3] = alpha;
|
||||
o[3] = 1.0;
|
||||
}
|
||||
});
|
||||
out
|
||||
@@ -265,3 +263,7 @@ fn combine_with(layers: &[Vec<[f32; 4]>], f: impl Fn(&mut [f32], &mut EntropyScr
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "stack_result_alpha_tests.rs"]
|
||||
mod stack_result_alpha_tests;
|
||||
@@ -135,7 +135,7 @@ fn deep_median_stack_uses_only_visible_samples_per_channel() {
|
||||
let mut samples: Vec<f32> = layers.iter().filter(|l| l[0][3] > 0.0).map(|l| l[0][channel]).collect();
|
||||
assert_eq!(actual[0][channel].to_bits(), sorted_median(&mut samples).to_bits());
|
||||
}
|
||||
assert_eq!(actual[0][3], 0.5);
|
||||
assert_eq!(actual[0][3], 1.0);
|
||||
assert_eq!(actual[1], [0.0; 4]);
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3e3d004c, 0x3e0b4396, 0x3e030e1f, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x3e594eb2, 0x3e6ef420, 0x3e7ffffe, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f000000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f800000],
|
||||
[0x3e6eeeee, 0x3e6eeeee, 0x3e6eeeee, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -181,7 +181,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3f666666, 0x3f000000, 0x3f000000, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x40400000, 0x40800000, 0x3fc00000, 0x3f800000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f000000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f800000],
|
||||
[0x3f000000, 0x3f400000, 0x3f000000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -193,7 +193,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3ee66666, 0x3e99999a, 0x3ec00000, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x3f19999a, 0x3f800000, 0x3f000000, 0x3f800000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f000000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f800000],
|
||||
[0x3ea00000, 0x3f200000, 0x3ea00000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -205,7 +205,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3ecccccd, 0x3e99999a, 0x3ecccccd, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x3f000000, 0x3f000000, 0x3f000000, 0x3f800000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f000000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f800000],
|
||||
[0x3e800000, 0x3f400000, 0x3e800000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -217,7 +217,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3dcccccd, 0x3dcccccd, 0x3e4ccccd, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0xc0000000, 0xbf800000, 0x00000000, 0x3f800000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f000000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f800000],
|
||||
[0x3e800000, 0x3e800000, 0x3e800000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -229,7 +229,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3f4ccccc, 0x3ecccccd, 0x3e99999a, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x40a00000, 0x40a00000, 0x3fc00000, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f000000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f800000],
|
||||
[0x3e800000, 0x3f000000, 0x3e800000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -241,7 +241,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3f1bd152, 0x3efffffe, 0x3ee4a11b, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x3eedb65a, 0x3f2ea754, 0x3f3a6c7a, 0x3f800000],
|
||||
[0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000],
|
||||
[0x3f000000, 0x3f000000, 0x3f000000, 0x3f800000],
|
||||
[0x3f49e69e, 0x3e58658a, 0x3f49e69e, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -253,7 +253,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3e97739e, 0x3e21e89b, 0x3e050581, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x3fd3e0b1, 0x3fd9f9e5, 0x3f0c378c, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f000000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f800000],
|
||||
[0x3dddb3d7, 0x3e5db3d7, 0x3dddb3d7, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -265,7 +265,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3fe66666, 0x3f99999a, 0x3fc00000, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x40400000, 0x40a00000, 0x40200000, 0x3f800000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f000000],
|
||||
[0x3f333333, 0x3e4ccccd, 0x3dcccccd, 0x3f800000],
|
||||
[0x3fa00000, 0x40200000, 0x3fa00000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -277,7 +277,7 @@ fn statistics_are_bit_identical_to_the_serial_implementation() {
|
||||
[0x3db33332, 0x3ccccccd, 0x3c8a3d70, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000],
|
||||
[0x402f5c29, 0x4039999a, 0x3e99999a, 0x3f800000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f000000],
|
||||
[0x00000000, 0x00000000, 0x00000000, 0x3f800000],
|
||||
[0x3c400000, 0x3d400000, 0x3c400000, 0x3f800000],
|
||||
]
|
||||
.to_vec(),
|
||||
@@ -303,7 +303,7 @@ fn entropy_matches_hand_computed_values() {
|
||||
// Pixel 3, red: -2 and 0 land in bin 0, 3 and 1.5 clamp into bin 255, 0.5 is alone.
|
||||
assert!((f64::from(out[3][0]) - h(&[2.0, 2.0, 1.0])).abs() < 1e-6, "{}", out[3][0]);
|
||||
// Pixel 4: a single contributing sample has no entropy.
|
||||
assert_eq!(out[4], [0.0, 0.0, 0.0, 0.5]);
|
||||
assert_eq!(out[4], [0.0, 0.0, 0.0, 1.0]);
|
||||
// Pixel 5: three samples share a bin, one is alone, in every channel.
|
||||
for (c, v) in out[5].iter().take(3).enumerate() {
|
||||
assert!((f64::from(*v) - h(&[3.0, 1.0])).abs() < 1e-6, "channel {c}: {v}");
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//! The stack result's alpha (#18296): opaque wherever at least one layer has a pixel,
|
||||
//! transparent where none has.
|
||||
|
||||
use super::*;
|
||||
|
||||
const MODES: [Stat; 11] = [
|
||||
Stat::Entropy,
|
||||
Stat::Kurtosis,
|
||||
Stat::Maximum,
|
||||
Stat::Mean,
|
||||
Stat::Median,
|
||||
Stat::Minimum,
|
||||
Stat::Range,
|
||||
Stat::Skewness,
|
||||
Stat::StandardDeviation,
|
||||
Stat::Summation,
|
||||
Stat::Variance,
|
||||
];
|
||||
|
||||
/// Five layers over two pixels: the first is grey 200 at `alpha` on every layer, the second
|
||||
/// is empty on every layer.
|
||||
fn five_layers(alpha: f32) -> Vec<Vec<[f32; 4]>> {
|
||||
let grey = 200.0 / 255.0;
|
||||
(0..5).map(|_| vec![[grey, grey, grey, alpha], [0.0; 4]]).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn half_transparent_samples_give_an_opaque_result_with_the_opaque_colour() {
|
||||
let half = five_layers(128.0 / 255.0);
|
||||
let opaque = five_layers(1.0);
|
||||
for mode in MODES {
|
||||
let out = combine(&half, mode);
|
||||
assert_eq!(out[0][3], 1.0, "{mode:?}");
|
||||
// Partly transparent samples count at full weight: the colour is what the same
|
||||
// samples give when opaque.
|
||||
assert_eq!(out[0], combine(&opaque, mode)[0], "{mode:?}");
|
||||
assert_eq!(out[1], [0.0; 4], "{mode:?}: a pixel empty on every layer stays transparent");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_faint_sample_among_empty_layers_is_enough_for_an_opaque_result() {
|
||||
let layers = vec![vec![[0.0; 4]], vec![[0.25, 0.5, 0.75, 0.1]], vec![]];
|
||||
for mode in MODES {
|
||||
assert_eq!(combine(&layers, mode)[0][3], 1.0, "{mode:?}");
|
||||
}
|
||||
assert_eq!(combine(&layers, Stat::Mean)[0], [0.25, 0.5, 0.75, 1.0]);
|
||||
}
|
||||
@@ -110,6 +110,8 @@ fn all_filters() -> Vec<FilterParams> {
|
||||
FilterParams::SmartSharpen { amount: 100.0, radius: 1.0, reduce_noise: 20.0 },
|
||||
FilterParams::HighPass { radius: 3.0 },
|
||||
FilterParams::AddNoise { amount: 25.0, distribution: Distribution::Gaussian, monochromatic: false, seed: 3 },
|
||||
FilterParams::AddNoise { amount: 25.0, distribution: Distribution::Uniform, monochromatic: true, seed: 3 },
|
||||
FilterParams::AddNoise { amount: 25.0, distribution: Distribution::Gaussian, monochromatic: true, seed: 3 },
|
||||
FilterParams::Median { radius: 2.0 },
|
||||
FilterParams::DustAndScratches { radius: 2.0, threshold: 10.0 },
|
||||
FilterParams::Minimum { radius: 1.0, preserve: Preserve::Squareness },
|
||||
@@ -291,24 +293,49 @@ fn high_pass_of_flat_is_mid_gray() {
|
||||
assert!((p[0] - 0.5).abs() < 1e-5 && (p[1] - 0.5).abs() < 1e-5);
|
||||
}
|
||||
|
||||
/// Both noise distributions preserve alpha and share a seeded value across color channels.
|
||||
#[test]
|
||||
fn noise_is_deterministic_monochrome_and_centred() {
|
||||
let s = flat(SampleType::F32, R, [0.5, 0.5, 0.5, 1.0]);
|
||||
let p = FilterParams::AddNoise { amount: 50.0, distribution: Distribution::Uniform, monochromatic: true, seed: 1 };
|
||||
let a = run(&s, &p);
|
||||
assert_eq!(a, run(&s, &p));
|
||||
let v = a.read_region(R);
|
||||
let mut mean = 0.0;
|
||||
for px in v.as_chunks::<4>().0 {
|
||||
assert_eq!(px[0], px[1]);
|
||||
assert_eq!(px[1], px[2]);
|
||||
assert!((px[0] - 0.5).abs() <= 0.25 + 1e-6);
|
||||
mean += px[0];
|
||||
for distribution in [Distribution::Uniform, Distribution::Gaussian] {
|
||||
let s = flat(SampleType::F32, R, [0.5, 0.5, 0.5, 1.0]);
|
||||
let p = FilterParams::AddNoise { amount: 50.0, distribution, monochromatic: true, seed: 1 };
|
||||
let a = run(&s, &p);
|
||||
assert_eq!(a, run(&s, &p));
|
||||
let v = a.read_region(R);
|
||||
let mut mean = 0.0;
|
||||
for px in v.as_chunks::<4>().0 {
|
||||
assert_eq!(px[0], px[1]);
|
||||
assert_eq!(px[1], px[2]);
|
||||
if matches!(distribution, Distribution::Uniform) {
|
||||
assert!((px[0] - 0.5).abs() <= 0.25 + 1e-6);
|
||||
}
|
||||
assert_eq!(px[3], 1.0);
|
||||
mean += px[0];
|
||||
}
|
||||
mean /= (v.len() / 4) as f32;
|
||||
assert!((mean - 0.5).abs() < 0.03, "{mean}");
|
||||
let other_seed = run(&s, &FilterParams::AddNoise { amount: 50.0, distribution, monochromatic: true, seed: 2 });
|
||||
assert_ne!(a, other_seed);
|
||||
}
|
||||
}
|
||||
|
||||
/// RGB8 goldens from 799e1296's original Add Noise, before monochrome sampling was hoisted.
|
||||
#[test]
|
||||
fn monochrome_noise_matches_original_rgb8_bytes() {
|
||||
let area = Rect::new(0, 0, 3, 2);
|
||||
let mut source = Surface::new(PixelFormat::new(ColorMode::Rgb, SampleType::U8, false));
|
||||
source.fill_rect(area, &[0.5, 0.5, 0.5]);
|
||||
let rgb_bytes = |surface: &Surface| surface.read_region(area).iter().map(|v| (v * 255.0).round() as u8).collect::<Vec<_>>();
|
||||
let cases: [(Distribution, [u8; 18]); 2] = [
|
||||
(Distribution::Uniform, [65, 65, 65, 96, 96, 96, 134, 134, 134, 67, 67, 67, 86, 86, 86, 118, 118, 118]),
|
||||
(Distribution::Gaussian, [105, 105, 105, 104, 104, 104, 117, 117, 117, 103, 103, 103, 167, 167, 167, 136, 136, 136]),
|
||||
];
|
||||
for (distribution, expected) in cases {
|
||||
let monochrome = apply(&source, &FilterParams::AddNoise { amount: 50.0, distribution, monochromatic: true, seed: 1 }, area, area, None);
|
||||
assert_eq!(rgb_bytes(&monochrome).as_slice(), expected.as_slice(), "{distribution:?}");
|
||||
let colored = apply(&source, &FilterParams::AddNoise { amount: 50.0, distribution, monochromatic: false, seed: 1 }, area, area, None);
|
||||
assert!(rgb_bytes(&colored).as_chunks::<3>().0.iter().any(|pixel| pixel[0] != pixel[1] || pixel[1] != pixel[2]), "{distribution:?}");
|
||||
}
|
||||
mean /= (v.len() / 4) as f32;
|
||||
assert!((mean - 0.5).abs() < 0.03, "{mean}");
|
||||
let other_seed = run(&s, &FilterParams::AddNoise { amount: 50.0, distribution: Distribution::Uniform, monochromatic: true, seed: 2 });
|
||||
assert_ne!(a, other_seed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -168,7 +168,7 @@ pub(crate) fn bicubic(t: f64) -> [f64; 4] {
|
||||
/// The result has the same format as `src`, with alpha added if `src` had none; pixels outside
|
||||
/// the warped quad are transparent.
|
||||
pub fn warp_surface(src: &Surface, src_rect: Rect, h: &Homography, interp: Interp) -> Result<Surface, photocraft_raster::AllocationError> {
|
||||
warp(src, src_rect, h, interp, None, &Interrupt::NONE)
|
||||
warp(src, src_rect, h, interp, None, &Interrupt::NONE, false)
|
||||
}
|
||||
|
||||
/// [`warp_surface`] reporting progress per destination tile; `Ok(None)` once `ctl` is cancelled.
|
||||
@@ -179,7 +179,7 @@ pub fn warp_surface_with(
|
||||
interp: Interp,
|
||||
ctl: &Interrupt,
|
||||
) -> Result<Option<Surface>, photocraft_raster::AllocationError> {
|
||||
let out = warp(src, src_rect, h, interp, None, ctl)?;
|
||||
let out = warp(src, src_rect, h, interp, None, ctl, false)?;
|
||||
Ok((!ctl.cancelled()).then_some(out))
|
||||
}
|
||||
|
||||
@@ -187,7 +187,19 @@ pub fn warp_surface_with(
|
||||
/// `clip` even when part of the source lies at or beyond the map's horizon (a Perspective Crop of a
|
||||
/// layer that reaches far past the crop quad), which would make the full warped extent unbounded.
|
||||
pub fn warp_surface_clipped(src: &Surface, src_rect: Rect, h: &Homography, interp: Interp, clip: Rect) -> Result<Surface, photocraft_raster::AllocationError> {
|
||||
warp(src, src_rect, h, interp, Some(clip), &Interrupt::NONE)
|
||||
warp(src, src_rect, h, interp, Some(clip), &Interrupt::NONE, false)
|
||||
}
|
||||
|
||||
/// Perspective Crop's clipped warp. Bilinear reductions average the source pixels covered by each
|
||||
/// output pixel, as Image Size does. The ordinary transform entry points keep direct Bilinear sampling.
|
||||
pub fn warp_surface_clipped_for_crop(
|
||||
src: &Surface,
|
||||
src_rect: Rect,
|
||||
h: &Homography,
|
||||
interp: Interp,
|
||||
clip: Rect,
|
||||
) -> Result<Surface, photocraft_raster::AllocationError> {
|
||||
warp(src, src_rect, h, interp, Some(clip), &Interrupt::NONE, true)
|
||||
}
|
||||
|
||||
/// Is `q` (TL, TR, BR, BL) a usable Perspective Crop quad: finite, strictly convex with every
|
||||
@@ -369,6 +381,176 @@ fn corner_bounds(corners: &[(f64, f64); 4]) -> Option<Rect> {
|
||||
Some(Rect::new(bx0, by0, bx1, by1))
|
||||
}
|
||||
|
||||
/// A convex quad clipped against four pixel edges needs at most twelve stored vertices,
|
||||
/// including coincident boundary intersections. Keep this scratch on the stack, not per-pixel heap allocations.
|
||||
#[derive(Clone, Copy)]
|
||||
struct CropPolygon {
|
||||
points: [(f64, f64); 12],
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl CropPolygon {
|
||||
fn quad(points: [(f64, f64); 4]) -> Self {
|
||||
let mut polygon = Self { points: [(0.0, 0.0); 12], len: 4 };
|
||||
polygon.points[..4].copy_from_slice(&points);
|
||||
polygon
|
||||
}
|
||||
|
||||
fn push(&mut self, point: (f64, f64)) -> Result<(), photocraft_raster::AllocationError> {
|
||||
let slot = self.points.get_mut(self.len).ok_or(photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
*slot = point;
|
||||
self.len += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clip(&mut self, axis: usize, bound: f64, greater: bool) -> Result<(), photocraft_raster::AllocationError> {
|
||||
let points = self.points.get(..self.len).ok_or(photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
let Some(mut previous) = points.last().copied() else { return Ok(()) };
|
||||
let distance = |p: (f64, f64)| (if axis == 0 { p.0 } else { p.1 } - bound) * if greater { 1.0 } else { -1.0 };
|
||||
let mut previous_distance = distance(previous);
|
||||
let mut out = Self { points: [(0.0, 0.0); 12], len: 0 };
|
||||
for ¤t in points {
|
||||
let current_distance = distance(current);
|
||||
if (previous_distance >= 0.0) != (current_distance >= 0.0) {
|
||||
let t = previous_distance / (previous_distance - current_distance);
|
||||
let mut point = ((current.0 - previous.0).mul_add(t, previous.0), (current.1 - previous.1).mul_add(t, previous.1));
|
||||
if axis == 0 {
|
||||
point.0 = bound;
|
||||
} else {
|
||||
point.1 = bound;
|
||||
}
|
||||
out.push(point)?;
|
||||
}
|
||||
if current_distance >= 0.0 {
|
||||
out.push(current)?;
|
||||
}
|
||||
previous = current;
|
||||
previous_distance = current_distance;
|
||||
}
|
||||
*self = out;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn area(&self) -> Result<f64, photocraft_raster::AllocationError> {
|
||||
let points = self.points.get(..self.len).ok_or(photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
let Some(&(x, y)) = points.first() else { return Ok(0.0) };
|
||||
// Translate before the cross products: a small footprint may sit far from the origin.
|
||||
let twice: f64 = points.windows(2).map(|p| (p[0].0 - x) * (p[1].1 - y) - (p[0].1 - y) * (p[1].0 - x)).sum();
|
||||
let area = twice.abs() * 0.5;
|
||||
if area.is_finite() { Ok(area) } else { Err(photocraft_raster::AllocationError::SizeOverflow) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct CropBilinearPlan {
|
||||
points: [(f64, f64); 4],
|
||||
/// Inward edge half-planes relative to points[0]: (normal x, normal y, offset).
|
||||
planes: [(f64, f64, f64); 4],
|
||||
bounds: Rect,
|
||||
lo: [f64; 2],
|
||||
hi: [f64; 2],
|
||||
inverse_area: f64,
|
||||
axis_aligned: bool,
|
||||
samples: usize,
|
||||
}
|
||||
|
||||
impl CropBilinearPlan {
|
||||
fn weight(&self, x: i32, y: i32) -> Result<f64, photocraft_raster::AllocationError> {
|
||||
let (x, y) = (f64::from(x), f64::from(y));
|
||||
if self.axis_aligned {
|
||||
// Fully covered source pixels retain uniform box weights. Fractional boundary pixels
|
||||
// contribute only their actual area; outside-source area is never clamped onto an edge.
|
||||
let width = (self.hi[0].min(x + 1.0) - self.lo[0].max(x)).max(0.0);
|
||||
let height = (self.hi[1].min(y + 1.0) - self.lo[1].max(y)).max(0.0);
|
||||
return Ok(width * height * self.inverse_area);
|
||||
}
|
||||
// Most source pixels are either wholly inside or wholly outside the quad. The extrema
|
||||
// of a linear half-plane over a unit square classify those without polygon clipping.
|
||||
let (dx, dy) = (x - self.points[0].0, y - self.points[0].1);
|
||||
let mut whole = true;
|
||||
for &(nx, ny, offset) in &self.planes {
|
||||
let distance = nx.mul_add(dx, ny.mul_add(dy, offset));
|
||||
if distance + nx.max(0.0) + ny.max(0.0) <= 0.0 {
|
||||
return Ok(0.0);
|
||||
}
|
||||
whole &= distance + nx.min(0.0) + ny.min(0.0) >= 0.0;
|
||||
}
|
||||
if whole {
|
||||
return Ok(self.inverse_area);
|
||||
}
|
||||
let mut polygon = CropPolygon::quad(self.points.map(|p| (p.0 - x, p.1 - y)));
|
||||
for (axis, bound, greater) in [(0, 0.0, true), (0, 1.0, false), (1, 0.0, true), (1, 1.0, false)] {
|
||||
polygon.clip(axis, bound, greater)?;
|
||||
if polygon.len < 3 {
|
||||
return Ok(0.0);
|
||||
}
|
||||
}
|
||||
Ok(polygon.area()?.min(1.0) * self.inverse_area)
|
||||
}
|
||||
}
|
||||
|
||||
fn crop_bilinear_plan(inv: &Homography, x: i32, y: i32, src: Rect) -> Result<Option<CropBilinearPlan>, photocraft_raster::AllocationError> {
|
||||
let (x, y) = (f64::from(x), f64::from(y));
|
||||
let corners = [(x, y), (x + 1.0, y), (x + 1.0, y + 1.0), (x, y + 1.0)];
|
||||
let points = corners.map(|(x, y)| inv.apply(x, y));
|
||||
// Leave room for endpoint arithmetic before converting a hostile projective coordinate to an integer.
|
||||
const LIMIT: f64 = (i64::MAX / 4) as f64;
|
||||
if src.is_empty() || points.iter().any(|(u, v)| !u.is_finite() || !v.is_finite() || u.abs() > LIMIT || v.abs() > LIMIT) {
|
||||
return Err(photocraft_raster::AllocationError::SizeOverflow);
|
||||
}
|
||||
let lo = [points.iter().map(|p| p.0).fold(f64::INFINITY, f64::min), points.iter().map(|p| p.1).fold(f64::INFINITY, f64::min)];
|
||||
let hi = [points.iter().map(|p| p.0).fold(f64::NEG_INFINITY, f64::max), points.iter().map(|p| p.1).fold(f64::NEG_INFINITY, f64::max)];
|
||||
if hi[0] - lo[0] <= 2.0 + 1e-9 && hi[1] - lo[1] <= 2.0 + 1e-9 {
|
||||
return Ok(None);
|
||||
}
|
||||
// A projective horizon inside this pixel has no bounded convex source footprint.
|
||||
let w = corners.map(|(x, y)| inv.w(x, y));
|
||||
if !w.iter().all(|v| v.is_finite() && *v > 0.0) && !w.iter().all(|v| v.is_finite() && *v < 0.0) {
|
||||
return Err(photocraft_raster::AllocationError::SizeOverflow);
|
||||
}
|
||||
let area = CropPolygon::quad(points).area()?;
|
||||
if area <= 0.0 || !area.recip().is_finite() {
|
||||
return Err(photocraft_raster::AllocationError::SizeOverflow);
|
||||
}
|
||||
let bounds = Rect::new(
|
||||
lo[0].floor().clamp(f64::from(src.x0), f64::from(src.x1)) as i32,
|
||||
lo[1].floor().clamp(f64::from(src.y0), f64::from(src.y1)) as i32,
|
||||
hi[0].ceil().clamp(f64::from(src.x0), f64::from(src.x1)) as i32,
|
||||
hi[1].ceil().clamp(f64::from(src.y0), f64::from(src.y1)) as i32,
|
||||
);
|
||||
let width = usize::try_from(i64::from(bounds.x1) - i64::from(bounds.x0)).map_err(|_| photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
let height = usize::try_from(i64::from(bounds.y1) - i64::from(bounds.y0)).map_err(|_| photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
let samples = width.checked_mul(height).ok_or(photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
let axis_aligned = points.iter().zip(points.iter().cycle().skip(1)).all(|(a, b)| a.0 == b.0 || a.1 == b.1);
|
||||
let mut planes = [(0.0, 0.0, 0.0); 4];
|
||||
if !axis_aligned {
|
||||
let [a, b, c, d] = points;
|
||||
let signed = (b.0 - a.0) * (c.1 - a.1) - (b.1 - a.1) * (c.0 - a.0) + (c.0 - a.0) * (d.1 - a.1) - (c.1 - a.1) * (d.0 - a.0);
|
||||
let winding = if signed >= 0.0 { 1.0 } else { -1.0 };
|
||||
for ((a, b), plane) in points.iter().zip(points.iter().cycle().skip(1)).zip(&mut planes) {
|
||||
let (nx, ny) = ((a.1 - b.1) * winding, (b.0 - a.0) * winding);
|
||||
*plane = (nx, ny, nx.mul_add(points[0].0 - a.0, ny * (points[0].1 - a.1)));
|
||||
}
|
||||
}
|
||||
Ok(Some(CropBilinearPlan { points, planes, bounds, lo, hi, inverse_area: area.recip(), axis_aligned, samples }))
|
||||
}
|
||||
|
||||
/// Weights already include source coverage, normalized by the whole mapped footprint (transparent outside).
|
||||
fn sample_crop_bilinear(plan: CropBilinearPlan, at: &impl Fn(i32, i32, usize) -> f64, acc: &mut [f64]) -> Result<(), photocraft_raster::AllocationError> {
|
||||
for y in plan.bounds.y0..plan.bounds.y1 {
|
||||
for x in plan.bounds.x0..plan.bounds.x1 {
|
||||
let weight = plan.weight(x, y)?;
|
||||
if weight <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
for (channel, value) in acc.iter_mut().enumerate() {
|
||||
*value += at(x, y, channel) * weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A cancelled `ctl` skips the remaining tiles; the caller discards the result.
|
||||
fn warp(
|
||||
src: &Surface,
|
||||
@@ -377,7 +559,9 @@ fn warp(
|
||||
interp: Interp,
|
||||
clip: Option<Rect>,
|
||||
ctl: &Interrupt,
|
||||
crop_bilinear: bool,
|
||||
) -> Result<Surface, photocraft_raster::AllocationError> {
|
||||
let crop_bilinear = crop_bilinear && interp == Interp::Bilinear;
|
||||
let mut fmt = src.format();
|
||||
let converted;
|
||||
let mut src = if fmt.alpha {
|
||||
@@ -404,7 +588,8 @@ fn warp(
|
||||
// Photoshop reduces with its Bicubic widened by 1 / scale (as Image Size does), so the source is
|
||||
// brought down by the whole local scale first and the warp samples it at about 1:1; a plain
|
||||
// 4×4 kernel at 50 % aliased (Photoshop 27.11 Free Transform, 50 % of an impulse image).
|
||||
// Bilinear samples the source directly, as Photoshop's does (exact at 50 % without a prefilter).
|
||||
// Free Transform's Bilinear samples directly (exact at 50 % without a prefilter).
|
||||
// Perspective Crop's Bilinear reduction is averaged per output pixel below.
|
||||
if interp == Interp::Bicubic && scale < 0.999 && scale > 0.0 {
|
||||
let f = scale.max(1.0 / 64.0);
|
||||
reduced = resize_surface(src, f, f, Resample::Bicubic);
|
||||
@@ -498,7 +683,10 @@ fn warp(
|
||||
return Ok(None);
|
||||
}
|
||||
// Premultiplied source window.
|
||||
let mut px = src_ref.try_read_region(foot)?;
|
||||
// The crop sampler can visit the sparse surface directly when a highly reduced tile would
|
||||
// need more than 64 MB of dense source samples. Other interpolation paths keep their reads.
|
||||
let dense = !crop_bilinear || u64::from(foot.width()).saturating_mul(u64::from(foot.height())).saturating_mul(n as u64) <= (1 << 24);
|
||||
let mut px = if dense { src_ref.try_read_region(foot)? } else { Vec::new() };
|
||||
for p in px.chunks_exact_mut(n) {
|
||||
let al = p[a];
|
||||
for v in &mut p[..a] {
|
||||
@@ -506,8 +694,20 @@ fn warp(
|
||||
}
|
||||
}
|
||||
let fw = foot.width() as usize;
|
||||
let cached = std::cell::Cell::new((None, [0.0f32; 8]));
|
||||
let at = |x: i32, y: i32, c: usize| -> f64 {
|
||||
if x < foot.x0 || y < foot.y0 || x >= foot.x1 || y >= foot.y1 {
|
||||
if !dense {
|
||||
if cached.get().0 != Some((x, y)) {
|
||||
let mut sample = [0.0f32; 8];
|
||||
src_ref.read_pixel(x, y, &mut sample[..n]);
|
||||
let alpha = sample[a];
|
||||
for channel in sample.iter_mut().take(a) {
|
||||
*channel *= alpha;
|
||||
}
|
||||
cached.set((Some((x, y)), sample));
|
||||
}
|
||||
f64::from(cached.get().1[c])
|
||||
} else if x < foot.x0 || y < foot.y0 || x >= foot.x1 || y >= foot.y1 {
|
||||
0.0
|
||||
} else {
|
||||
px[((y - foot.y0) as usize * fw + (x - foot.x0) as usize) * n + c] as f64
|
||||
@@ -529,6 +729,7 @@ fn warp(
|
||||
outp.try_reserve_exact(len).map_err(|_| photocraft_raster::AllocationError::NotEnoughMemory { bytes })?;
|
||||
outp.resize(len, 0.0f32);
|
||||
let mut any = false;
|
||||
let mut crop_samples = 0usize;
|
||||
let mut acc = [0.0f64; 8];
|
||||
for y in t.y0..t.y1 {
|
||||
for x in t.x0..t.x1 {
|
||||
@@ -537,9 +738,18 @@ fn warp(
|
||||
}
|
||||
let (u, v) = inv.apply(x as f64 + 0.5, y as f64 + 0.5);
|
||||
let (u, v) = (u - 0.5, v - 0.5);
|
||||
if u < src_rect.x0 as f64 - 1.0 || v < src_rect.y0 as f64 - 1.0 || u > src_rect.x1 as f64 || v > src_rect.y1 as f64 {
|
||||
let crop = if crop_bilinear { crop_bilinear_plan(&inv, x, y, src_rect)? } else { None };
|
||||
if crop.is_none() && (u < src_rect.x0 as f64 - 1.0 || v < src_rect.y0 as f64 - 1.0 || u > src_rect.x1 as f64 || v > src_rect.y1 as f64) {
|
||||
continue;
|
||||
}
|
||||
if let Some(plan) = crop {
|
||||
// Bound hostile near-horizon footprints before any source-pixel iteration. The bound
|
||||
// is per destination tile, independent of the source rectangle's size or sparsity.
|
||||
crop_samples = crop_samples.checked_add(plan.samples).ok_or(photocraft_raster::AllocationError::SizeOverflow)?;
|
||||
if crop_samples > 1 << 26 {
|
||||
return Err(photocraft_raster::AllocationError::SizeOverflow);
|
||||
}
|
||||
}
|
||||
acc[..n].fill(0.0);
|
||||
match interp {
|
||||
Interp::Nearest => {
|
||||
@@ -549,12 +759,16 @@ fn warp(
|
||||
}
|
||||
}
|
||||
Interp::Bilinear => {
|
||||
let (ix, iy) = (u.floor() as i32, v.floor() as i32);
|
||||
let (fx, fy) = (u - ix as f64, v - iy as f64);
|
||||
for (dy, wy) in [(0, 1.0 - fy), (1, fy)] {
|
||||
for (dx, wx) in [(0, 1.0 - fx), (1, fx)] {
|
||||
for (c, s) in acc.iter_mut().enumerate().take(n) {
|
||||
*s += clamped(ix + dx, iy + dy, c) * wx * wy;
|
||||
if let Some(plan) = crop {
|
||||
sample_crop_bilinear(plan, &at, &mut acc[..n])?;
|
||||
} else {
|
||||
let (ix, iy) = (u.floor() as i32, v.floor() as i32);
|
||||
let (fx, fy) = (u - ix as f64, v - iy as f64);
|
||||
for (dy, wy) in [(0, 1.0 - fy), (1, fy)] {
|
||||
for (dx, wx) in [(0, 1.0 - fx), (1, fx)] {
|
||||
for (c, s) in acc.iter_mut().enumerate().take(n) {
|
||||
*s += clamped(ix + dx, iy + dy, c) * wx * wy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,8 +786,9 @@ fn warp(
|
||||
}
|
||||
}
|
||||
}
|
||||
if interp != Interp::Nearest {
|
||||
// How much of this pixel the warped source rect covers, per axis.
|
||||
if interp != Interp::Nearest && crop.is_none() {
|
||||
// Planned crop reductions already include coverage in their pixel-intersection weights.
|
||||
// Keep the existing edge coverage for the direct samplers.
|
||||
let (uc, vc) = (u + 0.5, v + 0.5);
|
||||
let cu = ((uc - src_rect.x0 as f64).min(src_rect.x1 as f64 - uc) / foot_u + 0.5).clamp(0.0, 1.0);
|
||||
let cv = ((vc - src_rect.y0 as f64).min(src_rect.y1 as f64 - vc) / foot_v + 0.5).clamp(0.0, 1.0);
|
||||
@@ -629,3 +844,6 @@ fn warp(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod perspective_bilinear_reduction_tests;
|
||||
@@ -0,0 +1,249 @@
|
||||
//! #18071: Perspective Crop's Bilinear reductions average fine source detail.
|
||||
|
||||
use super::*;
|
||||
|
||||
fn reduction() -> Homography {
|
||||
Homography([4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1.0])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_line_phase_averages_to_the_measured_112_level() {
|
||||
let src = Rect::new(0, 0, 16, 16);
|
||||
for line in 0..16 {
|
||||
for x in 0..4 {
|
||||
let plan = crop_bilinear_plan(&reduction(), x, 1, src).unwrap().unwrap();
|
||||
assert_eq!(plan.samples, 16);
|
||||
let mut sample = [0.0; 4];
|
||||
sample_crop_bilinear(plan, &|sx, _, channel| if channel == 3 || sx == line { 1.0 } else { 64.0 / 255.0 }, &mut sample).unwrap();
|
||||
let expected = if x == line / 4 { 111.75 } else { 64.0 };
|
||||
assert!((sample[0] * 255.0 - expected).abs() < 1e-9, "line {line}, column {x}: {:?}", sample);
|
||||
assert_eq!(sample[3], 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stripes_remain_averaged_under_a_projective_skew() {
|
||||
let inv = Homography([4.0, 0.8, 0.0, 0.2, 4.0, 0.0, 0.002, 0.0, 1.0]);
|
||||
for y in 1..8 {
|
||||
for x in 1..8 {
|
||||
let plan = crop_bilinear_plan(&inv, x, y, Rect::new(0, 0, 64, 64)).unwrap().unwrap();
|
||||
let mut sample = [0.0; 4];
|
||||
sample_crop_bilinear(plan, &|sx, _, channel| if channel == 3 || sx % 2 == 0 { 1.0 } else { 64.0 / 255.0 }, &mut sample).unwrap();
|
||||
assert!((0.5..0.8).contains(&sample[0]), "fine stripes must average at ({x}, {y}): {sample:?}");
|
||||
assert!((sample[3] - 1.0).abs() < 1e-12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thin_source_coverage_is_the_same_for_each_line_placement() {
|
||||
for line in 0..4 {
|
||||
let plan = crop_bilinear_plan(&reduction(), 0, 1, Rect::new(line, 0, line + 1, 16)).unwrap().unwrap();
|
||||
let mut sample = [0.0; 4];
|
||||
sample_crop_bilinear(plan, &|_, _, channel| if channel == 0 || channel == 3 { 1.0 } else { 0.0 }, &mut sample).unwrap();
|
||||
assert_eq!(sample, [0.25, 0.0, 0.0, 0.25], "coverage is part of the premultiplied weights, exactly once");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enlargement_and_half_size_keep_the_existing_two_by_two_sampler() {
|
||||
for scale in [0.5, 1.0, 2.0] {
|
||||
let inv = Homography([scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, 1.0]);
|
||||
assert!(crop_bilinear_plan(&inv, 4, 4, Rect::new(0, 0, 32, 32)).unwrap().is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_projective_footprints_fail_before_sampling() {
|
||||
for value in [f64::NAN, f64::INFINITY, f64::MAX] {
|
||||
let inv = Homography([value, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1.0]);
|
||||
assert!(crop_bilinear_plan(&inv, 0, 0, Rect::new(0, 0, 16, 16)).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_source_edges_are_integrated_once_and_never_read_outside_the_source() {
|
||||
let inv = Homography([4.0, 0.0, -0.5, 0.0, 4.0, 0.0, 0.0, 0.0, 1.0]);
|
||||
let plan = crop_bilinear_plan(&inv, 0, 0, Rect::new(0, 0, 8, 8)).unwrap().unwrap();
|
||||
for line in [0, 3] {
|
||||
let mut sample = [0.0; 4];
|
||||
sample_crop_bilinear(
|
||||
plan,
|
||||
&|x, y, channel| {
|
||||
assert!((0..8).contains(&x) && (0..8).contains(&y));
|
||||
if channel == 3 || x == line { 1.0 } else { 0.0 }
|
||||
},
|
||||
&mut sample,
|
||||
)
|
||||
.unwrap();
|
||||
let contribution = if line == 0 { 0.25 } else { 0.125 };
|
||||
assert!((sample[0] - contribution).abs() < 1e-12);
|
||||
assert!((sample[3] - 0.875).abs() < 1e-12);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clipped_projective_footprints_conserve_area_in_either_winding() {
|
||||
for inv in [
|
||||
Homography([4.0, 1.5, 0.25, 0.5, 4.0, 0.75, 0.02, 0.01, 1.0]),
|
||||
Homography([-4.0, 1.5, 12.25, -0.5, 4.0, 4.75, 0.02, 0.01, 1.0]),
|
||||
Homography([0.0, -4.0, 12.25, 4.0, 0.0, 0.75, 0.0, 0.0, 1.0]),
|
||||
] {
|
||||
let plan = crop_bilinear_plan(&inv, 0, 0, Rect::new(-32, -32, 32, 32)).unwrap().unwrap();
|
||||
let mut sample = [0.0];
|
||||
sample_crop_bilinear(plan, &|_, _, _| 1.0, &mut sample).unwrap();
|
||||
assert!((sample[0] - 1.0).abs() < 1e-12, "clipping partitions the full footprint without adding or losing area");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn footprint_weights_are_invariant_under_large_integer_source_translations() {
|
||||
let mut samples = Vec::new();
|
||||
for offset in [0, 1 << 30] {
|
||||
let inv = Homography([4.0, 4.0, f64::from(offset) + 0.25, 0.0, 4.0, -f64::from(offset) + 0.5, 0.0, 0.0, 1.0]);
|
||||
let plan = crop_bilinear_plan(&inv, 0, 0, Rect::new(offset, -offset, offset + 16, -offset + 16)).unwrap().unwrap();
|
||||
let mut sample = [0.0, 0.0];
|
||||
sample_crop_bilinear(plan, &|x, y, channel| if channel == 1 || (x - offset + y + offset) % 3 == 0 { 1.0 } else { 0.0 }, &mut sample).unwrap();
|
||||
samples.push(sample);
|
||||
}
|
||||
for (near, far) in samples[0].iter().zip(samples[1]) {
|
||||
assert!((near - far).abs() < 1e-12);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_horizon_crossing_or_collapsed_reduction_is_refused_before_sampling() {
|
||||
for inv in [Homography([4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 2.0, 0.0, -1.0]), Homography([4.0, 4.0, 0.0, 4.0, 4.0, 0.0, 0.0, 0.0, 1.0])] {
|
||||
assert!(crop_bilinear_plan(&inv, 0, 0, Rect::new(0, 0, 16, 16)).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
// Surface integration coverage follows. The small standalone check runs the sampling tests above.
|
||||
|
||||
use photocraft_color::{ColorMode, SampleType};
|
||||
|
||||
#[test]
|
||||
fn axis_aligned_crop_matches_image_size_for_all_channel_models_and_depths() {
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab] {
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
let fmt = PixelFormat::new(mode, depth, true);
|
||||
let rect = Rect::new(0, 0, 16, 16);
|
||||
for line in 0..16 {
|
||||
let mut src = Surface::new(fmt);
|
||||
let mut gray = vec![64.0 / 255.0; fmt.channels()];
|
||||
*gray.last_mut().unwrap() = 1.0;
|
||||
src.fill_rect(rect, &gray);
|
||||
src.fill_rect(Rect::new(line, 0, line + 1, 16), &vec![1.0; fmt.channels()]);
|
||||
let expected = crate::resample::resize_surface_in_canvas(&src, 0.25, 0.25, Resample::Bilinear, rect);
|
||||
let h = Homography([0.25, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 1.0]);
|
||||
let crop = warp_surface_clipped_for_crop(&src, rect, &h, Interp::Bilinear, Rect::new(0, 0, 4, 4)).unwrap();
|
||||
for x in 0..4 {
|
||||
let value = crop.pixel(x, 1);
|
||||
let reference = expected.pixel(x, 1);
|
||||
for (value, expected) in value.iter().zip(reference) {
|
||||
assert!((value - expected).abs() <= 1.0 / 255.0, "{mode:?}, {depth:?}, line {line}, x {x}: {value} vs {expected}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thin_opaque_lines_keep_premultiplied_colour_and_quarter_coverage() {
|
||||
for line in 0..4 {
|
||||
let mut src = Surface::new(PixelFormat::RGBA32F);
|
||||
src.fill_rect(Rect::new(line, 0, line + 1, 16), &[1.0, 0.0, 0.0, 1.0]);
|
||||
let h = Homography([0.25, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 1.0]);
|
||||
let crop = warp_surface_clipped_for_crop(&src, src.content_bounds(), &h, Interp::Bilinear, Rect::new(0, 0, 4, 4)).unwrap();
|
||||
let pixel = crop.pixel(0, 1);
|
||||
assert_eq!(pixel, vec![1.0, 0.0, 0.0, 0.25], "line {line}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_edge_lines_contribute_their_area_without_repeated_edge_weights() {
|
||||
for horizontal in [false, true] {
|
||||
for last in [false, true] {
|
||||
let mut src = Surface::new(PixelFormat::RGBA32F);
|
||||
src.fill_rect(Rect::new(0, 0, 8, 8), &[0.0, 0.0, 0.0, 1.0]);
|
||||
let line = if last { 7 } else { 0 };
|
||||
let rect = if horizontal { Rect::new(0, line, 8, line + 1) } else { Rect::new(line, 0, line + 1, 8) };
|
||||
src.fill_rect(rect, &[1.0; 4]);
|
||||
let offset = if last { 5.0 } else { -1.0 };
|
||||
let (tx, ty) = if horizontal { (0.0, offset) } else { (offset, 0.0) };
|
||||
let inverse = Homography([4.0, 0.0, tx, 0.0, 4.0, ty, 0.0, 0.0, 1.0]);
|
||||
let crop =
|
||||
warp_surface_clipped_for_crop(&src, Rect::new(0, 0, 8, 8), &inverse.inverse().unwrap(), Interp::Bilinear, Rect::new(0, 0, 1, 1)).unwrap();
|
||||
let pixel = crop.pixel(0, 0);
|
||||
assert!((pixel[3] - 0.75).abs() < 1e-6, "three of four columns/rows are inside: {pixel:?}");
|
||||
assert!((pixel[0] * pixel[3] - 0.25).abs() < 1e-6, "the line covers one quarter of the full footprint: {pixel:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sheared_footprints_use_pixel_intersection_area_instead_of_the_bounding_box() {
|
||||
let inverse = Homography([4.0, 4.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1.0]);
|
||||
for y in 0..4 {
|
||||
for x in 0..8 {
|
||||
let mut src = Surface::new(PixelFormat::RGBA32F);
|
||||
src.fill_rect(Rect::new(0, 0, 8, 4), &[0.0, 0.0, 0.0, 1.0]);
|
||||
src.fill_rect(Rect::new(x, y, x + 1, y + 1), &[1.0; 4]);
|
||||
let crop =
|
||||
warp_surface_clipped_for_crop(&src, Rect::new(0, 0, 8, 4), &inverse.inverse().unwrap(), Interp::Bilinear, Rect::new(0, 0, 1, 1)).unwrap();
|
||||
let pixel = crop.pixel(0, 0);
|
||||
// The parallelogram is y <= x <= y + 4 for 0 <= y <= 4 (area 16).
|
||||
// Its diagonal edges bisect their grid cells; the three interior cells in each row are whole.
|
||||
let area = if x == y || x == y + 4 {
|
||||
0.5
|
||||
} else if x > y && x < y + 4 {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
assert!((pixel[0] - area / 16.0).abs() < 1e-6, "pixel ({x}, {y}) has intersection area {area}: {pixel:?}");
|
||||
assert!((pixel[3] - 1.0).abs() < 1e-6, "the footprint is fully inside the opaque source");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_source_clipped_shear_keeps_its_colour_and_geometric_alpha_in_both_windings() {
|
||||
let source = Rect::new(2, 0, 6, 4);
|
||||
let mut src = Surface::new(PixelFormat::RGBA32F);
|
||||
src.fill_rect(source, &[1.0, 0.0, 0.0, 1.0]);
|
||||
for inv in [Homography([4.0, 4.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1.0]), Homography([-4.0, 4.0, 4.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1.0])] {
|
||||
let crop = warp_surface_clipped_for_crop(&src, source, &inv.inverse().unwrap(), Interp::Bilinear, Rect::new(0, 0, 1, 1)).unwrap();
|
||||
// Clipping y <= x <= y + 4 to 2 <= x <= 6 leaves area 12 of the original 16.
|
||||
assert_eq!(crop.pixel(0, 0), vec![1.0, 0.0, 0.0, 0.75]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_interpolation_paths_and_bilinear_enlargement_match_exactly() {
|
||||
let mut src = Surface::new(PixelFormat::RGBA32F);
|
||||
let rect = Rect::new(0, 0, 16, 16);
|
||||
src.fill_rect(rect, &[0.25, 0.5, 0.75, 1.0]);
|
||||
src.fill_rect(Rect::new(3, 0, 4, 16), &[1.0, 0.0, 0.0, 0.5]);
|
||||
for (scale, interpolation) in [(0.25, Interp::Nearest), (0.25, Interp::Bicubic), (2.0, Interp::Bilinear)] {
|
||||
let h = Homography([scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, 1.0]);
|
||||
let clip = Rect::new(0, 0, (16.0 * scale) as i32, (16.0 * scale) as i32);
|
||||
let before = warp_surface_clipped(&src, rect, &h, interpolation, clip).unwrap();
|
||||
let crop = warp_surface_clipped_for_crop(&src, rect, &h, interpolation, clip).unwrap();
|
||||
assert_eq!(crop.read_region(clip), before.read_region(clip), "{interpolation:?}, scale {scale}");
|
||||
}
|
||||
let h = Homography([0.25, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 1.0]);
|
||||
let direct = warp_surface_clipped(&src, rect, &h, Interp::Bilinear, Rect::new(0, 0, 4, 4)).unwrap();
|
||||
assert_eq!(direct.pixel(0, 1), vec![0.25, 0.5, 0.75, 1.0], "Free Transform keeps direct Bilinear sampling");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_absurd_sparse_reduction_is_refused_without_a_dense_source_read() {
|
||||
let mut src = Surface::new(PixelFormat::RGBA32F);
|
||||
src.fill_rect(Rect::new(0, 0, 1, 1), &[1.0, 0.0, 0.0, 1.0]);
|
||||
let h = Homography([0.0001, 0.0, 0.0, 0.0, 0.0001, 0.0, 0.0, 0.0, 1.0]);
|
||||
let result = warp_surface_clipped_for_crop(&src, Rect::new(0, 0, 10_000, 10_000), &h, Interp::Bilinear, Rect::new(0, 0, 1, 1));
|
||||
assert!(matches!(result, Err(photocraft_raster::AllocationError::SizeOverflow)));
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
//! The source rectangle is subdivided into a fine grid whose vertices are mapped forward; each
|
||||
//! cell's two triangles are rasterized in destination space with the source position
|
||||
//! interpolated barycentrically, then the source is sampled there (premultiplied, nearest /
|
||||
//! bilinear / Photoshop's Keys bicubic, like Free Transform). Cells are a few pixels across in
|
||||
//! bilinear / Keys bicubic; Edit › Transform › Warp and smart objects pick theirs with
|
||||
//! [`warp_interp`]). Cells are a few pixels across in
|
||||
//! both the source and the destination (a thin layer stretched far gets as many cells as its
|
||||
//! warped size needs), so the piecewise-affine inverse is within a small fraction of a pixel of
|
||||
//! the true one; affine
|
||||
@@ -15,7 +16,7 @@
|
||||
//! the layers composite; for other mesh maps (lens corrections, distortions) the later
|
||||
//! (lower-right) cell wins. Work is split per destination tile (parallel on native).
|
||||
|
||||
use photocraft_color::PixelFormat;
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_geom::{Rect, TileCoord};
|
||||
use photocraft_raster::{Interrupt, Surface, Tile};
|
||||
use std::sync::Arc;
|
||||
@@ -38,6 +39,17 @@ pub enum Fold<'a> {
|
||||
Stack(&'a (dyn Fn(f64, f64) -> (f64, f64) + Sync)),
|
||||
}
|
||||
|
||||
/// How the warped picture's outline meets the transparency around it.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Outline {
|
||||
/// Pixels the outline crosses blend with the transparency (partial alpha).
|
||||
Antialiased,
|
||||
/// Each pixel whose centre the warp covers takes the picture's value, the others stay
|
||||
/// transparent: sampling reads the edge pixels in place of what lies past them. Inside the
|
||||
/// picture the result is the same as [`Outline::Antialiased`]'s.
|
||||
Hard,
|
||||
}
|
||||
|
||||
impl Fold<'_> {
|
||||
/// [`Fold::Stack`] about the identity: a warp of a layer where it is.
|
||||
pub const IN_PLACE: Fold<'static> = Fold::Stack(&|x: f64, y: f64| (x, y));
|
||||
@@ -49,10 +61,25 @@ const MAX_SS: f64 = 8.0;
|
||||
/// Bounding-box pixels scanned per destination pixel of a tile, across all its triangles.
|
||||
const MAX_SCAN_PER_PIXEL: usize = 256;
|
||||
|
||||
/// The kernel Edit › Transform › Warp samples with for an interpolation choice on a surface of
|
||||
/// format `fmt`. The reference application's Warp knows two: Nearest Neighbor, and one smooth
|
||||
/// kernel that does not ring next to an edge, which Bilinear and every Bicubic give alike (Free
|
||||
/// Transform without warp honours each choice and keeps its own kernels). That was measured on RGB
|
||||
/// at 8 and 16 bits; other modes and 32 bits keep the choice as it is.
|
||||
pub fn warp_interp(choice: Interp, fmt: PixelFormat) -> Interp {
|
||||
let measured = fmt.mode == ColorMode::Rgb && matches!(fmt.sample, SampleType::U8 | SampleType::U16);
|
||||
match choice {
|
||||
Interp::Nearest => Interp::Nearest,
|
||||
_ if measured => Interp::Bilinear,
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
/// Places a smart object's source image (`src`, its pixels in `src_rect`) in the document:
|
||||
/// through `warp` (source space) and then the affine `t` (source → document) in one resampling
|
||||
/// pass, an exact shift for whole-pixel translations (so conversions and re-renders are
|
||||
/// lossless), bicubic otherwise. Shared by the engine's re-render and PSD export's filter cache.
|
||||
/// lossless), bicubic otherwise. A warp ignores the interpolation choice and always samples with
|
||||
/// the smooth kernel of [`warp_interp`], as the reference application's smart-object warps do. Shared by the engine's re-render and PSD export's filter cache.
|
||||
pub fn place_source(
|
||||
src: &Surface,
|
||||
src_rect: Rect,
|
||||
@@ -67,7 +94,7 @@ pub fn place_source(
|
||||
};
|
||||
// A fold's layers are ordered by how far the warp moved them, not the placement.
|
||||
let rest = |x: f64, y: f64| (a * x + c * y + e, b * x + d * y + f);
|
||||
return Ok(mesh(src, src_rect, &map, Fold::Stack(&rest), Interp::Bicubic, &Interrupt::NONE));
|
||||
return Ok(mesh(src, src_rect, &map, Fold::Stack(&rest), warp_interp(Interp::Bicubic, src.format()), &Interrupt::NONE));
|
||||
}
|
||||
let near = |x: f64, y: f64| (x - y).abs() < 1e-9;
|
||||
if near(a, 1.0) && near(b, 0.0) && near(c, 0.0) && near(d, 1.0) && near(e, e.round()) && near(f, f.round()) {
|
||||
@@ -90,7 +117,7 @@ pub fn place_source_projective(
|
||||
h.apply(u, v)
|
||||
};
|
||||
let rest = |x: f64, y: f64| h.apply(x, y);
|
||||
return Ok(mesh(src, src_rect, &map, Fold::Stack(&rest), Interp::Bicubic, &Interrupt::NONE));
|
||||
return Ok(mesh(src, src_rect, &map, Fold::Stack(&rest), warp_interp(Interp::Bicubic, src.format()), &Interrupt::NONE));
|
||||
}
|
||||
crate::transform::warp_surface(src, src_rect, h, Interp::Bicubic)
|
||||
}
|
||||
@@ -112,7 +139,20 @@ pub fn warp_mesh_surface_with(
|
||||
interp: Interp,
|
||||
ctl: &Interrupt,
|
||||
) -> Option<Surface> {
|
||||
let out = mesh(src, src_rect, f, fold, interp, ctl);
|
||||
warp_mesh_surface_outline(src, src_rect, f, fold, interp, Outline::Antialiased, ctl)
|
||||
}
|
||||
|
||||
/// [`warp_mesh_surface_with`] with the outline drawn as `outline` says.
|
||||
pub fn warp_mesh_surface_outline(
|
||||
src: &Surface,
|
||||
src_rect: Rect,
|
||||
f: &(dyn Fn(f64, f64) -> (f64, f64) + Sync),
|
||||
fold: Fold,
|
||||
interp: Interp,
|
||||
outline: Outline,
|
||||
ctl: &Interrupt,
|
||||
) -> Option<Surface> {
|
||||
let out = mesh_outline(src, src_rect, f, fold, interp, outline, ctl);
|
||||
(!ctl.cancelled()).then_some(out)
|
||||
}
|
||||
|
||||
@@ -158,6 +198,19 @@ pub fn cell_order(pos: &[[f64; 2]], rest: &[[f64; 2]], row: usize) -> Vec<usize>
|
||||
|
||||
/// Folds stack as `fold` says.
|
||||
fn mesh(src: &Surface, src_rect: Rect, f: &(dyn Fn(f64, f64) -> (f64, f64) + Sync), fold: Fold, interp: Interp, ctl: &Interrupt) -> Surface {
|
||||
mesh_outline(src, src_rect, f, fold, interp, Outline::Antialiased, ctl)
|
||||
}
|
||||
|
||||
/// [`mesh`] with the outline drawn as `outline` says.
|
||||
fn mesh_outline(
|
||||
src: &Surface,
|
||||
src_rect: Rect,
|
||||
f: &(dyn Fn(f64, f64) -> (f64, f64) + Sync),
|
||||
fold: Fold,
|
||||
interp: Interp,
|
||||
outline: Outline,
|
||||
ctl: &Interrupt,
|
||||
) -> Surface {
|
||||
if src_rect.is_empty() {
|
||||
let fmt = src.format();
|
||||
return Surface::new(PixelFormat::new(fmt.mode, fmt.sample, true));
|
||||
@@ -211,7 +264,7 @@ fn mesh(src: &Surface, src_rect: Rect, f: &(dyn Fn(f64, f64) -> (f64, f64) + Syn
|
||||
rank
|
||||
};
|
||||
let stack: Option<&(dyn Fn() -> Vec<u32> + Sync)> = matches!(fold, Fold::Stack(_)).then_some(&rank);
|
||||
triangles(src, src_rect, &verts, &tris, interp, ctl, stack)
|
||||
triangles(src, src_rect, &verts, &tris, (interp, outline), ctl, stack)
|
||||
}
|
||||
|
||||
/// Probe lines per axis [`mapped_lengths`] follows through the map.
|
||||
@@ -256,7 +309,7 @@ fn mapped_lengths(src_rect: Rect, f: &(dyn Fn(f64, f64) -> (f64, f64) + Sync)) -
|
||||
/// interpolation of its source positions. Later triangles in `tris` draw over earlier ones (the
|
||||
/// order is the depth order). Output has `src`'s format with alpha added.
|
||||
pub fn warp_triangles(src: &Surface, src_rect: Rect, verts: &[([f64; 2], [f64; 2])], tris: &[[usize; 3]], interp: Interp) -> Surface {
|
||||
triangles(src, src_rect, verts, tris, interp, &Interrupt::NONE, None)
|
||||
triangles(src, src_rect, verts, tris, (interp, Outline::Antialiased), &Interrupt::NONE, None)
|
||||
}
|
||||
|
||||
/// [`warp_triangles`], reporting progress per destination tile to `ctl`. A cancelled `ctl` skips
|
||||
@@ -405,7 +458,7 @@ fn triangles(
|
||||
src_rect: Rect,
|
||||
verts: &[([f64; 2], [f64; 2])],
|
||||
tris: &[[usize; 3]],
|
||||
interp: Interp,
|
||||
(interp, outline): (Interp, Outline),
|
||||
ctl: &Interrupt,
|
||||
stack: Option<&(dyn Fn() -> Vec<u32> + Sync)>,
|
||||
) -> Surface {
|
||||
@@ -684,6 +737,12 @@ fn triangles(
|
||||
let top_win = |q: [f64; 2]| top_regions.of(q).and_then(|r| top.get(r)).and_then(Option::as_ref);
|
||||
let below_win = |q: [f64; 2]| below_regions.of(q).and_then(|r| below.get(r)).and_then(Option::as_ref);
|
||||
let at = |win: &Win, x: i32, y: i32, c: usize| -> f64 {
|
||||
// A hard outline reads the picture's edge pixels past its edge, so a pixel the warp
|
||||
// covers takes no transparency in (the windows lie inside `src_rect`).
|
||||
let (x, y) = match outline {
|
||||
Outline::Hard => (x.clamp(src_rect.x0, src_rect.x1 - 1), y.clamp(src_rect.y0, src_rect.y1 - 1)),
|
||||
Outline::Antialiased => (x, y),
|
||||
};
|
||||
let foot = win.foot;
|
||||
if x < foot.x0 || y < foot.y0 || x >= foot.x1 || y >= foot.y1 {
|
||||
0.0
|
||||
@@ -900,6 +959,10 @@ pub fn warp_mesh_gray_with(s: &Surface, f: &(dyn Fn(f64, f64) -> (f64, f64) + Sy
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "warp_smooth_kernel_tests.rs"]
|
||||
mod smooth_kernel_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
//! Edit › Transform › Warp and smart-object warps sample with one smooth, non-ringing kernel for
|
||||
//! every smooth interpolation choice (#17577).
|
||||
|
||||
use super::*;
|
||||
use crate::transform::Homography;
|
||||
use photocraft_color::{ColorMode, SampleType};
|
||||
use photocraft_geom::Affine;
|
||||
use photocraft_geom::warp::{Warp, WarpStyle};
|
||||
|
||||
const SMOOTH: [&str; 5] = ["bicubic", "bicubicSharper", "bicubicSmoother", "bicubicAutomatic", "bilinear"];
|
||||
|
||||
/// The item's test layer: 200 × 150 px at (100, 75), grey 128 with a 1 px black line every 10 px.
|
||||
fn grid(depth: SampleType) -> (Surface, Rect) {
|
||||
grid_in(ColorMode::Rgb, depth)
|
||||
}
|
||||
|
||||
fn grid_in(mode: ColorMode, depth: SampleType) -> (Surface, Rect) {
|
||||
let r = Rect::new(100, 75, 300, 225);
|
||||
let mut s = Surface::new(PixelFormat::new(mode, depth, true));
|
||||
let n = mode.color_channels();
|
||||
let px = |v: f32| (0..=n).map(|c| if c == n { 1.0 } else { v }).collect::<Vec<f32>>();
|
||||
s.fill_rect(r, &px(128.0 / 255.0));
|
||||
for i in 0..20 {
|
||||
s.fill_rect(Rect::new(r.x0 + i * 10, r.y0, r.x0 + i * 10 + 1, r.y1), &px(0.0));
|
||||
}
|
||||
for i in 0..15 {
|
||||
s.fill_rect(Rect::new(r.x0, r.y0 + i * 10, r.x1, r.y0 + i * 10 + 1), &px(0.0));
|
||||
}
|
||||
(s, r)
|
||||
}
|
||||
|
||||
fn arc(r: Rect) -> Warp {
|
||||
Warp::preset(WarpStyle::Arc, 50.0, [f64::from(r.x0), f64::from(r.y0), f64::from(r.x1), f64::from(r.y1)])
|
||||
}
|
||||
|
||||
fn warp(src: &Surface, r: Rect, w: &Warp, choice: &str) -> Surface {
|
||||
warp_mesh_surface_with(src, r, &|x, y| w.map(x, y), Fold::IN_PLACE, warp_interp(Interp::parse(choice), src.format()), &Interrupt::NONE).unwrap()
|
||||
}
|
||||
|
||||
/// The brightest colour channel of the opaque pixels, in 8-bit levels.
|
||||
fn interior_max(s: &Surface) -> f32 {
|
||||
let b = s.content_bounds();
|
||||
let mut max = 0.0f32;
|
||||
for y in b.y0..b.y1 {
|
||||
for x in b.x0..b.x1 {
|
||||
let p = s.pixel(x, y);
|
||||
let (alpha, colour) = p.split_last().unwrap_or((&0.0, &[]));
|
||||
if *alpha >= 1.0 {
|
||||
max = colour.iter().fold(max, |m, &c| m.max(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
max * 255.0
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_smooth_choice_warps_like_bilinear_at_8_and_16_bit() {
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
let (src, r) = grid(depth);
|
||||
let w = arc(r);
|
||||
let want = warp(&src, r, &w, "bilinear");
|
||||
let b = want.content_bounds();
|
||||
for choice in SMOOTH {
|
||||
let got = warp(&src, r, &w, choice);
|
||||
assert_eq!(got.content_bounds(), b, "{depth:?} {choice}");
|
||||
assert!(got.read_region(b) == want.read_region(b), "{depth:?} {choice}: not the bilinear pixels");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arc_50_on_the_grid_never_rises_above_its_grey() {
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
let (src, r) = grid(depth);
|
||||
for choice in SMOOTH {
|
||||
let max = interior_max(&warp(&src, r, &arc(r), choice));
|
||||
assert!(max <= 128.5, "{depth:?} {choice}: interior max {max}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_neighbor_keeps_only_the_source_values() {
|
||||
let (src, r) = grid(SampleType::U8);
|
||||
let out = warp(&src, r, &arc(r), "nearestNeighbor");
|
||||
let b = out.content_bounds();
|
||||
assert!(b.y0 < r.y0, "the arc moved the layer: {b:?}");
|
||||
for y in b.y0..b.y1 {
|
||||
for x in b.x0..b.x1 {
|
||||
let p = out.pixel(x, y);
|
||||
if p[3] > 0.0 {
|
||||
let level = (p[0] * 255.0).round();
|
||||
assert!(level == 0.0 || level == 128.0, "({x}, {y}): {p:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_smart_object_warp_does_not_ring_under_any_placement() {
|
||||
let (src, r) = grid(SampleType::U8);
|
||||
let w = arc(r);
|
||||
let shifted = Affine { m: [1.0, 0.0, 0.0, 1.0, 12.0, -7.0] };
|
||||
let turned = Affine { m: [0.9986, 0.0523, -0.0523, 0.9986, 8.0, -9.0] };
|
||||
for t in [shifted, turned] {
|
||||
let out = place_source(&src, r, &t, Some(&w)).unwrap();
|
||||
assert!(!out.content_bounds().is_empty());
|
||||
let max = interior_max(&out);
|
||||
assert!(max <= 128.5, "{:?}: interior max {max}", t.m);
|
||||
}
|
||||
let h = Homography::rect_to_quad(
|
||||
[f64::from(r.x0), f64::from(r.y0), f64::from(r.x1), f64::from(r.y1)],
|
||||
[[100.0, 80.0], [310.0, 70.0], [300.0, 230.0], [95.0, 220.0]],
|
||||
)
|
||||
.unwrap();
|
||||
let max = interior_max(&place_source_projective(&src, r, &h, Some(&w)).unwrap());
|
||||
assert!(max <= 128.5, "distorted placement: interior max {max}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modes_and_depths_not_measured_keep_their_bicubic() {
|
||||
for (mode, depth) in [(ColorMode::Grayscale, SampleType::U8), (ColorMode::Rgb, SampleType::F32), (ColorMode::Cmyk, SampleType::U16)] {
|
||||
let (src, r) = grid_in(mode, depth);
|
||||
let w = arc(r);
|
||||
let bicubic = warp(&src, r, &w, "bicubic");
|
||||
let max = interior_max(&bicubic);
|
||||
assert!(max > 129.0, "{mode:?} {depth:?}: Bicubic still overshoots, interior max {max}");
|
||||
let smart = place_source(&src, r, &Affine { m: [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] }, Some(&w)).unwrap();
|
||||
let max = interior_max(&smart);
|
||||
assert!(max > 129.0, "{mode:?} {depth:?}: a smart-object warp keeps today's bicubic, interior max {max}");
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ fn scalar_local_sharpen(
|
||||
for c in 0..ch {
|
||||
let v = data[i + c];
|
||||
if Some(c) == alpha {
|
||||
out[o + c] = v;
|
||||
out[o + c] = if protect_detail { v } else { (v + amount * (v - blur[o + c])).clamp(0.0, 1.0) };
|
||||
continue;
|
||||
}
|
||||
let d = v - blur[o + c];
|
||||
|
||||
@@ -334,10 +334,24 @@ impl Headless {
|
||||
_ => return Err(AutomationError::BadRequest("automation filesystem access is not granted: write authority is absent".into())),
|
||||
};
|
||||
let mut outputs = workspace.export_sequence(dir)?;
|
||||
let written = photocraft_engine::export_data_sets_with(&this.session, params, |name, bytes| {
|
||||
let report = photocraft_engine::export_data_sets_report_with(&this.session, params, |name, bytes| {
|
||||
outputs.write(name, bytes).map_err(|e| photocraft_engine::EngineError::Other(e.to_string()))
|
||||
});
|
||||
exported(dir, written, &mut outputs)
|
||||
// The sets a missing replacement image left out or stopped at, as the command says (#13767).
|
||||
let (written, report) = match report {
|
||||
Ok(report) => (Ok(report.files.clone()), Some(report)),
|
||||
Err(error) => (Err(error), None),
|
||||
};
|
||||
let mut result = exported(dir, written, &mut outputs)?;
|
||||
if let Some(report) = report {
|
||||
let full = report.json(Vec::new());
|
||||
for key in ["skipped", "stopped"] {
|
||||
if let Some(value) = full.get(key) {
|
||||
result[key] = value.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -573,7 +573,7 @@ fn doc_export_layers_reports_skips_in_workspace_and_trusted_sessions() {
|
||||
let mut h =
|
||||
if trusted { Headless::trusted_local() } else { Headless::with_workspace(crate::AuthorizedWorkspace::new(Some(&base), Some(&base)).unwrap()) };
|
||||
h.handle("doc.new", json!({"width": 4, "height": 4, "background": "white", "name": "card"})).unwrap();
|
||||
let adjustment = h.handle("engine.execute", json!({"command": "layer.newAdjustmentLayer.levels"})).unwrap()["layer"].clone();
|
||||
h.handle("engine.execute", json!({"command": "layer.newAdjustmentLayer.levels"})).unwrap();
|
||||
h.handle("engine.execute", json!({"command": "layer.setProps", "params": {"name": "Levels"}})).unwrap();
|
||||
let hidden = h.handle("engine.execute", json!({"command": "layer.new.layer", "params": {"name": "Hidden"}})).unwrap()["layer"].clone();
|
||||
h.handle("engine.execute", json!({"command": "layer.setProps", "params": {"visible": false}})).unwrap();
|
||||
@@ -586,23 +586,22 @@ fn doc_export_layers_reports_skips_in_workspace_and_trusted_sessions() {
|
||||
let reply: Value = serde_json::from_slice(&output).unwrap();
|
||||
assert_eq!(reply["id"], 8491);
|
||||
assert_eq!(reply["ok"], true, "{reply}");
|
||||
assert_eq!(reply["result"]["files"], json!([format!("{out_dir}/card_0002_Background.png")]));
|
||||
assert_eq!(reply["result"]["files"], json!([format!("{out_dir}/card_0001_Levels.png"), format!("{out_dir}/card_0002_Background.png")]));
|
||||
if !trusted {
|
||||
assert_eq!(reply["result"]["count"], 1);
|
||||
assert_eq!(reply["result"]["count"], 2);
|
||||
}
|
||||
assert_eq!(
|
||||
reply["result"]["skipped"],
|
||||
json!([
|
||||
{"layer": hidden, "name": "Hidden", "reason": "hidden by visibleOnly"},
|
||||
{"layer": adjustment, "name": "Levels", "reason": "adjustment layer has no pixels of its own"}
|
||||
{"layer": hidden, "name": "Hidden", "reason": "hidden by visibleOnly"}
|
||||
])
|
||||
);
|
||||
assert_eq!(std::fs::read_dir(base.join("out")).unwrap().count(), 1);
|
||||
assert_eq!(std::fs::read_dir(base.join("out")).unwrap().count(), 2);
|
||||
let mut h = h.into_inner().unwrap();
|
||||
let all_dir = base.join("all").to_string_lossy().into_owned();
|
||||
let all = h.export_layers(None, &all_dir, &json!({"visibleOnly": false})).unwrap();
|
||||
assert_eq!(all["files"].as_array().unwrap().len(), 2);
|
||||
assert_eq!(all["skipped"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(all["files"].as_array().unwrap().len(), 3);
|
||||
assert_eq!(all["skipped"].as_array().unwrap().len(), 0);
|
||||
// Workspace no-overwrite errors still fail and remove only newly created files.
|
||||
if !trusted {
|
||||
let collision = base.join("collision");
|
||||
|
||||
@@ -637,6 +637,9 @@ impl PhotocraftMcp {
|
||||
|
||||
pub fn with_backend(backend: Backend) -> Self {
|
||||
let mut tool_router = Self::tool_router();
|
||||
if matches!(&backend, Backend::Headless(_)) {
|
||||
tool_router.map.retain(|name, _| !name.starts_with("ui_") && name != "control_call");
|
||||
}
|
||||
for route in tool_router.map.values_mut() {
|
||||
let mut schema = (*route.attr.input_schema).clone();
|
||||
strict_schema(&mut schema);
|
||||
@@ -869,7 +872,7 @@ impl PhotocraftMcp {
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Export top-level layers as files (groups merged). Returns files and skipped: [{layer, name, reason}] for hidden layers (visible_only) and adjustments with no pixels of their own. Workspace exports resolve beneath the write root, also return count of written files, and reject existing files instead of overwriting them. Trusted-local/bridge exports use the engine command's file access policy."
|
||||
description = "Export each layer as a file; groups are walked (a group gets no file, each layer in it does, named <prefix>_<group index>s_<index>_<name>). Returns files and skipped: [{layer, name, reason}] for hidden layers (visible_only, including the layers of a hidden group) and adjustments with no pixels of their own. Workspace exports resolve beneath the write root, also return count of written files, and reject existing files instead of overwriting them. Trusted-local/bridge exports use the engine command's file access policy."
|
||||
)]
|
||||
async fn doc_export_layers(&self, Parameters(p): Parameters<ExportLayersParams>) -> Result<CallToolResult, McpError> {
|
||||
let mut opts = serde_json::Map::new();
|
||||
@@ -1058,13 +1061,13 @@ impl PhotocraftMcp {
|
||||
`disabledReason` says why a command is off (null when enabled); `needsDocument` is true when it is off because no \
|
||||
document is open: create or open one first (doc_new, doc_open).")]
|
||||
async fn command_list(&self, Parameters(p): Parameters<ListParams>) -> Result<CallToolResult, McpError> {
|
||||
let all = if let Some(r) = self.headless_op(|h| Ok(h.command_list())).await {
|
||||
r
|
||||
let (all, headless) = if let Some(r) = self.headless_op(|h| Ok(h.command_list())).await {
|
||||
(r, true)
|
||||
} else {
|
||||
let Some(b) = self.bridge_client() else {
|
||||
return Ok(no_backend());
|
||||
};
|
||||
b.call_read("engine.commands", json!({})).await
|
||||
(b.call_read("engine.commands", json!({})).await, false)
|
||||
};
|
||||
let all = match all {
|
||||
Ok(v) => v,
|
||||
@@ -1072,10 +1075,19 @@ impl PhotocraftMcp {
|
||||
};
|
||||
let needle = p.filter.map(|f| f.to_lowercase());
|
||||
let enabled_only = p.enabled_only.unwrap_or(false);
|
||||
let params = json!({});
|
||||
let items: Vec<Value> = into_command_rows(all)
|
||||
.into_iter()
|
||||
.filter(|c| {
|
||||
needle.as_ref().is_none_or(|n| photocraft_engine::commands::list_entry_matches(c, n))
|
||||
let allowed = c.get("id").and_then(Value::as_str).is_some_and(|id| {
|
||||
if headless {
|
||||
id == "file.export.renderVideo" || crate::workspace::authorize_engine_command(id, ¶ms).is_ok()
|
||||
} else {
|
||||
crate::workspace::authorize_desktop_engine_command(id, ¶ms).is_ok()
|
||||
}
|
||||
});
|
||||
allowed
|
||||
&& needle.as_ref().is_none_or(|n| photocraft_engine::commands::list_entry_matches(c, n))
|
||||
&& (!enabled_only || c.get("enabled").and_then(Value::as_bool).unwrap_or(true))
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -9,7 +9,7 @@ use rmcp::service::RequestContext;
|
||||
|
||||
const DOCUMENT: &str = "photocraft://document";
|
||||
const COMMANDS: &str = "photocraft://commands";
|
||||
const INSTRUCTIONS: &str = "PhotoCraft image editor. Start with doc_new/doc_open, discover ids and parameter docs with command_list, edit with command_run or command_batch (one history step per command). Inspect with doc_inspect and render_preview; doc_save writes native .pcraft or exports by extension. File paths are relative to the read/write roots granted at launch; agent_folders tells where they are. ui_inspect/ui_screenshot and other ui_* tools require bridge mode. Read photocraft://document and photocraft://commands for live JSON state.";
|
||||
const INSTRUCTIONS: &str = "PhotoCraft image editor. Start with doc_new/doc_open, discover ids and parameter docs with command_list, edit with command_run or command_batch (one history step per command). Inspect with doc_inspect and render_preview; doc_save writes native .pcraft or exports by extension. File paths are relative to the read/write roots granted at launch; agent_folders tells where they are. ui_* tools and control_call, where listed, need the open app (bridge mode). Read photocraft://document and photocraft://commands for live JSON state.";
|
||||
|
||||
fn annotated(mut tool: Tool) -> Tool {
|
||||
let words = tool.name.replace('_', " ");
|
||||
|
||||
@@ -93,15 +93,11 @@ async fn lists_expected_tools() {
|
||||
"command_list",
|
||||
"command_run",
|
||||
"command_batch",
|
||||
"ui_inspect",
|
||||
"ui_screenshot",
|
||||
"ui_pointer",
|
||||
"ui_menu_invoke",
|
||||
"ui_set",
|
||||
"control_call",
|
||||
] {
|
||||
assert!(names.contains(&n.to_string()), "missing tool {n}: {names:?}");
|
||||
}
|
||||
assert!(!names.iter().any(|name| name.starts_with("ui_") || name == "control_call"));
|
||||
assert!(client.call_tool(CallToolRequestParams::new("ui_screenshot")).await.is_err());
|
||||
for t in &tools {
|
||||
assert!(t.name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_'), "tool name `{}`", t.name);
|
||||
assert!(t.description.as_ref().is_some_and(|d| !d.is_empty()));
|
||||
@@ -165,6 +161,15 @@ async fn command_list_filters() {
|
||||
let all = json_of(&call(&client, "command_list", json!({})).await);
|
||||
let n_all = all.as_array().unwrap().len();
|
||||
assert!(n_all > 20);
|
||||
for id in ["file.openAs", "file.placeEmbedded", "file.export.quickExport", "file.automate.photomerge"] {
|
||||
assert!(!all.as_array().unwrap().iter().any(|row| row["id"] == id), "{id}");
|
||||
}
|
||||
for filter in ["rotate", "rotation"] {
|
||||
let rows = json_of(&call(&client, "command_list", json!({"filter": filter})).await);
|
||||
for id in ["image.imageRotation.90cw", "edit.transform.rotate90Cw"] {
|
||||
assert!(rows.as_array().unwrap().iter().any(|row| row["id"] == id), "{filter}: {id}");
|
||||
}
|
||||
}
|
||||
let blur = json_of(&call(&client, "command_list", json!({"filter": "blur"})).await);
|
||||
assert!(!blur.as_array().unwrap().is_empty() && blur.as_array().unwrap().len() < n_all);
|
||||
assert!(blur.as_array().unwrap().iter().all(|c| c["params"].is_string()));
|
||||
@@ -221,7 +226,7 @@ fn strict_schema_problems(path: &str, schema: &Value, out: &mut Vec<String>) {
|
||||
async fn tool_schemas_pass_strict_validators() {
|
||||
// #1782: `ui_pointer`'s `items: true` and `command_batch`'s `$ref`/`$defs` made strict
|
||||
// providers (e.g. Moonshot via Volcano Ark) reject the whole request.
|
||||
let client = connect(PhotocraftMcp::headless()).await;
|
||||
let client = connect(PhotocraftMcp::bridge("127.0.0.1:1", CONTROL_TOKEN).unwrap()).await;
|
||||
let tools = client.list_all_tools().await.unwrap();
|
||||
let mut problems = Vec::new();
|
||||
for t in &tools {
|
||||
@@ -294,7 +299,7 @@ fn ui_set_fields() -> Vec<String> {
|
||||
/// three fields missing when the issue was filed.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn ui_set_description_names_every_accepted_field() {
|
||||
let client = connect(PhotocraftMcp::headless()).await;
|
||||
let client = connect(PhotocraftMcp::bridge("127.0.0.1:1", CONTROL_TOKEN).unwrap()).await;
|
||||
let tools = client.list_all_tools().await.unwrap();
|
||||
let tool = tools.iter().find(|t| t.name == "ui_set").expect("ui_set tool");
|
||||
let schema = Value::Object((*tool.input_schema).clone());
|
||||
@@ -319,9 +324,6 @@ async fn errors_are_tool_errors_not_crashes() {
|
||||
assert_eq!(r.is_error, Some(true));
|
||||
let r = call(&client, "doc_open", json!({"path": "/definitely/missing.png"})).await;
|
||||
assert_eq!(r.is_error, Some(true));
|
||||
let r = call(&client, "ui_inspect", json!({})).await;
|
||||
assert_eq!(r.is_error, Some(true));
|
||||
assert!(text(&r).contains("bridge"));
|
||||
let r = call(&client, "doc_export", json!({})).await;
|
||||
assert_eq!(r.is_error, Some(true));
|
||||
// Quality 0 is refused, not clamped to 1 (serde already refuses 500, -1 and "85").
|
||||
@@ -983,22 +985,22 @@ async fn doc_export_layers_reports_skipped_layers() {
|
||||
let hidden = json_of(&call(&client, "command_run", json!({"id": "layer.new.layer", "params": {"name": "Hidden"}})).await)["layer"].clone();
|
||||
json_of(&call(&client, "command_run", json!({"id": "layer.setProps", "params": {"visible": false}})).await);
|
||||
let result = json_of(&call(&client, "doc_export_layers", json!({"dir": "layers"})).await);
|
||||
assert_eq!(result["count"], 1);
|
||||
assert_eq!(result["files"], json!(["layers/card_0002_Background.png"]));
|
||||
assert_eq!(result["count"], 2);
|
||||
assert_eq!(result["files"], json!(["layers/card_0001_Levels_α.png", "layers/card_0002_Background.png"]));
|
||||
assert_eq!(
|
||||
result["skipped"],
|
||||
json!([
|
||||
{"layer": hidden, "name": "Hidden", "reason": "hidden by visibleOnly"},
|
||||
{"layer": adjustment, "name": "Levels/α", "reason": "adjustment layer has no pixels of its own"}
|
||||
{"layer": hidden, "name": "Hidden", "reason": "hidden by visibleOnly"}
|
||||
])
|
||||
);
|
||||
let all = json_of(&call(&client, "doc_export_layers", json!({"dir": "all", "visible_only": false})).await);
|
||||
assert_eq!(all["count"], 2);
|
||||
assert_eq!(all["skipped"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(std::fs::read_dir(base.join("layers")).unwrap().count(), 1);
|
||||
assert_eq!(std::fs::read_dir(base.join("all")).unwrap().count(), 2);
|
||||
assert_eq!(all["count"], 3);
|
||||
assert_eq!(all["skipped"].as_array().unwrap().len(), 0);
|
||||
assert_eq!(std::fs::read_dir(base.join("layers")).unwrap().count(), 2);
|
||||
assert_eq!(std::fs::read_dir(base.join("all")).unwrap().count(), 3);
|
||||
// Every top-level layer is still accounted for when none can be exported.
|
||||
json_of(&call(&client, "command_run", json!({"id": "layer.setProps", "params": {"layer": background, "visible": false}})).await);
|
||||
json_of(&call(&client, "command_run", json!({"id": "layer.setProps", "params": {"layer": adjustment, "visible": false}})).await);
|
||||
let none = json_of(&call(&client, "doc_export_layers", json!({"dir": "none"})).await);
|
||||
assert_eq!(none["files"], json!([]));
|
||||
assert_eq!(none["count"], 0);
|
||||
@@ -1368,6 +1370,58 @@ async fn command_batch_description_exposes_non_atomic_semantics_when_tools_are_l
|
||||
client.cancel().await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn invalid_edit_parameters_do_not_modify_the_document() {
|
||||
let client = connect(PhotocraftMcp::headless()).await;
|
||||
json_of(&call(&client, "doc_new", json!({"width": 8, "height": 8})).await);
|
||||
let before = json_of(&call(&client, "doc_inspect", json!({})).await);
|
||||
for (id, params, expected) in [
|
||||
("image.adjustments.desaturate", json!({"amount": 50}), "unknown parameter"),
|
||||
("image.adjustments.desaturate", json!([]), "object"),
|
||||
("document.pixel", json!({"x": 0}), "y must be a number"),
|
||||
("image.crop", json!({"deleteCroppedPixels": "false"}), "must be true or false"),
|
||||
] {
|
||||
let step = json!({"id": id, "params": params});
|
||||
let reply = call(&client, "command_run", step.clone()).await;
|
||||
assert_eq!(reply.is_error, Some(true), "{id}: {}", text(&reply));
|
||||
assert!(text(&reply).contains(expected), "{id}: {}", text(&reply));
|
||||
let batch = json_of(&call(&client, "command_batch", json!({"steps": [step]})).await);
|
||||
assert_eq!(batch["failed"], 1, "{batch}");
|
||||
assert!(batch["results"][0]["error"].as_str().unwrap().contains(expected), "{batch}");
|
||||
}
|
||||
let after = json_of(&call(&client, "doc_inspect", json!({})).await);
|
||||
assert_eq!(after["history"], before["history"]);
|
||||
assert_eq!(after["width"], 8);
|
||||
assert_eq!(after["height"], 8);
|
||||
client.cancel().await.unwrap();
|
||||
}
|
||||
|
||||
/// The headless session's gate is no reason to refuse a crop frame past the canvas: the Crop tool
|
||||
/// extends the canvas that way, and Reveal All always crops to a frame larger than the canvas.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn gated_sessions_still_crop_past_the_canvas() {
|
||||
let client = connect(PhotocraftMcp::headless()).await;
|
||||
json_of(&call(&client, "doc_new", json!({"width": 8, "height": 8})).await);
|
||||
let size = |doc: &Value| (doc["width"].as_u64().unwrap(), doc["height"].as_u64().unwrap());
|
||||
let run = |id: &'static str, params: Value| {
|
||||
let client = &client;
|
||||
async move {
|
||||
let reply = call(client, "command_run", json!({"id": id, "params": params})).await;
|
||||
assert_ne!(reply.is_error, Some(true), "{id}: {}", text(&reply));
|
||||
}
|
||||
};
|
||||
run("image.crop", json!({"x": -2, "y": 0, "width": 10, "height": 8})).await;
|
||||
let extended = size(&json_of(&call(&client, "doc_inspect", json!({})).await));
|
||||
assert!(extended.0 > 8, "an extending crop widens the canvas: {extended:?}");
|
||||
run("image.crop", json!({"x": 2, "y": 0, "width": 4, "height": 8, "deleteCroppedPixels": false})).await;
|
||||
let cropped = size(&json_of(&call(&client, "doc_inspect", json!({})).await));
|
||||
assert!(cropped.0 < extended.0, "{cropped:?}");
|
||||
run("image.revealAll", json!({})).await;
|
||||
let revealed = size(&json_of(&call(&client, "doc_inspect", json!({})).await));
|
||||
assert!(revealed.0 > cropped.0, "Reveal All brings the hidden pixels back: {revealed:?}");
|
||||
client.cancel().await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn command_batch_runs_steps_in_order() {
|
||||
let client = connect(PhotocraftMcp::headless()).await;
|
||||
@@ -1552,7 +1606,7 @@ async fn convention_tool_hints_match_what_each_tool_does() {
|
||||
("ui_set", EDITS),
|
||||
("control_call", EDITS),
|
||||
];
|
||||
let client = connect(PhotocraftMcp::headless()).await;
|
||||
let client = connect(PhotocraftMcp::bridge("127.0.0.1:1", CONTROL_TOKEN).unwrap()).await;
|
||||
let tools = client.list_all_tools().await.unwrap();
|
||||
assert_eq!(tools.len(), expected.len(), "classify every tool here");
|
||||
for tool in tools {
|
||||
|
||||
@@ -26,6 +26,8 @@ fn layered_documents_save_reopen_and_save_in_place_as_openraster() {
|
||||
let path_str = path.to_str().unwrap();
|
||||
let mut h = Headless::trusted_local();
|
||||
h.handle("doc.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap();
|
||||
// This lossless OpenRaster fixture deliberately has no metadata to drop.
|
||||
std::sync::Arc::make_mut(h.session.active_mut().unwrap().doc_mut()).metadata.xmp = None;
|
||||
exec(&mut h, "layer.new.layer", json!({}));
|
||||
exec(&mut h, "paint.stroke", json!({"points": [[4, 4], [30, 20]], "size": 6, "hardness": 1.0, "color": "#ff0000"}));
|
||||
let top = h.session.active().unwrap().doc.layers.last().unwrap().id.0;
|
||||
@@ -77,6 +79,8 @@ fn an_openraster_file_never_overwrites_what_it_cannot_hold() {
|
||||
let path_str = path.to_str().unwrap();
|
||||
let mut h = Headless::trusted_local();
|
||||
h.handle("doc.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap();
|
||||
// This lossless OpenRaster fixture deliberately has no metadata to drop.
|
||||
std::sync::Arc::make_mut(h.session.active_mut().unwrap().doc_mut()).metadata.xmp = None;
|
||||
exec(&mut h, "layer.new.layer", json!({}));
|
||||
exec(&mut h, "paint.stroke", json!({"points": [[4, 4], [30, 20]], "size": 6, "hardness": 1.0, "color": "#ff0000"}));
|
||||
h.handle("doc.save", json!({"path": path_str})).unwrap();
|
||||
|
||||
@@ -684,6 +684,84 @@ pub fn composite_atop(mode: BlendMode, backdrop: [f32; 4], source: [f32; 4], opa
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether CMYK paint blends `mode` on the inks themselves ([`blend_inks`]): the modes measured
|
||||
/// there (#18662). Normal, Dissolve and the rest keep the RGB path.
|
||||
pub fn blends_inks(mode: BlendMode) -> bool {
|
||||
use BlendMode::*;
|
||||
matches!(
|
||||
mode,
|
||||
Darken
|
||||
| Multiply
|
||||
| ColorBurn
|
||||
| LinearBurn
|
||||
| Lighten
|
||||
| Screen
|
||||
| ColorDodge
|
||||
| LinearDodge
|
||||
| Overlay
|
||||
| SoftLight
|
||||
| HardLight
|
||||
| VividLight
|
||||
| LinearLight
|
||||
| PinLight
|
||||
| HardMix
|
||||
| Difference
|
||||
| Exclusion
|
||||
| Subtract
|
||||
| Divide
|
||||
| Hue
|
||||
| Saturation
|
||||
| Color
|
||||
| Luminosity
|
||||
| DarkerColor
|
||||
| LighterColor
|
||||
)
|
||||
}
|
||||
|
||||
/// `B(Cb, Cs)` on CMYK inks, each given as `v = 1 − ink` (C, M, Y, K): the separable modes apply
|
||||
/// their RGB formula to all four channels; Hue, Saturation and Color work on C, M, Y and keep the
|
||||
/// backdrop's K, Luminosity keeps the source's K; Darker and Lighter Color pick the whole pixel by
|
||||
/// `lum(C, M, Y) × K`. Hard Mix gives full ink (0) where `cb + cs` is exactly 1, measured, also
|
||||
/// at the ends (paper under full ink), where the RGB formula gives white.
|
||||
pub fn blend_inks(mode: BlendMode, cb: [f32; 4], cs: [f32; 4]) -> [f32; 4] {
|
||||
let cmy = |c: [f32; 4]| [c[0], c[1], c[2]];
|
||||
let with_k = |c: [f32; 3], k: f32| [c[0], c[1], c[2], k];
|
||||
let out = match mode {
|
||||
BlendMode::Hue | BlendMode::Saturation | BlendMode::Color => with_k(blend_rgb(mode, cmy(cb), cmy(cs)), cb[3]),
|
||||
BlendMode::Luminosity => with_k(blend_rgb(mode, cmy(cb), cmy(cs)), cs[3]),
|
||||
BlendMode::DarkerColor | BlendMode::LighterColor => {
|
||||
let (b, s) = (lum(cmy(cb)) * cb[3], lum(cmy(cs)) * cs[3]);
|
||||
let source = if mode == BlendMode::DarkerColor { s < b } else { s > b };
|
||||
if source { cs } else { cb }
|
||||
}
|
||||
// Callers pass 8- or 16-bit whole levels only, so a tie is exact up to f32 rounding.
|
||||
BlendMode::HardMix => std::array::from_fn(|i| if cb[i] + cs[i] > 1.0 + 1e-6 { 1.0 } else { 0.0 }),
|
||||
m => std::array::from_fn(|i| blend_channel(m, cb[i], cs[i])),
|
||||
};
|
||||
out.map(|v| v.clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
/// [`composite`] (or [`composite_atop`] when `atop`) on CMYK inks (0 = none, 1 = full), blended
|
||||
/// with [`blend_inks`] in `v = 1 − ink`. `ab` is the backdrop's alpha and `as_` the source's
|
||||
/// alpha times its coverage. Returns the inks and the alpha.
|
||||
pub fn composite_inks(mode: BlendMode, backdrop: [f32; 4], ab: f32, source: [f32; 4], as_: f32, atop: bool) -> ([f32; 4], f32) {
|
||||
if as_ <= 0.0 {
|
||||
return (backdrop, ab);
|
||||
}
|
||||
let (cb, cs) = (backdrop.map(|v| 1.0 - v), source.map(|v| 1.0 - v));
|
||||
let b = blend_inks(mode, cb, cs);
|
||||
let (v, alpha): ([f32; 4], f32) = if atop {
|
||||
(std::array::from_fn(|i| (1.0 - as_) * cb[i] + as_ * b[i]), ab)
|
||||
} else {
|
||||
let ao = as_ + ab * (1.0 - as_);
|
||||
if ao <= 0.0 {
|
||||
return ([0.0; 4], 0.0);
|
||||
}
|
||||
(std::array::from_fn(|i| ((1.0 - as_) * ab * cb[i] + (1.0 - ab) * as_ * cs[i] + as_ * ab * b[i]) / ao), ao)
|
||||
};
|
||||
(v.map(|v| (1.0 - v).clamp(0.0, 1.0)), alpha)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
||||
@@ -4,4 +4,8 @@
|
||||
#
|
||||
# It is recommended to check this file in to source control so that
|
||||
# everyone who runs the test benefits from these saved cases.
|
||||
cc a795914e4492bef1e662315563d48d54f09030c48e046df95329465c86dde4b4 # shrinks to s = Spec { w: 4, h: 6, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [1.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }, Pixels { kind: Adjust(Levels { channel: 0, levels: [0.0, 0.6, 1.0105422, 0.0, 0.7] }), blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.0, fill: 0.0, clipped: false, visible: true, mask: None }] }
|
||||
cc e14b02709a87770da2637c28678c4fa761b5628f402e0c6d60fe66f1aa4d4bfa # shrinks to s = Spec { w: 3, h: 2, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }, Group { children: [Pixels { kind: Adjust(Levels { channel: 0, levels: [0.0, 0.6, 0.3, 0.0, 0.7] }), blend: Dissolve, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.8972109, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: true, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
cc 4eeba1f8db987228717b932b82d043d61e82fd897a33ea9e2ce68d6c61d7f491 # shrinks to s = Spec { w: 3, h: 5, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 0.026626235, clipped: false, visible: true, mask: None }, Pixels { kind: Adjust(Invert), blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.0, fill: 0.0, clipped: false, visible: true, mask: None }], pass_through: true, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
cc 33fb5c528e97f31669a82a4634930230f903c97e58ce59fc88fd733ac097089c # shrinks to s = Spec { w: 6, h: 4, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 5, y1: 3 }, [0.0, 1.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }, Group { children: [Pixels { kind: Solid, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 1.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: VividLight, opacity: 1.0, fill: 1.0, mask: None }, Pixels { kind: Text, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: true, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
cc 9cd32fd3b0d418f70a3535174d06eccab73fdd2345cf51e50b53c9f2e006043e # shrinks to s = Spec { w: 2, h: 2, layers: [Group { children: [Pixels { kind: Solid, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.54360455, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }, Pixels { kind: Adjust(Curves { channel: 2, points: [(0.4490113, 1.0), (1.0, 0.0)] }), blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.6871668, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
@@ -1,10 +0,0 @@
|
||||
# Seeds for failure cases proptest has generated in the past. It is
|
||||
# automatically read and these particular cases re-run before any
|
||||
# novel cases are generated.
|
||||
#
|
||||
# It is recommended to check this file in to source control so that
|
||||
# everyone who runs the test benefits from these saved cases.
|
||||
cc a795914e4492bef1e662315563d48d54f09030c48e046df95329465c86dde4b4 # shrinks to s = Spec { w: 4, h: 6, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [1.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }, Pixels { kind: Adjust(Levels { channel: 0, levels: [0.0, 0.6, 1.0105422, 0.0, 0.7] }), blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.0, fill: 0.0, clipped: false, visible: true, mask: None }] }
|
||||
cc e14b02709a87770da2637c28678c4fa761b5628f402e0c6d60fe66f1aa4d4bfa # shrinks to s = Spec { w: 3, h: 2, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }, Group { children: [Pixels { kind: Adjust(Levels { channel: 0, levels: [0.0, 0.6, 0.3, 0.0, 0.7] }), blend: Dissolve, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.8972109, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: true, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
cc 4eeba1f8db987228717b932b82d043d61e82fd897a33ea9e2ce68d6c61d7f491 # shrinks to s = Spec { w: 3, h: 5, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 0.026626235, clipped: false, visible: true, mask: None }, Pixels { kind: Adjust(Invert), blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 0.0])], opacity: 0.0, fill: 0.0, clipped: false, visible: true, mask: None }], pass_through: true, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
cc 33fb5c528e97f31669a82a4634930230f903c97e58ce59fc88fd733ac097089c # shrinks to s = Spec { w: 6, h: 4, layers: [Group { children: [Pixels { kind: Raster, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 5, y1: 3 }, [0.0, 1.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }, Group { children: [Pixels { kind: Solid, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 1.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: false, visible: true, mask: None }], pass_through: false, blend: VividLight, opacity: 1.0, fill: 1.0, mask: None }, Pixels { kind: Text, blend: Normal, fills: [(Rect { x0: 0, y0: 0, x1: 1, y1: 1 }, [0.0, 0.0, 0.0, 0.0, 1.0])], opacity: 1.0, fill: 1.0, clipped: true, visible: true, mask: None }], pass_through: false, blend: Normal, opacity: 1.0, fill: 1.0, mask: None }] }
|
||||
@@ -191,8 +191,8 @@ fn apply_depth_mode(adj: &Adjustment, buf: &mut Buffer, transfer: Transfer, dept
|
||||
}
|
||||
None => (0.0, 0.0, 0.0),
|
||||
};
|
||||
let sat = colorize_saturation((*saturation / 100.0 + ds).clamp(-1.0, 1.0), *lightness / 100.0, *colorize, depth);
|
||||
let out = hue_saturation_in(c, *hue + dh, sat, (*lightness / 100.0).clamp(-1.0, 1.0), *colorize, depth);
|
||||
let sat = colorize_saturation((*saturation / 100.0).clamp(-1.0, 1.0), *lightness / 100.0, *colorize, depth);
|
||||
let out = hue_saturation_in(c, *hue + dh, sat, ds.clamp(-1.0, 1.0), (*lightness / 100.0).clamp(-1.0, 1.0), *colorize, depth);
|
||||
range_lightness(out, dl)
|
||||
})
|
||||
}
|
||||
@@ -434,6 +434,9 @@ mod gradient_map_grayscale_tests;
|
||||
#[cfg(test)]
|
||||
mod tone_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod hue_saturation_range_multiply_tests;
|
||||
|
||||
/// Legacy Brightness/Contrast scales contrast around 128 of 255 (contrast 80 keeps 128 at 128,
|
||||
/// measured on Photoshop 27.11; a 0.5 pivot moved it to 130).
|
||||
pub const LEGACY_PIVOT: f32 = 128.0 / 255.0;
|
||||
|
||||
@@ -30,15 +30,18 @@ pub fn colorize_saturation(s: f32, lightness: f32, colorize: bool, depth: Option
|
||||
/// Colorize sets the hue and saturation instead of shifting them; at 0% it leaves only the
|
||||
/// lightness, as in Photoshop (#2326). Ticking Colorize in the dialog starts saturation at 25%.
|
||||
pub fn hue_saturation(c: [f32; 3], hue: f32, s: f32, l: f32, colorize: bool) -> [f32; 3] {
|
||||
hue_saturation_in(c, hue, s, l, colorize, None)
|
||||
hue_saturation_in(c, hue, s, 0.0, l, colorize, None)
|
||||
}
|
||||
|
||||
/// [`hue_saturation`] in a document of `depth`. At 32 bits Photoshop doesn't clip the raised
|
||||
/// saturation, so saturated colours leave 0..1 (red with Hue +40, Saturation +25, Lightness -10
|
||||
/// becomes (1.0477, 0.649, -0.1477)), and it scales each colour's chroma around its lightness by
|
||||
/// [`hdr_saturation_factor`], so colours at or above lightness 1 keep their hue too: the photoshop
|
||||
/// corpus's rgb32 hue-saturation.psd is exact so.
|
||||
pub fn hue_saturation_in(c: [f32; 3], hue: f32, s: f32, l: f32, colorize: bool, depth: Option<SampleType>) -> [f32; 3] {
|
||||
/// corpus's rgb32 hue-saturation.psd is exact so. A colour range's saturation `range_s` scales
|
||||
/// the pixel's saturation again after the master's, so their factors multiply: Master -50 with
|
||||
/// Reds -50 leaves a quarter of red's saturation, (255, 0, 0) becomes (159, 95, 95) in the
|
||||
/// reference application (#14741). Colorize ignores it, as ranges don't apply there.
|
||||
pub fn hue_saturation_in(c: [f32; 3], hue: f32, s: f32, range_s: f32, l: f32, colorize: bool, depth: Option<SampleType>) -> [f32; 3] {
|
||||
let hdr = depth == Some(SampleType::F32);
|
||||
let lighten = |v: f32| if l > 0.0 { v + (1.0 - v) * l } else { v * (1.0 + l) };
|
||||
if colorize {
|
||||
@@ -56,12 +59,13 @@ pub fn hue_saturation_in(c: [f32; 3], hue: f32, s: f32, l: f32, colorize: bool,
|
||||
if hdr {
|
||||
// The chroma, not the HSL saturation, whose `2 - max - min` divisor is 0 at lightness 1
|
||||
// and negative above it: (2, 0, 0) with Hue +40 becomes (2, 1.333, 0) in Photoshop.
|
||||
let d = (lc[0].max(lc[1]).max(lc[2]) - lc[0].min(lc[1]).min(lc[2])) * hdr_saturation_factor(s);
|
||||
let d = (lc[0].max(lc[1]).max(lc[2]) - lc[0].min(lc[1]).min(lc[2])) * (hdr_saturation_factor(s) * hdr_saturation_factor(range_s));
|
||||
return hue_rgb(hh, ll - d / 2.0, ll + d / 2.0);
|
||||
}
|
||||
// Raising saturation divides by 1 - s, lowering it multiplies by 1 + s: +50 % doubles it
|
||||
// (measured in Photoshop 27.11); +100 % saturates any colour that has some.
|
||||
let ss = if s > 0.0 { ss / (1.0 - s).max(1.0 / 512.0) } else { ss * (1.0 + s) }.clamp(0.0, 1.0);
|
||||
let scale = |v: f32, by: f32| if by > 0.0 { v / (1.0 - by).max(1.0 / 512.0) } else { v * (1.0 + by) };
|
||||
let ss = scale(scale(ss, s), range_s).clamp(0.0, 1.0);
|
||||
hsl_to_rgb(hh, ss, ll)
|
||||
}
|
||||
|
||||
@@ -71,7 +75,7 @@ pub fn hue_saturation_in(c: [f32; 3], hue: f32, s: f32, l: f32, colorize: bool,
|
||||
/// 1/256 and stops at 32767/256, so +25 % gives 340/256, +99 % 63.75 and +100 % 127.996.
|
||||
/// compose.wgsl's Hue/Saturation does the same in whole numbers.
|
||||
pub fn hdr_saturation_factor(s: f32) -> f32 {
|
||||
// The 1e-4 keeps a master plus range sum on its step: -0.46 + 0.96 is 0.49999997 in f32.
|
||||
// The 1e-4 keeps a value a rounding error under a step on that step: 0.49999997 is +50 %.
|
||||
let s = s.clamp(-1.0, 1.0);
|
||||
if s <= 0.0 {
|
||||
return 1.0 - (-s * 256.0 + 1e-4).floor() / 256.0;
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//! #14741: a colour range's Saturation multiplies the Master Saturation's factor instead of
|
||||
//! adding to it.
|
||||
|
||||
use super::*;
|
||||
|
||||
fn hue_sat(master: f32, reds: f32) -> Adjustment {
|
||||
let mut ranges = HueRange::defaults();
|
||||
ranges[0].saturation = reds;
|
||||
Adjustment::HueSaturation { hue: 0.0, saturation: master, lightness: 0.0, colorize: false, ranges }
|
||||
}
|
||||
|
||||
fn run(adj: &Adjustment, c: [f32; 3], depth: SampleType) -> [f32; 3] {
|
||||
let mut b = Buffer::filled(crate::Rect::new(0, 0, 1, 1), [c[0], c[1], c[2], 1.0]);
|
||||
apply_depth(adj, &mut b, Transfer::Gamma(1.0), Some(depth));
|
||||
[b.px[0][0], b.px[0][1], b.px[0][2]]
|
||||
}
|
||||
|
||||
fn levels(c: [f32; 3]) -> [f32; 3] {
|
||||
c.map(|v| (v * 255.0).round())
|
||||
}
|
||||
|
||||
fn within(got: [f32; 3], want: [f32; 3], tolerance: f32) -> bool {
|
||||
levels(got).iter().zip(levels(want)).all(|(g, w)| (g - w).abs() <= tolerance)
|
||||
}
|
||||
|
||||
/// The reference application, measured: Master -50 with Reds -50 turns (255, 0, 0) into
|
||||
/// (159, 95, 95), a quarter of red's saturation. Adding the two made -100 and grey.
|
||||
#[test]
|
||||
fn master_and_reds_minus_fifty_keep_a_quarter_of_red() {
|
||||
let got = run(&hue_sat(-50.0, -50.0), [1.0, 0.0, 0.0], SampleType::U8);
|
||||
let want = [159.0, 95.0, 95.0].map(|v| v / 255.0);
|
||||
assert!(within(got, want, 1.0), "{:?}", levels(got));
|
||||
}
|
||||
|
||||
/// The 72-hue ramp of the measurement at HSL saturation 100 % and 50 %: no Reds cell turns grey,
|
||||
/// and away from the range's fades every cell has master × range of its saturation.
|
||||
#[test]
|
||||
fn ramp_cells_take_the_product_of_both_factors() {
|
||||
let adj = hue_sat(-50.0, -50.0);
|
||||
for s in [1.0, 0.5] {
|
||||
for step in 0..72 {
|
||||
let deg = step as f32 * 5.0;
|
||||
let c = hsl_to_rgb(deg / 360.0, s, 0.5);
|
||||
let got = run(&adj, c, SampleType::U8);
|
||||
let from_red = deg.min(360.0 - deg);
|
||||
if from_red < 45.0 {
|
||||
let chroma = got[0].max(got[1]).max(got[2]) - got[0].min(got[1]).min(got[2]);
|
||||
assert!(chroma * 255.0 >= 8.0, "hue {deg} at {s}: {:?} is grey", levels(got));
|
||||
}
|
||||
let factor = match from_red {
|
||||
d if d <= 15.0 => 0.25,
|
||||
d if d >= 45.0 => 0.5,
|
||||
_ => continue,
|
||||
};
|
||||
let want = hsl_to_rgb(deg / 360.0, s * factor, 0.5);
|
||||
assert!(within(got, want, 2.0), "hue {deg} at {s}: {:?}, want {:?}", levels(got), levels(want));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Raised and mixed settings combine as the same factors applied in turn: +50 doubles the
|
||||
/// saturation, -50 halves it, +25 multiplies it by 4/3.
|
||||
#[test]
|
||||
fn raised_and_mixed_settings_multiply_their_factors() {
|
||||
let red = |s: f32| hsl_to_rgb(0.0, s, 0.5);
|
||||
for (master, reds, s, want) in
|
||||
[(50.0, -50.0, 0.4, 0.4), (-50.0, 50.0, 0.4, 0.4), (25.0, 25.0, 0.3, 0.3 * 16.0 / 9.0), (50.0, 50.0, 0.4, 1.0), (-100.0, 50.0, 0.4, 0.0)]
|
||||
{
|
||||
let got = run(&hue_sat(master, reds), red(s), SampleType::U8);
|
||||
assert!(within(got, red(want), 1.0), "master {master}, reds {reds}: {:?}, want {:?}", levels(got), levels(red(want)));
|
||||
}
|
||||
}
|
||||
|
||||
/// 32 bits scale the chroma by the product of their own factors: a quarter of red's chroma for
|
||||
/// -50 twice, and Reds -50 halves what Master +50 (510/256) or +100 (32767/256) alone gives.
|
||||
#[test]
|
||||
fn thirty_two_bits_multiply_too() {
|
||||
let chroma = |c: [f32; 3]| c[0].max(c[1]).max(c[2]) - c[0].min(c[1]).min(c[2]);
|
||||
for (master, reds, want) in [(-50.0, -50.0, 0.25), (50.0, -50.0, 255.0 / 256.0), (100.0, -50.0, 32767.0 / 512.0)] {
|
||||
let got = run(&hue_sat(master, reds), [1.0, 0.0, 0.0], SampleType::F32);
|
||||
assert!((chroma(got) - want).abs() < 1e-3 * want, "master {master}, reds {reds}: {got:?}, chroma {want}");
|
||||
assert!(got[1..].iter().all(|v| (v - (1.0 - want) / 2.0).abs() < 1e-3 * want.max(1.0)), "{got:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A range alone reaches the saturation step as a master of the same value does, bit for bit, on
|
||||
/// a colour inside the range: one setting alone is untouched by the change.
|
||||
#[test]
|
||||
fn one_setting_alone_passes_through_unchanged() {
|
||||
let c = hsl_to_rgb(2.0 / 360.0, 0.6, 0.45);
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for k in -20..=20 {
|
||||
let v = k as f32 * 5.0;
|
||||
let range = run(&hue_sat(0.0, v), c, depth).map(f32::to_bits);
|
||||
let master = run(&hue_sat(v, 0.0), c, depth).map(f32::to_bits);
|
||||
assert_eq!(range, master, "{depth:?}, {v}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_values_stay_finite() {
|
||||
for depth in [SampleType::U8, SampleType::F32] {
|
||||
for (m, r) in [(f32::INFINITY, -50.0), (f32::NEG_INFINITY, 50.0), (100.0, 100.0), (-100.0, -100.0), (100.0, -100.0), (500.0, 500.0), (-500.0, 1e9)] {
|
||||
let got = run(&hue_sat(m, r), [0.8, 0.1, 0.2], depth);
|
||||
assert!(got.iter().all(|v| v.is_finite()), "{depth:?}, {m}, {r}: {got:?}");
|
||||
}
|
||||
let _ = run(&hue_sat(f32::NAN, f32::NAN), [0.8, 0.1, 0.2], depth);
|
||||
}
|
||||
}
|
||||
@@ -87,13 +87,8 @@ fn thirty_two_bit_hue_saturation_keeps_bright_colours() {
|
||||
let got = hdr(&adj, c);
|
||||
assert!(near(got, want), "hue {hue}, saturation {sat}, {c:?}: {got:?}, Photoshop {want:?}");
|
||||
}
|
||||
// A master plus a range edit that add up to a whole step stay on it: Reds +96 over a master
|
||||
// -46 scales red as much as a master +50 alone (in f32 the sum is 0.49999997).
|
||||
let mut ranges = HueRange::defaults();
|
||||
ranges[0].saturation = 96.0;
|
||||
let summed = Adjustment::HueSaturation { hue: 0.0, saturation: -46.0, lightness: 0.0, colorize: false, ranges };
|
||||
let single = Adjustment::HueSaturation { hue: 0.0, saturation: 50.0, lightness: 0.0, colorize: false, ranges: HueRange::defaults() };
|
||||
assert_eq!(hdr(&summed, [1.0, 0.0, 0.0]), hdr(&single, [1.0, 0.0, 0.0]));
|
||||
// A value a rounding error under a step stays on it: 0.49999997 is +50 %.
|
||||
assert_eq!(hdr_saturation_factor(0.49999997), hdr_saturation_factor(0.5));
|
||||
// Lightness 0 with a negative channel divides by zero the same way.
|
||||
let adj = Adjustment::HueSaturation { hue: 40.0, saturation: 25.0, lightness: 0.0, colorize: false, ranges: HueRange::defaults() };
|
||||
assert!(hdr(&adj, [0.25, -0.25, 0.0]).iter().all(|v| v.is_finite()));
|
||||
|
||||
@@ -19,6 +19,7 @@ struct Entry {
|
||||
struct Cache {
|
||||
entries: HashMap<usize, Entry>,
|
||||
sweep_at: usize,
|
||||
purge_generation: u64,
|
||||
}
|
||||
|
||||
const MIN_SWEEP: usize = 1 << 16;
|
||||
@@ -31,16 +32,22 @@ fn next_sweep(survivors: usize) -> usize {
|
||||
|
||||
fn cache() -> &'static Mutex<Cache> {
|
||||
static C: std::sync::OnceLock<Mutex<Cache>> = std::sync::OnceLock::new();
|
||||
C.get_or_init(|| Mutex::new(Cache { entries: HashMap::new(), sweep_at: MIN_SWEEP }))
|
||||
C.get_or_init(|| Mutex::new(Cache { entries: HashMap::new(), sweep_at: MIN_SWEEP, purge_generation: 0 }))
|
||||
}
|
||||
|
||||
impl Cache {
|
||||
fn purge(&mut self) {
|
||||
self.entries.clear();
|
||||
self.sweep_at = MIN_SWEEP;
|
||||
self.purge_generation = self.purge_generation.wrapping_add(1);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn purge() {
|
||||
let mut cache = cache().lock().unwrap_or_else(|e| e.into_inner());
|
||||
cache.entries.clear();
|
||||
cache.sweep_at = MIN_SWEEP;
|
||||
cache().lock().unwrap_or_else(|e| e.into_inner()).purge();
|
||||
}
|
||||
|
||||
/// `Surface::content_bounds`, cached per tile.
|
||||
/// Surface content bounds, cached per tile.
|
||||
pub fn content_bounds(s: &Surface) -> Rect {
|
||||
if s.tile_count() == 0 {
|
||||
return Rect::EMPTY;
|
||||
@@ -48,26 +55,9 @@ pub fn content_bounds(s: &Surface) -> Rect {
|
||||
let fmt = s.format();
|
||||
let mut dp = vec![0u8; fmt.bytes_per_pixel()];
|
||||
photocraft_raster::encode_pixel(&fmt, &s.default_pixel(), &mut dp);
|
||||
let mut c = cache().lock().unwrap_or_else(|e| e.into_inner());
|
||||
if c.entries.len() > c.sweep_at {
|
||||
c.entries.retain(|_, e| e.tile.strong_count() > 0);
|
||||
c.sweep_at = next_sweep(c.entries.len());
|
||||
}
|
||||
let mut out = Rect::EMPTY;
|
||||
for (coord, t) in s.tiles() {
|
||||
let key = Arc::as_ptr(t) as usize;
|
||||
let hit = c.entries.get(&key).filter(|e| e.tile.upgrade().is_some_and(|u| Arc::ptr_eq(&u, t)) && *e.default == *dp).map(|e| e.bounds);
|
||||
let b = match hit {
|
||||
Some(b) => b,
|
||||
None => {
|
||||
let generation = photocraft_raster::spill::read_error_generation();
|
||||
let b = t.content_bounds(&dp);
|
||||
if photocraft_raster::spill::check_since(generation).is_ok() && t.scratch_health().is_ok() {
|
||||
c.entries.insert(key, Entry { tile: Arc::downgrade(t), default: dp.clone().into_boxed_slice(), bounds: b });
|
||||
}
|
||||
b
|
||||
}
|
||||
};
|
||||
let b = tile_bounds(cache(), t, &dp, || t.content_bounds(&dp));
|
||||
if let Some((x0, y0, x1, y1)) = b {
|
||||
let o = coord.rect();
|
||||
let r = Rect::new(o.x0 + x0 as i32, o.y0 + y0 as i32, o.x0 + x1 as i32, o.y0 + y1 as i32);
|
||||
@@ -77,10 +67,64 @@ pub fn content_bounds(s: &Surface) -> Rect {
|
||||
out
|
||||
}
|
||||
|
||||
/// Pixel scans and spill reads must not hold the cache lock used by input handling.
|
||||
fn tile_bounds(cache: &Mutex<Cache>, tile: &Arc<Tile>, default: &[u8], scan: impl FnOnce() -> Option<(u16, u16, u16, u16)>) -> Option<(u16, u16, u16, u16)> {
|
||||
let key = Arc::as_ptr(tile) as usize;
|
||||
let purge_generation = {
|
||||
let mut c = cache.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if c.entries.len() > c.sweep_at {
|
||||
c.entries.retain(|_, e| e.tile.strong_count() > 0);
|
||||
c.sweep_at = next_sweep(c.entries.len());
|
||||
}
|
||||
if let Some(hit) = c.entries.get(&key).filter(|e| e.tile.upgrade().is_some_and(|u| Arc::ptr_eq(&u, tile)) && *e.default == *default) {
|
||||
return hit.bounds;
|
||||
}
|
||||
c.purge_generation
|
||||
};
|
||||
let generation = photocraft_raster::spill::read_error_generation();
|
||||
let bounds = scan();
|
||||
if photocraft_raster::spill::check_since(generation).is_ok() && tile.scratch_health().is_ok() {
|
||||
let mut c = cache.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if c.purge_generation == purge_generation {
|
||||
c.entries.insert(key, Entry { tile: Arc::downgrade(tile), default: default.into(), bounds });
|
||||
}
|
||||
}
|
||||
bounds
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cache_misses_scan_without_holding_the_shared_lock() {
|
||||
let mut surface = Surface::new(photocraft_color::PixelFormat::RGBA8);
|
||||
surface.fill_rect(Rect::new(1, 2, 30, 40), &[0.2, 0.4, 0.6, 1.0]);
|
||||
let (_, tile) = surface.tiles().next().unwrap();
|
||||
let cache = Mutex::new(Cache { entries: HashMap::new(), sweep_at: MIN_SWEEP, purge_generation: 0 });
|
||||
let default = [0u8; 4];
|
||||
let actual = tile_bounds(&cache, tile, &default, || {
|
||||
assert!(cache.try_lock().is_ok(), "pixel scanning must not hold the shared bounds-cache lock");
|
||||
tile.content_bounds(&default)
|
||||
});
|
||||
assert_eq!(actual, tile.content_bounds(&default));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn purging_during_a_scan_does_not_repopulate_the_cache() {
|
||||
let mut surface = Surface::new(photocraft_color::PixelFormat::RGBA8);
|
||||
surface.fill_rect(Rect::new(1, 2, 30, 40), &[0.2, 0.4, 0.6, 1.0]);
|
||||
let (_, tile) = surface.tiles().next().unwrap();
|
||||
let cache = Mutex::new(Cache { entries: HashMap::new(), sweep_at: MIN_SWEEP, purge_generation: 0 });
|
||||
let default = [0u8; 4];
|
||||
let actual = tile_bounds(&cache, tile, &default, || {
|
||||
cache.lock().unwrap().purge();
|
||||
tile.content_bounds(&default)
|
||||
});
|
||||
assert_eq!(actual, tile.content_bounds(&default), "an in-flight caller still gets its bounds");
|
||||
assert!(cache.lock().unwrap().entries.is_empty(), "Purge also discards in-flight cache fills");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sweeps_again_only_past_twice_the_survivors() {
|
||||
// A cache of live tiles past the minimum isn't swept on every call (it used to be).
|
||||
|
||||
@@ -55,7 +55,7 @@ use distance::{
|
||||
use paint::dissolves;
|
||||
pub use paint::{
|
||||
aa_shift, anti_aliased_contour, bevel_contour_lut, glow_gradient_gain, glow_lut, glow_paint_lut, gradient_t, gradient_units, hash_noise, ranged_lut,
|
||||
sample_gradient, satin_lut, spread_split,
|
||||
sample_gradient, satin_aa_shift, satin_lut, spread_split,
|
||||
};
|
||||
#[cfg(test)]
|
||||
use paint::{glow_map, lut_at, noise, offset, shadow_map};
|
||||
@@ -246,6 +246,8 @@ impl FxMaps {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod drop_shadow_anti_alias_tests;
|
||||
#[cfg(test)]
|
||||
mod inner_shadow_anti_alias_tests;
|
||||
#[cfg(test)]
|
||||
@@ -256,6 +258,8 @@ mod inner_shadow_noise_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod outer_glow_noise_tests;
|
||||
#[cfg(test)]
|
||||
mod outer_glow_precise_edge_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -263,6 +267,8 @@ mod tests;
|
||||
#[cfg(test)]
|
||||
mod outer_glow_range_one_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod satin_anti_alias_tests;
|
||||
#[cfg(test)]
|
||||
mod satin_invert_contour_tests;
|
||||
#[cfg(test)]
|
||||
@@ -270,5 +276,8 @@ mod satin_size_one_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod inner_glow_size_one_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod inner_glow_noise_tests;
|
||||
#[cfg(test)]
|
||||
mod stroke_partial_alpha_tests;
|
||||
@@ -270,8 +270,12 @@ pub fn satin_distance(s: &photocraft_doc::effects::Satin) -> f32 {
|
||||
|
||||
pub(super) fn satin_map(shape: &Map, s: &photocraft_doc::effects::Satin) -> Map {
|
||||
let (dx, dy) = offset(s.angle, satin_distance(s));
|
||||
let mut a = shape.shifted(dx, dy, 0.0);
|
||||
let mut b = shape.shifted(-dx, -dy, 0.0);
|
||||
// #14984: an Anti-aliased Satin takes both copies from the shape a third of a pixel towards
|
||||
// the top-left (`satin_aa_shift`): the pattern moves, its Distance does not. The final clip
|
||||
// below stays on the layer's own shape.
|
||||
let aa = super::paint::satin_aa_shift(s.anti_alias, &s.contour, s.size);
|
||||
let mut a = shape.shifted(dx + aa, dy + aa, 0.0);
|
||||
let mut b = shape.shifted(-dx + aa, -dy + aa, 0.0);
|
||||
if s.size == 1.0 {
|
||||
// #14983: the measured edge has one quarter-strength pixel on either side.
|
||||
super::blur::size_one_blur(&mut a);
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
//! #14881 - BUG-LAYER-STYLE-DROP-SHADOW-ANTI-ALIASED-IGNORED.
|
||||
//!
|
||||
//! Measured on the issue's test document: 400 x 300 px, 72 ppi, RGB 8 bit, white Background, a
|
||||
//! pixel layer with an orange (255, 128, 0) rectangle at x 100..=299, y 75..=224, Global Light
|
||||
//! 120 / 30. Black Drop Shadow, Multiply 100 %, Size 10, Distance 0, Spread 0, Noise 0, Contour
|
||||
//! Gaussian. The tables are the R channel of the flattened image read from a layer edge outwards
|
||||
//! (255 = no shadow): top = column x 200 from y 74 up, left = row y 150 from x 99, bottom = column
|
||||
//! x 200 from y 225 down, right = row y 150 from x 300. Outside the layer the shadow multiplies
|
||||
//! the white Background, so R = 255 x (1 - coverage).
|
||||
//!
|
||||
//! On main `shadow_map` read `Shadow::anti_alias` for the Inner Shadow only (#14934), so a Drop
|
||||
//! Shadow gave one map both ways: every edge read 115 161 205 231 244 250 252 253 254. The
|
||||
//! reference application's Anti-aliased profile is a drop shadow whose source sits a third of a
|
||||
//! pixel towards the top-left, the same offset #14934 measured for the Inner Shadow: the top and
|
||||
//! left edges read 98 147 191 223 241 249 252 254 255, the bottom and right 130 177 214 236 247
|
||||
//! 252 254 254 255.
|
||||
|
||||
use super::*;
|
||||
|
||||
const DOC_W: usize = 400;
|
||||
const DOC_H: usize = 300;
|
||||
|
||||
/// The layer's alpha over the whole document: solid over x 100..=299, y 75..=224.
|
||||
fn document_shape() -> Map {
|
||||
let mut m = Map::new(DOC_W, DOC_H, 0.0);
|
||||
for y in 75..=224 {
|
||||
for x in 100..=299 {
|
||||
m.v[y * DOC_W + x] = 1.0;
|
||||
}
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
fn curve(name: &str, pts: &[(f32, f32)]) -> Contour {
|
||||
Contour::Custom {
|
||||
name: name.into(),
|
||||
points: pts.iter().map(|(input, output)| photocraft_doc::adjust::CurvePoint { input: *input, output: *output }).collect(),
|
||||
// Every inner point of a built-in preset is a corner (the Contour picker stores it that
|
||||
// way), so the curve is its polyline.
|
||||
corners: (0..pts.len()).map(|i| i > 0 && i < pts.len() - 1).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Gaussian contour as the built-in preset carries it (`layer_style::CONTOURS`).
|
||||
fn gaussian() -> Contour {
|
||||
curve(
|
||||
"Gaussian",
|
||||
&[
|
||||
(0.0, 0.0),
|
||||
(0.117, 0.023),
|
||||
(0.172, 0.055),
|
||||
(0.234, 0.117),
|
||||
(0.305, 0.234),
|
||||
(0.383, 0.414),
|
||||
(0.523, 0.688),
|
||||
(0.617, 0.812),
|
||||
(0.703, 0.891),
|
||||
(0.805, 0.953),
|
||||
(1.0, 1.0),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
/// A second built-in preset, to show the gate is "the measured contour", not "any curve".
|
||||
fn cone() -> Contour {
|
||||
curve(
|
||||
"Cone",
|
||||
&[
|
||||
(0.0, 0.0),
|
||||
(0.172, 0.477),
|
||||
(0.195, 0.555),
|
||||
(0.266, 0.711),
|
||||
(0.383, 0.922),
|
||||
(0.43, 0.969),
|
||||
(0.477, 0.992),
|
||||
(0.523, 0.992),
|
||||
(0.57, 0.969),
|
||||
(0.664, 0.859),
|
||||
(0.703, 0.789),
|
||||
(0.742, 0.711),
|
||||
(0.836, 0.477),
|
||||
(0.859, 0.398),
|
||||
(0.914, 0.266),
|
||||
(0.945, 0.156),
|
||||
(0.977, 0.078),
|
||||
(1.0, 0.0),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
/// The issue's Drop Shadow: black, Multiply, 100 %, Global Light 120 / 30, Spread `spread`.
|
||||
fn shadow(size: f32, distance: f32, spread: f32, contour: Contour, anti_aliased: bool) -> Shadow {
|
||||
Shadow {
|
||||
common: photocraft_doc::FxCommon::new(BlendMode::Multiply, 1.0),
|
||||
color: photocraft_color::Color::BLACK,
|
||||
angle: 120.0,
|
||||
use_global_light: true,
|
||||
distance,
|
||||
spread,
|
||||
size,
|
||||
contour,
|
||||
anti_alias: anti_aliased,
|
||||
noise: 0.0,
|
||||
knocks_out: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn map(size: f32, distance: f32, spread: f32, contour: Contour, anti_aliased: bool) -> Map {
|
||||
shadow_map(&document_shape(), &shadow(size, distance, spread, contour, anti_aliased), &GlobalLight::default(), false, (0, 0))
|
||||
}
|
||||
|
||||
/// The R channel of the white Background under a black Multiply drop shadow of coverage `c`.
|
||||
fn r(c: f32) -> f32 {
|
||||
255.0 * (1.0 - c)
|
||||
}
|
||||
|
||||
/// The nine R values outwards from each of the issue's four edges, in the order it reads them.
|
||||
fn ramps(m: &Map) -> [Vec<f32>; 4] {
|
||||
let line = |first: (i64, i64), step: (i64, i64)| (0..9).map(|k| r(m.get(first.0 + k * step.0, first.1 + k * step.1))).collect();
|
||||
[line((200, 74), (0, -1)), line((99, 150), (-1, 0)), line((200, 225), (0, 1)), line((300, 150), (1, 0))]
|
||||
}
|
||||
|
||||
/// Assert each edge's ramp against `want` within `tol` levels.
|
||||
fn assert_edges(m: &Map, want: &[&[f32]; 4], tol: f32, what: &str) {
|
||||
for ((side, got), w) in ["top", "left", "bottom", "right"].iter().zip(ramps(m)).zip(want) {
|
||||
for (d, (got, want)) in got.iter().zip(*w).enumerate() {
|
||||
assert!((got - want).abs() <= tol, "{what}, {side} edge, {d} px out: {got:.1} vs measured {want} (within {tol})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A hash over every coverage value of a map: the map is bit-for-bit unchanged iff this is.
|
||||
fn bit_hash(m: &Map) -> u64 {
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
for v in &m.v {
|
||||
h = (h ^ u64::from(v.to_bits())).wrapping_mul(0x0000_0100_0000_01b3);
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
/// Done when: on the issue's test document, Gaussian with Anti-aliased gives the measured
|
||||
/// top/left and bottom/right profiles within 3 levels. *Why* the two pairs of edges differ is not
|
||||
/// measured; one sub-pixel source offset reproduces both, as it does for the Inner Shadow.
|
||||
#[test]
|
||||
fn anti_aliased_gaussian_gives_both_measured_profiles() {
|
||||
let tl: &[f32] = &[98.0, 147.0, 191.0, 223.0, 241.0, 249.0, 252.0, 254.0, 255.0];
|
||||
let br: &[f32] = &[130.0, 177.0, 214.0, 236.0, 247.0, 252.0, 254.0, 254.0, 255.0];
|
||||
assert_edges(&map(10.0, 0.0, 0.0, gaussian(), true), &[tl, tl, br, br], 3.0, "Size 10 Gaussian, Anti-aliased");
|
||||
}
|
||||
|
||||
/// Done when: without Anti-aliased the profiles stay as today. These are the R values
|
||||
/// `shadow_map` gave on main, and they sit within 3 levels of the issue's measured Anti-aliased
|
||||
/// off profile, 114 163 205 231 244 251 253 254 255, on every edge.
|
||||
#[test]
|
||||
fn without_anti_alias_the_profiles_stay_as_today() {
|
||||
let today: [i32; 9] = [115, 161, 205, 231, 244, 250, 252, 253, 254];
|
||||
let measured: &[f32] = &[114.0, 163.0, 205.0, 231.0, 244.0, 251.0, 253.0, 254.0, 255.0];
|
||||
let m = map(10.0, 0.0, 0.0, gaussian(), false);
|
||||
for (side, got) in ["top", "left", "bottom", "right"].iter().zip(ramps(&m)) {
|
||||
for (d, got) in got.iter().enumerate() {
|
||||
assert_eq!(got.round() as i32, today[d], "Anti-aliased off moved the {side} edge, {d} px out: {got:.2}");
|
||||
}
|
||||
}
|
||||
assert_edges(&m, &[measured, measured, measured, measured], 3.0, "Size 10 Gaussian, Anti-aliased off");
|
||||
assert_eq!(bit_hash(&m), 0x5e49_20b6_9751_cc45, "the Size 10 Gaussian drop shadow map (Anti-aliased off) moved");
|
||||
}
|
||||
|
||||
/// The offset is a third of a pixel, so the shadow reaches at most one pixel further at the top
|
||||
/// and left: it stays inside the effect margin (`margin`: Size + Distance + 2) on every side.
|
||||
#[test]
|
||||
fn anti_aliased_stays_inside_the_effect_margin() {
|
||||
let m = map(10.0, 0.0, 0.0, gaussian(), true);
|
||||
for (x, y) in [(200i64, 75 - 12), (200, 224 + 12), (100 - 12, 150), (299 + 12, 150), (100 - 12, 75 - 12), (299 + 12, 224 + 12)] {
|
||||
assert_eq!(m.get(x, y), 0.0, "Anti-aliased drop shadow beyond the effect margin at ({x},{y})");
|
||||
}
|
||||
}
|
||||
|
||||
/// Not measured: Anti-aliased with a contour other than Gaussian. Those keep today's map
|
||||
/// bit-for-bit - the Linear default and a second built-in curve.
|
||||
#[test]
|
||||
fn other_contours_keep_todays_map() {
|
||||
assert_eq!(bit_hash(&map(10.0, 0.0, 0.0, Contour::Linear, true)), 0x8dc3_4139_f452_da9d, "a Linear drop shadow with Anti-aliased moved");
|
||||
assert_eq!(bit_hash(&map(10.0, 0.0, 0.0, Contour::Linear, false)), 0x8dc3_4139_f452_da9d, "a Linear drop shadow without Anti-aliased moved");
|
||||
assert_eq!(bit_hash(&map(10.0, 0.0, 0.0, cone(), true)), bit_hash(&map(10.0, 0.0, 0.0, cone(), false)), "a Cone drop shadow moved with Anti-aliased");
|
||||
}
|
||||
|
||||
/// The flag off leaves every other Size, Distance and Spread exactly as it was: whole-map hashes
|
||||
/// `shadow_map` gave on main 610c86b969 before this change.
|
||||
#[test]
|
||||
fn the_off_path_is_bit_for_bit_unchanged() {
|
||||
let hashes: [(f32, u64); 9] = [
|
||||
(0.5, 0xa067_0cbe_8a34_6225),
|
||||
(1.0, 0xa067_0cbe_8a34_6225),
|
||||
(1.5, 0xdc2a_66a2_b0c4_a04d),
|
||||
(2.0, 0x2b77_3190_0ec6_f501),
|
||||
(3.0, 0x202a_f725_63f0_d551),
|
||||
(6.0, 0x1ba8_550d_7781_8ee9),
|
||||
(10.0, 0x5e49_20b6_9751_cc45),
|
||||
(20.0, 0xf1a6_f4c4_f2f3_5d11),
|
||||
(250.0, 0x0842_22f2_601f_bfb1),
|
||||
];
|
||||
for (size, want) in hashes {
|
||||
assert_eq!(bit_hash(&map(size, 0.0, 0.0, gaussian(), false)), want, "the whole Size {size} drop shadow map (Anti-aliased off) moved");
|
||||
}
|
||||
assert_eq!(bit_hash(&map(10.0, 5.0, 0.0, gaussian(), false)), 0xda80_8e81_2a08_7185, "the Size 10 Distance 5 drop shadow map moved");
|
||||
assert_eq!(bit_hash(&map(10.0, 0.0, 0.5, gaussian(), false)), 0x5419_4d5e_753c_77a1, "the Size 10 Spread 50 % drop shadow map moved");
|
||||
}
|
||||
|
||||
/// The Inner Shadow's gate (`aa_shift`) applies unchanged: a Size whose blur is the identity
|
||||
/// (Size 1, Size 2 at Spread 50 %) would turn the offset into the whole map, and a Spread that
|
||||
/// dilates makes the CPU recompute its distance on the offset map while the GPU shifts a
|
||||
/// whole-pixel field of the unshifted shape. None of them was measured, so they keep today's map.
|
||||
#[test]
|
||||
fn degenerate_and_dilating_neighbours_keep_todays_map() {
|
||||
for (size, spread, what) in [(1.0, 0.0, "Size 1"), (2.0, 0.5, "Size 2 Spread 50 %"), (10.0, 0.5, "Size 10 Spread 50 %"), (10.0, 0.05, "Size 10 Spread 5 %")]
|
||||
{
|
||||
assert_eq!(
|
||||
bit_hash(&map(size, 0.0, spread, gaussian(), true)),
|
||||
bit_hash(&map(size, 0.0, spread, gaussian(), false)),
|
||||
"the {what} drop shadow map moved with Anti-aliased"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Guard: the rule is in the inputs, not keyed to the measured Size 10. Every Size whose blur is
|
||||
/// wider than the identity takes the offset at Spread 0, and so does a Distance other than 0.
|
||||
#[test]
|
||||
fn the_offset_follows_the_inputs_not_the_measured_size() {
|
||||
for size in [1.5, 2.0, 3.0, 6.0, 20.0, 250.0] {
|
||||
assert_ne!(
|
||||
bit_hash(&map(size, 0.0, 0.0, gaussian(), true)),
|
||||
bit_hash(&map(size, 0.0, 0.0, gaussian(), false)),
|
||||
"Anti-aliased did nothing at Size {size}, Spread 0"
|
||||
);
|
||||
}
|
||||
assert_ne!(
|
||||
bit_hash(&map(10.0, 5.0, 0.0, gaussian(), true)),
|
||||
bit_hash(&map(10.0, 5.0, 0.0, gaussian(), false)),
|
||||
"Anti-aliased did nothing at Size 10, Distance 5"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
//! #14926 - BUG-LAYER-STYLE-INNER-GLOW-NOISE-TOO-WEAK.
|
||||
//!
|
||||
//! Measured on the issue's test document: 400 x 300 px, RGB 8 bit, white Background, an orange
|
||||
//! (255, 128, 0) pixel layer covering x 100..299, y 75..224. Inner Glow black, Normal, 100 %,
|
||||
//! Softer, Source Edge, Choke 0, Size 10, Contour Linear, Range 50 %. The issue counts the G
|
||||
//! channel of the flattened top band y 75..83, x 110..289 (1620 px): G 128 is the layer's own
|
||||
//! orange (no glow), G 0 is full black glow. The shared `noise` law (#14936, #14952) leaves 244
|
||||
//! band pixels without glow at Noise 50, while the reference application shows 343.
|
||||
|
||||
use super::*;
|
||||
|
||||
const DOC_W: usize = 400;
|
||||
const DOC_H: usize = 300;
|
||||
|
||||
/// The layer's alpha over the whole document: solid over x 100..=299, y 75..=224.
|
||||
fn document_shape() -> Map {
|
||||
let mut m = Map::new(DOC_W, DOC_H, 0.0);
|
||||
for y in 75..=224 {
|
||||
for x in 100..=299 {
|
||||
m.v[y * DOC_W + x] = 1.0;
|
||||
}
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
/// The issue's Inner Glow settings: black, Normal, 100 %, Softer, Source Edge, Choke 0, Size 10,
|
||||
/// Contour Linear, Range 50 %, Jitter 0, Anti-aliased off, Noise `noise`.
|
||||
fn glow(noise: f32) -> Glow {
|
||||
Glow {
|
||||
common: photocraft_doc::FxCommon::new(BlendMode::Normal, 1.0),
|
||||
paint: FxPaint::Color(photocraft_color::Color::BLACK),
|
||||
technique: GlowTechnique::Softer,
|
||||
spread: 0.0,
|
||||
size: 10.0,
|
||||
contour: Contour::Linear,
|
||||
anti_alias: false,
|
||||
range: 0.5,
|
||||
jitter: 0.0,
|
||||
noise,
|
||||
source: GlowSource::Edge,
|
||||
}
|
||||
}
|
||||
|
||||
fn map(noise: f32) -> Map {
|
||||
glow_map(&document_shape(), &glow(noise), true, (0, 0))
|
||||
}
|
||||
|
||||
/// The G channel of the orange layer under a black Normal inner glow of coverage `c`.
|
||||
fn g_u8(c: f32) -> u8 {
|
||||
(128.0 * (1.0 - c)).round().clamp(0.0, 128.0) as u8
|
||||
}
|
||||
|
||||
/// The issue's band, y 75..=83 and x 110..=289 (1620 px), as G channel values.
|
||||
fn band(m: &Map) -> Vec<u8> {
|
||||
let mut out = Vec::with_capacity(180 * 9);
|
||||
for y in 75..=83 {
|
||||
for x in 110..=289 {
|
||||
out.push(g_u8(m.get(x, y)));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Done when: Noise 50 on that band leaves 260..430 pixels at G 128 (no glow at all), at most
|
||||
/// 30 pixels equal to the noiseless result, and reaches G 0. The shared law alone leaves 244.
|
||||
#[test]
|
||||
fn noise_fifty_scatters_the_glow_across_the_band() {
|
||||
let plain = band(&map(0.0));
|
||||
let noisy = band(&map(0.5));
|
||||
let gone = noisy.iter().filter(|v| **v == 128).count();
|
||||
let equal = noisy.iter().zip(&plain).filter(|(a, b)| a == b).count();
|
||||
let min = noisy.iter().copied().min().unwrap_or(128);
|
||||
assert!((260..=430).contains(&gone), "Noise 50: {gone} pixels without glow, want 260..430 (reference: 343)");
|
||||
assert!(equal <= 30, "Noise 50: {equal} pixels equal to the noiseless result, want at most 30 (reference: 8)");
|
||||
assert_eq!(min, 0, "Noise 50: minimum G {min}, want 0");
|
||||
}
|
||||
|
||||
/// Done when: Noise 100 leaves 400..580 pixels at G 128 (reference: 490).
|
||||
#[test]
|
||||
fn noise_hundred_thins_the_glow_further() {
|
||||
let noisy = band(&map(1.0));
|
||||
let gone = noisy.iter().filter(|v| **v == 128).count();
|
||||
assert!((400..=580).contains(&gone), "Noise 100: {gone} pixels without glow, want 400..580 (reference: 490)");
|
||||
}
|
||||
|
||||
/// Done when: the interior beyond the glow's reach stays G 128 at every Noise.
|
||||
#[test]
|
||||
fn noise_keeps_the_interior_beyond_the_glow_clean() {
|
||||
let plain = map(0.0);
|
||||
for noise in [0.25f32, 0.5, 1.0] {
|
||||
let noisy = map(noise);
|
||||
for y in (100..=200).step_by(5) {
|
||||
for x in (130..=270).step_by(7) {
|
||||
assert_eq!(plain.get(x, y), 0.0, "noiseless coverage at ({x},{y}) is not empty");
|
||||
assert_eq!(noisy.get(x, y), 0.0, "noise {noise} lit up ({x},{y}): {}", noisy.get(x, y));
|
||||
assert_eq!(g_u8(noisy.get(x, y)), 128, "noise {noise} moved the interior at ({x},{y}) off 128");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Done when: the same settings give the identical image twice.
|
||||
#[test]
|
||||
fn the_same_noise_renders_identically_twice() {
|
||||
for noise in [0.5f32, 1.0] {
|
||||
let a = map(noise);
|
||||
let b = map(noise);
|
||||
assert_eq!(a.v, b.v, "noise {noise} is not deterministic");
|
||||
}
|
||||
}
|
||||
|
||||
/// Noise that is not a positive number leaves the glow exactly as Noise 0 does, and the inner
|
||||
/// strength does not reach the Outer Glow, whose band was measured on the shared law (#14952).
|
||||
#[test]
|
||||
fn odd_noise_values_and_outer_glows_keep_the_shared_law() {
|
||||
let plain = map(0.0);
|
||||
for odd in [-0.5f32, f32::NAN, f32::INFINITY] {
|
||||
assert_eq!(map(odd).v, plain.v, "noise {odd} changed the inner glow");
|
||||
}
|
||||
let shape = document_shape();
|
||||
let outer = glow_map(&shape, &glow(0.0), false, (0, 0));
|
||||
let mut by_law = outer.clone();
|
||||
noise(&mut by_law, 0.5, 0, 0);
|
||||
assert_eq!(glow_map(&shape, &glow(0.5), false, (0, 0)).v, by_law.v, "the outer glow left the shared law");
|
||||
}
|
||||
|
||||
/// A hash over every coverage value of a map: the map is bit-for-bit unchanged iff this is.
|
||||
fn bit_hash(m: &Map) -> u64 {
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
for v in &m.v {
|
||||
h = (h ^ u64::from(v.to_bits())).wrapping_mul(0x0000_0100_0000_01b3);
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
/// Noise 0 stays bit-identical: the whole-map FNV hash `glow_map` gives for the issue's
|
||||
/// document with Noise 0 on origin/main.
|
||||
#[test]
|
||||
fn noise_zero_maps_stay_bit_identical() {
|
||||
assert_eq!(bit_hash(&map(0.0)), 0xefad_fffb_8195_d0b9, "the Noise 0 inner glow map moved");
|
||||
}
|
||||
|
||||
/// The Centre source and the Precise technique were not measured, so they keep the shared law at every Noise: only
|
||||
/// the measured Softer, Edge-sourced Inner Glow gets the stronger mid-Noise scatter.
|
||||
#[test]
|
||||
fn unmeasured_centre_and_precise_inner_glows_keep_the_shared_law() {
|
||||
let shape = document_shape();
|
||||
let centre = |noise| Glow { source: GlowSource::Center, ..glow(noise) };
|
||||
let precise = |noise| Glow { technique: GlowTechnique::Precise, ..glow(noise) };
|
||||
let precise_centre = |noise| Glow { technique: GlowTechnique::Precise, source: GlowSource::Center, ..glow(noise) };
|
||||
for (name, make) in [("Centre", ¢re as &dyn Fn(f32) -> Glow), ("Precise", &precise), ("Precise Centre", &precise_centre)] {
|
||||
for amount in [0.25f32, 0.5] {
|
||||
let mut by_law = glow_map(&shape, &make(0.0), true, (0, 0));
|
||||
noise(&mut by_law, amount, 0, 0);
|
||||
assert_eq!(glow_map(&shape, &make(amount), true, (0, 0)).v, by_law.v, "{name}, Noise {amount}: left the shared law");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,15 +188,16 @@ fn anti_aliased_still_paints_nothing_outside_the_layer() {
|
||||
}
|
||||
|
||||
/// Not measured: Anti-aliased with a contour other than Gaussian. Those keep today's map
|
||||
/// bit-for-bit - the Linear default, a second built-in curve, and the Drop Shadow (its own item is
|
||||
/// #14881). Hashes are the ones these maps had on upstream/main before the change.
|
||||
/// bit-for-bit - the Linear default and a second built-in curve. Hashes are the ones these maps had
|
||||
/// on upstream/main before the change. The Drop Shadow's off path is pinned here too; with the flag
|
||||
/// on it takes the same offset since #14881 (`drop_shadow_anti_alias_tests`).
|
||||
#[test]
|
||||
fn other_contours_and_the_drop_shadow_keep_todays_map() {
|
||||
fn other_contours_keep_todays_map() {
|
||||
assert_eq!(bit_hash(&map(10.0, 0.0, 0.0, 0.0, Contour::Linear, true)), 0x2200_2b2d_61bc_9c2d, "a Linear-contour inner shadow with Anti-aliased moved");
|
||||
assert_eq!(bit_hash(&map(10.0, 0.0, 0.0, 0.0, cone(), true)), 0xb86c_68a7_8a2f_e689, "a Cone-contour inner shadow with Anti-aliased moved");
|
||||
let drop = |aa: bool| shadow_map(&document_shape(), &shadow(10.0, 0.0, 0.0, 0.0, gaussian(), aa), &GlobalLight::default(), false, (0, 0));
|
||||
assert_eq!(bit_hash(&drop(false)), 0x5e49_20b6_9751_cc45, "the Drop Shadow Gaussian map (Anti-aliased off) moved");
|
||||
assert_eq!(bit_hash(&drop(true)), 0x5e49_20b6_9751_cc45, "the Drop Shadow still ignores Anti-aliased (#14881)");
|
||||
assert_ne!(bit_hash(&drop(true)), 0x5e49_20b6_9751_cc45, "the Drop Shadow honours Anti-aliased since #14881");
|
||||
}
|
||||
|
||||
/// The flag off leaves every other Size, Distance and Choke exactly as it was. These are the whole
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! #15006 - Outer Glow: a flat-contour Precise band's outermost pixel is soft on a pixel-aligned
|
||||
//! edge.
|
||||
//!
|
||||
//! Measured on the issue's document: 60 x 60 px, transparent, a black 20 x 20 square at x/y
|
||||
//! 20..39. Outer Glow Normal 100 %, Precise, Spread 0, Size 4 px, Range 50 %, custom flat contour
|
||||
//! (0,255)-(255,255), Anti-aliased off. Along row 30, x 14 and 15 read alpha 0, x 16 (4 px out)
|
||||
//! 213 and x 17..19 255. On the diagonal, (16, 16) reads 0, (17, 17) 161 and (18, 18) 255.
|
||||
|
||||
use super::{Contour, Effect, FxPaint, Glow, GlowSource, GlowTechnique};
|
||||
use photocraft_color::{BlendMode, Color, ColorMode, SampleType};
|
||||
use photocraft_doc::{Document, FxCommon, Layer, adjust::CurvePoint};
|
||||
use photocraft_geom::{Rect, Size};
|
||||
|
||||
fn outer_glow(contour: Contour) -> Glow {
|
||||
Glow {
|
||||
common: FxCommon::new(BlendMode::Normal, 1.0),
|
||||
paint: FxPaint::Color(Color::BLACK),
|
||||
technique: GlowTechnique::Precise,
|
||||
spread: 0.0,
|
||||
size: 4.0,
|
||||
contour,
|
||||
anti_alias: false,
|
||||
range: 0.5,
|
||||
jitter: 0.0,
|
||||
noise: 0.0,
|
||||
source: GlowSource::Edge,
|
||||
}
|
||||
}
|
||||
|
||||
fn flat() -> Contour {
|
||||
Contour::Custom { name: "Flat".into(), points: vec![CurvePoint { input: 0.0, output: 1.0 }, CurvePoint { input: 1.0, output: 1.0 }], corners: vec![] }
|
||||
}
|
||||
|
||||
fn alphas(glow: Glow) -> impl Fn(i32, i32) -> u8 {
|
||||
let mut doc = Document::new("Outer glow", Size::new(60, 60), ColorMode::Rgb, SampleType::U8);
|
||||
let mut layer = Layer::raster("Square", doc.pixel_format());
|
||||
layer.surface_mut().unwrap().fill_rect(Rect::new(20, 20, 40, 40), &[0.0, 0.0, 0.0, 1.0]);
|
||||
layer.effects.items.push(Effect::OuterGlow(glow));
|
||||
doc.layers.push(layer);
|
||||
let image = crate::flatten(&doc);
|
||||
move |x, y| (image.get(x, y)[3] * 255.0).round() as u8
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pixel_at_size_px_out_is_soft() {
|
||||
let alpha = alphas(outer_glow(flat()));
|
||||
for (x, expected) in [(14, 0), (15, 0), (17, 255), (18, 255), (19, 255)] {
|
||||
assert_eq!(alpha(x, 30), expected, "x {x}");
|
||||
}
|
||||
let edge = alpha(16, 30);
|
||||
assert!(edge.abs_diff(213) <= 3, "x 16, 4 px out: expected 213, got {edge}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_corner_diagonal_fades_the_same_way() {
|
||||
let alpha = alphas(outer_glow(flat()));
|
||||
assert_eq!(alpha(16, 16), 0);
|
||||
assert_eq!(alpha(18, 18), 255);
|
||||
let diagonal = alpha(17, 17);
|
||||
assert!(diagonal.abs_diff(161) <= 5, "(17, 17), √18 px out: expected 161, got {diagonal}");
|
||||
}
|
||||
@@ -109,9 +109,9 @@ fn softer_edge_floor(size: f32) -> f32 {
|
||||
/// rounded down to a table entry for both techniques); the coverage where it reaches 1 is per
|
||||
/// technique:
|
||||
///
|
||||
/// - Precise: the falloff is linear in distance, so the edge is the distance left to the reach's
|
||||
/// end: the last pixel steps down by how far inside the reach its centre is (one soft pixel,
|
||||
/// as Photoshop's flat-contour band).
|
||||
/// - Precise: a fixed coverage, [`PRECISE_FULL_COVERAGE`]. The falloff is linear in distance, so
|
||||
/// at Spread 0 the band fades over its last `0.24 · (size + 1)` px: about one soft pixel at
|
||||
/// Size 4, two to three at Size 10, as Photoshop's flat-contour band.
|
||||
/// - Softer: coverage is a tent blur, and the same coverage means a different distance for a
|
||||
/// straight edge and a single pixel, so no coverage-only model gives the distance. The edge
|
||||
/// reaches 1 at the coverage one opaque pixel gives one pixel inside its reach along a row
|
||||
@@ -122,7 +122,7 @@ fn softer_edge_floor(size: f32) -> f32 {
|
||||
/// So:
|
||||
///
|
||||
/// - coverage 0 always paints 0, for any contour (nothing beyond the reach);
|
||||
/// - a high contour is solid up to the last pixel of the reach, which steps down;
|
||||
/// - a high contour is solid up to the outer pixels of the reach, which step down;
|
||||
/// - it never paints less than the Linear contour would, so a contour that already follows or
|
||||
/// stays under the falloff (Linear, or a custom curve with `contour(0) = 0` rising no faster
|
||||
/// than the reach edge) is unchanged. The reach does not depend on Range: Range stretches the
|
||||
@@ -151,6 +151,14 @@ pub fn glow_paint_lut(g: &Glow, inner: bool) -> Option<Vec<f32>> {
|
||||
)
|
||||
}
|
||||
|
||||
/// The Precise coverage at which a high contour's reach edge paints in full (#15006), whatever
|
||||
/// the Size: with `v = ½·(1 − (d − solid) / soft)`, Photoshop paints `v / 0.12`. Measured at
|
||||
/// Range 50 %, Spread 0: Size 4 at 4 px out (a pixel-aligned edge) 213 of 255 and at √18 px (a
|
||||
/// corner's diagonal) 161; Size 10, #11361's ellipse row `153, 120, 92` (this gives
|
||||
/// `155, 123, 92`). Other Ranges and Spreads are unmeasured. Tying the knee to the distance
|
||||
/// instead (`1 / (2·soft)`, the reach's last pixel) left the pixel at Size px out solid.
|
||||
const PRECISE_FULL_COVERAGE: f32 = 0.12;
|
||||
|
||||
/// Entries in a glow's transfer table: the GPU's `compose.wgsl` `lut` reads 4096, linearly
|
||||
/// interpolated, as the CPU's [`lut_at`] does.
|
||||
const GLOW_LUT_LEN: usize = 4096;
|
||||
@@ -170,16 +178,11 @@ fn glow_reach_edge(per_coverage: f32, v: f32) -> f32 {
|
||||
/// coverage rounded down to a whole table step (at least one), so the knee lands on a table entry
|
||||
/// and the table interpolates the edge exactly (rounding down only widens what paints in full).
|
||||
///
|
||||
/// - Precise: `v = ½·(1 − (d − solid) / soft)`, which reaches 0 at `d = size + 1` (centre to
|
||||
/// centre), so the distance left to the reach's end is `size + 1 − d = 2·soft·v`: full at
|
||||
/// `v = 1 / (2·soft)`.
|
||||
/// - Precise: full at [`PRECISE_FULL_COVERAGE`].
|
||||
/// - Softer: full at [`softer_full_coverage`].
|
||||
fn glow_edge_per_coverage(g: &Glow) -> f32 {
|
||||
let full = match g.technique {
|
||||
GlowTechnique::Precise => {
|
||||
let solid = g.size * g.spread;
|
||||
0.5 / (g.size + 1.0 - solid).max(1e-3)
|
||||
}
|
||||
GlowTechnique::Precise => PRECISE_FULL_COVERAGE,
|
||||
GlowTechnique::Softer => softer_full_coverage(spread_split(g.size, g.spread).1),
|
||||
};
|
||||
let steps = (GLOW_LUT_LEN - 1) as f32;
|
||||
@@ -355,6 +358,19 @@ pub fn aa_shift(on: bool, c: &Contour, size: f32, spread: f32) -> f32 {
|
||||
if on && anti_aliased_contour(c) && anti_aliased_geometry(size, spread) { -1.0 / 3.0 } else { 0.0 }
|
||||
}
|
||||
|
||||
/// The sub-pixel offset an Anti-aliased Satin builds both of its shifted copies from (#14984):
|
||||
/// the same third of a pixel towards the top-left as `aa_shift`, which moves the whole satin
|
||||
/// pattern while keeping its Distance. The reference application was measured with the Gaussian
|
||||
/// and the Ring contour (both bands move up: the top band lighter at its inner end, the bottom band
|
||||
/// darker) and with Linear (no change at all, which `satin_lut`'s identity makes a non-event
|
||||
/// anyway, so it keeps today's map bit-for-bit); every other contour, and a Size whose blur is the
|
||||
/// identity (`anti_aliased_geometry` with no spread: Size 0, and Size 1, which has its own measured
|
||||
/// kernel, #14983), keeps today's map. Public because the GPU satin builder asks the same rule.
|
||||
pub fn satin_aa_shift(on: bool, c: &Contour, size: f32) -> f32 {
|
||||
let measured = matches!(c, Contour::Custom { name, .. } if name.eq_ignore_ascii_case("Gaussian") || name.eq_ignore_ascii_case("Ring"));
|
||||
if on && measured && anti_aliased_geometry(size, 0.0) { -1.0 / 3.0 } else { 0.0 }
|
||||
}
|
||||
|
||||
/// The lengths a 100 % gradient at `angle` spans in a `w` × `h` frame: the chord (Linear and
|
||||
/// Reflected) and the ellipse-norm length (Radial, Angle, Diamond; its half is the radius).
|
||||
pub fn gradient_units(angle: f32, w: f32, h: f32) -> (f32, f32) {
|
||||
@@ -502,10 +518,10 @@ pub fn spread_split(size: f32, spread: f32) -> (f32, f32) {
|
||||
pub(super) fn shadow_map(shape: &Map, s: &Shadow, light: &GlobalLight, inner: bool, origin: (i32, i32)) -> Map {
|
||||
let angle = if s.use_global_light { light.angle } else { s.angle };
|
||||
let (dx, dy) = offset(angle, s.distance);
|
||||
// #14934: an Anti-aliased Inner Shadow builds its map from the shape off-centre (`aa_shift`).
|
||||
// Only the inner branch was measured, so a Drop Shadow keeps today's map (#14881 is its own),
|
||||
// and `aa_shift` leaves every Choke that dilates and every Size whose blur is the identity.
|
||||
let aa = aa_shift(inner && s.anti_alias, &s.contour, s.size, s.spread);
|
||||
// #14934 (Inner Shadow) and #14881 (Drop Shadow): an Anti-aliased shadow builds its map from
|
||||
// the shape off-centre (`aa_shift`); both measured the same third of a pixel. `aa_shift`
|
||||
// leaves every Choke / Spread that dilates and every Size whose blur is the identity.
|
||||
let aa = aa_shift(s.anti_alias, &s.contour, s.size, s.spread);
|
||||
let src = if inner { shape.clone().map(|a| 1.0 - a) } else { shape.clone() };
|
||||
let mut m = src.shifted(dx + aa, dy + aa, if inner { 1.0 } else { 0.0 });
|
||||
let (r, bw) = spread_split(s.size, s.spread);
|
||||
@@ -569,7 +585,13 @@ pub(super) fn glow_map(shape: &Map, g: &Glow, inner: bool, origin: (i32, i32)) -
|
||||
if inner && g.source == GlowSource::Center {
|
||||
m = m.map(|v| 1.0 - v);
|
||||
}
|
||||
noise(&mut m, g.noise, origin.0, origin.1);
|
||||
// #14926: an Inner Glow scatters harder at mid Noise than the shared law gives (measured
|
||||
// band: Noise 50 leaves 343 of 1620 px without glow, Noise 100 490). The square root keeps
|
||||
// Noise 0 and Noise 100 where they are and lifts Noise 50 to the law's 0.71 (about 340 px).
|
||||
// Only the measured Softer, Edge-sourced case; Centre and Precise keep the shared law.
|
||||
let measured = inner && g.technique == GlowTechnique::Softer && g.source == GlowSource::Edge;
|
||||
let amount = if measured && g.noise > 0.0 { g.noise.sqrt() } else { g.noise };
|
||||
noise(&mut m, amount, origin.0, origin.1);
|
||||
if inner {
|
||||
for (v, a) in m.v.iter_mut().zip(&shape.v) {
|
||||
*v *= a;
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
//! #14984 - BUG-LAYER-STYLE-SATIN-ANTI-ALIASED-IGNORED.
|
||||
//!
|
||||
//! Measured on the issue's test document: 400 x 300 px, 72 ppi, RGB 8 bit, white Background, a
|
||||
//! pixel layer with an orange (255, 128, 0) rectangle at x 100..=299, y 75..=224. Black Satin,
|
||||
//! Normal, Opacity 100 %, Angle 90, Distance 20, Size 10, Invert off. The tables are the G channel
|
||||
//! of the flattened image down column x 200 from y 75 to y 224 (128 = no satin, 0 = full black
|
||||
//! satin), written as the issue writes them: `0x11` is the value 0 eleven times in a row.
|
||||
//!
|
||||
//! On main `satin_map` never read `Satin::anti_alias`, so a Gaussian or Ring Satin gave one map
|
||||
//! both ways. In the reference application Anti-aliased moves both bands of the column upwards:
|
||||
//! the top band gets lighter at its inner end and the bottom band darker. One sub-pixel source
|
||||
//! offset reproduces both bands for both contours - the third of a pixel towards the top-left the
|
||||
//! Inner Shadow (#14934) and Drop Shadow (#14881) measured - applied to both shifted copies of the
|
||||
//! shape, so the satin's own Distance is unchanged and the whole pattern moves.
|
||||
|
||||
use super::*;
|
||||
use photocraft_doc::Satin;
|
||||
|
||||
const DOC_W: usize = 400;
|
||||
const DOC_H: usize = 300;
|
||||
|
||||
/// The layer's alpha over the whole document: solid over x 100..=299, y 75..=224.
|
||||
fn document_shape() -> Map {
|
||||
let mut m = Map::new(DOC_W, DOC_H, 0.0);
|
||||
for y in 75..=224 {
|
||||
for x in 100..=299 {
|
||||
m.v[y * DOC_W + x] = 1.0;
|
||||
}
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
fn curve(name: &str, pts: &[(f32, f32)]) -> Contour {
|
||||
Contour::Custom {
|
||||
name: name.into(),
|
||||
points: pts.iter().map(|(input, output)| photocraft_doc::adjust::CurvePoint { input: *input, output: *output }).collect(),
|
||||
// Every inner point of a built-in preset is a corner (the Contour picker stores it that
|
||||
// way), so the curve is its polyline.
|
||||
corners: (0..pts.len()).map(|i| i > 0 && i < pts.len() - 1).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Gaussian contour as the built-in preset carries it (`layer_style::CONTOURS`).
|
||||
fn gaussian() -> Contour {
|
||||
curve(
|
||||
"Gaussian",
|
||||
&[
|
||||
(0.0, 0.0),
|
||||
(0.117, 0.023),
|
||||
(0.172, 0.055),
|
||||
(0.234, 0.117),
|
||||
(0.305, 0.234),
|
||||
(0.383, 0.414),
|
||||
(0.523, 0.688),
|
||||
(0.617, 0.812),
|
||||
(0.703, 0.891),
|
||||
(0.805, 0.953),
|
||||
(1.0, 1.0),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
/// The Ring contour as the built-in preset carries it (`layer_style::CONTOURS`).
|
||||
fn ring() -> Contour {
|
||||
curve(
|
||||
"Ring",
|
||||
&[
|
||||
(0.0, 0.0),
|
||||
(0.031, 0.078),
|
||||
(0.039, 0.117),
|
||||
(0.117, 0.383),
|
||||
(0.172, 0.609),
|
||||
(0.195, 0.734),
|
||||
(0.266, 0.953),
|
||||
(0.305, 1.0),
|
||||
(0.344, 0.992),
|
||||
(0.383, 0.922),
|
||||
(0.43, 0.805),
|
||||
(0.477, 0.641),
|
||||
(0.57, 0.281),
|
||||
(0.617, 0.141),
|
||||
(0.664, 0.055),
|
||||
(0.703, 0.016),
|
||||
(0.742, 0.016),
|
||||
(0.773, 0.062),
|
||||
(0.836, 0.234),
|
||||
(0.859, 0.344),
|
||||
(0.891, 0.445),
|
||||
(0.914, 0.547),
|
||||
(0.945, 0.734),
|
||||
(0.977, 0.875),
|
||||
(1.0, 1.0),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
/// A built-in preset the issue did not measure with Anti-aliased.
|
||||
fn cone() -> Contour {
|
||||
curve(
|
||||
"Cone",
|
||||
&[
|
||||
(0.0, 0.0),
|
||||
(0.172, 0.477),
|
||||
(0.195, 0.555),
|
||||
(0.266, 0.711),
|
||||
(0.383, 0.922),
|
||||
(0.43, 0.969),
|
||||
(0.477, 0.992),
|
||||
(0.523, 0.992),
|
||||
(0.57, 0.969),
|
||||
(0.664, 0.859),
|
||||
(0.703, 0.789),
|
||||
(0.742, 0.711),
|
||||
(0.836, 0.477),
|
||||
(0.859, 0.398),
|
||||
(0.914, 0.266),
|
||||
(0.945, 0.156),
|
||||
(0.977, 0.078),
|
||||
(1.0, 0.0),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
fn satin(size: f32, distance: f32, angle: f32, contour: Contour, anti_aliased: bool, invert: bool) -> Satin {
|
||||
Satin {
|
||||
common: photocraft_doc::FxCommon::new(BlendMode::Normal, 1.0),
|
||||
color: photocraft_color::Color::BLACK,
|
||||
angle,
|
||||
distance,
|
||||
size,
|
||||
contour,
|
||||
anti_alias: anti_aliased,
|
||||
invert,
|
||||
}
|
||||
}
|
||||
|
||||
fn map(size: f32, distance: f32, angle: f32, contour: Contour, anti_aliased: bool) -> Map {
|
||||
satin_map(&document_shape(), &satin(size, distance, angle, contour, anti_aliased, false))
|
||||
}
|
||||
|
||||
/// The issue's document: Angle 90, Distance 20, Size 10.
|
||||
fn issue_map(contour: Contour, anti_aliased: bool) -> Map {
|
||||
map(10.0, 20.0, 90.0, contour, anti_aliased)
|
||||
}
|
||||
|
||||
/// The G channel of column x 200 from y 75 to y 224 under a black Normal satin, rounded to the
|
||||
/// 8-bit levels the issue reads from the flattened image.
|
||||
fn column(m: &Map) -> Vec<f32> {
|
||||
(75..=224).map(|y| (128.0 * (1.0 - m.get(200, y))).round()).collect()
|
||||
}
|
||||
|
||||
/// The issue's run-length notation: `0x11` is 0 eleven times, a bare number is one value.
|
||||
fn expand(spec: &str) -> Vec<f32> {
|
||||
let mut out = Vec::new();
|
||||
for t in spec.split_whitespace() {
|
||||
let (v, n) = t.split_once('x').unwrap_or((t, "1"));
|
||||
let (v, n): (f32, usize) = (v.parse().unwrap(), n.parse().unwrap());
|
||||
out.extend(std::iter::repeat_n(v, n));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// A top half followed by its mirror image ("the bottom half mirrors the top half").
|
||||
fn mirrored(top: &str) -> Vec<f32> {
|
||||
let mut v = expand(top);
|
||||
let mut bottom = v.clone();
|
||||
bottom.reverse();
|
||||
v.extend(bottom);
|
||||
v
|
||||
}
|
||||
|
||||
/// Assert the column against `want` within `tol` levels, with per-row exceptions `(y, tol)`.
|
||||
fn assert_column(m: &Map, want: &[f32], tol: f32, exceptions: &[(usize, f32)], what: &str) {
|
||||
assert_eq!(want.len(), 150, "{what}: the measured column has 150 rows");
|
||||
for (i, (got, want)) in column(m).iter().zip(want).enumerate() {
|
||||
let y = 75 + i;
|
||||
let tol = exceptions.iter().find(|(ey, _)| *ey == y).map_or(tol, |(_, t)| *t);
|
||||
assert!((got - want).abs() <= tol, "{what}, y {y}: G {got} vs measured {want} (within {tol})");
|
||||
}
|
||||
}
|
||||
|
||||
/// A hash over every coverage value of a map: the map is bit-for-bit unchanged iff this is.
|
||||
fn bit_hash(m: &Map) -> u64 {
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
for v in &m.v {
|
||||
h = (h ^ u64::from(v.to_bits())).wrapping_mul(0x0000_0100_0000_01b3);
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
const GAUSSIAN_OFF: &str = "0x11 1x3 3 6 13 26 46 71 93 107 116 121 124 125 126 127 128x47";
|
||||
const GAUSSIAN_ON: &str = "0x10 1x3 2 4 8 16 32 55 79 98 110 117 122 124 126 127x2 128x94 127 126 125 123 119 113 103 86 63 39 21 10 5 2 1x3 0x11";
|
||||
const RING_OFF: &str = "0x11 4 12 25 43 69 102 126 124 94 46 12 1 13 37 64 89 108 121 128x46";
|
||||
const RING_ON: &str = "0x10 1 7 16 30 51 80 112 127 115 78 34 6 3 20 46 72 95 113 124 128x91 126 117 102 81 55 28 8 3 22 62 105 126 120 91 60 37 21 10 3 0x11";
|
||||
|
||||
/// Done when: Gaussian with Anti-aliased gives the measured column within 3 levels.
|
||||
#[test]
|
||||
fn anti_aliased_gaussian_gives_the_measured_column() {
|
||||
assert_column(&issue_map(gaussian(), true), &expand(GAUSSIAN_ON), 3.0, &[], "Gaussian, Anti-aliased");
|
||||
}
|
||||
|
||||
/// Done when: Ring with Anti-aliased gives the measured column within 3 levels. One row is the
|
||||
/// exception: at y 100 the Ring's off path on main already sits 3 levels from the measured
|
||||
/// Anti-aliased-off column (61 against 64, `without_anti_alias_the_columns_stay_as_today`), and the
|
||||
/// same row lands 4 levels off with the flag on (68 against 72). That residue is the off path's,
|
||||
/// not the offset's; every other row of the column lands within 3.
|
||||
#[test]
|
||||
fn anti_aliased_ring_gives_the_measured_column() {
|
||||
assert_column(&issue_map(ring(), true), &expand(RING_ON), 3.0, &[(100, 4.0)], "Ring, Anti-aliased");
|
||||
}
|
||||
|
||||
/// The flag moves both bands, so neither column can be met by the off path: the measured
|
||||
/// difference is what the change adds, not slack in the tolerance.
|
||||
#[test]
|
||||
fn anti_aliased_moves_both_bands() {
|
||||
for (name, contour) in [("Gaussian", gaussian()), ("Ring", ring())] {
|
||||
let (on, off) = (column(&issue_map(contour.clone(), true)), column(&issue_map(contour, false)));
|
||||
let top = (0..40).map(|i| (on[i] - off[i]).abs()).fold(0.0, f32::max);
|
||||
let bottom = (110..150).map(|i| (on[i] - off[i]).abs()).fold(0.0, f32::max);
|
||||
assert!(top > 3.0 && bottom > 3.0, "{name}: Anti-aliased moved the top band by {top:.1} and the bottom band by {bottom:.1} levels");
|
||||
}
|
||||
}
|
||||
|
||||
/// Done when: without Anti-aliased the columns stay as today. The whole maps keep the hashes they
|
||||
/// had on main 610c86b969, and the columns sit within 3 levels of the issue's measured
|
||||
/// Anti-aliased-off tables. The row y 150 stays 128 and the layer centre stays uncovered in every
|
||||
/// case, as measured.
|
||||
#[test]
|
||||
fn without_anti_alias_the_columns_stay_as_today() {
|
||||
let gauss = issue_map(gaussian(), false);
|
||||
assert_eq!(bit_hash(&gauss), 0x287f_b22f_d709_0159, "the Gaussian Satin map (Anti-aliased off) moved");
|
||||
assert_column(&gauss, &mirrored(GAUSSIAN_OFF), 3.0, &[], "Gaussian, Anti-aliased off");
|
||||
let ring_off = issue_map(ring(), false);
|
||||
assert_eq!(bit_hash(&ring_off), 0x6581_1338_3ebc_56d5, "the Ring Satin map (Anti-aliased off) moved");
|
||||
assert_column(&ring_off, &mirrored(RING_OFF), 3.0, &[], "Ring, Anti-aliased off");
|
||||
for contour in [Contour::Linear, gaussian(), ring()] {
|
||||
for aa in [false, true] {
|
||||
let m = issue_map(contour.clone(), aa);
|
||||
assert_eq!(m.get(200, 150), 0.0, "the layer centre gained satin ({contour:?}, Anti-aliased {aa})");
|
||||
for x in 100..=299 {
|
||||
assert!(m.get(x, 150) < 0.5 / 128.0, "row y 150 is not 128 at x {x} ({contour:?}, Anti-aliased {aa})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Done when: with Linear, Anti-aliased on gives a pixel-identical image to Anti-aliased off.
|
||||
/// Contours the issue did not measure with Anti-aliased (Cone here) keep today's map too.
|
||||
#[test]
|
||||
fn linear_and_unmeasured_contours_ignore_anti_alias() {
|
||||
for size in [3.0, 10.0, 30.0] {
|
||||
assert_eq!(bit_hash(&map(size, 20.0, 90.0, Contour::Linear, true)), bit_hash(&map(size, 20.0, 90.0, Contour::Linear, false)), "Linear Size {size}");
|
||||
}
|
||||
assert_eq!(bit_hash(&issue_map(Contour::Linear, true)), 0xbc2c_550d_40a1_6091, "the Linear Satin map moved");
|
||||
assert_eq!(bit_hash(&issue_map(cone(), true)), bit_hash(&issue_map(cone(), false)), "a Cone Satin moved with Anti-aliased");
|
||||
}
|
||||
|
||||
/// The gate shared with the shadows (`anti_aliased_geometry` at no spread): Size 0 and Size 1 are
|
||||
/// not a blur wider than the identity (Size 1 is its own measured kernel, #14983), so the offset
|
||||
/// would be the whole edge; neither was measured with Anti-aliased and both keep today's map.
|
||||
#[test]
|
||||
fn identity_blur_sizes_keep_todays_map() {
|
||||
for size in [0.0, 1.0] {
|
||||
for contour in [gaussian(), ring()] {
|
||||
assert_eq!(bit_hash(&map(size, 20.0, 90.0, contour.clone(), true)), bit_hash(&map(size, 20.0, 90.0, contour, false)), "Size {size}");
|
||||
}
|
||||
}
|
||||
assert_eq!(bit_hash(&map(1.0, 20.0, 90.0, gaussian(), false)), 0x7746_6f79_0561_5215, "the Size 1 Gaussian Satin map moved");
|
||||
}
|
||||
|
||||
/// Guard: the rule is in the inputs, not keyed to the measured document. Other Sizes, Distances
|
||||
/// and Angles take the offset too; with the flag off they keep the maps they had on main.
|
||||
#[test]
|
||||
fn the_offset_follows_the_inputs() {
|
||||
for (size, distance, angle) in [(3.0, 20.0, 90.0), (30.0, 20.0, 90.0), (10.0, 50.0, 45.0)] {
|
||||
assert_ne!(
|
||||
bit_hash(&map(size, distance, angle, gaussian(), true)),
|
||||
bit_hash(&map(size, distance, angle, gaussian(), false)),
|
||||
"Anti-aliased did nothing at Size {size}, Distance {distance}, Angle {angle}"
|
||||
);
|
||||
}
|
||||
assert_eq!(bit_hash(&map(3.0, 20.0, 90.0, gaussian(), false)), 0xc2d9_f2ff_2e28_b5e5, "Size 3 Gaussian off");
|
||||
assert_eq!(bit_hash(&map(30.0, 20.0, 90.0, gaussian(), false)), 0x34f9_ed94_4796_b7cd, "Size 30 Gaussian off");
|
||||
assert_eq!(bit_hash(&map(10.0, 50.0, 45.0, gaussian(), false)), 0x251b_da84_c855_0df1, "Distance 50 Angle 45 Gaussian off");
|
||||
}
|
||||
|
||||
/// Invert flips the result after the contour (#14981), so an inverted Anti-aliased Satin is the
|
||||
/// exact opposite of the same Satin without Invert; the flag off keeps main's inverted map.
|
||||
#[test]
|
||||
fn invert_stays_the_opposite_with_anti_alias() {
|
||||
let shape = document_shape();
|
||||
let off = satin_map(&shape, &satin(10.0, 20.0, 90.0, gaussian(), false, true));
|
||||
assert_eq!(bit_hash(&off), 0x9bd6_7f2d_bcb2_1e9d, "the inverted Gaussian Satin map (Anti-aliased off) moved");
|
||||
let plain = satin_map(&shape, &satin(10.0, 20.0, 90.0, gaussian(), true, false));
|
||||
let inverted = satin_map(&shape, &satin(10.0, 20.0, 90.0, gaussian(), true, true));
|
||||
for ((p, i), a) in plain.v.iter().zip(&inverted.v).zip(&shape.v) {
|
||||
assert!((p + i - a).abs() < 1e-6, "Invert is not the opposite of the Anti-aliased Satin: {p} + {i} vs {a}");
|
||||
}
|
||||
}
|
||||
@@ -1004,8 +1004,8 @@ fn flat_contour_outer_glow_is_a_solid_band_with_one_soft_pixel() {
|
||||
let n = 60;
|
||||
let at = |m: &Map, x: usize| m.v[30 * n + x];
|
||||
// Precise, with the square's left column half covered: its edge sits mid-pixel, so the
|
||||
// pixels out from it are 1.5, 2.5, 3.5, 4.5, 5.5 px (centre to centre) from the shape, and
|
||||
// the reach (size + 1 = 5) ends half-way across the 4.5 px one.
|
||||
// pixels out from it are 1.5, 2.5, 3.5, 4.5, 5.5 px (centre to centre) from the shape. The
|
||||
// 4.5 px one has coverage 0.05, which the 0.12 knee (#15006) paints at 5/12.
|
||||
let mut shape = square_20_40();
|
||||
for y in 20..40 {
|
||||
shape.v[y * n + 19] = 0.5;
|
||||
@@ -1014,18 +1014,17 @@ fn flat_contour_outer_glow_is_a_solid_band_with_one_soft_pixel() {
|
||||
for x in 16..=19 {
|
||||
assert!(at(&m, x) > 0.999, "precise, solid band at x {x}: {}", at(&m, x));
|
||||
}
|
||||
assert!((at(&m, 15) - 0.5).abs() < 0.05, "precise, the soft outer pixel: {}", at(&m, 15));
|
||||
assert!((at(&m, 15) - 5.0 / 12.0).abs() < 0.01, "precise, the soft outer pixel: {}", at(&m, 15));
|
||||
assert!(at(&m, 14) == 0.0 && at(&m, 0) == 0.0, "precise, beyond the reach: {} {}", at(&m, 14), at(&m, 0));
|
||||
// Precise, pixel-aligned edge: the pixels out from it are 1..5 px (centre to centre) from the
|
||||
// shape and the reach ends at the 5 px one's centre, so the band is solid through Size (x 16,
|
||||
// 4 px out, 1.0) and the next pixel (x 15) is beyond it. Point-sampled, as the measured Linear
|
||||
// falloff is: an area-averaged falloff would leave x 15 half covered (the reach ends 4.5 px
|
||||
// past the shape's edge, half-way across it), not 0.84.
|
||||
// shape and the reach ends at the 5 px one's centre. Photoshop's x 16 (4 px out, coverage
|
||||
// 0.1) reads 213 of 255 (#15006), and x 15 is beyond the reach.
|
||||
let shape = square_20_40();
|
||||
let m = glow_map(&shape, &contour_glow(GlowTechnique::Precise, 4.0, &FLAT), false, (0, 0));
|
||||
for x in 16..20 {
|
||||
for x in 17..20 {
|
||||
assert!(at(&m, x) > 0.999, "precise aligned, solid band at x {x}: {}", at(&m, x));
|
||||
}
|
||||
assert!((at(&m, 16) * 255.0 - 213.0).abs() <= 1.0, "precise aligned, the soft outer pixel: {}", at(&m, 16));
|
||||
assert!(at(&m, 15) == 0.0, "precise aligned, beyond the reach: {}", at(&m, 15));
|
||||
// Softer, size 4: the tent's last tap (1/64, at x 16) is above what one opaque pixel gives one
|
||||
// pixel inside its reach (t[3]·t[0] ≈ 0.0137), so a straight edge is solid through its reach.
|
||||
|
||||