Bug 479356

Summary: [Import tool] Auto-rotate doesn't rotate thumbnail
Product: [Applications] digikam Reporter: Ludovic <grand.titus>
Component: Import-MainViewAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: caulier.gilles, metzpinguin
Priority: NOR    
Version First Reported In: 8.2.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In: 8.3.0
Sentry Crash Report:
Attachments: Screenshot of DigiKam vs Gimp, GeoSetter and XnViewMP

Description Ludovic 2024-01-03 12:57:53 UTC
SUMMARY
When importing photographs from USB, if I check "Auto-rota/Flip image", the image is correctly rotated but not the thumbnail. 
After importing, everything seems OK in DigiKam and even in Windows Explorer. But with other tools (like XnViewMP or GeoSetter) the thumbnail is either horizontaly displayed or deformed.

OBSERVED RESULT
I am a beginner with DigiKam. So, maybe I miss some options. Previously I used XnViewMP to auto-rotate images.
When I extract thumbnail (with exiftool -b -ThumbnailImage) from an image auto-rotated by DigiKam, I see that it is horizontal (even if the photograph is vertical). 
When I do the same with an image auto-rotated by XnViewMP, the thumbnail is vertical.

EXPECTED RESULT
Is it possible to rotate the thumbnail when rotating the image to be compatible with "old" image viewers?

SOFTWARE/OS VERSIONS
Windows: Windows 11
Comment 1 Maik Qualmann 2024-01-03 16:07:07 UTC
The question is what your rotation settings are in the digiKam settings under Metadata-> Rotation. In any case, digiKam rotates the embedded thumbnail in the event of a lossless or lossy rotation. If you just do a metadata rotation, of course not.

Please also note that the automatic rotation during import is only carried out on JPG files.

Maik
Comment 2 Ludovic 2024-01-04 10:27:11 UTC
Created attachment 164662 [details]
Screenshot of DigiKam vs Gimp, GeoSetter and XnViewMP

