@@ -436,6 +436,14 @@ pub struct Mp4parseParser {
436
436
video_track_sample_descriptions : TryHashMap < u32 , TryVec < Mp4parseTrackVideoSampleInfo > > ,
437
437
}
438
438
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
+
439
447
/// A unified interface for the parsers which have different contexts, but
440
448
/// share the same pattern of construction. This allows unification of
441
449
/// argument validation from C and minimizes the surface of unsafe code.
@@ -1177,26 +1185,31 @@ fn mp4parse_get_track_video_info_safe(
1177
1185
/// # Safety
1178
1186
///
1179
1187
/// 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
1183
1191
/// 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.
1185
1195
#[ no_mangle]
1186
- pub unsafe extern "C" fn mp4parse_avif_get_primary_item (
1196
+ pub unsafe extern "C" fn mp4parse_avif_get_image (
1187
1197
parser : * mut Mp4parseAvifParser ,
1188
- primary_item : * mut Mp4parseByteData ,
1198
+ avif_image : * mut AvifImage ,
1189
1199
) -> Mp4parseStatus {
1190
- if parser. is_null ( ) {
1200
+ if parser. is_null ( ) || avif_image . is_null ( ) {
1191
1201
return Mp4parseStatus :: BadArg ;
1192
1202
}
1193
1203
1194
1204
// Initialize fields to default values to ensure all fields are always valid.
1195
- * primary_item = Default :: default ( ) ;
1196
-
1205
+ * avif_image = Default :: default ( ) ;
1197
1206
let context = ( * parser) . context ( ) ;
1198
1207
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
+ }
1200
1213
1201
1214
Mp4parseStatus :: Ok
1202
1215
}
0 commit comments