Skip to content

Commit f7fd86d

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 7f32137 commit f7fd86d

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
@@ -554,7 +554,7 @@ impl DecodedImage {
554554
}
555555

556556
// FIXME: this assumes PixelFormat::RgbA32
557-
pub(crate) fn apply_rgb24_bitmap(
557+
pub(crate) fn apply_rgb24<const REV: bool>(
558558
&mut self,
559559
rgb24: &[u8],
560560
update_rectangle: &InclusiveRectangle,
@@ -569,28 +569,35 @@ impl DecodedImage {
569569

570570
let pointer_rendering_state = self.pointer_rendering_begin(update_rectangle)?;
571571

572-
rgb24
573-
.chunks_exact(rectangle_width * SRC_COLOR_DEPTH)
574-
.rev()
575-
.enumerate()
576-
.for_each(|(row_idx, row)| {
577-
row.chunks_exact(SRC_COLOR_DEPTH)
578-
.enumerate()
579-
.for_each(|(col_idx, src_pixel)| {
580-
let dst_idx = ((top + row_idx) * image_width + left + col_idx) * DST_COLOR_DEPTH;
572+
let it = rgb24.chunks_exact(rectangle_width * SRC_COLOR_DEPTH);
573+
// can it monomorphize this?
574+
let it: Box<dyn Iterator<Item = _>> = if REV { Box::new(it.rev()) } else { Box::new(it) };
575+
it.enumerate().for_each(|(row_idx, row)| {
576+
row.chunks_exact(SRC_COLOR_DEPTH)
577+
.enumerate()
578+
.for_each(|(col_idx, src_pixel)| {
579+
let dst_idx = ((top + row_idx) * image_width + left + col_idx) * DST_COLOR_DEPTH;
581580

582-
// Copy RGB channels as is
583-
self.data[dst_idx..dst_idx + SRC_COLOR_DEPTH].copy_from_slice(src_pixel);
584-
// Set alpha channel to opaque(0xFF)
585-
self.data[dst_idx + 3] = 0xFF;
586-
})
587-
});
581+
// Copy RGB channels as is
582+
self.data[dst_idx..dst_idx + SRC_COLOR_DEPTH].copy_from_slice(src_pixel);
583+
// Set alpha channel to opaque(0xFF)
584+
self.data[dst_idx + 3] = 0xFF;
585+
})
586+
});
588587

589588
let update_rectangle = self.pointer_rendering_end(pointer_rendering_state)?;
590589

591590
Ok(update_rectangle)
592591
}
593592

593+
pub(crate) fn apply_rgb24_bitmap(
594+
&mut self,
595+
rgb24: &[u8],
596+
update_rectangle: &InclusiveRectangle,
597+
) -> SessionResult<InclusiveRectangle> {
598+
self.apply_rgb24::<true>(rgb24, update_rectangle)
599+
}
600+
594601
// FIXME: this assumes PixelFormat::RgbA32
595602
pub(crate) fn apply_rgb32_bitmap(
596603
&mut self,

0 commit comments

Comments
 (0)