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 / image memlocks

Author
Message
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th Apr 2009 00:09
i need the formulas for finding the red green and blue values in an image memblock based on the x and y of the wanted pixel

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Apr 2009 02:08
Position = ((Y*Width)+X)*4+12

the times 4 is because it's a dword(4 bytes) and plus 12 is because theres a 12 byte header(0=Width,4=Height,8=Depth)

I just learned this a while back! lol

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th Apr 2009 02:45
ok, i knew bn2 or some1 posted it a while back but i couldnt remember where

but that would take me to the 1st byte of data for that pixel, the red value

so to get the green and blue id add one and two more to that position, respectively

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Apr 2009 03:11
if you just use Memblock dword(Mem,Pos) then it will give you the RGB value of that pixel and to get each indavidule(idk how to spell that ) color then use

RGBR()
RGBG()
RGBB()

Optionally You can use memblock byte(Mem,Pos+Offset) where Offset is which color your want(r,g,b)

oh and by the way the 4th byte of the dword is the alpha value for that pixel.

Oh and that formula works only for 32bit mode. actually the best way to use that formula is this

Depth = Screen Depth()
Pos = ((Y*Width)+X)*(Depth/4)+12

so 16 bit is 4 bytes per pixel 32 is 8 64 is 16 and so on... thats a more versitle way.

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Apr 2009 03:17
When you convert an image to a memblock, the alpha channel becomes useless for use within DBC. If you try to read all 4 bytes as a color from a memblock, DBC treats it as a float value. If you create your own save routine with a proper header for a specific image output format, you could, however, save the memblock information with the alpha channel intact.

If you are in 16 bit display mode, the image information will be stored as 2 bytes. You must use the proper conversion format to convert the 2 bytes to 3 byte color representation (RGB565, RGB555, RGB1555) depending on the graphics card.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th Apr 2009 03:41
ok so dword would actually give me the color of that pixel and ignore the alpha, that sounds like exactly what i need

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Apr 2009 03:53
Oh Whoops not divided by 4! it's 8 sorry!

and i even said the values and i didn't catch it wow lol

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Apr 2009 04:02
As boring as it may be That1Smart Guy, read through the following thread. It should answer all of your questions:

Memblcok color

Enjoy your day.

Login to post a reply

Server time is: 2025-06-08 05:26:30
Your offset time is: 2025-06-08 05:26:30