Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/wrappers/rust/examples/demo_reader.rs @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2024 Axel Waggershauser | |
| 3 */ | |
| 4 // SPDX-License-Identifier: Apache-2.0 | |
| 5 | |
| 6 use zxingcpp::*; | |
| 7 | |
| 8 fn main() -> anyhow::Result<()> { | |
| 9 let filename = std::env::args().nth(1).expect("no image file name provided"); | |
| 10 let formats = std::env::args().nth(2); | |
| 11 let fast = std::env::args().nth(3).is_some(); | |
| 12 | |
| 13 let image = image::open(&filename)?; | |
| 14 | |
| 15 #[cfg(not(feature = "image"))] | |
| 16 let lum_img = image.into_luma8(); | |
| 17 #[cfg(not(feature = "image"))] | |
| 18 let iv = ImageView::from_slice(&lum_img, lum_img.width(), lum_img.height(), ImageFormat::Lum)?; | |
| 19 | |
| 20 let formats = BarcodeFormats::from_str(formats.unwrap_or_default())?; | |
| 21 let read_barcodes = BarcodeReader::new() | |
| 22 .formats(formats) | |
| 23 .try_harder(!fast) | |
| 24 .try_invert(!fast) | |
| 25 .try_rotate(!fast) | |
| 26 .try_downscale(!fast) | |
| 27 .return_errors(true); | |
| 28 | |
| 29 #[cfg(feature = "image")] | |
| 30 let barcodes = read_barcodes.from(&image)?; | |
| 31 #[cfg(not(feature = "image"))] | |
| 32 let barcodes = read_barcodes.from(iv)?; | |
| 33 | |
| 34 if barcodes.is_empty() { | |
| 35 println!("No barcode found."); | |
| 36 } else { | |
| 37 for barcode in barcodes { | |
| 38 println!("Text: {}", barcode.text()); | |
| 39 println!("Bytes: {:?}", barcode.bytes()); | |
| 40 println!("Format: {}", barcode.format()); | |
| 41 println!("Content: {}", barcode.content_type()); | |
| 42 println!("Identifier: {}", barcode.symbology_identifier()); | |
| 43 println!("EC Level: {}", barcode.ec_level()); | |
| 44 println!("Error: {}", barcode.error()); | |
| 45 println!("Rotation: {}", barcode.orientation()); | |
| 46 println!("Position: {}", barcode.position()); | |
| 47 println!(); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 Ok(()) | |
| 52 } |
