Use Bytes as the Container of ImageBuffer

Since we don't need to mutate images once loaded,
we avoid unnecessary extra allocations.
This commit is contained in:
Héctor Ramón Jiménez 2024-05-01 00:55:49 +02:00
parent 7c084d9695
commit 45254ab88c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
5 changed files with 105 additions and 109 deletions

View file

@ -10,7 +10,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
#[derive(Debug)]
pub enum Memory {
/// Image data on host
Host(image_rs::ImageBuffer<image_rs::Rgba<u8>, Vec<u8>>),
Host(image_rs::ImageBuffer<image_rs::Rgba<u8>, image::Bytes>),
/// Storage entry
Device(atlas::Entry),
/// Image not found
@ -51,7 +51,7 @@ impl Cache {
}
let memory = match graphics::image::load(handle) {
Ok(image) => Memory::Host(image.to_rgba8()),
Ok(image) => Memory::Host(image),
Err(image_rs::error::ImageError::IoError(_)) => Memory::NotFound,
Err(_) => Memory::Invalid,
};