Bug 469766

Summary: Krita doesn't recognize Adobe RGB JPG photo without embedded icc profile
Product: [Applications] krita Reporter: Alberto Mattea <alberto>
Component: GeneralAssignee: Krita Bugs <krita-bugs-null>
Status: CONFIRMED ---    
Severity: minor CC: halla
Priority: NOR    
Version First Reported In: 5.1.5   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: AdobeRGB Photo without embedded profile

Description Alberto Mattea 2023-05-14 21:32:25 UTC
SUMMARY
Many cameras when configured to work in the AdobeRGB color space don't actually embed the icc profile in every photo, instead they add an exif tag like

Interoperability Index          : R03 - DCF option file (Adobe RGB)

Krita doesn't recognize these tags, and opens the files as sRGB producing wrong colors.

If I manually add the icc profile using exiftool (or open and resave the photo with gimp) it works fine.
Comment 1 Halla Rempt 2023-06-21 10:58:33 UTC
Could you please make an image like that available?
Comment 2 Alberto Mattea 2023-06-21 12:26:00 UTC
Created attachment 159808 [details]
AdobeRGB Photo without embedded profile

Here's a picture taken with a Fujifilm X-T4 in AdobeRGB mode (straight out of camera, untouched). Krita treats it as sRGB.
Comment 3 Halla Rempt 2023-06-21 12:33:56 UTC
Thanks!
Comment 4 Halla Rempt 2023-06-21 12:36:55 UTC
From the looks of it, krita doesn't even see that string, I cannot find it in the metadata dialog. Of course, even if krita didn't see it, it still wouldn't select the adobe rgb profile, so I can confirm this bug.
Comment 5 Halla Rempt 2023-06-22 09:52:14 UTC
If I dump all the exiv data Krita gets, I see 

Name: "ColorSpace" Qualified name: "exif:ColorSpace" Value: Variant: QVariant(int, 65535)

If I check GIMP, I see

Exif.Photo.ColorSpace: Adobe RGB

So, to start with, there's something weird going on in Krita...
Comment 6 Halla Rempt 2023-06-22 10:27:34 UTC
While exiftool gives

Interoperability Index          : R03 - DCF option file (Adobe RGB)
Comment 7 Halla Rempt 2023-06-22 10:33:16 UTC
ImageMagick shows nothing related... And digikam's showfoto has Color Space:Uncalibrated
Comment 8 Halla Rempt 2023-06-22 10:43:14 UTC
This seems interesting: https://forum.affinity.serif.com/index.php?/topic/33729-what-is-going-on-with-the-exif-color-space-values/&do=findComment&comment=166753 

(sorry for spamming, I'm making notes here as I investigate. But looks like we _do_ get a value of -65535. There's no int: 2 anywhere in the log dump.)
Comment 9 Halla Rempt 2023-06-22 11:02:22 UTC
Following https://ninedegreesbelow.com/photography/embedded-color-space-information.html

halla@thinkstations:~$ exiftool -a -S -G0 -ColorSpace -InteropIndex -WhitePoint -PrimaryChromaticities -Gamma -ICC_Profile:all _DSF5485.JPG 
[EXIF] ColorSpace: Uncalibrated
[EXIF] InteropIndex: R03 - DCF option file (Adobe RGB)
[EXIF] WhitePoint: 0.313 0.329
[EXIF] PrimaryChromaticities: 0.64 0.33 0.21 0.71 0.15 0.06
[EXIF] Gamma: 2.2

So, it looks like ColorSpace really is not set to '2' -- Adobe RGB. as noted in the Affinity thread. Gimp must be faking that.

And as for InteropIndex, Krita logs:

krita(1091750)/(default) KisExifIO::loadFrom: Unknown exif tag, cannot load: Exif.Iop.InteroperabilityIndex
krita(1091750)/(default) KisExifIO::loadFrom: Unknown exif tag, cannot load: Exif.Iop.InteroperabilityVersion
Comment 10 Alberto Mattea 2023-06-22 12:20:37 UTC
(In reply to Halla Rempt from comment #9)
> Following
> https://ninedegreesbelow.com/photography/embedded-color-space-information.
> html
> 
> halla@thinkstations:~$ exiftool -a -S -G0 -ColorSpace -InteropIndex
> -WhitePoint -PrimaryChromaticities -Gamma -ICC_Profile:all _DSF5485.JPG 
> [EXIF] ColorSpace: Uncalibrated
> [EXIF] InteropIndex: R03 - DCF option file (Adobe RGB)
> [EXIF] WhitePoint: 0.313 0.329
> [EXIF] PrimaryChromaticities: 0.64 0.33 0.21 0.71 0.15 0.06
> [EXIF] Gamma: 2.2
> 
> So, it looks like ColorSpace really is not set to '2' -- Adobe RGB. as noted
> in the Affinity thread. Gimp must be faking that.
> 
> And as for InteropIndex, Krita logs:
> 
> krita(1091750)/(default) KisExifIO::loadFrom: Unknown exif tag, cannot load:
> Exif.Iop.InteroperabilityIndex
> krita(1091750)/(default) KisExifIO::loadFrom: Unknown exif tag, cannot load:
> Exif.Iop.InteroperabilityVersion

Yeah, as far as I know a ColorSpace value of 2 for AdobeRGB is not actually in the exif standard, so many cameras just set it to "uncalibrated" and use the Interoperability Index instead. Note that as part of my experiments I also tried setting ColorSpace to 2 (without embedding the icc profile) and krita still treated it as sRGB
Comment 11 Halla Rempt 2023-06-22 13:05:10 UTC
Yes -- because it's not part of the standard, so we don't take it into account. And for the rest of the tags, anything that we didn't know about in 2007, and anything that's a bit custom (like all the fujifilm tags) is skipped. It was never a big problem because working with camera images hasn't been the main goal of Krita for ages. But since it's there, we really need to figure out how to fix this properly.