mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix/sec-oracle-diff-example
28
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
5585ad6407 | Merge remote-tracking branch 'origin/main' into pr-11577 | ||
|
|
b0f1fae496 |
Merge pull request #9323 from DuBearte/fix/8595-pcraft-memory-budget
fix(format): a .pcraft load's decode budget follows the machine's memory (#8595) |
||
|
|
453ea8c9ca |
[Extend XCF import into native PhotoCraft documents 1/6] Persist import conversion data and bounded native filter foundations
Imported documents need durable conversion evidence and native pixel operations before XCF conversion can produce editable PhotoCraft data. This adds bounded document/report types, lossless pattern construction and `.pcraft` persistence, plus native HDR, percentile, noise, convolution, Average, coverage and matting kernels and checked Smart-filter mixing. Runtime color models/depths are retained; source attachments remain inert. Native SVG operations retain parsing, lowering, rendering and parser-tree destruction on one bounded worker, including nested resources; WebAssembly reports a controlled error for depths requiring native isolation. Native filter corrections cover matte black points and signed HDR, extent-wide Smart-filter coverage, flat-image identity Auto Levels, opaque FillHoles capability, exact unselected channel preservation, coverage-preserving Average selection and bounded pattern expansion. Checked Smart-filter mixing rejects nonfinite native F32 samples, preserves unchanged Normal pixels without regenerating CMYK separations, and recovers representable alpha mixtures after an overflowing difference. HDR blend overflow retries use cold F64 arithmetic while retaining ordinary finite results and integer-depth behavior. Both opaque and alpha-bearing F32 mask recovery retain signed/HDR colors. Stored pattern declarations remain lossless and inert. Dense PSD/PAT/ASL pattern export now checks dimensions and one shared plane-allocation budget before conversion. PAT/ASL report conversion errors; PSD/PSB report named omission warnings. Matching raw PSD pattern blocks remain verbatim. CMYK offsets retain the established brightness convention. Command registration, XCF decoding and frontend workflows follow in dependent parts. The contributor entry is the author's existing chosen entry. <!-- native-foundations-fixes-20261107:start --> Small noise, convolution and point-operation edits admit their clipped work area on large owners while retaining output/workspace limits and whole-owner FillHoles bounds. HDR toning retains skipped transparent native samples. Normal Smart-filter strength interpolates stored CMYK/Lab/ink planes with premultiplied coverage, preserving unchanged channels. Bitmap Custom Pattern reads compact patterns in bounded row bands and ranks the complete map once. Embedded SVG isolation failures propagate independently of strict mode; ordinary invalid images can still be omitted, and private native parses share the complete-operation worker. The import-report regression now primes the layer blob cache and requires its specific limit diagnostic. <!-- native-foundations-fixes-20261107:end --> <!-- adversarial-5810371597:start --> Import-report accounting uses portable fixed costs. HDR scene means use F64. Bitmap pattern ranking preflights a 256 MiB input/order/output budget, uses fallible allocation and heap-scratch-free sorting. Average uses the supplied image domain and retains one global mean across output tiles. Non-Normal Smart-filter coverage is classified once across the complete mixing extent. A fallible filter dispatcher and engine error conversion preserve checked native diagnostics and cancellation. Smart-filter engine integration remains in part 5 (#11032). <!-- adversarial-5810371597:end --> ## Six-part series Each branch is hosted in Terra854/photocraft, and every PR targets storytold/photocraft:main. Merge in the order below. Later drafts currently show cumulative diffs while prerequisites are unmerged; their descriptions link to isolated comparisons. Rebase each part onto current upstream main after its prerequisites merge, including squash-merge ancestry, and rerun affected checks before requesting review. | Part | Upstream PR | Fork branch | Scope | | --- | --- | --- | --- | | 1 | [#11009](https://github.com/storytold/photocraft/pull/11009) | xcf-support-v2-01-import-data | Document/native-format data and pixel foundations | | 2 | [#11029](https://github.com/storytold/photocraft/pull/11029) | xcf-support-v2-02-decoder | Bounded transport/records, precision, metadata, editable text and paths | | 3 | [#11030](https://github.com/storytold/photocraft/pull/11030) | xcf-support-v2-03-effects-core | Native effect frames and primary tone/color/spatial/resource/transform adapters | | 4 | [#11031](https://github.com/storytold/photocraft/pull/11031) | xcf-support-v2-04-effects-graphs | Remaining adapters, bounded graph lowering, coverage installation and source evidence | | 5 | [#11032](https://github.com/storytold/photocraft/pull/11032) | xcf-support-v2-05-engine | Native commands, import preparation, historical choices, editing and persistence workflows | | 6 | [#11033](https://github.com/storytold/photocraft/pull/11033) | xcf-support-v2-06-frontends | Desktop/web UI, CLI/MCP, translations, GPU diagnostics and qualification/docs | The full integration remains preserved on `xcf-support-v2`; original #7098 remains available for reference. ## Validation <!-- main-catchup-0d08cb7dd:start --> Updated to upstream `main` at `0d08cb7dd` and restacked all six branches. Part 1 is `640a01f43`; full integration is `24cd17301`. The final six-part tree exactly matches the full integration tree. The merge preserves both upstream's new tests/crop translations and the XCF historical-open tests/report labels. The automation adapter now preserves import-source protection across multiple granted read roots: relative source names cover every matching candidate so newly shadowing files cannot expose the original to overwrite, while absolute source names remain precise. Existing ordered reads and implicit-save provenance are retained. Read-only import source identity is kept independently of whether its library root grants an implicit Save target. Focused regressions cover source aliases, removed files, denied candidates, changing root precedence, and read-only library imports; the Windows escape fixture also uses a real junction when symlink privileges are unavailable. The new upstream UI import fixture also uses the native import outcome type. Local validation passed affected host all-target checks, core and native frontend/automation unit and integration suites, forced-Vulkan GPU unit and integration suites, pinned IO corpora, strict all-target Clippy, formatting, layering, panel command dispatch, WASM, adversarial command tests, and the quick CPU performance harness. Offscreen historical-XCF prompt and conversion-report captures were reviewed. The first two PR boundaries also passed independent all-target engine checks. Tests used the pinned craft-fonts input, four Rayon workers, serial tests for large fixtures and opt-level=0 for engine/UI test glue; pixel/format crates retained their repository settings. Quick mode uses small documents and does not enforce full-size budgets. The part 1 push triggered fresh [CI](https://github.com/storytold/photocraft/actions/runs/42885527754) and [SonarCloud](https://github.com/storytold/photocraft/actions/runs/42885527740) runs. After upstream approval, CI passed the Linux gate, Windows unit/integration tests, no-HEIF tests, pinned corpora and web build. SonarCloud's instrumented archive, coverage shards and actual scan remain skipped behind its token guard; its outer green status does not mean coverage ran. Catching up with main therefore retriggered normal tests but did not remove that SonarCloud skip. Older validation below remains evidence for its explicitly named earlier commits. <!-- main-catchup-0d08cb7dd:end --> <!-- average-no-extent-4517477902:start --> Average no-extent follow-up at part 1 `f8ddb626f` (full integration `882def329`), carried through all six branches. The checked Average dispatcher now uses the requested `area` when no owner extent is supplied; an explicit extent retains its existing clipping behavior. Other filters, the Average pixel kernel and resource admission are unchanged. The new regression fails against the preceding revision and passes with the fix. It covers `apply`, one-pixel explicit tiling, and the cancellable tiled API at 8/16/32-bit, signed/HDR colors, hidden RGB, native alpha preservation, unchanged source data and pixels outside the requested area. Validation passed the algorithm unit/integration suite (935 tests; 27 existing ignored), strict all-target algorithm Clippy, formatting, layering, WASM (24 crates plus HEIF), and independent all-target engine checks of the first two PR boundaries. The broader suites below remain evidence for their named earlier commits and were not rerun for this dispatcher-only follow-up. <!-- average-no-extent-4517477902:end --> <!-- review-20261110:start --> Review follow-up at part 1 `a3144d559` (full integration `b5fd3e211`), carried through all six branches. Average admits long thin regions within its existing pixel/workspace budgets, clamps finite selection coverage, and uses owner extents for off-canvas replay. HDR Toning also adapts over the owner extent. Pattern GPU uploads now use bounded bands; the warning-free `document_to_psd` API returns `Result` on pattern export failure and reuses prepared pattern blocks. Warning-enabled exports retain explicit omission warnings. Five filter regressions fail against the previous revision and pass with the fixes. Local validation passed 1,597 algorithm/compositor/GPU tests with Vulkan, all 129 GPU integration tests separately on DX12 with FXC (the app uses FXC when no bundled DXC is present), a separate forced DX12 pattern upload/readback test, 1,144 IO unit and 675 pinned IO integration tests, 10 affected engine tests, strict all-target Clippy, formatting, layering, WASM and quick CPU performance checks. The first two PR boundaries passed independent all-target engine checks. This Intel driver's DX12/DXC configuration rejects the unchanged `fs_adjust` pipeline (`0x80070057`); DX12/FXC and Vulkan both pass. The full workspace suite was not rerun; earlier broad evidence below remains tied to its named commits. Quick performance mode does not enforce full-size budgets. A separate 24 MP signed/HDR RGBA32F public Average-kernel probe retained exact mean RGB and original alpha. Three alternating runs had medians of 1,274.713 ms before and 1,259.885 ms after; this small difference is within run variation and is not a speedup claim. The Minor/Poor-tradeoff report-deserialization finding remains open and documented. Encoded records are capped at 32 MiB and individual arrays are bounded, but compact targets can still amplify transient decoded memory before aggregate validation rejects the report. Early shared-budget deserialization is not implemented in this follow-up. <!-- review-20261110:end --> <!-- main-catchup-7c64653d5:start --> Updated to upstream `main` at `7c64653d5` and restacked all six branches. Part 1 is `cbf068d5f`; full integration is `206f71012`. The full integration tree exactly matches part 6. The merge retains main's alpha-preserving Average behavior with bounded checked processing, and uses it consistently for XCF coverage conversion and native replay. Historical XCF normalization and import preparation now run through main's resumable Place flow and Open as Smart Object; regression tests cover source byte order and native Edit Contents. XCF report/filter labels also cover the seven languages main promoted to menu-complete status. The current tree passed affected host all-target checks, core/IO, GPU, engine and frontend suites, strict all-target Clippy, formatting, layering, panel command dispatch, WASM and the web build, adversarial command tests, pinned IO corpora and the quick CPU performance harness. Offscreen historical-XCF prompt and conversion-report captures were reviewed. The first two PR boundaries also passed independent all-target engine checks. Tests used CI-pinned craft-fonts `b076417b5880bd4154bd22f00695b1d28c6bea83`, four Rayon workers, serial tests for RAM-heavy suites and opt-level=0 for engine/UI test glue; pixel and format crates kept repository settings. Quick performance mode uses smaller documents and does not enforce full-size budgets. Older measurements below remain evidence for their named earlier commits. <!-- main-catchup-7c64653d5:end --> <!-- percentile-owner-4502952267:start --> Percentile owner-bounds follow-up at part 1 `93946db04` (full integration `f7264af14`): nonempty owner bounds now supply edge samples without a dense whole-owner admission check. The unchanged preflight still bounds clipped output, padded halo, workspace and CPU work; dense-image adapter limits remain in place. Two new regressions failed with `InvalidGeometry` before the fix and pass afterward, covering small edits on 81 MP and wider sparse owners, clamped-edge oracles, fractional selections, source preservation, clipped requests, invalid domains, oversized output, work limits and cancellation. This follow-up passed 903 algorithm tests (887 unit + 16 integration; 27 existing ignored), all-target strict algorithm Clippy, formatting, layering and WASM (24 crates plus the HEIF configuration). Only sampling-bound admission changed; percentile processing and resource-preflight code are byte-for-byte unchanged. The broader qualification below remains tied to its explicitly named earlier commits; the full workspace suite was not rerun for this one-file follow-up. <!-- percentile-owner-4502952267:end --> <!-- native-foundations-validation-20261107:start --> The production fixes at part 1 `c16e274b8` (full integration `6f8349cd5`) passed 7,245 affected algorithm/compositor/document/engine/native-format/IO tests across 46 binaries, with 65 existing ignored tests, plus doctests, affected all-target strict Clippy, layering, WASM, adversarial command tests, formatting and the pinned IO corpus (1,107 unit + 661 integration tests, 26 existing ignored). The final diagnostics regressions also passed independently on the foundation and full integration branches. The first PR passed an independent all-target engine check. Tests used four Rayon/test workers and the existing CI font pin; engine test glue used opt-level=0, and the foundation-only diagnostic probe also used opt-level=0 for its algorithm dependency. The full integration tree exactly matches the final sixth branch. Paired 24 MP release probes used three timed repetitions per version after warm-ups, alternating order, matching inlining controls, opaque parameters and a current public-API control, with four Rayon workers. Timings are completed operations on this host. | Probe | Before (ms) | After (ms) | Public API (ms) | | --- | ---: | ---: | ---: | | HDR toning | 830.3 | 834.4 | 791.2 | | Rgb-Normal | 1070.5 | 1069.3 | 1079.7 | | Cmyk-Normal | 683.0 | 669.7 | 691.5 | | Rgb-Multiply | 1103.1 | 1303.3 | 1297.5 | The extent-wide coverage prepass adds 200.2 ms (18.2%) in the alpha-preserving Multiply case. This is the measured cost of applying one consistent coverage rule; the Normal RGB/CMYK controls remain near baseline. The uniform HDR probe's middle-gray output changed from 0.200004 to 0.180000 (target 0.18); the public control agrees. Mixer probes check native colors and alpha at sampled positions. The quick CPU application harness also completed; its saved cross-machine comparison was skipped, and quick mode does not apply full-size budgets. No budgets or baselines changed. <!-- native-foundations-validation-20261107:end --> Earlier validation of full integration `c003e3f50`, before these follow-up fixes, completed the upstream `main` catch-up at `c101cbfb7` on 2026-11-07. The cumulative series passed affected host all-target checks, foundation and IO suites, GPU, engine and frontend suites, strict Clippy, layering, WASM, adversarial command tests, formatting, pinned IO corpora and the quick CPU performance harness. Offscreen historical-XCF prompt and conversion-report captures were reviewed. Local tests used CI-pinned craft-fonts `b076417b5880bd4154bd22f00695b1d28c6bea83`, four Rayon workers and temporary opt-level=0 overrides for engine/UI test glue; pixel and format crates retained repository settings. The full UI library passed 5,330 tests, and the final dialog-dispatch cleanup passed 945 focused dialog tests. The decoder and engine PR boundaries also passed independent all-target checks. The full `xcf-support-v2` integration tree matches the final sixth branch exactly. SVG stack regressions retain their 512 KiB caller, isolated complete native lifecycle and 100 retained group levels. The matched performance figures below were measured before this main integration; the HDR recovery arithmetic and bounded tile implementation are preserved. Forward filter-mask mixing retains its existing four-buffer allocation optimization and arithmetic. Its matched 24 MP RGBA32F probes measured opaque pixels at 392.410→182.842 ms, semitransparent pixels at 383.321→179.916 ms, and signed HDR pixels at 373.696→183.903 ms (five-run medians, 50–53% faster). Inverse filter-mask recovery now processes at most eight native tiles in parallel, with four reusable scratch buffers per slot and ordered surface publication. Small inputs, one-worker operation and WebAssembly use the same serial tile helper. All F64 and integer pixel arithmetic is unchanged. Bitwise regressions compare full/partial/missing tiles, negative coordinates, differing defaults and hidden/zero-alpha outputs across 30 format combinations; an explicit one-worker/two-worker comparison checks both execution paths. Matched 24 MP HDR inverse-recovery public-API probes measured 166.972→90.565 ms (opaque, 45.8% faster), and 433.325→130.707 ms (semitransparent, 69.8% faster). Five-run medians use four Rayon workers on this host; all runs assert recovered HDR samples at three positions. The existing F64 precision and HDR saturation bounds are preserved. Mask recovery retains signed/HDR colors, extreme finite values, subnormals and exact full coverage. The PSD/PSB regression uses a real blur on spatially varying HDR pixels and partial masks; raw exported channels must match the unmasked filter result, and reimported Smart caches must match independently authored masked values. The prior quick CPU application harness completed. Its saved cross-machine baseline comparison was skipped, so the paired public-API measurements above provide the direct before/after evidence. No performance budgets or baselines changed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added image adjustments and filters for averaging, channel noise, convolution, percentile effects, alpha and coverage editing, black matte removal, HDR toning, and automatic tone, contrast, and color correction. * Added Smart-filter blending controls for opacity and blend modes. * Import-conversion information is preserved when saving and reopening documents. * **Improvements** * Improved handling of deeply nested SVGs and large patterns, with bounded pattern processing and warnings when pattern export is not possible. * Improved stability when blending extreme HDR values and applying filters to HDR images. * Improved transparency handling for channel-selective filters and added clearer feedback when image processing or export cannot be completed. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
7426cb9858 |
fix(format): a .pcraft load's decode budget follows the machine (#8595)
LoadOptions::default took the format's 16 GiB total-bytes limit on every machine, so a small bundle of nearly empty, highly compressed tiles could ask for far more than the machine has. The default is now that limit lowered to the available RAM plus the scratch disk's room (decoded tiles spill there as memory fills), never below 1 GiB, and unchanged where neither is known. It uses photocraft_raster's own memory and scratch measurements; no new dependency. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
9bcb6776ec | Separate bounded reads and exclusive file publication | ||
|
|
316e00a97e |
Bound Photomerge memory and safely reject out-of-budget jobs (#7851) (#10463)
* Reduce Photomerge input and fill memory * Bounded working-memory budgeting and safe allocation for Photomerge * Photomerge memory: estimate warped sizes, no RAM ceiling, shared RAM detection - Budget is half of physical RAM (at least 1 GiB) with no 8 GiB ceiling. - The pre-flight estimate uses each image's warped extent and the band grid's exact bound (band_bytes_bound), at the levels seam_blend uses. - Auto-Blend keeps its old batching with no single-band cap. - multiband returns a Result instead of a blank image on failure. - Physical-memory detection moves to photocraft_engine::memory; the GPU budgets reuse it, so PHOTOCRAFT_RAM_MB means the same in both. - Document memoryBudget; restore comments; tests for the band cap and the budget precedence. * Photomerge: lower the blend's peak and estimate it by phase - The band build makes its binary coverage straight from the alpha and writes each Laplacian level in place, so a band holds two fewer planes. - The weight sums are freed before the collapse, which adds each level in place and frees it as it goes. - The estimate is the largest phase (warp, ROIs, bands, collapse, output, fill) rather than the sum of all of them, and the bands get what is left of the budget after the ROIs and accumulators. Every output pixel is unchanged: each change drops a plane or does the same elementwise operation in place. * Fix Photomerge band budget validation and fallible pyramid allocation * Keep reference pyramid test helpers infallible * Photomerge: bound source loading with the memory budget Resolve the budget before any source is read, and admit each flattened source before its surface is allocated. The accounting charges the retained surface, the same-canvas temporary the flatten writes while the source document is alive, and a file import's encoded bytes, with saturating math so an overflow cannot wrap under a finite budget. Merge to HDR Pro passes no budget and keeps its previous behaviour. Tests cover the exact retained-plus-temporary charge, a refused source, the within/over-budget command paths, the post-load estimate path, and the unbudgeted HDR loader. * Photomerge: bound source reads and imports by the remaining budget Read each source file with what is left of the budget as its limit, lower the importer's own PSD/TIFF preflight or the flat decoders' pixel allowance to the remainder after the retained sources and encoded bytes, and refuse formats with no pre-decode estimate. Charge the decoded document's actual pixels (every layer) plus the flatten's working and output surfaces before flattening. Merge to HDR Pro keeps its unbudgeted read-and-import path. * Remove redundant TIFF decode options update * Clean up Photomerge budget Clippy findings * Accept early decoder admission in source budget regression * Photomerge: report unreadable sources as file errors; never reserve past a read limit - A budgeted Photomerge reported a missing or unreadable source file as 'not enough memory'. Only a file over the remaining budget, or one memory cannot hold, is a memory error now; others are file errors, as without a budget. - read_all_with reserved a whole read chunk before checking the caller's limit for a file that grew after it was statted. It now refuses first and caps the reservation at the limit. --------- Co-authored-by: FredApps <[email protected]> |
||
|
|
37a01ca874 |
format: bound blob inflation by the load's remaining budget; browser budgets (#10984)
LoadFetch::blob_bounded decompressed a new blob up to max_blob_bytes and only then charged it against max_total_bytes. Successful blobs are retained, so several distinct, highly compressible blobs each allocated a full max_blob_bytes before the total was checked. A new blob may now inflate only to what the total budget has left. The browser build loaded native documents with the desktop defaults (1 GiB a blob, 16 GiB in all), far beyond a wasm32 instance's 4 GiB of linear memory that the editor also uses. On wasm32 the defaults are now 512 MiB a blob and 1 GiB in all. |
||
|
|
05fc07b538 |
Merge main into fix/save-memory-6607
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. |
||
|
|
fef15729aa |
Merge main into feat/pcraft-full-composite
Main now takes the manifest envelope from craft-pcraft-format, which has no full_composite member. The save writes the member after the envelope when it writes composite/full.png, and read_full_composite reads it back. |
||
|
|
289dd0a874 |
Format: take the .pcraft envelope from craft-pcraft-format (#10724)
* Format: take the .pcraft envelope from craft-pcraft-format The manifest envelope, TileRef, Hash, FORMAT_VERSION, EXTENSION, the entry names, tile_path and blob_path, is_valid_hash, the manifest nesting and item checks and the migration runner now come from craft-libs' craft-pcraft-format. photocraft-format re-exports them, so callers do not change. Manifest is craft_pcraft_format::Manifest<DocM>. Saved bundles keep the same bytes. A save still checks only the nesting and the item count of its manifest, not its size, and the manifest nesting limit is still computed from photocraft_doc::MAX_GROUP_DEPTH. Tests: a save, load and save again gives the same bytes in every color mode and depth, with and without previews; MAX_GROUP_DEPTH equals craft_pcraft_format::MAX_GROUP_DEPTH. * Format: pin craft-pcraft-format from storytold/craft-libs * Format: read manifests with craft-pcraft-format's read_manifest_with Pins craft-pcraft-format to dca870a0, the head of craft-libs #407. Loading reads the manifest with read_manifest_with, which runs the limit check, the version check, the migration steps and the envelope read in one path; the layers are still decoded one at a time after the rest of the document. A save builds the manifest with Manifest::new and tile references with TileRef::new, and the bundle's directory names and the .zst suffix come from the crate's constants. Saved bytes and error messages are unchanged. * Format: pin craft-pcraft-format to craft-libs #407's head 04dd1bd 04dd1bd changes only the crate's docs and a test, so photocraft-format builds the same code. * Format: pin craft-pcraft-format to craft-libs main at b8f7d93 craft-libs #407 merged as b8f7d93. Its read_manifest also refuses a thumbnail other than thumb.png and a composite other than composite/preview.png, the only names photocraft-format writes. |
||
|
|
ddd11aaa9a |
Format: a full-size composite that fails is left out, and pcraftFullComposite takes only booleans
- The PNG encoder gets a fallibly reserved copy of the composite's pixels instead of a clone, and a full-size composite that cannot be copied or encoded is left out of the ZIP or directory bundle and out of its manifest; the save goes on without it. - The ZIP size limit for keeping the full-size composite counts the central directory and end record as well as the entries. - `pcraftFullComposite` that is not true, false or null is a bad parameter of `file.saveACopy`, the other engine saves and the automation `doc.save`. - MCP `doc_save` in bridge mode refuses `pcraftFullComposite: false` as well as `true`. The app's `app.save` does not take the option. |
||
|
|
b527b5062a |
Save the flattened document at full size into .pcraft files as an option
A .pcraft bundle holds the flattened document only as thumb.png (at most 256 px) and composite/preview.png (at most 1024 px). A new option also writes composite/full.png: the flattened document at its canvas size, an 8-bit RGBA PNG made like the two previews, with the ICC profile of its pixels embedded. The option is off by default, and a save without it writes the same bytes as before. - Preferences > File Handling > Save Full-Size Composite in .pcraft Files sets it for the app's Save, Save As and Save a Copy, in the desktop and web builds. - The engine's file.saveACopy and its batch and export commands take "pcraftFullComposite" (unset, the preference), the automation doc.save and MCP doc_save take "pcraftFullComposite": true, and photocraft-cli convert, run and batch take --pcraft-full-composite. The manifest names the image in a new optional member, full_composite; the format version stays 1, and bundles without it open as before. A canvas over 2^30 pixels, or one whose pixels cannot be allocated, is saved without it, and so is a ZIP bundle that it would take past 4 GiB or 65,535 entries. |
||
|
|
ec6a4c1a50 |
Save: stop doubling the encoded file in memory (#6607)
Saving needed about 4x the file's size in extra RAM: the whole encoded file was buffered in memory before it hit the disk. Now PSD/PSB and layered TIFF stream into the destination as they are encoded. - format: atomic_write_stream_progress hands the encoder a writer that goes through the temp file, so bytes are freed as they are written; ZipWriter reserves the estimate only where output can exceed it, and gives back the unused part of a reserved buffer after compressing. - psd: PsdFile::save streams layer by layer (ImageSourceData::take_from_psd moves rather than copies), and the TIFF encoder writes rows out as they are compressed instead of holding the uncompressed plane. - io/codecs: layered TIFF export streams the interleaved composite, the app's save and export paths pass a progress callback through the stream. A 24 MB PSD/PSB or layered TIFF now saves with a few MB of working set instead of a second copy of the file; on wasm32 the memory is returned, on Windows it is no longer counted as committed. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
d658c13c4e |
fix(format): serialise directory bundle saves with a bundle-wide lock
A directory save lists the existing objects, writes its own, publishes its manifest and removes what that manifest doesn't reference. Two writers (two stores, or two processes) saving the same bundle could interleave, and one writer's cleanup could remove an object the other's winning manifest needs. Each save now holds an OS advisory lock on save.lock for its whole transaction; a held lock is waited for (10 s by default, PcraftWriter::set_lock_wait), then the save fails without writing. A crash releases the lock; a file system without file locks saves unlocked as before. Fixes #4957. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
bea81c2f3d |
Save: show save progress as Saving NN% in the status bar and tab title (#3389) (#3485)
Background saves only ever reported 0 % ("Encoding", then "Writing"), because
photocraft_io::export produced all the bytes in one call: the status bar showed an
indeterminate bar and no percentage. Now:
- photocraft_io::export_with(doc, name, opts, &Interrupt) reports encoding progress
(export keeps its signature and calls it with Interrupt::NONE, same bytes): PSD/PSB
per layer record and per composite band, layered TIFF the same plus its encoder
stages, .pcraft after its previews, flat formats once the composite is rendered.
Cancelling stops the conversion early and returns IoError::Cancelled.
- photocraft_format::atomic_write_progress writes in 8 MiB chunks and reports the
fraction written.
- The desktop save maps encoding to 0..85 % and writing to 85..99 %, 100 % once the
file is flushed and renamed.
- The status bar reads "Saving 45%" for a save (file name on hover), and the
document's tab title gets " - Saving 45%" in both tab strips, as in Photoshop.
Percentages round down so 100 % only shows when done.
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
|
||
|
|
6e9ba6511d |
Format: admit the declared .pcraft canvas before loading it (#2935) (#3295)
* Format: admit the declared .pcraft canvas before loading it (#2935) A .pcraft manifest's canvas size was copied into the Document unchecked, so a few bytes of JSON could declare a 300000x300000 (or u32::MAX) canvas that the CPU reduction, thumbnails and display textures then work against in proportion to its area. The loader now refuses an empty canvas, a side above 300000 (Photoshop's PSB limit, as for PSD and file.new) and an area above 4 gigapixels, right after reading the manifest and before any tile or blob is decoded. Both limits are LoadOptions fields so trusted callers can change them. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Format: admit every canvas the app can create on .pcraft load (#2935) The default pixel budget was 2^32 (65536 x 65536), but file.new, Canvas Size, Image Size with Resample off and PSB import all reach 300000 x 300000, so a document a user could create and save would not reopen. The default is now the full 300000^2 PSB canvas; the side limit still refuses anything larger, and callers handling untrusted files can lower either budget. Loading stays proportional to the file: layers keep only the tiles the bundle holds, so a huge declared canvas allocates nothing for its area. A compile-time assert in document_preset_cmds ties file.new's MAX_DIMENSION to the loader's defaults. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
60339cf675 |
app.open: open directory .pcraft through the automation read root (#2490) (#2581)
* app.open: open directory .pcraft through the automation read root (#2490) The native on-disk format is a directory, but the automation read path serves regular files only, so agents could not open the files the app itself writes. The format crate's storage seam is now public (ByteSource + load_bytes_source); the workspace opens the .pcraft subdirectory through the held capability and loads through it. app.open tries the directory form for .pcraft paths and falls back to the bytes path for the single-file (zip) form; every other format is unchanged. * app.open .pcraft: review fixes (#2581) read_entry now bounds the read itself (the stat length is only a buffer hint) and both directory sources reject non-regular entries, so a crafted bundle with a FIFO entry can no longer block the open and stream unbounded. The desktop opener runs under the crash guard like its import sibling, the zip fallback is structural (Ok(None) instead of an error-message match), a directory-form document no longer arms a save-back target the file-only automation writer could never replace, and the open status is translated (Opened {name}, 16 locales). * read_entry: saturating max+1 so a usize::MAX budget can't overflow Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Brandon Thomas <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
9e6bfdc76c |
fix(format): refuse to save a document holding a NaN or infinite float (#1101) (#1172)
serde_json writes a non-finite float as `null`, and the manifest's plain
`f32`/`f64` fields refuse `null` on load. So a document that picked one up
(a PSD `expA` block, a descriptor double) saved and autosaved with a success
report, and every later open failed with `manifest JSON: invalid type:
null, expected f32`. JSON has no spelling for these values, so the save is
refused instead of writing a file that can never be read back.
`finite::check` walks the manifest with a serde `Serializer` that produces
nothing and fails on the first non-finite float, tracking struct fields,
sequence indices, variants and map keys so the error names the value
(`document.layers[2].content.adjustment.exposure`). `PcraftWriter::prepare`
runs it before serialising, so one-shot, incremental, directory and
autosave saves all share it. New `FormatError::NonFinite { path }` with an
actionable message.
Tests: unit (`finite_values_pass_and_each_position_is_named`: each
container kind reports its path) and integration
(`a_non_finite_float_is_refused_at_save_rather_than_breaking_every_later_load`:
NaN/-inf in an Exposure layer and +inf in `resolution_dpi` are refused with
the field named, through both `save_to_bytes` and `PcraftWriter`, and the
finite document round-trips as before). The integration case was the
issue's repro: on main it saved and failed to load.
Co-authored-by: wstock <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
|
||
|
|
b6f5df3b3f |
pcraft directory saves: re-verify a rolling share of cached objects; stronger file signature (#821)
Follow-up to #752. After a directory save verifies an object, later saves trust it while its file signature is unchanged. A file damaged in place with the same length and modification time (bit rot, or a tool that restores timestamps) was trusted until the writer was recreated. - The signature also carries inode, device and change time on Unix, which an in-place rewrite changes even when the modification time is restored. - Each directory save re-reads and re-checks cached objects, oldest-checked first, up to DEFAULT_REVERIFY_BUDGET (16 MiB of compressed data; at least one object), so over enough saves every object is read again and a damaged one is rewritten. Repeat saves of small documents stay a full check; large ones pay a bounded cost per save. PcraftWriter::set_reverify_budget tunes it (0 = trust signatures, u64::MAX = check all). - PcraftWriter's doc comment states what the cache trusts. - Tests: a same-size, same-mtime tamper is repaired on the next save (fails with the budget at 0 on Windows, where there is no change time), and with a 1-byte budget the rolling re-check reaches the damaged object within one pass over the objects. Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
1b24b5212b |
Repair corrupt directory-save objects (#752)
* Fix directory save reuse of corrupt objects Co-authored-by: Copilot <[email protected]> Copilot-Session: e77cd34a-ce3e-4981-996f-4d37d49df90d * Avoid revalidating unchanged directory-save objects Co-authored-by: Copilot <[email protected]> Copilot-Session: e85c024b-ace5-4415-9208-b8d4e4684505 --------- Copilot-Session: e77cd34a-ce3e-4981-996f-4d37d49df90d Copilot-Session: e85c024b-ace5-4415-9208-b8d4e4684505 |
||
|
|
a8afec4455 |
Open documents in bounded reads, with a clear out-of-memory error (#375) (#401)
Every open path read the whole file with std::fs::read, which asks Windows for up to 4 GiB in a single ReadFile. Some file systems (exFAT, network redirectors) reject a read that large with ERROR_INVALID_PARAMETER, "The parameter is incorrect" (os error 87), as reported for a 4.75 GB PSB in #375. Add photocraft_format::read_file and read_all beside atomic_write: 64 MiB reads into a buffer reserved up front, and an OutOfMemory error that says how much the file needed. Route every document read through them: - the background open job (engine jobs.rs read_path); - the engine's read_file; - Open Recent and OS open events; - desktop drag and drop, which now goes through open_path (and so through the background job when jobs are on); - the File > Open dialog; - .pcraft loading; - the automation workspace read and automation::files::open; - smart object Replace Contents and linked files. The dialog no longer fails silently: PickOpenFn returns the picked name with the read result, and a failure is reported through open_failed and the notices like any other open failure. Speed is unchanged (1.11 s vs 1.13 s for a warm 4.75 GB file). Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
2868220032 |
Formats: deep .pcraft groups reopen; zero-size PSD rejected; JPEG mattes over white; no-ICC formats get sRGB (#517, #519, #521, #522) (#555)
* PSD: reject a header with zero width or height (#519) A 0xN header opened as an empty document and saved back as another zero-sized PSD or .pcraft. Header::validate now requires at least 1x1 (the spec range starts at 1), and PSD export validates the header so a zero-sized canvas is never written. Co-Authored-By: Claude Opus 5.5 <[email protected]> * .pcraft: documents with deeply nested groups load again (#517) serde_json's 128-level recursion limit made bundles with 40 or more nested groups unreadable after a successful save. The manifest is now parsed with that limit disabled behind a linear JSON depth check, layers are decoded and converted one level at a time with small stack frames, and groups may nest up to MAX_GROUP_DEPTH (100) levels, which load and save within a few hundred KiB of stack. Saving a deeper document fails instead of writing a bundle that can't be opened. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Export: convert non-sRGB RGB to sRGB for formats without a profile (#522) GIF, BMP, QOI, TGA, ICO and Netpbm can't embed ICC, so a linear-light or Display P3 document was written with values that only meant something under the dropped profile (a linear EXR came out dark). export_flat now converts such RGB to sRGB through photocraft-cms (perceptual, as Quick Export does) for every photocraft_io::export route. The EXR/HDR linear conversion shares the same banded helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Export: composite transparency over white for formats without alpha (#521) The CLI, MCP, Save As, Layers to Files and Layer > Export As dropped the alpha channel when writing JPEG (or Radiance HDR), exposing the colours stored under transparent pixels, while Export As and Quick Export composite over white. export_flat now flattens over white too (no ink for CMYK) and says so in its warnings. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
bd1322a5e4 |
Recovered documents keep their recovery data until saved or closed (#444) (#549)
Launch no longer deletes recovery entries right after loading them. A recovered document adopts the entry it came from: its next autosave replaces it in place (atomically) and saving or closing the document removes it, so a second crash before the next autosave loses nothing. New documents autosave under per-launch keys, so a document id reused from an earlier launch never overwrites a surviving entry, and sidecars whose key doesn't match their file name are ignored. Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
82270711de | Atomic saves: one crash-safe atomic_write for every document write (#230) (#230) | ||
|
|
28a63fe27e | fix(io): recognize reordered PhotoCraft archives (#137) | ||
|
|
69f0e25d5f |
Never crash: psd, codecs, format, io are panic-free (Rule 9) (#34)
- codecs: bump tiff 0.10 -> 0.11. tiff 0.10 indexed an empty SampleFormat list and panicked on a crafted TIFF (found by mutation fuzzing); regression test tiff_empty_sample_format_is_an_error. - codecs: Image::new returns Result instead of panicking on size overflow. - format: par_compress returns an error if a compression worker panics. - io: par_map joins every worker before relaying a worker panic, so the thread scope can't panic on an unjoined thread. - All four crates now deny unwrap/expect/panic/unimplemented/todo/ unreachable outside tests. Co-authored-by: Claude Opus 5.5 <[email protected]> |
||
|
|
f7eb6ea9e7 |
Format: adopt the craft-family rustfmt.toml and format the workspace
CI's `cargo fmt --all -- --check` has failed on every run because the repo had no rustfmt config and was never formatted. Use the same settings as EffectCraft/FilmCraft (max_width 160, use_small_heuristics Max), which also keeps the churn small. Formatting only; no code changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
ae92ac20bf | continued wip |