Sign in to follow this  

Possible Optimization

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

This topic is 4730 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this