1
0
Fork 0
forked from wry/wry

color-management: implement set_tf_power

This commit is contained in:
Julian Orth 2025-09-08 18:37:07 +02:00
parent a2d726e508
commit c37567f1cd
8 changed files with 121 additions and 28 deletions

View file

@ -5,6 +5,7 @@ use {
ifs::{
color_management::{
FEATURE_EXTENDED_TARGET_VOLUME, FEATURE_SET_MASTERING_DISPLAY_PRIMARIES,
FEATURE_SET_TF_POWER,
consts::{
FEATURE_PARAMETRIC, FEATURE_SET_LUMINANCES, FEATURE_SET_PRIMARIES,
FEATURE_WINDOWS_SCRGB, PRIMARIES_ADOBE_RGB, PRIMARIES_BT2020,
@ -79,6 +80,7 @@ impl WpColorManagerV1 {
self.send_supported_feature(FEATURE_SET_PRIMARIES);
self.send_supported_feature(FEATURE_SET_LUMINANCES);
self.send_supported_feature(FEATURE_SET_MASTERING_DISPLAY_PRIMARIES);
self.send_supported_feature(FEATURE_SET_TF_POWER);
self.send_supported_feature(FEATURE_EXTENDED_TARGET_VOLUME);
self.send_supported_feature(FEATURE_WINDOWS_SCRGB);
self.send_supported_tf_named(TRANSFER_FUNCTION_BT1886);

View file

@ -2,7 +2,7 @@ use {
crate::{
client::{Client, ClientError},
cmm::{
cmm_eotf::Eotf,
cmm_eotf::{Eotf, EotfPow},
cmm_luminance::{Luminance, TargetLuminance},
cmm_primaries::{NamedPrimaries, Primaries},
},
@ -125,8 +125,21 @@ impl WpImageDescriptionCreatorParamsV1RequestHandler for WpImageDescriptionCreat
Ok(())
}
fn set_tf_power(&self, _req: SetTfPower, _slf: &Rc<Self>) -> Result<(), Self::Error> {
Err(WpImageDescriptionCreatorParamsV1Error::SetTfPowerNotSupported)
fn set_tf_power(&self, req: SetTfPower, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let pow = EotfPow(req.eexp);
if pow < EotfPow::MIN || pow > EotfPow::MAX {
return Err(WpImageDescriptionCreatorParamsV1Error::SetTfPowerOutOfBounds);
}
let tf = match pow {
EotfPow::LINEAR => Eotf::Linear,
EotfPow::GAMMA22 => Eotf::Gamma22,
EotfPow::GAMMA28 => Eotf::Gamma28,
_ => Eotf::Pow(pow),
};
if self.tf.replace(Some(tf)).is_some() {
return Err(WpImageDescriptionCreatorParamsV1Error::TfAlreadySet);
}
Ok(())
}
fn set_primaries_named(
@ -259,8 +272,8 @@ pub enum WpImageDescriptionCreatorParamsV1Error {
ClientError(Box<ClientError>),
#[error("{} is not a supported named primary", .0)]
UnsupportedPrimaries(u32),
#[error("set_tf_power is not supported")]
SetTfPowerNotSupported,
#[error("The exponent is out of bounds")]
SetTfPowerOutOfBounds,
#[error("{} is not a supported named EOTF", .0)]
UnsupportedTf(u32),
#[error("The EOTF has already been set")]

View file

@ -1,7 +1,11 @@
use {
crate::{
client::Client,
cmm::{cmm_description::ColorDescription, cmm_eotf::Eotf, cmm_primaries::NamedPrimaries},
cmm::{
cmm_description::ColorDescription,
cmm_eotf::{Eotf, EotfPow},
cmm_primaries::NamedPrimaries,
},
ifs::color_management::{
MIN_LUM_MUL, PRIMARIES_ADOBE_RGB, PRIMARIES_BT2020, PRIMARIES_CIE1931_XYZ,
PRIMARIES_DCI_P3, PRIMARIES_DISPLAY_P3, PRIMARIES_GENERIC_FILM, PRIMARIES_MUL,
@ -28,17 +32,24 @@ pub struct WpImageDescriptionInfoV1 {
impl WpImageDescriptionInfoV1 {
pub fn send_description(&self, d: &ColorDescription) {
let tf = match d.eotf {
Eotf::Linear => TRANSFER_FUNCTION_EXT_LINEAR,
Eotf::St2084Pq => TRANSFER_FUNCTION_ST2084_PQ,
Eotf::Bt1886 => TRANSFER_FUNCTION_BT1886,
Eotf::Gamma22 => TRANSFER_FUNCTION_GAMMA22,
Eotf::Gamma28 => TRANSFER_FUNCTION_GAMMA28,
Eotf::St240 => TRANSFER_FUNCTION_ST240,
Eotf::Log100 => TRANSFER_FUNCTION_LOG_100,
Eotf::Log316 => TRANSFER_FUNCTION_LOG_316,
Eotf::St428 => TRANSFER_FUNCTION_ST428,
};
'tf: {
let tf = match d.eotf {
Eotf::Linear => TRANSFER_FUNCTION_EXT_LINEAR,
Eotf::St2084Pq => TRANSFER_FUNCTION_ST2084_PQ,
Eotf::Bt1886 => TRANSFER_FUNCTION_BT1886,
Eotf::Gamma22 => TRANSFER_FUNCTION_GAMMA22,
Eotf::Gamma28 => TRANSFER_FUNCTION_GAMMA28,
Eotf::St240 => TRANSFER_FUNCTION_ST240,
Eotf::Log100 => TRANSFER_FUNCTION_LOG_100,
Eotf::Log316 => TRANSFER_FUNCTION_LOG_316,
Eotf::St428 => TRANSFER_FUNCTION_ST428,
Eotf::Pow(e) => {
self.send_tf_power(e);
break 'tf;
}
};
self.send_tf_named(tf);
}
self.send_primaries(&d.linear.primaries);
if let Some(n) = d.named_primaries {
let n = match n {
@ -55,7 +66,6 @@ impl WpImageDescriptionInfoV1 {
};
self.send_primaries_named(n);
}
self.send_tf_named(tf);
self.send_luminances(&d.linear.luminance);
self.send_target_primaries(&d.linear.target_primaries);
self.send_target_luminances(&d.linear.target_luminance);
@ -103,11 +113,10 @@ impl WpImageDescriptionInfoV1 {
});
}
#[expect(dead_code)]
pub fn send_tf_power(&self, eexp: f64) {
pub fn send_tf_power(&self, e: EotfPow) {
self.client.event(TfPower {
self_id: self.id,
eexp: (eexp * 10_000.0) as u32,
eexp: e.0,
});
}