Centralize HEIF/AVIF encoded output ownership - #466
Open
gregbenz wants to merge 1 commit into
Open
Conversation
gregbenz
force-pushed
the
codex/heif-avif-owned-output-current-main
branch
from
September 10, 2026 02:35
ce74204 to
6e0c915
Compare
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.
Why
HEIF/AVIF encoding currently keeps two output allocations alive when encoding finishes: the
writer's growable buffer and a separate
uhdr_encode()result buffer reserved asmax(64 KiB, 6 * width * height). The encoded bytes are then copied from one buffer to the other.This change lets the returned compressed image take ownership of the writer's allocation. That
removes the speculative result allocation and final copy, reducing peak memory use during
HEIF/AVIF encoding. It also allows valid output larger than the old estimate to succeed.
What changed
free-compatiblecleanup without relying on C++ exceptions.
data_szwhen a fixeddestination is invalid or too small.
larger than the old estimate, buffer reuse, and null-data validation.
The public C API remains unchanged, and this does not change decoder behavior.
Testing
-fno-exceptions -Wall -Wextra -Wshadow -Werror.