Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some JPEG images in Display P3 color profile fail to produce description #1

Closed
AttilaTheFun opened this issue Jul 12, 2021 · 5 comments
Assignees

Comments

@AttilaTheFun
Copy link

Hi! I'm trying out your library for my image processing web server and seeing a strange bug when trying to get the description of the color space for some JPG images with a Display P3 color profile. I have attached one such image:

decode

When I try to decode the description, I get the error "expected 'desc' but got 'desc'" even though the macOS preview window correctly shows the color space as Display P3.

@mandykoh mandykoh self-assigned this Jul 14, 2021
@mandykoh
Copy link
Owner

mandykoh commented Jul 14, 2021

Hi @AttilaTheFun, thanks for reporting this. The error message has copy-pasta—it should say "expected 'mluc' but got 'desc'". I’ll get this fixed.

As to why this happens, on a quick glance, it looks like this image contains a profile marked as V4 but the profileDescriptionTag is in V2 format…I’ll try to have a deeper look at why this might be and how it should be handled. Can you provide any information about how this image was created, where the profile came from, etc?

@mandykoh
Copy link
Owner

Also do you mind if I extract the profile from this image and include it as data for a test case?

@AttilaTheFun
Copy link
Author

AttilaTheFun commented Jul 15, 2021

@mandykoh Sure thing! I have a way to produce images that reproduce the issue reliably.

iOS converts wide color images to the Display P3 color profile when using the UIGraphicsImageRenderer class which is the new (since iOS 10) standard way to export images from the user's camera roll for upload to a web server.

Here is another image I exported using that same approach:
E431A404-FD12-41EC-91C2-EA8D8ECB2360

The source image was a HEIC image that comes bundled with iOS simulators for testing. I used UIGraphicsImageRenderer to export it as a wide color jpeg.

I saw that the value was actually a v2 desc field. I'm not sure if there is a mulc tag after that or not.

Out of curiosity, I downloaded both the v2 and v4 specifications from color.org, and I see that there is some talk of backwards compatibility with the v2 desc tag in the v4 spec. I suspect this image may have both tags so that v2 readers can display the desc and v4 readers would either ignore the field or map it into a mulc tag.

From the v4 spec:

For profiles conforming to ICC Profile Specification ICC.1:2001-12 (ICC V4.0.0) and later, the entire multiLocalizedUnicodeType contents of the Profile Description Tag shall be included in the Profile Identifier structure. For profiles conforming to ICC Profile Specification ICC.1:2001-04 (ICC V2.4.0) and earlier, the contents of the textDescriptionType Profile Description Tag shall be converted to multiLocalizedUnicodeType and used in the Profile Identifier structure.

NOTE One way of creating a multiLocalizedUnicodeType from a textDescriptionType is by converting the 7-bit ASCII part of the textDescriptionType to a 'enUS' Unicode string by mapping the 7-bit ASCII characters to 16-bit Unicode characters, and storing the 'enUS' Unicode string in the multiLocalizedUnicodeType.

Per the spec, I think the solution here is to parse the v2 desc tag as ASCII text first, then map the ASCII text to UTF-16 and store it in the MultiLocalisedUnicode entriesByLanguageCountry map. If the image has a separate enUS localized value, it would overwrite this value. But if it does not we'd at least have an English localization.

@mandykoh
Copy link
Owner

Thanks for the info! Given that we’re abstracting over v2/v4, and that you can tell whether it’s a desc or a multiLocalizedUnicodeType from the tag type, I’ve chosen to parse based on the tag type. (We might need a strategy like you’ve described when we need to handle profiles with both v2 and v4 descriptions in future but we can cross that bridge when we get to it, if such profiles are a thing.)

Can you try v0.34.0 and see if it fixes this issue for you?

@AttilaTheFun
Copy link
Author

Yep! I just verified that v0.34.0 fixes the issue and I'm able to parse the description of Display P3 images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants