Bug 233094 - libpgf relevant : thumbnails blurry (when scaling) on PowerPC platform (big-endian)
Summary: libpgf relevant : thumbnails blurry (when scaling) on PowerPC platform (big-e...
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Thumbs-Engine (show other bugs)
Version: 1.2.0
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-02 19:09 UTC by Vlado Plaga
Modified: 2017-07-28 14:58 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 1.3.0


Attachments
comparison between PGF compression levels 4 and 3 (550.35 KB, image/png)
2010-04-08 14:33 UTC, Vlado Plaga
Details
PGF thumbail channel map patch (1.71 KB, patch)
2010-04-14 18:47 UTC, Raphael Schweizer
Details
Modified to write debug image files (6.95 KB, text/plain)
2010-04-15 14:48 UTC, Raphael Schweizer
Details
patch to digiKam 1.2.0's pgfutils.cpp to create debug files in /tmp (1.13 KB, patch)
2010-04-18 14:58 UTC, Vlado Plaga
Details
Maximum thumbnail size on Ubuntu 1600x1200 (212.83 KB, image/bmp)
2010-04-21 11:07 UTC, Raphael Schweizer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vlado Plaga 2010-04-02 19:09:03 UTC
Version:           1.2.0 (using KDE 4.3.4)
Compiler:          GCC 4.4.3 
OS:                Linux
Installed from:    Debian testing/unstable Packages

This problem was already partly discussed in #224999 "Thumbnails blury after upgrade to 1.0.0 from 0.10" (starting with comment no 24), and I suspect it might be related to #210580 "digiKam crashes on PPC Linux when changing thumbnail size".

The problem with digiKam 1.2.0 on my PowerPC Debian system is that thumbnails appear extremely blurry as soon is I scale them down a little.

As described in my comments to #224999 thumbnails are always blurry when generated in Ubuntu 10.04 on the same PowerPC computer.

I get clear, scalable thumbnails, when I compile digiKam with "-DENABLE_THUMBS_DB=no" - but (re)-loading of thumbnails, also when I change their size or just change a picture's rating, is a lot faster with the new Thumbs DB method. So having this thumbnail sharpness problem fixed properly would probably make digiKam usage a lot more convenient for me (and maybe some others too)!
Comment 1 Marcel Wiesweg 2010-04-02 22:50:25 UTC
One thing to rule out is a problem with libpgf. For this test, change in libs/threadimageio/thumbnailcreator.cpp, line 498,
    dbInfo.type             = DatabaseThumbnail::PGF;
to
    dbInfo.type             = DatabaseThumbnail::PNG;

From now on you will create PNG thumbnails in your database. Please check if that makes any difference.
Comment 2 caulier.gilles 2010-04-03 12:11:14 UTC
If there is a difference, this problem will be relevant of libpgf running under PPC computer. Please confirm... In this case, i will contact libpgf team for feedback

Gilles Caulier
Comment 3 Vlado Plaga 2010-04-03 19:11:36 UTC
Yeah, success! It is libpgf again. Thanks for the quick reaction, Marcel and Gilles! Now I've also got the best digiKam ever, finally. :-)
Comment 4 caulier.gilles 2010-04-03 19:56:14 UTC
Ok thanks. I CC libpgf team for info.

Gilles Caulier
Comment 5 caulier.gilles 2010-04-03 20:42:27 UTC
Raphael,

Please look at this file. Sound like another libpgf problem under PPC computer. Here, Vlado see thumbnails blured in digiKam icon view. It's typically a compression problem with libpgf, i think.

Code relevant in digiKam is there :

http://lxr.kde.org/source/extragear/graphics/digikam/libs/threadimageio/pgfutils.cpp#83

This method is used to create a bytearray of a compressed PGF image
computed from a QImage instance. This bytearray is stored in digiKam Database as well.

To extract PGF bytearray from database and create a QImage, we use this method :

http://lxr.kde.org/source/extragear/graphics/digikam/libs/threadimageio/pgfutils.cpp#53

The rest of thumbnail process in digiKam is Qt4 based code, and the problem is not there.

About libpgf compiled in digiKam core, we use this CMake code :

http://lxr.kde.org/source/extragear/graphics/digikam/CMakeLists.txt#1002

There is no special compilation flag set for libpgf.

Finally, lipgf code is there :

http://lxr.kde.org/source/extragear/graphics/digikam/libs/3rdparty/libpgf/

Thanks in advance for your help

Gilles Caulier
Comment 6 Raphael Schweizer 2010-04-04 10:14:46 UTC
Thank you for reporting and all the helpful details.
A PPC will be at my disposal starting April 6th. I'll look into it immediately.

Raphael Schweizer
Comment 7 caulier.gilles 2010-04-04 10:28:05 UTC
Raphael,

Great. If you need more info, ask to Vlado. he has a PPC computer (I don't have it).

If you want to compile digiKam, just post your questions here. All developers are in this room.

Gilles Caulier
Comment 8 Raphael Schweizer 2010-04-07 18:12:51 UTC
Gilles,

Investigation has started.
Using Ubuntu 9.10 and the current pgf codec w/ console I could not find a difference between big and little endian encoded images so far. I'm currently trying to compile my own svn version of digiKam (repository version is at 1.0.0, which crashes on PPCs, as we know :-D) CMake says:
--
CMake Error at libkipi/CMakeLists.txt:60 (INSTALL):
 install FILES given no DESTINATION!
CMake Error at libkipi/pics/CMakeLists.txt:1 (KDE4_INSTALL_ICONS):
 Unknown CMake command "KDE4_INSTALL_ICONS".
--
What am I doing wrong?

I suppose digiKam calculates the thumnail images once and scales these images afterwards? So if the thumbnails look OK after generation and get blurry after scaling, where does libpgf come in? I do, however, not understand why the problem disappears if dbInfo.type = DatabaseThumbnail::PNG

Raphael Schweizer
Comment 9 caulier.gilles 2010-04-07 18:25:25 UTC
To compile digiKam, you need to compile and install shared libraries from kdegraphics, and after compile digiKam and kipi-plugins. Look instruction here :

http://www.digikam.org/drupal/download/KDE4

Using svn trunk version is the best, because it's current code.

To solve external dependencies, look in README files, all is explained indeep. It's not difficult...

About PNG stuff, yes, this is strange. PNG encoder is libpng based (through Qt4 API), and PGF codec is dropped to render thumbs. This is why i suspect libpgf here.

Gilles Caulier
Comment 10 Vlado Plaga 2010-04-07 19:02:27 UTC
My suggestion for compiling digiKam in Ubuntu 9.10:

Get the digiKam 1.2.0 tarball and follow instructions on that website:
http://www.digikam.org/drupal/download?q=download/tarball

You can get all build dependencies for digiKam by doing
# apt-get build-dep digikam

It is also possible to create proper deb packages, but compiling that way takes longer, because it creates both a normal and a debug version:
http://mail.kde.org/pipermail/digikam-users/2010-March/010083.html

I don't think it is necessary to experiment with the latest code, if the problem is already there in version 1.2.0.

Raphael, I hope you can reproduce and solve my problem (although it is not urgent for me, thanks to the PNG workaround)! I experienced different results on Debian and on Ubuntu 10.04 - digiKam on Ubuntu 9.10 might behave differently again.
Comment 11 caulier.gilles 2010-04-07 19:14:42 UTC
Vlado,

I has a question for you ? Can you test again using PGF codec on your computer, and change compression level of PGF image. There is only an hardcoded value to change in source code here :

http://lxr.kde.org/source/extragear/graphics/digikam/libs/threadimageio/thumbnailcreator.cpp#504

The last parameter '4' is PGF compression level. Using smaller value compress lesser. '0' value is lossless compression as PNG.

Can you test with 3, 2, 1, and 0 to see if blurring effect disappear ?

Note : Of course don't forget to revert changes done following #1 from Marcel to use PGF codec.

Thanks in advance

Gilles
Comment 12 Vlado Plaga 2010-04-08 14:33:09 UTC
Created attachment 42593 [details]
comparison between PGF compression levels 4 and 3

Gilles, you seem to be on the right track. Changing PGF compression levels has a significant effect, as can be seen in the attached comparison between levels 4 (default) and 3. I did these tests with digiKam 1.2 on Debian sid / PPC. I also checked level 0 (before level 3), but I can't see a significant difference between 0 and 3, so I did not bother attaching a level 0 screen-shot.
Comment 13 caulier.gilles 2010-04-08 14:48:02 UTC
Vlado,

Thanks to comparing compression levels. i will set PGF compression to 3 immediately in source code.

Raphael,

Any comments about difference between PGF compression level 3 and 4 ? Why the image become blurred ? It's a side effect of wavelets compression ? If yes, why i cannot reproduce i never see that with JPEG 2000 ?

Gilles Caulier
Comment 14 Raphael Schweizer 2010-04-08 16:22:19 UTC
Gilles,

starting with compression level 4 downsampling is used (see DownsampleThreshold in http://lxr.kde.org/source/extragear/graphics/digikam/libs/3rdparty/libpgf/PGFtypes.h#53), which may explain a small difference. Judging from Vlado's screenshots there must be something else. Perhaps libpgf is reporting wrong level sizes on PPCs, such that scaling (http://lxr.kde.org/source/extragear/graphics/digikam/libs/threadimageio/pgfutils.cpp#129) does not work correctly. I'll check that.

Raphael Schweizer
Comment 15 Raphael Schweizer 2010-04-14 18:47:14 UTC
Created attachment 42783 [details]
PGF thumbail channel map patch

Gilles,

the blurriness issue is finally demystified:

1) on big endian systems, libpgf did a wrong YUV transform of thumbnails (missing ARGB / BGRA map) which led to increased data size
2) libPGF crashed when a ARGB PGF was loaded (short channel map).

a) loadPGFScaled only works with (A)RGB PGFs (some mapping PGF.Mode <-> QImage.Mode is needed)
b) Judging from screenshots thumbnail images are stored 256x256 but displayed 254x254 (with black border). Resizing introduces blurriness.

