decoder: Add basic color profile support

This only covers 8bit RGB(A) JPEG, PNG, and HEIF.
Should only be a temporary solution until GTK supports
color profiles.

Closes #36

Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/172>
This commit is contained in:
Sophie Herold 2023-04-12 04:13:30 +02:00
parent 3b6cc8c404
commit e710419a22
6 changed files with 186 additions and 23 deletions

View file

@ -228,3 +228,20 @@ pub fn spawn<R: 'static, F: std::future::Future<Output = R> + 'static>(
let ctx = glib::MainContext::default();
ctx.spawn_local(f)
}
pub fn new_trafo<F: Copy>(
icc_profile: &[u8],
src_format: lcms2::PixelFormat,
) -> anyhow::Result<lcms2::Transform<F, F>> {
let src_profile = lcms2::Profile::new_icc(icc_profile)?;
let target_profile = lcms2::Profile::new_srgb();
Ok(lcms2::Transform::new(
&src_profile,
src_format,
&target_profile,
src_format,
lcms2::Intent::Perceptual,
)?)
}