Files
QRGen/examples/high_ecc.rs
T
Serendipity effc88c6d7 feat: QR 码解码器 — 从零手写的完整解码流水线
新增 core/src/decoder/ 模块(9 文件,~1500 行):
- bch.rs: BCH(15,5)+BCH(18,6) 查表解码(32+64 有效码字,t≤3)
- format.rs: 从矩阵读取格式信息(EC+掩码)+版本信息(2 副本容错)
- extract.rs: 逆向蛇形排列提取数据码字
- deinterleave.rs: 逆向 RS 数据交错
- rs_decode.rs: RS 纠错流水线(伴随式→BM→Chien→Forney)
- mode_decode.rs: 逆向 4 种编码模式(数字/字母/字节/汉字 Shift JIS)
- detect.rs: 定位图案检测(1:1:3:1:1 比例+交叉验证+聚类)
- image.rs: 图像加载+灰度二值化(PNG/JPEG/WebP)
- mod.rs: 顶层 API(decode_image + decode_matrix)

修改已有文件:
- core: galois.rs 表 pub(crate), 新增 poly_eval(); reed_solomon 公开内部函数
- cli: 新增 --decode <file> 解码模式
- web: 新增 POST /api/decode(multipart file upload)

测试: 72 passed (58 原有 + 14 新增 decoder 测试)
2026-06-19 20:36:12 +08:00

29 lines
719 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! QRGen 高纠错示例:生成可抵抗 30% 损坏的 QR 码
//!
//! 运行: `cargo run --example high_ecc`
use qr_core::qr::{QrCode, QrConfig, VersionMode};
use qr_core::version::EcLevel;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = QrConfig {
level: EcLevel::H, // 30% 纠错能力
version: VersionMode::Auto,
margin: 6, // 更大的静区
};
let qr = QrCode::encode("重要数据 - High ECC", config)?;
println!(
"版本: {}, 纠错: {:?}, 尺寸: {}×{}",
qr.version.0,
qr.level,
qr.size(),
qr.size()
);
let svg = qr.to_svg();
println!("SVG 生成成功: {} 字节", svg.len());
Ok(())
}