Skip to content

decoder: keep 'dimg' inputs as an ordered list on the derived item - #885

Open
Nexory wants to merge 1 commit into
webmproject:mainfrom
Nexory:dimg-inputs-on-derived-item
Open

decoder: keep 'dimg' inputs as an ordered list on the derived item#885
Nexory wants to merge 1 commit into
webmproject:mainfrom
Nexory:dimg-inputs-on-derived-item

Conversation

@Nexory

@Nexory Nexory commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Requested in AOMediaCodec/libavif#3342, which made the
same change on the libavif side.

Item::source_item_ids already holds the input item ids in dimg order, but it
was reconstructed rather than parsed: populate_source_item_ids() walked every
item, kept the ones whose single-valued dimg_for_id matched, and sorted by
dimg_index to recover the order the box had already given. This records the ids
on the derived item while the iref box is read instead, so the walk, the sort
and both fields go away.

It also lets an item be an input of several derived items, which the
single-valued mapping could not express and rejected with NotImplemented. That
restriction came from #248, mirroring AOMediaCodec/libavif#2315; libavif has now
dropped it. The rule from section 8.11.12.1 that a value occurs at most once
within one array is kept, and its diagnostic is unchanged.

dimg_shared moves from NotImplemented to BmffParseFailed: item 10 of
color_grid_alpha_grid_tile_shared_in_dimg.avif is a cell of both the color grid
and the alpha grid, so with the restriction gone the file reaches the codec
configuration check and stops there. color_grid_alpha_grid_shared_tiles.avif is
added for the case that now decodes, with both dimg lists pointing at the same
four cells; it is derived from that same file by editing five bytes.

Tested with cargo test, cargo clippy --all-targets -- -D warnings and
cargo +nightly fmt --all -- --check.

Item::source_item_ids already holds the input item ids in 'dimg' order, but it
was reconstructed rather than parsed: populate_source_item_ids() walked every
item, kept the ones whose single-valued dimg_for_id matched, and sorted by
dimg_index to recover the order the box had already given.

Record the ids on the derived item while the 'iref' box is read instead. The
walk, the sort and both fields go away, and an item can be an input of several
derived items, which the single-valued mapping could not express and rejected
with NotImplemented.

The rule from section 8.11.12.1 that a value occurs at most once within one
array is kept, and its diagnostic is unchanged.

color_grid_alpha_grid_tile_shared_in_dimg.avif now reaches the codec
configuration check instead: its item 10 is a cell of both the color grid and
the alpha grid, and those av1C differ. The new test file points both 'dimg'
lists at the same four cells so the tiles agree and the decode completes; it is
derived from that same file by editing five bytes.

@y-guyon y-guyon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this change.

Comment thread src/decoder/mod.rs

let mut source_item_ids: Vec<u32> = Vec::new();
// The input items are recorded on the derived item in 'dimg' order while the
// 'iref' box is parsed, so nothing has to be collected or reordered here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the second part of the sentence.

Comment thread src/decoder/mod.rs
let mut source_item_ids: Vec<u32> = Vec::new();
// The input items are recorded on the derived item in 'dimg' order while the
// 'iref' box is parsed, so nothing has to be collected or reordered here.
let source_item_ids = self.items.get(&item_id).unwrap().source_item_ids.clone();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid cloning.

Comment thread src/decoder/item.rs
Comment on lines +745 to +749
if reference.reference_type == "dimg" {
// Derived images refer in the opposite direction, so make sure the input
// item exists before the derived item is borrowed below.
insert_item_if_not_exists(reference.to_item_id, &mut items);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move that check back where it was. Repeat the row 751 after the check if necessary.

Comment thread src/decoder/item.rs
Comment on lines +746 to +747
// Derived images refer in the opposite direction, so make sure the input
// item exists before the derived item is borrowed below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment is inaccurate. Revert to the original comment.

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