mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Merge branch 'main' into port_cpp_qrcode
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rxing"
|
name = "rxing"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
description="A rust port of the zxing barcode library."
|
description="A rust port of the zxing barcode library."
|
||||||
license="Apache-2.0"
|
license="Apache-2.0"
|
||||||
repository="https://github.com/rxing-core/rxing"
|
repository="https://github.com/rxing-core/rxing"
|
||||||
|
|||||||
@@ -202,14 +202,17 @@ impl BitMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Gets the requested bit, where true means black.</p>
|
* Gets the requested bit, where true means black.
|
||||||
*
|
*
|
||||||
* @param x The horizontal component (i.e. which column)
|
* x The horizontal component (i.e. which column)
|
||||||
* @param y The vertical component (i.e. which row)
|
* y The vertical component (i.e. which row)
|
||||||
* @return value of given bit in matrix
|
* returns the value of given bit in matrix, or false if the requested point is out of bounds of the image
|
||||||
*/
|
*/
|
||||||
pub fn get(&self, x: u32, y: u32) -> bool {
|
pub fn get(&self, x: u32, y: u32) -> bool {
|
||||||
let offset = self.get_offset(y, x);
|
let offset = self.get_offset(y, x);
|
||||||
|
if offset >= self.bits.len() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
((self.bits[offset] >> (x & 0x1f)) & 1) != 0
|
((self.bits[offset] >> (x & 0x1f)) & 1) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +235,10 @@ impl BitMatrix {
|
|||||||
Some(((self.bits[offset] >> (x & 0x1f)) & 1) != 0)
|
Some(((self.bits[offset] >> (x & 0x1f)) & 1) != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn try_get_point(&self, point: Point) -> Option<bool> {
|
||||||
|
self.try_get(point.x as u32, point.y as u32)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn try_get_area(&self, x: u32, y: u32, box_size: u32) -> Option<bool> {
|
pub fn try_get_area(&self, x: u32, y: u32, box_size: u32) -> Option<bool> {
|
||||||
let mut matrix = Vec::with_capacity((box_size * box_size) as usize);
|
let mut matrix = Vec::with_capacity((box_size * box_size) as usize);
|
||||||
let start_x = (x as i32 - box_size as i32 / 2).max(0) as u32;
|
let start_x = (x as i32 - box_size as i32 / 2).max(0) as u32;
|
||||||
@@ -255,7 +262,12 @@ impl BitMatrix {
|
|||||||
|
|
||||||
/// Confusingly returns true if the requested element is out of bounds
|
/// Confusingly returns true if the requested element is out of bounds
|
||||||
pub fn check_in_bounds(&self, x: u32, y: u32) -> bool {
|
pub fn check_in_bounds(&self, x: u32, y: u32) -> bool {
|
||||||
(self.get_offset(y, x)) > self.bits.len()
|
(self.get_offset(y, x)) >= self.bits.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Confusingly returns true if the requested element is out of bounds
|
||||||
|
pub fn check_point_in_bounds(&self, point: Point) -> bool {
|
||||||
|
self.check_in_bounds(point.x as u32, point.y as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ impl Circle<'_> {
|
|||||||
// count left
|
// count left
|
||||||
while {
|
while {
|
||||||
let point = get_point(self.center, (x, y), rotation);
|
let point = get_point(self.center, (x, y), rotation);
|
||||||
!self.image.get(point.x as u32, point.y as u32) && x > 0
|
!self.image.check_point_in_bounds(point) && !self.image.get_point(point) && x > 0
|
||||||
} {
|
} {
|
||||||
x -= 1;
|
x -= 1;
|
||||||
length += 1;
|
length += 1;
|
||||||
@@ -293,7 +293,7 @@ impl Circle<'_> {
|
|||||||
// count right
|
// count right
|
||||||
while {
|
while {
|
||||||
let point = get_point(self.center, (x, y), rotation);
|
let point = get_point(self.center, (x, y), rotation);
|
||||||
!self.image.get(point.x as u32, point.y as u32)
|
!self.image.check_point_in_bounds(point) && !self.image.get_point(point)
|
||||||
} {
|
} {
|
||||||
x += 1;
|
x += 1;
|
||||||
length += 1;
|
length += 1;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
File diff suppressed because one or more lines are too long
24
tests/github_issues.rs
Normal file
24
tests/github_issues.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use rxing::DecodingHintDictionary;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn issue_27_part_2() {
|
||||||
|
let mut data = Vec::new();
|
||||||
|
std::fs::File::open("test_resources/blackbox/github_issue_cases/panic_data2_issue_27.bin")
|
||||||
|
.unwrap()
|
||||||
|
.read_to_end(&mut data)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
rxing::helpers::detect_multiple_in_luma(data, 720, 618).unwrap_or_default();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn issue_28() {
|
||||||
|
let mut hints: DecodingHintDictionary = DecodingHintDictionary::new();
|
||||||
|
hints.insert(
|
||||||
|
rxing::DecodeHintType::TRY_HARDER,
|
||||||
|
rxing::DecodeHintValue::TryHarder(true),
|
||||||
|
);
|
||||||
|
rxing::helpers::detect_multiple_in_file_with_hints("test_resources/blackbox/github_issue_cases/226611447-be6041dc-5b21-42fe-827b-068ccc59082c.png", &mut hints).unwrap_or_default();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user