News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Opt Tutorial Example - Image Cross Fading

Started by kevin, February 07, 2009, 07:58:42 AM

Previous topic - Next topic

kevin


>> PlayBasic Optimization Tutorial  - Cross fade Methods <<



This code was written to coincide with tutorial on PlayBasic optimization.

  All of the following examples do the same thing, which is they perform a cross fade between two images.  To do this we'll be alpha blending a screen full of pixels, and for the most part  individually (dot by dot).    This is not something we really want to do doing in any language, let alone through a generic graphics library, but none the less, people do try..

  The routines bellow start out at the most obvious (slowest) method (ie text book blender).  Where each pair of pixels are read from the image1 & image2, blended together and then drawn to the output surface. The operation is fairly simple,  but given we're trying to blend some 480,000 pixels (800x*600y), we can't afford to let any fat inside those inner blending loops.   

   So what i've done here is try working through various methods, looking for ways improve the performances by utilizing some of the built in color management functions, ink modes and ultimately the Pb blitter which of course is much faster than any manual (pixel by pixel) method is ever going to be.    Interestingly just by a little reshuffling i've been able to improve the manual blender by approximately 5 times.

   The original slowest blender clocks around 1100 milliseconds.  Taking over 1 second to render a frame on my machine, while and the quickest manual blender does the same job in around 175 milliseconds.   Not super quick, but a massive improvement over what it was,  and that's the point of optimization !      (The blitter version is about 18 times faster than that of course)

   Hopefully,  this exercise will help inspire you to dream up alternative  ways of doing other calculations in your games and demos.  Have Fun


Related Articles
A Crash Course In Optimization