OS4 DepotLogo by Alkaron 
(anonymous IP: 18.219.253.199,2258) 
 HomeRecentStatsSearchSubmitUploadsMirrorsContactInfoDisclaimerConfigAdmin
 Menu

 Features
   Crashlogs
   Bug tracker
   Locale browser
 

 Categories

   o Audio (343)
   o Datatype (51)
   o Demo (203)
   o Development (602)
   o Document (24)
   o Driver (97)
   o Emulation (149)
   o Game (1011)
   o Graphics (500)
   o Library (118)
   o Network (234)
   o Office (66)
   o Utility (932)
   o Video (69)

Total files: 4399

Full index file
Recent index file

 Links

  Amigans.net
  OpenAmiga
  Aminet
  IntuitionBase


Support the site


 File comments for:  Demo » Misc » waveeffect.lha

Waveeffect

Description: Simple Wave effect with source code
Download: waveeffect.lha
Version: 0.1
Date: 30 Jun 2005
Category: demo/misc
FileID: 864
RSS Feed url: https://os4depot.net/modules/comments/rssfeed.php?file=demo/misc/waveeffect.lha

[Back to readme page]   [Add Comment]   [Refresh page]

Comment by: Capehill (82.128.191.210)At: 30 Jun 2005, 17:23File 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.
 
 

Copyright © 2004-2024 by Björn Hagström All Rights Reserved