#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
use alloc::vec::Vec;
use crate::types::{EcLevel, Version};
pub mod rqrr;
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub struct GrayPixels<'a> {
width: u32,
height: u32,
data: &'a [u8],
}
impl<'a> GrayPixels<'a> {
#[must_use]
pub fn new(width: u32, height: u32, data: &'a [u8]) -> Self {
Self { width, height, data }
}
#[must_use]
pub const fn width(&self) -> u32 {
self.width
}
#[must_use]
pub const fn height(&self) -> u32 {
self.height
}
#[must_use]
pub fn get(&self, x: u32, y: u32) -> u8 {
self.data[(y as usize) * (self.width as usize) + (x as usize)]
}
}
#[cfg(feature = "image")]
impl<'a> From<&'a image::GrayImage> for GrayPixels<'a> {
fn from(img: &'a image::GrayImage) -> Self {
Self::new(img.width(), img.height(), img.as_raw())
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DecodedQrCode {
data: Vec<u8>,
version: Version,
ec_level: EcLevel,
}
impl DecodedQrCode {
#[must_use]
pub fn new(data: Vec<u8>, version: Version, ec_level: EcLevel) -> Self {
Self { data, version, ec_level }
}
#[must_use]
pub fn data(&self) -> &[u8] {
&self.data
}
#[must_use]
pub fn version(&self) -> Version {
self.version
}
#[must_use]
pub fn ec_level(&self) -> EcLevel {
self.ec_level
}
}
pub trait QrDecoder {
type Error;
fn decode(&self, image: GrayPixels<'_>) -> Result<Vec<DecodedQrCode>, Self::Error>;
}