Bug 498650

Summary: avif file fails to load, but loads after renaming the same file to `.heif`
Product: [Applications] digikam Reporter: Yuxuan Shui <yshuiv7>
Component: Plugin-DImg-QImageAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: caulier.gilles, metzpinguin
Priority: NOR    
Version First Reported In: 8.5.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 8.6.0
Sentry Crash Report:

Description Yuxuan Shui 2025-01-14 14:07:56 UTC
STEPS TO REPRODUCE
1. Try to load an `.avif` file

OBSERVED RESULT
digikam show no thumbnail, when trying to open the image, it says "failed to load image".

in the logs

```
digikam.general: Trying to get thumbnail with DImg preview for "a.avif"
digikam.dimg: "a.avif" : Unknown image format !!!
digikam.general: mimetype =  ""  ext =  "AVIF"
digikam.general: Cannot create thumbnail for "a.avif"
digikam.general: Thumbnail is null for  "a.avif"
```

but after renaming the same file to `a.heif`, everything works.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: NixOS 25.05
KDE Plasma Version: 
KDE Frameworks Version: 6.9.0
Qt Version: 6.8.1

ADDITIONAL INFORMATION
Comment 1 Yuxuan Shui 2025-01-14 14:21:49 UTC
I suspect this is because dimg's heif loader only checks the file extensions for `.heif`... and I don't have other image loader plugins installed.
Comment 2 caulier.gilles 2025-01-14 14:27:51 UTC
heif has nothing to do with avif.

The work around to rename file force digiKam to use the KImageIO plugin to load image through QImage.

Did you have the avif type mime in the list of the setup page :

https://docs.digikam.org/en/setup_application/views_settings.html#mime-types-settings

Gilles Caulier
Comment 3 Maik Qualmann 2025-01-14 17:42:22 UTC
digiKam also checks the magic bytes, e.g. for HEIF images:

    if (
        (memcmp(&header.data()[4], "ftypheic", 8) == 0) ||
        (memcmp(&header.data()[4], "ftypheix", 8) == 0) ||
        (memcmp(&header.data()[4], "ftypmif1", 8) == 0)
       )

Unfortunately your log is too short and does not contain the magic bytes check.

Another reason could be that you do not have the KImageFormat plugins installed.

Please provide the file.


Maik
Comment 4 Maik Qualmann 2025-01-14 17:47:43 UTC
A test here with avif and heif images whose extensions are reversed shows that digiKam always recognizes the correct file type.

Maik
Comment 5 Yuxuan Shui 2025-01-15 11:32:15 UTC
avif files are AV1 encode inside heif container, or was I mistaken?

I don't have _any_ KImage or QImage imageformat plugins installed.
Comment 6 Maik Qualmann 2025-01-15 11:38:43 UTC
Without the KImageFormat plugins, digiKam cannot load AVIF images or other "modern" formats such as WebP. It is not intended that our HEIF loader will do this job as an alternative.

Maik
Comment 7 Yuxuan Shui 2025-01-15 15:09:20 UTC
(In reply to Maik Qualmann from comment #6)
> Without the KImageFormat plugins, digiKam cannot load AVIF images or other
> "modern" formats such as WebP. It is not intended that our HEIF loader will
> do this job as an alternative.
> 
> Maik

I see. I think I should clarify that once I had the plugins, `.avif` files load fine.

It's just curious that even without the plugins, `.avif` files _can_ be loaded as long as they are named `.heif`. Why leave this capability on the table if it works?
Comment 8 caulier.gilles 2025-01-15 15:57:25 UTC
The heif is container where avif data can be hosted. By chance your libheif is compiled with avif support (optional) and libheif is able to extract the data.

heif and avif are handled by 2 separated plugins. Some linux distro ban libheif due to patents stuff...

Gilles Caulier
Comment 9 Yuxuan Shui 2025-01-16 00:28:39 UTC
in that case, can the internal libheif based loader at least try loading the avif file? if libheif isn't compiled with avif support, then fine, we give up. it couldn't hurt to at least try?
Comment 10 caulier.gilles 2025-01-16 05:58:48 UTC
As i already say, if libheif is not present in a Linux distro, you will lost HEIF and AVIF support. There is no restriction with AVIF plugin. So 2 separate loaders is better.

Gilles Caulier
Comment 11 Yuxuan Shui 2025-01-17 00:15:28 UTC
I don't get this argument? If I don't have the avif plugin installed, I don't get avif support either.

OTOH if I do have an avif capable libheif installed and digikam is not using it to loader avif files, that's wasted potential. I don't understand why digikam can't at least try loading avif files with libheif.
Comment 12 Yuxuan Shui 2025-01-17 00:26:13 UTC
I do want to understand your position here. Is the problem here that you don't want to have multiple plugins supporting the same format? So you don't have to think about plugin priorities, etc.?
Comment 13 Maik Qualmann 2025-01-17 07:17:58 UTC
Well, adding the magic bytes "ftypavif" as a supported file type to the HEIF loader would be no problem. However, in digiKam the respective image loader decides which mime type it is. Here we would then store the AVIF file in digiKam as a HEIF file in the DB. So we would have to create another workaround so that this image is treated as an AVIF mime type. Sorry, we should definitely make a clear separation of the image loaders here. I already wrote that without the KImageFormat plugins you cannot load many other modern formats (WebP, JXL, etc.).

Maik