Issues 1) & 2) are solved with the attached patch. a) and b) are outside the scope of this bug.

Please note that a rebuild of the thumbnails is needed on big endian systems.

Raphael Schweizer
Comment 16 caulier.gilles 2010-04-14 21:27:47 UTC
Thanks Raphael,

I will patch digiKam.

Yes thumbs are 256x256 and are downscaled to 254x254. I thinl that image must be cropped instead. Marcel ?

Gilles
Comment 17 caulier.gilles 2010-04-14 21:33:04 UTC
SVN commit 1114868 by cgilles:

patch from Raphael Schweizer to play properly with PGF image under PowerPC computer
CCBUGS: 233094


 M  +17 -4     pgfutils.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1114868
Comment 18 Marcel Wiesweg 2010-04-14 22:20:44 UTC
Referring to this code?
void ThumbnailLoadThread::slotThumbnailLoaded(const LoadingDescription& description, const QImage& thumb)

        pix = QPixmap(w + 2, h + 2);
        QPainter p(&pix);
        p.setPen(QPen(Qt::black, 1));
        p.drawRect(0, 0, w + 1, h + 1);
        p.drawImage(1, 1, thumb);

The pixmap is created two pixels larger than the loaded thumbnail. No scaling is done here.
Comment 19 caulier.gilles 2010-04-14 22:23:49 UTC
Thanks Marcel,

So nothing can be done anymore in this file. I close it now.

Gilles Caulier
Comment 20 Raphael Schweizer 2010-04-14 22:56:19 UTC
Marcel,

please excuse me for my wrong accusation.
On my work machine the thumb strip on top (when viewing thumbs and preview) can be expanded just so far that the thumbnail is at most 254x254 (which led to the wrong conclusion). In a VM I just used, it as at most 246px. Maybe you could allow resizing the upper part of the UI to allow "native" sized thumbnails.

Raphael
Comment 21 caulier.gilles 2010-04-15 08:52:50 UTC
Raphael,

In comment #14, you talk about a threshold for downsampling image. Currently it set to level 3. 

It's possible to add an option to disable this feature in compression process if quality is more than 3 ?

Gilles
Comment 22 Raphael Schweizer 2010-04-15 13:49:56 UTC
Gilles,

it is possible to set a higher threshold in http://lxr.kde.org/source/extragear/graphics/digikam/libs/3rdparty/libpgf/PGFtypes.h#53 Set it to 31 to completely disable downsampling. However, no one should be able to distinguish visually images compressed on q4 with downsampling en- or disabled.

I recommend using the PGFconsole to experiment with encoding settings and observing PSNR / size changes.

Raphael
Comment 23 Raphael Schweizer 2010-04-15 14:48:33 UTC
Created attachment 42801 [details]
Modified to write debug image files

Vlado,

though we did find some PPC / big endian issues we couldn't reproduce the dramatic quality loss you demonstrated in comment #12

I would be pleased to investigate further. Do you mind compiling digiKam using the attached pgfutils.cpp (and comparing it's results to the PGFconsole [SVN: https://libpgf.svn.sourceforge.net/svnroot/libpgf]). pgfutils is modified to write to "/tmp/":
a) writeQImage.bmp (the thumbnail image we encode)
b) writeStream.pgf (the encoded thumbnail)
c) readStream.pgf (the pgf read from the thmbnails db)
d) readQImage.bmp (the decoded bitmap, returned to digiKam)
I'm interested in all those files (+ a) encoded with the console and afterwards decoded + the original image.)

