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
Pixels::set builds no mipmaps, so a streamed image drawn well below its size aliases #1385
Context: Strata (lgse/strata), a file manager on Rune, streams thumbnails into one Pixels handle per file (the handle stays, the image arrives later) and draws them at whatever size the grid uses.
What's missing (67d73a5f). Pixels::set (crates/rune-image/src/pixels.rs:95-106) is the streaming path and clears frame.mips = None (:103; set_mips at :108-118 is pub(crate)), so a 256 px thumbnail drawn at 37 pt samples bilinearly and aliases. ImageCache images get mips, but ImageCache::rgba (crates/rune-image/src/lib.rs:310-318) makes a new handle for each call (keyed by the bytes) and fills its mips later, so a store that keeps one handle per file can't use it: each landed image would be a new handle, and the view would commit to swap it in.
Repro (headless; ran at 2a44156 with --snap out.png --scale 1 --at 0.5, source unchanged at 67d73a5f): a 256 × 256 one-pixel checkerboard drawn at 37 × 37 pt, streamed through Pixels::set (left) and through ImageCache::rgba of the same bytes (right).
use rune::{App,AppSpec,Cx,El,Image,ImageCache,Pixels,Waker, el, row};structS{streamed:Pixels,cached:Option<Image>}fnboard() -> Vec<u8>{(0..256u32*256).flat_map(|i| {let v = if(i % 256 + i / 256) % 2 == 0{0}else{255};[v, v, v,255]}).collect()}fninit() -> S{let p = Pixels::new(); p.set(256,256,board());S{streamed: p,cached:None}}fnsetup(s:&mutS,waker:Waker){let img = ImageCache::new(waker).rgba(256,256,board());let _ = img.wait();
s.cached = Some(img);}fnview(s:&S, _:&mutCx<S>) -> El{letmut r = row().w_full().h_full().child(el().size(37.0,37.0).pixels(&s.streamed)).child(el().size(13.0,37.0));ifletSome(i) = &s.cached{ r = r.child(el().size(37.0,37.0).pixels(i.pixels()));}
r
}fnmain(){letmut spec = AppSpec::new("mips",(87.0,37.0), init, view);
spec.setup = Some(setup);App::new(spec).run();}
The streamed square shows a beat pattern of near-black and white blocks (grey levels 7 to 248, standard deviation 37 of 255, inside its edge); the cached one is an even grey (188, no deviation). A 256 → 32 draw (an exact eighth) hides it.
Ask. A mipmapped set (levels built off the main thread), or ImageCache::rgba_into(&Pixels, …) that fills an existing handle.
Related: #163 (atlas pages keep a CPU copy), #148 (reading Pixels back), #702, #1042.
Added ImageCache::rgba_into on dev in #1907 (commit 1f6dd178b).
use std::sync::Arc;use rune::{ImageCache,Pixels};let cache = ImageCache::new(Arc::new(|| {}));let thumb = Pixels::new();
cache.rgba_into(&thumb,256,256, rgba_bytes);
This follows Rune's ImageCache::rgba linear-light mip pipeline and latest-wins request discipline while keeping Pixels::set as the zero-allocation unmipped streaming path. rgba_into updates an existing Pixels handle in place without creating a new Image or content-hashing the bytes: images up to 64×64 finish inline on native, larger images build linear-premultiplied mipmaps on the shared decoder workers, and wasm32 builds them in main-thread slices. A monotonic per-handle ticket ensures a slower worker never overwrites a newer Pixels::set, Pixels::replace, or rgba_into call, and dropped handles skip pending work. Passing zero width or height with empty bytes clears the handle; oversized (> 8192 px) or mismatched-length inputs are ignored without modifying target.
You can compare unmipped Pixels::replace vs mipmapped ImageCache::rgba_into on a 256×256 checkerboard downscaled to 37×37 pt in examples/matched (--scene mips).
Verified on Windows (crates/rune-image 63 passed + 3 doctests, crates/rune/tests/pixels_streaming.rs, examples/matched tests), macOS arm64 (crates/rune-image 64 passed + 3 doctests), Linux aarch64 compile check, and wasm32 compile checks (cargo check-wasm, cargo check-webgl). Not run: a live desktop window or browser execution of the wasm32 sliced path.
Activity
Hona commentedon Nov 24, 2026
Added
ImageCache::rgba_intoondevin #1907 (commit1f6dd178b).This follows Rune's
ImageCache::rgbalinear-light mip pipeline and latest-wins request discipline while keepingPixels::setas the zero-allocation unmipped streaming path.rgba_intoupdates an existingPixelshandle in place without creating a newImageor content-hashing the bytes: images up to 64×64 finish inline on native, larger images build linear-premultiplied mipmaps on the shared decoder workers, andwasm32builds them in main-thread slices. A monotonic per-handle ticket ensures a slower worker never overwrites a newerPixels::set,Pixels::replace, orrgba_intocall, and dropped handles skip pending work. Passing zero width or height with empty bytes clears the handle; oversized (> 8192px) or mismatched-length inputs are ignored without modifyingtarget.You can compare unmipped
Pixels::replacevs mipmappedImageCache::rgba_intoon a 256×256 checkerboard downscaled to 37×37 pt inexamples/matched(--scene mips).Verified on Windows (
crates/rune-image63 passed + 3 doctests,crates/rune/tests/pixels_streaming.rs,examples/matchedtests), macOS arm64 (crates/rune-image64 passed + 3 doctests), Linux aarch64 compile check, andwasm32compile checks (cargo check-wasm,cargo check-webgl). Not run: a live desktop window or browser execution of thewasm32sliced path.