Repository navigation
Decode odd crops and odd-sized rotations in decode_bounded - #39
Merged
laurenspriem merged 1 commit intoNov 25, 2026
Merged
Conversation
decode_bounded refused every file for which libheif converts 4:2:0 chroma to 4:4:4 first: a clean aperture with an odd origin, or a rotation or mirror of an odd-sized image. It now converts them the way the regular decoders do, with bilinear chroma, the limited-range round trip and the late colr override, one band of rows at a time while each tile is converted to RGB. Grid tiles are converted in units shifted one pixel up and left, so each unit only needs the last chroma row and column of tiles decoded before it. Those edges are kept in canvas-wide strips between the decode and render phases. Grids that need no conversion keep the single-pass path. The incremental experiment shares the converter, which adds the round trip it skipped and judges the conversion with libheif's walker instead of the final crop's parity, so crops after orientation work. generate-bounded.rb replaces its refuse-* cases with pass-* cases, including tiled grids, that trim the converted image's edges.
Author
|
@codex review |
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.
decode_boundedrefused every HEIC for which libheif converts 4:2:0 chroma to 4:4:4 first: aclapwith an odd origin, or anirot/imirof an odd-sized image. It now decodes them the way the regular decoders do (bilinear chroma, the limited-range round trip, the latecolroverride), building 4:4:4 a band of rows at a time while each tile is converted to RGB. Whether to convert is decided withlibheif_converts_to_yuv444_before, judged at the size the image has when each transform applies.On grids, tiles are converted in units shifted one pixel up and left. Each unit then only needs the last chroma row and column of tiles decoded before it, and those edges are kept in canvas-wide strips. Grids that need no conversion keep the old single-pass decode. The incremental experiment uses the same converter. That adds the round trip it was missing and lets crops come after orientation; grids of several tiles that need the conversion are still refused there. Tile-level transforms and 4:2:2 (unsupported by the bounded HEVC decoder) stay refused.
generate-bounded.rb'srefuse-*cases now decode, and against pinned libheif 1.21.2 they differ only on the converted image's edge pixels. That is the pinned border defect:decode_boundedmatches the regular decoder exactly on all seven. They are replaced bypass-*cases that end with a 1-pixel trim, including 2×2 and 3×2 grids whose seams fall inside the converted area, so CI's--require-passcovers the new paths.Evidence, on a fresh
generate.rbcorpus and the pinned oracle:verify-bounded.rbover the CI corpora went from 106 to 148 passes with no new failures. The odd-crop and 4:2:0orientation/files, and the newpass-*grids, are exact at full size and within ±1 at side 97.Source fork PR: laurens-pilot#28
@laurenspriem