Commit Graph
93 Commits
Author SHA1 Message Date
Diego Chagas 5e9eefc3b0 memory: a skipped mountinfo line no longer proves the cgroup mount absent
Review feedback: parse_mountinfo drops malformed lines, so a valid root mount
plus a truncated cgroup line counted as 'no cgroup mount'. Every non-empty
line must now parse; otherwise the case stays fail-closed.
2026-11-07 07:25:07 -03:00
Diego ChagasandClaude Sonnet 5.5 43b200743e memory: drop the helper the single parse made unused
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 07:18:30 -03:00
Diego ChagasandClaude Sonnet 5.5 ce73b335c9 memory: parse mountinfo once in the absent-cgroup-root check
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 07:17:09 -03:00
Diego ChagasandClaude Sonnet 5.5 2504120c33 memory: an absent /sys/fs/cgroup counts only when mountinfo lists real mounts
An empty or garbled mountinfo parses to no mounts, which proved nothing but let the
sandbox shortcut report NotConstrained. Now at least one mount must parse, none a cgroup
filesystem. Tests: missing/empty/garbage mountinfo, a non-NotFound stat error, and v1/v2
alternate mounts with unreadable limits all stay Unreadable.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 07:17:09 -03:00
Diego Chagas 5734b44052 memory: only a confirmed-missing /sys/fs/cgroup takes the sandbox fallback
Review feedback: a failed stat for another reason (permissions) stays
fail-closed, and a test covers a cgroup2 mount at an alternate path.
2026-11-07 07:17:09 -03:00
Diego Chagas 3f62397fbd memory: a sandbox without a cgroup mount no longer reads as 0 bytes free
In the Flatpak sandbox /sys/fs/cgroup is absent, so the detector found a
membership path it could not read and failed closed: available RAM 0, and
every PSD refused with a 0 byte hard limit. With no cgroup mount in
mountinfo and no /sys/fs/cgroup, no limit is observable; use host memory.
2026-11-07 07:17:09 -03:00
FredApps d2ce418bb3 Merge pull request #11641 from wanikhawar/claude/agitated-jones-8e1a8e
A little free memory no longer refuses every PSD; the refusal says what to do
2026-11-06 18:36:17 +01:00
FredApps 91a2fd1d85 Merge pull request #11652 from wanikhawar/claude/stoic-yalow-d695ab
A scratch folder that stops answering no longer freezes the app
2026-11-06 18:28:41 +01:00
FredApps ce97bde34b Merge pull request #11628 from wanikhawar/claude/brave-wu-261567
Network scratch folders report their own free space, or say they can't
2026-11-06 18:15:40 +01:00
FredApps 1eba8f6c72 Bound scratch capacity test query waits 2026-11-06 17:51:32 +01:00
FredApps 0a2365e925 Keep rejected scratch growth queries due for retry 2026-11-06 17:50:54 +01:00
FredApps aee46a2fc6 Merge remote-tracking branch 'origin/main' into fix/10164-final-prune-u2 2026-11-06 17:28:48 +01:00
Khawar Zamman Wani cd2250cb25 Scratch folder queries: address second review
A stuck close no longer holds up the files queued behind it (up to four
closer threads), and a query identifies the current file by the configured
folder. Tests don't read the room and the status across a late answer, and
the growth-check step proves its query is stalled.
2026-11-06 20:48:08 +05:30
Khawar Zamman Wani e01c8719a0 Scratch folder queries: address review
The whole folder change now waits 2 s at most, old files close on one
background thread, the cap counts query threads until they finish, and
writes during a query aren't counted twice. Capacity is refused if a sweep
paused spilling meanwhile, a query opens a file unless this folder has one,
and on macOS an unrelated dead mount only costs the purgeable figure.
2026-11-06 19:44:03 +05:30
Khawar Zamman Wani 2c68c07dbf A scratch folder that stops answering no longer freezes the app
Opening and measuring the folder ran under the config lock, which the UI
takes every frame, and could run on the UI thread itself. They now run on
a short-lived thread, one per folder and question and 16 overall; callers
wait at most 2 s, and a late answer applies if the folder is still current.
No answer counts as unmeasured, or pauses spilling if nothing is open yet.
2026-11-06 17:45:34 +05:30
Khawar Zamman WaniandClaude 873ed7bf37 Scratch status: hold the lock across the directory check and the store
A guard that is a temporary in an if condition drops before the body runs, so a configuration change
could still land between the two.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-06 16:46:04 +05:30
Khawar Zamman WaniandClaude 4d559c0e4c Scratch free space: address review
Windows queries the verbatim path, as stripping the prefix can change what a trailing dot means. A
slow query no longer overwrites the status of a folder configured meanwhile. macOS recognises the
listed volume by its mount point's statvfs numbers, not the total alone. Tests no longer assume the
temp volume reports capacity or compare live readings, and a real failed measurement is covered.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-06 15:56:11 +05:30
Khawar Zamman WaniandClaude ed49cd9401 Scratch free space is asked of the folder itself, so network folders report their own numbers
Windows network folders reported unknown because sysinfo doesn't list them, and an unlisted Linux
NFS or CIFS mount used the numbers of its listed parent. GetDiskFreeSpaceEx (Windows) and statvfs
(Unix) on the directory fix both. macOS keeps sysinfo's figure, which counts purgeable space, when
the listed disk is this volume. A mount that reports no space is flagged in Preferences, in the
hard-limit refusal and in spill::stats, with a hint to set a Scratch Size Limit or use a local disk.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-06 14:58:27 +05:30
Khawar Zamman Wani 7fc39a61c1 Caller-space test queries the temp directory, not its drive root
A temp folder on a volume mounted without a drive letter has a root on a
different volume, so the comparison could fail on correct code.
2026-11-06 14:57:19 +05:30
Khawar Zamman Wani 349a03b6b1 Refusal text states the lower limit, links the download and shows readable sizes
The 32-bit message ended mid-phrase. It now says the cap applies or less if
less memory is free, and separates the cause from the next step. Windows
scratch tests check the returned numbers belong to the temp directory's volume.
2026-11-06 14:01:03 +05:30
Khawar Zamman Wani 1eb3218a4b Merge remote-tracking branch 'origin/main' into claude/investigate-issue-e27e90 2026-11-06 12:37:29 +05:30
Khawar Zamman Wani 6ebc4c96f8 Place: move the pixels a few tiles at a time, name the real place command in the size error
A place at an offset off the tile grid rebuilt nearly every tile the image touches in
a single poll, which can overrun the ~8 ms slice on a big image. TranslateSteps
(photocraft-raster) builds the target tiles of Surface::translated a tile at a time
with the same code (a shared ShiftBuilder), so the result is bit-identical; the place
runs it as a Placing stage of its own in a cooperative session.

