Audio (343) Datatype (51) Demo (203) Development (602) Document (24) Driver (97) Emulation (148) Game (1010) Graphics (500) Library (118) Network (233) Office (66) Utility (932) Video (69)
Total files: 4396
Full index file Recent index file
Amigans.net OpenAmiga Aminet IntuitionBase
|
[Back to readme page] [Add Comment] [Refresh page]
Comment by: Capehill (82.128.191.210) | At: 30 Jun 2005, 17:23 | File version: 0.1 | After wondering why it's so slow, I optimized the loop a bit:
--
for ( y = 0; y < height; y++ )
{
// Calculate modulo outside the inner loop
const Uint32 y_offset = y * image->pitch;
// Uint32 _cos = (y + iter) % height;
Uint32 _cos = y + iter;
while ( _cos >= height )
_cos -= height;
// Source pixel's base address
Uint8* src = (Uint8*)image->pixels + y_offset;
for ( x = 0; x < width; x++ )
{
//Uint32 _sin = (x + iter) % width;
Uint32 _sin = x + iter;
while ( _sin >= width )
_sin -= width;
// Calculate wave effect. It depends on wave height and sin/cos functions
Sint32 _x = x + ( sin_lut[ _sin ] );
Sint32 _y = y + ( cos_lut[ _cos ] );
// Check dimensions
if ( _x < 0 )
_x = width + _x;
else if ( _x >= width )
_x = _x - width;
if ( _y < 0 )
_y = height + _y;
else if ( _y >= height )
_y = _y - height;
// Destinations pixel's base address
Uint8* dest = (Uint8*)screen->pixels + _x * d_bpp + _y * screen->pitch;
// Red
*(dest + dr) = *( src + sr );
// Green
*(dest + dg) = *( src + sg );
// Blue
*(dest + db) = *( src + sb );
src += s_bpp;
} // x
} // y
--
Also MAX_X & MAX_Y multiplications were move to main() where sin_lut and cos_lut are initialized.
Optimizations give > 30% better performance.
| | |
|