Skip to content

Commit

Permalink
feat(server): add BitmapUpdate stride support
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
  • Loading branch information
elmarco authored and CBenoit committed Aug 14, 2024
1 parent c73330b commit a73e0b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions crates/ironrdp-server/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct BitmapUpdate {
pub format: PixelFormat,
pub order: PixelOrder,
pub data: Vec<u8>,
pub stride: usize,
}

impl std::fmt::Debug for BitmapUpdate {
Expand Down
20 changes: 15 additions & 5 deletions crates/ironrdp-server/src/encoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,23 @@ impl UpdateEncoder {
}

fn none_update(&mut self, mut bitmap: BitmapUpdate) -> Result<UpdateFragmenter<'_>> {
let stride = usize::from(bitmap.format.bytes_per_pixel()) * usize::from(bitmap.width.get());
let data = match bitmap.order {
PixelOrder::BottomToTop => mem::take(&mut bitmap.data),
PixelOrder::BottomToTop => {
if stride == bitmap.stride {
mem::take(&mut bitmap.data)
} else {
let mut data = Vec::with_capacity(stride * usize::from(bitmap.height.get()));
for row in bitmap.data.chunks(bitmap.stride) {
data.extend_from_slice(&row[..stride]);
}
data
}
}
PixelOrder::TopToBottom => {
let row_len = usize::from(bitmap.width.get()) * usize::from(bitmap.format.bytes_per_pixel());
let mut data = Vec::with_capacity(bitmap.data.len());
for row in bitmap.data.chunks(row_len).rev() {
data.extend_from_slice(row);
let mut data = Vec::with_capacity(stride * usize::from(bitmap.height.get()));
for row in bitmap.data.chunks(bitmap.stride).rev() {
data.extend_from_slice(&row[..stride]);
}
data
}
Expand Down
5 changes: 2 additions & 3 deletions crates/ironrdp-server/src/encoder/rfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl RfxEncoder {
let bpp = usize::from(bitmap.format.bytes_per_pixel());
let width = usize::from(bitmap.width.get());
let height = usize::from(bitmap.height.get());
let stride = width * bpp;

let tiles_x = (width + 63) / 64;
let tiles_y = (height + 63) / 64;
Expand All @@ -77,12 +76,12 @@ impl RfxEncoder {
let tile_width = std::cmp::min(width - x, 64);
let tile_height = std::cmp::min(height - y, 64);

let input = &bitmap.data[y * stride + x * bpp..];
let input = &bitmap.data[y * bitmap.stride + x * bpp..];

let y = &mut [0i16; 4096];
let cb = &mut [0i16; 4096];
let cr = &mut [0i16; 4096];
to_64x64_ycbcr_tile(input, tile_width, tile_height, stride, bitmap.format, y, cb, cr);
to_64x64_ycbcr_tile(input, tile_width, tile_height, bitmap.stride, bitmap.format, y, cb, cr);

let (y_data, new_rest) = rest.split_at_mut(4096);
let (cb_data, new_rest) = new_rest.split_at_mut(4096);
Expand Down
1 change: 1 addition & 0 deletions crates/ironrdp/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ impl RdpServerDisplayUpdates for DisplayUpdates {
format: PixelFormat::BgrA32,
order: PixelOrder::TopToBottom,
data,
stride: usize::from(width.get()).checked_mul(4).unwrap(),
};
Some(DisplayUpdate::Bitmap(bitmap))
}
Expand Down

0 comments on commit a73e0b7

Please sign in to comment.