use crate::Orientation;
use zenpixels::PixelDescriptor;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct OutputInfo {
pub width: u32,
pub height: u32,
pub native_format: PixelDescriptor,
pub has_alpha: bool,
pub orientation_applied: Orientation,
pub crop_applied: Option<[u32; 4]>,
}
impl OutputInfo {
pub fn full_decode(width: u32, height: u32, native_format: PixelDescriptor) -> Self {
Self {
width,
height,
native_format,
has_alpha: native_format.has_alpha(),
orientation_applied: Orientation::Identity,
crop_applied: None,
}
}
pub fn with_alpha(mut self, has_alpha: bool) -> Self {
self.has_alpha = has_alpha;
self
}
pub fn with_orientation_applied(mut self, o: Orientation) -> Self {
self.orientation_applied = o;
self
}
pub fn with_crop_applied(mut self, rect: [u32; 4]) -> Self {
self.crop_applied = Some(rect);
self
}
pub fn buffer_size(&self) -> u64 {
self.width as u64 * self.height as u64 * self.native_format.bytes_per_pixel() as u64
}
pub fn pixel_count(&self) -> u64 {
self.width as u64 * self.height as u64
}
}
#[cfg(test)]
mod tests {
use super::*;
use zenpixels::PixelDescriptor;
#[test]
fn output_info_full_decode() {
let info = OutputInfo::full_decode(10, 5, PixelDescriptor::RGBA8_SRGB);
assert_eq!(info.buffer_size(), 200); assert_eq!(info.pixel_count(), 50); assert!(info.has_alpha); }
}