add qr module
This commit is contained in:
parent
cacd02be91
commit
222324d954
3 changed files with 40 additions and 1 deletions
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
mod qr;
|
|
@ -58,7 +58,7 @@ impl eframe::App for Flasher {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let bytes = ImageBuilder::default()
|
let bytes = ImageBuilder::default()
|
||||||
.fit_width(1200)
|
.fit_width(1100)
|
||||||
.to_pixmap(&qr)
|
.to_pixmap(&qr)
|
||||||
.encode_png()
|
.encode_png()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
38
src/qr.rs
Normal file
38
src/qr.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
use fast_qr::ECL;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum Mode {
|
||||||
|
Ascii,
|
||||||
|
Binary,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_size(len: usize, mode: Mode) -> usize {
|
||||||
|
if mode == Mode::Ascii {
|
||||||
|
// alphanumeric mode is only 5.5 bits per character, so 5.5 / 8 = 0.6875
|
||||||
|
(len as f64 * 0.6875).ceil() as usize
|
||||||
|
} else {
|
||||||
|
len
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn choose_version(size: usize, ecl: ECL) -> fast_qr::Version {
|
||||||
|
use fast_qr::Version::*;
|
||||||
|
let ecl = match ecl {
|
||||||
|
ECL::L => 0.7,
|
||||||
|
ECL::M => 0.15,
|
||||||
|
ECL::Q => 0.25,
|
||||||
|
ECL::H => 0.30,
|
||||||
|
};
|
||||||
|
|
||||||
|
let size = (size as f64 / ecl) as usize;
|
||||||
|
|
||||||
|
match size {
|
||||||
|
0..=7 => V01,
|
||||||
|
8..=14 => V02,
|
||||||
|
15..=24 => V03,
|
||||||
|
25..=78 => V04,
|
||||||
|
|
||||||
|
//
|
||||||
|
_ => V40,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue