PSD import: keep adjustment layers pending over layers that draw nothing

- A hidden pass-through group, kept with the hidden layers, and an
  adjustment layer at 0 opacity or 0 fill no longer hold back the
  adjustment layers above them in a pass-through group.
- Layers that draw nothing (no pixels stored, 0 opacity, or 0 fill with
  nothing clipped to them) and groups of only such layers don't count as
  content below an adjustment layer, so in a pass-through group it still
  changes what is below the group. Layers clipped to a layer at 0 fill
  or to an adjustment layer count as content.
- An adjustment layer whose layer mask is too large for the memory
  allowed is counted as not applied, merged or clipped, instead of
  stopping the layered import.
This commit is contained in:
dotCooCoo committed 2026-11-21 05:21:56 -08:00
1 parent 64dd48d801
commit aecf4b1284
4 files changed
+318 -43

No files matched your search

+129 -39
View File
@@ -45,7 +45,9 @@
//! otherwise, and Posterize maps each channel to the nearest of its evenly spaced levels, the higher
//! one on a tie. The adjusted color is composited over the color below in the layer's blend mode,
//! at its opacity times its fill opacity, through its layer mask; transparency stays as it was. One
//! with nothing visible below it in its group changes nothing; in a pass-through group it changes
//! with nothing visible below it in its group that draws (a layer that stores no pixels or is at 0
//! opacity or 0 fill with nothing clipped to it doesn't, nor does a group of only such layers)
//! changes nothing; in a pass-through group it changes
//! what is below the group when the group is merged, and otherwise isn't applied. One that layers
//! are clipped to, and one clipped to another adjustment layer, isn't applied.
//!
@@ -54,7 +56,7 @@
//! whose fill isn't read or whose shape is a vector mask, layer effects that are switched on, vector
//! masks, and the knockouts of top-level layers, of clipped layers, of layers that others are clipped
//! to and of layers in a pass-through group with a layer in another mode, and other Knockout values,
//! and adjustments whose merge needs more memory than allowed aren't applied; the warnings count them
//! and adjustments whose merge, their layer mask included, needs more memory than allowed aren't applied; the warnings count them
//! and the hidden layers left out.
//!
//! The file is untrusted: every count, length and size is checked before anything is allocated,
@@ -487,6 +489,12 @@ impl Record<'_> {
}
}
/// Does the layer draw nothing (an adjustment layer, or one that stores no pixels and isn't a
/// fill drawn from its color over the canvas; see [`Builder::image`])?
fn draws_nothing(&self) -> bool {
self.covers_without_drawing() || (self.stores_nothing() && !self.color_over_canvas())
}
/// Is the layer a fill that stores no pixels and whose shape is a vector mask, so that it
/// isn't drawn?
fn undrawn_shape(&self) -> bool {
@@ -1089,6 +1097,22 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
Ok(Some((i64::from(m.bounds.left), i64::from(m.bounds.top), img, read(m.default))))
}
/// Does record `i`'s layer mask, switched on, fit the memory allowed for reading it with
/// [`Self::mask`]? `true` when it has none, and when its size is damaged (reading it says so).
fn mask_fits(&self, i: usize) -> Result<bool, String> {
let rec = self.record(i)?;
let Some(m) = rec.mask.filter(|m| !m.disabled) else { return Ok(true) };
if !rec.channels.iter().any(|(c, _)| *c == -2) {
return Ok(true);
}
let (w, rows) = m.bounds.size();
let max_side = if self.h.psb { 300_000 } else { 30_000 };
if w > max_side || rows > max_side {
return Ok(true);
}
Ok(self.fits((row_bytes(w, self.h.depth) as u64 + w as u64).saturating_mul(rows as u64)).is_ok())
}
/// Multiply `c`'s transparency by record `i`'s layer mask.
fn apply_mask(&self, c: &mut Canvas, i: usize) -> Result<(), String> {
let Some((left, top, m, default)) = self.mask(i, false)? else { return Ok(()) };
@@ -1205,6 +1229,10 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
}
// A clipped adjustment layer changes the merged canvas in place, through its layer mask.
let adjust = self.adjustment(body)?;
// Its layer mask too large to read needs more memory than allowed.
if adjust.is_some() && !base_adjustment && !self.mask_fits(i)? {
return Ok(false);
}
let layer = match adjust {
Some(_) => Canvas::default(),
None => match self.draw_body(body, Some(i))? {
@@ -1433,13 +1461,15 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
}
/// The records of the adjustment layers kept in `out` at `level` (in a pass-through group, to
/// change what is below the group), those kept in the pass-through groups of `out` included.
/// change what is below the group), those kept in the visible pass-through groups of `out`
/// included.
fn pending(&self, out: &[Unit<'_>], level: Level) -> Result<Vec<usize>, String> {
let mut records = vec![];
if level != Level::Pass {
return Ok(records);
}
for u in out {
// A hidden unit, kept with the hidden layers, or one at 0 opacity, changes nothing.
for u in out.iter().filter(|u| u.visible && u.opacity > 0.0) {
if self.adjustment(&u.body)?.is_some() {
records.push(u.record);
} else if let (Body::Group(_, items), Blend::Pass) = (&u.body, u.blend) {
@@ -1451,44 +1481,98 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
/// The adjustment layers the import applies that a pass-through group with the layers `items`
/// keeps to change what is below it: from the first one with nothing that draws below it in the
/// group (hidden and clipped layers, other adjustment layers and fills that draw nothing aren't
/// counted), it and every one above it, in the pass-through groups inside it too. Also whether
/// anything in `items` draws.
/// group (hidden and clipped layers, other adjustment layers, layers and groups at 0 opacity, and
/// layers and groups that draw nothing aren't counted), it and every one above it, in the
/// pass-through groups inside it too; one at 0 opacity isn't kept. Also whether anything in
/// `items` draws.
fn leading(&self, items: &[Item]) -> Result<(Vec<usize>, bool), String> {
let (mut records, mut draws) = (vec![], false);
for item in items {
match item {
Item::Layer(i) => {
let r = self.record(*i)?;
if r.hidden || r.clipped {
continue;
}
if r.adjust().is_some() {
if !draws || !records.is_empty() {
records.push(*i);
}
} else if !r.covers_without_drawing() {
draws = true;
for (k, item) in items.iter().enumerate() {
let (i, r, children) = match item {
Item::Layer(i) => (*i, self.record(*i)?, None),
Item::Group(g, children) => (*g, self.record(*g)?, Some(children)),
};
// A clipped one draws as part of the one it is clipped to.
if r.hidden || r.clipped {
continue;
}
let (clips, drawn) = self.base_draws(items, k)?;
// One that layers are clipped to isn't kept, and a pass-through group they are clipped to
// is drawn alone (see `clip`). One at 0 opacity changes nothing (see `adjust_below`).
let keeps = !clips && r.opacity * r.fill > 0.0 && (!draws || !records.is_empty());
match children {
None if r.adjust().is_some() && !clips => {
if keeps {
records.push(i);
}
}
Item::Group(g, children) => {
let r = self.record(*g)?;
if r.hidden {
continue;
}
if r.blend == Blend::Pass && (!draws || !records.is_empty()) {
let (inner, inner_draws) = self.leading(children)?;
records.extend(inner);
draws |= inner_draws;
} else {
draws = true;
}
Some(children) if r.blend == Blend::Pass && keeps => {
let (inner, inner_draws) = self.leading(children)?;
records.extend(inner);
draws |= inner_draws;
}
_ => draws |= drawn,
}
}
Ok((records, draws))
}
/// Does anything in `items` draw: a visible layer or group that isn't clipped and draws (see
/// [`Self::base_draws`])?
fn draws(&self, items: &[Item]) -> Result<bool, String> {
for (k, item) in items.iter().enumerate() {
let r = match item {
Item::Layer(i) => self.record(*i)?,
Item::Group(g, _) => self.record(*g)?,
};
if !r.hidden && !r.clipped && self.base_draws(items, k)?.1 {
return Ok(true);
}
}
Ok(false)
}
/// For item `k` of `items`, visible and not clipped: whether visible layers are clipped to it,
/// and whether it draws, above 0 opacity: by its own pixels (a group's, those of its layers)
/// above 0 fill, or by those of the layers clipped to it that draw, which show in its pixels at
/// any fill, or over the canvas when it is a layer that covers it without drawing.
fn base_draws(&self, items: &[Item], k: usize) -> Result<(bool, bool), String> {
let Some(item) = items.get(k) else { return Ok((false, false)) };
let (r, own) = self.pixels(item)?;
let covers = matches!(item, Item::Layer(_)) && r.covers_without_drawing();
let (mut clips, mut clips_draw) = (false, false);
for above in items.get(k + 1..).unwrap_or_default() {
let c = match above {
Item::Layer(i) => self.record(*i)?,
Item::Group(g, _) => self.record(*g)?,
};
if !c.clipped {
break;
}
if c.hidden {
continue;
}
clips = true;
if !clips_draw && c.opacity * c.fill > 0.0 {
clips_draw = self.pixels(above)?.1;
}
}
let drawn = (r.fill > 0.0 && own) || (clips_draw && (covers || own));
Ok((clips, r.opacity > 0.0 && drawn))
}
/// `item`'s record, and whether it has pixels of its own: a layer that draws, or a group with
/// something in it that draws (see [`Self::draws`]).
fn pixels(&self, item: &Item) -> Result<(&Record<'_>, bool), String> {
Ok(match item {
Item::Layer(i) => {
let r = self.record(*i)?;
(r, !r.draws_nothing())
}
Item::Group(g, children) => (self.record(*g)?, self.draws(children)?),
})
}
/// `items`' units, at `level`, with the layers in blend modes VectorCraft lacks, and in a group
/// the layers with a shallow knockout, merged with those below.
fn merged<'i>(&mut self, items: &'i [Item], keep_hidden: bool, level: Level) -> Result<Vec<Unit<'i>>, String> {
@@ -1625,7 +1709,8 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
/// Adjustment layer `u` (one the import applies), at `level`, merged with the visible units
/// `out` below it in its list: they become one layer, adjusted. A hidden one would need the
/// merge and is left out. With nothing visible below it that draws (other adjustment layers and
/// fills that draw nothing don't count), or at 0 opacity, it changes nothing
/// layers and groups that draw nothing or are at 0 opacity don't count), or at 0 opacity, it
/// changes nothing
/// and comes in as nothing, except in a pass-through group, where it is kept to change what is
/// below the group when the group is drawn onto it; there, once one is kept (in the group or in
/// a pass-through group in it), the ones above it are kept too, in order. One that layers are clipped to, and one whose merge needs more memory
@@ -1645,12 +1730,15 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
return Ok(());
}
let mut below = false;
for b in out.iter() {
match &b.body {
// An adjustment layer, or a fill that draws nothing, has nothing to change.
Body::Layer(i) if self.record(*i)?.covers_without_drawing() => {}
_ => below |= b.visible,
}
for b in out.iter().filter(|b| b.visible && b.opacity > 0.0) {
below |= match &b.body {
// An adjustment layer, a layer that draws nothing, or a group of such layers, has
// nothing to change.
Body::Layer(i) => !self.record(*i)?.draws_nothing(),
Body::Group(_, items) => self.draws(items)?,
// Clipped layers merged with a base that has no pixels have none either.
Body::Merged(c) => c.px.iter().any(|p| p[3] > 0.0),
};
}
// Kept below it in the group, or in a pass-through group below it there.
let pending = !self.pending(out, level)?.is_empty();
@@ -1930,6 +2018,8 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
if let Some(a) = self.adjustment(&u.body)? {
if let Some(c) = acc.as_mut() {
let mask = match u.mask_of {
// A layer mask too large to read needs more memory than allowed.
Some(i) if !self.mask_fits(i)? => return Ok(false),
Some(i) => self.mask(i, false)?,
None => None,
};
@@ -1456,6 +1456,171 @@ fn an_adjustment_layer_in_a_pass_through_group_changes_what_is_below_the_group()
assert_eq!(row_of(&s, &d.layers[0]), [[10, 20, 30, 255]]);
}
/// The layer of a pass-through group's sublayers whose name ends with `end`.
fn sublayer<'d>(folder: &'d Node, end: &str) -> &'d Node {
let children = folder.children().map(Vec::as_slice).unwrap_or_default();
let names: Vec<&str> = children.iter().map(|c| name(c)).collect();
children.iter().find(|c| name(c).ends_with(end)).unwrap_or_else(|| panic!("no sublayer ending with {end} in {names:?}"))
}
/// An adjustment layer that changes nothing, in a hidden pass-through group or at 0 opacity or 0
/// fill, keeps no adjustment layer above it in the group from merging with the layers below it:
/// the gray 100 posterizes to 85.
#[test]
fn adjustment_layers_that_change_nothing_hold_none_back() {
let invert = |opacity: u8, fill: u8| {
let mut l = L { opacity, ..adjustment("Invert", b"nvrt", &[]) };
l.blocks.push((*b"iOpa", vec![fill]));
l
};
let cases = [("hidden group", true, invert(255, 255)), ("0 opacity", false, invert(0, 255)), ("0 fill", false, invert(255, 0))];
for (what, hidden, invert) in cases {
let layers = [
group_end(),
group_end(),
invert,
L { hidden, ..group("Inner", b"pass") },
layer("Photo", [0, 0, 1, 1], [100, 100, 100, 255]),
adjustment("Posterize", b"post", &[0, 4, 0, 0]),
group("Folder", b"pass"),
];
let (s, r) = open(&file(1, 1, &layers, 8, false, false), json!({"hiddenLayers": hidden}));
let d = &s.doc().unwrap().doc;
assert_eq!(d.layers.iter().map(|l| name(l)).collect::<Vec<_>>(), ["Folder"], "{what}: {r}");
assert_eq!(row_of(&s, sublayer(&d.layers[0], "Photo + Posterize")), [[85, 85, 85, 255]], "{what}: {r}");
}
}
/// A layer that stores no pixels draws nothing: an adjustment layer above it in a pass-through group,
/// directly or in a pass-through group inside it, still changes what is below the group.
#[test]
fn an_adjustment_layer_over_layers_that_draw_nothing_changes_what_is_below_the_group() {
let empty = || layer("Empty", [0, 0, 0, 0], [0; 4]);
let direct = [
layer("Under", [0, 0, 1, 1], [10, 20, 30, 255]),
group_end(),
empty(),
adjustment("Invert", b"nvrt", &[]),
group("Folder", b"pass"),
L { blend: b"lddg", ..layer("Dodge", [0, 0, 1, 1], [0, 0, 0, 255]) },
];
let (s, r) = open(&file(1, 1, &direct, 8, false, false), json!({}));
let d = &s.doc().unwrap().doc;
assert_eq!(d.layers.iter().map(|l| name(l)).collect::<Vec<_>>(), ["Under + Folder + Dodge"], "{r}");
assert_eq!(row_of(&s, &d.layers[0]), [[245, 235, 225, 255]], "{r}");
assert!(!r["warnings"].to_string().contains("adjustment"), "{r}");
// Inverted in the inner group, then posterized to 4 levels.
let nested = [
layer("Under", [0, 0, 1, 1], [10, 20, 30, 255]),
group_end(),
group_end(),
empty(),
adjustment("Invert", b"nvrt", &[]),
group("Inner", b"pass"),
adjustment("Posterize", b"post", &[0, 4, 0, 0]),
group("Folder", b"pass"),
L { blend: b"lddg", ..layer("Dodge", [0, 0, 1, 1], [0, 0, 0, 255]) },
];
let (s, r) = open(&file(1, 1, &nested, 8, false, false), json!({}));
let d = &s.doc().unwrap().doc;
assert_eq!(d.layers.iter().map(|l| name(l)).collect::<Vec<_>>(), ["Under + Folder + Dodge"], "{r}");
assert_eq!(row_of(&s, &d.layers[0]), [[255, 255, 255, 255]], "{r}");
assert!(!r["warnings"].to_string().contains("adjustment"), "{r}");
// Nor does a group of such layers, in any mode, or a layer at 0 opacity: below them, directly
// or in the inner group, Invert and Posterize still change what is below the outer group.
let mut no_fill = layer("Clear", [0, 0, 1, 1], [0, 0, 0, 255]);
no_fill.blocks.push((*b"iOpa", vec![0]));
let photo = || layer("Photo", [0, 0, 1, 1], [0, 0, 255, 255]);
let below: [(&str, Vec<L>); 5] = [
("empty group", vec![group_end(), empty(), group("Empty", b"norm")]),
("empty pass-through group", vec![group_end(), empty(), group("Empty", b"pass")]),
("0 opacity", vec![L { opacity: 0, ..layer("Clear", [0, 0, 1, 1], [0, 0, 0, 255]) }]),
("0 fill in a group", vec![group_end(), no_fill, group("Empty", b"norm")]),
("group clipped to an empty layer", vec![empty(), group_end(), photo(), L { clipped: true, ..group("Clipped", b"norm") }]),
];
for (what, nothing) in below {
let direct = [
&[layer("Under", [0, 0, 1, 1], [10, 20, 30, 255]), group_end()][..],
&nothing,
&[adjustment("Invert", b"nvrt", &[]), group("Folder", b"pass"), L { blend: b"lddg", ..layer("Dodge", [0, 0, 1, 1], [0, 0, 0, 255]) }],
]
.concat();
let (s, r) = open(&file(1, 1, &direct, 8, false, false), json!({}));
assert_eq!(row_of(&s, &s.doc().unwrap().doc.layers[0]), [[245, 235, 225, 255]], "{what}: {r}");
let nested = [
&[layer("Under", [0, 0, 1, 1], [10, 20, 30, 255]), group_end(), group_end()][..],
&nothing,
&[
adjustment("Invert", b"nvrt", &[]),
group("Inner", b"pass"),
adjustment("Posterize", b"post", &[0, 4, 0, 0]),
group("Folder", b"pass"),
L { blend: b"lddg", ..layer("Dodge", [0, 0, 1, 1], [0, 0, 0, 255]) },
],
]
.concat();
let (s, r) = open(&file(1, 1, &nested, 8, false, false), json!({}));
assert_eq!(row_of(&s, &s.doc().unwrap().doc.layers[0]), [[255, 255, 255, 255]], "{what}: {r}");
}
}
/// Layers clipped to a layer at 0 fill, or to an adjustment layer, draw: an adjustment layer above
/// them in a pass-through group merges with them and is applied.
#[test]
fn an_adjustment_layer_over_clipped_layers_merges_with_them() {
let mut clear = layer("Base", [0, 0, 1, 1], [0, 0, 0, 255]);
clear.blocks.push((*b"iOpa", vec![0]));
let photo = || L { clipped: true, ..layer("Photo", [0, 0, 1, 1], [0, 0, 255, 255]) };
let layers = [
group_end(),
group_end(),
clear,
photo(),
adjustment("Invert", b"nvrt", &[]),
group("Folder", b"pass"),
L { blend: b"lddg", ..layer("Dodge", [0, 0, 1, 1], [0, 0, 0, 255]) },
group("Outer", b"pass"),
];
let (s, r) = open(&file(1, 1, &layers, 8, false, false), json!({}));
let d = &s.doc().unwrap().doc;
let merged = "layers in blend modes VectorCraft doesn't have (Linear Dodge) were merged with the layers below them";
assert_eq!(r["warnings"], json!([merged]), "{r}");
assert_eq!(row_of(&s, sublayer(&d.layers[0], "Dodge")), [[255, 255, 0, 255]], "{r}");
// The same with a group at 0 fill as the base.
let mut clear_group = group("Base", b"norm");
clear_group.blocks.push((*b"iOpa", vec![0]));
let layers = [
group_end(),
group_end(),
group_end(),
layer("Black", [0, 0, 1, 1], [0, 0, 0, 255]),
clear_group,
photo(),
adjustment("Invert", b"nvrt", &[]),
group("Folder", b"pass"),
L { blend: b"lddg", ..layer("Dodge", [0, 0, 1, 1], [0, 0, 0, 255]) },
group("Outer", b"pass"),
];
let (s, r) = open(&file(1, 1, &layers, 8, false, false), json!({}));
let d = &s.doc().unwrap().doc;
assert_eq!(r["warnings"], json!([merged]), "{r}");
assert_eq!(row_of(&s, sublayer(&d.layers[0], "Dodge")), [[255, 255, 0, 255]], "{r}");
// Clipped to an Invert layer, which isn't applied then, the photo shows over the canvas, and
// Posterize merges with it: the gray 100 posterizes to 85.
let layers = [
group_end(),
group_end(),
adjustment("Invert", b"nvrt", &[]),
L { clipped: true, ..layer("Photo", [0, 0, 1, 1], [100, 100, 100, 255]) },
group("Folder", b"pass"),
adjustment("Posterize", b"post", &[0, 4, 0, 0]),
group("Outer", b"pass"),
];
let (s, r) = open(&file(1, 1, &layers, 8, false, false), json!({}));
let d = &s.doc().unwrap().doc;
assert_eq!(row_of(&s, sublayer(&d.layers[0], "Posterize")), [[85, 85, 85, 255]], "{r}");
}
/// Invert, Threshold and Posterize data that can't be read is not applied, with a warning: a level
/// out of range, data too short, or a second adjustment block on the layer.
#[test]
@@ -1523,6 +1688,25 @@ fn an_adjustment_merge_past_the_memory_allowed_isnt_applied() {
assert!(warnings.iter().any(|w| w == "1 adjustment layer was not applied"), "{warnings:?}");
}
/// An adjustment layer whose layer mask is too large for the memory allowed isn't applied, merged
/// with the layers below it or clipped to one, and the file still opens with its layers.
#[test]
fn an_adjustment_mask_past_the_memory_allowed_isnt_applied() {
let cms = |c: [f32; 4]| [c[0], c[1], c[2]];
// The 100 × 100 mask takes more than 128 bytes; the 1-pixel layer below it doesn't.
let masked = |clipped: bool| L { clipped, mask: Some(([0, 0, 100, 100], 255, 0, vec![0; 10_000])), ..adjustment("Invert", b"nvrt", &[]) };
for clipped in [false, true] {
let f = file(1, 1, &[layer("Under", [0, 0, 1, 1], [10, 20, 30, 255]), masked(clipped)], 8, false, false);
let (doc, warnings) = psdlayers::import(&f, false, 128, cms).unwrap_or_else(|e| panic!("{clipped}: {e}")).unwrap();
assert_eq!(doc.layers.iter().map(|l| name(l)).collect::<Vec<_>>(), ["Under"], "{clipped}: {warnings:?}");
assert_eq!(warnings, ["1 adjustment layer was not applied"], "{clipped}");
// With the memory for it, the mask's black leaves the layer as it was.
let (doc, warnings) = psdlayers::import(&f, false, 1 << 20, cms).unwrap().unwrap();
assert_eq!(doc.layers.iter().map(|l| name(l)).collect::<Vec<_>>(), ["Under + Invert"], "{clipped}: {warnings:?}");
assert!(warnings.is_empty(), "{clipped}: {warnings:?}");
}
}
/// Damaged Invert, Threshold and Posterize layers, masked and clipped, open without a panic.
#[test]
fn damaged_adjustment_layers_never_panic() {
+4 -3
View File
@@ -10916,12 +10916,13 @@ The rest are VectorCraft's own rules:
encoded back to 0..255) is above the level (1 to 255) and black otherwise; Posterize maps each channel to the
nearest of its 2 to 255 evenly spaced levels, the higher one on a tie. The adjusted color is composited over the
color below in the layer's blend mode, at its opacity times its fill opacity, through its layer mask, and
transparency is kept. A hidden one is left out. One with nothing visible below it in its group changes nothing; in
a Pass Through group it changes what is below the group only when the group is merged, and is otherwise not
transparency is kept. A hidden one is left out. One with nothing visible below it in its group that draws (a layer
that stores no pixels or is at 0 opacity or 0 fill with nothing clipped to it doesn't, nor does a group of only such
layers) changes nothing, and so does one at 0 opacity or 0 fill; in a Pass Through group it changes what is below the group only when the group is merged, and is otherwise not
applied.
- Other adjustment layers, Invert, Threshold and Posterize layers that others are clipped to, that are clipped to
another adjustment layer, whose data can't be read (a level out of range, too short, or two adjustment blocks on
one layer) or whose merge needs more memory than allowed, fill layers that store no pixels and whose fill isn't
one layer) or whose merge, its layer mask included, needs more memory than allowed, fill layers that store no pixels and whose fill isn't
read, layer effects that are switched on, the other knockouts (top-level layers, clipped layers, layers that others
are clipped to, Pass Through groups with layers in other modes, other Knockout values, and merges that need more
memory than allowed) and vector masks are not applied; the `warnings` count them.
+1 -1
View File
@@ -2324,7 +2324,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Targa files (`.tga`, `.vda`, `.icb`, `.vst`) open, place linked or embedded, relink and update at their pixel size: color-mapped, true-color and black-and-white, raw or run-length encoded, in any of the four row orders. The image descriptor's attribute bits and the extension area's Attributes Type decide the transparency: a file with no attribute bits, or with attribute data the Attributes Type calls undefined, opens opaque; with one bit, a 16-bit true-color pixel takes that bit as its alpha, and a color-mapped pixel takes the bit of the 16-bit color map entry it indexes; premultiplied colors are divided by their alpha. Open and Place recognize a Targa file by its extension, and `clipboard.importImage` and Glass's Load Texture… by its header; a Targa file copied in a file manager pastes as a bitmap (`crates/engine/src/cmd/fileio/tests_tiffbmp.rs`, `crates/engine/src/tests/links.rs`).
- BMP files named `.dib` or `.rle` (run-length encoded bitmaps included), Photoshop files named `.pdd` and PNG files named `.pns` open and place, linked or embedded, as BMP, PSD and PNG files, in any letter case: the Open and Place dialogs list them with their format, the Links panel names their format, and Edit Original opens them. Exports write only `.bmp`, `.psd` and `.png` (`crates/engine/src/cmd/fileio/tests_tiffbmp.rs`, `crates/engine/src/cmd/fileio/tests_psdread.rs`, `crates/engine/src/tests/links.rs`).
- File › Open converts a PSD or PSB file's layers to objects, keeping the layer structure, merging clipped layers into one layer, merging a layer that uses a Knockout option with the layers below it, and leaving out hidden layers that would need a merge, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for the option that converts layers to objects; hidden layers come in with `hiddenLayers`, as Import Hidden Layers brings them in, and `layers: false` opens the merged image. VectorCraft's own rules: each layer becomes a layer holding its pixels with its name, visibility, opacity and blend mode, groups become layers of sublayers, layers in Dissolve, Linear Burn, Linear Dodge, Vivid Light, Linear Light, Pin Light, Hard Mix, Subtract, Divide, Darker Color and Lighter Color are merged with the layers below, layer masks become opacity masks, fill opacity multiplies the opacity (in a layer that others are clipped to, it fades only that layer's own pixels), a Knockout value of 1 is read as a shallow knockout and applied to a layer or group inside a group, which is merged with the visible layers below it in that group (its pixels clear them to transparency, it is drawn there at its fill opacity, and its opacity fades the result; in a pass-through group only when it and the visible layers below it are in the Normal mode; a knockout at 0 opacity, or at 0 fill where it covers none of their painted pixels, isn't merged for the knockout), and adjustment layers other than Invert, Threshold and Posterize, layer effects, vector masks and the other knockouts (top-level layers, clipped layers, layers that others are clipped to, pass-through groups with layers in other modes, other Knockout values, and merges that need more memory than allowed) aren't applied and are counted in the warnings. 8-, 16- and 32-bit files, PSB, raw, PackBits and zipped channels (`crates/engine/src/cmd/fileio/tests_psdlayers.rs`).
- File › Open with a PSD or PSB file's layers as objects applies Invert, Threshold and Posterize adjustment layers (the `nvrt`, `thrs` and `post` blocks of the [PSD file format specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/)): each is merged with the visible layers below it in its group, which it changes, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for adjustment layers; clipped to a layer, it changes only that layer and the layers clipped to it. Each adjustment works on the colors as [the help page](https://helpx.adobe.com/photoshop/desktop/adjust-color/color-effects-techniques/apply-special-color-effects-to-images.html) describes them. VectorCraft's own rules: each channel is taken as an 8-bit sRGB value; Invert turns `v` into `255 − v`; Threshold compares the Rec. 709 luminance of linear sRGB, encoded back to 0..255, with its level (1 to 255), white above it and black at or below it; Posterize maps each channel to the nearest of its 2 to 255 evenly spaced levels, the higher one on a tie; the adjusted color is composited over the color below in the layer's blend mode at its opacity and fill opacity, through its layer mask, and transparency is kept. A hidden one is left out; one with nothing visible below it in its group changes nothing, and in a pass-through group it changes what is below the group only when the group is merged; one that layers are clipped to, one clipped to another adjustment layer, one whose data can't be read (a level out of range, too short, or two adjustment blocks on one layer), and one whose merge needs more memory than allowed aren't applied and are counted in the warnings (`crates/engine/src/cmd/fileio/tests_psdlayers.rs`).
- File › Open with a PSD or PSB file's layers as objects applies Invert, Threshold and Posterize adjustment layers (the `nvrt`, `thrs` and `post` blocks of the [PSD file format specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/)): each is merged with the visible layers below it in its group, which it changes, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for adjustment layers; clipped to a layer, it changes only that layer and the layers clipped to it. Each adjustment works on the colors as [the help page](https://helpx.adobe.com/photoshop/desktop/adjust-color/color-effects-techniques/apply-special-color-effects-to-images.html) describes them. VectorCraft's own rules: each channel is taken as an 8-bit sRGB value; Invert turns `v` into `255 − v`; Threshold compares the Rec. 709 luminance of linear sRGB, encoded back to 0..255, with its level (1 to 255), white above it and black at or below it; Posterize maps each channel to the nearest of its 2 to 255 evenly spaced levels, the higher one on a tie; the adjusted color is composited over the color below in the layer's blend mode at its opacity and fill opacity, through its layer mask, and transparency is kept. A hidden one is left out; one with nothing visible below it in its group that draws (a layer that stores no pixels or is at 0 opacity or 0 fill with nothing clipped to it doesn't, nor does a group of only such layers) changes nothing, and so does one at 0 opacity or 0 fill; in a pass-through group it changes what is below the group only when the group is merged; one that layers are clipped to, one clipped to another adjustment layer, one whose data can't be read (a level out of range, too short, or two adjustment blocks on one layer), and one whose merge, its layer mask included, needs more memory than allowed aren't applied and are counted in the warnings (`crates/engine/src/cmd/fileio/tests_psdlayers.rs`).
- File › Open of a PSD or PSB file with two or more layers, and File › Place of one without Link, show PSD Import Options: Convert Layers to Objects with Import Hidden Layers, or Flatten Layers to a Single Image, the options [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for a file that is opened or embedded. A file placed with Link shows its flat image and isn't asked about. `file.place` takes `layers` and `hiddenLayers`, and `document.psdInfo` counts a file's layers without opening it. VectorCraft's own rules: placed layers come in as one group named after the file, a layer as an image and a layer group as a group, at the place the merged image would take and clipped to the canvas when layers reach past it; the dialog asks from two layers up and starts from the choices made last. Layer comps aren't read (`crates/engine/src/cmd/fileio/tests_psdlayers.rs`, `crates/ui-egui/src/dialogs/psd_import.rs`).
- A PSD or PSB file's clipping path, the saved path that image resource 2999 names in the [PSD file format specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), clips its merged image on File › Place and on File › Open of the merged image, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for a file imported as one flattened image. The image comes in a clip group whose clipping path has no paint and uses the even-odd rule, and the path can be edited or released. `links.update` and `links.relink` give the clip group the clipping path the new file names, or leave a plain group when it names none; `links.update` leaves a distorted image's clipping as it is. When Placement Options do not clip the image, a clip group whose clipping path was changed in the document (an anchor or handle moved by a thousandth of a point or more, anchors added or removed, a subpath opened or closed, or its fill rule changed) and a clipping mask made in the document are kept: a new file that names no clipping path leaves the mask clipping the image, and the clip group of a new file that names one goes inside the mask. Files that name no clipping path come in as before. `links.unembed` keeps the clip group, and the PNG or TIFF it writes is read with the path on File › Open, File › Place, `links.relink` and `links.update` (`crates/engine/src/cmd/fileio/tests_psdread.rs`, `crates/engine/src/tests/dcs.rs`).
- Import Slices: File › Open of a PSD or PSB file with slices, and File › Place of one without Link, bring its slices in as user slices, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for a file that is opened or embedded; PSD Import Options offers Import Slices for such a file. `document.open` and `file.place` take `importSlices`, and `document.psdInfo` counts the slices. The slices are read from image resource 1050 in version 6 and in the descriptor of versions 7 and 8, as the [Photoshop File Formats Specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/) describes it. VectorCraft's own rules: Import Slices applies to Convert Layers to Objects and to Flatten Layers to a Single Image alike, and makes the dialog ask for a file with fewer than two layers; placed slices move and scale with the art in the same undo step; each slice keeps its name, type, link, target, message, alternative text, cell text and background color; slices the file generated automatically, and slices wholly outside the canvas, are left out; slices that can't be read are left out with a warning while the art comes in; with Show Import Options off, a PSD file is placed with the PSD Import Options chosen last, and on, each PSD file of the place cursor asks for them (`crates/engine/src/cmd/fileio/tests_psdslices.rs`, `crates/ui-egui/src/dialogs/psd_import.rs`).