strukturag / libheif

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

AVIF color grid without alpha grid looses alpha when decoded #708

Closed y-guyon closed 1 year ago

y-guyon commented 1 year ago

This is an image encoded with avifenc --grid 1x2 (at https://github.com/AOMediaCodec/libavif/commit/cd03eef10a7cc6081ee98e3911e21d977a2bf17b using ext/aom):

colorgrid_alphagrid avif (extension is .jpg but it is an actual AVIF file)

The pattern is the following:

[primary item grid]
   ^       ^     ^
   |dimg   |dimg |
   |       |     |auxl
[color] [color]  |
                 |
   [alpha aux grid]
      ^       ^
      |dimg   |dimg
      |       |
   [alpha] [alpha]

Here is the same image manually edited to match the following pattern:

colorgrid_alpha_alpha avif

[primary item grid]
   ^       ^
   |dimg   |dimg
   |       |
[color] [color]
   ^       ^
   |auxl   |auxl
   |       |
[alpha] [alpha]

I did not find anything in ISOBMFF, HEIF and MIAF specifications regarding the invalidity of this pattern. Compliance Warden does not report more errors than for the image generated only with avifenc (even fewer errors actually because there is one less grid to complain about construction_method=-1 on a derived image item).

heif-convert (at d3ec0df07ef1c6f01f0ce81885f76128f3f1fc52 using installed aom) leads to the wrongly opaque following PNG:

colorgrid_alpha_alpha_libheif

No error is reported by heic-convert.

There is the same issue with libavif: https://github.com/AOMediaCodec/libavif/issues/1203

farindk commented 1 year ago

Thanks for the example image. Let me see why this is the case.

farindk commented 1 year ago

Works now. The heif_image_handle_has_alpha_channel() did not dive into the 'grid' structure previously.