4949//! ```
5050
5151use crate :: error:: NativeErrorExt ;
52- use crate :: formats:: yuv2rgb:: write_rgb8_f32x8_par;
53- // use crate::formats::yuv2rgb::{write_rgb8_f32x8, write_rgb8_f32x8_par, write_rgb8_scalar, write_rgb8_scalar_par };
52+ use crate :: formats:: yuv2rgb:: { write_rgb8_f32x8_par, write_rgba8_f32x8 , write_rgba8_scalar } ;
53+ // use crate::formats::yuv2rgb::{write_rgb8_f32x8, write_rgb8_f32x8_par, write_rgb8_scalar, write_rgb8_scalar, write_rgba8_f32x8, write_rgba8_scalar_par };
5454use crate :: formats:: { YUVSlices , YUVSource } ;
5555use crate :: { Error , OpenH264API , Timestamp } ;
5656use openh264_sys2:: {
@@ -296,7 +296,7 @@ impl Decoder {
296296
297297 #[ rustfmt:: skip]
298298 unsafe {
299- raw_api. initialize ( & config. params ) . ok ( ) ?;
299+ raw_api. initialize ( & raw const config. params ) . ok ( ) ?;
300300 raw_api. set_option ( DECODER_OPTION_TRACE_LEVEL , addr_of_mut ! ( config. debug) . cast ( ) ) . ok ( ) ?;
301301 raw_api. set_option ( DECODER_OPTION_NUM_OF_THREADS , addr_of_mut ! ( config. num_threads) . cast ( ) ) . ok ( ) ?;
302302 raw_api. set_option ( DECODER_OPTION_ERROR_CON_IDC , addr_of_mut ! ( config. error_concealment) . cast ( ) ) . ok ( ) ?;
@@ -348,7 +348,7 @@ impl Decoder {
348348 packet. as_ptr ( ) ,
349349 packet. len ( ) as i32 ,
350350 from_mut ( & mut dst) . cast ( ) ,
351- & mut buffer_info,
351+ & raw mut buffer_info,
352352 )
353353 . ok ( ) ?;
354354 }
@@ -388,7 +388,7 @@ impl Decoder {
388388
389389 if let Some ( image) = unsafe { DecodedYUV :: from_raw_open264_ptrs ( & dst, & buffer_info) } {
390390 frames. push ( image) ;
391- } ;
391+ }
392392 }
393393
394394 Ok ( frames)
@@ -420,7 +420,7 @@ impl Decoder {
420420 /// # Ok(())
421421 /// # }
422422 /// ```
423- pub unsafe fn raw_api ( & mut self ) -> & mut DecoderRawAPI {
423+ pub const unsafe fn raw_api ( & mut self ) -> & mut DecoderRawAPI {
424424 & mut self . raw_api
425425 }
426426
@@ -445,7 +445,9 @@ impl Decoder {
445445 let mut buffer_info = SBufferInfo :: default ( ) ;
446446
447447 unsafe {
448- self . raw_api ( ) . flush_frame ( from_mut ( & mut dst) . cast ( ) , & mut buffer_info) . ok ( ) ?;
448+ self . raw_api ( )
449+ . flush_frame ( from_mut ( & mut dst) . cast ( ) , & raw mut buffer_info)
450+ . ok ( ) ?;
449451 Ok ( ( dst, buffer_info) )
450452 }
451453 }
@@ -604,25 +606,13 @@ impl DecodedYUV<'_> {
604606 wanted,
605607 target. len( )
606608 ) ;
607-
608- for y in 0 ..dim. 1 {
609- for x in 0 ..dim. 0 {
610- let base_tgt = ( y * dim. 0 + x) * 4 ;
611- let base_y = y * strides. 0 + x;
612- let base_u = ( y / 2 * strides. 1 ) + ( x / 2 ) ;
613- let base_v = ( y / 2 * strides. 2 ) + ( x / 2 ) ;
614-
615- let rgb_pixel = & mut target[ base_tgt..base_tgt + 4 ] ;
616-
617- let y: f32 = self . y [ base_y] . into ( ) ;
618- let u: f32 = self . u [ base_u] . into ( ) ;
619- let v: f32 = self . v [ base_v] . into ( ) ;
620-
621- rgb_pixel[ 0 ] = 1.402f32 . mul_add ( v - 128.0 , y) as u8 ;
622- rgb_pixel[ 1 ] = 0.714f32 . mul_add ( -( v - 128.0 ) , 0.344f32 . mul_add ( -( u - 128.0 ) , y) ) as u8 ;
623- rgb_pixel[ 2 ] = 1.772f32 . mul_add ( u - 128.0 , y) as u8 ;
624- rgb_pixel[ 3 ] = 255 ;
625- }
609+ // for f32x8 math, image needs to:
610+ // - have a width divisible by 8
611+ // - have at least two rows
612+ if dim. 0 % 8 == 0 && dim. 1 >= 2 {
613+ write_rgba8_f32x8 ( self . y , self . u , self . v , dim, strides, target) ;
614+ } else {
615+ write_rgba8_scalar ( self . y , self . u , self . v , dim, strides, target) ;
626616 }
627617 }
628618}
0 commit comments