Extract PhotoCraft guide framing from 2aa88b0956; leave rounding and document ordering with callers. Add fixed-byte and hostile-prefix coverage.
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
Adapt PhotoCraft parse_guides from 16941f7198, retaining signed-position semantics from 1a54384d80. Allocation-free framing preserves complete-prefix recovery.
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
from_bytes still requires the slice to be fully consumed. parse_prefix
returns the descriptor and the number of bytes used, matching
VersionedDescriptor, so apps can read a descriptor that is followed by
more data (layer effects, fill and adjustment blocks).
Part of #778 and effectcraft#786.
Extract framing from PhotoCraft 16941f7198da9ae1811a8928f4c256b5cb37c1cb, retaining the overflow protection added by 3b45e8baee7117e53847523b5bc3ae2b337966d4. Allocation-free adaptation leaves text policy with callers.
Co-authored-by: Valentin Klein <vangel1976@googlemail.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
Port raw framing from PhotoCraft f7f8fdcd89 and 9a390661b5; preserve tolerant import semantics and keep colour policy with consumers.
Co-authored-by: Khawar Zamman Wani <wanikhawar@gmail.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
Extract the fixed layout from PhotoCraft 772cf39c09930229e11b920196f486239bbbfab8, incorporating alternate-colour handling from 2d7c62055ee47497f8cb77bbdfd3befa29718f4a. Keep document colour/curve policy out of the codec.
Co-authored-by: David Mann <daaavid.mann@gmail.com>
Preserve transform safety work and compatibility recovery; adapt to shared array geometry and add regression tests.
Co-authored-by: David Mann <daaavid.mann@gmail.com>
Co-authored-by: Sean Lavery <Theseanlavery@gmail.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
* craft-psd: Photoshop PSD/PSB reader and writer, moved from PhotoCraft
PhotoCraft's `photocraft-psd` crate (crates/psd at storytold/photocraft
63b641b55e54bf8f5c83efd977fdb16a2c255431) as `craft-psd`: the lossless
PSD/PSB model, reader, writer and builder, descriptors, the Photoshop
resource files that share its primitives (.abr, .asl, .aco, .act, .ase,
.grd, .pat, .atn, .csh, .shc) and the Photoshop blocks of a layered TIFF.
The crate had no dependency on any other PhotoCraft crate.
Code is unchanged apart from the crate name, craft-libs' rustfmt width,
comments that named other PhotoCraft crates, issue references (now
`photocraft#N`), and the corpus tests' directory (`CRAFT_PSD_CORPUS` or
`corpus/` at the workspace root). Tests, proptests, fuzz targets and
fixtures move with it.
Part of #778, #786.
* craft-psd: engine_data, the text engine document of type layers
The EngineData reader and writer from PhotoCraft's photocraft-text
(crates/text/src/engine_data.rs at storytold/photocraft 63b641b5): a
tree of values that is written back in Photoshop's layout, with strings
stored as plain bytes kept as plain bytes.
From EffectCraft's effectcraft-psd (crates/psd/src/engine_data.rs at
storytold/effectcraft 072e1af9), ported onto that tree: `first_style`,
the first style run as a typed `TextStyle` with bounded sizes and
spacings, and `minimal`, a one-run document for writers and fixtures.
`Value::index` is new.
Both apps had their own parser for the same syntax.
* craft-psd: engine_data::parse_lossy reads what it can of a damaged document
EffectCraft's EngineData reader was best effort: a truncated or damaged
document still gave the text and style it held. `parse_lossy` does that
on the same parser: a truncated dictionary, array or string keeps what
it has, a byte that starts no key is skipped, a token that is no number
becomes a name, and garbage gives an empty dictionary. `parse` stays
strict and is unchanged in what it accepts.
The parser's `value` is split into one function per kind of value, and
reads with `get` instead of indexing.
* craft-psd: typed views of type layers, smart objects and adjustments
Read-only views EffectCraft's effectcraft-psd had over the blocks this
crate keeps raw (storytold/effectcraft f334bcf3, crates/psd/src/parse.rs
and placed.rs). The blocks stay raw and write back unchanged.
- `text`: `TypeLayer` from `TySh`: text, transform (the identity when not
finite), bounds, the first style run (read with
`engine_data::parse_lossy`) and the text descriptor.
`LayerRecord::type_layer`.
- `smart`: `SmartObject` from `SoLd`/`SoLE` (id, quad, non-affine
transform, size, warp) and `PlLd`; `Warp` with the named styles and the
custom quilt mesh; the quad geometry (`map`, `placed_bounds`,
`placed_size`, `bake_scale`, `placement`). `LinkedFile` and
`linked_files` for `lnk2`/`lnkD`/`lnk3`/`lnkE`, `PsdFile::linked_files`
and `PsdFile::linked_data`. `LayerRecord::smart_object`.
- `adjust`: `Adjustment` from `nvrt`, `brit`, `CgEd`, `hue2`/`hue `,
`levl`, `expA`, and the other adjustment keys by name;
`LayerRecord::adjustment`, `solid_color` (`SoCo`) and `effects` (`lfx2`).
- `Descriptor`: `object`, `number`, `numbers`, `boolean`, `text`,
`enumerated`, `raw_data`, `color`; `Value::as_number`.
Linked-file data is a range of the block's data, checked against the
record, instead of a range of the whole file.
* craft-psd: shared descriptor lookups
Descriptor::get_bool, get_number, get_text, get_enum and get_object,
used by asl, grd and slices in place of their own copies.
Ported from storytold/photocraft#9552 (its crates/psd part).
* craft-psd: the typed views use the shared descriptor lookups
One set of Descriptor accessors: the get_* lookups from photocraft#9552.
numbers, raw_data and color move next to them as get_numbers,
get_raw_data and get_color.
* craft-psd: linked-layer record editing, the thumbnail header and brst
Format code that PhotoCraft keeps in crates/io (linked.rs,
psd_thumbnail.rs, blocks.rs at storytold/photocraft f1b5e7d7), moved
here without the document mapping:
- smart: `file_type`, `encode_embedded_file` (a version-7 liFD record),
`linked_records`, `linked_uuids`, `rebuild_linked_block`,
`select_linked_records` (exact UTF-8 ids, cut selected records are an
error), `contains_linked_record`, `copy_linked_record`.
- resources: `Thumbnail` reads the 1036/1033 header, and
`Thumbnail::jfif_bytes` writes it as Photoshop does.
- tagged: `channel_restrictions` / `channel_restrictions_data` for brst.
PhotoCraft's tests for these functions move with them.
* craft-psd: write SoLd and PlLd from the placement types the reader gives
From PhotoCraft's crates/io/src/smart_map/placed.rs (storytold/photocraft
f1b5e7d7), on craft-psd's `SmartObject` and `Warp`: the caller works out
the quad and the warp from its own geometry.
- `SmartObject::to_placed_layer_data(&PlacedLayerOptions)` writes `SoLd`:
a fresh descriptor in Photoshop's key order, or the imported one
(`template`) with only the placed id, the transform (when the quad
moved), the warp and the filter stack rewritten.
- `SmartObject::to_placed_layer()` writes `PlLd` (plcL version 3).
- `Warp::to_descriptor`, `Warp::quilt_descriptor` (a split custom warp,
`quiltWarp`) and `Warp::mesh_is_valid`.
The reader now takes `quiltWarp` before `warp`, and patch boundaries
stored as an object array, as Photoshop writes them, so a split warp
reads back.
---------
Co-authored-by: Omar Saidahmed <osaidahm@uwaterloo.ca>
* craft-psd: Photoshop PSD/PSB reader and writer, moved from PhotoCraft
PhotoCraft's `photocraft-psd` crate (crates/psd at storytold/photocraft
63b641b55e54bf8f5c83efd977fdb16a2c255431) as `craft-psd`: the lossless
PSD/PSB model, reader, writer and builder, descriptors, the Photoshop
resource files that share its primitives (.abr, .asl, .aco, .act, .ase,
.grd, .pat, .atn, .csh, .shc) and the Photoshop blocks of a layered TIFF.
The crate had no dependency on any other PhotoCraft crate.
Code is unchanged apart from the crate name, craft-libs' rustfmt width,
comments that named other PhotoCraft crates, issue references (now
`photocraft#N`), and the corpus tests' directory (`CRAFT_PSD_CORPUS` or
`corpus/` at the workspace root). Tests, proptests, fuzz targets and
fixtures move with it.
Part of #778, #786.
* craft-psd: engine_data, the text engine document of type layers
The EngineData reader and writer from PhotoCraft's photocraft-text
(crates/text/src/engine_data.rs at storytold/photocraft 63b641b5): a
tree of values that is written back in Photoshop's layout, with strings
stored as plain bytes kept as plain bytes.
From EffectCraft's effectcraft-psd (crates/psd/src/engine_data.rs at
storytold/effectcraft 072e1af9), ported onto that tree: `first_style`,
the first style run as a typed `TextStyle` with bounded sizes and
spacings, and `minimal`, a one-run document for writers and fixtures.
`Value::index` is new.
Both apps had their own parser for the same syntax.
* craft-psd: engine_data::parse_lossy reads what it can of a damaged document
EffectCraft's EngineData reader was best effort: a truncated or damaged
document still gave the text and style it held. `parse_lossy` does that
on the same parser: a truncated dictionary, array or string keeps what
it has, a byte that starts no key is skipped, a token that is no number
becomes a name, and garbage gives an empty dictionary. `parse` stays
strict and is unchanged in what it accepts.
The parser's `value` is split into one function per kind of value, and
reads with `get` instead of indexing.
* craft-psd: typed views of type layers, smart objects and adjustments
Read-only views EffectCraft's effectcraft-psd had over the blocks this
crate keeps raw (storytold/effectcraft f334bcf3, crates/psd/src/parse.rs
and placed.rs). The blocks stay raw and write back unchanged.
- `text`: `TypeLayer` from `TySh`: text, transform (the identity when not
finite), bounds, the first style run (read with
`engine_data::parse_lossy`) and the text descriptor.
`LayerRecord::type_layer`.
- `smart`: `SmartObject` from `SoLd`/`SoLE` (id, quad, non-affine
transform, size, warp) and `PlLd`; `Warp` with the named styles and the
custom quilt mesh; the quad geometry (`map`, `placed_bounds`,
`placed_size`, `bake_scale`, `placement`). `LinkedFile` and
`linked_files` for `lnk2`/`lnkD`/`lnk3`/`lnkE`, `PsdFile::linked_files`
and `PsdFile::linked_data`. `LayerRecord::smart_object`.
- `adjust`: `Adjustment` from `nvrt`, `brit`, `CgEd`, `hue2`/`hue `,
`levl`, `expA`, and the other adjustment keys by name;
`LayerRecord::adjustment`, `solid_color` (`SoCo`) and `effects` (`lfx2`).
- `Descriptor`: `object`, `number`, `numbers`, `boolean`, `text`,
`enumerated`, `raw_data`, `color`; `Value::as_number`.
Linked-file data is a range of the block's data, checked against the
record, instead of a range of the whole file.
* craft-psd: shared descriptor lookups
Descriptor::get_bool, get_number, get_text, get_enum and get_object,
used by asl, grd and slices in place of their own copies.
Ported from storytold/photocraft#9552 (its crates/psd part).
* craft-psd: the typed views use the shared descriptor lookups
One set of Descriptor accessors: the get_* lookups from photocraft#9552.
numbers, raw_data and color move next to them as get_numbers,
get_raw_data and get_color.
* craft-psd: linked-layer record editing, the thumbnail header and brst
Format code that PhotoCraft keeps in crates/io (linked.rs,
psd_thumbnail.rs, blocks.rs at storytold/photocraft f1b5e7d7), moved
here without the document mapping:
- smart: `file_type`, `encode_embedded_file` (a version-7 liFD record),
`linked_records`, `linked_uuids`, `rebuild_linked_block`,
`select_linked_records` (exact UTF-8 ids, cut selected records are an
error), `contains_linked_record`, `copy_linked_record`.
- resources: `Thumbnail` reads the 1036/1033 header, and
`Thumbnail::jfif_bytes` writes it as Photoshop does.
- tagged: `channel_restrictions` / `channel_restrictions_data` for brst.
PhotoCraft's tests for these functions move with them.
---------
Co-authored-by: Omar Saidahmed <osaidahm@uwaterloo.ca>
A version-16 .atn file can hold several sets after one version header.
- `atn::parse_sets` / `parse_sets_with_encoding` read every set to the end
of the file (a malformed later set fails the whole result);
`write_sets` writes them with one header. Archive-wide limits:
`MAX_SETS`, `MAX_TOTAL_ACTIONS`, `MAX_TOTAL_ITEMS`, on top of the
per-set and per-action ones.
- `parse_sets_with_spans` returns, for each set, action and step, the
byte ranges of its header fields and descriptor in the input, so a
library can edit one field and keep every other byte as it was.
- `parse` and `write` (one set) are unchanged.
Ported from storytold/photocraft#11021 (its crates/psd part).
Co-authored-by: yoriswind <yoriswind@yahoo.com>