Repository navigation
Decode HEVC tiles row by row on 32-bit targets, and add decode_bounded_tiny - #43
Merged
Merged
Conversation
rav1d needs 64-bit atomics, which 32-bit targets such as xtensa-esp32s3-espidf lack. AVIF decoding now sits behind a default `avif` feature; without it, AVIF decodes return DecoderUnavailable. The temp spool counter becomes an AtomicUsize.
At the end of each CTU row, the in-memory row decoder now reads end_of_subset_one_bit, moves to the next entry point and restores the contexts saved after the row's second CTU, like the whole-picture decoder. The entry point adjustment for emulation prevention bytes moves out of decode_slice so both paths share it. The streaming path still rejects WPP because it cannot seek.
rows::info and rows::decode_rows decode one HEVC coded item, such as a grid tile, one CTU row band at a time. The tests compare every band with the whole-tile decode on the in-repo Apple WPP fixtures and on a single-substream slice.
Without the avif feature, image-integration no longer registers the AVIF decoding hook or the avif/avis format detection hooks, so they cannot shadow another AVIF decoder, and the registration reports the AVIF hook as not registered. API.md now lists the real default features and the row API's emulation prevention bookkeeping.
decode_bounded_tiny takes the same options and returns the same pixels as decode_bounded, but decodes one coded item at a time on the calling thread, a CTU row at a time, and reduces each row into the output straight away. WPP items are decoded from a copy of the item's payload; other items are streamed from the input. Preflight reads only item headers, and admission reserves the output plus the largest row workspace instead of a whole tile's reconstruction. decode_bounded is unchanged.
…refuses decode_bounded_tiny now reserves header-parsing memory from the actual parameter-set and slice-prefix sizes, so crafted 64 KiB parameter sets can no longer push it past its budget, and it charges only the three CTU rows of SAO state it keeps. It refuses a grid primary that carries an hvcC, as decode_bounded does. Without the avif feature, AVIF decodes return DecoderUnavailable before reading the coded payload. API.md lists the inputs tiny refuses and the AVIF content-guessing limit.
decode_bounded now decodes 10- and 12-bit items and tone maps PQ and HLG, while decode_bounded_tiny and rows::decode_rows still decode 8-bit SDR only. API.md lists those refusals, and a test checks that decode_rows refuses a 10-bit item instead of decoding it into 8-bit bands.
Author
|
@codex review |
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.
The Ente e-ink frame (ESP32-S3 with 8 MB PSRAM) needs to decode iPhone HEIC originals without holding whole tiles in memory. This adds:
aviffeature. With default features off, the crate builds forxtensa-esp32s3-espidf. Withoutavif, AVIF decodes returnDecodeAvifError::DecoderUnavailablebefore reading the coded payload, and theimagehooks leaveavif/avis-branded files to other decoders. The temp spool counter is now anAtomicUsize. Builds with default features, such as ente-image, are unchanged; the new error variant means exhaustive matches onDecodeAvifErrorneed an extra arm (ente-image has none).rows::infoandrows::decode_rows, which decode one coded item a CTU row at a time and hand out the Y/Cb/Cr samples.decode_bounded_tiny, a separate bounded decode for small-memory devices. It takes the same options and returns the same image asdecode_bounded, but decodes one coded item at a time, a CTU row at a time, on the calling thread.decode_boundeditself is unchanged.On 452 local HEIC/HEIF/AVIF files at max side 6000, 1600 and 512,
decode_bounded_tinygave byte-identical output todecode_boundedon all 480 decodes where both succeed. It refused only the 13 10-bit files thatdecode_boundednow decodes, and it also decodes 8 large single images thatdecode_boundedrefuses for memory. Under an allocator that refuses anything beyond the budget, every one of its 336 decodes at 1600 and 512 px succeeded at the smallest budget it admits.Memory beyond the output at 1600 px, measured on the Mac:
decode_bounded_tinydecode_bounded(single-threaded)Speed is the same or slightly faster: 186 ms vs 213 ms for a 12 MP photo. Admission is conservative: iPhone photos need a budget of output + 1.2 to 3.8 MB, of which 2 MiB is the colour-transform reservation shared with
decode_bounded. It refuses a few inputsdecode_boundedaccepts: 10- and 12-bit and PQ/HLG images (whichdecode_boundedtone maps since #42), parameter sets outsidehvcC, HEVC tiles, over 256 MP, and multi-tile grids needing 4:4:4 chroma. API.md lists them, androws::decode_rowslikewise refuses 10- and 12-bit items.Not covered: WPP pictures only one or two CTUs wide, which no available encoder produces. Not yet run on the frame itself.
Source fork PR: laurens-pilot#31
@laurenspriem