Repository navigation
Match libheif when rotating or mirroring odd 4:2:0 and 4:2:2 images - #38
Merged
laurenspriem merged 1 commit intoNov 24, 2026
Merged
Conversation
libheif converts a 4:2:0 image to 4:4:4 with bilinear chroma before an irot that reverses an odd side, and before any imir when either side is odd. It converts a 4:2:2 image before a 90 or 270 degree irot, a 180 degree irot of an odd height, and a left-right imir of an odd width, but rotates the half-width chroma planes of an odd-width 4:2:2 image by 180 degrees without converting them. The regular RGBA, RGB8 and image-hook paths now walk the transforms as libheif does, tracking the image size: they apply the transforms before the first conversion to the YUV planes, then build the 4:4:4 image in bands with the limited-range round trip and late colr override the odd clap crop already models, and leave the rest to the RGBA path. Grids that need this go through the assembled canvas. generate.rb adds an orientation subdirectory that default verify compares exactly against heif-dec. The 4:2:0 cases rotate or mirror an odd grid canvas and then trim one pixel from every edge with a clap, because the pinned libheif's 4:2:0 bilinear border is defective. The 4:2:2 cases keep their edges, as that kernel has no defect. wrap.rb gains TRANSFORM_ORDER and takes the chroma format from the SPS.
Author
|
@codex review |
1 similar comment
Author
|
@codex review |
This was referenced Nov 24, 2026
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.
libheif also converts an image to 4:4:4 with bilinear chroma before some rotations and mirrors:
irotthat reverses an odd side, and before anyimirwhen either side is odd.irot, a 180°irotof an odd height, or a left-rightimirof an odd width. An odd-width 4:2:2 image's half-width chroma planes are rotated by 180° without conversion.heic-decoder rotated and mirrored RGBA converted with nearest-neighbour chroma instead, and differed by up to 92 when an odd-width crop was followed by such a rotation or mirror. The regular RGBA, RGB8 and image-hook paths now walk the transforms the way libheif does, tracking the image size. They apply the transforms before the first conversion to the YUV planes. The conversion then builds the 4:4:4 image in bands, with the same limited-range round trip and late
colroverride as the odd-origin crop in #25, and the rest goes to the RGBA path. Grids that need this go through the assembled canvas. For a 7999×8000 grid withirot1, peak heap on the RGB8 path is 387 MB, against 768 MB when the whole image is converted first.The generated corpus gains an
orientation/subdirectory of 13 cases, which default verify compares exactly againstheif-dec:clap, because the pinned libheif's 4:2:0 bilinear border is defective.wrap.rbgainsTRANSFORM_ORDERand now takes the chroma format from the SPS.This is stacked on #25. Locally, all 29 files of the regenerated incremental corpus pass the exact verify.
decode_boundedstill refuses these transforms.Source fork PR: laurens-pilot#26
@laurenspriem