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.

Dark GDK / Structure of memblocks from image

Author
Message
archie456
16
Years of Service
User Offline
Joined: 13th Feb 2008
Location:
Posted: 11th Jul 2008 22:38
I want to load an image into a memblock, which I will query, I have a character on screen which will move about by key presses from the user, the routine will translate the characters position onto the memblock and return data from the image which will represent somewhere the character can or can’t move.

That’s the theory.

I need to translate the characters X,Y position into:-
dbReadMemblockByte ( int memblock, int position );

The screen’s co-ords 0,0 is in the top left hand corner and so I assume the memblocks position variable will also start in the top left hand side.

I am guessing that to get the X,Y co-ords into the position I just need to work out the size of the image in pixels (say 200 wide and 400 high) and then add or subtract 400 accordingly to the position variable every time the character move up or down and add / subtract 1 for left or right.

Is this about right? Or am I not understanding how these things work?
(Hope the above makes sense.)
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jul 2008 12:12 Edited at: 12th Jul 2008 12:13
The first 12 bytes of the memblock are the dimensions of the image held in 3 integer values - width, height and colour depth (in bits) - for a total of 12 bytes. Then the data starts at this point.

The position in the memblock can be calculated like so:
Position = ((Width * y) + x) * (depth / 8) + 12

If you know that you will always be dealing with 32 bit images, then the (depth / 8) can be replaced with 4, or 2 if always using 16 bit images.

Quote: "I am guessing that to get the X,Y co-ords into the position I just need to work out the size of the image in pixels (say 200 wide and 400 high) and then add or subtract 400 accordingly to the position variable every time the character move up or down and add / subtract 1 for left or right."

Yes, almost. When moving left, remove (depth/8) from the position, when moving right, add it. When moving up, remove width*(depth/8) from the position, when moving down, add it.

archie456
16
Years of Service
User Offline
Joined: 13th Feb 2008
Location:
Posted: 12th Jul 2008 16:07
Thanks for that Ian, how did you find all this out? There is virtually no documentation on this...
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jul 2008 17:00
The format is the same as DBPro, and I've been using that for quite a few years now. The format is also fairly basic so it's easy to work out with a little experimentation.

Login to post a reply

Server time is: 2024-09-30 01:32:15
Your offset time is: 2024-09-30 01:32:15