Skip to content

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

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

Alex Gorevski2c02d41eaf25
diff --git a/crates/ui-egui/src/chrome_ui.rs b/crates/ui-egui/src/chrome_ui.rs
index bec143bac..dd3bbf86b 100644
--- a/crates/ui-egui/src/chrome_ui.rs
+++ b/crates/ui-egui/src/chrome_ui.rs
@@ -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();
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 9f4ee8a93..7f3fe278c 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -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
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 63ebbd954..8e399e4b3 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -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
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 9ce3867fb..6ee1b67d0 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -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
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 8e6226182..f8beb7247 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -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 — удалить
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index d5f0672ad..181f71d6e 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -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
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 3bac4fb82..a6198321e 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -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