Skip to content

Commit bdd6c5a

Browse files
committed
load base64
1 parent 3659f99 commit bdd6c5a

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ crate-type = ["cdylib", "rlib", "staticlib"]
1414

1515
[features]
1616
default = ["libc", "glutin", "gl" ,"ratatui" ,"icy_sixel", "image", "ratatui-image"]
17-
ffi = ["image"]
17+
ffi = ["image", "base64"]
1818

1919
[profile.release]
2020
opt-level = "s"
@@ -37,7 +37,7 @@ glutin = { version = "0.28.0", optional = true }
3737
gl = { version = "0.14.0", optional = true }
3838
ratatui = { version = "^0.29.0", features = ["crossterm"], optional = true }
3939
icy_sixel = { version = "^0.1.1", optional = true }
40-
image = { version = "^0.25.1", default-features = false, features = ["jpeg"], optional = true }
40+
image = { version = "^0.25.1", default-features = false, features = ["jpeg", "png"], optional = true }
4141
ratatui-image = { version = "4.2.0", optional = true }
4242
base64 = { version = "0.21.7", optional = true }
4343

src/lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ use std::sync::OnceLock;
44

55
use 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")]
148
use wasm_bindgen::prelude::*;
159

@@ -105,6 +99,9 @@ pub extern "C" fn image() -> ImageBuffer {
10599

106100
#[no_mangle]
107101
pub 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

Comments
 (0)