@@ -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,50 +1185,35 @@ 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` are set with 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 ( ) ;
1205
+ * avif_image = Default :: default ( ) ;
1206
+ let image_ref = & mut ( * avif_image) ;
1196
1207
1197
1208
let context = ( * parser) . context ( ) ;
1198
1209
1199
- ( * primary_item) . set_data ( context. primary_item ( ) ) ;
1200
-
1201
- Mp4parseStatus :: Ok
1202
- }
1203
-
1204
- #[ no_mangle]
1205
- pub unsafe extern "C" fn mp4parse_avif_get_alpha_item (
1206
- parser : * mut Mp4parseAvifParser ,
1207
- alpha_item : * mut Mp4parseByteData ,
1208
- premultiplied_alpha : * mut bool ,
1209
- ) -> Mp4parseStatus {
1210
- if parser. is_null ( ) {
1211
- return Mp4parseStatus :: BadArg ;
1212
- }
1213
-
1214
- * alpha_item = Default :: default ( ) ;
1215
-
1216
- let context = ( * parser) . context ( ) ;
1210
+ image_ref. primary_item . set_data ( context. primary_item ( ) ) ;
1217
1211
if let Some ( context_alpha_item) = context. alpha_item ( ) {
1218
- ( * alpha_item) . set_data ( context_alpha_item) ;
1219
- * premultiplied_alpha = context. premultiplied_alpha ;
1220
- Mp4parseStatus :: Ok
1221
- } else {
1222
- Mp4parseStatus :: Invalid
1212
+ image_ref. alpha_item . set_data ( context_alpha_item) ;
1213
+ image_ref. premultiplied_alpha = context. premultiplied_alpha ;
1223
1214
}
1215
+
1216
+ Mp4parseStatus :: Ok
1224
1217
}
1225
1218
1226
1219
/// Fill the supplied `Mp4parseByteData` with index information from `track`.
0 commit comments