pixel_widgets/
graphics.rs1use std::sync::{Arc, Mutex};
2
3use anyhow::*;
4
5use crate::cache::Cache;
6use crate::draw::{ImageData, Patch};
7
8pub struct Graphics {
10 pub(crate) cache: Arc<Mutex<Cache>>,
11}
12
13impl Graphics {
14 pub fn load_image<B: AsRef<[u8]>>(&self, bytes: B) -> Result<ImageData> {
16 let image = image::load_from_memory(bytes.as_ref())?;
17 let image = self.cache.lock().unwrap().load_image(image.into_rgba8());
18 Ok(image)
19 }
20
21 pub fn load_patch<B: AsRef<[u8]>>(&self, bytes: B) -> Result<Patch> {
23 let image = image::load_from_memory(bytes.as_ref())?;
24 let image = self.cache.lock().unwrap().load_patch(image.into_rgba8());
25 Ok(image)
26 }
27}
28
29impl Clone for Graphics {
30 fn clone(&self) -> Self {
31 Self {
32 cache: self.cache.clone(),
33 }
34 }
35}