Skip to main content

ReadbackTarget

Trait ReadbackTarget 

Source
pub trait ReadbackTarget: DrawTarget {
    // Required method
    fn read_pixel(&self, point: Point) -> Option<Self::Color>;

    // Provided method
    fn read_area(&self, area: &Rectangle, out: &mut [Self::Color]) -> usize { ... }
}
Expand description

A DrawTarget that can read back the pixels it has drawn.

Implement this for targets that retain their pixels in memory (framebuffers, canvases, simulators). Streaming targets that forward straight to a bus cannot read back and should not implement it.

§Cost contract

Destination-aware renderers call read_area once per run on the hot path — they assume a read is roughly the cost of a write. That holds for RAM-backed framebuffers, where a read is slice arithmetic; those are the intended targets. A panel whose only read primitive is a slow per-pixel bus command should not implement this trait merely because it can: the default read_area turns every antialiased run into width bus round-trips. Implement it where reads are cheap, and override read_area with a block copy whenever the target allows it.

Required Methods§

Source

fn read_pixel(&self, point: Point) -> Option<Self::Color>

The colour currently at point, or None if point lies outside the target’s bounding box.

Matches GetPixel::pixel.

Provided Methods§

Source

fn read_area(&self, area: &Rectangle, out: &mut [Self::Color]) -> usize

Read the pixels of area row-major into out, returning how many were in bounds (and so written).

The default reads pixel-by-pixel via read_pixel: each in-bounds colour is written to the matching out slot and out-of-bounds slots are left untouched. Iteration stops at whichever of area or out is exhausted first. Override this when the target can copy a whole region out of its framebuffer in one operation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<C, BO, const WIDTH: usize, const HEIGHT: usize, const N: usize> ReadbackTarget for Framebuffer<C, C::Raw, BO, WIDTH, HEIGHT, N>
where Self: DrawTarget<Color = C>, C: PixelColor + From<C::Raw>, BO: ByteOrder, for<'a> RawDataSlice<'a, C::Raw, BO>: IntoIterator<Item = C::Raw>,

Available on crate feature framebuffer only.
Source§

fn read_pixel(&self, point: Point) -> Option<C>

Source§

fn read_area(&self, area: &Rectangle, out: &mut [C]) -> usize

Implementors§

Source§

impl<T> ReadbackTarget for Masked<'_, T>
where T: ReadbackTarget,

Source§

impl<T> ReadbackTarget for Shifted<'_, T>
where T: ReadbackTarget,

Source§

impl<T> ReadbackTarget for Windowed<'_, T>
where T: ReadbackTarget,