Skip to content

Commit cd7a60b

Browse files
elmarcoCBenoit
authored andcommitted
feat(session): add DecodeImage helpers
Having a helper to take the slice of updated region data is generally helpful. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 45f6611 commit cd7a60b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

crates/ironrdp-session/src/image.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ impl DecodedImage {
175175
self.width
176176
}
177177

178+
pub fn bytes_per_pixel(&self) -> usize {
179+
usize::from(self.pixel_format.bytes_per_pixel())
180+
}
181+
182+
pub fn stride(&self) -> usize {
183+
usize::from(self.width) * self.bytes_per_pixel()
184+
}
185+
186+
pub fn data_for_rect(&self, rect: &InclusiveRectangle) -> &[u8] {
187+
let start = usize::from(rect.left) * self.bytes_per_pixel() + usize::from(rect.top) * self.stride();
188+
let end =
189+
start + usize::from(rect.height() - 1) * self.stride() + usize::from(rect.width()) * self.bytes_per_pixel();
190+
&self.data[start..end]
191+
}
192+
178193
pub fn height(&self) -> u16 {
179194
self.height
180195
}

0 commit comments

Comments
 (0)