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).
 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 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 getWidth()
           
 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
equals, getClass, hashCode, 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

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

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-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.