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.

Newcomers DBPro Corner / Memblock Image Positioning

Author
Message
flashing snall
18
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 17th Feb 2010 22:15
Ive done a bunch of searches, and gone through lots of tutorials on memblocks and images, and still I am having a tricky issue.

I want to retrieve the RGB value of a point on an image, that point being function defined. I know of the native point command, but Ive been told that its slow and standoffish...

The problem Im having is that I cannot for the life of me figure out the coordinate's conversion to a memory location within the memblock. Here is what I got.




Help would be awesome.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 17th Feb 2010 22:42



Hope that helps

flashing snall
18
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 17th Feb 2010 23:08
WOw thats great. My only question is what happened to the alpha channel? Like, it makes sense that each pixel has one dword, but how does one go about getting the alpha value out of it?

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 17th Feb 2010 23:14
That's the fine thing with the 32-bits, you have one byte for alpha, one for red, one for green and one for blue.
So the alpha value would in fact be at the exact same position, only you read a byte instead. For the colour channels, you have to add 1, 2 or 3 to the pixel offset.

To extract the alpha from a full colour dword you can use the bitwise AND operator:
(colour && 0xff000000) / (256 ^ 3)
would return only the most significant byte of the word (in this case the alpha value). As you know, AND is only true when both sides are true. Therefore, by and'ing the bits of a word with 0, they are deleted. In this case, all bits after the first 8 are set to false, thus returning only the bits of the first byte. Seeing as the first byte in a DWORD represents its value multiplied by 256^3, we divide the result with that to get the value as a single byte.

flashing snall
18
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 18th Feb 2010 00:02
Alright. thanks man, this was my first fowray into memblocks, Ive been avoiding them because they sound crazy hard, but it isnt actually that bad. Thanks!

Login to post a reply

Server time is: 2024-09-28 14:22:41
Your offset time is: 2024-09-28 14:22:41