java.lang.Cloneablepublic final class BitMatrix
extends java.lang.Object
implements java.lang.Cloneable
Represents a 2D matrix of bits. In function arguments below, and throughout the common module, x is the column position, and y is the row position. The ordering is always x, y. The origin is at the top-left.
Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins with a new int. This is done intentionally so that we can copy out a row into a BitArray very efficiently.
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 implementation.
| Constructor | Description |
|---|---|
BitMatrix(int dimension) |
|
BitMatrix(int width,
int height) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
clear() |
Clears all bits (sets to false).
|
BitMatrix |
clone() |
|
boolean |
equals(java.lang.Object o) |
|
void |
flip(int x,
int y) |
Flips the given bit.
|
boolean |
get(int x,
int y) |
Gets the requested bit, where true means black.
|
int[] |
getBottomRightOnBit() |
|
int[] |
getEnclosingRectangle() |
This is useful in detecting the enclosing rectangle of a 'pure' barcode.
|
int |
getHeight() |
|
de.uniks.networkparser.bytes.qr.BitArray |
getRow(int y,
de.uniks.networkparser.bytes.qr.BitArray row) |
A fast method to retrieve one row of data from the matrix as a BitArray.
|
int |
getRowSize() |
|
int[] |
getTopLeftOnBit() |
This is useful in detecting a corner of a 'pure' barcode.
|
int |
getWidth() |
|
int |
hashCode() |
|
static BitMatrix |
parse(java.lang.String stringRepresentation,
java.lang.String setString,
java.lang.String unsetString) |
|
void |
rotate180() |
Modifies this
BitMatrix to represent the same but rotated 180 degrees |
void |
set(int x,
int y) |
Sets the given bit to true.
|
void |
setRegion(int left,
int top,
int width,
int height) |
Sets a square region of the bit matrix to true.
|
void |
setRow(int y,
de.uniks.networkparser.bytes.qr.BitArray row) |
|
java.lang.String |
toString() |
|
java.lang.String |
toString(java.lang.String setString,
java.lang.String unsetString) |
|
void |
unset(int x,
int y) |
public BitMatrix(int dimension)
public BitMatrix(int width,
int height)
public static BitMatrix parse(java.lang.String stringRepresentation, java.lang.String setString, java.lang.String unsetString)
public boolean get(int x,
int y)
Gets the requested bit, where true means black.
x - The horizontal component (i.e. which column)y - The vertical component (i.e. which row)public void set(int x,
int y)
Sets the given bit to true.
x - The horizontal component (i.e. which column)y - The vertical component (i.e. which row)public void unset(int x,
int y)
public void flip(int x,
int y)
Flips the given bit.
x - The horizontal component (i.e. which column)y - The vertical component (i.e. which row)public void clear()
public void setRegion(int left,
int top,
int width,
int height)
Sets a square region of the bit matrix to true.
left - The horizontal position to begin at (inclusive)top - The vertical position to begin at (inclusive)width - The width of the regionheight - The height of the regionpublic de.uniks.networkparser.bytes.qr.BitArray getRow(int y,
de.uniks.networkparser.bytes.qr.BitArray row)
y - The row to retrieverow - An optional caller-allocated BitArray, will be allocated if null or too smallpublic void setRow(int y,
de.uniks.networkparser.bytes.qr.BitArray row)
y - row to setrow - BitArray to copy frompublic void rotate180()
BitMatrix to represent the same but rotated 180 degreespublic int[] getEnclosingRectangle()
left,top,width,heightpublic int[] getTopLeftOnBit()
x,ypublic int[] getBottomRightOnBit()
public int getWidth()
public int getHeight()
public int getRowSize()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(java.lang.String setString,
java.lang.String unsetString)
setString - representation of a set bitunsetString - representation of an unset bitpublic BitMatrix clone()
clone in class java.lang.Object