mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
* Use craft-psd from craft-libs; remove crates/psd * Regenerate the scorecard (28 crate roots) * Take craft-psd at craft-libs 55d120f2 * Regenerate lockfile for current shared format crates * Pin shared format crates to current craft-libs main * Match brush import cap to shared decoder budget * xtask: update layer fixtures after PSD extraction
40 lines
1.7 KiB
Rust
40 lines
1.7 KiB
Rust
//! A PSD's Background is recognised by its structure (the bottom record, transparency-protected,
|
|
//! stored without a transparency channel), whatever its name in the Photoshop language that
|
|
//! saved the file.
|
|
|
|
use craft_psd::{ColorMode, Compression, PsdFile, TaggedBlock, Version, testgen};
|
|
use photocraft_io::psd_to_document;
|
|
|
|
/// `testgen::layered` with its bottom layer turned into a Photoshop Background named `name`.
|
|
fn file(name: &str, transparency_channel: bool) -> PsdFile {
|
|
let mut f = testgen::layered(Version::Psd, ColorMode::Rgb, 8, Compression::Rle);
|
|
let bottom = f.layers_mut().first_mut().unwrap();
|
|
bottom.name = name.bytes().filter(u8::is_ascii).collect();
|
|
bottom.blocks.retain(|b| &b.key != b"luni" && &b.key != b"lspf");
|
|
bottom.blocks.push(TaggedBlock::unicode_name(name));
|
|
bottom.flags.set_transparency_protected(true);
|
|
if !transparency_channel {
|
|
bottom.channels.retain(|c| c.id != -1);
|
|
}
|
|
f
|
|
}
|
|
|
|
#[test]
|
|
fn a_localized_background_is_the_background() {
|
|
for name in ["Hintergrund", "背景", "Arrière-plan"] {
|
|
let (d, _) = psd_to_document(&file(name, false));
|
|
let bg = d.background().unwrap_or_else(|| panic!("{name}: no Background"));
|
|
assert_eq!(bg.name, name);
|
|
assert!(bg.locks.transparency && bg.locks.position, "{name}");
|
|
assert_eq!(bg.id, d.layers[0].id);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_protected_layer_with_transparency_is_not_the_background() {
|
|
// Lock Transparent Pixels on an ordinary bottom layer: it keeps its transparency channel.
|
|
let (d, _) = psd_to_document(&file("Background", true));
|
|
assert!(d.layers[0].locks.transparency);
|
|
assert!(d.background().is_none());
|
|
}
|