mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
untested luma8
This commit is contained in:
@@ -204,7 +204,7 @@ impl LuminanceSource for BufferedImageLuminanceSource {
|
|||||||
.collect::<Vec<&u8>>(); // get all the rows we want to look at
|
.collect::<Vec<&u8>>(); // get all the rows we want to look at
|
||||||
|
|
||||||
let data = unmanaged
|
let data = unmanaged
|
||||||
.chunks(self.image.width() as usize)
|
.chunks_exact(self.image.width() as usize)
|
||||||
.into_iter() // Get rows
|
.into_iter() // Get rows
|
||||||
.flat_map(|f| {
|
.flat_map(|f| {
|
||||||
f.iter()
|
f.iter()
|
||||||
|
|||||||
@@ -1,19 +1,27 @@
|
|||||||
use crate::LuminanceSource;
|
use crate::LuminanceSource;
|
||||||
|
|
||||||
|
/// A simple luma8 source for bytes, supports cropping but not rotation
|
||||||
pub struct Luma8LuminanceSource {
|
pub struct Luma8LuminanceSource {
|
||||||
|
/// image dimension in form (x,y)
|
||||||
dimensions: (u32, u32),
|
dimensions: (u32, u32),
|
||||||
|
/// image origin in the form (x,y)
|
||||||
origin: (u32, u32),
|
origin: (u32, u32),
|
||||||
|
/// raw data for luma 8
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
|
/// flag indicating if the underlying data needs to be inverted for use
|
||||||
inverted: bool,
|
inverted: bool,
|
||||||
|
/// original dimensions of the data, used to manage crop
|
||||||
original_dimension: (u32, u32),
|
original_dimension: (u32, u32),
|
||||||
}
|
}
|
||||||
impl LuminanceSource for Luma8LuminanceSource {
|
impl LuminanceSource for Luma8LuminanceSource {
|
||||||
fn getRow(&self, y: usize) -> Vec<u8> {
|
fn getRow(&self, y: usize) -> Vec<u8> {
|
||||||
self.data
|
self.data
|
||||||
.chunks_exact(y * self.dimensions.0 as usize)
|
.chunks_exact(self.original_dimension.0 as usize)
|
||||||
.skip(y)
|
.skip(y + self.origin.1 as usize)
|
||||||
.take(1)
|
.take(1)
|
||||||
.flatten()
|
.flatten()
|
||||||
|
.skip(self.origin.0 as usize)
|
||||||
|
.take(self.dimensions.0 as usize)
|
||||||
.map(|byte| Self::invert_if_should(*byte, self.inverted))
|
.map(|byte| Self::invert_if_should(*byte, self.inverted))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@@ -21,8 +29,20 @@ impl LuminanceSource for Luma8LuminanceSource {
|
|||||||
fn getMatrix(&self) -> Vec<u8> {
|
fn getMatrix(&self) -> Vec<u8> {
|
||||||
self.data
|
self.data
|
||||||
.iter()
|
.iter()
|
||||||
.map(|byte| Self::invert_if_should(*byte, self.inverted))
|
.skip((self.original_dimension.0 * self.origin.1) as usize)
|
||||||
.collect()
|
.take((self.dimensions.1 * self.original_dimension.0) as usize)
|
||||||
|
.collect::<Vec<&u8>>()
|
||||||
|
.chunks_exact(self.original_dimension.0 as usize)
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|f| {
|
||||||
|
f.iter()
|
||||||
|
.skip((self.origin.0) as usize)
|
||||||
|
.take(self.getWidth())
|
||||||
|
.copied()
|
||||||
|
}) // flatten this all out
|
||||||
|
.copied() // copy it over so that it's u8
|
||||||
|
.map(|byte| Self::invert_if_should(byte, self.inverted))
|
||||||
|
.collect() // collect into a vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getWidth(&self) -> usize {
|
fn getWidth(&self) -> usize {
|
||||||
@@ -38,7 +58,7 @@ impl LuminanceSource for Luma8LuminanceSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn isCropSupported(&self) -> bool {
|
fn isCropSupported(&self) -> bool {
|
||||||
false
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crop(
|
fn crop(
|
||||||
|
|||||||
Reference in New Issue
Block a user