Skip to content

Commit

Permalink
load base64
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 12, 2025
1 parent 3659f99 commit bdd6c5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crate-type = ["cdylib", "rlib", "staticlib"]

[features]
default = ["libc", "glutin", "gl" ,"ratatui" ,"icy_sixel", "image", "ratatui-image"]
ffi = ["image"]
ffi = ["image", "base64"]

[profile.release]
opt-level = "s"
Expand All @@ -37,7 +37,7 @@ glutin = { version = "0.28.0", optional = true }
gl = { version = "0.14.0", optional = true }
ratatui = { version = "^0.29.0", features = ["crossterm"], optional = true }
icy_sixel = { version = "^0.1.1", optional = true }
image = { version = "^0.25.1", default-features = false, features = ["jpeg"], optional = true }
image = { version = "^0.25.1", default-features = false, features = ["jpeg", "png"], optional = true }
ratatui-image = { version = "4.2.0", optional = true }
base64 = { version = "0.21.7", optional = true }

Expand Down
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ use std::sync::OnceLock;

use std::ffi::CString;

// #[cfg(feature = "ffi")]
// use base64::{Engine, engine::general_purpose};

// #[cfg(feature = "ffi")]
// use std::io::Cursor;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

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

#[no_mangle]
pub extern "C" fn image_base64() -> *const std::os::raw::c_char {
use base64::{engine::general_purpose, Engine};
use std::io::Cursor;

if let Some(gb) = GAMEBOY.get() {
if let Ok(mut locked_gb) = gb.lock() {
let width = 160;
Expand Down Expand Up @@ -136,19 +133,20 @@ pub extern "C" fn image_base64() -> *const std::os::raw::c_char {
// );
// }

// let mut png: Vec<u8> = vec![];
// img.write_to(&mut Cursor::new(&mut png), image::ImageFormat::Png).expect("don't fail img write_to");
// let data = general_purpose::STANDARD.encode(&png);
let mut png: Vec<u8> = vec![];
img.write_to(&mut Cursor::new(&mut png), image::ImageFormat::Png)
.expect("don't fail img write_to");
let data = general_purpose::STANDARD.encode(&png);

let cstring_data = CString::new(img.as_bytes()).expect("don't fail");
return cstring_data.into_raw();
// let cstring_data = CString::new(img.as_bytes()).expect("don't fail");
// return cstring_data.into_raw();

// let mut png: Vec<u8> = vec![];
// img.write_to(&mut Cursor::new(&mut png), image::ImageFormat::Png).expect("don't fail img write_to");
// let data = general_purpose::STANDARD.encode(&png);

// let cstring_data = CString::new(data).expect("don't fail");
// return cstring_data.into_raw();
let cstring_data = CString::new(data).expect("don't fail");
return cstring_data.into_raw();
}
}

Expand Down

0 comments on commit bdd6c5a

Please sign in to comment.