OS4 DepotLogo by Alkaron 
(anonymous IP: 216.73.216.169,2518) 
 HomeRecentStatsSearchSubmitUploadsMirrorsContactInfoDisclaimerConfigAdmin
 Menu

 Features
   Crashlogs
   Bug tracker
   Locale browser
   Markdown composer
 

 Categories

   o Audio (351)
   o Datatype (51)
   o Demo (214)
   o Development (629)
   o Document (24)
   o Driver (103)
   o Emulation (155)
   o Game (1063)
   o Graphics (516)
   o Library (123)
   o Network (243)
   o Office (69)
   o Utility (962)
   o Video (74)

Total files: 4577

Full index file
Recent index file

 Links

  Amigans.net
  Aminet
  IntuitionBase
  Hyperion Entertainment
  A-Eon
  Amiga Future


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://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, 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-2026 by Björn Hagström All Rights Reserved