strukturag / libheif

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

For monochrome image `heif_image_handle_get_preferred_decoding_colorspace` return YCbCr ? #1390

Closed bigcat88 closed 3 days ago

bigcat88 commented 5 days ago

I'm trying the new libheif version 1.19.3 and I noticed that on image with one channel it tells me that Colorspace=0(YCBCR) and Chroma=1(420)

In version 1.18 - for this image results was: Colorspace=2(MONOCHROME), Chroma=0(MONOCHROME) (AFAIK)

This is how it should be? If so - then how can I correct determine in version 1.19 that this is a monochrome image without decoding?

Example of test image if needed can be found here

bradh commented 5 days ago

The format in the pixi box is a single channel, and the hvcC box has chroma_format_idc of 0 (which is monochrome), so I think it should not be chroma of 4:2:0.

However that is not what I get when using heif-info from current master (which is probably pretty close to 1.19.3)

MIME type: image/heic
main brand: heic
compatible brands: mif1, heic, miaf

image: 29x100 (id=1), primary
  tiles: 1x1, tile size: 29x100
  colorspace: monochrome
  bit depth: 8
  color profile: no
  alpha channel: no 
  depth channel: no
metadata:
  none
transformations:
  crop: left=0 top=0 right=35 bottom=0
region annotations:
  none
properties:

Can you say where you are getting "Colorspace=0(YCBCR) and Chroma=1(420)" from?

farindk commented 5 days ago

I also don't see where "4:2:0" is returned. heif_decode_image() with heif_colorspace_unknown and heif_chroma_unknown returns monochrome:

image

bigcat88 commented 4 days ago

Sorry, I incorrectly identified the file with which this happens.

It happens with the same file but in avif format

File was created 9 months ago and with libheif 1.18 version it was detected as monochrome... Maybe that was the bug of 1.18 version and file in reality is not a monochrome and I should rebuild "avif" files

bradh commented 4 days ago

Indeed that file should be mono from both the pixi box and av1C.

Looks like we are missing a check for the monochrome bit flag in https://github.com/strukturag/libheif/blob/8363b2cb25426b73a999f871970aac315eace55d/libheif/codecs/avif_boxes.h#L70-L83

farindk commented 4 days ago

@bradh Right, that function misses the monochrome case. I've added it.

This only affected the output of heif_image_handle_get_preferred_decoding_colorspace(). The decoding function heif_decode_image() correctly returned the monochrome image.

bradh commented 3 days ago

Can this issue be closed?

bigcat88 commented 3 days ago

Yes. Can a release be published with it please when someone has time?

farindk commented 3 days ago

Version 1.19.4 has been released.

bigcat88 commented 3 days ago

thank you