@@ -4,12 +4,6 @@ use std::sync::OnceLock;
44
55use std:: ffi:: CString ;
66
7- // #[cfg(feature = "ffi")]
8- // use base64::{Engine, engine::general_purpose};
9-
10- // #[cfg(feature = "ffi")]
11- // use std::io::Cursor;
12-
137#[ cfg( target_arch = "wasm32" ) ]
148use wasm_bindgen:: prelude:: * ;
159
@@ -105,6 +99,9 @@ pub extern "C" fn image() -> ImageBuffer {
10599
106100#[ no_mangle]
107101pub extern "C" fn image_base64 ( ) -> * const std:: os:: raw:: c_char {
102+ use base64:: { engine:: general_purpose, Engine } ;
103+ use std:: io:: Cursor ;
104+
108105 if let Some ( gb) = GAMEBOY . get ( ) {
109106 if let Ok ( mut locked_gb) = gb. lock ( ) {
110107 let width = 160 ;
@@ -136,19 +133,20 @@ pub extern "C" fn image_base64() -> *const std::os::raw::c_char {
136133 // );
137134 // }
138135
139- // let mut png: Vec<u8> = vec![];
140- // img.write_to(&mut Cursor::new(&mut png), image::ImageFormat::Png).expect("don't fail img write_to");
141- // let data = general_purpose::STANDARD.encode(&png);
136+ let mut png: Vec < u8 > = vec ! [ ] ;
137+ img. write_to ( & mut Cursor :: new ( & mut png) , image:: ImageFormat :: Png )
138+ . expect ( "don't fail img write_to" ) ;
139+ let data = general_purpose:: STANDARD . encode ( & png) ;
142140
143- let cstring_data = CString :: new ( img. as_bytes ( ) ) . expect ( "don't fail" ) ;
144- return cstring_data. into_raw ( ) ;
141+ // let cstring_data = CString::new(img.as_bytes()).expect("don't fail");
142+ // return cstring_data.into_raw();
145143
146144 // let mut png: Vec<u8> = vec![];
147145 // img.write_to(&mut Cursor::new(&mut png), image::ImageFormat::Png).expect("don't fail img write_to");
148146 // let data = general_purpose::STANDARD.encode(&png);
149147
150- // let cstring_data = CString::new(data).expect("don't fail");
151- // return cstring_data.into_raw();
148+ let cstring_data = CString :: new ( data) . expect ( "don't fail" ) ;
149+ return cstring_data. into_raw ( ) ;
152150 }
153151 }
154152
0 commit comments