#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Exposure {
pub stops: f32,
pub automatic: Option<AutoExposure>,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AutoExposure {
pub speed_brighten: f32,
pub speed_darken: f32,
pub correction_min: f32,
pub correction_max: f32,
pub compensation: CompensationCurve,
pub metering_mask: MeteringMask,
}
impl Default for AutoExposure {
fn default() -> Self {
Self {
speed_brighten: 3.,
speed_darken: 1.,
correction_min: f32::MIN,
correction_max: f32::MAX,
compensation: CompensationCurve::default(),
metering_mask: MeteringMask::UNIFORM,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct CompensationCurve {
points: [[f32; 2]; CompensationCurve::MAX_POINTS],
len: usize,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CompensationCurveError {
TooManyPoints,
NotFinite,
NotIncreasing,
}
impl std::fmt::Display for CompensationCurveError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::TooManyPoints => "a compensation curve has at most eight points",
Self::NotFinite => "a compensation curve point is not finite",
Self::NotIncreasing => "compensation curve luminances must strictly increase",
})
}
}
impl std::error::Error for CompensationCurveError {}
impl CompensationCurve {
pub const MAX_POINTS: usize = 8;
pub fn new(points: &[[f32; 2]]) -> Result<Self, CompensationCurveError> {
if points.len() > Self::MAX_POINTS {
return Err(CompensationCurveError::TooManyPoints);
}
if points.iter().flatten().any(|value| !value.is_finite()) {
return Err(CompensationCurveError::NotFinite);
}
if points.windows(2).any(|pair| pair[1][0] <= pair[0][0]) {
return Err(CompensationCurveError::NotIncreasing);
}
let mut curve = Self::default();
curve.points[..points.len()].copy_from_slice(points);
curve.len = points.len();
Ok(curve)
}
pub fn points(&self) -> &[[f32; 2]] {
&self.points[..self.len]
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct MeteringMask {
pub weights: [[u8; 16]; 16],
}
impl MeteringMask {
pub const UNIFORM: Self = Self {
weights: [[255; 16]; 16],
};
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct BloomParameters {
pub intensity: f32,
}
impl Default for BloomParameters {
fn default() -> Self {
Self { intensity: 0.15 }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MotionBlurParameters {
pub shutter_angle: f32,
}
impl Default for MotionBlurParameters {
fn default() -> Self {
Self { shutter_angle: 0.5 }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct ColorGrading {
pub global: ColorGradingGlobal,
pub shadows: ColorGradingSection,
pub midtones: ColorGradingSection,
pub highlights: ColorGradingSection,
pub agx_look: AgxLook,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum AgxLook {
#[default]
None,
Punchy,
Golden,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ColorGradingGlobal {
pub temperature: f32,
pub tint: f32,
pub hue: f32,
pub post_saturation: f32,
pub midtones_start: f32,
pub midtones_end: f32,
}
impl Default for ColorGradingGlobal {
fn default() -> Self {
Self {
temperature: 0.,
tint: 0.,
hue: 0.,
post_saturation: 1.,
midtones_start: 0.2,
midtones_end: 0.7,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ColorGradingSection {
pub saturation: f32,
pub contrast: f32,
pub gamma: f32,
pub gain: f32,
pub lift: f32,
}
impl Default for ColorGradingSection {
fn default() -> Self {
Self {
saturation: 1.,
contrast: 1.,
gamma: 1.,
gain: 1.,
lift: 0.,
}
}
}