add qr module

This commit is contained in:
Joe Ardent 2023-08-01 13:48:34 -07:00
parent cacd02be91
commit 222324d954
3 changed files with 40 additions and 1 deletions

1
src/lib.rs Normal file
View file

@ -0,0 +1 @@
mod qr;

View file

@ -58,7 +58,7 @@ impl eframe::App for Flasher {
.build()
.unwrap();
let bytes = ImageBuilder::default()
.fit_width(1200)
.fit_width(1100)
.to_pixmap(&qr)
.encode_png()
.unwrap();

38
src/qr.rs Normal file
View 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,
}
}