Skip to content

Decode non-grid HEIC images in bounded decoding - #33

Merged
laurenspriem merged 1 commit into
ente:mainfrom
laurens-pilot:feat/bounded-single-image
Nov 5, 2026
Merged

laurenspriem merged 1 commit into
ente:mainfrom
laurens-pilot:feat/bounded-single-image

Conversation

@laurens-pilot

Copy link
Copy Markdown

decode_bounded only accepted grid primaries, so non-grid HEICs, including some iPhone exports, failed with "primary item must be a HEIC grid". A single hvc1/hev1 primary is now decoded as a grid with one tile, with the same orientation, Exif and colour handling as a grid.

Unlike a grid, a single image is reconstructed all at once. Its workspace is reserved during preflight from the coded size, so an image that doesn't fit the budget is refused before any decoding. Its payload is bounded by the budget rather than the 16 MiB grid tile cap. At a 512 MiB budget this admits single images up to roughly 55 MP (an estimate); grids are unaffected. The bounded path also now accepts a one-channel 8-bit pixi, which only the incremental experiment allowed before.

Measured through ente_image::decode_bounded at a 512 MiB budget and max side 6000, against an area downsample of the full decode:

File Result Peak heap
1718_rotate_90_cw.HEIC exact match 79 MiB
7949_mirror_horizontal_rotate_270_cw.HEIC within ±1 17 MiB
8192×4320 WPP image within ±1, ~0.5 s 270 MiB

At a 32 MiB budget, 1718 is refused with a 9.5 MiB peak. 119 of 172 single-image HEVC files in the local corpora now decode; the rest are 10/12-bit, 4:2:2/4:4:4, alpha or malformed. Grid output is byte-identical to main on all 36 grid files compared.

Ente's non_grid_heic_fixtures_are_rejected_when_present test will need updating when it picks this up, since 1718 and 7949 now decode.

Source fork PR: laurens-pilot#21

@laurenspriem

A single hvc1/hev1 primary is decoded as a grid with one tile. Its
reconstruction workspace is reserved during preflight, so an image that
does not fit the budget is refused before decoding, and its payload is
bounded by the budget instead of the 16 MiB grid tile cap. The bounded
path also accepts a one-channel 8-bit pixi.
@laurens-pilot

Copy link
Copy Markdown
Author

@codex review

@laurenspriem
laurenspriem merged commit 42fca7b into ente:main Nov 5, 2026
3 checks passed
@laurens-pilot
laurens-pilot deleted the feat/bounded-single-image branch November 5, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants