Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Help with bitmap memblocks required

Author
Message
John Smith
19
Years of Service
User Offline
Joined: 9th Jun 2007
Location:
Posted: 9th Jun 2007 12:02
How should I go about reading pixel data from a memblock of a bitmap if I want to reaseble the bitmap on the screen pixel by pixel.

How do I covert the pixel data dwords into RGB colour values?

I am very stuck, please could you give some help.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Jun 2007 19:41 Edited at: 10th Jun 2007 17:21
Hello,

Well, the first thing you have to know is the difference between BYTE, WORD, and DWORD and how they relate to the screen resolution. Since 8bit is so rare these days, you probably won't be reading back a pixel's color as a single BYTE. If your resolution is 16 bit, then you most likely will be reading the color data back as a WORD, and if your resolution is 24 or 32 bit, then you will most likely be reading back the color information as a DWORD.

So far so good?

Next, I usually use MAKE MEMBLOCK FROM IMAGE instead of from bitmap just because it's easier for me to deal with, and it allows me to size the image however I want.

The structure in the memblock once you have used MAKE MEMBLOCK FROM IMAGE is

Header
DWORD - Image Width (4 bytes - lowbyte to highbyte)
DWORD - Image Height (4 bytes - lowbyte to highbyte)
DWORD - Image Depth (4 bytes - lowbyte to highbyte)

Data
Pixel data - based on the depth (BYTE, WORD, or DWORD)

Here's an example of taking a look at what's inside the memblock after converting a 1 pixel image (green by the way) to a memblock at 16 bit resolution:



After you run this you see
1 0 0 0 1 0 0 0 16 0 0 0 224 7

Which means width=1 height=1 depth=1 and pixel is a WORD = green

Once you convert the memblock, you'll need it's size so that you know how big to make a loop to read back the information to the screen. This information is given back in total bytes. So remember that the header is 12 bytes long(3 DWORDs) and that each pixel will have a size based on depth. So in the previous example, if I want to reassemble the bitmap, I have to look at the header, and determine the bitdepth so I know what data type I will read back from the memblock for each pixel. Here's an example using 32 bitdepth:



[EDIT]
16bit is actually a bit more complicated because of the color conversion and the example program won't quite work right unless you add a conversion routine. If you search the web for RGB565 or 16bit RGB you'll find tons of information on how to deal with this. Here's a link to a thread I had started regarding the 16bit conversion:

http://forum.thegamecreators.com/?m=forum_view&t=105474&b=10

Enjoy your day.
John Smith
19
Years of Service
User Offline
Joined: 9th Jun 2007
Location:
Posted: 20th Jun 2007 19:58
Thanks

Login to post a reply

Server time is: 2026-07-05 22:37:20
Your offset time is: 2026-07-05 22:37:20