-
Notifications
You must be signed in to change notification settings - Fork 127
Preliminary refactoring patches for QOI #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a57d139
204ddee
f96085a
bba517c
171d3fe
45722f2
cc2619b
fa89695
17a19c7
a481916
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use core::num::NonZeroU16; | ||
|
||
use anyhow::Result; | ||
use bytes::{Bytes, BytesMut}; | ||
use ironrdp_displaycontrol::pdu::DisplayControlMonitorLayout; | ||
use ironrdp_pdu::pointer::PointerPositionAttribute; | ||
|
||
|
@@ -24,12 +25,6 @@ pub enum DisplayUpdate { | |
DefaultPointer, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum PixelOrder { | ||
TopToBottom, | ||
BottomToTop, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct RGBAPointer { | ||
pub width: u16, | ||
|
@@ -61,32 +56,111 @@ pub struct ColorPointer { | |
pub xor_mask: Vec<u8>, | ||
} | ||
|
||
pub struct Framebuffer { | ||
pub width: NonZeroU16, | ||
pub height: NonZeroU16, | ||
pub format: PixelFormat, | ||
pub data: BytesMut, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: What is the benefit of using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not nessarily a Vec, we may have shared memory. Although I realize shared memory may be problematic too... Perhaps a whole copy is inavoidable.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User has to be careful that shared memory will be owned by the server. But we should still allow shared memory to avoid copy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that at some point |
||
pub stride: usize, | ||
} | ||
|
||
impl TryInto<Framebuffer> for BitmapUpdate { | ||
type Error = &'static str; | ||
|
||
fn try_into(self) -> Result<Framebuffer, Self::Error> { | ||
assert_eq!(self.x, 0); | ||
assert_eq!(self.y, 0); | ||
Ok(Framebuffer { | ||
width: self.width, | ||
height: self.height, | ||
format: self.format, | ||
data: self.data.try_into_mut().map_err(|_| "BitmapUpdate is shared")?, | ||
stride: self.stride, | ||
}) | ||
} | ||
} | ||
|
||
/// Bitmap Display Update | ||
/// | ||
/// Bitmap updates are encoded using RDP 6.0 compression, fragmented and sent using | ||
/// Fastpath Server Updates | ||
/// | ||
#[derive(Clone)] | ||
pub struct BitmapUpdate { | ||
pub top: u16, | ||
pub left: u16, | ||
pub x: u16, | ||
pub y: u16, | ||
pub width: NonZeroU16, | ||
pub height: NonZeroU16, | ||
pub format: PixelFormat, | ||
pub order: PixelOrder, | ||
pub data: Vec<u8>, | ||
pub data: Bytes, | ||
pub stride: usize, | ||
} | ||
|
||
impl BitmapUpdate { | ||
/// Extracts a sub-region of the bitmap update. | ||
/// | ||
/// # Parameters | ||
/// | ||
/// - `x`: The x-coordinate of the top-left corner of the sub-region. | ||
/// - `y`: The y-coordinate of the top-left corner of the sub-region. | ||
/// - `width`: The width of the sub-region. | ||
/// - `height`: The height of the sub-region. | ||
/// | ||
/// # Returns | ||
/// | ||
/// An `Option` containing a new `BitmapUpdate` representing the sub-region if the specified | ||
/// dimensions are within the bounds of the original bitmap update, otherwise `None`. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// # use core::num::NonZeroU16; | ||
/// # use bytes::Bytes; | ||
/// # use ironrdp_graphics::image_processing::PixelFormat; | ||
/// # use ironrdp_server::BitmapUpdate; | ||
/// let original = BitmapUpdate { | ||
/// x: 0, | ||
/// y: 0, | ||
/// width: NonZeroU16::new(100).unwrap(), | ||
/// height: NonZeroU16::new(100).unwrap(), | ||
/// format: PixelFormat::ARgb32, | ||
/// data: Bytes::from(vec![0; 40000]), | ||
/// stride: 400, | ||
/// }; | ||
/// | ||
/// let sub_region = original.sub(10, 10, NonZeroU16::new(50).unwrap(), NonZeroU16::new(50).unwrap()); | ||
/// assert!(sub_region.is_some()); | ||
/// ``` | ||
#[must_use] | ||
pub fn sub(&self, x: u16, y: u16, width: NonZeroU16, height: NonZeroU16) -> Option<Self> { | ||
if x + width.get() > self.width.get() || y + height.get() > self.height.get() { | ||
None | ||
} else { | ||
let bpp = usize::from(self.format.bytes_per_pixel()); | ||
let start = usize::from(y) * self.stride + usize::from(x) * bpp; | ||
let end = start + usize::from(height.get() - 1) * self.stride + usize::from(width.get()) * bpp; | ||
Some(Self { | ||
x: self.x + x, | ||
y: self.y + y, | ||
width, | ||
height, | ||
format: self.format, | ||
data: self.data.slice(start..end), | ||
stride: self.stride, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
impl core::fmt::Debug for BitmapUpdate { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
f.debug_struct("BitmapUpdate") | ||
.field("top", &self.top) | ||
.field("left", &self.left) | ||
.field("x", &self.x) | ||
.field("y", &self.y) | ||
.field("width", &self.width) | ||
.field("height", &self.height) | ||
.field("format", &self.format) | ||
.field("order", &self.order) | ||
.field("stride", &self.stride) | ||
.finish() | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.