need help with locking dd surf

Started by
3 comments, last by octavsoft 22 years, 10 months ago
When I lock a dd surface, how can I get to pixel (x,y)?? Let''s say that I lock rectangle rc, and in ddsd I have the surface description. What''s the formula to get to the memory for pixel (x,y), relative to the upper-left corner of rc. The bpp is 16bits. I tried: *(WORD*)((BYTE*)ddsd.lpSurface+y*ddsd.lPitch+x*2) but i get something weird. Please help me, someone. Octavian E-mail: octav@octavsoft.com Webpage: http://www.octavsoft.com
OctavianE-mail: [email=octav@octavsoft.com]octav@octavsoft.com[/email]Webpage: http://www.octavsoft.com
Advertisement
Try this ...

  WORD *pixbuffer = (WORD *)ddsd.lpSurfacepixbuffer[x+y*ddsd.lPitch];  


This is all assuming that you locked the surface with the proper perameters such as DDLOCK_SURFACEMEMORYPTR in the flags when you lock the surface...

Also note that x and y are the co-ordinates on the screen - I hope this helps ...

Sincerely,

Destroyer

===============================
In a world without boundaries -
Who needs gates or windows ?
=============================== [/source]

Edited by - Destroyer on June 25, 2001 4:30:02 PM
In 16bpp mode if you are going to cast the buffer to a word* you will need to divide the pitch by 2. If you are going to cast to a byte* you need to mult x by 2:

WORD *pixbuffer = (WORD *)ddsd.lpSurface;
pixbuffer += (x + (y * (ddsd.lpitch/2)));
*pixbuffer = color;

or

BYTE *pixbuffer = (BYTE *)ddsd.lpSurface;
pixbuffer += ((x*2) + (y * ddsd.lpitch));
*pixbuffer = color;

Lots of room for optimization here, but you get the picture.
Uh oh...

Thats the first I''ve heard about dividing or multipying by 2 - why do you have to do that ?

Destroyer
I figured it out in the end. Aldacron is right, because each pixel is 2 bytes (1 word) in 16 bpp. he pitch is always in bytes, so the width has to be multiplied with 2 or the oder way around. The fastest one would be:
*( (WORD*) ( (BYTE*) surf + y * ddsd1.lPitch ) + x )
cause there is no divide or multiplication.

Octavian
E-mail: octav@octavsoft.com
Webpage: http://www.octavsoft.com
OctavianE-mail: [email=octav@octavsoft.com]octav@octavsoft.com[/email]Webpage: http://www.octavsoft.com

This topic is closed to new replies.

Advertisement