Public Group

# Memory Pitch

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

## 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 on other sites
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 on other sites
Doh !!
Thanks man , i got the concept :)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633301
• Total Posts
3011270
• ### Who's Online (See full list)

There are no registered users currently online

×