From 8da999998ab8d5ceff9ca51b3d37bb136acdc2d5 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Fri, 3 Oct 2025 16:10:04 -0400 Subject: [PATCH] add `load_texture_checked` Signed-off-by: kernelkind --- crates/notedeck/src/media/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/notedeck/src/media/mod.rs b/crates/notedeck/src/media/mod.rs index e9f3d3d..4971047 100644 --- a/crates/notedeck/src/media/mod.rs +++ b/crates/notedeck/src/media/mod.rs @@ -10,6 +10,7 @@ pub use blur::{ compute_blurhash, update_imeta_blurhashes, ImageMetadata, ObfuscationType, PixelDimensions, PointDimensions, }; +use egui::{ColorImage, TextureHandle}; pub use images::ImageType; pub use renderable::RenderableMedia; @@ -33,3 +34,18 @@ impl AnimationMode { // max size wgpu can handle without panicing pub const MAX_SIZE_WGPU: usize = 8192; + +pub fn load_texture_checked( + ctx: &egui::Context, + name: impl Into, + image: ColorImage, + options: egui::TextureOptions, +) -> TextureHandle { + let size = image.size; + + if size[0] > MAX_SIZE_WGPU || size[1] > MAX_SIZE_WGPU { + panic!("The image MUST be less than or equal to {MAX_SIZE_WGPU} pixels in each direction"); + } + + ctx.load_texture(name, image, options) +}