Skip to main content
GameDev.net gamedev.net
🔒 Locked

Possible Optimization

Started by aprentice Dec 31, 2004 at 8:42 PM 6 replies 600+ views
Original Post
aprentice
aprentice
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
Basiror
Basiror
why do you do it per pixel?
http://www.8ung.at/basiror/theironcross.html
aprentice
aprentice
Quote:
Original post by Basiror
why do you do it per pixel?


I interpret data, sort of like bitmaps do, but not exactly the same.
JohnBolton
JohnBolton
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;    } 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
trevaaar
trevaaar
try to just assign the values directly instead of using memcpy if you are going to do it pixel-by-pixel
aprentice
aprentice
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...

Muhammad Haggag
Muhammad Haggag
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

aprentice
aprentice
thanks for your help guys, I've got it working now :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.