OS4 DepotLogo by Nickman 
(anonymous IP: 18.206.177.17,1695) 
 HomeRecentStatsSearchSubmitUploadsMirrorsContactInfoDisclaimerConfigAdmin
 Menu

 Features
   Crashlogs
   Bug tracker
   Locale browser
 

 Categories

   o Audio (332)
   o Datatype (50)
   o Demo (190)
   o Development (563)
   o Document (21)
   o Driver (96)
   o Emulation (143)
   o Game (923)
   o Graphics (480)
   o Library (105)
   o Network (219)
   o Office (60)
   o Utility (859)
   o Video (65)

Total files: 4106

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: http://eu.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, 15: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-2021 by Björn Hagström All Rights Reserved