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: no way to read the image back, so apps keep a second copy #148
Pixels takes an RGBA buffer by value in set and keeps it, but has no way to read it back. The public API at devd03349e2 is new, source_url, source_set, set and size (pixels.rs#L49-L118). An app that shows an image and also edits, copies or saves it must keep its own copy beside the Pixels.
Why it matters
For a screenshot app every full image is large: a 3024x1964 RGBA capture is 23.8 MB (width x height x 4). We keep the full-size images we show (a cloud image in the viewer, the frozen frame in the region selector) twice: once as our RgbaImage for edit, copy to clipboard and save, and once inside a Pixels. That is one extra full copy per open image. We did not measure this cost on its own; the number is the arithmetic above.
Ask
A borrow, so no copy is made:
implPixels{/// Runs `f` with the current frame: width, height and straight-alpha RGBA rows, top first./// None when the image came from an `ImageCache` decode (it holds premultiplied mips only).pubfnwith_rgba<R>(&self,f:implFnOnce(u32,u32,&[u8]) -> R) -> Option<R>;}
The Mutex around Frame already guards the buffer (pixels.rs#L11-L23), so the closure form keeps the lock short and lets set swap the buffer afterwards. For decoded images, mip 0 could be returned with a premultiplied flag later; we only need frames given through set.
Done when: an app can read the RGBA of a Pixels it filled with set without copying it, and a test checks that the bytes it reads equal the bytes it set.
Related: #142 (a hidden overlay keeps its last frame) and #80 (GPU block sizing). All three are about memory for full-screen images in a screenshot app.
Added Pixels::with_rgba on dev in #1907 (commit 1f6dd178b).
use rune::Pixels;let pixels = Pixels::new();
pixels.set(2,1,vec![10,20,30,255,40,50,60,255]);let first = pixels.with_rgba(|w, h, bytes| (w, h, bytes[0]));
This follows the Rust closure-borrow (with_*) pattern and matches the lock-free Arc snapshot used in ImageAtlas::place_at: with_rgba clones only the Arc<Vec<u8>> pointer under the frame lock and drops the lock before running the closure, so calling size, set, or replace inside the callback cannot deadlock and rendering is not blocked. It returns None when empty or when the handle holds decoded mipmaps, and preserves in-place Arc reuse after the closure returns.
You can also see it in examples/matched (--scene mips).
Verified with unit tests and doctests in crates/rune-image on Windows (63 passed + 3 doctests) and macOS arm64 (64 passed + 3 doctests), zero-allocation streaming tests in crates/rune/tests/pixels_streaming.rs and crates/runepixels tests on Windows, Linux aarch64 compile check (cargo check -p rune-image --tests), and wasm32-unknown-unknown compile checks (cargo check-wasm, cargo check-webgl). Not run: a live desktop window or browser runtime.
Activity
godismyjudge95 commentedon Nov 6, 2026
Related: #142 (a hidden overlay keeps its last frame) and #80 (GPU block sizing). All three are about memory for full-screen images in a screenshot app.
Posted via Claude
Hona commentedon Nov 24, 2026
Added
Pixels::with_rgbaondevin #1907 (commit1f6dd178b).This follows the Rust closure-borrow (
with_*) pattern and matches the lock-freeArcsnapshot used inImageAtlas::place_at:with_rgbaclones only theArc<Vec<u8>>pointer under the frame lock and drops the lock before running the closure, so callingsize,set, orreplaceinside the callback cannot deadlock and rendering is not blocked. It returnsNonewhen empty or when the handle holds decoded mipmaps, and preserves in-placeArcreuse after the closure returns.You can also see it in
examples/matched(--scene mips).Verified with unit tests and doctests in
crates/rune-imageon Windows (63 passed + 3 doctests) and macOS arm64 (64 passed + 3 doctests), zero-allocation streaming tests incrates/rune/tests/pixels_streaming.rsandcrates/runepixelstests on Windows, Linux aarch64 compile check (cargo check -p rune-image --tests), andwasm32-unknown-unknowncompile checks (cargo check-wasm,cargo check-webgl). Not run: a live desktop window or browser runtime.