com.google.zxing.common
Class BitMatrix

java.lang.Object
  extended by com.google.zxing.common.BitMatrix

public final class BitMatrix
extends Object

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.

Since:
BlackBerry API 6.0.0

Field Summary
 int[] bits
           
 int height
           
 int rowSize
           
 int width
           
 
Constructor Summary
BitMatrix(int dimension)
           
BitMatrix(int width, int height)
           
 
Method Summary
 void clear()
          Clears all bits (sets to false).
 boolean equals(Object o)
          Indicates whether some other object is "equal to" this one.
 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 getDimension()
          This method is for compatibility with older code.
 int getHeight()
           
 BitArray getRow(int y, BitArray row)
          A fast method to retrieve one row of data from the matrix as a BitArray.
 int[] getTopLeftOnBit()
          This is useful in detecting a corner of a 'pure' barcode.
 int getWidth()
           
 int hashCode()
          Returns a hash code value for the object.
 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.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 



Field Detail

width

public final int width
Since:
BlackBerry API 6.0.0

height

public final int height
Since:
BlackBerry API 6.0.0

rowSize

public final int rowSize
Since:
BlackBerry API 6.0.0

bits

public final int[] bits
Since:
BlackBerry API 6.0.0


Constructor Detail

BitMatrix

public BitMatrix(int dimension)
Since:
BlackBerry API 6.0.0

BitMatrix

public BitMatrix(int width,
                 int height)
Since:
BlackBerry API 6.0.0


Method Detail

get

public boolean get(int x,
                   int y)

Gets the requested bit, where true means black.

Parameters:
x - The horizontal component (i.e. which column)
y - The vertical component (i.e. which row)
Returns:
value of given bit in matrix
Since:
BlackBerry API 6.0.0

set

public void set(int x,
                int y)

Sets the given bit to true.

Parameters:
x - The horizontal component (i.e. which column)
y - The vertical component (i.e. which row)
Since:
BlackBerry API 6.0.0

flip

public void flip(int x,
                 int y)

Flips the given bit.

Parameters:
x - The horizontal component (i.e. which column)
y - The vertical component (i.e. which row)
Since:
BlackBerry API 6.0.0

clear

public void clear()
Clears all bits (sets to false).

Since:
BlackBerry API 6.0.0

setRegion

public void setRegion(int left,
                      int top,
                      int width,
                      int height)

Sets a square region of the bit matrix to true.

Parameters:
left - The horizontal position to begin at (inclusive)
top - The vertical position to begin at (inclusive)
width - The width of the region
height - The height of the region
Since:
BlackBerry API 6.0.0

getRow

public BitArray getRow(int y,
                       BitArray row)
A fast method to retrieve one row of data from the matrix as a BitArray.

Parameters:
y - The row to retrieve
row - An optional caller-allocated BitArray, will be allocated if null or too small
Returns:
The resulting BitArray - this reference should always be used even when passing your own row
Since:
BlackBerry API 6.0.0

getTopLeftOnBit

public int[] getTopLeftOnBit()
This is useful in detecting a corner of a 'pure' barcode.

Returns:
{x,y} coordinate of top-left-most 1 bit, or null if it is all white
Since:
BlackBerry API 7.0.0

getBottomRightOnBit

public int[] getBottomRightOnBit()
Since:
BlackBerry API 7.0.0

getWidth

public int getWidth()
Returns:
The width of the matrix
Since:
BlackBerry API 6.0.0

getHeight

public int getHeight()
Returns:
The height of the matrix
Since:
BlackBerry API 6.0.0

getDimension

public int getDimension()
This method is for compatibility with older code. It's only logical to call if the matrix is square, so I'm throwing if that's not the case.

Returns:
row/column dimension of this matrix
Since:
BlackBerry API 6.0.0

equals

public boolean equals(Object o)
Description copied from class: Object
Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation:

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).

Overrides:
equals in class Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Boolean.hashCode(), Hashtable
Since:
BlackBerry API 7.0.0

hashCode

public int hashCode()
Description copied from class: Object
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable
Since:
BlackBerry API 7.0.0

toString

public String toString()
Description copied from class: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.
Since:
BlackBerry API 6.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal