Bug 498076 - Colors of .heic file are corrupted once a tag is assigned
Summary: Colors of .heic file are corrupted once a tag is assigned
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Tags-Engine (show other bugs)
Version: 8.5.0
Platform: macOS (DMG) macOS
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-31 08:47 UTC by Tom
Modified: 2025-01-01 21:12 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 8.6.0
Sentry Crash Report:


Attachments
Picture with corrupted colors after I assigned the tag in Digicam (2.19 MB, image/heic)
2024-12-31 08:47 UTC, Tom
Details
Original heic file (2.14 MB, image/heic)
2024-12-31 11:53 UTC, Tom
Details
Metadata difference between original HEIC and status after adding a tag with Digikam (6.67 KB, text/plain)
2024-12-31 16:55 UTC, Tom
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom 2024-12-31 08:47:04 UTC
Created attachment 176986 [details]
Picture with corrupted colors after I assigned the tag in Digicam

DigiKam changes the colors of an HEIF picture once a Tag is assigned. The HEIC is still shown correctly in DigiKam, but if the file is looked at on the OS level or copied back to the iPhone, the colors are incorrect.
 

STEPS TO REPRODUCE
1.  Take a picture with an iPhone 14 and add it to a folder which is added as a DigiKam Collection
2.  Double click the file and open - looks fine. Check on Finder/OS level, File is still fine
3. In Captions/Tags select a Tag (in my case "_Album") and assign it to the HEIC

OBSERVED RESULT
1. The HEIC File is changed and an .xmp is created
2. Check the HEIC File on Finder/OS Level and see the corrupted colors (see attached file IMG_1295.heic.)
3. Compared the corrupted File vs. the original file "IMG_1295_original.heic" - original looks fine

EXPECTED RESULT
No changes in the color in the original file

SOFTWARE/OS VERSIONS
macOS: Sonoma 14.6.1
ExifTools: 13.10

ADDITIONAL INFORMATION
Comment 1 Maik Qualmann 2024-12-31 10:00:44 UTC
The cause is related to the color profile. This bug is fixed in digiKam-8.6.0, pre-release version is available here:

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

Maik
Comment 2 Maik Qualmann 2024-12-31 10:01:52 UTC
For digiKam-8.5.0 you can activate the reading of metadata with ExifTool as a workaround.

Maik
Comment 3 Tom 2024-12-31 11:05:17 UTC
@Mike: Thx for the super-fast feedback. Turning on Exiftools to READ the Metadata (+restarting DigiKam) did unfortunately not solve the issue (fyi). I will upgrade to the 8.6 after doing a backup.
Comment 4 Maik Qualmann 2024-12-31 11:18:36 UTC
Can you please provide an original HEIC file?

Maik
Comment 5 Tom 2024-12-31 11:53:13 UTC
Created attachment 176989 [details]
Original heic file
Comment 6 Tom 2024-12-31 11:54:25 UTC
could not update to 8.6 as I am running an intel based Mac and there is no .dmg / pkg for Intel Mac available yet - so can't test on 8.6 if bug is fixed on macOS.
Comment 7 Maik Qualmann 2024-12-31 12:01:34 UTC
Look in the "legacy" folder, there is the Intel version.

Maik
Comment 8 Tom 2024-12-31 14:51:25 UTC
Thx a lot for your instant reply.
I installed 8.6 (Build 30.12.24 20:02) - unfortunately the problem remains. I started with a fresh iPhone
Image which shows nicely in DigiKam and when previewed in Finder, but once I tag the image with DigiKam, the colors are shown wrong in Finder. From within DigiKam the colors of the image do not change.
I also checked if the problem disappears if I separate the changed image from the xml - 
but even if I move the changed image without the corresponding .xmp to another place, colors are still wrong when viewed on Finder.

Can I provide any further help to solve the issue?

Best, Tom
Comment 9 caulier.gilles 2024-12-31 15:02:36 UTC
It's clear that metadata as changed between original and tagged new one.
Probably a tag is reaffected to a wrong value or something like that.
The good news is that image data is not touched while this process, as metadata are store in separated chuck in file.

Can you extract with exiftool the metadata between both files and compare ?
Comment 10 caulier.gilles 2024-12-31 15:04:42 UTC
As Maik said, it's probably relevant of color profile properties.

Also please double check with another application to show the HEIF (not digiKam).

Q: did you use a color profile for your screen ?
Comment 11 Maik Qualmann 2024-12-31 15:42:47 UTC
The original HEIC file has two additional ICC profiles in addition to the Apple ICC profile. These are not being adopted since we copied the ICC profiles with ExifTool. I have not found any program in the Linux world that uses these additional profiles. Let's see how we can fix this.

---- ICC_Profile ----
Profile Description             : Display P3
Profile Copyright               : Copyright Apple Inc., 2022
Media White Point               : 0.96419 1 0.82489
Red Matrix Column               : 0.51512 0.2412 -0.00105
Green Matrix Column             : 0.29198 0.69225 0.04189
Blue Matrix Column              : 0.1571 0.06657 0.78407
Red Tone Reproduction Curve     : (Binary data 32 bytes, use -b option to extract)
Chromatic Adaptation            : 1.04788 0.02292 -0.0502 0.02959 0.99048 -0.01706 -0.00923 0.01508 0.75168
Blue Tone Reproduction Curve    : (Binary data 32 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 32 bytes, use -b option to extract)
---- ICC_Profile2 ----
Gray Tone Reproduction Curve    : (Binary data 14 bytes, use -b option to extract)
---- ICC_Profile3 ----
A To B0                         : (Binary data 19478 bytes, use -b option to extract)
B To A0                         : (Binary data 6412 bytes, use -b option to extract)
Luminance                       : 0 100 0

Maik
Comment 12 Tom 2024-12-31 16:55:05 UTC
Yes, I have calibrated bei Mac and I am using an own profile (Apple iMac-1 2024 08).
Comment 13 Tom 2024-12-31 16:55:52 UTC
Created attachment 177003 [details]
Metadata difference between original HEIC and status after adding a tag with Digikam
Comment 14 Maik Qualmann 2025-01-01 10:27:56 UTC
Git commit cd2fe076c323c41b300d25e446c5436d6edfdeb0 by Maik Qualmann.
Committed on 01/01/2025 at 10:27.
Pushed by mqualmann into branch 'master'.

workaround for images from Apple devices with extra color profiles
FIXED-IN: 8.6.0

M  +1    -1    NEWS
M  +5    -0    core/libs/metadataengine/engine/metaengine.cpp

https://invent.kde.org/graphics/digikam/-/commit/cd2fe076c323c41b300d25e446c5436d6edfdeb0
Comment 15 Maik Qualmann 2025-01-01 10:35:38 UTC
In order not to break Bug 495646, we have to do a workaround at the moment. Images from current Apple devices can contain extra color profiles, these have names like AToB0 or ​​BToA0 in ExifTool as an example. These extra color profiles can only be read by ExifTool, they are not writable, i.e. they cannot be copied to another image. Therefore, we currently ignore the ICC profiles when reading the metadata with ExifTool from Apple devices. This means that no new profiles are written and the existing ones are not changed/deleted.

Maik
Comment 16 Tom 2025-01-01 21:12:42 UTC
Dear Maik,
happy New Year!
I installed Build 01.01.25 16:02 and the problem does not appear anymore.
You made my day!!

Best, Tom