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 Professional Discussion / Understanding Pixel Data

Author
Message
Avoth
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location:
Posted: 13th Aug 2011 02:49 Edited at: 13th Aug 2011 02:55
I currently am in the process of teaching to myself the structure of a Bitmap. So i started with the absolute basics. Heres my code.



The first 12 Bytes (0 - 11) Contain the BMP data, when i retrieve the data for position 12 i recieve the following Info.

"There are 32 Bits Per Pixel"
"The Deails of Point 12 is 9737364"

I understand this number is the combination of the next 4 Bytes (12 - 15) but i dont understand how that is translated from the Colour the first Pixel. Could someone shed some light on this for me?
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 13th Aug 2011 02:59
Depending on the format of the bitmap, ARGB, RGBA, etc.. it would be easier to read each byte, at least in my opinion.

Each byte would then represent (in an RGBA format bitmap for example) Red, then Green, then Blue, then Alpha. So it is 4 bytes per pixel, but you can read them individually, instead of having to do the math operations on a DWORD to extract it.

Avoth
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location:
Posted: 13th Aug 2011 03:11 Edited at: 13th Aug 2011 05:41
So in DBPro how would you extract the individual Bytes without using Dword Command? I would assume you just use the Byte command instead? Which will read only the requested Byte and not the requested byte + the following 3. (Word/Dword)

Also just to help me understand this Dword Concept could you break down the result of my algorythm? Or explain the math in order for me to break it down. I am working from Hand On Darkbasic Pro Vol 1 + 2 and it doesnt realy explain this in great depth.

"The Deails of Point 12 is 9737364"

This I believe is the result of next 4 Bytes (12 - 15) but need to fully understand its details (what each number represents or clusters of numbers represent) 7 numbers seems an odd numbered result.

I am using a grey scale image (heightmap) and trying to work out its scale of black to white in order to create a value to manipulate objects/mesh ultimately so my aim is to understand the Bytes in order to receive a common value so to calculate the increase in height based on the darkness of each pixel... usual height map mechanics

[EDIT]
I have just had a play around with RGB values using this 7 digit number.

Would i be right in saying this number represents an ARGB Value (A being irelivent for heightmap) Meaning A=9 R=73 G=74 B=64

[EDIT]
After playing with different blocks of 4 bytes i have established that this 7 digit number isnt broken down this way.

Though instead of reading Dword i have read each byte in groups of 4. Giving me what seems to be

Byte 12 = R 148
Byte 13 = G 148
Byte 14 = B 148
Byte 15 = A (always 0)

I would still like to understand how these 4 Bites have been converted by Dword command into the 7 digit number posted above. Providing i have interpreted this correctly.

Also assuming my latest calcs are correct, using a greyscale heightmap would only realy require me to check the value of byte 1 out of blocks of 4 as Grey scale RGB values are identicle, correct? (Providing the setup is RGBA)

But then the real question is how do you determine if the BMP is ARGB/RGBA or otherwise?

[EDIT]

After some attempts to make bitmaps from pure code. I have established the Order of colour out of the first 4 Bytes (proceeding the initial 12 discriptive bytes) seems to be..
Byte 1 = B
Byte 2 = G
Byte 3 = R
Byte 4 = Unknown, Tried experimenting with different values but it doesnt make any effect on transparency according to my colour picker, so i would assume this value is not Alpha.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Aug 2011 15:22
Quote: "so i would assume this value is not Alpha"


It is - but you may need to tell DBPro to use it. Some code would help.

The colour coding uses base 256 not 10 which is why your colour components don't match up to the digits in 9737364.

Here's a short snippet which might help:

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Aug 2011 20:04
Quote: "Each byte would then represent (in an RGBA format bitmap for example) Red, then Green, then Blue, then Alpha"


That's almost spot on, but for one strange quirk...in a memblock, DBP uses BGRA. I don't think the original format matters, other than knowing whether it's 16 or 32-bit.

Login to post a reply

Server time is: 2026-07-10 10:19:57
Your offset time is: 2026-07-10 10:19:57