switch to using Point in one-d-derive macros

Also start updates to make point more generic, still not complete or fully implemented.

Some code cleanup
This commit is contained in:
Henry Schimke
2023-04-29 17:51:26 -05:00
parent e0305549e3
commit 74a830f462
8 changed files with 55 additions and 27 deletions

View File

@@ -25,7 +25,7 @@ image = {version = "0.24", optional = true}
imageproc = {version = "0.23", optional = true}
unicode-segmentation = "1.10"
codepage-437 = "0.1.0"
rxing-one-d-proc-derive = {version = "0.4", path ="./crates/one-d-proc-derive"}
rxing-one-d-proc-derive = {version = "0.5", path ="./crates/one-d-proc-derive"}
num = "0.4.0"
svg = {version = "0.13", optional = true}
resvg = {version = "0.29.0", optional = true, default-features=false}

View File

@@ -1,7 +1,7 @@
[package]
name = "rxing-one-d-proc-derive"
repository = "https://github.com/rxing-core/rxing/tree/main/crates/one-d-proc-derive"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
description = "proc macros to simplify the development of one-d barcode symbologies in rxing (https://github.com/rxing-core/rxing)"
license = "Apache-2.0"

View File

@@ -20,7 +20,7 @@ fn impl_one_d_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
use crate::DecodingHintDictionary;
use crate::RXingResultMetadataType;
use crate::RXingResultMetadataValue;
use crate::RXingResultPoint;
use crate::Point;
use crate::Reader;
use crate::Binarizer;
@@ -64,7 +64,7 @@ fn impl_one_d_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
let points = result.getRXingResultPointsMut();
for i in 0..total_points{
// for (int i = 0; i < points.length; i++) {
points[i] = RXingResultPoint::new(height as f32- points[i].getY() - 1.0, points[i].getX());
points[i] = Point::new(height as f32- points[i].getY() - 1.0, points[i].getX());
}
// }

View File

@@ -159,7 +159,7 @@ impl BitSource {
let mask = (0xFF >> bits_to_not_read) << bits_to_not_read;
result = (result << num_bits)
| ((self.bytes[byte_offset] & mask) as u32 >> bits_to_not_read);
bit_offset += num_bits;
//bit_offset += num_bits; // Removed, this is a holdover from setting the actual values in c++
}
}

View File

@@ -228,9 +228,10 @@ impl<'a> PatternView<'a> {
let mut size = size.unwrap_or(0);
if size == 0 {
size = self.count - offset;
} else if size < 0 {
size += self.count - offset;
}
}
// else if size < 0 {
// size += self.count - offset;
// }
PatternView {
data: self.data,

View File

@@ -145,7 +145,7 @@ pub fn ToAlphaNumericChar(value: u32) -> Result<char> {
' ', '$', '%', '*', '+', '-', '.', '/', ':',
];
if value < 0 || value >= (ALPHANUMERIC_CHARS.len()) {
if value >= (ALPHANUMERIC_CHARS.len()) {
return Err(Exceptions::index_out_of_bounds_with(
"oAlphaNumericChar: out of range",
));

View File

@@ -590,20 +590,23 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
// #if 1
let apM = version.as_ref().unwrap().getAlignmentPatternCenters(); // alignment pattern positions in modules
let mut apP = Matrix::new(apM.len(), apM.len())?; // found/guessed alignment pattern positions in pixels
// let apP = Matrix<std::optional<PointF>>(Size(apM), Size(apM)); // found/guessed alignment pattern positions in pixels
let N = (apM.len()) - 1;
// project the alignment pattern at module coordinates x/y to pixel coordinate based on current mod2Pix
let projectM2P = /*[&mod2Pix, &apM]*/| x, y, mod2Pix: &PerspectiveTransform| { mod2Pix.transform_point(Point::centered(point_i(apM[x], apM[y]))) };
let projectM2P = |x, y, mod2Pix: &PerspectiveTransform| {
mod2Pix.transform_point(Point::centered(point_i(apM[x], apM[y])))
};
let mut findInnerCornerOfConcentricPattern = /*[&image, &apP, &projectM2P]*/| x, y, fp:ConcentricPattern| {
let pc = apP.set(x, y, projectM2P(x, y, &mod2Pix));
if let Some(fpQuad) = FindConcentricPatternCorners(image, fp.p, fp.size, 2)
// if (auto fpQuad = FindConcentricPatternCorners(image, fp, fp.size, 2))
{for c in fpQuad .0
{if Point::distance(c, pc) < (fp.size as f32) / 2.0
{apP.set(x, y, c);}}}
};
let mut findInnerCornerOfConcentricPattern = |x, y, fp: ConcentricPattern| {
let pc = apP.set(x, y, projectM2P(x, y, &mod2Pix));
if let Some(fpQuad) = FindConcentricPatternCorners(image, fp.p, fp.size, 2) {
for c in fpQuad.0 {
if Point::distance(c, pc) < (fp.size as f32) / 2.0 {
apP.set(x, y, c);
}
}
}
};
findInnerCornerOfConcentricPattern(0, 0, fp.tl);
findInnerCornerOfConcentricPattern(0, N, fp.bl);
@@ -823,11 +826,10 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
[tr, point(-1.0, 1.0)],
[bl, point(1.0, -1.0)],
] {
// for (auto [p, d] : {std::pair(tl, PointI{1, 1}), {tr, {-1, 1}}, {bl, {1, -1}}}) {
diagonal = EdgeTracer::new(image, p, d)
.readPatternFromBlack(1, Some((width / 3 + 1) as i32))
.ok_or(Exceptions::NOT_FOUND)?;
// diagonal = BitMatrixCursorI(image, p, d).readPatternFromBlack<Pattern>(1, width / 3 + 1);
let diag_hld = diagonal.to_vec().into();
let view = PatternView::new(&diag_hld);
if !(IsPattern::<E2E, 5, 7, false>(&view, &PATTERN, None, 0.0, 0.0) != 0.0) {

View File

@@ -15,9 +15,37 @@ use crate::ResultPoint;
*/
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Default)]
pub struct Point {
pub(crate) x: f32,
pub(crate) y: f32,
pub struct PointT<T> {
pub x: T,
pub y: T,
}
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// #[derive(Debug, Clone, Copy, Default)]
// pub struct Point {
// pub(crate) x: f32,
// pub(crate) y: f32,
// }
pub type PointF = PointT<f32>;
pub type PointI = PointT<u32>;
pub type Point = PointF;
impl Into<PointI> for Point {
fn into(self) -> PointI {
PointI{
x: self.x.floor() as u32,
y: self.y.floor() as u32,
}
}
}
impl Into<Point> for PointI {
fn into(self) -> Point {
Point {
x: self.x as f32,
y: self.y as f32,
}
}
}
/** An alias for `Point::new`. */
@@ -33,9 +61,6 @@ pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point {
Point::new(x.into() as f32, y.into() as f32)
}
/** Currently necessary because the external OneDReader proc macro uses it. */
pub type RXingResultPoint = Point;
impl Hash for Point {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.x.to_string().hash(state);