Skip to content
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

KeyBitmap FromBGR24Array #19

Closed
tgd-git opened this issue Jul 20, 2023 · 6 comments
Closed

KeyBitmap FromBGR24Array #19

tgd-git opened this issue Jul 20, 2023 · 6 comments

Comments

@tgd-git
Copy link

tgd-git commented Jul 20, 2023

I am tinkering with setting GPU rendered graphics on a key. The GPU textures are always float4 (always with alpha channel, regardless of the fact if it is used or not). Now when reading these textures back from GPU to byte arrays it is at minimal cost (just a copy of the vram) but i am stuck with 4 channels. now stripping the 4th channel from that array requires a costly loop over the whole array. i would like to avoid that step.
I wish there would be at least BGRA32 or a more common RGBA32 option beside the BGR24 format. I understand that there is no point to care about the alpha channel on a key and omitting alpha reduces the amount of data to be sent. I wonder if one could still provide 4 channel images and the lib could just skip the 4th channel when sending the data to the device? sorry if i get anything wrong about how that works, i just wonder if the lib could be more convenient in case the source data is not BGR24.

@wischi-chr
Copy link
Member

Hi @tgd-git

I certainly can provide a way to construct a KeyBitmap from a four channel BGRA32 or RGBA32 but the performance gain would probably be negligible. Many macro boards expect the keys to be in a particular format und for some of them (Stream Deck MK2, Stream Deck XL, etc.) the keys even are JPEG encoded so before sending the keys over USB the library (StreamDeckSharp) even has to JPEG-encode the image which is far more costly than copying a buffer.

There are some performance optimizations already implemented, especially if the constructed KeyBitmap is reused the encoding (for example to jpeg) only happens once. But for stuff like videos (you can check out the video example) the images have to be encoded to jpg for each frame and even that part of the code is faster than the max. frame-rate for most such macro devices.

So if I's implement that I'd probably just end up copying the buffer internally anyways because it's probably not worth the effort to rewrite everything internally to be a hand full of nanoseconds faster just to end up JPEG encoding the image later.

@tgd-git
Copy link
Author

tgd-git commented Aug 1, 2023

Thank you for the explanation, i see i was bit off in my thinking how the data is handled :) I am very surprised about the JPEG encoding. I see your point that this is the most costly part. You might still want to add a method for 4 channel input just for user convenience in some cases.
Me personally took this little issue as an opportunity to learn a bit about compute shaders. Just want to try construct the right format on the gpu already before reading back and providing to the lib. Still on it though:) Thanks again for clarifying and the work on this nice lib anyway. Cheers

@wischi-chr
Copy link
Member

In the new version (5.0.0 via nuget) there are two new methods FromBgra32Array and FromRgba32Array to create KeyBitmaps.

Details see source: https://github.com/OpenMacroBoard/OpenMacroBoard.SDK/blob/master/src/OpenMacroBoard.SDK/KeyBitmapBasicFactoryExtensions.cs

@tgd-git
Copy link
Author

tgd-git commented Aug 2, 2023

works like a charm, thanks for the update! feels much cleaner now.

image

@wischi-chr
Copy link
Member

👌
What's that node/graph editor you've screenshotted there? Is that something you have developed or some kind of tool? Looks nice.

@tgd-git
Copy link
Author

tgd-git commented Aug 2, 2023

thats the editor view for a visual programming language called vvvv, made in berlin. https://visualprogramming.net/
using it a lot. it is based on .net so it can use .net libraries and nugets too. its fun:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants