properties_view: Show ICC profile or CICP

Closes #510
This commit is contained in:
Sophie Herold 2026-07-07 13:52:08 +02:00
parent b5cf827585
commit 2112f87168
7 changed files with 158 additions and 24 deletions

41
Cargo.lock generated
View file

@ -946,8 +946,8 @@ dependencies = [
[[package]] [[package]]
name = "glycin" name = "glycin"
version = "4.0.0-alpha.1" version = "4.0.0-alpha.7"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"glycin-builtin", "glycin-builtin",
"glycin-external", "glycin-external",
@ -955,8 +955,8 @@ dependencies = [
[[package]] [[package]]
name = "glycin-builtin" name = "glycin-builtin"
version = "4.0.0-alpha.1" version = "4.0.0-alpha.7"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"glycin-core", "glycin-core",
] ]
@ -964,7 +964,7 @@ dependencies = [
[[package]] [[package]]
name = "glycin-common" name = "glycin-common"
version = "2.0.0-alpha.1" version = "2.0.0-alpha.1"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"bitflags 2.13.0", "bitflags 2.13.0",
"gufo-common", "gufo-common",
@ -981,8 +981,8 @@ dependencies = [
[[package]] [[package]]
name = "glycin-core" name = "glycin-core"
version = "4.0.0-alpha.1" version = "4.0.0-alpha.7"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"async-fs", "async-fs",
"async-global-executor", "async-global-executor",
@ -1019,16 +1019,16 @@ dependencies = [
[[package]] [[package]]
name = "glycin-external" name = "glycin-external"
version = "4.0.0-alpha.1" version = "4.0.0-alpha.7"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"glycin-core", "glycin-core",
] ]
[[package]] [[package]]
name = "glycin-image-rs" name = "glycin-image-rs"
version = "2.2.0-alpha.6" version = "2.2.0-alpha.7"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"exr", "exr",
@ -1050,7 +1050,7 @@ dependencies = [
[[package]] [[package]]
name = "glycin-utils" name = "glycin-utils"
version = "5.0.0-alpha.1" version = "5.0.0-alpha.1"
source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=32083724ee730fb6b35b6382fb8af7b6ab1f2992#32083724ee730fb6b35b6382fb8af7b6ab1f2992" source = "git+https://gitlab.gnome.org/GNOME/glycin.git?rev=882965515fc0de4f00f52318f2c35098a76855c9#882965515fc0de4f00f52318f2c35098a76855c9"
dependencies = [ dependencies = [
"async-lock", "async-lock",
"bitflags 2.13.0", "bitflags 2.13.0",
@ -1196,7 +1196,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo" name = "gufo"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"chrono", "chrono",
"gufo-common", "gufo-common",
@ -1213,7 +1213,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-common" name = "gufo-common"
version = "2.0.0-alpha.2" version = "2.0.0-alpha.2"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"chrono", "chrono",
"paste", "paste",
@ -1239,7 +1239,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-exif" name = "gufo-exif"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"chrono", "chrono",
"gufo-common", "gufo-common",
@ -1267,7 +1267,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-jpeg" name = "gufo-jpeg"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"gufo-common", "gufo-common",
"indexmap", "indexmap",
@ -1279,7 +1279,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-png" name = "gufo-png"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"encoding_rs", "encoding_rs",
@ -1292,7 +1292,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-tiff" name = "gufo-tiff"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"gufo-common", "gufo-common",
"thiserror", "thiserror",
@ -1301,7 +1301,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-webp" name = "gufo-webp"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"gufo-common", "gufo-common",
"thiserror", "thiserror",
@ -1310,7 +1310,7 @@ dependencies = [
[[package]] [[package]]
name = "gufo-xmp" name = "gufo-xmp"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.4"
source = "git+https://github.com/gufo-rs/gufo.git#2079c478a108141d4507e93d2d74360b353f5d83" source = "git+https://github.com/gufo-rs/gufo.git?rev=25ae7f4d68532314fe8b43b0f27360b952d5a0b6#25ae7f4d68532314fe8b43b0f27360b952d5a0b6"
dependencies = [ dependencies = [
"chrono", "chrono",
"gufo-common", "gufo-common",
@ -1653,6 +1653,7 @@ dependencies = [
"libadwaita", "libadwaita",
"libc", "libc",
"libgweather", "libgweather",
"moxcms",
"strum", "strum",
"thiserror", "thiserror",
"tracing", "tracing",

View file

@ -6,9 +6,9 @@ rust-version = "1.93"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
[patch.crates-io] [patch.crates-io]
glycin = { git = "https://gitlab.gnome.org/GNOME/glycin.git", rev = "32083724ee730fb6b35b6382fb8af7b6ab1f2992" } glycin = { git = "https://gitlab.gnome.org/GNOME/glycin.git", rev = "882965515fc0de4f00f52318f2c35098a76855c9" }
gufo = { git = "https://github.com/gufo-rs/gufo.git" } gufo = { git = "https://github.com/gufo-rs/gufo.git", rev = "25ae7f4d68532314fe8b43b0f27360b952d5a0b6" }
gufo-common = { git = "https://github.com/gufo-rs/gufo.git" } gufo-common = { git = "https://github.com/gufo-rs/gufo.git", rev = "25ae7f4d68532314fe8b43b0f27360b952d5a0b6" }
[profile.release] [profile.release]
lto = true lto = true
@ -17,6 +17,9 @@ codegen-units = 1
[features] [features]
x11 = ["ashpd/gtk4_x11"] x11 = ["ashpd/gtk4_x11"]
[lints.clippy]
dbg_macro = "warn"
[dependencies] [dependencies]
adw = { package = "libadwaita", version = "0.9.0", features = ["v1_8"] } adw = { package = "libadwaita", version = "0.9.0", features = ["v1_8"] }
anyhow = { version = "1.0.66" } anyhow = { version = "1.0.66" }
@ -43,6 +46,7 @@ gvdb-macros = "0.1.6"
indexmap = "2.0.0" indexmap = "2.0.0"
libc = "0.2.158" libc = "0.2.158"
libgweather = "4.8.0" libgweather = "4.8.0"
moxcms = "0.8.1"
strum = { version = "0.28.0", features = ["derive"] } strum = { version = "0.28.0", features = ["derive"] }
thiserror = "2.0.3" thiserror = "2.0.3"
tracing = "0.1.44" tracing = "0.1.44"

View file

@ -0,0 +1 @@
Show ICC profile description or generated CICP description if applicable.

View file

@ -28,6 +28,7 @@ use chrono::prelude::*;
pub use file::FileInfo; pub use file::FileInfo;
use glib::TimeZone; use glib::TimeZone;
use glycin::{Frame, FrameDetails, ImageDetails, MemoryFormat}; use glycin::{Frame, FrameDetails, ImageDetails, MemoryFormat};
use gufo::common::cicp;
use gufo::common::datetime::DateTime; use gufo::common::datetime::DateTime;
use gufo::common::orientation::Orientation; use gufo::common::orientation::Orientation;
use gufo::common::physical_dimension; use gufo::common::physical_dimension;
@ -44,6 +45,8 @@ pub struct Metadata {
image_info: Option<glycin::ImageDetails>, image_info: Option<glycin::ImageDetails>,
frame_info: Option<FrameDetails>, frame_info: Option<FrameDetails>,
memory_format: Option<MemoryFormat>, memory_format: Option<MemoryFormat>,
icc_profile: Option<moxcms::ColorProfile>,
cicp: Option<cicp::Cicp>,
} }
impl Metadata { impl Metadata {
@ -87,6 +90,17 @@ impl Metadata {
pub fn set_frame_metadata(&mut self, frame: &Frame) { pub fn set_frame_metadata(&mut self, frame: &Frame) {
self.frame_info = Some(frame.details().clone()); self.frame_info = Some(frame.details().clone());
self.memory_format = Some(frame.memory_format()); self.memory_format = Some(frame.memory_format());
if let Some(iccp) = frame.details().color_icc_profile() {
match moxcms::ColorProfile::new_from_slice(iccp) {
Err(err) => {
tracing::warn!("Couldn't parse color profile: {err}");
}
Ok(profile) => {
self.icc_profile = Some(profile);
}
}
}
self.cicp = frame.details().color_cicp();
} }
pub fn set_file_info(&mut self, file_info: FileInfo) { pub fn set_file_info(&mut self, file_info: FileInfo) {
@ -116,6 +130,12 @@ impl Metadata {
if self.memory_format.is_none() { if self.memory_format.is_none() {
self.memory_format = other.memory_format; self.memory_format = other.memory_format;
} }
if self.icc_profile.is_none() {
self.icc_profile = other.icc_profile;
}
if self.cicp.is_none() {
self.cicp = other.cicp;
}
} }
pub fn mime_type(&self) -> Option<String> { pub fn mime_type(&self) -> Option<String> {
@ -435,4 +455,86 @@ impl Metadata {
pub fn physical_size(&self) -> Option<physical_dimension::PhysicalSize> { pub fn physical_size(&self) -> Option<physical_dimension::PhysicalSize> {
self.frame_info.as_ref().and_then(|x| x.physical_size()) self.frame_info.as_ref().and_then(|x| x.physical_size())
} }
pub fn icc_profile_description(&self) -> Option<String> {
if self.prefer_cicp() && self.cicp.is_some() {
return None;
}
if let Some(icc_profile) = &self.icc_profile {
icc_profile.description.as_ref().and_then(Self::icc_string)
} else {
None
}
}
fn icc_string(text: &moxcms::ProfileText) -> Option<String> {
let s = match text {
moxcms::ProfileText::Description(desc) => Some(desc.unicode_string.clone()),
moxcms::ProfileText::Localizable(local) => local.first().map(|x| x.value.clone()),
moxcms::ProfileText::PlainString(s) => Some(s.to_owned()),
};
if let Some(s) = s {
let s = s.trim().replace('\0', "");
if s.is_empty() { None } else { Some(s) }
} else {
None
}
}
pub fn cicp_description(&self) -> Option<String> {
if !self.prefer_cicp() && self.icc_profile.is_some() {
return None;
}
if let Some(cicp) = self.cicp {
let primaries = match cicp.color_primaries {
cicp::ColorPrimaries::DciP3 => gettext("DCI P3"),
cicp::ColorPrimaries::DisplayP3 => gettext("Display P3"),
cicp::ColorPrimaries::Rec2020 => gettext("Rec.2020"),
cicp::ColorPrimaries::Srgb => gettext("sRGB"),
cicp::ColorPrimaries::Unspecified => gettext("Unspecified"),
cicp::ColorPrimaries::Unknown(n) => gettext_f("Unknown ({})", [n.to_string()]),
_ => String::new(),
};
let coefficients = match cicp.matrix_coefficients {
cicp::MatrixCoefficients::Identity => None,
cicp::MatrixCoefficients::ICtCp => Some(gettext("ICtCp")),
cicp::MatrixCoefficients::Unspecified => Some(gettext("Unspecified")),
cicp::MatrixCoefficients::Unknown(n) => {
Some(gettext_f("Unknown ({})", [n.to_string()]))
}
_ => None,
};
let transfer = match cicp.transfer_characteristics {
cicp::TransferCharacteristics::Dci => gettext("DCI"),
cicp::TransferCharacteristics::Pq => gettext("PQ"),
cicp::TransferCharacteristics::Gamma24 => gettext("Gamma 2.4"),
cicp::TransferCharacteristics::Unknown(n) => {
gettext_f("Unknown ({})", [n.to_string()])
}
_ => String::new(),
};
if let Some(coefficients) = coefficients {
Some(format!("{primaries}, {transfer}, {coefficients}"))
} else {
Some(format!("{primaries}, {transfer}"))
}
} else {
None
}
}
pub fn prefer_cicp(&self) -> bool {
!matches!(
self.frame_info
.as_ref()
.map(|x| x.color_profile_preference()),
Some(glycin::ColorProfilePreference::IccProfile)
)
}
} }

View file

@ -277,7 +277,7 @@ pub fn locale_uses_inch() -> bool {
.and_then(|x| x.get(0..2)) .and_then(|x| x.get(0..2))
&& (locale == b"US" || locale == b"LR") && (locale == b"US" || locale == b"LR")
{ {
dbg!(true) true
} else { } else {
false false
} }

View file

@ -97,6 +97,10 @@ mod imp {
lens: TemplateChild<adw::ActionRow>, lens: TemplateChild<adw::ActionRow>,
#[template_child] #[template_child]
software: TemplateChild<adw::ActionRow>, software: TemplateChild<adw::ActionRow>,
#[template_child]
icc_profile: TemplateChild<adw::ActionRow>,
#[template_child]
cicp: TemplateChild<adw::ActionRow>,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -253,6 +257,8 @@ mod imp {
Self::update_row(&self.maker_model, metadata.maker_model()), Self::update_row(&self.maker_model, metadata.maker_model()),
Self::update_row(&self.lens, metadata.lens()), Self::update_row(&self.lens, metadata.lens()),
Self::update_row(&self.software, metadata.software()), Self::update_row(&self.software, metadata.software()),
Self::update_row(&self.icc_profile, metadata.icc_profile_description()),
Self::update_row(&self.cicp, metadata.cicp_description()),
] ]
.iter() .iter()
.any(|x| *x); .any(|x| *x);

View file

@ -274,6 +274,26 @@
</style> </style>
</object> </object>
</child> </child>
<child>
<object class="AdwActionRow" id="icc_profile">
<property name="title" translatable="yes">ICC Profile</property>
<property name="subtitle-selectable">True</property>
<property name="use-markup">False</property>
<style>
<class name="property" />
</style>
</object>
</child>
<child>
<object class="AdwActionRow" id="cicp">
<property name="title" translatable="yes">CICP</property>
<property name="subtitle-selectable">True</property>
<property name="use-markup">False</property>
<style>
<class name="property" />
</style>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>