Pages reduced by k > 1 whose source starts on a multiple of k now use the
band/tile reduced render (one-colour tile skipping, parallel tiles) on a
factor-aligned cell grid instead of compositing every pixel at full size and
averaging. Unaligned sources keep the averaging path, which tests use as the
reference (U8/U16/F32, k = 2, 4, 16, max difference < 1e-4). The reduced
render now checks the page's interrupt between bands.
A drop guard armed only once this call created the temp file replaces the error-path
remove_file, so a writer panic no longer leaves a temp file and a create_new collision
never removes a file this call did not make.
Like the tile scratch file, each append records a CRC-32; a save copying it (whole or
in consecutive parts) fails on the last part if the scratch disk returned different
bytes, so the document is never replaced with them.
* security(affinity): charge allocation records, empty subpaths, paint lists, tile indexes and shape lookups
Several readers still did work per occurrence of a shared object that no
document-wide budget counted:
- Archive::open walked every allocation table's records, and overlapping tables
could reparse one long run thousands of times. Records are now charged against
MAX_TABLE_RECORDS before each table is walked.
- curves() charged a subpath's records but not the subpath, so a shared curve
full of empty subpaths was walked for free. Each subpath now costs one record.
- Colours and gradient positions decoded their whole float record (up to 64 KiB)
to read two to five components; only those are decoded now.
- Paint selection collected whole BFFl/LIFl/LILn lists without charging their
slots; the lists are charged and walked once without collecting.
- Dash patterns were copied per occurrence with no length limit; they are capped
at 64 entries and charged against the document budget.
- The raster tile index skipped null Idx slots uncharged; every slot walked is
charged now.
- shapes::last rescanned all fields per lookup and CTyp/ShCR were copied whole;
the field index records last occurrences too, and only four corners are read.
* test(affinity): cover the allocation record budget across chained tables
* test(affinity): directory records count against the allocation record budget
The exr crate sizes a preview attribute's pixel buffer from its
declared dimensions (up to 4 MiB at once, zero-filled) before it finds
the attribute too short, and in the non-pedantic mode every reader here
uses, it then skips the attribute and continues. A header with
thousands of tiny malformed previews therefore cost thousands of 4 MiB
allocations before any size check ran.
check_previews walks the raw headers and refuses a preview whose
declared width x height x 4 exceeds its value size. It runs before
every header read: read_meta, read_layer, the Cryptomatte listing and
decode_deep_exr.
The portable data folder's writability check wrote a fixed, PID-named file with
std::fs::write, which follows an existing symlink and truncates its target.
Create the probe with create_new, try another name on a collision, and remove
only a probe this call created.
Review nitpick (#9466): the test only checked that the default export had some ICC profile and that `none` matched it, so a regression writing sRGB instead of the input's Display P3 would still pass. It now compares the default export's profile with the input's bytes.
Review follow-up on #9975. The help text and the CLI book page said the
XMP and free-form text are kept in every flat export and the ICC profile,
EXIF and resolution "either way". Not every format holds them: JPEG and
WebP have no place for free-form text, TIFF writes only its named text
tags, and an Indexed Color document's palette PNG carries no XMP, text,
ICC or EXIF at all, only its resolution. The texts (and the parity-doc
revision row) now say the XMP and text are kept where the format holds
them and that the option leaves everything else as it is without it.
The test fixture gains a free-form text entry and a Display P3 profile
(from photocraft-cms, now a dev-dependency; no profile file committed),
so it checks the text is gone with `none` and kept by a default PNG, and
that the default export keeps a real ICC profile that `none` matches,
instead of comparing None with None.
Since #733 a flat export from the CLI keeps the document's whole XMP
packet and free-form text, as Save As does; only Export As starts at
Metadata: None. Batch exports of Photoshop masters therefore carry the
full DocumentAncestors list (and the text of every type layer), which
can be many times larger than the image, with no way to leave it out.
`--metadata` is a new export option shared by `convert`, `run --out`
and `batch`. `none` sets ExportOptions::xmp to XmpEmbed::None, the same
path Export As's Metadata: None and Quick Export use, so the XMP packet
and free-form text are dropped while the ICC profile, EXIF and
resolution are written as before; PSD, PSB and .pcraft keep the XMP
either way. `all` is the default, so existing scripts write the same
files. Any other value is a usage error (exit 2) naming the flag,
before anything is read or written.
Tested through the binary for PNG, WebP, JPEG and TIFF from all three
subcommands (packet present by default and with `all`, absent with
`none`; pixels, ICC and resolution unchanged), layered saves, and bad
values. Documented in the CLI book page and file-format parity doc.
Review follow-up: open the menu on a started crop and assert it adds a glyph
texture per overlay, so the canvas menu's icon wiring cannot regress silently.
Six original icons in the house style, one per crop overlay, drawn in the
crop-mark frame around the guide they name. They sit between the check mark
and the label in the options-bar overlay menu and in the canvas Crop menu, and
the options-bar button paints the overlay in use.
Tests: crates/ui-egui/tests/it/crop_overlay_icons.rs (#10889).
Review follow-up: a ratio picked on the untouched frame changes its bounds, so
the temporary "Selection" entry must not come back when the ratio is cleared.
The dropdown test now also checks that the entry sits above the Ratio presets
and reads as checked.
AuthorizedWorkspace::write_stream keeps write()'s refusals and atomic replace but
lets the encoder write (and seek back) straight into the temp file, so an
automation PSB save no longer builds the whole file in a Vec.
Each colour channel and the merged image is parked in a scratch stage file as
soon as it is encoded (documents of 1 GiB+ raw pixels, chunks of 64 KiB+), so a
save no longer holds every encoded plane in memory before #8115's checked write.
The written file is byte-identical; when staging is unavailable the data stays
in memory.
Shares ScratchFile's private open (0600, unlinked at once, delete-on-close on
Windows) so encoded save data can be parked off the heap and read back by offset.
A document that goes over the canvas budget kept its texture set (and the compositor's
pages for it) resident while drawn from viewport pages, holding the memory the pages are
budgeted against. texture_key is needed outside tests now; fetch_update is deprecated.
A channel or merged image still in its source (an imported file's, or one
spilled to scratch) is copied to the output in 8 MiB pieces instead of being
read whole into memory first.
Resolve conflicts with #5331 (EXR streaming): the block-by-block EXR import now
reads from the same identity-verified handle as the rest of the open path, and
docs/scratch-disks.md keeps both the EXR streaming pointer and the RAM/scratch
admission notes.
Redesign of the viewport streaming for #5332 on current main:
- Only documents whose display texture set doesn't fit the canvas budget
(GpuCanvas::fits_canvas, from detected RAM/VRAM) use pages, so GPU Memory
on Auto (gpu_memory_mb = 0) no longer streams every document.
- Documents that fit keep main's texture set path (LayerFit, DEFER_PX
deferral, background redraw, admit_output); no pixel-count cutoff.
- Edits dirty only the pages their damage reaches; nothing scans layer tiles.
- Pages are held to half the per-document canvas budget; no change to the
global wgpu resource budget or to gpu_budget's split between documents.
- Bounded workers (2) and uploads per frame, cancellation on pan/zoom/edit,
CPU canvas fallback when a page fails or no page fits.
The tile halo was sized from the clamped effect values, but the pixel code still read the raw
stored ones, so a stored value past its range could have a kernel larger than its halo and show
seams where tiles meet. `run` and `Prepared::new` now clamp the stack once at the entry, so the
reach and the pixels use the same values. The new test renders every gallery filter with its
range values at three times the maximum and requires the same pixels as at the maximum; it fails
without the change (ColoredPencil first).
Addresses the CodeRabbit review on this PR.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Fill dropdown's first entry now reads Background (default) with Delete
Cropped Pixels on, and Transparent (default) with it off, as the reference
application does; both keep crop_content_aware false, so only the label
changes. Its translations carry over from Background (Default).
The crop preset dropdown shows a checked Selection entry above Ratio while the
frame is the untouched default frame made from a selection's bounds. It is a
label: choosing it changes nothing, and editing the frame or picking a ratio
removes it.
Tests live in tools/crop_options_labels_tests.rs (#10872).
Rescope: this merge takes main's tree as is. The stacked #5331 commit
(streaming PSD import reader, EXR, duplicate atomic/streaming save infra,
the try_reserve_operation export pre-check) and the #5332 GPU commit stay in
their own PRs; main's Services::save_file/SaveCtl and #8115's streamed PSD
writer replace this branch's save plumbing. The band-wise PSB writer is
re-added on top in the next commit.
Main moved the GPU canvas into canvas/gpu_canvas/* and gained its own
budget, LayerFit and background-redraw machinery. Conflicted files take
main's version; the viewport streaming is re-integrated on top of main's
budget in the following commit.
One RAM detector: the cgroup v1/v2, macOS reclaimable and Windows commit providers move from
photocraft-io into photocraft_raster::memory::system (L0), which the residency budget (#5330)
and photocraft_io::memory both read. Unreadable container limits still fail closed, swap is
never counted as RAM. sysinfo is unified on =0.40.1 (raster only).
While the scratch disk is spilling (on, not paused), import admission credits the tile pixels
of an estimate against spill::scratch_capacity() (free space above the reserve, within the
Scratch Size Limit); decode buffers, conversion copies and merged planes stay RAM-only. Spilling
off/paused and the web keep the RAM-only policy unchanged. PsdMemoryEstimate gains tile_bytes;
the flat TIFF streaming check credits its tile surface the same way; engine approveMemory's
fast pre-check uses the credited hard limit and the import re-checks exactly.
Resolve against main's save restructure (Services::save_file/SaveCtl, scratch-integrity checks,
ZipWriter::with_entries, exact encoded_len):
- PSD/PSB saves stream the file model through atomic_write_stream_progress; the length used for
progress and reservations is main's exact encoded_len (the PR's size_bound under-counted lazy
data); export_with/encode_with share checked_stages, so main's scratch checks (previews
included) still refuse unreadable scratch.
- Drop ZipWriter::for_entries in favour of main's with_entries.
- TIFF: take_from_psd moves layer data out of the export's own model (never the document);
body() reserves its exact length, failures are OutOfMemory (not LimitExceeded, which would
trigger the PSB retry).
- Streaming writer: AlreadyExists from the writer is a failed save, not a name collision.
- Remove dead Vec put_widened_rle; channel_data_len is test-only.
- import_file_for_open_with decodes single-part flat scanline EXR block by block into
tiles; headers the band decoder refuses fall back to the whole-file decoder, so files
main opened still open. Band-time failures and cancellation publish no document.
- The RAM tile budget and scratch-disk checks live in exr_native (the PSD stream module
they came from is dropped); over-budget opens fail with IoError::OutOfMemory.
- The band decoder picks colour channels with exr_color_channels, like the byte decoder.
- Tests move into the per-crate it binaries and use import_file; an engine open-job test
covers the OpenSource::Path route. The ui-egui sync open test is dropped: main's
synchronous open reads bytes, and the io test covers the oversized header.
- docs/streaming-io.md, roadmap, scratch-disks and REL-212-1 describe EXR only.