Android Question Need to manually write colors into a framebuffer

Roger Taylor

Member
Licensed User
Longtime User
Long story short, I'm toying with the idea of creating a retro computer emulator that has an 800x525 display.

I guess the easiest way to describe what I need is a way to byte-blast from an existing byte array into some kind of bitmap that has already been set up to render in 2, 4, or 16 colors. I had the idea of having an existing Windows Bitmap file wrapper (header + blank image area for 800x525), and blasting the bytes into the .bmp "file".

Even a way to write the 3 RGB bytes per color into a native B4A bitmap or image framebuffer would be nice.

Does LibGDX support some of the things I might need? Block copying byte arrays into an image/bitmap/canvas, etc.?
 

Roger Taylor

Member
Licensed User
Longtime User
I made BX32 before to simulate a retro game computer. Exactly I used BitmapCreator for this as a framebuffer.
I'm not sure this is what I need, but glancing at the examples there doesn't appear to be any support for B4A which I'm posting about. I also don't see an .xml along with the .jar,... does it need it?
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
BitmapCreator is an internal library. There are many examples in the forum. It supports random access of pixels and the internal buffer() can be accessed like a framebuffer.
 
Upvote 0

Roger Taylor

Member
Licensed User
Longtime User
This thread was on a closely-related topic:

https://www.b4x.com/android/forum/threads/bitmapcreator-and-pixel-color.142900/

ie bit-bashing (well, byte- and int- bashing) a raw frame buffer

If you work with a 32-bit RGBA buffer then the RGBAs are 32-bits ie look like Ints, and so an Array of Ints is a convenient alias for an Array of pixels.
This sounds promising. Maybe I could also use a buffer to see if any source video bytes have changed and only update those that are different. The idea is to keep the same B4A bitmap displaying "live" if that's possible.
 
Upvote 0

Roger Taylor

Member
Licensed User
Longtime User
My current demo does work to fill the bitmap with random colors which looks like a video noise screen, only the frame rate is maybe 10 hz.
Here's the line that just kills the idea:
Bit.ArrayCopy(bc.IntsToBytes(linePixels), 0, bmc.buffer, 0, 800*525*4).

My array of 800x525 integer colors has to go through a conversion to bytes before it's then copied into the bitmap creator buffer. This is much overkill and I'm looking for some kind of shortcut.

I know this is a lot of bytes to move around which is why I prefer the concept of writing directly into a Windows BitMap "file" that has a prefab wrapper for 800x525 size.
 
Upvote 0

Roger Taylor

Member
Licensed User
Longtime User
I'm testing on a Fire TV stick (Android). This test attempts to animate a video noise effect and it uses a lot of RND functions. I assume that when I really get into converting video bytes into 8x8 font characters, etc. that it's going to take even longer to build the source int array. I would hope that by 2022 I wouldn't be staring at something this pitifully slow even with high-level code.
 

Attachments

  • test.zip
    140.8 KB · Views: 128
Last edited:
Upvote 0

Roger Taylor

Member
Licensed User
Longtime User
The test app is blazing on my Galaxy Tab S7+. This looks promising. However, I need to figure out how to run my video renderer in it's own thread, in a loop, while the CPU will have it's own thread. New topic?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
 
Upvote 0
Top