Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,23 +462,26 @@ The primary item may be a grid of uniform HEVC tiles or a single HEVC image
(`hvc1`/`hev1`). Every coded item must be opaque 8-bit 4:2:0 HEVC with one IDR
slice; WPP is supported. A single image is decoded as a grid with one tile.
`clap`/`irot`/`imir` are applied, and Exif orientation applies when no
effective container orientation is present. Container transforms for which
libheif first converts 4:2:0 chroma to 4:4:4 return `Unsupported`. Each is
judged at the size the image has when it applies: a `clap` with an odd left or
top edge, an anticlockwise 90° rotation (`irot` 1) of an odd width, a 180°
rotation with either side odd, an anticlockwise 270° rotation (`irot` 3) of an
odd height, or a mirror with either side odd. A display area that starts on an
odd source row or column is also refused, which is stricter than libheif when
a rotation or mirror comes before the crop. RGB matrix/TRC ICC profiles and
SDR nclx colour with BT.709, BT.2020 or Display P3 primaries are converted to
sRGB. HDR transfer functions, grayscale or
lookup-table ICC profiles, unprofiled wide-gamut HEVC colour, alpha, and
unknown required auxiliaries return errors. Known depth, semantic matte, and
effective container orientation is present. When a container transform makes
libheif convert 4:2:0 chroma to 4:4:4 (the 4:2:0 rules under Container
transforms above), the output matches the regular decoders: bilinear chroma
with clamped edges, the limited-range round trip through RGB, and the `colr`
nclx override after all transforms. The 4:4:4 samples are built a band of rows
at a time while each tile is converted to RGB, so no full-size 4:4:4 image is
held. Grid tiles are then converted in units shifted one pixel up and left, so
each unit needs only the last chroma row and column of tiles decoded before
it; those edges are kept in strips as wide as the canvas. Clean apertures,
rotations and mirrors on individual grid tiles are refused. RGB matrix/TRC ICC
profiles and SDR nclx colour with BT.709, BT.2020 or Display P3 primaries are
converted to sRGB. HDR transfer functions, grayscale or lookup-table ICC
profiles, unprofiled wide-gamut HEVC colour, alpha, and unknown required
auxiliaries return errors. Known depth, semantic matte, and
gain-map auxiliaries are ignored.

Before any pixel decoding, preflight reads every coded item's headers and
reserves its reconstruction workspace, and admission then reserves the output
together with the largest tile workspace. Inputs that do not fit return
together with the largest tile workspace, which includes the 4:4:4 band
buffers when the conversion applies. Inputs that do not fit return
`MemoryBudgetExceeded` or `LimitExceeded` without decoding pixels. Grid tiles
decode one at a time, or concurrently with `parallel-grid` when the budget
allows. A single image's full-resolution reconstruction must fit the budget at
Expand Down Expand Up @@ -517,9 +520,9 @@ payloads. Use Path input when avoiding a caller-owned compressed input buffer
is also important.

This first subset retains limits of 16384 per coded side, 256 million display
pixels, bounded metadata, and a 64 KiB slice-header prefix. It supports one
clean-aperture crop before orientation, with chroma interpolation for odd
origins on a single coded image or one-tile grid. Odd-origin crops across
multiple grid items and repeated crops or crops after orientation are
unsupported. Exif orientation applies when no effective container orientation
is present. `decoder-tracing` disables bounded decoding.
pixels, bounded metadata, and a 64 KiB slice-header prefix. It applies
`clap`/`irot`/`imir` in property order and converts to 4:4:4 like
`decode_bounded` on a single coded image or a one-tile grid. Grids of several
coded items that need the 4:4:4 conversion return `Unsupported`. Exif
orientation applies when no effective container orientation is present.
`decoder-tracing` disables bounded decoding.
23 changes: 14 additions & 9 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,15 @@ These files are kept out of `incremental-corpus` because `verify.rb` requires
every file there to decode with the incremental experiment. The script refuses
an output folder that overlaps the incremental corpus, or that is not empty
and lacks the `.generate-bounded` marker it writes, and it only replaces the
`pass-*` and `refuse-*` files in its own folder. `refuse-*` files use rotations, mirrors or
grid canvases for which libheif converts to 4:4:4, so `decode_bounded` must
refuse them; if one decodes, the pixel comparison fails. `pass-*` files are
the matching controls and the Display P3 and BT.2020 nclx cases. CI passes
every `pass-*` file, `IMG_0983.HEIC` and `1718_rotate_90_cw.HEIC` with
`pass-*` files in its own folder, deleting any `refuse-*` files left by older
versions. The files cover odd crops with rotations that keep 4:2:0 chroma, the
Display P3 and BT.2020 nclx cases, and transforms for which libheif converts
to 4:4:4: odd-origin crops and odd-sized rotations and mirrors, on one tile and
on 2×2 and 3×2 grids whose seams fall inside the converted area. Rotations and
mirrors that convert are followed by a crop that trims one pixel from every
side, because the pinned libheif 1.21.2 interpolates the converted image's
edge rows and columns differently from the fixed kernel the decoders use. CI
passes every `pass-*` file, `IMG_0983.HEIC` and `1718_rotate_90_cw.HEIC` with
`--require-pass`, which fails the run unless that file passes at both sizes.

