Repository navigation
Match libheif when transforms convert AVIF chroma to 4:4:4 - #40
Merged
laurenspriem merged 3 commits intoNov 25, 2026
Merged
Conversation
AVIF items converted to RGBA with nearest-neighbour chroma before their clap/irot/imir, so they differed from libheif wherever it first converts 4:2:0 or 4:2:2 to bilinear 4:4:4. Those items now go through the HEIC conversion path: transforms before the conversion run on the planes, the 4:4:4 image is built in bands, the coded colour drives the conversion and a colr nclx property applies afterwards. The coded colour of an AV1 item is its sequence header's color_config. AVIF items without a colr nclx property used to convert as full range with unspecified coefficients; they now use the sequence header, as libheif does. wrap.rb also wraps an FFmpeg AVIF, and generate.rb writes AVIF cases to incremental-corpus/avif so default verify compares them with heif-dec.
Author
|
@codex review |
…orm-chroma # Conflicts: # TESTING.md
This was referenced Nov 26, 2026
laurenspriem
added a commit
to ente/ente
that referenced
this pull request
Nov 26, 2026
Update `ente-image`'s HEIC decoder pin from `5fbe1d2` to [`5b0a6af`](ente/heic-decoder@5fbe1d2...5b0a6af). It brings: - Faster bounded decoding of grid HEICs (ente/heic-decoder#41). Measured there on a Pixel 10, `decode_bounded` took 0.62–0.77× as long as the regular decoder on 12–24 MP phone HEICs, against 1.14–1.29× before. This is the path ML indexing, face thumbnails, OCR and the internal Android HEIC viewer use. - `decode_bounded` now decodes HEICs with an odd-origin crop or an odd-sized rotation or mirror instead of refusing them (ente/heic-decoder#39). - The regular decoder now matches libheif on those crops, rotations and mirrors in HEIC and AVIF, converting chroma to 4:4:4 before the transform (ente/heic-decoder#37, #38, #40). A grid whose tiles need different conversions now fails, as it does in libheif. - AVIF items without a `colr` nclx property now use the AV1 stream's range and matrix (ente/heic-decoder#40). On 309 HEIC, HEIF and AVIF files (ente's test fixtures, phone HEICs, libheif's examples, fuzz and stress files, and heic-decoder's generated corpora), both decoders give the same pixels or the same refusal under both pins on 294, including every real phone photo. The other 15 are generated odd-crop and odd-size rotation and mirror files: the regular decoder now gives different pixels, and `decode_bounded` decodes them instead of refusing, with exactly the regular decoder's output. Source fork PR: laurens-pilot#308 @laurenspriem Co-authored-by: laurenspriem <laurens-pilot-git@lrns.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AVIF items converted to RGBA with nearest-neighbour chroma before their
clap/irot/imir, so they differed from libheif wherever it first converts 4:2:0 or 4:2:2 to bilinear 4:4:4. That happens for crops with an odd origin and for rotations and mirrors of odd sizes. On 22 SVT-AV1 test files, 19 differed fromheif-dec. Only the three controls that need no conversion matched. On photo content every pixel differed, by up to 21 levels at 8-bit, mostly from libheif's limited-range round trip and its latecolrrelabel. On a harsh chroma pattern the difference reached 211 levels.These items now go through the HEIC code from #37 and #38. That covers plane transforms before the conversion, the 4:4:4 image built a band at a time, conversion with the coded colour, and the
colroverride applied afterwards. Items that need no conversion keep the existing AVIF path. An 8-bit item that needs the conversion has its planes widened to 16-bit for the decode.The AVIF path also ignored the AV1 sequence header's colour: an item without a
colrnclx property converted as full range with unspecified (BT.601) coefficients. It now uses the sequence header's range and matrix, as libheif does, anddecode_primary_avif_to_imagereports them. This changes RGBA output for such files, for example ICC-only AVIFs with a limited-range or BT.709 stream. A limited-range test file withoutcolrdiffered by up to 47 levels before.wrap.rbcan now wrap an FFmpeg AVIF, and its HEVC output is byte-identical.generate.rbwrites 16 AVIF cases toincremental-corpus/avif/: 8-bit and 10-bit, full and limited range, acolroverride that differs from the stream, and items withoutcolr. It uses libaom-av1 when FFmpeg has it and libsvtav1 otherwise. Locally, using SVT-AV1 4.2, all 16 cases matchheif-decexactly. The full default verify has 317 files, 264 exact and 0 failures. The bounded runner refuses the AVIF cases. No fixture covers 4:2:2 AVIF, which SVT-AV1 cannot encode, or alpha combined with a converting transform. Unit tests cover both through the shared code.Source fork PR: laurens-pilot#27
@laurenspriem