\r
private static final int MAX_ROW_DIFFERENCE = 6;\r
private static final int MAX_ROWS = 90;\r
- private static final int MAX_COLUMNS = 30;\r
+ //private static final int MAX_COLUMNS = 30;\r
// Maximum Codewords (Data + Error)\r
private static final int MAX_CW_CAPACITY = 929;\r
private static final int MODULES_IN_SYMBOL = 17;\r
\r
private final BitMatrix bitMatrix;\r
private int rows = 0;\r
- private int columns = 0;\r
+ //private int columns = 0;\r
\r
private int leftColumnECData = 0;\r
private int rightColumnECData = 0;\r
*\r
* @return an array of codewords.\r
*/\r
- int[] readCodewords() throws ReaderException {\r
+ int[] readCodewords() {\r
int width = bitMatrix.getDimension();\r
// TODO should be a rectangular matrix\r
int height = width;\r
} else {\r
if (rowInProgress) {\r
// Process Row\r
- next = processRow(rowCounters, rowNumber, rowHeight,\r
- moduleWidth, codewords, next);\r
+ next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);\r
if (next == -1) {\r
// Something is wrong, since we have exceeded\r
// the maximum columns in the specification.\r
// TODO Maybe return error code\r
return null;\r
}\r
- next = processRow(rowCounters, rowNumber, rowHeight, moduleWidth,\r
- codewords, next);\r
+ next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);\r
rowNumber++;\r
rows = rowNumber;\r
}\r
*/\r
private static int[] trimArray(int[] array, int size) {\r
if (size > 0) {\r
- int a[] = new int[size];\r
+ int[] a = new int[size];\r
for (int i = 0; i < size; i++) {\r
a[i] = array[i];\r
}\r
\r
/**\r
* Convert the symbols in the row to codewords.\r
+ * Each PDF417 symbol character consists of four bar elements and four space\r
+ * elements, each of which can be one to six modules wide. The four bar and\r
+ * four space elements shall measure 17 modules in total.\r
*\r
* @param rowCounters an array containing the counts of black pixels for each column\r
* in the row.\r
* @param rowNumber the current row number of codewords.\r
* @param rowHeight the height of this row in pixels.\r
- * @param moduleWidth the size of a module in pixels.\r
* @param codewords the codeword array to save codewords into.\r
* @param next the next available index into the codewords array.\r
* @return the next available index into the codeword array after processing\r
* this row.\r
- * @throws ReaderException\r
*/\r
- /*\r
- * Each PDF417 symbol character consists of four bar elements and four space\r
- * elements, each of which can be one to six modules wide. The four bar and\r
- * four space elements shall measure 17 modules in total.\r
- */\r
- int processRow(int[] rowCounters, int rowNumber, int rowHeight,\r
- float moduleWidth, int[] codewords, int next) throws ReaderException {\r
+ int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next) {\r
int width = bitMatrix.getDimension();\r
int columnNumber = 0;\r
long symbol = 0;\r
for (int i = 0; i < width; i += MODULES_IN_SYMBOL) {\r
for (int mask = MODULES_IN_SYMBOL - 1; mask >= 0; mask--) {\r
- if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight / 2) {\r
+ if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight >>> 1) {\r
symbol |= 1 << mask;\r
}\r
}\r
if (columnNumber > 0) {\r
- int cw = getCodeword(symbol, rowNumber);\r
+ int cw = getCodeword(symbol);\r
// if (debug) System.out.println(" " + Long.toBinaryString(symbol) +\r
// " cw=" +cw + " ColumnNumber=" +columnNumber + "i=" +i);\r
if (cw < 0 && i < width - MODULES_IN_SYMBOL) {\r
}\r
} else {\r
// Left row indicator column\r
- int cw = getCodeword(symbol, rowNumber);\r
+ int cw = getCodeword(symbol);\r
// if (debug) System.out.println(" " + Long.toBinaryString(symbol) +\r
// " cw=" +cw + " ColumnNumber=" +columnNumber + "i=" +i);\r
if (ecLevel < 0) {\r
}\r
}\r
symbol = 0;\r
- columns = columnNumber;\r
+ //columns = columnNumber;\r
columnNumber++;\r
}\r
if (columnNumber > 1) {\r
// Right row indicator column is in codeword[next]\r
- columns--;\r
+ //columns--;\r
// Overwrite the last codeword i.e. Right Row Indicator\r
--next;\r
if (ecLevel < 0) {\r
}\r
\r
/**\r
- * Build a symbol from the pixels\r
+ * Build a symbol from the pixels.\r
+ * Each symbol character is defined by an 8-digit bar-space sequence which\r
+ * represents the module widths of the eight elements of that symbol\r
+ * character.\r
*\r
* @param counters array of pixel counter corresponding to each Bar/Space pattern.\r
- * @param rowNumber\r
* @return the symbol\r
*/\r
/*\r
- * Each symbol character is defined by an 8-digit bar-space sequence which\r
- * represents the module widths of the eight elements of that symbol\r
- * character.\r
- */\r
- private static long getSymbol(int[] counters, int rowNumber, float moduleWidth) {\r
+ private static long getSymbol(int[] counters, float moduleWidth) {\r
int pixelsInSymbol = 0;\r
for (int j = 0; j < counters.length; j++) {\r
pixelsInSymbol += counters[j];\r
}\r
return symbol;\r
}\r
+ */\r
\r
/**\r
* Translate the symbol into a codeword.\r
*\r
* @param symbol\r
- * @param row\r
* @return the codeword corresponding to the symbol.\r
- * @throws ReaderException\r
*/\r
- private int getCodeword(long symbol, int row) throws ReaderException {\r
-\r
+ private int getCodeword(long symbol) {\r
long sym = symbol;\r
sym &= 0x3ffff;\r
int i = findCodewordIndex(sym);\r
- long cw = 0;\r
if (i == -1) {\r
return -1;\r
} else {\r
- cw = CODEWORD_TABLE[i] - 1;\r
+ long cw = CODEWORD_TABLE[i] - 1;\r
cw %= 929;\r
+ return (int) cw;\r
}\r
- return (int) cw;\r
}\r
\r
/**\r
* @param symbol the symbol from the barcode.\r
* @return the index into the codeword table.\r
*/\r
- private int findCodewordIndex(long symbol) {\r
+ private static int findCodewordIndex(long symbol) {\r
int first = 0;\r
int upto = SYMBOL_TABLE.length;\r
while (first < upto) {\r
- int mid = (first + upto) / 2; // Compute mid point.\r
+ int mid = (first + upto) >>> 1; // Compute mid point.\r
if (symbol < SYMBOL_TABLE[mid]) {\r
upto = mid; // repeat search in bottom half.\r
} else if (symbol > SYMBOL_TABLE[mid]) {\r
* Ends up being a bit faster than Math.round(). This merely rounds its\r
* argument to the nearest int, where x.5 rounds up.\r
*/\r
+ /*\r
private static int round(float d) {\r
return (int) (d + 0.5f);\r
}\r
-\r
- /**\r
- * Returns the number of codewords flagged as erasures.\r
*/\r
- public int getEraseCount() {\r
- return eraseCount;\r
- }\r
\r
/**\r
* Returns an array of locations representing the erasures.\r
* this row.\r
* @throws ReaderException\r
*/\r
+ /*\r
int processRow1(int[] rowCounters, int rowNumber, int rowHeight,\r
- float moduleWidth, int[] codewords, int next) throws ReaderException {\r
+ float moduleWidth, int[] codewords, int next) {\r
int width = bitMatrix.getDimension();\r
int firstBlack = 0;\r
\r
for (firstBlack = 0; firstBlack < width; firstBlack++) {\r
// Step forward until we find the first black pixels\r
- if (rowCounters[firstBlack] >= rowHeight / 2) {\r
+ if (rowCounters[firstBlack] >= rowHeight >>> 1) {\r
break;\r
}\r
}\r
// for\r
// black\r
// If more than half the column is black\r
- if (rowCounters[i] >= rowHeight / 2 || i == width - 1) {\r
+ if (rowCounters[i] >= rowHeight >>> 1 || i == width - 1) {\r
if (i == width - 1) {\r
counters[state]++;\r
}\r
counters[state]++;\r
}\r
} else {\r
- if (rowCounters[i] < rowHeight / 2) {\r
+ if (rowCounters[i] < rowHeight >>> 1) {\r
// Found white pixels\r
state++;\r
if (state == 7 && i == width - 1) {\r
return -1;\r
}\r
if (columnNumber > 0) {\r
- symbol = getSymbol(counters, rowNumber, moduleWidth);\r
- int cw = getCodeword(symbol, rowNumber);\r
+ symbol = getSymbol(counters, moduleWidth);\r
+ int cw = getCodeword(symbol);\r
// if (debug) System.out.println(" " +\r
// Long.toBinaryString(symbol) + " cw=" +cw + " ColumnNumber="\r
// +columnNumber + "i=" +i);\r
}\r
} else {\r
// Left row indicator column\r
- symbol = getSymbol(counters, rowNumber, moduleWidth);\r
- int cw = getCodeword(symbol, rowNumber);\r
+ symbol = getSymbol(counters, moduleWidth);\r
+ int cw = getCodeword(symbol);\r
if (ecLevel < 0) {\r
switch (rowNumber % 3) {\r
case 0:\r
counters = new int[8];\r
columns = columnNumber;\r
columnNumber++;\r
- /*\r
- * // Introduce some errors if (rowNumber == 0 && columnNumber == 4)\r
- * { codewords[next-1] = 0; erasures[eraseCount] = next-1;\r
- * eraseCount++; } if (rowNumber == 0 && columnNumber == 6) {\r
- * codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
- * eraseCount++; } if (rowNumber == 0 && columnNumber == 8) {\r
- * codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
- * eraseCount++; }\r
- */\r
+ // Introduce some errors if (rowNumber == 0 && columnNumber == 4)\r
+ // { codewords[next-1] = 0; erasures[eraseCount] = next-1;\r
+ // eraseCount++; } if (rowNumber == 0 && columnNumber == 6) {\r
+ // codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
+ // eraseCount++; } if (rowNumber == 0 && columnNumber == 8) {\r
+ // codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
+ // eraseCount++; }\r
state = 0;\r
symbol = 0;\r
}\r
}\r
return next;\r
}\r
+ */\r
\r
/**\r
* The sorted table of all possible symbols. Extracted from the PDF417\r