Skip to content

Commit 5555c7b

Browse files
elmarcoCBenoit
authored andcommitted
refactor(session): decode RFX to RgbX
Decode to the desired format, instead of converting from BgrX to the DecodedImage format (typically RgbA) when applying the tile / drawing. Signed-off-by: Marc-André Lureau <[email protected]>
1 parent bb41724 commit 5555c7b

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

crates/ironrdp-graphics/src/color_conversion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io;
22

33
use yuvutils_rs::{
44
rdp_abgr_to_yuv444, rdp_argb_to_yuv444, rdp_bgra_to_yuv444, rdp_rgba_to_yuv444, rdp_yuv444_to_argb,
5-
rdp_yuv444_to_bgra, BufferStoreMut, YuvPlanarImage, YuvPlanarImageMut,
5+
rdp_yuv444_to_rgba, BufferStoreMut, YuvPlanarImage, YuvPlanarImageMut,
66
};
77

88
use crate::image_processing::PixelFormat;
@@ -24,7 +24,7 @@ pub fn ycbcr_to_argb(input: YCbCrBuffer<'_>, output: &mut [u8]) -> io::Result<()
2424
rdp_yuv444_to_argb(&planar, output, len).map_err(io::Error::other)
2525
}
2626

27-
pub fn ycbcr_to_bgra(input: YCbCrBuffer<'_>, output: &mut [u8]) -> io::Result<()> {
27+
pub fn ycbcr_to_rgba(input: YCbCrBuffer<'_>, output: &mut [u8]) -> io::Result<()> {
2828
let len = u32::try_from(output.len()).map_err(io::Error::other)?;
2929
let width = len / 4;
3030
let planar = YuvPlanarImage {
@@ -37,7 +37,7 @@ pub fn ycbcr_to_bgra(input: YCbCrBuffer<'_>, output: &mut [u8]) -> io::Result<()
3737
width,
3838
height: 1,
3939
};
40-
rdp_yuv444_to_bgra(&planar, output, len).map_err(io::Error::other)
40+
rdp_yuv444_to_rgba(&planar, output, len).map_err(io::Error::other)
4141
}
4242

4343
#[allow(clippy::too_many_arguments)]

crates/ironrdp-session/src/image.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use ironrdp_pdu::geometry::{InclusiveRectangle, Rectangle as _};
99
use crate::SessionResult;
1010

1111
const TILE_SIZE: u16 = 64;
12-
const SOURCE_PIXEL_FORMAT: PixelFormat = PixelFormat::BgrX32;
13-
const SOURCE_STRIDE: u16 = TILE_SIZE * SOURCE_PIXEL_FORMAT.bytes_per_pixel() as u16;
1412

1513
pub struct DecodedImage {
1614
pixel_format: PixelFormat,
@@ -470,6 +468,7 @@ impl DecodedImage {
470468
pub(crate) fn apply_tile(
471469
&mut self,
472470
tile_output: &[u8],
471+
pixel_format: PixelFormat,
473472
clipping_rectangles: &Region,
474473
update_rectangle: &InclusiveRectangle,
475474
) -> SessionResult<InclusiveRectangle> {
@@ -481,16 +480,17 @@ impl DecodedImage {
481480
for region_rectangle in &update_region.rectangles {
482481
let source_x = region_rectangle.left - update_rectangle.left;
483482
let source_y = region_rectangle.top - update_rectangle.top;
483+
let stride = u16::from(pixel_format.bytes_per_pixel()) * TILE_SIZE;
484484
let source_image_region = ImageRegion {
485485
region: InclusiveRectangle {
486486
left: source_x,
487487
top: source_y,
488488
right: source_x + region_rectangle.width() - 1,
489489
bottom: source_y + region_rectangle.height() - 1,
490490
},
491-
step: SOURCE_STRIDE,
492-
pixel_format: SOURCE_PIXEL_FORMAT,
493491
data: tile_output,
492+
step: stride,
493+
pixel_format,
494494
};
495495

496496
let mut destination_image_region = ImageRegionMut {

crates/ironrdp-session/src/rfx.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::cmp::min;
22

33
use ironrdp_graphics::color_conversion::{self, YCbCrBuffer};
4+
use ironrdp_graphics::image_processing::PixelFormat;
45
use ironrdp_graphics::rectangle_processing::Region;
56
use ironrdp_graphics::{dwt, quantization, rlgr, subband_reconstruction};
67
use ironrdp_pdu::codecs::rfx::{self, EntropyAlgorithm, Headers, Quant, RfxRectangle, Tile};
@@ -150,6 +151,7 @@ impl DecodingContext {
150151

151152
let current_update_rectangle = image.apply_tile(
152153
&self.decoding_tiles.tile_output,
154+
PixelFormat::RgbA32,
153155
&clipping_rectangles,
154156
&update_rectangle,
155157
)?;
@@ -195,7 +197,7 @@ fn decode_tile(
195197
cr: ycbcr_temp[2].as_slice(),
196198
};
197199

198-
color_conversion::ycbcr_to_bgra(ycbcr_buffer, output).map_err(|e| custom_err!("decode_tile", e))?;
200+
color_conversion::ycbcr_to_rgba(ycbcr_buffer, output).map_err(|e| custom_err!("decode_tile", e))?;
199201

200202
Ok(())
201203
}

crates/ironrdp-testsuite-core/tests/graphics/color_conversion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn ycbcr_to_rgb_converts_one_element_buffer() {
3838
let expected = [128, 127, 128, 255];
3939

4040
let mut actual = vec![0; 4];
41-
ycbcr_to_bgra(ycbcr, actual.as_mut()).unwrap();
41+
ycbcr_to_rgba(ycbcr, actual.as_mut()).unwrap();
4242
assert_eq!(expected.as_ref(), actual.as_slice());
4343
}
4444

0 commit comments

Comments
 (0)