add wasm qr decode

This commit is contained in:
2020-05-24 21:43:46 +08:00
parent c205ccd1b2
commit d150bbcc5a
6 changed files with 575 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
use std::ffi::CString;
use std::os::raw::c_char;
pub const SAMPLE_QR_BYTES: &[u8] = std::include_bytes!("sample_qr.png");
#[no_mangle]
pub extern "C" fn parse_default_qr() -> *mut c_char {
let s = CString::new(parse_qr()).unwrap();
s.into_raw()
}
pub fn parse_qr() -> String {
let img = image::load_from_memory(SAMPLE_QR_BYTES).unwrap();
let decoder = bardecoder::default_decoder();
let mut ret = vec![];
let results = decoder.decode(&img);
for result in results {
let qr = result.unwrap();
println!("{}", qr);
ret.push(qr);
}
ret.join(",")
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB