summaryrefslogtreecommitdiff
path: root/src/image.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-01-24 16:48:24 +0100
committerLaurenz <laurmaedje@gmail.com>2022-01-24 17:39:49 +0100
commit3739ab77207e0e54edb55a110a16a1eb925b84f4 (patch)
tree06c8e5987d2fe070ad273ef94641161bbaef7095 /src/image.rs
parentdb158719d67fdef1d2c76300fb232cf2d4bfb35d (diff)
Export into rendered images
Diffstat (limited to 'src/image.rs')
-rw-r--r--src/image.rs16
1 files changed, 1 insertions, 15 deletions
diff --git a/src/image.rs b/src/image.rs
index 3d80896f..bd70bf28 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -9,12 +9,11 @@ use std::rc::Rc;
use image::io::Reader as ImageReader;
use image::{DynamicImage, GenericImageView, ImageFormat};
-use serde::{Deserialize, Serialize};
use crate::loading::{FileHash, Loader};
/// A unique identifier for a loaded image.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct ImageId(u32);
impl ImageId {
@@ -37,7 +36,6 @@ pub struct ImageStore {
loader: Rc<dyn Loader>,
files: HashMap<FileHash, ImageId>,
images: Vec<Image>,
- on_load: Option<Box<dyn Fn(ImageId, &Image)>>,
}
impl ImageStore {
@@ -47,18 +45,9 @@ impl ImageStore {
loader,
files: HashMap::new(),
images: vec![],
- on_load: None,
}
}
- /// Register a callback which is invoked each time an image is loaded.
- pub fn on_load<F>(&mut self, f: F)
- where
- F: Fn(ImageId, &Image) + 'static,
- {
- self.on_load = Some(Box::new(f));
- }
-
/// Load and decode an image file from a path.
pub fn load(&mut self, path: &Path) -> io::Result<ImageId> {
let hash = self.loader.resolve(path)?;
@@ -69,9 +58,6 @@ impl ImageStore {
let ext = path.extension().and_then(OsStr::to_str).unwrap_or_default();
let image = Image::parse(&buffer, ext)?;
let id = ImageId(self.images.len() as u32);
- if let Some(callback) = &self.on_load {
- callback(id, &image);
- }
self.images.push(image);
entry.insert(id)
}