Show active ICC profile in the status bar (#321) (#432)

* Show active ICC profile in status bar (#321)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f77709e9-6475-4953-ab57-b78347b4499d

* Fix active profile status review feedback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e5e4c3e6-e406-4010-b05d-5042f9f4e4fc

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f77709e9-6475-4953-ab57-b78347b4499d
Copilot-Session: e5e4c3e6-e406-4010-b05d-5042f9f4e4fc
This commit is contained in:
Alex Gorevski 2026-10-07 04:08:51 -07:00 committed by GitHub
parent d07eecf66f
commit 2c02d41eaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 68 additions and 3 deletions

View File

@ -101,10 +101,22 @@ pub fn status_info_text(doc: &Document, key: &str, tool: &str, profile: &str) ->
}
fn profile_name(doc: &Document) -> String {
if doc.icc_profile.is_none() {
return crate::i18n::fmt(tl!("Untagged {mode}"), &[("mode", tl!(&crate::canvas::mode_label(doc)))]);
let mode = crate::canvas::mode_label(doc);
let Some(bytes) = doc.icc_profile.as_ref() else {
return crate::i18n::fmt(tl!("Untagged {mode}"), &[("mode", tl!(mode))]);
};
let Ok(profile) = photocraft_engine::color_cmds::profile_from_bytes(bytes) else {
return crate::i18n::fmt(tl!("Invalid {mode} profile"), &[("mode", tl!(mode))]);
};
if profile.color_space != photocraft_engine::color_cmds::mode_space(doc.mode) {
return crate::i18n::fmt(tl!("Invalid {mode} profile"), &[("mode", tl!(mode))]);
}
photocraft_engine::color_cmds::document_profile(doc).description.clone()
let name: String = profile.description.chars().filter(|c| !c.is_control()).take(128).collect();
let name = name.trim();
if name.is_empty() {
return crate::i18n::fmt(tl!("Unnamed {mode} profile"), &[("mode", tl!(mode))]);
}
name.to_owned()
}
/// Status bar body (Pro): zoom %, the chosen info field and its ">" menu, then status messages.
@ -220,6 +232,47 @@ mod tests {
assert!(status_info_text(&d, "profile", "", "sRGB IEC61966-2.1").ends_with("(8bpc)"));
}
#[test]
fn status_profile_describes_rgb_gray_and_custom_profiles_without_mutating_the_document() {
let mut rgb = doc();
rgb.icc_profile = Some(photocraft_engine::color_cmds::working_profile(rgb.mode).to_bytes());
let before = rgb.icc_profile.clone();
assert_eq!(profile_name(&rgb), "sRGB IEC61966-2.1");
assert_eq!(status_info_text(&rgb, "profile", "", &profile_name(&rgb)), "sRGB IEC61966-2.1 (8bpc)");
assert_eq!(rgb.icc_profile, before);
let mut gray = doc();
gray.mode = photocraft_doc::ColorMode::Grayscale;
gray.icc_profile = Some(photocraft_engine::color_cmds::working_profile(gray.mode).to_bytes());
assert_eq!(profile_name(&gray), "sGray (sRGB tone curve, Photocraft)");
let mut custom = (*photocraft_engine::color_cmds::working_profile(photocraft_doc::ColorMode::Cmyk)).clone();
custom.description = "PhotoCraft Studio CMYK".into();
let mut custom_doc = doc();
custom_doc.mode = photocraft_doc::ColorMode::Cmyk;
custom_doc.icc_profile = Some(custom.with_encoded_bytes().to_bytes());
assert_eq!(profile_name(&custom_doc), "PhotoCraft Studio CMYK");
}
#[test]
fn status_profile_falls_back_for_malformed_unnamed_and_mismatched_profiles() {
let mut malformed = doc();
malformed.icc_profile = Some(std::sync::Arc::new(vec![1, 2, 3]));
assert_eq!(profile_name(&malformed), "Invalid RGB profile");
let mut unnamed_profile = (*photocraft_engine::color_cmds::working_profile(photocraft_doc::ColorMode::Cmyk)).clone();
unnamed_profile.description.clear();
let mut unnamed = doc();
unnamed.mode = photocraft_doc::ColorMode::Cmyk;
unnamed.icc_profile = Some(unnamed_profile.with_encoded_bytes().to_bytes());
assert_eq!(profile_name(&unnamed), "Unnamed CMYK profile");
let mut mismatched = doc();
mismatched.mode = photocraft_doc::ColorMode::Grayscale;
mismatched.icc_profile = Some(photocraft_engine::color_cmds::working_profile(photocraft_doc::ColorMode::Rgb).to_bytes());
assert_eq!(profile_name(&mismatched), "Invalid Gray profile");
}
#[test]
fn document_sizes_match_photoshop_rounding() {
let d = doc();

View File

@ -1682,6 +1682,8 @@
Doc: {flat}/{layered} Dok.: {flat}/{layered}
Scratch: {size} Odkládací: {size}
Untagged {mode} {mode} bez profilu
Invalid {mode} profile Neplatný profil {mode}
Unnamed {mode} profile Bezejmenný profil {mode}
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
Resolution: {dpi} pixels/inch Rozlišení: {dpi} pixelů/palec
Doc: {w} × {h} px Dok.: {w} × {h} px

Can't render this file because it contains an unexpected character in line 6 and column 47.

View File

@ -1667,6 +1667,8 @@
Doc: {flat}/{layered} Doc: {flat}/{layered}
Scratch: {size} Temporal: {size}
Untagged {mode} Sin etiquetar {mode}
Invalid {mode} profile Perfil {mode} no válido
Unnamed {mode} profile Perfil {mode} sin nombre
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
Resolution: {dpi} pixels/inch Resolución: {dpi} píxeles/pulgada
Doc: {w} × {h} px Doc: {w} × {h} px

Can't render this file because it contains an unexpected character in line 4 and column 47.

View File

@ -1672,6 +1672,8 @@
Doc: {flat}/{layered} ドキュメント: {flat}/{layered}
Scratch: {size} スクラッチ: {size}
Untagged {mode} タグなし {mode}
Invalid {mode} profile 無効な {mode} プロファイル
Unnamed {mode} profile 名前のない {mode} プロファイル
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
Resolution: {dpi} pixels/inch 解像度: {dpi} ピクセル/インチ
Doc: {w} × {h} px ドキュメント: {w} × {h} px

Can't render this file because it contains an unexpected character in line 6 and column 47.

View File

@ -1403,6 +1403,8 @@
{name} options Параметры: {name}
Align {what} Выровнять: {what}
Untagged {mode} Без профиля ({mode})
Invalid {mode} profile Недопустимый профиль {mode}
Unnamed {mode} profile Безымянный профиль {mode}
Constraints ({n}) Ограничения ({n})
Count: {n} Счёт: {n}
Click to add a point · drag off or {key}-click or Delete to remove Щёлкните, чтобы добавить точку · уведите или {key}-клик, либо Delete — удалить

Can't render this file because it contains an unexpected character in line 6 and column 47.

View File

@ -1679,6 +1679,8 @@
Doc: {flat}/{layered} 文档:{flat}/{layered}
Scratch: {size} 暂存:{size}
Untagged {mode} 未标记的 {mode}
Invalid {mode} profile 无效的 {mode} 配置文件
Unnamed {mode} profile 未命名的 {mode} 配置文件
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
Resolution: {dpi} pixels/inch 分辨率:{dpi} 像素/英寸
Doc: {w} × {h} px 文档:{w} × {h} px

Can't render this file because it has a wrong number of fields in line 13.

View File

@ -1669,6 +1669,8 @@
Doc: {flat}/{layered} 文件:{flat}/{layered}
Scratch: {size} 暫存:{size}
Untagged {mode} 未標記的 {mode}
Invalid {mode} profile 無效的 {mode} 描述檔
Unnamed {mode} profile 未命名的 {mode} 描述檔
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
Resolution: {dpi} pixels/inch 解析度:{dpi} 像素/英吋
Doc: {w} × {h} px 文件:{w} × {h} px

Can't render this file because it contains an unexpected character in line 6 and column 47.