use std::{
hash::{Hash, Hasher},
sync::Arc,
};
use tessera_ui::DrawCommand;
#[derive(Debug, Clone)]
pub struct ImageData {
pub data: Arc<Vec<u8>>,
pub width: u32,
pub height: u32,
}
impl Hash for ImageData {
fn hash<H: Hasher>(&self, state: &mut H) {
self.data.as_ref().hash(state);
self.width.hash(state);
self.height.hash(state);
}
}
impl PartialEq for ImageData {
fn eq(&self, other: &Self) -> bool {
self.width == other.width
&& self.height == other.height
&& self.data.as_ref() == other.data.as_ref()
}
}
impl Eq for ImageData {}
#[derive(Debug, Clone, PartialEq)]
pub struct ImageCommand {
pub data: Arc<ImageData>,
pub opacity: f32,
}
impl DrawCommand for ImageCommand {
fn sample_region(&self) -> Option<tessera_ui::SampleRegion> {
None
}
fn apply_opacity(&mut self, opacity: f32) {
self.opacity = (self.opacity * opacity).clamp(0.0, 1.0);
}
}