@@ -436,6 +436,14 @@ pub struct Mp4parseParser {
436436 video_track_sample_descriptions : TryHashMap < u32 , TryVec < Mp4parseTrackVideoSampleInfo > > ,
437437}
438438
439+ #[ repr( C ) ]
440+ #[ derive( Default ) ]
441+ pub struct AvifImage {
442+ pub primary_item : Mp4parseByteData ,
443+ pub alpha_item : Mp4parseByteData ,
444+ pub premultiplied_alpha : bool ,
445+ }
446+
439447/// A unified interface for the parsers which have different contexts, but
440448/// share the same pattern of construction. This allows unification of
441449/// argument validation from C and minimizes the surface of unsafe code.
@@ -1177,26 +1185,31 @@ fn mp4parse_get_track_video_info_safe(
11771185/// # Safety
11781186///
11791187/// This function is unsafe because it dereferences both the parser and
1180- /// primary_item raw pointers passed into it. Callers should ensure the parser
1181- /// pointer points to a valid `Mp4parseAvifParser`, and that the primary_item
1182- /// pointer points to a valid `Mp4parseByteData `. If there was not a previous
1188+ /// avif_image raw pointers passed into it. Callers should ensure the parser
1189+ /// pointer points to a valid `Mp4parseAvifParser`, and that the avif_image
1190+ /// pointer points to a valid `AvifImage `. If there was not a previous
11831191/// successful call to `mp4parse_avif_read()`, no guarantees are made as to
1184- /// the state of `primary_item`.
1192+ /// the state of `avif_image`. If `avif_image.alpha_item` is set to a
1193+ /// positive `length` and non-null `data`, then the `avif_image` contains an
1194+ /// valid alpha channel data. Otherwise, the image is opaque.
11851195#[ no_mangle]
1186- pub unsafe extern "C" fn mp4parse_avif_get_primary_item (
1196+ pub unsafe extern "C" fn mp4parse_avif_get_image (
11871197 parser : * mut Mp4parseAvifParser ,
1188- primary_item : * mut Mp4parseByteData ,
1198+ avif_image : * mut AvifImage ,
11891199) -> Mp4parseStatus {
1190- if parser. is_null ( ) {
1200+ if parser. is_null ( ) || avif_image . is_null ( ) {
11911201 return Mp4parseStatus :: BadArg ;
11921202 }
11931203
11941204 // Initialize fields to default values to ensure all fields are always valid.
1195- * primary_item = Default :: default ( ) ;
1196-
1205+ * avif_image = Default :: default ( ) ;
11971206 let context = ( * parser) . context ( ) ;
11981207
1199- ( * primary_item) . set_data ( context. primary_item ( ) ) ;
1208+ ( * avif_image) . primary_item . set_data ( context. primary_item ( ) ) ;
1209+ if let Some ( context_alpha_item) = context. alpha_item ( ) {
1210+ ( * avif_image) . alpha_item . set_data ( context_alpha_item) ;
1211+ ( * avif_image) . premultiplied_alpha = context. premultiplied_alpha ;
1212+ }
12001213
12011214 Mp4parseStatus :: Ok
12021215}
0 commit comments