use crate::{_impl_init, RasterChannels, RasterSampleFormat};
#[doc = crate::_tags!(image layout)]
#[doc = crate::_doc_meta!{
location("media/visual/image/raster"),
test_size_of(RasterFormat = 4|32),
}]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct RasterFormat {
pub(super) channels: RasterChannels,
pub(super) sample: RasterSampleFormat,
pub(super) transfer: RasterTransfer,
pub(super) alpha: RasterAlpha,
}
_impl_init![Self::UNKNOWN => RasterFormat];
impl RasterFormat {
pub const fn is_unknown(self) -> bool {
self.channels.is_unknown() || self.sample.is_unknown() || self.transfer.is_unknown()
}
pub const fn channel_count(self) -> Option<u8> {
self.channels.channel_count()
}
pub const fn color_channel_count(self) -> Option<u8> {
self.channels.color_channel_count()
}
pub const fn is_indexed(self) -> bool {
self.channels.is_indexed()
}
pub const fn is_packed(self) -> bool {
self.channels.is_packed()
}
pub const fn has_padding_channel(self) -> bool {
self.channels.has_padding_channel()
}
pub const fn has_alpha(self) -> bool {
matches!(self.alpha, RasterAlpha::Straight | RasterAlpha::Premultiplied)
}
pub const fn has_alpha_field(self) -> bool {
self.channels.has_alpha_field()
}
pub const fn is_straight_alpha(self) -> bool {
matches!(self.alpha, RasterAlpha::Straight)
}
pub const fn is_premultiplied(self) -> bool {
matches!(self.alpha, RasterAlpha::Premultiplied)
}
pub const fn is_opaque(self) -> bool {
matches!(self.alpha, RasterAlpha::None | RasterAlpha::Opaque)
}
pub const fn is_srgb(self) -> bool {
matches!(self.transfer, RasterTransfer::Srgb)
}
pub const fn is_linear(self) -> bool {
matches!(self.transfer, RasterTransfer::Linear)
}
pub const fn is_float(self) -> bool {
self.sample.is_float()
}
pub const fn is_integer(self) -> bool {
self.sample.is_integer()
}
pub const fn bits_per_sample(self) -> Option<u16> {
self.sample.bits()
}
pub const fn depth_bits(self) -> Option<u16> {
self.channels.depth_bits(self.sample)
}
pub const fn bits_per_pixel(self) -> Option<u16> {
self.channels.bits_per_pixel(self.sample)
}
pub const fn stored_bytes_per_pixel(self) -> Option<u16> {
match self.bits_per_pixel() {
Some(bits) if bits % 8 == 0 => Some(bits / 8),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub(crate) enum RasterAlpha {
#[default]
None,
Opaque,
Straight,
Premultiplied,
}
_impl_init![Self::None => RasterAlpha];
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub(crate) enum RasterTransfer {
#[default]
Unknown,
Linear,
Srgb,
}
_impl_init![Self::Unknown => RasterTransfer];
impl RasterTransfer {
pub const fn is_unknown(self) -> bool {
matches!(self, Self::Unknown)
}
}