Jump to content
  • Advertisement
Sign in to follow this  
Nokturnal

Memory Pitch

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi , i ve been following andres , trick's book , in one of the chapters he explains how a surface is created and how to attach a palatte to it. Assuming the layout of memory is linear , the following formula is pretty much abvious to set a pixel colour : for 8 bpp :- UCHAR *video_buffer8; video_buffer8[x + y*memory_pitchB] = pixel_color_8; Unsigned char having size 8 bits = 1 byte. What i fail to understand is why does the pitch need to be divide memory pitch by 2 when working in 16 bpp , the fomula stated is as follows : USHORT *video_buffer16; video_buffer16[x + y*(memory_pitchB >> 1)] = pixel_color_16; the size of unsigned short being 16. so to address the 0,1 pixel in 16 bit , the formula would suggest : 0 + 1 (16>>1) = 0+1*8 =8 but the actual location should be at 16. Where am i going wrong ?? thanks.

Share this post


Link to post
Share on other sites
Advertisement
Well, first, addresses are in bytes, not bits. So the first address will be 0, and the next should be 2. (16 bit = 2 byte). What you're computing aren't addresses though, they're indexes into your array.
The memory pitch is divided because it is given in bytes, but your array uses shorts. So if it gives you a pitch of, say, 40 bytes, that corresponds to 20 shorts, so when you're indexing into your array, you need to add 20, not 40. And so, it's divided by two first. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!