Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

File Handling: wire Maximize PSD and PSB File Compatibility (#204) (#3955)

Erica Francobbfaefd5f03c
diff --git a/apps/photocraft-web/src/web.rs b/apps/photocraft-web/src/web.rs
index 6c9939607..16781e42b 100644
--- a/apps/photocraft-web/src/web.rs
+++ b/apps/photocraft-web/src/web.rs
@@ -347,6 +347,7 @@ fn services(inbox: Inbox) -> Services {
opts.xmp = if settings.xmp_all { photocraft_io::XmpEmbed::All } else { photocraft_io::XmpEmbed::None };
opts.tga_bits = settings.tga_bits;
opts.image_previews = settings.image_previews;
+ opts.psd_maximize_compatibility = settings.psd_maximize_compatibility;
photocraft_io::export(doc, path, &opts).map(|r| (r.bytes, r.warnings)).map_err(|e| e.to_string())
})),
file_dialog: Some(Box::new(|request, _parent, reply| match request {
diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rs
index f6695717b..fea0d3454 100644
--- a/apps/photocraft/src/services.rs
+++ b/apps/photocraft/src/services.rs
@@ -217,6 +217,7 @@ fn export_options(settings: &photocraft_ui_egui::ExportSettings) -> photocraft_i
opts.xmp = if settings.xmp_all { photocraft_io::XmpEmbed::All } else { photocraft_io::XmpEmbed::None };
opts.tga_bits = settings.tga_bits;
opts.image_previews = settings.image_previews;
+ opts.psd_maximize_compatibility = settings.psd_maximize_compatibility;
opts
}
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs
index 5aa2441a1..74069c8b8 100644
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@ -218,8 +218,8 @@ pub(crate) fn import(name: &str, bytes: &[u8]) -> Result<Document> {
Ok(r.document)
}
-/// What a headless save writes beyond the format: JPEG quality, TIFF layers, Targa bits and PSD
-/// previews.
+/// What a headless save writes beyond the format: JPEG quality, TIFF layers, Targa bits, PSD
+/// previews and the PSD merged image.
#[derive(Debug, Clone, Copy)]
pub(crate) struct SaveOpts {
/// Photoshop's 0–12 JPEG scale.
@@ -231,25 +231,30 @@ pub(crate) struct SaveOpts {
pub tga_bits: Option<photocraft_io::TgaBits>,
/// PSD/PSB: embed the thumbnail resource (Preferences › File Handling › Image Previews).
pub image_previews: bool,
+ /// PSD/PSB: write the real merged image (Preferences › File Handling › Maximize PSD and PSB
+ /// File Compatibility).
+ pub psd_maximize_compatibility: bool,
}
impl Default for SaveOpts {
fn default() -> Self {
- SaveOpts { quality: None, tiff_layers: false, tga_bits: None, image_previews: true }
+ SaveOpts { quality: None, tiff_layers: false, tga_bits: None, image_previews: true, psd_maximize_compatibility: true }
}
}
impl SaveOpts {
/// `quality`, `tiffLayers` and `tgaBits` from command `cmd`'s params (a `tgaBits` other than
- /// 24 or 32 is an error); the image previews from the session's File Handling preferences
- /// (Ask When Saving has no dialog here, so it saves them, as Photoshop's Save As checkbox
- /// starts on).
+ /// 24 or 32 is an error); the image previews and the PSD merged image from the session's File
+ /// Handling preferences (Ask When Saving has no dialog here, so it saves them, as Photoshop's
+ /// Save As checkbox and its Maximize Compatibility checkbox both start on).
pub(crate) fn from_params(s: &Session, p: &Value, cmd: &str) -> Result<Self> {
+ let file_handling = &s.prefs().file_handling;
Ok(SaveOpts {
quality: f64_param(p, "quality"),
tiff_layers: p.get("tiffLayers").and_then(Value::as_bool).unwrap_or(false),
tga_bits: tga_bits_param(p, cmd)?,
- image_previews: s.prefs().file_handling.image_previews != crate::prefs::Ask::Never,
+ image_previews: file_handling.image_previews != crate::prefs::Ask::Never,
+ psd_maximize_compatibility: file_handling.maximize_psd_compatibility != crate::prefs::Ask::Never,
})
}
@@ -283,8 +288,13 @@ pub fn tga_bits_param(p: &Value, cmd: &str) -> Result<Option<photocraft_io::TgaB
pub(crate) fn encode(doc: &Document, path: &str, save: impl Into<SaveOpts>) -> Result<(Vec<u8>, Vec<String>)> {
crate::allocation::checkpoint("saving document")?;
let save = save.into();
- let mut opts =
- photocraft_io::ExportOptions { tiff_layers: save.tiff_layers, tga_bits: save.tga_bits, image_previews: save.image_previews, ..Default::default() };
+ let mut opts = photocraft_io::ExportOptions {
+ tiff_layers: save.tiff_layers,
+ tga_bits: save.tga_bits,
+ image_previews: save.image_previews,
+ psd_maximize_compatibility: save.psd_maximize_compatibility,
+ ..Default::default()
+ };
// No quality chosen: write the file the way it was opened (a JPEG at its own quality, a WebP
// lossy or lossless as it was), as Photoshop's Save does.
photocraft_io::apply_file_encoding(doc, &mut opts.encode);
diff --git a/crates/engine/src/file_cmds/tests.rs b/crates/engine/src/file_cmds/tests.rs
index a4100a138..8cab1ce63 100644
--- a/crates/engine/src/file_cmds/tests.rs
+++ b/crates/engine/src/file_cmds/tests.rs
@@ -192,6 +192,26 @@ fn image_previews_preference_controls_the_psd_thumbnail() {
}
}
+/// Preferences › File Handling › Maximize PSD and PSB File Compatibility decides whether a
+/// layered PSD keeps its real merged image: Always and Ask When Saving write it, Never writes
+/// Photoshop's placeholder and says so in resource 1057.
+#[test]
+fn maximize_compatibility_preference_controls_the_psd_merged_image() {
+ use crate::prefs::Ask;
+ let dir = tmp("maximize");
+ let mut s = session(300, 200, 16);
+ s.execute("layer.new.layer", json!({})).unwrap();
+ let real_merged = |path: &str| photocraft_psd::PsdFile::from_bytes(&std::fs::read(path).unwrap()).unwrap().has_real_merged_data();
+ for (ask, expect) in [(Ask::Always, true), (Ask::Never, false), (Ask::Ask, true)] {
+ s.edit_prefs(|p| p.file_handling.maximize_psd_compatibility = ask);
+ for ext in ["psd", "psb"] {
+ let out = join(&dir, &format!("{ask:?}.{ext}"));
+ s.execute("file.saveACopy", json!({"path": out})).unwrap();
+ assert_eq!(real_merged(&out), Some(expect), "{ask:?} {ext}");
+ }
+ }
+}
+
#[test]
fn open_as_forces_the_decoder() {
let dir = tmp("openas");
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index 074835fd0..3a8b7ce69 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -1054,7 +1054,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[
"workspace.autoShowHiddenPanels",
"workspace.enableFloatingDocumentWindowDocking",
"fileHandling.saveInBackground",
- "fileHandling.maximizePsdCompatibility",
"performance.cacheLevels",
"performance.effectCacheMb",
"performance.legacyCompositing",
diff --git a/crates/io/src/lib.rs b/crates/io/src/lib.rs
index c387dc4e3..6d33c332a 100644
--- a/crates/io/src/lib.rs
+++ b/crates/io/src/lib.rs
@@ -177,11 +177,23 @@ pub struct ExportOptions {
/// PSD/PSB: embed the thumbnail image resource (1036), Preferences › File Handling › Image
/// Previews. On by default, as Photoshop's Always Save.
pub image_previews: bool,
+ /// PSD/PSB: write the real merged image, Preferences › File Handling › Maximize PSD and PSB
+ /// File Compatibility (see [`PsdExportOptions::maximize_compatibility`]). On by default, as
+ /// Photoshop's Always.
+ pub psd_maximize_compatibility: bool,
}
impl Default for ExportOptions {
fn default() -> Self {
- ExportOptions { encode: EncodeOptions::default(), force_psb: false, tiff_layers: false, xmp: XmpEmbed::All, tga_bits: None, image_previews: true }
+ ExportOptions {
+ encode: EncodeOptions::default(),
+ force_psb: false,
+ tiff_layers: false,
+ xmp: XmpEmbed::All,
+ tga_bits: None,
+ image_previews: true,
+ psd_maximize_compatibility: true,
+ }
}
}
@@ -382,7 +394,7 @@ fn export_stages(doc: &Document, name_or_ext: &str, opts: &ExportOptions, ctl: &
return Ok(ExportResult { bytes: photocraft_format::save_to_bytes(doc.as_ref(), &previews)?, warnings: Vec::new() });
}
if ext == "psd" || ext == "psb" {
- let o = PsdExportOptions { force_psb: opts.force_psb || ext == "psb", ..Default::default() };
+ let o = PsdExportOptions { force_psb: opts.force_psb || ext == "psb", maximize_compatibility: opts.psd_maximize_compatibility, ..Default::default() };
let (mut file, mut warnings) = with_span(ctl, 0.0, PSD_MODEL_DONE, |ctl| psd_export::document_to_psd_interruptible(doc, &o, ctl));
// A cancelled conversion stops early with an incomplete model: never write it.
ctl.check().map_err(|_| IoError::Cancelled)?;
diff --git a/crates/io/src/psd_export.rs b/crates/io/src/psd_export.rs
index 36f5941f7..38db08087 100644
--- a/crates/io/src/psd_export.rs
+++ b/crates/io/src/psd_export.rs
@@ -35,11 +35,17 @@ pub struct PsdExportOptions {
pub merged_matte: bool,
/// Compression of the merged image (32-bit float documents are always written raw).
pub merged_compression: Compression,
+ /// Write the real merged image (Preferences › File Handling › Maximize PSD and PSB File
+ /// Compatibility). `false` writes Photoshop's white placeholder instead and records
+ /// `has_real_merged_data = false` in resource 1057: a smaller file and a faster save, but
+ /// readers that only show the merged image see white. A document without layer records always
+ /// gets the real image, since its pixels live nowhere else.
+ pub maximize_compatibility: bool,
}
impl Default for PsdExportOptions {
fn default() -> Self {
- PsdExportOptions { force_psb: false, merged_matte: true, merged_compression: Compression::Rle }
+ PsdExportOptions { force_psb: false, merged_matte: true, merged_compression: Compression::Rle, maximize_compatibility: true }
}
}
@@ -1227,6 +1233,28 @@ fn merged_planes(doc: &Document, fmt: &PixelFormat, cmyk: bool, matte: bool, ctl
(planes, has_alpha, translucent)
}
+/// The merged image of a file saved without Maximize Compatibility: Photoshop's white placeholder
+/// in the document's colour channels, with no alpha. Encoded like [`merged_planes`], so CMYK white
+/// is no ink and Lab white is L 100 with neutral a*/b*.
+fn placeholder_planes(doc: &Document, fmt: &PixelFormat) -> Vec<u8> {
+ let cc = fmt.mode.color_channels();
+ let cmyk = cmyk_of(fmt);
+ let lab16 = fmt.mode == ColorMode::Lab && fmt.sample == SampleType::U16;
+ let space = photocraft_compose::cmyk_space(doc);
+ let white = photocraft_color::convert::with_cmyk_space(space.as_ref(), || photocraft_raster::from_rgba(fmt, [1.0, 1.0, 1.0, 1.0]));
+ let n = doc.size.area() as usize;
+ let mut planes = Vec::with_capacity(n * fmt.sample.bytes() * cc);
+ for c in 0..cc {
+ let v = white.get(c).copied().unwrap_or(1.0);
+ let x = if cmyk { 1.0 - v } else { v };
+ let x = if lab16 && (c == 1 || c == 2) { x * (crate::pixels::LAB16_CHROMA_MAX / 65535.0) } else { x };
+ let mut sample = Vec::with_capacity(4);
+ encode_be(x, fmt.sample, &mut sample);
+ planes.extend(sample.iter().copied().cycle().take(n * sample.len()));
+ }
+ planes
+}
+
/// Converts a document to a PSD file model (see [`document_to_psd_with`]).
pub fn document_to_psd(doc: &Document) -> PsdFile {
document_to_psd_with(doc, &PsdExportOptions::default()).0
@@ -1470,15 +1498,24 @@ fn document_to_psd_nested(doc: &Document, opts: &PsdExportOptions, depth: u32, c
let space = photocraft_compose::cmyk_space(doc);
photocraft_color::convert::with_cmyk_space(space.as_ref(), || ex.emit(&doc.layers, &mut tick));
- // Merged composite, rendered and encoded in bands (no full-size float composite). Matting
- // against white only changes pixels with alpha < 1; if some are slightly translucent but all
- // round to opaque (so no alpha channel is written), encode once more without the matte.
- let merged_end = layers_share + (1.0 - layers_share) * MERGED_RENDERED;
- let (mut planes, has_alpha, translucent) =
- crate::with_span(ctl, layers_share, merged_end, |ctl| merged_planes(doc, &fmt, cmyk_of(&fmt), opts.merged_matte, ctl));
- if !has_alpha && translucent && opts.merged_matte {
- planes = merged_planes(doc, &fmt, cmyk_of(&fmt), false, &Interrupt::cancel_only(&|| ctl.cancelled())).0;
- }
+ // Without Maximize Compatibility the merged image is a white placeholder and the composite
+ // isn't rendered at all. A document without layer records keeps the real image: its pixels
+ // live nowhere else.
+ let real_merged = opts.maximize_compatibility || ex.records.is_empty();
+ let (mut planes, has_alpha) = if real_merged {
+ // Merged composite, rendered and encoded in bands (no full-size float composite). Matting
+ // against white only changes pixels with alpha < 1; if some are slightly translucent but
+ // all round to opaque (so no alpha channel is written), encode once more without the matte.
+ let merged_end = layers_share + (1.0 - layers_share) * MERGED_RENDERED;
+ let (mut planes, has_alpha, translucent) =
+ crate::with_span(ctl, layers_share, merged_end, |ctl| merged_planes(doc, &fmt, cmyk_of(&fmt), opts.merged_matte, ctl));
+ if !has_alpha && translucent && opts.merged_matte {
+ planes = merged_planes(doc, &fmt, cmyk_of(&fmt), false, &Interrupt::cancel_only(&|| ctl.cancelled())).0;
+ }
+ (planes, has_alpha)
+ } else {
+ (placeholder_planes(doc, &fmt), false)
+ };
let n = doc.size.area() as usize;
if !has_alpha {
planes.truncate(cc * n * sample.bytes());
@@ -1623,7 +1660,7 @@ fn document_to_psd_nested(doc: &Document, opts: &PsdExportOptions, depth: u32, c
if let Some(Some(data)) = slices_resource {
resources.push(ImageResource::new(crate::slices_map::SLICES, data));
}
- resources.push(version_info_resource(true));
+ resources.push(version_info_resource(real_merged));
let has_layers = !ex.records.is_empty();
let placement = match (has_layers, sample) {
diff --git a/crates/io/src/tiff_layers.rs b/crates/io/src/tiff_layers.rs
index 3142bc1a8..0aca0fe88 100644
--- a/crates/io/src/tiff_layers.rs
+++ b/crates/io/src/tiff_layers.rs
@@ -201,7 +201,8 @@ pub(crate) fn export_layered(doc: &Document, opts: &ExportOptions, ctl: &photocr
let big = doc.size.width > 30_000 || doc.size.height > 30_000;
// The PSD exporter renders the composite we need for the TIFF itself: unmatted (the TIFF
// keeps straight alpha) and uncompressed (its planes are interleaved below).
- let psd_opts = PsdExportOptions { force_psb: opts.force_psb || big, merged_matte: false, merged_compression: Compression::Raw };
+ let psd_opts =
+ PsdExportOptions { force_psb: opts.force_psb || big, merged_matte: false, merged_compression: Compression::Raw, maximize_compatibility: true };
let (file, w) = crate::with_span(ctl, 0.0, TIFF_MODEL_DONE, |ctl| crate::psd_export::document_to_psd_interruptible(doc, &psd_opts, ctl));
// A cancelled conversion stops early with an incomplete model: never encode it.
ctl.check().map_err(|_| IoError::Cancelled)?;
diff --git a/crates/io/tests/psd_maximize_compatibility.rs b/crates/io/tests/psd_maximize_compatibility.rs
new file mode 100644
index 000000000..c8f277f6e
--- /dev/null
+++ b/crates/io/tests/psd_maximize_compatibility.rs
@@ -0,0 +1,115 @@
+//! Preferences › File Handling › Maximize PSD and PSB File Compatibility: turned off, a layered
+//! PSD/PSB stores Photoshop's white placeholder instead of the merged image and says so in
+//! resource 1057 (`has_real_merged_data = false`). Layers, alpha channels and the Quick Mask are
+//! written as usual, so the file reopens the same.
+
+use photocraft_color::{ColorMode, PixelFormat, SampleType};
+use photocraft_doc::{AlphaChannel, Document, Layer};
+use photocraft_geom::{Rect, Size};
+use photocraft_io::{ExportOptions, export, import};
+use photocraft_psd::PsdFile;
+use photocraft_raster::Surface;
+
+fn compat_off() -> ExportOptions {
+ ExportOptions { psd_maximize_compatibility: false, ..Default::default() }
+}
+
+fn parse(bytes: &[u8]) -> PsdFile {
+ PsdFile::from_bytes(bytes).expect("parse")
+}
+
+/// A `w`×`h` document of `mode`/`depth` holding one layer of `rgba` over the whole canvas.
+fn filled(mode: ColorMode, depth: SampleType, w: u32, h: u32, rgba: [f32; 4]) -> Document {
+ let mut d = Document::new("compat", Size::new(w, h), mode, depth);
+ let fmt = d.pixel_format();
+ let mut px = vec![0.0; fmt.channels()];
+ photocraft_raster::from_rgba_into(&fmt, rgba, &mut px);
+ let mut layer = Layer::raster("pixels", fmt);
+ layer.surface_mut().unwrap().fill_rect(Rect::new(0, 0, w as i32, h as i32), &px);
+ d.layers.push(layer);
+ d
+}
+
+/// An 8-bit RGB document whose layer is seeded noise, alpha included: its merged image barely
+/// compresses, unlike the placeholder.
+fn noisy(w: u32, h: u32) -> Document {
+ let mut d = Document::new("noise", Size::new(w, h), ColorMode::Rgb, SampleType::U8);
+ let fmt = d.pixel_format();
+ let mut state = 0x2545_f491_u32;
+ let mut next = || {
+ state ^= state << 13;
+ state ^= state >> 17;
+ state ^= state << 5;
+ (state & 0xff) as f32 / 255.0
+ };
+ let vals: Vec<f32> = (0..(w * h) as usize * fmt.channels()).map(|_| next()).collect();
+ let mut layer = Layer::raster("noise", fmt);
+ layer.surface_mut().unwrap().write_region(Rect::new(0, 0, w as i32, h as i32), &vals);
+ d.layers.push(layer);
+ d
+}
+
+#[test]
+fn off_writes_the_white_placeholder_and_flags_it() {
+ let d = noisy(96, 64);
+ for name in ["x.psd", "x.psb"] {
+ let no_previews = |o: ExportOptions| ExportOptions { image_previews: false, ..o };
+ let on = export(&d, name, &no_previews(ExportOptions::default())).unwrap();
+ let off = export(&d, name, &no_previews(compat_off())).unwrap();
+ let (real, placeholder) = (parse(&on.bytes), parse(&off.bytes));
+ assert_eq!(real.has_real_merged_data(), Some(true), "{name}");
+ assert_eq!(placeholder.has_real_merged_data(), Some(false), "{name}");
+ assert!(real.merged_has_alpha() && !placeholder.merged_has_alpha(), "{name}: the placeholder has no alpha");
+ assert!(placeholder.composite_rgba8().unwrap().data.iter().all(|&b| b == 255), "{name}: opaque white");
+ assert_eq!(real.layers(), placeholder.layers(), "{name}: the layers are written the same");
+ assert!(off.bytes.len() * 3 < on.bytes.len() * 2, "{name}: {} bytes without the merged image, {} with it", off.bytes.len(), on.bytes.len());
+ }
+}
+
+/// The placeholder is exactly the white a real merged image would store, in every colour model
+/// and depth PSD has: CMYK white is no ink, Lab white is L 100 with neutral a*/b*.
+#[test]
+fn the_placeholder_is_the_white_a_real_merged_image_stores() {
+ use ColorMode::{Cmyk, Grayscale, Lab, Rgb};
+ use SampleType::{F32, U8, U16};
+ for (mode, depth) in
+ [(Rgb, U8), (Rgb, U16), (Rgb, F32), (Grayscale, U8), (Grayscale, U16), (Grayscale, F32), (Cmyk, U8), (Cmyk, U16), (Lab, U8), (Lab, U16)]
+ {
+ let d = filled(mode, depth, 9, 5, [1.0; 4]);
+ let real = parse(&export(&d, "x.psd", &ExportOptions::default()).unwrap().bytes);
+ let placeholder = parse(&export(&d, "x.psd", &compat_off()).unwrap().bytes);
+ assert_eq!(placeholder.has_real_merged_data(), Some(false), "{mode:?} {depth:?}");
+ assert!(!real.merged_has_alpha(), "{mode:?} {depth:?}: an opaque document");
+ assert_eq!(placeholder.header, real.header, "{mode:?} {depth:?}");
+ assert_eq!(placeholder.decode_merged().unwrap(), real.decode_merged().unwrap(), "{mode:?} {depth:?}");
+ }
+}
+
+#[test]
+fn layers_and_alpha_channels_reopen_unchanged() {
+ let mut d = noisy(32, 16);
+ let mut selection = Surface::new(PixelFormat::new(ColorMode::Grayscale, SampleType::U8, false));
+ selection.fill_rect(Rect::new(0, 0, 10, 16), &[1.0]);
+ d.channels.push(AlphaChannel::new("Alpha 1", selection.clone()));
+ d.quick_mask = Some(AlphaChannel::new("Quick Mask", selection));
+ let reopen = |opts: &ExportOptions| {
+ let r = import("x.psd", &export(&d, "x.psd", opts).unwrap().bytes).unwrap();
+ assert!(r.warnings.is_empty(), "{:?}", r.warnings);
+ r.document
+ };
+ let (on, off) = (reopen(&ExportOptions::default()), reopen(&compat_off()));
+ assert_eq!(off.layers.len(), 1);
+ assert_eq!(off.channels, on.channels, "alpha channels follow the placeholder");
+ assert_eq!(off.quick_mask, on.quick_mask);
+ let canvas = d.bounds();
+ assert_eq!(photocraft_compose::render(&off, canvas).px, photocraft_compose::render(&on, canvas).px, "the same image");
+}
+
+/// Without layer records the merged image is the only copy of the pixels, so it stays real.
+#[test]
+fn a_file_without_layers_keeps_its_real_merged_image() {
+ let d = Document::new("empty", Size::new(8, 8), ColorMode::Rgb, SampleType::U8);
+ let file = parse(&export(&d, "x.psd", &compat_off()).unwrap().bytes);
+ assert!(file.layers().is_empty());
+ assert_eq!(file.has_real_merged_data(), Some(true));
+}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 5e54fd274..1092f4081 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -250,11 +250,23 @@ pub struct ExportSettings {
/// PSD/PSB: embed a thumbnail (Preferences › File Handling › Image Previews; see
/// [`PhotocraftApp::save_settings`]).
pub image_previews: bool,
+ /// PSD/PSB: write the real merged image (Preferences › File Handling › Maximize PSD and PSB
+ /// File Compatibility; see [`PhotocraftApp::save_settings`]).
+ pub psd_maximize_compatibility: bool,
}
impl Default for ExportSettings {
fn default() -> Self {
- ExportSettings { jpeg_quality: None, webp_lossless: true, webp_quality: None, tiff_layers: true, xmp_all: true, tga_bits: None, image_previews: true }
+ ExportSettings {
+ jpeg_quality: None,
+ webp_lossless: true,
+ webp_quality: None,
+ tiff_layers: true,
+ xmp_all: true,
+ tga_bits: None,
+ image_previews: true,
+ psd_maximize_compatibility: true,
+ }
}
}
@@ -1315,13 +1327,16 @@ impl PhotocraftApp {
}
/// What a save writes by default under the preferences: File Handling › Image Previews
- /// decides whether a PSD/PSB gets its thumbnail. Ask When Saving has no Save As checkbox
- /// here yet, so it saves the preview, as Photoshop's checkbox starts on. A JPEG or WebP
- /// is written the way the active document's file was (its JPEG quality, a WebP lossy at
- /// its quality or lossless), as Photoshop's Save and Save As options start there.
+ /// decides whether a PSD/PSB gets its thumbnail, and Maximize PSD and PSB File Compatibility
+ /// whether it gets its real merged image. Ask When Saving has no dialog here yet, so it saves
+ /// both, as Photoshop's checkboxes start on. A JPEG or WebP is written the way the active
+ /// document's file was (its JPEG quality, a WebP lossy at its quality or lossless), as
+ /// Photoshop's Save and Save As options start there.
pub(crate) fn save_settings(&self) -> ExportSettings {
- let previews = self.session.prefs().file_handling.image_previews != photocraft_engine::prefs::Ask::Never;
- let mut settings = ExportSettings { image_previews: previews, ..ExportSettings::default() };
+ let file_handling = &self.session.prefs().file_handling;
+ let previews = file_handling.image_previews != photocraft_engine::prefs::Ask::Never;
+ let maximize = file_handling.maximize_psd_compatibility != photocraft_engine::prefs::Ask::Never;
+ let mut settings = ExportSettings { image_previews: previews, psd_maximize_compatibility: maximize, ..ExportSettings::default() };
if let Some(st) = self.session.active() {
let e = &st.doc.file_encoding;
settings.jpeg_quality = e.jpeg_quality.map(|q| q.clamp(1, 100));
diff --git a/crates/ui-egui/src/save_identity_tests.rs b/crates/ui-egui/src/save_identity_tests.rs
index c0cd85eae..c947afc9b 100644
--- a/crates/ui-egui/src/save_identity_tests.rs
+++ b/crates/ui-egui/src/save_identity_tests.rs
@@ -205,6 +205,29 @@ fn image_previews_preference_reaches_the_exporter() {
}
}
+/// Preferences › File Handling › Maximize PSD and PSB File Compatibility reaches the exporter of
+/// Save As, Save and automation saves: Always and Ask When Saving keep the PSD's real merged
+/// image, Never doesn't.
+#[test]
+fn maximize_compatibility_preference_reaches_the_exporter() {
+ let seen = Rc::new(RefCell::new(Vec::new()));
+ let mut app = app();
+ let log = seen.clone();
+ app.services.export = Some(Box::new(move |_, _, settings: &ExportSettings| {
+ log.borrow_mut().push(settings.psd_maximize_compatibility);
+ Ok((b"out".to_vec(), Vec::new()))
+ }));
+ let ctx = egui::Context::default();
+ for (value, expect) in [("always", true), ("never", false), ("ask", true)] {
+ app.run("prefs.set", json!({"path": "fileHandling.maximizePsdCompatibility", "value": value})).unwrap();
+ seen.borrow_mut().clear();
+ menus::invoke(&mut app, &ctx, "file.saveAs", json!({"path": format!("{value}.psd")})).unwrap();
+ menus::invoke(&mut app, &ctx, "file.save", json!({})).unwrap();
+ app.save_automation(Some(format!("{value} agent.psd"))).unwrap();
+ assert_eq!(*seen.borrow(), [expect; 3], "{value}");
+ }
+}
+
/// #2399: Save and Save As start at the opened file's own encoding: a JPEG's estimated quality,
/// a WebP lossy (at its quality) or lossless; a new document keeps the codec defaults.
#[test]
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 31ded86f2..d2ee641b1 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 6 | 13 | 8 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 |
| [Tools](#tools) | 28 | 14 | 1 | |
-| [Workspace and UI](#workspace-and-ui) | 13 | 5 | 5 | settings that do nothing: 27 of 156 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 13 | 5 | 5 | settings that do nothing: 26 of 156 (target 0) |
| [Type](#type) | 4 | 2 | 3 | |
| [Automation](#automation) | 5 | 2 | 4 | 631 of 631 menu items live (100.0%) |
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present |
@@ -176,9 +176,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
-**Settings that do nothing: 27 of 156** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
+**Settings that do nothing: 26 of 156** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
-Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `file_handling.save_in_background`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
+Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `file_handling.save_in_background`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|