diff --git a/Cargo.toml b/Cargo.toml index 748daf4..e5286d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rxing" -version = "0.4.2" +version = "0.4.3" description="A rust port of the zxing barcode library." license="Apache-2.0" repository="https://github.com/rxing-core/rxing" diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index 0868d7b..fd6afb0 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -202,14 +202,17 @@ impl BitMatrix { } /** - *
Gets the requested bit, where true means black.
+ * Gets the requested bit, where true means black. * - * @param x The horizontal component (i.e. which column) - * @param y The vertical component (i.e. which row) - * @return value of given bit in matrix + * x The horizontal component (i.e. which column) + * y The vertical component (i.e. which row) + * 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 { let offset = self.get_offset(y, x); + if offset >= self.bits.len() { + return false; + } ((self.bits[offset] >> (x & 0x1f)) & 1) != 0 } @@ -232,6 +235,10 @@ impl BitMatrix { Some(((self.bits[offset] >> (x & 0x1f)) & 1) != 0) } + pub fn try_get_point(&self, point: Point) -> Option