diff --git a/core/embed/rust/src/ui/shape/bitmap.rs b/core/embed/rust/src/ui/shape/bitmap.rs index 7c760ec846..067d704c59 100644 --- a/core/embed/rust/src/ui/shape/bitmap.rs +++ b/core/embed/rust/src/ui/shape/bitmap.rs @@ -295,6 +295,7 @@ impl<'a> Drop for Bitmap<'a> { } } +#[derive(Copy, Clone)] pub struct BitmapView<'a> { pub bitmap: &'a Bitmap<'a>, pub offset: Offset, diff --git a/core/embed/rust/src/ui/shape/mod.rs b/core/embed/rust/src/ui/shape/mod.rs index 001971637f..2e17cc38df 100644 --- a/core/embed/rust/src/ui/shape/mod.rs +++ b/core/embed/rust/src/ui/shape/mod.rs @@ -10,6 +10,7 @@ mod display; #[cfg(feature = "ui_jpeg_decoder")] mod jpeg; mod qrcode; +mod rawimage; mod render; mod text; mod toif; @@ -29,6 +30,7 @@ pub use display::render_on_display; #[cfg(feature = "ui_jpeg_decoder")] pub use jpeg::JpegImage; pub use qrcode::QrImage; +pub use rawimage::RawImage; pub use render::{DirectRenderer, ProgressiveRenderer, Renderer}; pub use text::Text; pub use toif::ToifImage; diff --git a/core/embed/rust/src/ui/shape/rawimage.rs b/core/embed/rust/src/ui/shape/rawimage.rs new file mode 100644 index 0000000000..41ba382f4c --- /dev/null +++ b/core/embed/rust/src/ui/shape/rawimage.rs @@ -0,0 +1,45 @@ +use crate::ui::geometry::Rect; + +use super::{BitmapView, Canvas, DrawingCache, Renderer, Shape, ShapeClone}; + +use without_alloc::alloc::LocalAllocLeakExt; + +/// A shape for rendering compressed TOIF images. +pub struct RawImage<'a> { + /// Destination area + area: Rect, + // Bitmap reference + bitmap: BitmapView<'a>, +} + +impl<'a> RawImage<'a> { + pub fn new(area: Rect, bitmap: BitmapView<'a>) -> Self { + Self { area, bitmap } + } + + pub fn render(self, renderer: &mut impl Renderer<'a>) { + renderer.render_shape(self); + } +} + +impl<'a> Shape<'a> for RawImage<'a> { + fn bounds(&self) -> Rect { + self.area + } + + fn cleanup(&mut self, _cache: &DrawingCache<'a>) {} + + fn draw(&mut self, canvas: &mut dyn Canvas, _cache: &DrawingCache<'a>) { + canvas.draw_bitmap(self.area, self.bitmap); + } +} + +impl<'a> ShapeClone<'a> for RawImage<'a> { + fn clone_at_bump(self, bump: &'a T) -> Option<&'a mut dyn Shape<'a>> + where + T: LocalAllocLeakExt<'a>, + { + let clone = bump.alloc_t()?; + Some(clone.uninit.init(RawImage { ..self })) + } +}