The flatten size refusal named "file.place", which is no command: it now names
file.placeEmbedded or file.placeLinked.
2026-11-06 09:13:41 +05:30
Khawar Zamman Wani 123b2032c4 Web build: Place runs a slice per frame, so a large PNG no longer freezes the page (#10164, rebased onto main)
The remaining commits of the stack, applied on top of the squash-merged #10147:

- PNG decodes in resumable steps of rows (PngDecodeRows, shared with decode_rows)
- PNG imports as a document in resumable steps (io PngImport, text metadata and
  document build in bounded steps)
- Jobs can run a slice at a time where there are no threads (StepWork,
  cooperative sessions, Session::poll_jobs)
- Place decodes, flattens and resizes in slices (PlaceSteps), reading a path
  and keeping the frame, memory gate and typed memory-budget errors main has
- The web build places dropped and picked files a slice per frame, with a
  bounded place inbox
- A measurement of the stepped place; docs for jobs without threads
2026-11-06 08:51:17 +05:30
6326117c53 Web build: big operations that won't fit fail with an error instead of trapping, and a trap says so (#10129)
* Raster: ask the allocator whether a big operation fits; PSD save reserves its whole output

New photocraft_raster::headroom: ensure(need) tries to reserve the need plus a margin and frees it
at once (web only; native always passes), below(bytes) tells whether less than that can be
allocated, and simulate_available fakes the answer for tests and diagnostics.

PsdFile::to_bytes reserved only the pixel data, so embedded smart-object data and other tagged
blocks grew the output by doubling, which on the web is one unrecoverable huge realloc. It now
reserves the exact encoded length.

* Big operations that won't fit in memory fail with an error instead of trapping

Place, Image Size, a smart-object re-render and Save now ask the allocator whether their estimated
need can be allocated before they start (photocraft_engine::memory_gate, estimates per operation,
photocraft_io::estimate_export_bytes for saves). A refusal changes nothing and says what the
operation needed and what to do (save, Edit > Purge > All, close documents).

A standing notice warns when less than 512 MiB can be allocated, with hysteresis, so the user can
save before anything traps. Notices can now be sticky, which keeps them past the auto-hide delay.

* Web build: a trap says so instead of freezing the page, and ?free-mb simulates low memory

index.html holds a hidden, static 'PhotoCraft stopped' message with a Reload link. web.rs reveals
it when the module traps (the window error event, or an unhandled rejection from a spawned
future), tells running out of memory from an internal error by the panic message a chained panic
hook kept, and skips the Leave site prompt once stopped. ?free-mb=N makes the memory gates and the
low-memory warning see only N MiB, for checking them in a browser.

* Docs: web build memory handling in the gaps list and the parity assessment

* Engine: use is_multiple_of in the megabyte formatter

* Cargo.lock: the web shell depends on photocraft-raster

* Web boot page: carry the stopped message too, as the test that keeps the two pages equal requires

* Save check counts one copy of the document, and runs once per save

The encoded file's buffer is reserved fallibly, so a save it doesn't fit
in fails with an error instead of trapping; counting it as well refused
saves that would have fitted. On the background-save path the check ran
in write_document and again in start_save, which other callers reach
directly; it now runs only in start_save there.

* Review fixes: warning check allocates nothing, PSD merged image counted, automation saves checked

The low-memory warning's periodic check reads the size of linear memory
instead of reserving a block: wasm memory never shrinks, so a trial every
few seconds raised the high-water mark by up to 768 MiB for nothing. The
operation checks keep their trial reservation.

PSD and PSB saves always build a canvas-sized merged image (a placeholder
without maximum compatibility) and hold it raw and encoded; the save
estimate now counts it. The synchronous automation save checks memory
before encoding, as File > Save does, and its test asserts the memory
error.

The trap listeners go in before the app is built, so a trap while
building it shows the stopped message too, and a memory access out of
bounds reads as unexpected rather than as running out of memory.

* Cover layered PSD preflight limitation

* Fix layered PSD test iteration

* Docs: layered PSD preflight limitation in the gaps list

* Web OOM gate: gate direct exports, truthful advice for unbounded PSD sources (#10024)

* Web OOM gate: estimate layered PSDs per layer instead of refusing every real PSD

The PSD check admitted a file only when its color-mode data, image
resources and layer section were all empty. Every Photoshop file has
image resources (at least the resolution), so on the web nearly every
real PSD was refused for Place, PSD smart objects could not render,
and Image Size was refused for documents holding one, whatever the
free memory (u64::MAX never fits).

The color-mode data and image resources hold no pixels, so they are
now only skipped. A layered file reads its layer count from the layer
info (signed, absolute value) and adds a canvas-sized surface and mask
per layer to the flat estimate. Files that are not 8-bit RGB or
grayscale, keep their layers in a Layr tagged block, or whose sections
can't be read stay unbounded and refused, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Web stopped page: match trap messages ignoring case

Safari reports the allocation-failure abort as "Unreachable code
should not be executed" and Firefox says "out of memory", which the
case-sensitive matching missed: the trap was not recognised, or was
shown as an unexpected stop instead of running out of memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Export estimate: count the merged image OpenRaster writes

The ORA writer keeps the layers but also flattens the document for
mergedimage.png, a 16 B/px composite of the canvas, which the
estimate left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:04:59 +01:00
Khawar Zamman Wani eecc821ee8 Scratch room uses what the user can write; a failed volume query is unknown
sysinfo reports a Windows volume's free bytes, which a per-user disk quota can
exceed, so admission could promise room the user can't write. free_space now asks
GetDiskFreeSpaceEx for the bytes available to the caller.

sysinfo also keeps a volume whose space query failed, with both numbers zero, which
read as an empty disk and would pause spilling. A zero total now counts as unknown.

Docs: describe network scratch per platform and the size limit's import allowance.
2026-11-06 00:21:07 +05:30
Khawar Zamman Wani af2914fd17 Refusal wording holds when memory sets the 32-bit limit; keep non-UTF-8 scratch paths
On a 32-bit build, free RAM or commit headroom can set the limit instead of the
cap, and then 'install the 64-bit build' was wrong. The message now mentions the
cap and says the 64-bit build may open the file.

The verbatim prefix is now removed through path components, so a scratch path with
a non-UTF-8 name still finds its disk. The UNC rewrite is gone: sysinfo lists only
fixed and removable volumes, so a network path can never match. That limitation is
now documented.
2026-11-05 23:22:13 +05:30
Khawar Zamman Wani 83f492f445 Windows scratch room is measured; hard memory refusal names the build's limit
fs::canonicalize returns verbatim paths on Windows, whose prefix never equals a
disk's plain mount point, so free_space always returned None there. That removed
the scratch allowance from import admission (unless a size limit was set) and
turned off the low-disk check.

The PsdHardBudget message said 'on this machine' even when the limit is the fixed
cap of the 32-bit desktop or web build. It now says so and names the build to use.
2026-11-05 22:07:47 +05:30
Khawar Zamman WaniandFredApps 98bcbfab90 perf(io): build JPEG/PNG tiles straight from the decoded rows, in parallel (#10259) (#10281)
* perf(io): build JPEG/PNG tiles straight from the decoded rows, in parallel (#10259)

Surface::try_write_rows_with fills tiles row by row on all cores; image_surface
converts from the borrowed decoded rows into it (no per-band copy, no staging
Image). Opaque sources skip the prune scan. import_flat_with checks cancel after
the decode and the tile build and reports progress.

* fix(io): store an F16 target as F32 so its opaque alpha is 1.0

An image without alpha converted to an F16 target got the alpha 0.0: the
opaque-alpha path copied two bytes of 1.0f32. The surface keeps 16-bit float
as 32-bit float anyway, so image_surface now converts an F16 target to F32.

* Format fused tile import integration

* Route default flat imports through interrupt wrapper

* Remove unused flat import cancellation wrapper

* Exercise options import API in cancellation tests

* Stop flat image tile construction on cancellation

---------

Co-authored-by: FredApps <FredApps@users.noreply.github.com>
2026-11-05 10:33:29 +01:00
FredApps be3b2918c3 raster: checksum stage-file appends and fail a read pass over changed bytes
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.
2026-11-03 12:16:23 +01:00
FredApps 7cffeef725 Merge remote-tracking branch 'upstream/main' into pr-5333 2026-11-03 11:16:05 +01:00
FredApps 4b27da939f raster: anonymous append-only stage file on the scratch disk
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.
2026-11-03 10:49:38 +01:00
FredApps 3695186329 Consolidate RAM detection in raster::memory::system; scratch-aware PSD/TIFF admission
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.
2026-11-03 09:48:22 +01:00
FredApps ed681787c3 Add a Scratch Size Limit preference and honour the web memory cap in the memory policy 2026-11-03 01:16:52 +01:00
FredApps c9478d0501 Expect the Windows scratch entry until its delete-on-close handle closes
Windows keeps delete-on-close (unlinking an open file is not portable there), so a
live scratch file still has a directory entry. Only Unix unlinks it right after
opening. Check that the directory is empty once the file is closed on both.
2026-11-03 00:54:09 +01:00
FredApps 9eddf1d8ca Pause and retry a failed or full scratch disk instead of turning spilling off
A scratch write or create failure, or a volume about to drop below max(1 GiB, 5%)
free space, now pauses spilling with exponential backoff (1 s doubling to 60 s)
instead of disabling it for the session. Tiles stay resident, set_budget keeps
the latest budget for the resume, preference changes retry at once, and
spill::epoch lets the engine re-apply History's byte limit while paused.
spill::set_size_cap adds an explicit size limit; free space comes from sysinfo's
disk feature.
2026-11-02 22:31:56 +01:00
FredApps 44f13e5498 Scope scratch read failures to the document that holds the tile
One unreadable tile used to block editing, saving and exporting every open document
(spill::check_integrity was process-global). Add Tile/Surface/Document::scratch_health
(free while no tile has failed) and Document::for_each_surface (ops' history walk now
delegates to it). edit_with checks the document before and after, jobs the document they
captured, import the result, save/export the document written; check_since is now
generation-only so a failure or recovery during an operation refuses it once and a retry
works. Caches check their own sources and purge once per new failure instead of every
frame. Fault-injection tests use a duplicated handle (the Unix file has no name).
2026-11-02 22:23:42 +01:00
FredApps 947038d0db Unlink Unix scratch files right after opening
The spill manager is process-global and never dropped, so the Unix scratch file was only
removed by the next launch's reap. Unlink it immediately after opening and read/write
through the one handle with pread/pwrite (readers can no longer reopen it by path).
Windows keeps delete-on-close and per-thread readers. The abrupt-exit test now asserts
that no file remains on every platform; docs/scratch-disks.md updated.
2026-11-02 22:17:50 +01:00
FredApps 13271f58fa Size filter working sets by area and serialize overlapping operations
working_bytes reserved three 256 MiB result groups for every filter, so two
concurrent filters on a 24x18 image could exhaust the transient allowance and
actions.play reported 'not enough working memory'. Bound the result groups by
the area, charge only untiled RSS when resident tiles are evictable, always admit
the transient allowance, and let an operation that fits on its own wait (bounded,
30 s, native only) for concurrent reservations instead of failing.

Replace the deprecated AtomicU64::fetch_update with try_update (stable since
1.95, the MSRV).
2026-11-02 22:16:32 +01:00
FredApps b0f3c7516b Merge current main into codex/scratch-storage
Resolve conflicts with main's prefs UI split, session/execute.rs move, GPU memory
budget (gpuMemoryMb, 0 = auto, kept from main) and effective_memory_usage_mb history
budget. Port the Memory Usage % and Scratch Disks preferences into prefs_ui, the edit
integrity guard into session/execute.rs, and adapt main's new pixel readers to the
guarded TileBytes API. Cargo.lock regenerated; scorecard regenerated.
2026-11-02 22:16:22 +01:00
Khawar Zamman Wani 86ddfb72f7 Reuse large buffers so returning freed memory to the OS doesn't slow filters (#10479) (#10514)
* perf: reuse large buffers so a pinned glibc trim threshold costs no speed (#10479)

With MALLOC_TRIM_THRESHOLD_ set (#8743), glibc maps every allocation over
128 KiB fresh, so tiles, compositor bands and filter scratch were page-faulted
in on every call: viewport compose 3.6x slower, Gaussian Blur up to 1.8x,
.pcraft save 2.4x.

- photocraft_raster::scratch: a process-wide, capped pool of large Vec
  buffers (u8/u16/f32/[f32; 4]). A miss drops the oldest buffers worth its
  size down to a 256 MiB floor, so peak memory stays near glibc's defaults.
  The engine releases the pool after any command that closes a document,
  Headless::close does too, and an idle thread releases it after 2 s unused.
- Tiles, compose Buffer/masks/bands, algo Image and the blur paths, engine
  adjustment/filter scratch, GPU tile upload and io import buffers go through
  the pool.
- .pcraft save reuses one zstd FrameCompressor per worker (byte-identical).
- interactive_bench reports minor page faults per run.

36 MP, trim threshold set vs glibc defaults: viewport 5.6 vs 6.1 ms (was
22.7), Blur r4 445 vs 437 ms (was 852), Curves CPU proxy 35.0 vs 35.7 ms
(was 50), flatten 146 vs 147 ms (was 237), save .pcraft 251 vs 230 ms (was
545). RSS after closing a 5400x7200 document: 21 MB with trim set.

* fix: corpus tests build again; return remaining pooled buffers (#10479 review)

- Corpus-gated io tests and the Photoshop-oracle test moved `.px` out of a
  `Buffer`, which now implements `Drop` (E0509 with `--features corpus`):
  use `into_px()`.
- io: masks, the merged image, extra channels, smart-filter masks,
  smart-object pixels and patterns give their `interleave` buffers back to
  the scratch pool after writing them.
- compose: recycle the mask values of a pass-through group, `effect_shape`
  and both `split_parts` callers.
- Styled Free Transform preview copies each band out instead of moving it,
  so the band returns to the pool.
- interactive_bench: the fault count covers each whole run, untimed setup
  included; say so.

* fix: recycle the masks of adjustment-atop and shape layers (#10479 review)

* fix: recycle effect hiding masks (#10479 review)

* fix: recycle knockout, CMYK and GPU shape masks; release the pool when Split/Merge Channels close a document (#10479 review)

* fix: release the pool when a closed document's cancelled workers exit; idle-release switch for tests; don't pool PSD planes (#10479 review)

* fix: release the pool for workers cancelled before their document closes; take the pool lock for budget and idle-release changes (#10479 review)

* fix: idle release rechecks activity under the lock; try_take_exact releases the pool and retries before failing (#10479 review)

* test: cover a successful try_take_exact miss; name the failed-reservation test for what it checks (#10479 review)

* fix: pool the final GPU effect shape buffer and return it after use (#10479 review)

* docs: describe scratch pool lifecycle regression invariants

* test: verify polling releases cancelled document scratch buffers

* perf: recycle remaining transform selection and PSD scratch buffers

* fix: free PSD gather bands before allocating channel planes

* test: assert exact scratch take reuses pooled storage
2026-11-02 09:29:59 +01:00
Khawar Zamman Wani 97a83f074f Bound PSD layer and mask import memory before decoding (#10503)
* Bound PSD import pixel storage before decoding

* Include ZIP inflater workspace in PSD preflight

* PSD import: budget unknown-mode layers, stop after a fatal layer error, keep best-effort for non-allocation limits (#8593 review)
2026-11-01 12:33:09 +01:00
Khawar Zamman Wani 0ce7991aaa Merge origin/main into fix/8169-huge-tiff-open 2026-10-28 09:22:54 +05:30
David Mann 3a689f217c Merge remote-tracking branch 'origin/main' into HEAD
# Conflicts:
#	crates/engine/src/file_cmds.rs
#	crates/engine/src/retouch_cmds.rs
#	crates/engine/src/vector_cmds.rs
#	crates/io/src/psd_export.rs
#	crates/io/src/psd_import.rs
#	crates/io/src/smart_map.rs
#	crates/psd/src/layer.rs
#	crates/raster/src/lib.rs
#	crates/ui-egui/src/camera_raw_ui.rs
#	crates/ui-egui/src/canvas.rs
#	crates/ui-egui/src/filter_dialog.rs
#	crates/ui-egui/src/gpu_canvas.rs
#	crates/ui-egui/src/panels.rs
#	crates/ui-egui/src/retouch_ui.rs
#	crates/ui-egui/src/transform_tool.rs
#	crates/ui-egui/src/vector_ui.rs
#	docs/gaps.md
2026-10-27 14:26:26 +01:00
David Mann c14a707d2a Merge PR #6583: PSD/PSB open without reading the whole file: channel data read as decoded, in bands into tiles (#5106)
Merged at the fix-up commit before its main merge (362947695d); the
conflicts with the batch are resolved here: psd_import.rs keeps both
sides' tests, tiff_layers.rs takes ImageData::new.
2026-10-27 13:50:37 +01:00
Khawar Zamman Wani 720cd37518 Merge origin/main into fix/8169-huge-tiff-open 2026-10-27 09:28:53 +05:30
aiongg 84a9b585b4 refactor(raster): move lib.rs tests to tests.rs 2026-10-26 22:30:14 +00:00
Khawar Zamman Wani cdc3bdbd2f Merge origin/main into fix/8169-huge-tiff-open 2026-10-26 10:20:12 +05:30
Dylan M. Taylor 3877bb1dbe chore: resolve SonarCloud maintainability issues (#9044)
* chore: resolve SonarCloud maintainability issues

* fix: format imports and fix effect_entry argument type

* fix: restore test closure and wildcard import that broke compilation

* refactor: split composite_to_surface to reduce cognitive complexity
2026-10-25 19:38:31 -04:00
Phil TrinhandClaude Opus 5.5 4915f0970e PSD/PSB open without reading the whole file: channel data read as it is decoded, in bands straight into tiles (#5106)
Opening a 2.14 GB PSD (2000×2000, 109 layers, 821 MB of embedded smart objects) peaked at
7.28 GB and took 6.8 s; it now peaks at 3.00 GB and takes 3.6 s (macOS peak memory footprint,
`cargo run --release -p photocraft-io --example psd_open_mem`).

- photocraft-psd: `PsdFile::from_source` parses from a `ReadAt` source (`FileSource`: pread /
  seek_read in bounded reads). Channel data and the merged image become `Stored` ranges read
  when decoded; the model equals `from_bytes`'s and writes back the same bytes (tests compare
  the two on every generated file, including Lr16/Lr32 layer blocks and truncated files).
- `ChannelData::row_decoder` decodes any band of rows: RLE via its row table (a stored channel
  reads only the band's bytes), raw by offset, ZIP inflated once.
- photocraft-io: `import_file` opens a path; PSD/PSB through `from_source`, other formats read
  whole. Layers decode in bands of whole tile rows (~32 MB) into tiles: no whole-layer plane or
  interleaved buffer. Global blocks move into the document instead of being copied; finding an
  embedded smart object no longer copies every file in `lnk2`.
- photocraft-raster: `Surface::share_uniform_tiles` + `TileInterner`; the PSD import shares
  single-value tiles (backgrounds, fill caches, masks) across layers.
- The background open job and the CLI/MCP (`automation::files::open`) use `import_file`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 02:37:20 +08:00
Khawar Zamman Wani 43a6b30354 TIFF: refuse an image too large for free memory instead of being OOM-killed (#8536 review)
Limits::banded() lifted the 2^30 px cap, and the only failure left was a
tile allocation error. Linux overcommits, so the tiles were allocated
anyway and writing them had the out-of-memory killer end the app and
every open document. A valid all-black Deflate RGB8 TIFF declaring
100,000 x 100,000 px (30 GB of pixels) is a few tens of MB on disk and
passes the bomb guard.

- io memory.rs: memory::available() is MemAvailable plus free swap on
  Linux, capped by the process's cgroup v2 memory.max (and those above
  it) and memory.swap.max; None elsewhere (Windows refuses past its
  commit limit, which the importer already reports). check_fits refuses
  when the need plus a 512 MiB reserve doesn't fit.
- tiff_to_document checks the layer's tiles plus the working copies of
  one group before allocating anything: "not enough memory to open this
  100000 x 100000 px image: it needs about 41.7 GB and 7.8 GB is free".
- codecs TiffBands::group_bytes gives the largest group; a single-strip
  file is one group (the whole image), which the check now counts.
- TiffBands puts Truncated before MorePages, as the whole-image decode.
- raster: try_write_interleaved reports a wrong length as
  AllocationError::LengthMismatch { expected, got }, not SizeOverflow.
- Comments and docs no longer name another editor.

Tests: io a_tiff_larger_than_free_memory_is_refused (300,000^2 black
RGB8, Linux) was OOM-killed in a 4 GB cgroup without the check; memory
unit tests for the policy and the meminfo/cgroup parsing; codecs
a_cut_off_page_of_several_warns_in_the_whole_image_order and
group_bytes_is_the_largest_group_handed_over.
2026-10-25 06:55:51 +05:30