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 / Image in memblock - byte location from image width and height

Author
Message
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 10th Jan 2012 22:44
How do I determine the byte (rgba) I can edit
For X=0 to Image Width(1)
For Y=0 to Image height(1)
...
Next Y
Next X
in the code above?

I'm no noob lol - but this is most certainly a simple question, I just can't get the math right... though I am close.

They total byte size of the image is equal to its width X height X 4 (a byte for R,G,B,A)+12 for the 3 dword header... for a 128X128 16 bit thats 12+(128*128*4)=65548 bytes... now how do I get the X and Y location from the byte being read in the for-next loops like the ones above?

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Jan 2012 23:21 Edited at: 10th Jan 2012 23:22
(imgX * 4 * (Y)) + ((X+1) * 4) + 12

That should be about right, if 0,0 is your first pixel as you have shown.
Then the bytes are BGRA.

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Jan 2012 23:43
BatVink's expression should do the trick. A little explanation.

It is easy to find the X location; you just multiply it by 4; then add 12.

The tricky bit is the Y location. The expression above offsets the pointer if Y is more than zero. For each row pixels in Y, add the width of the image multiplied by 4.

I'm not sure about the X+1, maybe my head is not thinking right because it is late; but I believe if X & Y are zero, then position 12 should be the first pixel, not 16. ((X+1) * 4)+12 ?



Here's a visual aid and an article about memblock bitmaps.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 11th Jan 2012 02:26 Edited at: 11th Jan 2012 02:29
ALSO:
For X=0 to Image Width(1)-1
For Y=0 to Image height(1)-1

counting zero, from 0 to imagewidth-1 there are imagewidth pixels.
[edit]
Also, this is how I always do it:
(width*y+x)*4+12

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 11th Jan 2012 05:04
Lol on the byte part - i knew that Ive just always used the byte size verses the image width and height

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jan 2012 06:33
Interesting... but if one was to save an image into a memblock... [warning noob question ahead] can you not just load image from memblock¿

I am still yet to get around to this...

Though I do have HODBP books one and two it is covered in there but want to see if there have been changes since... or improved ways...

Thanks and Hi All¡¡¡

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 11th Jan 2012 10:20
This was the purpose - anyone got a guess as to what I did wrong?


Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Jan 2012 12:25
I didn't look at all of your code, but you can speed it up.

Before putting all your dots to the image, lock the backbuffer (LOCK BACKBUFFER ON? I don't remember the exact command). Then unlock it afterwards.

As an alternative, use one of the third party commands for your dots - either Diggsey's advanced 2D or Cloggy's Plugin. They are much more efficient.

Where you are dividing by 2, multiply by 0.5, it's quicker

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 11th Jan 2012 18:56
Not using any plugins unless I can 'draw a texture' otherwise this code painting colors will be come code painting a texture on an image

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Jan 2012 22:45
The plugins I mentioned simply replace the dot command in your code with a faster dot command.

Login to post a reply

Server time is: 2024-11-22 06:30:27
Your offset time is: 2024-11-22 06:30:27