mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
wip: add dxo edge barcode (inop)
This commit is contained in:
@@ -47,6 +47,10 @@ impl PatternRow {
|
||||
pub fn into_pattern_view(&self) -> PatternView {
|
||||
PatternView::new(self)
|
||||
}
|
||||
|
||||
pub fn sum(&self) -> PatternType {
|
||||
self.0.iter().sum()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for PatternRow {
|
||||
@@ -363,12 +367,16 @@ impl<'a> From<&PatternView<'a>> for &'a [PatternType] {
|
||||
*
|
||||
* The operator[](int) can be used in combination with a PatternView
|
||||
*/
|
||||
#[derive(Default)]
|
||||
struct BarAndSpace<T: Default + std::cmp::PartialEq> {
|
||||
#[derive(Default, Clone)]
|
||||
pub struct BarAndSpace<T: Default + std::cmp::PartialEq> {
|
||||
bar: T,
|
||||
space: T,
|
||||
}
|
||||
impl<T: Default + std::cmp::PartialEq> BarAndSpace<T> {
|
||||
pub fn new(bar: T, space: T) -> BarAndSpace<T> {
|
||||
Self { bar, space }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn isValid(&self) -> bool {
|
||||
self.bar != T::default() && self.space != T::default()
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
use std::iter::Sum;
|
||||
use std::ops::Shl;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::qrcode::cpp_port::detector::AppendBit;
|
||||
use crate::{Exceptions, Point};
|
||||
|
||||
use super::{Direction, RegressionLineTrait};
|
||||
@@ -66,3 +70,38 @@ pub fn ToString<T: Into<usize>>(val: T, len: usize) -> Result<String> {
|
||||
|
||||
Ok(result.iter().collect())
|
||||
}
|
||||
|
||||
pub fn ToInt(a: &[u32]) -> Option<u32> {
|
||||
if a.iter().sum::<u32>() <= 32 {
|
||||
return None;
|
||||
}
|
||||
// assert(Reduce(a) <= 32);
|
||||
|
||||
let mut pattern = 0;
|
||||
for (i, element) in a.iter().copied().enumerate() {
|
||||
// for (int i = 0; i < Size(a); i++)
|
||||
pattern = (pattern << element) | !(0xffffffff << element) * (!i & 1) as u32;
|
||||
}
|
||||
|
||||
return Some(pattern);
|
||||
}
|
||||
|
||||
pub fn ToIntPos(
|
||||
bits: &[u8],
|
||||
pos: usize, /* = 0 */
|
||||
count: usize, /* = 8 * sizeof(T)*/
|
||||
) -> Option<u32> {
|
||||
// assert(0 <= count && count <= 8 * (int)sizeof(T));
|
||||
// assert(0 <= pos && pos + count <= bits.size());
|
||||
|
||||
let count = std::cmp::min(count as usize, bits.len());
|
||||
let mut res = 0;
|
||||
for bit in bits.iter().skip(pos).take(count) {
|
||||
AppendBit(&mut res, bit == &0);
|
||||
}
|
||||
// let it = bits.iterAt(pos);
|
||||
// for (int i = 0; i < count; ++i, ++it)
|
||||
// {AppendBit(res, *it);}
|
||||
|
||||
return Some(res as u32);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user