BitMatrix.java (zxing-zxing-3.4.1) | : | BitMatrix.java (zxing-zxing-3.5.0) | ||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
* efficiently.</p> | * efficiently.</p> | |||
* | * | |||
* <p>The ordering of bits is row-major. Within each int, the least significant bits are used first, | * <p>The ordering of bits is row-major. Within each int, the least significant bits are used first, | |||
* meaning they represent lower x values. This is compatible with BitArray's imp lementation.</p> | * meaning they represent lower x values. This is compatible with BitArray's imp lementation.</p> | |||
* | * | |||
* @author Sean Owen | * @author Sean Owen | |||
* @author dswitkin@google.com (Daniel Switkin) | * @author dswitkin@google.com (Daniel Switkin) | |||
*/ | */ | |||
public final class BitMatrix implements Cloneable { | public final class BitMatrix implements Cloneable { | |||
private final int width; | private int width; | |||
private final int height; | private int height; | |||
private final int rowSize; | private int rowSize; | |||
private final int[] bits; | private int[] bits; | |||
/** | /** | |||
* Creates an empty square {@code BitMatrix}. | * Creates an empty square {@code BitMatrix}. | |||
* | * | |||
* @param dimension height and width | * @param dimension height and width | |||
*/ | */ | |||
public BitMatrix(int dimension) { | public BitMatrix(int dimension) { | |||
this(dimension, dimension); | this(dimension, dimension); | |||
} | } | |||
skipping to change at line 193 | skipping to change at line 193 | |||
* | * | |||
* @param x The horizontal component (i.e. which column) | * @param x The horizontal component (i.e. which column) | |||
* @param y The vertical component (i.e. which row) | * @param y The vertical component (i.e. which row) | |||
*/ | */ | |||
public void flip(int x, int y) { | public void flip(int x, int y) { | |||
int offset = y * rowSize + (x / 32); | int offset = y * rowSize + (x / 32); | |||
bits[offset] ^= 1 << (x & 0x1f); | bits[offset] ^= 1 << (x & 0x1f); | |||
} | } | |||
/** | /** | |||
* <p>Flips every bit in the matrix.</p> | ||||
*/ | ||||
public void flip() { | ||||
int max = bits.length; | ||||
for (int i = 0; i < max; i++) { | ||||
bits[i] = ~bits[i]; | ||||
} | ||||
} | ||||
/** | ||||
* Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the correspon ding | * Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the correspon ding | |||
* mask bit is set. | * mask bit is set. | |||
* | * | |||
* @param mask XOR mask | * @param mask XOR mask | |||
*/ | */ | |||
public void xor(BitMatrix mask) { | public void xor(BitMatrix mask) { | |||
if (width != mask.width || height != mask.height || rowSize != mask.rowSize) { | if (width != mask.width || height != mask.height || rowSize != mask.rowSize) { | |||
throw new IllegalArgumentException("input matrix dimensions do not match") ; | throw new IllegalArgumentException("input matrix dimensions do not match") ; | |||
} | } | |||
BitArray rowArray = new BitArray(width); | BitArray rowArray = new BitArray(width); | |||
skipping to change at line 298 | skipping to change at line 308 | |||
int bottomRowIndex = height - 1 - i; | int bottomRowIndex = height - 1 - i; | |||
bottomRow = getRow(bottomRowIndex, bottomRow); | bottomRow = getRow(bottomRowIndex, bottomRow); | |||
topRow.reverse(); | topRow.reverse(); | |||
bottomRow.reverse(); | bottomRow.reverse(); | |||
setRow(i, bottomRow); | setRow(i, bottomRow); | |||
setRow(bottomRowIndex, topRow); | setRow(bottomRowIndex, topRow); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Modifies this {@code BitMatrix} to represent the same but rotated 90 degree | ||||
s counterclockwise | ||||
*/ | ||||
public void rotate90() { | ||||
int newWidth = height; | ||||
int newHeight = width; | ||||
int newRowSize = (newWidth + 31) / 32; | ||||
int[] newBits = new int[newRowSize * newHeight]; | ||||
for (int y = 0; y < height; y++) { | ||||
for (int x = 0; x < width; x++) { | ||||
int offset = y * rowSize + (x / 32); | ||||
if (((bits[offset] >>> (x & 0x1f)) & 1) != 0) { | ||||
int newOffset = (newHeight - 1 - x) * newRowSize + (y / 32); | ||||
newBits[newOffset] |= 1 << (y & 0x1f); | ||||
} | ||||
} | ||||
} | ||||
width = newWidth; | ||||
height = newHeight; | ||||
rowSize = newRowSize; | ||||
bits = newBits; | ||||
} | ||||
/** | ||||
* This is useful in detecting the enclosing rectangle of a 'pure' barcode. | * This is useful in detecting the enclosing rectangle of a 'pure' barcode. | |||
* | * | |||
* @return {@code left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white | * @return {@code left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white | |||
*/ | */ | |||
public int[] getEnclosingRectangle() { | public int[] getEnclosingRectangle() { | |||
int left = width; | int left = width; | |||
int top = height; | int top = height; | |||
int right = -1; | int right = -1; | |||
int bottom = -1; | int bottom = -1; | |||
skipping to change at line 431 | skipping to change at line 465 | |||
return width == other.width && height == other.height && rowSize == other.ro wSize && | return width == other.width && height == other.height && rowSize == other.ro wSize && | |||
Arrays.equals(bits, other.bits); | Arrays.equals(bits, other.bits); | |||
} | } | |||
@Override | @Override | |||
public int hashCode() { | public int hashCode() { | |||
int hash = width; | int hash = width; | |||
hash = 31 * hash + width; | hash = 31 * hash + width; | |||
hash = 31 * hash + height; | hash = 31 * hash + height; | |||
hash = 31 * hash + rowSize; | hash = 31 * hash + rowSize; | |||
hash = 31 * hash + Arrays.hashCode(bits); | hash = 31 * hash + Arrays.hashCode(bits); | |||
return hash; | return hash; | |||
} | } | |||
/** | /** | |||
* @return string representation using "X" for set and " " for unset bits | * @return string representation using "X" for set and " " for unset bits | |||
*/ | */ | |||
@Override | @Override | |||
public String toString() { | public String toString() { | |||
return toString("X ", " "); | return toString("X ", " "); | |||
} | } | |||
End of changes. 4 change blocks. | ||||
5 lines changed or deleted | 40 lines changed or added |