}\r
\r
/**\r
+ * @param i bit to get\r
* @return true iff bit i is set\r
*/\r
public boolean get(int i) {\r
\r
/**\r
* Sets bit i.\r
+ *\r
+ * @param i bit to set\r
*/\r
public void set(int i) {\r
bits[i >> 5] |= 1 << (i & 0x1F);\r
}\r
\r
+ /**\r
+ * Sets a block of 32 bits, starting at bit i.\r
+ *\r
+ * @param i first bit to set\r
+ * @param newBits the new value of the next 32 bits. Note again that the least-significant bit\r
+ * correponds to bit i, the next-least-significant to i+1, and so on.\r
+ */\r
public void setBulk(int i, int newBits) {\r
bits[i >> 5] = newBits;\r
}\r
\r
/**\r
- * Clears all bits.\r
+ * Clears all bits (sets to false).\r
*/\r
public void clear() {\r
int max = bits.length;\r
bits = new int[arraySize];\r
}\r
\r
+ /**\r
+ * @param i row offset\r
+ * @param j column offset\r
+ * @return value of given bit in matrix\r
+ */\r
public boolean get(int i, int j) {\r
int offset = i + dimension * j;\r
return ((bits[offset >> 5] >>> (offset & 0x1F)) & 0x01) != 0;\r
}\r
\r
+ /**\r
+ * <p>Sets the given bit to true.</p>\r
+ *\r
+ * @param i row offset\r
+ * @param j column offset\r
+ */\r
public void set(int i, int j) {\r
int offset = i + dimension * j;\r
bits[offset >> 5] |= 1 << (offset & 0x1F);\r
}\r
\r
+ /**\r
+ * <p>Sets a square region of the bit matrix to true.</p>\r
+ *\r
+ * @param topI row offset of region's top-left corner (inclusive)\r
+ * @param leftJ column offset of region's top-left corner (inclusive)\r
+ * @param height height of region\r
+ * @param width width of region\r
+ */\r
public void setRegion(int topI, int leftJ, int height, int width) {\r
if (topI < 0 || leftJ < 0) {\r
throw new IllegalArgumentException("topI and leftJ must be nonnegative");\r
}\r
}\r
\r
+ /**\r
+ * @return row/column dimension of this matrix\r
+ */\r
public int getDimension() {\r
return dimension;\r
}\r
\r
+ /**\r
+ * @return array of ints holding internal representation of this matrix's bits\r
+ */\r
public int[] getBits() {\r
return bits;\r
}\r
\r
/*\r
public BufferedImage toBufferedImage() {\r
- BufferedImage image =\r
- new BufferedImage(dimension, dimension, BufferedImage.TYPE_BYTE_BINARY);\r
- for (int j = 0; j < dimension; j++) {\r
- for (int i = 0; i < dimension; i++) {\r
- image.setRGB(j, i, get(i, j) ? 0x00000000 : 0x00FFFFFF);\r
- }\r
- }\r
- return image;\r
- }\r
- */\r
+ BufferedImage image = new BufferedImage(dimension, dimension, BufferedImage.TYPE_BYTE_BINARY);\r
+ for (int j = 0; j < dimension; j++) {\r
+ for (int i = 0; i < dimension; i++) {\r
+ image.setRGB(j, i, get(i, j) ? 0x00000000 : 0x00FFFFFF);\r
+ }\r
+ }\r
+ return image;\r
+ }\r
+ */\r
\r
}\r
}
/**
- * 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) {
return a ^ b;
}
+ /**
+ * @return 2 to the power of a in GF(256)
+ */
static int exp(int a) {
return exp[a];
}
+ /**
+ * @return base 2 log of a in GF(256)
+ */
static int log(int a) {
if (a == 0) {
throw new IllegalArgumentException();
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) {
if (a == 0 || b == 0) {
return 0;
* port of his C++ Reed-Solomon implementation.</p>
*
* @author srowen@google.com (Sean Owen)
+ * @author William Rucklidge
*/
public final class 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 {
GF256Poly poly = new GF256Poly(received);
int[] syndromeCoefficients = new int[twoS];