In this screenshot, we can see that:
- the image rotated by Digikam is badly seen (horizontally or deformed) by Gimp, GeoSetter and XnViewMP
- the thumbnail generated by DigiKam (B) corresponds to a 180° rotation of the thumbnail of the original image (A) (whereas the thumbnail of XnViewMP has been correctly rotated by 90° to be vertical)
Comment 3 Ludovic 2024-01-04 10:32:27 UTC
(In reply to Maik Qualmann from comment #1)
> The question is what your rotation settings are in the digiKam settings
> under Metadata-> Rotation. In any case, digiKam rotates the embedded
> thumbnail in the event of a lossless or lossy rotation. If you just do a
> metadata rotation, of course not.
> 
> Please also note that the automatic rotation during import is only carried
> out on JPG files.
> 
> Maik

Thanks for your quick reply.

My rotation settings are exactly the same as in the documentation (https://docs.digikam.org/en/setup_application/metadata_settings.html#rotation-settings) :
- Rotate by changing the content if possible
- Write flag to metadata if possible
- Show images/thumbnails according to orientation tag
- Set orientation tag to normal after rotation

I think I have found the root cause of my problem: 
When DigiKam does a 90° rotation to the image, it rotates the thumbnails by 180°
I have join a screenshot to show it.
Comment 5 Maik Qualmann 2024-01-06 15:33:51 UTC
Git commit fcafdd4d0fcad88d7f2fb0ecf00cd703dbfeb2c8 by Maik Qualmann.
Committed on 06/01/2024 at 16:33.
Pushed by mqualmann into branch 'master'.

Revert "apply intermediate steps to the metadata during image transformation"

M  +23   -30   core/libs/jpegutils/jpegutils.cpp
M  +1    -2    core/libs/jpegutils/jpegutils.h

https://invent.kde.org/graphics/digikam/-/commit/fcafdd4d0fcad88d7f2fb0ecf00cd703dbfeb2c8
Comment 6 Ludovic 2024-01-06 22:01:36 UTC
(In reply to Maik Qualmann from comment #4)
> https://invent.kde.org/graphics/digikam/-/commit/
> 4d3bd40d0431c7382f0d520630502c3a36e464cd
> 
> Maik

Thanks for this very quick fix.

Of course, I am not able to validate your commit.
But if I can help to test a beta version, don't hesitate to ask me.(In reply to Maik Qualmann from comment #5)
> Git commit fcafdd4d0fcad88d7f2fb0ecf00cd703dbfeb2c8 by Maik Qualmann.
> Committed on 06/01/2024 at 16:33.
> Pushed by mqualmann into branch 'master'.
> 
> Revert "apply intermediate steps to the metadata during image transformation"
> 
> M  +23   -30   core/libs/jpegutils/jpegutils.cpp
> M  +1    -2    core/libs/jpegutils/jpegutils.h
> 
> https://invent.kde.org/graphics/digikam/-/commit/
> fcafdd4d0fcad88d7f2fb0ecf00cd703dbfeb2c8

Thanks for this very quick fix.

Of course, I am not able to validate your commit.
But if I can help to test a beta version, don't hesitate to ask me.
Comment 7 caulier.gilles 2024-01-06 22:07:54 UTC
8.3.0 pre-release windows installer is available here to test :

https://files.kde.org/digikam/

Gilles Caulier
Comment 8 Maik Qualmann 2024-01-06 22:25:01 UTC
There was currently no change because I reset it again. I played with various images and XnViewMP. I can't reproduce any problem. Please send me an image that the problem occurs when importing and rotating.

Maik
Comment 9 Ludovic 2024-01-07 17:33:40 UTC
(In reply to Maik Qualmann from comment #8)
> There was currently no change because I reset it again. I played with
> various images and XnViewMP. I can't reproduce any problem. Please send me
> an image that the problem occurs when importing and rotating.
> 
> Maik

I have put an example of a picture here: https://drive.google.com/drive/folders/1qrvFQMHzTXKsP506ovbGaIIvwSOZ2HCV?usp=sharing
You will find:
- Original.jpg: the JPG file generated by my canera (Olympus EM1 II)
- Rotate_with_xxx.jpg: the original image rotated by DigiKam and XnViewMP based on the orientation tag
- xxx_thumbnail.jpg: the thumbnails extracted by 'exiftool.exe -b -ThumbnailImage xxx.jpg > xxx_thumbnail.jpg'
Comment 10 Maik Qualmann 2024-01-07 18:26:04 UTC
Thanks for the sample images. The problem is that Exiv2 has a problem with the Olympus metadata to decode the preview image, so it won't rotate either.

Exiv2 ( 2 ) :  No image data to encode Exif.OlympusCs.PreviewImageStart.

In principle the problem should be reported to Exiv2. Let's see if we can do a workaround here.

Maik
Comment 11 Maik Qualmann 2024-01-07 19:05:49 UTC
Git commit b15d00a9c6e74dc8aede955efa09fd86a5bde365 by Maik Qualmann.
Committed on 07/01/2024 at 20:04.
Pushed by mqualmann into branch 'master'.

fix rotate EXIF thumbnail
FIXED-IN: 8.3.0

M  +1    -1    NEWS
M  +1    -1    core/libs/jpegutils/jpegutils.cpp

https://invent.kde.org/graphics/digikam/-/commit/b15d00a9c6e74dc8aede955efa09fd86a5bde365
Comment 12 Maik Qualmann 2024-01-07 19:09:47 UTC
The reason I couldn't reproduce it is because my test images (Nikon, Canon, etc.) all have a preview image. But your Olympus only has an Exif thumbnail image, which we didn't rotate correctly.

Maik
Comment 13 Ludovic 2024-01-07 21:19:43 UTC
Happy to see that the problem is finaly understood.

I am not sure if I can test the version digiKam-8.3.0-20240107T194535-Win64.exe (retrieve here https://files.kde.org/digikam/) ???
It seems to have been built before your commit.
Comment 14 Maik Qualmann 2024-01-07 21:29:53 UTC
The version already contains the change.

Maik
Comment 15 Ludovic 2024-01-08 21:46:10 UTC
I have tested on digiKam-8.3.0-20240107T194535-Win64.exe: 
Everything work fine now.
It seems to also fix another strange behavior when I do the rotation in XnViewMP and see the image in DigiKam (the thumbnail was badly oriented) even if I don't understand how your commit could have fixed that.

Thank you very much for your fix.