Skip to content

Commit

Permalink
decoder: Use the original dimg ordering from iref
Browse files Browse the repository at this point in the history
Instead of using the order from the constructed items, use the dimg
ordering from the iref box.

Fixes the libavif bug AOMediaCodec/libavif#2311

PiperOrigin-RevId: 655255206
  • Loading branch information
vigneshvg authored and copybara-github committed Jul 25, 2024
1 parent 466f1f5 commit e066c1d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,12 @@ impl Decoder {
"Expected number of tiles not found".into(),
));
}
// ISO/IEC 23008-12: The input images are inserted in row-major order,
// top-row first, left to right, in the order of SingleItemTypeReferenceBox of type 'dimg'
// for this derived image item within the ItemReferenceBox.
// Sort the grid items by dimg_index. dimg_index is the order in which the items appear in
// the 'iref' box.
grid_item_ids.sort_by_key(|k| self.items.get(k).unwrap().dimg_index);
let item = self.items.get_mut(&item_id).unwrap();
item.properties
.push(ItemProperty::CodecConfiguration(first_av1C.unwrap()));
Expand Down
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/decoder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,26 @@ fn dimg_shared() {
let mut decoder = get_decoder("color_grid_alpha_grid_tile_shared_in_dimg.avif");
assert_eq!(decoder.parse(), Err(AvifError::NotImplemented));
}

#[test]
fn dimg_ordering() {
if !HAS_DECODER {
return;
}
let mut decoder1 = get_decoder("sofa_grid1x5_420.avif");
let res = decoder1.parse();
assert!(res.is_ok());
let res = decoder1.next_image();
assert!(res.is_ok());
let mut decoder2 = get_decoder("sofa_grid1x5_420_random_dimg_order.avif");
let res = decoder2.parse();
assert!(res.is_ok());
let res = decoder2.next_image();
assert!(res.is_ok());
let image1 = decoder1.image().expect("image1 was none");
let image2 = decoder2.image().expect("image2 was none");
// Ensure that the pixels in image1 and image2 are not the same.
let row1 = image1.row(Plane::Y, 0).expect("row1 was none");
let row2 = image2.row(Plane::Y, 0).expect("row2 was none");
assert_ne!(row1, row2);
}

0 comments on commit e066c1d

Please sign in to comment.