extern crate alloc;
use alloc::collections::BTreeMap;
use alloc::string::String;
use crate::profile::IccProfile;
use crate::rendering_intent::RenderingIntent;
#[derive(Debug, Clone)]
pub struct OutputIntent {
name: String,
profile: IccProfile,
condition: Option<String>,
}
impl OutputIntent {
pub fn new(name: String, profile: IccProfile) -> Self {
Self {
name,
profile,
condition: None,
}
}
pub fn with_condition(mut self, condition: String) -> Self {
self.condition = Some(condition);
self
}
pub fn name(&self) -> &str {
&self.name
}
pub fn profile(&self) -> &IccProfile {
&self.profile
}
pub fn condition(&self) -> Option<&str> {
self.condition.as_deref()
}
}
#[derive(Debug, Clone)]
pub struct ColorPolicy {
output_intent: Option<OutputIntent>,
fallback_profile: Option<IccProfile>,
default_intent: RenderingIntent,
embedded_profiles: BTreeMap<String, IccProfile>,
}
impl ColorPolicy {
pub fn builder() -> ColorPolicyBuilder {
ColorPolicyBuilder {
output_intent: None,
fallback_profile: None,
default_intent: RenderingIntent::Perceptual,
embedded_profiles: BTreeMap::new(),
}
}
pub fn output_intent(&self) -> Option<&OutputIntent> {
self.output_intent.as_ref()
}
pub fn fallback_profile(&self) -> Option<&IccProfile> {
self.fallback_profile.as_ref()
}
pub fn default_intent(&self) -> RenderingIntent {
self.default_intent
}
pub fn get_profile(&self, name: &str) -> Option<&IccProfile> {
self.embedded_profiles.get(name)
}
}
#[derive(Debug)]
pub struct ColorPolicyBuilder {
output_intent: Option<OutputIntent>,
fallback_profile: Option<IccProfile>,
default_intent: RenderingIntent,
embedded_profiles: BTreeMap<String, IccProfile>,
}
impl ColorPolicyBuilder {
pub fn output_intent(mut self, intent: OutputIntent) -> Self {
self.output_intent = Some(intent);
self
}
pub fn fallback_profile(mut self, profile: IccProfile) -> Self {
self.fallback_profile = Some(profile);
self
}
pub fn default_intent(mut self, intent: RenderingIntent) -> Self {
self.default_intent = intent;
self
}
pub fn embed_profile(mut self, name: String, profile: IccProfile) -> Self {
self.embedded_profiles.insert(name, profile);
self
}
pub fn build(self) -> ColorPolicy {
ColorPolicy {
output_intent: self.output_intent,
fallback_profile: self.fallback_profile,
default_intent: self.default_intent,
embedded_profiles: self.embedded_profiles,
}
}
}