Skip to content

Commit 2fb69ff

Browse files
committed
refactor(session): generalize apply_rgb24()
Add an optional "flip" argument for inverting bitmaps. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 797a80c commit 2fb69ff

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

crates/ironrdp-session/src/fast_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Processor {
114114
usize::from(update.width),
115115
usize::from(update.height),
116116
) {
117-
Ok(()) => image.apply_rgb24_bitmap(&buf, &update.rectangle)?,
117+
Ok(()) => image.apply_rgb24(&buf, &update.rectangle, true)?,
118118
Err(err) => {
119119
warn!("Invalid RDP6_BITMAP_STREAM: {err}");
120120
update.rectangle.clone()

crates/ironrdp-session/src/image.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -570,43 +570,57 @@ impl DecodedImage {
570570
}
571571

572572
// FIXME: this assumes PixelFormat::RgbA32
573-
pub(crate) fn apply_rgb24_bitmap(
573+
fn apply_rgb24_iter<'a, I>(
574574
&mut self,
575-
rgb24: &[u8],
575+
rgb24: I,
576576
update_rectangle: &InclusiveRectangle,
577-
) -> SessionResult<InclusiveRectangle> {
577+
) -> SessionResult<InclusiveRectangle>
578+
where
579+
I: Iterator<Item = &'a [u8]>,
580+
{
578581
const SRC_COLOR_DEPTH: usize = 3;
579582
const DST_COLOR_DEPTH: usize = 4;
580583

581584
let image_width = self.width as usize;
582-
let rectangle_width = usize::from(update_rectangle.width());
583585
let top = usize::from(update_rectangle.top);
584586
let left = usize::from(update_rectangle.left);
585587

586588
let pointer_rendering_state = self.pointer_rendering_begin(update_rectangle)?;
587589

588-
rgb24
589-
.chunks_exact(rectangle_width * SRC_COLOR_DEPTH)
590-
.rev()
591-
.enumerate()
592-
.for_each(|(row_idx, row)| {
593-
row.chunks_exact(SRC_COLOR_DEPTH)
594-
.enumerate()
595-
.for_each(|(col_idx, src_pixel)| {
596-
let dst_idx = ((top + row_idx) * image_width + left + col_idx) * DST_COLOR_DEPTH;
590+
rgb24.enumerate().for_each(|(row_idx, row)| {
591+
row.chunks_exact(SRC_COLOR_DEPTH)
592+
.enumerate()
593+
.for_each(|(col_idx, src_pixel)| {
594+
let dst_idx = ((top + row_idx) * image_width + left + col_idx) * DST_COLOR_DEPTH;
597595

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

605603
let update_rectangle = self.pointer_rendering_end(pointer_rendering_state)?;
606604

607605
Ok(update_rectangle)
608606
}
609607

608+
pub(crate) fn apply_rgb24(
609+
&mut self,
610+
rgb24: &[u8],
611+
update_rectangle: &InclusiveRectangle,
612+
flip: bool,
613+
) -> SessionResult<InclusiveRectangle> {
614+
const SRC_COLOR_DEPTH: usize = 3;
615+
let rectangle_width = usize::from(update_rectangle.width());
616+
let lines = rgb24.chunks_exact(rectangle_width * SRC_COLOR_DEPTH);
617+
if flip {
618+
self.apply_rgb24_iter(lines.rev(), update_rectangle)
619+
} else {
620+
self.apply_rgb24_iter(lines, update_rectangle)
621+
}
622+
}
623+
610624
// FIXME: this assumes PixelFormat::RgbA32
611625
pub(crate) fn apply_rgb32_bitmap(
612626
&mut self,

0 commit comments

Comments
 (0)