@@ -744,8 +744,17 @@ where
744
744
/// Same as `convert_space_sliced` but with FFI types.
745
745
///
746
746
/// Returns 0 on success, 1 on invalid `from`, 2 on invalid `to`, 3 on invalid `pixels`
747
- #[ no_mangle]
748
- pub extern "C" fn convert_space_ffi ( from : * const c_char , to : * const c_char , pixels : * mut f32 , len : usize ) -> i32 {
747
+ ///
748
+ /// `len` is in elements rather than bytes
749
+ pub fn convert_space_ffi < T : DType , const N : usize > (
750
+ from : * const c_char ,
751
+ to : * const c_char ,
752
+ pixels : * mut T ,
753
+ len : usize ,
754
+ ) -> i32
755
+ where
756
+ Channels < N > : ValidChannels ,
757
+ {
749
758
let from = unsafe {
750
759
if from. is_null ( ) {
751
760
return 1 ;
@@ -785,7 +794,7 @@ pub extern "C" fn convert_space_ffi(from: *const c_char, to: *const c_char, pixe
785
794
core:: slice:: from_raw_parts_mut ( pixels, len)
786
795
}
787
796
} ;
788
- convert_space_sliced :: < _ , 3 > ( from, to, pixels) ;
797
+ convert_space_sliced :: < T , N > ( from, to, pixels) ;
789
798
0
790
799
}
791
800
@@ -1306,6 +1315,23 @@ where
1306
1315
1307
1316
// ### MONOTYPED EXTERNAL FUNCTIONS ### {{{
1308
1317
1318
+ #[ no_mangle]
1319
+ extern "C" fn convert_space_ffi_3f32 ( from : * const c_char , to : * const c_char , pixels : * mut f32 , len : usize ) -> i32 {
1320
+ convert_space_ffi :: < _ , 3 > ( from, to, pixels, len)
1321
+ }
1322
+ #[ no_mangle]
1323
+ extern "C" fn convert_space_ffi_4f32 ( from : * const c_char , to : * const c_char , pixels : * mut f32 , len : usize ) -> i32 {
1324
+ convert_space_ffi :: < _ , 4 > ( from, to, pixels, len)
1325
+ }
1326
+ #[ no_mangle]
1327
+ extern "C" fn convert_space_ffi_3f64 ( from : * const c_char , to : * const c_char , pixels : * mut f64 , len : usize ) -> i32 {
1328
+ convert_space_ffi :: < _ , 3 > ( from, to, pixels, len)
1329
+ }
1330
+ #[ no_mangle]
1331
+ extern "C" fn convert_space_ffi_4f64 ( from : * const c_char , to : * const c_char , pixels : * mut f64 , len : usize ) -> i32 {
1332
+ convert_space_ffi :: < _ , 4 > ( from, to, pixels, len)
1333
+ }
1334
+
1309
1335
macro_rules! cdef1 {
1310
1336
( $base: ident, $f32: ident, $f64: ident) => {
1311
1337
#[ no_mangle]
0 commit comments