Jump to content
  • Advertisement
Sign in to follow this  
aprentice

Possible Optimization

This topic is 5036 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

I have done some timing to see where I lose speed in my current pixel drawing routine and I have tracked it down to the following line where the function memcpy is used. int offset=((ly)+(x*main.pixelwidth)); memcpy(szSurface+offset,&bgpal[pixel],main.pixelwidth); bgpal is an array that holds the palette for the specified pixel. I was wondering if anyone has any optimization ideas. I'm using direct draw btw. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Rather than using memcpy, write 4 different blitting functions -- one for each pixel size, and use normal assignment to set the pixel's value. There might be some clever optimizations that you can use, but try this first.

Your 32-bit per pixel blitting code might look something like this:
    unsigned __int32 bgpal[256];
...
unsigned __int8 * srcrow = srcSurface + src_y * srcpitch + src_x;
unsigned __int8 * dstrow = dstSurface + dst_y * dstpitch + dst_x * 4;

for ( int y = 0; y < h; ++y )
{
unsigned __int8 * src = srcrow;
unsigned __int32 * dst = dstrow;

for ( int x = 0; x <= w; ++x )
{
dst[x] = bgpal[ src[x] ];
}
srcrow += srcpitch;
dstrow += dstpitch;
}

Share this post


Link to post
Share on other sites
I have tried the following code:

init:
unsigned int *lszSurface = ddsd.lpSurface;

draw_func:
int offset=((ly)+(x*main.pixelwidth));
lszSurface[offset] = bgpal[pixel];

The image isnt exactly comming out right, there space in between every pixel (approx. 4?), it may be 3am in the morning, but I don't see anything wrong...

Share this post


Link to post
Share on other sites
Quote:
Original post by aprentice
int offset=((ly)+(x*main.pixelwidth));
lszSurface[offset] = bgpal[pixel];

Assuming main.pixelwidth == pitch, it should be:
offset = ly * main.pixelwidth + x

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!