You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Images: rasters decode at full resolution whatever size they draw at #702
Rasters are decoded at the file's full resolution, whatever size they're drawn at. A 512 px PNG drawn at 64 px keeps 512×512 RGBA (1 MiB, plus mips) in the cache and the atlas, where 64×64 would do. Icons, avatars and notification images are almost always drawn far smaller than their files.
Proposal: ImageCache::load_scaled(bytes, size_pt, scale) decodes and downsamples to the draw size in device pixels, and builds the mip chain from there. An animated image decodes just its first frame unless the caller wants it animated. Otherwise an animated notification image keeps every frame at full size and wakes the app at the GIF's rate.
We use it for tray icons and notification images in our fork.
ImageCache::load_scaled(&self, bytes: impl Into<Arc<[u8]>>, size_pt: f32, scale: f32) -> Image decodes and downsamples raster images to fit (size_pt * scale).ceil().clamp(1.0, 8192.0) device pixels (preserving aspect ratio, never upscaling, applying EXIF orientation first, and decoding only frame 0 of animated GIF/WebP/APNG so thumbnails and notification icons never schedule idle frames) before building mipmaps in linear-premultiplied light. SVGs and SVGZs rasterize directly to that target size while preserving document dimensions on Image::intrinsic_size(). Handles are content-addressed by (bytes, max_px).
let cache = rune::ImageCache::new(waker);let thumb = cache.load_scaled(png_bytes,32.0, env.scale);// e.g. 512x256 -> 64x32 at 2xassert_eq!(thumb.wait(),Ok([64,32]));
This follows Rune's ImageCache::svg / ImageCache::app_icon_scaled API shape and browser createImageBitmap / Apple CGImageSourceCreateThumbnailAtIndex first-frame, orientation-applied, never-upscale thumbnail semantics. You can compare full vs scaled decodes interactively in examples/kit-gallery (--scene rune-image--decode).
Verified with rune-image unit tests and doctests on Windows and macOS (including --no-default-features), a Linux aarch64 compile check, rune and rune-kit image tests on Windows, cargo check-wasm / cargo check-webgl, and a headless Chromium WebGL2 scenario covering both browser-decoded JPEG and Rust-decoded PNG downsampling. Not verified in a live interactive window, on a hardware browser GPU, on Safari/Firefox, or on iOS (browser check used software rendering in Chromium without KHR_parallel_shader_compile).
Activity
Hona commentedon Nov 24, 2026
Added on
devin #1951 (merge commit4fcc338ec).ImageCache::load_scaled(&self, bytes: impl Into<Arc<[u8]>>, size_pt: f32, scale: f32) -> Imagedecodes and downsamples raster images to fit(size_pt * scale).ceil().clamp(1.0, 8192.0)device pixels (preserving aspect ratio, never upscaling, applying EXIF orientation first, and decoding only frame 0 of animated GIF/WebP/APNG so thumbnails and notification icons never schedule idle frames) before building mipmaps in linear-premultiplied light. SVGs and SVGZs rasterize directly to that target size while preserving document dimensions onImage::intrinsic_size(). Handles are content-addressed by(bytes, max_px).This follows Rune's
ImageCache::svg/ImageCache::app_icon_scaledAPI shape and browsercreateImageBitmap/ AppleCGImageSourceCreateThumbnailAtIndexfirst-frame, orientation-applied, never-upscale thumbnail semantics. You can compare full vs scaled decodes interactively inexamples/kit-gallery(--scene rune-image--decode).Verified with
rune-imageunit tests and doctests on Windows and macOS (including--no-default-features), a Linux aarch64 compile check,runeandrune-kitimage tests on Windows,cargo check-wasm/cargo check-webgl, and a headless Chromium WebGL2 scenario covering both browser-decoded JPEG and Rust-decoded PNG downsampling. Not verified in a live interactive window, on a hardware browser GPU, on Safari/Firefox, or on iOS (browser check used software rendering in Chromium withoutKHR_parallel_shader_compile).