mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Added more javadoc
git-svn-id: https://zxing.googlecode.com/svn/trunk@9 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
abf5a2cac4
commit
f44627915e
|
@ -34,6 +34,7 @@ public final class BitArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param i bit to get
|
||||||
* @return true iff bit i is set
|
* @return true iff bit i is set
|
||||||
*/
|
*/
|
||||||
public boolean get(int i) {
|
public boolean get(int i) {
|
||||||
|
@ -42,17 +43,26 @@ public final class BitArray {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets bit i.
|
* Sets bit i.
|
||||||
|
*
|
||||||
|
* @param i bit to set
|
||||||
*/
|
*/
|
||||||
public void set(int i) {
|
public void set(int i) {
|
||||||
bits[i >> 5] |= 1 << (i & 0x1F);
|
bits[i >> 5] |= 1 << (i & 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a block of 32 bits, starting at bit i.
|
||||||
|
*
|
||||||
|
* @param i first bit to set
|
||||||
|
* @param newBits the new value of the next 32 bits. Note again that the least-significant bit
|
||||||
|
* correponds to bit i, the next-least-significant to i+1, and so on.
|
||||||
|
*/
|
||||||
public void setBulk(int i, int newBits) {
|
public void setBulk(int i, int newBits) {
|
||||||
bits[i >> 5] = newBits;
|
bits[i >> 5] = newBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all bits.
|
* Clears all bits (sets to false).
|
||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
int max = bits.length;
|
int max = bits.length;
|
||||||
|
|
|
@ -50,16 +50,35 @@ public final class BitMatrix {
|
||||||
bits = new int[arraySize];
|
bits = new int[arraySize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param i row offset
|
||||||
|
* @param j column offset
|
||||||
|
* @return value of given bit in matrix
|
||||||
|
*/
|
||||||
public boolean get(int i, int j) {
|
public boolean get(int i, int j) {
|
||||||
int offset = i + dimension * j;
|
int offset = i + dimension * j;
|
||||||
return ((bits[offset >> 5] >>> (offset & 0x1F)) & 0x01) != 0;
|
return ((bits[offset >> 5] >>> (offset & 0x1F)) & 0x01) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Sets the given bit to true.</p>
|
||||||
|
*
|
||||||
|
* @param i row offset
|
||||||
|
* @param j column offset
|
||||||
|
*/
|
||||||
public void set(int i, int j) {
|
public void set(int i, int j) {
|
||||||
int offset = i + dimension * j;
|
int offset = i + dimension * j;
|
||||||
bits[offset >> 5] |= 1 << (offset & 0x1F);
|
bits[offset >> 5] |= 1 << (offset & 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Sets a square region of the bit matrix to true.</p>
|
||||||
|
*
|
||||||
|
* @param topI row offset of region's top-left corner (inclusive)
|
||||||
|
* @param leftJ column offset of region's top-left corner (inclusive)
|
||||||
|
* @param height height of region
|
||||||
|
* @param width width of region
|
||||||
|
*/
|
||||||
public void setRegion(int topI, int leftJ, int height, int width) {
|
public void setRegion(int topI, int leftJ, int height, int width) {
|
||||||
if (topI < 0 || leftJ < 0) {
|
if (topI < 0 || leftJ < 0) {
|
||||||
throw new IllegalArgumentException("topI and leftJ must be nonnegative");
|
throw new IllegalArgumentException("topI and leftJ must be nonnegative");
|
||||||
|
@ -82,25 +101,30 @@ public final class BitMatrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return row/column dimension of this matrix
|
||||||
|
*/
|
||||||
public int getDimension() {
|
public int getDimension() {
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array of ints holding internal representation of this matrix's bits
|
||||||
|
*/
|
||||||
public int[] getBits() {
|
public int[] getBits() {
|
||||||
return bits;
|
return bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public BufferedImage toBufferedImage() {
|
public BufferedImage toBufferedImage() {
|
||||||
BufferedImage image =
|
BufferedImage image = new BufferedImage(dimension, dimension, BufferedImage.TYPE_BYTE_BINARY);
|
||||||
new BufferedImage(dimension, dimension, BufferedImage.TYPE_BYTE_BINARY);
|
for (int j = 0; j < dimension; j++) {
|
||||||
for (int j = 0; j < dimension; j++) {
|
for (int i = 0; i < dimension; i++) {
|
||||||
for (int i = 0; i < dimension; i++) {
|
image.setRGB(j, i, get(i, j) ? 0x00000000 : 0x00FFFFFF);
|
||||||
image.setRGB(j, i, get(i, j) ? 0x00000000 : 0x00FFFFFF);
|
}
|
||||||
}
|
}
|
||||||
}
|
return image;
|
||||||
return image;
|
}
|
||||||
}
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ public final class Collections {
|
||||||
* Sorts its argument (destructively) using insert sort; in the context of this package
|
* Sorts its argument (destructively) using insert sort; in the context of this package
|
||||||
* insertion sort is simple and efficient given its relatively small inputs.
|
* insertion sort is simple and efficient given its relatively small inputs.
|
||||||
*
|
*
|
||||||
* @param vector
|
* @param vector vector to sort
|
||||||
* @param comparator
|
* @param comparator comparator to define sort ordering
|
||||||
*/
|
*/
|
||||||
public static void insertionSort(Vector vector, Comparator comparator) {
|
public static void insertionSort(Vector vector, Comparator comparator) {
|
||||||
int max = vector.size();
|
int max = vector.size();
|
||||||
|
|
|
@ -51,16 +51,24 @@ final class GF256 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Addition and subtraction are the same in GF(256).
|
* Implements both addition and subtraction -- they are the same in GF(256).
|
||||||
|
*
|
||||||
|
* @return sum/difference of a and b
|
||||||
*/
|
*/
|
||||||
static int addOrSubtract(int a, int b) {
|
static int addOrSubtract(int a, int b) {
|
||||||
return a ^ b;
|
return a ^ b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 2 to the power of a in GF(256)
|
||||||
|
*/
|
||||||
static int exp(int a) {
|
static int exp(int a) {
|
||||||
return exp[a];
|
return exp[a];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return base 2 log of a in GF(256)
|
||||||
|
*/
|
||||||
static int log(int a) {
|
static int log(int a) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
@ -78,6 +86,12 @@ final class GF256 {
|
||||||
return exp[255 - log[a]];
|
return exp[255 - log[a]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
* @return product of a and b in GF(256)
|
||||||
|
*/
|
||||||
static int multiply(int a, int b) {
|
static int multiply(int a, int b) {
|
||||||
if (a == 0 || b == 0) {
|
if (a == 0 || b == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -37,12 +37,22 @@ import java.util.Vector;
|
||||||
* port of his C++ Reed-Solomon implementation.</p>
|
* port of his C++ Reed-Solomon implementation.</p>
|
||||||
*
|
*
|
||||||
* @author srowen@google.com (Sean Owen)
|
* @author srowen@google.com (Sean Owen)
|
||||||
|
* @author William Rucklidge
|
||||||
*/
|
*/
|
||||||
public final class ReedSolomonDecoder {
|
public final class ReedSolomonDecoder {
|
||||||
|
|
||||||
private ReedSolomonDecoder() {
|
private ReedSolomonDecoder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Decodes given set of received codewords, which include both data and error-correction
|
||||||
|
* codewords. Really, this means it uses Reed-Solomon to detect and correct errors, in-place,
|
||||||
|
* in the input.</p>
|
||||||
|
*
|
||||||
|
* @param received data and error-correction codewords
|
||||||
|
* @param twoS number of error-correction codewords available
|
||||||
|
* @throws ReedSolomonException if decoding fails for any reaosn
|
||||||
|
*/
|
||||||
public static void decode(int[] received, int twoS) throws ReedSolomonException {
|
public static void decode(int[] received, int twoS) throws ReedSolomonException {
|
||||||
GF256Poly poly = new GF256Poly(received);
|
GF256Poly poly = new GF256Poly(received);
|
||||||
int[] syndromeCoefficients = new int[twoS];
|
int[] syndromeCoefficients = new int[twoS];
|
||||||
|
|
Loading…
Reference in a new issue