Every HEIC, HEIF and AVIF file under the given paths is decoded at max side
Expand Down Expand Up @@ -248,10 +252,11 @@ hidden: `heif-dec` writes visible tiles first, and `verify` would compare the
primary decode against a tile. Cases whose grid tiles carry their own odd
clean aperture are written to the `tile-crop` subdirectory. The incremental
and bounded decoders refuse tile crops. Cases that rotate or mirror odd-sized
or 4:2:2 images are written to the `orientation` subdirectory, because the
incremental and bounded decoders do not yet reproduce libheif's 4:4:4
conversion for them. The incremental runner below only receives the top-level
files, and default `verify` covers both subdirectories.
or 4:2:2 images are written to the `orientation` subdirectory. The bounded
decoder reproduces libheif's 4:4:4 conversion for the 4:2:0 cases there and
refuses the 4:2:2 ones, which its HEVC decoder does not support. The
incremental runner below only receives the top-level files, and default
`verify` and the bounded comparison cover both subdirectories.

```bash
cmake -S scripts/incremental -B .heic-test-runs/incremental-oracle \
Expand Down
35 changes: 25 additions & 10 deletions scripts/incremental/generate-bounded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,35 @@
'pass-odd-canvas-grid-rotate-270' => { 'GRID' => '1', 'CANVAS' => '255x256', 'ROTATION' => '3' },
'pass-nclx-display-p3' => { 'TILE_NCLX' => '12/13/6/0' },
'pass-nclx-bt2020' => { 'TILE_NCLX' => '9/1/9/0' },
'refuse-odd-width-crop-rotate-90' => { 'CROP' => '131x192', 'ROTATION' => '1' },
'refuse-odd-width-crop-rotate-180' => { 'CROP' => '131x192', 'ROTATION' => '2' },
'refuse-odd-height-crop-rotate-180' => { 'CROP' => '192x129', 'ROTATION' => '2' },
'refuse-odd-height-crop-rotate-270' => { 'CROP' => '192x129', 'ROTATION' => '3' },
'refuse-odd-width-crop-mirror-vertical-axis' => { 'CROP' => '131x192', 'MIRROR' => '0' },
'refuse-odd-width-crop-mirror-horizontal-axis' => { 'CROP' => '131x192', 'MIRROR' => '1' },
'refuse-odd-canvas-grid-rotate-180' => { 'GRID' => '1', 'CANVAS' => '255x256', 'ROTATION' => '2' }
'pass-odd-origin-crop' => { 'CROP' => '130x190' },
'pass-odd-origin-crop-rotate-90-mirror' => { 'CROP' => '130x190', 'ROTATION' => '1', 'MIRROR' => '1' },
'pass-odd-canvas-grid-rotate-90-trimmed' => {
'GRID' => '1', 'CANVAS' => '255x256', 'ROTATION' => '1', 'CROP' => '254x253', 'TRANSFORM_ORDER' => 'ROTATION,CROP'
},
'pass-odd-canvas-grid-rotate-180-trimmed' => {
'GRID' => '1', 'CANVAS' => '255x256', 'ROTATION' => '2', 'CROP' => '253x254', 'TRANSFORM_ORDER' => 'ROTATION,CROP'
},
'pass-odd-canvas-grid-mirror-trimmed' => {
'GRID' => '1', 'CANVAS' => '256x255', 'MIRROR' => '0', 'CROP' => '254x253', 'TRANSFORM_ORDER' => 'MIRROR,CROP'
},
'pass-tiled-odd-origin-crop' => { 'TILES' => '2x2', 'CROP' => '510x510' },
'pass-tiled-rotate-90-odd-origin-crop' => {
'TILES' => '2x2', 'ROTATION' => '1', 'CROP' => '510x508', 'TRANSFORM_ORDER' => 'ROTATION,CROP'
},
'pass-tiled-odd-canvas-rotate-90-trimmed' => {
'TILES' => '2x2', 'CANVAS' => '511x512', 'ROTATION' => '1', 'CROP' => '510x509', 'TRANSFORM_ORDER' => 'ROTATION,CROP'
},
'pass-tiled-odd-canvas-mirror-trimmed' => {
'TILES' => '3x2', 'CANVAS' => '767x511', 'MIRROR' => '1', 'CROP' => '765x509', 'TRANSFORM_ORDER' => 'MIRROR,CROP'
}
}
keys = %w[GRID CANVAS CROP ROTATION MIRROR TILE_NCLX PRIMARY_NCLX REFERENCE_COUNT]
keys = %w[GRID CANVAS CROP ROTATION MIRROR TRANSFORM_ORDER TILE_NCLX PRIMARY_NCLX REFERENCE_COUNT]
cases.each do |name, options|
path = File.join(output, "#{name}.heic")
environment = keys.to_h { |key| [key, nil] }.merge(options)
columns, rows = options.fetch('TILES', '1x1').split('x')
environment = keys.to_h { |key| [key, nil] }.merge(options.except('TILES'))
_, stderr, status = Open3.capture3(environment, RbConfig.ruby, File.join(__dir__, 'wrap.rb'), source, path,
'256', '256', '1', '1')
'256', '256', columns, rows)
abort "wrap.rb failed for #{name}:\n#{stderr}" unless status.success?
puts "Generated #{path}"
end
Loading