@@ -804,7 +804,7 @@ struct AvifMeta {
804
804
item_references : TryVec < SingleItemTypeReferenceBox > ,
805
805
properties : TryVec < AssociatedProperty > ,
806
806
primary_item_id : u32 ,
807
- iloc_items : TryVec < ItemLocationBoxItem > ,
807
+ iloc_items : TryHashMap < u32 , ItemLocationBoxItem > ,
808
808
}
809
809
810
810
/// A Media Data Box
@@ -1060,7 +1060,6 @@ impl TryFrom<u8> for IlocVersion {
1060
1060
/// `data_reference_index` is omitted, since only 0 (i.e., this file) is supported
1061
1061
#[ derive( Debug ) ]
1062
1062
struct ItemLocationBoxItem {
1063
- item_id : u32 ,
1064
1063
construction_method : ConstructionMethod ,
1065
1064
/// Unused for ConstructionMethod::Idat
1066
1065
extents : TryVec < Extent > ,
@@ -1449,10 +1448,10 @@ pub fn read_avif<T: Read>(f: &mut T) -> Result<AvifContext> {
1449
1448
let mut alpha_item = None ;
1450
1449
1451
1450
// store data or record location of relevant items
1452
- for loc in meta. iloc_items {
1453
- let item = if loc . item_id == meta. primary_item_id {
1451
+ for ( item_id , loc) in meta. iloc_items {
1452
+ let item = if item_id == meta. primary_item_id {
1454
1453
& mut primary_item
1455
- } else if Some ( loc . item_id ) == alpha_item_id {
1454
+ } else if Some ( item_id) == alpha_item_id {
1456
1455
& mut alpha_item
1457
1456
} else {
1458
1457
continue ;
@@ -2114,7 +2113,7 @@ fn read_auxc<T: Read>(src: &mut BMFFBox<T>) -> Result<AuxiliaryTypeProperty> {
2114
2113
2115
2114
/// Parse an item location box inside a meta box
2116
2115
/// See ISOBMFF (ISO 14496-12:2015) § 8.11.3
2117
- fn read_iloc < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TryVec < ItemLocationBoxItem > > {
2116
+ fn read_iloc < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TryHashMap < u32 , ItemLocationBoxItem > > {
2118
2117
let version: IlocVersion = read_fullbox_version_no_flags ( src) ?. try_into ( ) ?;
2119
2118
2120
2119
let iloc = src. read_into_try_vec ( ) ?;
@@ -2137,7 +2136,7 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
2137
2136
IlocVersion :: Two => iloc. read_u32 ( 32 ) ?,
2138
2137
} ;
2139
2138
2140
- let mut items = TryVec :: with_capacity ( item_count. to_usize ( ) ) ?;
2139
+ let mut items = TryHashMap :: with_capacity ( item_count. to_usize ( ) ) ?;
2141
2140
2142
2141
for _ in 0 ..item_count {
2143
2142
let item_id = match version {
@@ -2226,19 +2225,14 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
2226
2225
extents. push ( extent) ?;
2227
2226
}
2228
2227
2229
- // TODO: change items to TryHashMap once https://github.com/vcombey/fallible_collections/pull/12 merges
2230
- if items
2231
- . iter ( )
2232
- . any ( |prev_item : & ItemLocationBoxItem | prev_item. item_id == item_id)
2233
- {
2234
- return Err ( Error :: InvalidData ( "duplicate item_ID in iloc" ) ) ;
2235
- }
2236
-
2237
- items. push ( ItemLocationBoxItem {
2238
- item_id,
2228
+ let loc = ItemLocationBoxItem {
2239
2229
construction_method,
2240
2230
extents,
2241
- } ) ?;
2231
+ } ;
2232
+
2233
+ if items. insert ( item_id, loc) ?. is_some ( ) {
2234
+ return Err ( Error :: InvalidData ( "duplicate item_ID in iloc" ) ) ;
2235
+ }
2242
2236
}
2243
2237
2244
2238
if iloc. remaining ( ) == 0 {
0 commit comments