use zune_core::bit_depth::BitDepth;
use zune_core::colorspace::{ColorCharacteristics, ColorSpace};
use crate::codecs::ImageFormat;
mod exif;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AlphaState {
PreMultiplied,
NonPreMultiplied
}
#[derive(Clone, Debug)]
pub struct ImageMetadata {
pub(crate) color_trc: Option<ColorCharacteristics>,
pub(crate) default_gamma: Option<f32>,
pub(crate) width: usize,
pub(crate) height: usize,
pub(crate) colorspace: ColorSpace,
pub(crate) depth: BitDepth,
pub(crate) format: Option<ImageFormat>,
pub(crate) alpha: AlphaState,
#[cfg(feature = "metadata")]
pub(crate) exif: Option<Vec<::exif::Field>>
}
impl Default for ImageMetadata {
fn default() -> Self {
ImageMetadata {
color_trc: None,
default_gamma: None,
width: 0,
height: 0,
colorspace: ColorSpace::Unknown,
depth: BitDepth::default(),
format: None,
alpha: AlphaState::NonPreMultiplied,
#[cfg(feature = "metadata")]
exif: None
}
}
}
impl ImageMetadata {
#[cfg(feature = "metadata")]
pub const fn exif(&self) -> Option<&Vec<::exif::Field>> {
#[cfg(feature = "metadata")]
{
return self.exif.as_ref();
}
#[cfg(not(feature = "metadata"))]
{
return None;
}
}
#[cfg(feature = "metadata")]
pub fn exif_mut(&mut self) -> Option<&mut Vec<::exif::Field>> {
#[cfg(feature = "metadata")]
{
return self.exif.as_mut();
}
#[cfg(not(feature = "metadata"))]
{
return None;
}
}
pub const fn get_dimensions(&self) -> (usize, usize) {
(self.width, self.height)
}
pub fn set_dimensions(&mut self, width: usize, height: usize) {
self.width = width;
self.height = height;
}
pub const fn get_colorspace(&self) -> ColorSpace {
self.colorspace
}
pub fn set_colorspace(&mut self, colorspace: ColorSpace) {
self.colorspace = colorspace;
}
pub const fn get_color_trc(&self) -> Option<ColorCharacteristics> {
self.color_trc
}
pub fn set_color_trc(&mut self, trc: ColorCharacteristics) {
self.color_trc = Some(trc);
}
pub const fn get_depth(&self) -> BitDepth {
self.depth
}
pub fn set_depth(&mut self, depth: BitDepth) {
self.depth = depth;
}
pub fn set_default_gamma(&mut self, gamma: f32) {
self.default_gamma = Some(gamma);
}
pub const fn get_image_format(&self) -> Option<ImageFormat> {
self.format
}
pub const fn alpha(&self) -> AlphaState {
self.alpha
}
pub fn is_premultiplied_alpha(&self) -> bool {
self.alpha.eq(&AlphaState::PreMultiplied)
}
pub fn set_alpha(&mut self, alpha_state: AlphaState) {
self.alpha = alpha_state;
}
}