BitMatrix.java revision 7e3fa36d69ffee874dd364b8e3d9aa3cab9a273b
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <p>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.</p>
*
* <p>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.</p>
*
* <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 implementation.</p>
*
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class BitMatrix {
private final int width;
private final int height;
private final int rowSize;
private final int[] bits;
// A helper to construct a square matrix.
}
throw new IllegalArgumentException("Both dimensions must be greater than 0");
}
}
/**
* <p>Gets the requested bit, where true means black.</p>
*
* @param x The horizontal component (i.e. which column)
* @param y The vertical component (i.e. which row)
* @return value of given bit in matrix
*/
public boolean get(int x, int y) {
}
/**
* <p>Sets the given bit to true.</p>
*
* @param x The horizontal component (i.e. which column)
* @param y The vertical component (i.e. which row)
*/
public void set(int x, int y) {
}
/**
* <p>Flips the given bit.</p>
*
* @param x The horizontal component (i.e. which column)
* @param y The vertical component (i.e. which row)
*/
public void flip(int x, int y) {
}
/**
* Clears all bits (sets to false).
*/
public void clear() {
for (int i = 0; i < max; i++) {
bits[i] = 0;
}
}
/**
* <p>Sets a square region of the bit matrix to true.</p>
*
* @param left The horizontal position to begin at (inclusive)
* @param top The vertical position to begin at (inclusive)
* @param width The width of the region
* @param height The height of the region
*/
throw new IllegalArgumentException("Left and top must be nonnegative");
}
throw new IllegalArgumentException("Height and width must be at least 1");
}
throw new IllegalArgumentException("The region must fit inside the matrix");
}
}
}
}
/**
* A fast method to retrieve one row of data from the matrix as a BitArray.
*
* @param y The row to retrieve
* @param row An optional caller-allocated BitArray, will be allocated if null or too small
* @return The resulting BitArray - this reference should always be used even when passing
* your own row
*/
}
for (int x = 0; x < rowSize; x++) {
}
return row;
}
/**
* @param y row to set
* @param row {@link BitArray} to copy from
*/
}
/**
* This is useful in detecting the enclosing rectangle of a 'pure' barcode.
*
* @return {left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white
*/
public int[] getEnclosingRectangle() {
int right = -1;
int bottom = -1;
for (int y = 0; y < height; y++) {
if (theBits != 0) {
if (y < top) {
top = y;
}
if (y > bottom) {
bottom = y;
}
int bit = 0;
bit++;
}
}
}
int bit = 31;
bit--;
}
}
}
}
}
}
return null;
}
}
/**
* This is useful in detecting a corner of a 'pure' barcode.
*
* @return {x,y} coordinate of top-left-most 1 bit, or null if it is all white
*/
public int[] getTopLeftOnBit() {
int bitsOffset = 0;
bitsOffset++;
}
return null;
}
int y = bitsOffset / rowSize;
int bit = 0;
bit++;
}
x += bit;
return new int[] {x, y};
}
public int[] getBottomRightOnBit() {
bitsOffset--;
}
if (bitsOffset < 0) {
return null;
}
int y = bitsOffset / rowSize;
int bit = 31;
bit--;
}
x += bit;
return new int[] {x, y};
}
/**
* @return The width of the matrix
*/
public int getWidth() {
return width;
}
/**
* @return The height of the matrix
*/
public int getHeight() {
return height;
}
if (!(o instanceof BitMatrix)) {
return false;
}
return false;
}
return false;
}
}
return true;
}
public int hashCode() {
}
return hash;
}
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
}
}
}
}