Memory Pitch
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.
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. :)
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. :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement