pub struct Image565View { /* private fields */ }Expand description
A read-only view of all or part of a statically stored RGB565 image.
A view borrows the original pixels without copying or allocating. Create a
full-image view with Image565Fixed::view,
or select a rectangular portion with
Image565Fixed::view_rect.
Coordinates passed to Image565View::pixel_at are local to the view, so
(0, 0) addresses the crop’s top-left pixel rather than the original
image’s top-left pixel.
Views contain only color pixels and draw opaquely. For color-key
transparency, draw an Image565Fixed with a
MaskFixed, as shown in the
MaskFixed example.
§Example
use device_envoy_core::cyd::{
Cyd, CydDisplay,
display::{CydFrame, DrawItem, Image565Fixed, tga},
};
use embedded_graphics::{
prelude::{Point, Size},
primitives::Rectangle,
};
const IMAGE: Image565Fixed<45, 73, { 45 * 73 }> = tga!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/docs/assets/cyd_fill_contiguous.tga"
))
.to_565();
async fn draw<C: Cyd>(cyd: &mut C) -> Result<(), C::Error> {
let full_view = IMAGE.view();
let source = Rectangle::new(Point::new(2, 35), Size::new(41, 36));
let cropped_view = IMAGE.view_rect(source);
assert_eq!(cropped_view.size(), source.size);
assert_eq!(
cropped_view.pixel_at(Point::zero()),
full_view.pixel_at(source.top_left),
);
assert_eq!(
cropped_view.rgb565_iter().count(),
source.size.width as usize * source.size.height as usize,
);
let display = cyd.display();
let mut frame = display.full_frame_mut();
DrawItem::Bitmap {
view: full_view,
top_left: Point::new(80, 84),
}
.draw(&mut frame);
DrawItem::Bitmap {
view: cropped_view,
top_left: Point::new(200, 102),
}
.draw(&mut frame);
frame.flush().await
}
The complete image is shown on the left and its cropped view on the right:
Implementations§
Source§impl Image565View
impl Image565View
Sourcepub const fn new(pixels: &'static [u16], size: Size) -> Self
pub const fn new(pixels: &'static [u16], size: Size) -> Self
Creates a full-image view from a row-major RGB565 pixel slice.
Use this when pixels are already available as packed RGB565 values. For
a compile-time TGA image, prefer Image565Fixed::view,
as shown in the Image565View example.
Panics if pixels.len() != size.width * size.height.
Sourcepub const fn size(&self) -> Size
pub const fn size(&self) -> Size
Returns this view’s dimensions.
For a cropped view, these are the crop dimensions rather than the full
image dimensions. See the Image565View example.
Sourcepub fn pixel_at(&self, point: Point) -> Rgb565
pub fn pixel_at(&self, point: Point) -> Rgb565
Returns the pixel at a view-local coordinate.
(0, 0) is the top-left of this view, not necessarily the top-left of
the underlying image. See the Image565View example.
Panics if point is outside the view.
Sourcepub fn rgb565_iter(&self) -> impl Iterator<Item = Rgb565> + '_
pub fn rgb565_iter(&self) -> impl Iterator<Item = Rgb565> + '_
Iterate over the view’s pixels in row-major order as Rgb565 values.
Cropped views skip the pixels outside the view while preserving the view’s local row order.
See the Image565View example.
Trait Implementations§
Source§impl Clone for Image565View
impl Clone for Image565View
Source§fn clone(&self) -> Image565View
fn clone(&self) -> Image565View
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more