-
Notifications
You must be signed in to change notification settings - Fork 178
feat(pdu,graphics,egfx): add ClearCodec bitmap compression codec #1174
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
Open
Greg Lamberson (glamberson)
wants to merge
6
commits into
Devolutions:master
Choose a base branch
from
lamco-admin:feat/clearcodec-codec
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bccbc9
feat(pdu,graphics): add ClearCodec bitmap compression codec
glamberson 310dba5
feat(graphics): add ClearCodec encoder with glyph caching
glamberson 4ebd22f
feat(egfx): add ClearCodec server-side frame sending
glamberson 92edbf8
fix(pdu,graphics): harden ClearCodec and fix shortVBarYOff interpreta…
glamberson a33ed5b
style: apply stable rustfmt to clearcodec modules
glamberson 012af8b
fix(graphics,egfx): harden ClearCodec subcodec decode and fix review …
glamberson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| //! Glyph cache for ClearCodec (MS-RDPEGFX 2.2.4.1). | ||
| //! | ||
| //! When a bitmap area is <= 1024 pixels, ClearCodec can index it in a | ||
| //! 4,000-entry glyph cache. On a cache hit (FLAG_GLYPH_HIT), the previously | ||
| //! cached pixel data is reused without retransmission. | ||
|
|
||
| /// Maximum number of glyph cache entries. | ||
| pub const GLYPH_CACHE_SIZE: usize = 4_000; | ||
|
|
||
| /// A cached glyph entry: BGRA pixel data with dimensions. | ||
| #[derive(Debug, Clone)] | ||
| pub struct GlyphEntry { | ||
| pub width: u16, | ||
| pub height: u16, | ||
| /// BGRA pixel data (4 bytes per pixel). | ||
| pub pixels: Vec<u8>, | ||
| } | ||
|
|
||
| /// Glyph cache for ClearCodec bitmap deduplication. | ||
| pub struct GlyphCache { | ||
| entries: Vec<Option<GlyphEntry>>, | ||
| } | ||
|
|
||
| impl GlyphCache { | ||
| pub fn new() -> Self { | ||
| let mut entries = Vec::with_capacity(GLYPH_CACHE_SIZE); | ||
| entries.resize_with(GLYPH_CACHE_SIZE, || None); | ||
| Self { entries } | ||
| } | ||
|
|
||
| /// Look up a glyph by its cache index. | ||
| pub fn get(&self, index: u16) -> Option<&GlyphEntry> { | ||
| self.entries.get(usize::from(index)).and_then(|slot| slot.as_ref()) | ||
| } | ||
|
|
||
| /// Store a glyph at the given index. | ||
| /// | ||
| /// Returns `true` if the index was valid and the entry was stored. | ||
| pub fn store(&mut self, index: u16, entry: GlyphEntry) -> bool { | ||
| let idx = usize::from(index); | ||
| if idx < GLYPH_CACHE_SIZE { | ||
| self.entries[idx] = Some(entry); | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| /// Reset the entire glyph cache, removing all entries. | ||
| pub fn reset(&mut self) { | ||
| for slot in &mut self.entries { | ||
| *slot = None; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Default for GlyphCache { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn store_and_retrieve() { | ||
| let mut cache = GlyphCache::new(); | ||
| let entry = GlyphEntry { | ||
| width: 8, | ||
| height: 16, | ||
| pixels: vec![0xFF; 8 * 16 * 4], | ||
| }; | ||
| assert!(cache.store(42, entry)); | ||
| let retrieved = cache.get(42).unwrap(); | ||
| assert_eq!(retrieved.width, 8); | ||
| assert_eq!(retrieved.height, 16); | ||
| } | ||
|
|
||
| #[test] | ||
| fn get_empty_returns_none() { | ||
| let cache = GlyphCache::new(); | ||
| assert!(cache.get(0).is_none()); | ||
| assert!(cache.get(3999).is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn reject_out_of_range() { | ||
| let mut cache = GlyphCache::new(); | ||
| let entry = GlyphEntry { | ||
| width: 1, | ||
| height: 1, | ||
| pixels: vec![0; 4], | ||
| }; | ||
| assert!(!cache.store(4000, entry)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.