mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-23 02:44:24 +01:00
PSD import: looking for drawn pixels takes nothing from the import's allowance
Checking whether a layer's pixels are all fully transparent no longer counts its transparency against the memory allowed for the whole import. The layer is counted where it is drawn, so an import that fits no longer fails because the check counted the same pixels first.
This commit is contained in:
1 parent
365823add6
commit
91fd78e27a
2 files changed
+13
-6
No files matched your search
@@ -1156,13 +1156,14 @@ impl<F: Fn([f32; 4]) -> [f32; 3]> Builder<'_, F> {
|
||||
let bytes = (row as u64).saturating_mul(rows as u64);
|
||||
if bytes > self.room() {
|
||||
return Ok(false);
|
||||
} else {
|
||||
self.spend(bytes)?;
|
||||
match layer_channel(data, rows, row, self.h.psb, depth) {
|
||||
Ok(plane) => (0..rows)
|
||||
.all(|y| plane.get(y * row..(y + 1) * row).is_some_and(|r| (0..w).all(|x| byte(sample(r, x, depth, false)) == 0))),
|
||||
Err(_) => false,
|
||||
}
|
||||
// Not counted against the import's allowance: the transparency is read again, and
|
||||
// counted, where the layer is drawn.
|
||||
match layer_channel(data, rows, row, self.h.psb, depth) {
|
||||
Ok(plane) => {
|
||||
(0..rows).all(|y| plane.get(y * row..(y + 1) * row).is_some_and(|r| (0..w).all(|x| byte(sample(r, x, depth, false)) == 0)))
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
|
||||
@@ -2247,6 +2247,12 @@ fn damaged_layers_never_panic() {
|
||||
assert!(psdlayers::import(&file(8, 8, &many[..16], 8, false, false), false, 512, cms).unwrap().is_some());
|
||||
let e = psdlayers::import(&file(8, 8, &many, 8, false, false), false, 512, cms).err();
|
||||
assert!(e.as_deref().is_some_and(|e| e.contains("take more memory to read than allowed")), "{e:?}");
|
||||
// Looking through those layers' transparency for pixels that draw, below an adjustment layer,
|
||||
// takes nothing from the allowance.
|
||||
let mut clear: Vec<L> = (0..16).map(|_| layer("x", [0, 0, 8, 8], [1, 2, 3, 0])).collect();
|
||||
clear.push(adjustment("Invert", b"nvrt", &[]));
|
||||
let opened = psdlayers::import(&file(8, 8, &clear, 8, false, false), false, 512, cms);
|
||||
assert!(opened.as_ref().is_ok_and(Option::is_some), "{:?}", opened.err());
|
||||
}
|
||||
|
||||
/// A layer in a mode VectorCraft lacks above a pass-through group merges with the group's layers
|
||||
|
||||
Reference in new issue
Block a user