Refactor: Using only DirectX
and ImageSharp
based bitmap processing over GDI
#548
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.
Changes:
System.Drawing
withImageSharp
library.System.Drawing.Bitmap
references in favour ofImageSharp.Image<Bgra32>
GDI
basedAddonDataProvider
ImageSharp
lib, expect Mouse bitmap.Reasoning:
Over the past few weeks i've been experimented with only using
DXGI
in the project, finding a way to uniformly extract the texture from GPU memory to the main memory, on the other hand processing these textures more efficiently.While
System.Drawing.Bitmap
works really well, it has a really low processing latency, but the grabbing a frame operation its rather slow and block the thread, in a single point in time, there can be one and onlylock
on it, so multithreading is out of the question. On top of that, it actually used double locking with theLockBits
API. I've made a workaround by usinglock
all the time but it didn't felt right. Currently there are a few threads which would like to access the bitmap data only read-only mode.ImageSharp
comes to the rescue with a modernSpan<T>/Memory<T>
based based API, leveraging all the modern features whatdotnet6
can provide. It supports single writer multiple reader mechanism for working withBitmap
based data.DXGI
screen capture overGDI
shows really good performance boost, with greatly reduced latency.In the future i plan to take advantage of
ImageSharp
, executingNpcNameFinder
andMinimapNodeFinder
code at the GPU side.