Saturday, April 9, 2005

Adding fade-effect to kslideshow

I recently transferred some amzing photos from my long-term buddy Siddhartha Saha. What better use could they be put to other than using them as slideshow screensaver. And KDE screensaver comes with a kslideshow (/usr/bin/kslideshow.kss) which is just the perfect slideshow screensaver. Well, not quite.

kslideshow contains all the fancy inter-slide transition effects, horizonal lines, blobs, chessboard, spiralling ... except, the smoothest one - fading. While xscreensaver-gl is a much improved screensaver with fading and other fancy effects, it didnt make sense for kslideshow not to have this effect. One night of Qt-trial-and-error made me realize why this is the case.

First, I got the kdeartwork module from kde CVS. The kslideshow.kss source is in more or less contained in slideshow.cpp. Highly undocumented with quite short variable names; still it didnt take long to understand how the various effects were implemented.

Ended up after adding three effects (also removed the lines which randomly chose transitions - I fixed it to only one specific transition).

1. Added a different form of vertical lines transition that was fading. Currently I use this transition for kslideshow.

2. Added a true fading transition by adding alpha transparency to the previous image and adding alpha opacity to the next image, in small steps. A bit of qimage and qpixmap manipulation. Soon came to realize that manipulation alpha on a qpixmap requires visiting every pixel and manually adding alpha value. Boohoo... cant just set a transparent qbrush and paint the image with that brush. Optimistic me is waiting for Qt 4.0 which has transparent qbrush and qpen - giving the much sought after effect of transparent drawing. Anyway, visiting every pixel to change the alpha (found that I need to change alpha in steps of 8 from 0 to 255 to achieve smooth blending) is a bit too much (even on my modest 1024x768 desktop). The effect is cool but unusable due to high CPU usage. OpenGL based texture manipulations or smarter way of adding alpha to a few pixels at a time might give better performance. I will have a better idea when I fund out how xscreensaver-gl looks like.

3. Added a sweeping fading separator between the two images. Nothing great. I was just trying to see how I can get away by manipulating only a few pixels at a time.

I had in mind to change the kslideshow configuration to allow the user to choose which transition(s) he/she wanted. But now I dont feel like doing it - lets wait for Qt 4 when the alpha blending can be actually used.

- d.

1 comment:

dBera said...

I should post the code here. If anybody knows any better way of doing the fading in Qt3 please let me know.

I am just posting the three functions to be added in kdeartwork/kscreensaver/kdesavers/slideshow.cpp.
Add their declarations in slideshow.h and update the desired transition (effectQuickFade and effectVertLines are usable; effectFade very slow and CPU intensive but included for academic interest) in kSlideShowSaver::registerEffects().

Post a Comment