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

Output .avif image is washed out #7308

Open
everthis opened this issue May 11, 2024 · 6 comments
Open

Output .avif image is washed out #7308

everthis opened this issue May 11, 2024 · 6 comments

Comments

@everthis
Copy link

everthis commented May 11, 2024

ImageMagick version

7.1.1-32

Operating system

Linux

Operating system, version and so on

Ubuntu 24.04 LTS x86_64

Description

$ magick -version
Version: ImageMagick 7.1.1-32 Q16-HDRI x86_64 22207 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): fontconfig freetype heic png x xml zlib
Compiler: gcc (11.4)

The screenshot below is comparison of original hdr.avif(left) and out.avif(right).
As you can see, the ouput file out.avif is washed out, which is not desired.

329444577-d183aa4d-d9c0-4d89-8f0b-1a59552f8bc0

Steps to Reproduce

  1. Save https://raw.githubusercontent.com/AOMediaCodec/av1-avif/master/testFiles/Netflix/avif/hdr_cosmos01650_cicp9-16-9_yuv444_full_qp10.avif as hdr.avif
  2. Execute command: magick hdr.avif -resize 50% out.avif
  3. Preview the original file and output file in Chrome Version 124.0.6367.158 (Official Build) (64-bit)(Any version above v85 should also produce the same result).

Images

avif.zip
(This .zip file contains original hdr.avif and output out.avif)

@dlemstra
Copy link
Member

dlemstra commented May 11, 2024

The same thing happens when we run magick hdr.avif out.jpg so I suspect this has something to do with how the image is read. We are reading the image in the RGB colorspace but the preferred decoding colorspace of this image is YCbCr. I suspect that some internal color conversion in the aom or heif library is causing this issue.

And next time there is no need to create an issue when there is already an active discussion.

@kmilos
Copy link
Contributor

kmilos commented May 14, 2024

We are reading the image in the RGB colorspace

It's more likely the fact that IM is assuming sRGB when reading/converting images. The original is in the CICP 9/16/9 color space (BT.2020 color primaries and D65 white w/ PQ transfer curve).

Btw, "RGB colorspace" doesn't mean anything to me, except there are three (undefined) components. Which "RGB"? Primaries? White point? Transfer curve?

@dlemstra
Copy link
Member

There is an api that allows us to read the image in sRGB/RGB and that should do the color conversion but that is not happening correctly? We could read the image in YCbCr but I don't think we will be adding a patch for that anytime soon.

@kmilos
Copy link
Contributor

kmilos commented May 15, 2024

We could read the image in YCbCr

What you see above is not a YCbCr image - the channels are correct (green is still "some" green, blue is still "some" blue, etc.), just that the primaries and the transfer function are not mapped correctly.

There is an api that allows us to read the image in sRGB/RGB and that should do the color conversion

libavif/libheif don't have an API to do any "color space" conversion. They can only change format from YCbCr to RGB in the original image color space (BT.2020 + PQ in this case), it is up to clients to do color management. You're not getting an sRGB image automagically upon reading.

@kmilos
Copy link
Contributor

kmilos commented May 15, 2024

Another part of the problem could be that here:

length=heif_image_handle_get_raw_color_profile_size(image_handle);

you assume there will be an ICC profile embedded in the image, but AVIF/HEIF images can also encode their color profile as the CICP tuple only (nclx box), which is the case here:

---- ExifTool ----
ExifToolVersion                 : 12.76
---- System ----
FileName                        : hdr.avif
Directory                       : .
FileSize                        : 372 kB
FileModifyDate                  : 2024:05:07 15:48:38+02:00
FileAccessDate                  : 2024:05:11 14:56:55+02:00
FileCreateDate                  : 2024:05:10 10:48:15+02:00
FilePermissions                 : -rw-rw-rw-
---- File ----
FileType                        : AVIF
FileTypeExtension               : avif
MIMEType                        : image/avif
ImageWidth                      : 2048
ImageHeight                     : 858
---- QuickTime ----
MajorBrand                      : AV1 Image File Format (.AVIF)
MinorVersion                    : 0.0.0
CompatibleBrands                : avif, mif1, miaf, MA1A
HandlerType                     : Picture
HandlerDescription              : libavif
ImageSpatialExtent              : 2048x858
ImagePixelDepth                 : 10 10 10
AV1ConfigurationVersion         : 1
SeqProfile                      : 1
SeqLevelIdx0                    : 8
SeqTier0                        : 0
HighBitDepth                    : 1
TwelveBit                       : 0
ChromaFormat                    : YUV 4:4:4
ChromaSamplePosition            : Unknown
InitialDelaySamples             : 1
ColorProfiles                   : nclx
ColorPrimaries                  : BT.2020, BT.2100
TransferCharacteristics         : SMPTE ST 2084, ITU BT.2100 PQ
MatrixCoefficients              : BT.2020 non-constant luminance, BT.2100 YCbCr
VideoFullRangeFlag              : 1
MediaDataSize                   : 372069
MediaDataOffset                 : 282
MediaData                       : (Binary data 372069 bytes, use -b option to extract)
---- Meta ----
PrimaryItemReference            : 1
---- Composite ----
ImageSize                       : 2048x858
Megapixels                      : 1.8

so I guess this gets ignored by IM? out.avif is tagged as sRGB by default in the absence of a color profile, but I guess the pixel values are not remapped from the original:

ColorProfiles                   : nclx
ColorPrimaries                  : BT.709
TransferCharacteristics         : sRGB or sYCC
MatrixCoefficients              : BT.601

See also #6642

@kmilos
Copy link
Contributor

kmilos commented May 15, 2024

Also, CICP is now part of the PNG specification as well as an alternative to ICC, so you might want to consider supporting it in some way throughout (e.g. throw a warning if detected as minimum).

AFAIK, only libjxl will do an on-the-fly conversion of its internal color profile encoding to ICC...

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

No branches or pull requests

3 participants