strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.
Other
1.71k stars 298 forks source link

heic image decode color incorrect #1189

Open lam2003 opened 3 months ago

lam2003 commented 3 months ago

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 commented 3 months ago

output image: 1.jpg.zip

farindk commented 3 months ago

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?

lam2003 commented 3 months ago

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 commented 3 months ago

Is there something wrong on the color conversion?

lam2003 commented 3 months ago

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

farindk commented 3 months ago

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.

kmilos commented 3 months ago

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.

lam2003 commented 3 months ago

Attach file is h265 stream

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

1040g008313u8g0qp1m4g5nkalku094d2qla98k0.h265.zip

lam2003 commented 3 months ago

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
silverbacknet commented 3 months ago

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.

lam2003 commented 3 months ago

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