From f9aaae6863fd9c9afb145a615a225cf6e89cb5d3 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sun, 12 Jan 2025 09:43:53 +0100 Subject: [PATCH] Replace zbar-rust with rqrr --- Cargo.lock | 34 ++---------------- Cargo.toml | 2 +- .../com.belmoussaoui.Authenticator.Devel.json | 36 ------------------- meson.build | 1 - src/widgets/camera.rs | 24 ++++++------- 5 files changed, 13 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ebfe94f..683c9d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,6 +290,7 @@ dependencies = [ "qrencode", "rand", "ring", + "rqrr", "rust-argon2", "scrypt", "search-provider", @@ -300,7 +301,6 @@ dependencies = [ "tracing-subscriber", "url", "uuid", - "zbar-rust", "zeroize", "zip", ] @@ -802,26 +802,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" -[[package]] -name = "enum-ordinalize" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" -dependencies = [ - "enum-ordinalize-derive", -] - -[[package]] -name = "enum-ordinalize-derive" -version = "4.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "enumflags2" version = "0.7.10" @@ -2730,6 +2710,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f126a9b02152815d84315316e7a759ee18a216d057095d56d19cec68a428b385" dependencies = [ "g2p", + "image 0.25.4", "lru", ] @@ -3723,17 +3704,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "zbar-rust" -version = "0.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f7bacc14b37fba9a631a76a5c87ba243ea31eebff12d592d320516472c4626" -dependencies = [ - "enum-ordinalize", - "libc", - "pkg-config", -] - [[package]] name = "zbus" version = "4.4.0" diff --git a/Cargo.toml b/Cargo.toml index c452492..4fc87af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ prost = "0.13" qrencode = {version = "0.14", features = ["image"]} rand = "0.8" ring = "0.17" +rqrr = { version = "0.9", default-features = false, features = ["img"] } rust-argon2 = {version = "2.0", default-features = false} scrypt = {version = "0.11", default-features = false} search-provider = {version = "0.10", default-features = false, features = ["tokio"]} @@ -45,7 +46,6 @@ tracing = {version = "0.1", default-features = false} tracing-subscriber = {version = "0.3", default-features = false, features = ["fmt"]} url = "2.2" uuid = {version = "1.0", features = ["v4"]} -zbar-rust = "0.0" zeroize = {version = "1", features = ["zeroize_derive"]} zip = { version = "2.1", features = ["aes-crypto"] } diff --git a/build-aux/com.belmoussaoui.Authenticator.Devel.json b/build-aux/com.belmoussaoui.Authenticator.Devel.json index 0f78e92..6d51285 100644 --- a/build-aux/com.belmoussaoui.Authenticator.Devel.json +++ b/build-aux/com.belmoussaoui.Authenticator.Devel.json @@ -39,42 +39,6 @@ ] }, "modules": [ - { - "name": "zbar", - "config-opts": [ - "--disable-doc", - "--disable-video", - "--enable-codes=qrcode", - "--without-dbus", - "--without-directshow", - "--without-gir", - "--without-graphicsmagick", - "--without-gtk", - "--without-imagemagick", - "--without-jpeg", - "--without-java", - "--without-npapi", - "--without-python", - "--without-qt", - "--without-qt5", - "--without-xshm", - "--without-xv" - ], - "sources": [ - { - "type": "archive", - "url": "https://linuxtv.org/downloads/zbar/zbar-0.23.1.tar.gz", - "sha256": "c72b19eb63f48781ae5ff1830236f4e753f4bd6418cd781aea1cd85d625b119e" - }, - { - "type": "script", - "dest-filename": "autogen.sh", - "commands": [ - "autoreconf -vfi -W none" - ] - } - ] - }, { "name": "authenticator", "buildsystem": "meson", diff --git a/meson.build b/meson.build index c0c7ca6..d3321b3 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,6 @@ dependency('glib-2.0', version: '>= 2.56') dependency('gio-2.0', version: '>= 2.56') dependency('gtk4', version: '>= 4.10') dependency('libadwaita-1', version: '>=1.5.beta') -dependency('zbar', version: '>= 0.20') dependency('gstreamer-1.0', version: '>= 1.18') dependency('gstreamer-base-1.0', version: '>= 1.18') dependency('gstreamer-plugins-base-1.0', version: '>= 1.18') diff --git a/src/widgets/camera.rs b/src/widgets/camera.rs index 11f143e..8852e59 100644 --- a/src/widgets/camera.rs +++ b/src/widgets/camera.rs @@ -12,7 +12,6 @@ use gtk::{ glib::{self, clone}, prelude::*, }; -use image::GenericImageView; use super::CameraRow; use crate::utils::spawn_tokio; @@ -23,21 +22,18 @@ pub mod screenshot { pub fn scan(data: &[u8]) -> Result { // remove the file after reading the data let img = image::load_from_memory(data)?; + let img_data = img.to_luma8(); + let mut prepared_img = rqrr::PreparedImage::prepare(img_data); + let grids = prepared_img.detect_grids(); + let mut decoded = Vec::new(); - let (width, height) = img.dimensions(); - let img_data: Vec = img.to_luma8().to_vec(); - - let mut scanner = zbar_rust::ZBarImageScanner::new(); - - let results = scanner - .scan_y800(&img_data, width, height) - .map_err(|e| anyhow::format_err!(e))?; - - if let Some(result) = results.first() { - let content = String::from_utf8(result.data.clone())?; - return Ok(content); + if let Some(grid) = grids.first() { + grid.decode_to(&mut decoded)?; + } else { + anyhow::bail!("Invalid QR code") } - anyhow::bail!("Invalid QR code") + + Ok(String::from_utf8(decoded)?) } pub async fn capture(window: Option) -> Result {