Faster JPEG loading in Gwenview 2.1
written on Sunday, June 29, 2008
I have been neglecting my communication duties with regard to Gwenview for a few weeks (who said "months"?). I have been busy coding instead, which is probably a good thing. Anyway, I will try to be a bit more chatty about changes happening in Gwenview.
Let's start with a change which should please large image shooters: Faster JPEG loading.
If you ask the upcoming Gwenview 2.1 to display a 4000x3000 JPEG image to fit in your 1280x800 screen, it divides dimensions by two and load a 2000x1500 version of the image. This is much faster and less memory intensive. For bigger images, it may divide the dimensions by 4 or even 8.
I can hear some of you wondering, so let's try to address some of the questions you may have:
- Doesn't it look ugly?
- The result may look a little less sharper than if the full image has been loaded and scaled down, but my experience tend to prove this is only discernible when doing side by side comparisons.
- What happen when I zoom in?
- When you zoom in to the point where the reduced image is not big enough anymore, Gwenview will load a bigger version of it. If you were looking at a image reduced by 4, it will load an image reduced by 2, or the full image if it's not enough.
- What happen when I make changes to the image and save it?
- Whenever you make changes to the image, Gwenview loads the full image, so that it can save the changes.
Implementation detailsThis system has been implemented using Qt facilities to load scaled down images, namely
QImageReader::setScaledSize(). I had to wrote my own version of the JPEG decoder though, because Qt decoder was not aggressive enough in scaling down images.
I wrote a little bench program to compare both decoders. Give it a JPEG and it loads a scaled down version of it, two times, using both decoders. The target size is 1280x800. Here is some bench output:
./imageloadbench landscape-picture-2816x2112.jpg Using Qt loader Iteration: 0 Iteration: 1 time: 2615 Using Gwenview loader Iteration: 0 Iteration: 1 time: 1092 ./imageloadbench large-panoramic-image-21121x366.jpg Using Qt loader Iteration: 0 Iteration: 1 time: 24699 Using Gwenview loader Iteration: 0 Iteration: 1 time: 4424
As you can see, it's more than two times faster on not-so-big images, and gets even more efficient on very large ones.
If you are interested in this bench program, you can find it in kdegraphics/gwenview/tests/imageloadbench.cpp. You have to run
make imageloadbench to build it.