Skip to content

Commit f75bf13

Browse files
committed
feat(session): add apply_rgb24() to apply non-inverted bitmap
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 3d1762c commit f75bf13

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

crates/ironrdp-session/src/image.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl DecodedImage {
572572
}
573573

574574
// FIXME: this assumes PixelFormat::RgbA32
575-
pub(crate) fn apply_rgb24_bitmap(
575+
pub(crate) fn apply_rgb24<const REV: bool>(
576576
&mut self,
577577
rgb24: &[u8],
578578
update_rectangle: &InclusiveRectangle,
@@ -587,28 +587,35 @@ impl DecodedImage {
587587

588588
let pointer_rendering_state = self.pointer_rendering_begin(update_rectangle)?;
589589

590-
rgb24
591-
.chunks_exact(rectangle_width * SRC_COLOR_DEPTH)
592-
.rev()
593-
.enumerate()
594-
.for_each(|(row_idx, row)| {
595-
row.chunks_exact(SRC_COLOR_DEPTH)
596-
.enumerate()
597-
.for_each(|(col_idx, src_pixel)| {
598-
let dst_idx = ((top + row_idx) * image_width + left + col_idx) * DST_COLOR_DEPTH;
590+
let it = rgb24.chunks_exact(rectangle_width * SRC_COLOR_DEPTH);
591+
// can it monomorphize this?
592+
let it: Box<dyn Iterator<Item = _>> = if REV { Box::new(it.rev()) } else { Box::new(it) };
593+
it.enumerate().for_each(|(row_idx, row)| {
594+
row.chunks_exact(SRC_COLOR_DEPTH)
595+
.enumerate()
596+
.for_each(|(col_idx, src_pixel)| {
597+
let dst_idx = ((top + row_idx) * image_width + left + col_idx) * DST_COLOR_DEPTH;
599598

600-
// Copy RGB channels as is
601-
self.data[dst_idx..dst_idx + SRC_COLOR_DEPTH].copy_from_slice(src_pixel);
602-
// Set alpha channel to opaque(0xFF)
603-
self.data[dst_idx + 3] = 0xFF;
604-
})
605-
});
599+
// Copy RGB channels as is
600+
self.data[dst_idx..dst_idx + SRC_COLOR_DEPTH].copy_from_slice(src_pixel);
601+
// Set alpha channel to opaque(0xFF)
602+
self.data[dst_idx + 3] = 0xFF;
603+
})
604+
});
606605

607606
let update_rectangle = self.pointer_rendering_end(pointer_rendering_state)?;
608607

609608
Ok(update_rectangle)
610609
}
611610

611+
pub(crate) fn apply_rgb24_bitmap(
612+
&mut self,
613+
rgb24: &[u8],
614+
update_rectangle: &InclusiveRectangle,
615+
) -> SessionResult<InclusiveRectangle> {
616+
self.apply_rgb24::<true>(rgb24, update_rectangle)
617+
}
618+
612619
// FIXME: this assumes PixelFormat::RgbA32
613620
pub(crate) fn apply_rgb32_bitmap(
614621
&mut self,

0 commit comments

Comments
 (0)