libheif icon indicating copy to clipboard operation
libheif copied to clipboard

heic image decode color incorrect

Open lam2003 opened this issue 1 year ago • 11 comments

Hi, I use heif_convert command(from libheif example) to convert below heif image to jpg/png. The output image color incorrect which seems too green

1040g008313u8g0qp1m4g5nkalku094d2qla98k0 2.heic.zip

lam2003 avatar Jun 14 '24 11:06 lam2003

output image: 1.jpg.zip

lam2003 avatar Jun 14 '24 11:06 lam2003

I had a look at the file structure. It seems that there is no color-space information in that file (no nclx, no ICC). Also the file structure is different than what I have seen before. The EXIF data says that it was captured by a Xiaomi camera. Is that correct, or was it post-processed in some other software?

farindk avatar Jun 14 '24 11:06 farindk

The original image can play on MacOS(Version 13.4.1) correctly. I use mediainfo to parse file structure and found something difference.

1

lam2003 avatar Jun 14 '24 12:06 lam2003

Is there something wrong on the color conversion?

lam2003 avatar Jun 14 '24 12:06 lam2003

I have confirm the rgb matrix take from decoder already has color incorrection

lam2003 avatar Jun 14 '24 12:06 lam2003

It's strange that your tool says RGB colorspace, but Chroma 4:2:0. I'll need to have a closer look into the h265 stream.

farindk avatar Jun 14 '24 13:06 farindk

It's strange that your tool says RGB colorspace, but Chroma 4:2:0.

... and matrix coeffs identity? exiftool indeed does not see any nclx or ICC either, but only chroma 4:2:0 as well - no matrix coeffs, no transfer curve...

The white comes out as (128, 255, 128) in RGB, which looks to me like some (U, Y, V) values?

FWIW, Windows 11 photo app shows it correctly as well.

kmilos avatar Jun 14 '24 13:06 kmilos

Attach file is h265 stream

https://github.com/strukturag/libheif/assets/22312935/914cff8b-23ec-4cd3-ab70-9f6bdc92e5a0

1040g008313u8g0qp1m4g5nkalku094d2qla98k0.h265.zip

lam2003 avatar Jun 14 '24 14:06 lam2003

It's strange that your tool says RGB colorspace, but Chroma 4:2:0.

... and matrix coeffs identity? exiftool indeed does not see any nclx or ICC either, but only chroma 4:2:0 as well - no matrix coeffs, no transfer curve...

The white comes out as (128, 255, 128) in RGB, which looks to me like some (U, Y, V) values?

FWIW, Windows 11 photo app shows it correctly as well.

The matrix coeffs value is 0; image

lam2003 avatar Jun 14 '24 14:06 lam2003

My assumption is that these other libraries have sanity checks to change RGB 4:2:0 to Unspecified (and just treat that as 709), because shoddy developers assuming 0 is default or just not caring is definitely A Thing. This isn't an illegal configuration, if someone decided to subsample red & blue, it's just a weird and slightly crazy one.

I haven't checked whether flipping that bit to 1 will fix it, I can try when I get home tonight, but I suspect it will.

silverbacknet avatar Jun 14 '24 20:06 silverbacknet

My assumption is that these other libraries have sanity checks to change RGB 4:2:0 to Unspecified (and just treat that as 709), because shoddy developers assuming 0 is default or just not caring is definitely A Thing. This isn't an illegal configuration, if someone decided to subsample red & blue, it's just a weird and slightly crazy one.

I haven't checked whether flipping that bit to 1 will fix it, I can try when I get home tonight, but I suspect it will.

image

I set matrix_coefficients to heif_matrix_coefficients_unspecified and output image can show correctly. Thank you!

2.png.zip

lam2003 avatar Jun 15 '24 02:06 lam2003