mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
switch bitmatrix row fetch to skip usless clone
This commit is contained in:
@@ -151,17 +151,17 @@ fn test_get_row() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should allocate
|
// Should allocate
|
||||||
let array = matrix.getRow(2, &BitArray::new());
|
let array = matrix.getRow(2, BitArray::new());
|
||||||
assert_eq!(102, array.getSize());
|
assert_eq!(102, array.getSize());
|
||||||
|
|
||||||
// Should reallocate
|
// Should reallocate
|
||||||
let mut array2 = BitArray::with_size(60);
|
let mut array2 = BitArray::with_size(60);
|
||||||
array2 = matrix.getRow(2, &array2);
|
array2 = matrix.getRow(2, array2);
|
||||||
assert_eq!(102, array2.getSize());
|
assert_eq!(102, array2.getSize());
|
||||||
|
|
||||||
// Should use provided object, with original BitArray size
|
// Should use provided object, with original BitArray size
|
||||||
let mut array3 = BitArray::with_size(200);
|
let mut array3 = BitArray::with_size(200);
|
||||||
array3 = matrix.getRow(2, &array3);
|
array3 = matrix.getRow(2, array3);
|
||||||
assert_eq!(200, array3.getSize());
|
assert_eq!(200, array3.getSize());
|
||||||
|
|
||||||
for x in 0..102 {
|
for x in 0..102 {
|
||||||
|
|||||||
@@ -254,12 +254,12 @@ impl BitMatrix {
|
|||||||
"input matrix dimensions do not match".to_owned(),
|
"input matrix dimensions do not match".to_owned(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let rowArray = BitArray::with_size(self.width as usize);
|
let mut rowArray = BitArray::with_size(self.width as usize);
|
||||||
for y in 0..self.height {
|
for y in 0..self.height {
|
||||||
//for (int y = 0; y < height; y++) {
|
//for (int y = 0; y < height; y++) {
|
||||||
let offset = y as usize * self.row_size;
|
let offset = y as usize * self.row_size;
|
||||||
let tmp = mask.getRow(y, &rowArray);
|
rowArray = mask.getRow(y, rowArray);
|
||||||
let row = tmp.getBitArray();
|
let row = rowArray.getBitArray();
|
||||||
for x in 0..self.row_size {
|
for x in 0..self.row_size {
|
||||||
//for (int x = 0; x < rowSize; x++) {
|
//for (int x = 0; x < rowSize; x++) {
|
||||||
self.bits[offset + x] ^= row[x];
|
self.bits[offset + x] ^= row[x];
|
||||||
@@ -330,11 +330,11 @@ impl BitMatrix {
|
|||||||
* @return The resulting BitArray - this reference should always be used even when passing
|
* @return The resulting BitArray - this reference should always be used even when passing
|
||||||
* your own row
|
* your own row
|
||||||
*/
|
*/
|
||||||
pub fn getRow(&self, y: u32, row: &BitArray) -> BitArray {
|
pub fn getRow(&self, y: u32, row: BitArray) -> BitArray {
|
||||||
let mut rw: BitArray = if row.getSize() < self.width as usize {
|
let mut rw: BitArray = if row.getSize() < self.width as usize {
|
||||||
BitArray::with_size(self.width as usize)
|
BitArray::with_size(self.width as usize)
|
||||||
} else {
|
} else {
|
||||||
let mut z = row.clone();
|
let mut z = row; //row.clone();
|
||||||
z.clear();
|
z.clear();
|
||||||
z
|
z
|
||||||
// row.clear();
|
// row.clear();
|
||||||
@@ -395,9 +395,9 @@ impl BitMatrix {
|
|||||||
let maxHeight = (self.height + 1) / 2;
|
let maxHeight = (self.height + 1) / 2;
|
||||||
for i in 0..maxHeight {
|
for i in 0..maxHeight {
|
||||||
//for (int i = 0; i < maxHeight; i++) {
|
//for (int i = 0; i < maxHeight; i++) {
|
||||||
topRow = self.getRow(i, &topRow);
|
topRow = self.getRow(i, topRow);
|
||||||
let bottomRowIndex = self.height - 1 - i;
|
let bottomRowIndex = self.height - 1 - i;
|
||||||
bottomRow = self.getRow(bottomRowIndex, &bottomRow);
|
bottomRow = self.getRow(bottomRowIndex, bottomRow);
|
||||||
topRow.reverse();
|
topRow.reverse();
|
||||||
bottomRow.reverse();
|
bottomRow.reverse();
|
||||||
self.setRow(i, &bottomRow);
|
self.setRow(i, &bottomRow);
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ mod code_39_extended_mode_test_case {
|
|||||||
let matrix =
|
let matrix =
|
||||||
BitMatrix::parse_strings(encodedRXingResult, "1", "0").expect("bitmatrix parse");
|
BitMatrix::parse_strings(encodedRXingResult, "1", "0").expect("bitmatrix parse");
|
||||||
let row = BitArray::with_size(matrix.getWidth() as usize);
|
let row = BitArray::with_size(matrix.getWidth() as usize);
|
||||||
let row = matrix.getRow(0, &row);
|
let row = matrix.getRow(0, row);
|
||||||
let result = sut.decodeRow(0, &row, &HashMap::new()).expect("decode row");
|
let result = sut.decodeRow(0, &row, &HashMap::new()).expect("decode row");
|
||||||
assert_eq!(expectedRXingResult, result.getText());
|
assert_eq!(expectedRXingResult, result.getText());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user