use zbar_pack::{Image, ImageScanner, SymbolType};
fn create_minimal_qrcode_pattern() -> (Vec<u8>, u32, u32) {
let size = 21u32;
let mut data = vec![255u8; (size * size) as usize];
let mut set_module = |x: u32, y: u32, black: bool| {
if x < size && y < size {
data[(y * size + x) as usize] = if black { 0 } else { 255 };
}
};
for y in 0..7 {
for x in 0..7 {
let black = (x == 0 || x == 6 || y == 0 || y == 6)
|| ((2..=4).contains(&x) && (2..=4).contains(&y));
set_module(x, y, black);
}
}
for y in 0..7 {
for x in 14..21 {
let black = (x == 14 || x == 20 || y == 0 || y == 6)
|| ((16..=18).contains(&x) && (2..=4).contains(&y));
set_module(x, y, black);
}
}
for y in 14..21 {
for x in 0..7 {
let black = (x == 0 || x == 6 || y == 14 || y == 20)
|| ((2..=4).contains(&x) && (16..=18).contains(&y));
set_module(x, y, black);
}
}
for i in 8..13 {
set_module(i, 6, i % 2 == 0);
set_module(6, i, i % 2 == 0);
}
set_module(8, 13, true);
(data, size, size)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Generating test QR code pattern...");
let (data, width, height) = create_minimal_qrcode_pattern();
println!("Created {}x{} QR code pattern", width, height);
let mut scanner = ImageScanner::new()?;
scanner.set_config(SymbolType::QRCODE, 0, 1)?;
let image = Image::from_gray(&data, width, height)?;
println!("Scanning image...");
let symbols = scanner.scan_image(&image)?;
let mut count = 0;
for symbol in symbols {
count += 1;
println!("Found symbol {}:", count);
println!(" Type: {:?}", symbol.symbol_type());
println!(" Data: {:?}", symbol.data());
println!(" Quality: {}", symbol.quality());
}
if count == 0 {
println!("No symbols detected.");
println!("Note: This is a minimal test pattern and may not be");
println!("recognized as a valid QR code by the scanner.");
}
Ok(())
}