In order to make this work you'll have to create an album with only the image of interest, load this album (-> a,b) and resize the thumb (-> c,d)

I know this is a lot of work, please let me know if I can assist in any way.

Raphael
Comment 24 Vlado Plaga 2010-04-15 15:57:58 UTC
Ok, Raphael, your instructions for investigating the issue further seem clear enough to me. I should be able to produce these debug files on Sunday, but probably not earlier.
Comment 25 Marcel Wiesweg 2010-04-15 21:26:53 UTC
SVN commit 1115266 by mwiesweg:

Adjust the ImageThumbnailBar so that showing thumbnails up to full 256 is possible.
For this we need to find out pixel-exactly which viewport size (we know the max value for
that) corresponds to which widget size (which we can set a max value for).
It seems to work to just take the difference of the two at one point of time.
Additionally, add the two pixels used for the highlighting border.

CCBUG:  233094

 M  +16 -4     digikam/imagethumbnailbar.cpp  
 M  +1 -0      digikam/imagethumbnailbar.h  
 M  +2 -1      digikam/imagethumbnaildelegate.cpp  
 M  +8 -0      libs/threadimageio/thumbnailloadthread.cpp  
 M  +2 -0      libs/threadimageio/thumbnailloadthread.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1115266
Comment 26 Vlado Plaga 2010-04-18 14:58:56 UTC
Created attachment 42874 [details]
patch to digiKam 1.2.0's pgfutils.cpp to create debug files in /tmp

Raphael,
using your patched pgfutils.cpp from 2010-04-15 (comment 23) I also could not reproduce the blurriness issue. The reason seems to be that you patched the current SVN version of pgfutils.cpp, which already includes your patches from 2010-04-14 (comment 15)! Isolating the debug patch and merging the two relevant sections into digiKam 1.2.0's original pgfutils.cpp led to PGF files in /tmp that where buggy, showed in strange colours in showfoto, and even lead to a program crash (although that crash could also have been caused by something else). I'll send you the debug images (~ 500 KByte) in a private e-mail.

In case anyone is curious to (better) see the picture I mainly used for comparison:
http://www.vlado-do.de/photos/image.php?src=australia_2008&img=2008-11-21__17-48-38

Gilles, judging from the tests I ran today with digiKam 1.2.0 source code it seems not necessary to reduce the PGF thumbnails' compression level (in thumbnailcreator.cpp), if the current pgfutils.cpp (from SVN) is used. So you might want to undo that compression level change in SVN before the next digiKam release.
Comment 27 Raphael Schweizer 2010-04-18 17:57:32 UTC
Vlado,

thank you for creating those files. I'm glad to hear that the issues are resolved in the newest version.
The strange colors are caused by the missing int[] map. PGF internally works with YUV images and by default imports / exports BGRA bitmaps. If the caller supplies / needs ARGB format, we have to supply the corresponding mapping (ARGB -> BGRA: [3, 2, 1, 0]). As these are missing from 1.2.0 digiKam, libPGF does a wrong YUV transformation and the images end up 'blueish'. However, I can't explain how this is linked to the blurriness. The crash was most likely caused by a 'short' map, which is also fixed in SVN.
Encoding the debig_svn/writeQImage.bmp with the windows version of libPGF now gives the same result as on your PPC. Therefore, digiKam 1.3.0 should work as expected.

Raphael
Comment 28 caulier.gilles 2010-04-18 20:04:56 UTC
>Gilles, judging from the tests I ran today with digiKam 1.2.0 source code it
>seems not necessary to reduce the PGF thumbnails' compression level (in
>thumbnailcreator.cpp), if the current pgfutils.cpp (from SVN) is used. So you
>might want to undo that compression level change in SVN before the next digiKam
>release.

Yes, i will take a look about. it's in my TODO list

Gilles
Comment 29 caulier.gilles 2010-04-19 08:39:06 UTC
SVN commit 1116312 by cgilles:

restore PGF quality 4 for thumb compression. 
Please check if thumbnails are not to blured there with this value, else, use only 3 instead...
CCBUGS: 233094


 M  +4 -3      pgfutils.h  
 M  +3 -2      thumbnailcreator.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1116312
Comment 30 caulier.gilles 2010-04-19 08:41:27 UTC
To Vlado,

PGF compression quality is restored to 4. Please checkout svn trunk again, and re-generate all tumbnails using "Tool/Rebuild Thnumbnails" option. Check if blur effect is back or not.

Thanks in advance

Gilles Caulier
Comment 31 caulier.gilles 2010-04-19 08:46:31 UTC
Marcel, 

I'm not sure if i found a bug about color management and thumbs view.

There i generated all thumbs with CM enabled for thumbs, and disabling lead CM option do not change something. i use a dumy ICC profile as wide-gamut to see the difference, anyway sRGB do not give visible effect.

Do you store thumbs in DB with CM correction or as well, and you apply CM only when thumbs are displayed ?

Vlado, Just to be sure, do you use Color Management on your system ?

Gilles
Comment 32 Raphael Schweizer 2010-04-19 12:42:29 UTC
Marcel,

in revision 1116346 resizing the thumbnailbar to allow 256x256 images is not possible for me. Tried using work machine (resolution 1600x1200) and VM (do. & 1400x1050).

Raphael
Comment 33 Marcel Wiesweg 2010-04-19 21:59:38 UTC
SVN commit 1116583 by mwiesweg:

For the preview thumbbar, also adjust the thumbnail size to reach 256

CCBUG: 233094

 M  +1 -1      digikam/imagethumbnaildelegate.cpp  
 M  +7 -0      libs/threadimageio/thumbnailloadthread.cpp  
 M  +1 -0      libs/threadimageio/thumbnailloadthread.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1116583
Comment 34 Vlado Plaga 2010-04-20 23:21:39 UTC
Gilles, I currently can't compile SVN digiKam. Recently you answered someone's question "But svn requires kde 4.5?" with "yes digiKam from trunk depand of libkdcraw from trunk which is KDE 4.5" on digikam-users.

Anyway I now compiled digiKam 1.2 with pgfutils.cpp from SVN (and no other modifications) and the thumbnail quality seems good again. I tried this in Debian and Ubuntu. So I guess the big-endian problem is properly fixed now.

To answer you other question, Gilles: I don't use color management on my system.
Comment 35 caulier.gilles 2010-04-21 09:23:55 UTC
Thanks Vlado,

Yes, current code from svn need libkdcraw and libkexiv2 from trunk which will be published with KDE 4.5.

But libkdcraw and libkexiv2 do not depand of KDE 4.5 and compile fine with older KDE version. Just checkout code from kdegraphics/libs, compile and install these libraries, and recompile digiKam /kipi-plugins from trunk as well. 

More details here :

http://www.digikam.org/drupal/sharedlibs

http://www.digikam.org/drupal/download?q=download/KDE4

Here i use Mandriva 2010.0 which use KDE 4.3.x. No problem.

Gilles Caulier
Comment 36 Raphael Schweizer 2010-04-21 11:07:57 UTC
Created attachment 42934 [details]
Maximum thumbnail size on Ubuntu 1600x1200

Marcel,

as of rev. 1117090 I still can't resize the thumbnailbar to hold images of 256px (see attached, cropped screenshot). Do you need additional information?

Raphael
Comment 37 Vlado Plaga 2010-04-21 16:17:00 UTC
Gilles,

after you gave these more detailed instructions I tried to compile libkdcraw and libkexiv2 from trunk in my Debian unstable system. libkdcraw compiles all right, but libkexiv2 does not. Something seems to go wrong with the configuration, but there is only a warning "No cmake_minimum_required command is present". Still the Makefile generated by cmake is just 3.7 KByte, whereas the Makefile for libkdcraw is about 14 KByte. Calling "make" for libkexiv2 does not seem to do anything.

I could give it another try, if you have any suggestions, but I'm confident it is not necessary for the libpgf problem anymore.
Comment 38 Johannes Wienke 2010-04-21 17:28:12 UTC
You have to checkout the whole kdegraphics tree from that svn that contains libs/libkexiv2 as a subfolder, call cmake directly in kdegraphics, cd tp libs/libkexiv2 and call make, make install there.
Comment 39 Marcel Wiesweg 2010-04-21 18:40:36 UTC
Raphael: This affects only the thumbbar, in the main icon view you can reach 256?
Which widget style do you use, which KDE/Qt version?
There is no really clean solution, because I know the size the viewport shall have, while I can only set the size of the whole widget, including border, scrollbar etc. I tested here but maybe it doesn't work in other settings.
Comment 40 Vlado Plaga 2010-04-22 22:38:13 UTC
Ok, the problem is definitely fixed now. Today I tested digiKam from SVN (rev.: 1117432) on Debian/PPC, and thumbnails are looking great again.