From 13a3c3acaae86a44ae43cd82833eeddab72fbe52 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:59:00 +0100 Subject: [PATCH] Leave the profile out of an Indexed PSD when Include ICC Profile is off An Indexed Color document is written over its colour table by palette_map, which adds its RGB profile (resource 1039) and returned before the embed_icc check, so Layers to Files with Include ICC Profile off still wrote the profile into an Indexed document's PSD or PSB (#13973). That path now drops the resource when embed_icc is off. Indexed PNG, BMP and GIF never carry a profile, and its JPEG and flat and layered TIFF already followed the setting; the new test covers them too. --- .../file_cmds/layers_to_files_icc_tests.rs | 22 +++++++++++++++++++ crates/io/src/psd_export/document.rs | 6 ++++- crates/io/src/psd_export/tests.rs | 20 +++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/crates/engine-core/src/cmd/file_cmds/layers_to_files_icc_tests.rs b/crates/engine-core/src/cmd/file_cmds/layers_to_files_icc_tests.rs index a32b976b1c..19f2b9c24e 100644 --- a/crates/engine-core/src/cmd/file_cmds/layers_to_files_icc_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/layers_to_files_icc_tests.rs @@ -159,3 +159,25 @@ fn off_keeps_a_cmyk_documents_own_profile_for_its_colours() { assert!(s.active().unwrap().doc.icc_profile.is_some(), "the document keeps its profile"); } } + +/// An Indexed Color document with an RGB profile: `iccProfile: false` writes no profile in any file, +/// the PSD included, which is written over its colour table (CodeRabbit on #16653), and the +/// layered TIFF; `true` keeps it in the PSD. +#[test] +fn an_indexed_documents_files_follow_the_setting() { + let mut s = session("rgb", 8); + s.execute("edit.assignProfile", json!({"profile": "adobe-rgb-compat"})).unwrap(); + s.execute("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "dither": "none", "transparency": false})).unwrap(); + // The conversion flattens: a normal layer again (#13968). + s.execute("layer.new.layerFromBackground", json!({})).unwrap(); + let doc = &s.active().unwrap().doc; + assert_eq!(doc.mode, ColorMode::Indexed); + assert!(doc.icc_profile.is_some(), "the document keeps its profile"); + assert!(doc.layers.iter().any(|l| !doc.is_background(l.id)), "a layer to export"); + for format in ["png", "jpg", "tif", "psd", "bmp"] { + assert!(profiles(&mut s, format, json!({"iccProfile": false})).iter().all(|(_, icc)| icc.is_none()), "indexed {format}: no profile"); + } + let layered = profiles(&mut s, "tif", json!({"iccProfile": false, "tiffLayers": true})); + assert!(layered.iter().all(|(_, icc)| icc.is_none()), "indexed layered tif: no profile"); + assert_eq!(one(&mut s, "psd", json!({"iccProfile": true})).1, Some("RGB".into()), "indexed psd: the profile"); +} diff --git a/crates/io/src/psd_export/document.rs b/crates/io/src/psd_export/document.rs index 80c2377ccf..8c2f8f6d97 100644 --- a/crates/io/src/psd_export/document.rs +++ b/crates/io/src/psd_export/document.rs @@ -66,7 +66,11 @@ fn document_to_psd_sized_with_patterns( if doc.mode == ColorMode::Multichannel { return crate::multichannel_map::document_to_psd(doc, opts.force_psb, layerless_limit, patterns); } - if let Some(file) = crate::palette_map::document_to_psd(doc, opts.force_psb, layerless_limit, patterns)? { + if let Some(mut file) = crate::palette_map::document_to_psd(doc, opts.force_psb, layerless_limit, patterns)? { + // An Indexed document's RGB profile is written there too; Include ICC Profile off leaves it out. + if !opts.embed_icc { + file.0.resources.retain(|r| r.id != ids::ICC_PROFILE); + } return Ok(file); } let fmt = doc.pixel_format(); diff --git a/crates/io/src/psd_export/tests.rs b/crates/io/src/psd_export/tests.rs index 19819be3f8..89c8b16479 100644 --- a/crates/io/src/psd_export/tests.rs +++ b/crates/io/src/psd_export/tests.rs @@ -875,3 +875,23 @@ fn embed_icc_off_writes_no_profile_resource() { assert!(!has(&PsdExportOptions { embed_icc: false, ..Default::default() })); assert!(doc.icc_profile.is_some()); } + +/// An Indexed Color document is written over its colour table (`palette_map`): `embed_icc: false` +/// leaves its RGB profile out there too, as PSD and as PSB (CodeRabbit on #16653). +#[test] +fn embed_icc_off_writes_no_profile_resource_for_an_indexed_document() { + let white = photocraft_color::Color::rgba(1.0, 1.0, 1.0, 1.0); + let mut doc = Document::with_background("indexed", photocraft_geom::Size::new(4, 4), ColorMode::Rgb, SampleType::U8, white); + doc.mode = ColorMode::Indexed; + doc.color_table = Some(photocraft_doc::ColorTable { colors: vec![[255, 255, 255], [0, 0, 0]], transparent: None }); + doc.icc_profile = Some(std::sync::Arc::new(craft_cms::Builtin::Srgb.profile().to_bytes().to_vec())); + for force_psb in [false, true] { + let written = |embed_icc| document_to_psd_with(&doc, &PsdExportOptions { embed_icc, force_psb, ..Default::default() }).unwrap().0; + let on = written(true); + assert_eq!(on.header.color_mode, PsdMode::Indexed, "psb {force_psb}"); + assert!(on.resources.iter().any(|r| r.id == ids::ICC_PROFILE), "psb {force_psb}: on"); + let off = written(false); + assert_eq!((off.header.color_mode, off.header.version == Version::Psb), (PsdMode::Indexed, force_psb)); + assert!(!off.resources.iter().any(|r| r.id == ids::ICC_PROFILE), "psb {force_psb}: off"); + } +}