zedbar
A pure Rust implementation of barcode scanning, based on the ZBar bar code reader C library.
This is a port of the ZBar library to Rust, providing barcode detection and decoding capabilities with a type-safe, idiomatic Rust API.
Features
- Multiple Barcode Formats: QR Code, EAN-13, EAN-8, UPC-A, UPC-E, ISBN-10, ISBN-13, Code 128, Code 93, Code 39, Codabar, Interleaved 2 of 5, DataBar (RSS), SQCode
- Pure Rust: No C dependencies, fully memory-safe implementation
- Type-Safe Configuration: Compile-time validated configuration API
- Command-line Tool:
zedbarimgutility for scanning images from the command line - Position Tracking: Optional tracking of barcode positions in images
- Inverted Image Support: Can detect barcodes in inverted images
Installation
Add to your Cargo.toml:
[]
= "0.1"
Cargo Features
By default, all symbologies are enabled. You can selectively enable only the ones you need to reduce compile time and binary size:
[]
= { = "0.1", = false, = ["qrcode", "ean"] }
Symbology Features
qrcode- QR Code 2D barcodesqcode- SQ Code 2D barcodeean- EAN-8, EAN-13, UPC-A, UPC-E, ISBN-10, ISBN-13code128- Code 128code39- Code 39code93- Code 93codabar- Codabardatabar- GS1 DataBar (RSS)i25- Interleaved 2 of 5
Optional Dependencies
Heavy dependencies (tied to features):
encoding_rs,reed-solomon,rand,rand_chacha- Required for QR code decoding (enabled withqrcodefeature)image- Image format loading (PNG, JPEG, etc.) - needed for tests and thezedbarimgbinaryclap- Command-line parsing (needed for thezedbarimgbinary)
Note: 1D barcode decoders (EAN, Code39, Code128, etc.) have zero external dependencies!
The default feature enables all symbologies plus optional dependencies:
= ["qrcode", "sqcode", "ean", "code128", "code39", "code93", "codabar", "databar", "i25", "image", "clap"]
Minimal Library
For the absolute minimal build with zero external dependencies (1D barcodes only):
[]
= { = "0.1", = false, = ["ean"] }
For QR codes only (with necessary dependencies):
[]
= { = "0.1", = false, = ["qrcode"] }
Note: Disabling a feature at compile-time means that symbology will not be compiled into the binary at all, which is different from disabling it via runtime configuration.
Usage
Library
use ;
// Load and convert image to grayscale
let img = open?;
let gray = img.to_luma8;
let = gray.dimensions;
// Create scanner and scan image
let mut img = from_gray?;
let mut scanner = new;
let symbols = scanner.scan;
// Process decoded symbols
for symbol in symbols
Advanced Configuration
use *;
use ;
let config = new
.enable
.enable
.set_binary // Preserve binary data in QR codes
.set_length_limits // Code39 must be 4-20 chars
.test_inverted // Try inverted image if no symbols found
.scan_density; // Scan every 2nd line (faster)
let mut scanner = with_config;
Command-line Tool
# Build the tool
# Scan an image
Testing
Benchmarks
Comprehensive benchmarks comparing this library with rqrr, rxing, and the original C zbar library are available:
# Compare with rqrr (default)
# Compare with all libraries (requires optional dependencies)
See benches/README.md for detailed benchmark documentation and results.
Credits
Original ZBar Library
This project is based on the ZBar bar code reader library:
- Original C implementation: Copyright (C) 2007-2010 Jeff Brown spadix@users.sourceforge.net
- QR code decoder components: Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org)
- SQCode decoder: Copyright (C) 2018 Javier Serrano Polo javier@jasp.net
- Current C library maintenance: Mauro Carvalho Chehab and contributors
The original ZBar library is licensed under LGPL 2.1 or later.
Rust Port
This Rust implementation preserves the algorithms and structure of the original C library while providing a safe, idiomatic Rust API.
Alternatives
If this library doesn't meet your needs, consider these alternatives:
Rust Libraries
- rqrr - Pure Rust QR code reader with a different algorithm. Fast and reliable for QR codes specifically, but only supports QR codes.
- bardecoder - Another Rust barcode decoder supporting various 1D formats.
- rxing - Rust port of ZXing (Zebra Crossing) library, supports many formats.
- quircs - Rust bindings to the quirc QR code library.
C/C++ Libraries (via FFI)
- ZBar - The original C library this project is based on. Mature and well-tested.
- ZXing - Popular Java library with C++ port available.
- ZBar-lite - Lightweight fork of ZBar.
Choosing an Alternative
- For QR codes only: Consider
rqrr- it's fast, pure Rust, and has a simpler API. - For maximum format support: The original ZBar C library or ZXing are very mature.
- For pure Rust with broad format support: This library (
zedbar) orrxing. - For C bindings to ZBar: Use
zbar-rustwhich provides FFI bindings to the original C library.
License
LGPL 3.0 or later - See LICENSE for details.
This library is licensed under the GNU Lesser General Public License v3.0 or later, consistent with the original ZBar library's licensing.