mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
move to singleton ReaderException for a bit more performance
git-svn-id: https://zxing.googlecode.com/svn/trunk@714 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
405aba0044
commit
e9a29fb098
|
@ -47,7 +47,7 @@ public final class AWTImageMonochromeBitmapSource extends BaseMonochromeBitmapSo
|
||||||
try {
|
try {
|
||||||
grabber.grabPixels();
|
grabber.grabPixels();
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
throw new ReaderException("Interrupted while reading pixels");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,19 +23,25 @@ package com.google.zxing;
|
||||||
*
|
*
|
||||||
* @author Sean Owen
|
* @author Sean Owen
|
||||||
*/
|
*/
|
||||||
|
public final class ReaderException extends Exception {
|
||||||
|
|
||||||
// TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before
|
// TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before
|
||||||
// rejecting it. This involves a lot of overhead and memory allocation, and affects both performance
|
// rejecting it. This involves a lot of overhead and memory allocation, and affects both performance
|
||||||
// and latency on continuous scan clients. In the future, we should change all the decoders not to
|
// and latency on continuous scan clients. In the future, we should change all the decoders not to
|
||||||
// throw exceptions for routine events, like not finding a barcode on a given row. Instead, we
|
// throw exceptions for routine events, like not finding a barcode on a given row. Instead, we
|
||||||
// should return error codes back to the callers, and simply delete this class. In the mean time, I
|
// should return error codes back to the callers, and simply delete this class. In the mean time, I
|
||||||
// have altered this class to be as lightweight as possible, by ignoring the exception string, and
|
// have altered this class to be as lightweight as possible, by ignoring the exception string, and
|
||||||
// by disabling the generation of stack traces, which is especially time consuming. These are just
|
// by disabling the generation of stack traces, which is especially time consuming. These are just
|
||||||
// temporary measures, pending the big cleanup.
|
// temporary measures, pending the big cleanup.
|
||||||
public final class ReaderException extends java.lang.Throwable {
|
|
||||||
|
|
||||||
public ReaderException(String message) {
|
private static final ReaderException instance = new ReaderException();
|
||||||
// Do not pass message to Throwable, let it get optimized out
|
|
||||||
|
private ReaderException() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ReaderException getInstance() {
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent stack traces from being taken
|
// Prevent stack traces from being taken
|
||||||
|
|
|
@ -88,7 +88,7 @@ public final class BlackPointEstimator {
|
||||||
// for 1D formats, which are relatively lenient.
|
// for 1D formats, which are relatively lenient.
|
||||||
// We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"
|
// We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"
|
||||||
if (secondPeak - firstPeak <= numBuckets >> 4) {
|
if (secondPeak - firstPeak <= numBuckets >> 4) {
|
||||||
throw new ReaderException("Too little dynamic range in luminance");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a valley between them that is low and closer to the white peak
|
// Find a valley between them that is low and closer to the white peak
|
||||||
|
|
|
@ -67,7 +67,7 @@ public final class DefaultGridSampler extends GridSampler {
|
||||||
// This results in an ugly runtime exception despite our clever checks above -- can't have that.
|
// This results in an ugly runtime exception despite our clever checks above -- can't have that.
|
||||||
// We could check each point's coordinates but that feels duplicative. We settle for
|
// We could check each point's coordinates but that feels duplicative. We settle for
|
||||||
// catching and wrapping ArrayIndexOutOfBoundsException.
|
// catching and wrapping ArrayIndexOutOfBoundsException.
|
||||||
throw new ReaderException(aioobe.toString());
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bits;
|
return bits;
|
||||||
|
|
|
@ -122,7 +122,7 @@ public abstract class GridSampler {
|
||||||
int x = (int) points[offset];
|
int x = (int) points[offset];
|
||||||
int y = (int) points[offset + 1];
|
int y = (int) points[offset + 1];
|
||||||
if (x < -1 || x > width || y < -1 || y > height) {
|
if (x < -1 || x > width || y < -1 || y > height) {
|
||||||
throw new ReaderException("Transformed point out of bounds at " + x + ',' + y);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
nudged = false;
|
nudged = false;
|
||||||
if (x == -1) {
|
if (x == -1) {
|
||||||
|
@ -146,7 +146,7 @@ public abstract class GridSampler {
|
||||||
int x = (int) points[offset];
|
int x = (int) points[offset];
|
||||||
int y = (int) points[offset + 1];
|
int y = (int) points[offset + 1];
|
||||||
if (x < -1 || x > width || y < -1 || y > height) {
|
if (x < -1 || x > width || y < -1 || y > height) {
|
||||||
throw new ReaderException("Transformed point out of bounds at " + x + ',' + y);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
nudged = false;
|
nudged = false;
|
||||||
if (x == -1) {
|
if (x == -1) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class DataMatrixReader implements Reader {
|
||||||
borderWidth++;
|
borderWidth++;
|
||||||
}
|
}
|
||||||
if (borderWidth == minDimension) {
|
if (borderWidth == minDimension) {
|
||||||
throw new ReaderException("No black pixels found along diagonal");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// And then keep tracking across the top-left black module to determine module size
|
// And then keep tracking across the top-left black module to determine module size
|
||||||
|
@ -101,7 +101,7 @@ public final class DataMatrixReader implements Reader {
|
||||||
moduleEnd++;
|
moduleEnd++;
|
||||||
}
|
}
|
||||||
if (moduleEnd == width) {
|
if (moduleEnd == width) {
|
||||||
throw new ReaderException("No end to black pixels found along row");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
int moduleSize = moduleEnd - borderWidth;
|
int moduleSize = moduleEnd - borderWidth;
|
||||||
|
@ -112,14 +112,13 @@ public final class DataMatrixReader implements Reader {
|
||||||
columnEndOfSymbol--;
|
columnEndOfSymbol--;
|
||||||
}
|
}
|
||||||
if (columnEndOfSymbol < 0) {
|
if (columnEndOfSymbol < 0) {
|
||||||
throw new ReaderException("Can't find end of bottommost black module");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
columnEndOfSymbol++;
|
columnEndOfSymbol++;
|
||||||
|
|
||||||
// Make sure width of barcode is a multiple of module size
|
// Make sure width of barcode is a multiple of module size
|
||||||
if ((columnEndOfSymbol - borderWidth) % moduleSize != 0) {
|
if ((columnEndOfSymbol - borderWidth) % moduleSize != 0) {
|
||||||
throw new ReaderException("Bad module size / width: " + moduleSize +
|
throw ReaderException.getInstance();
|
||||||
" / " + (columnEndOfSymbol - borderWidth));
|
|
||||||
}
|
}
|
||||||
int dimension = (columnEndOfSymbol - borderWidth) / moduleSize;
|
int dimension = (columnEndOfSymbol - borderWidth) / moduleSize;
|
||||||
|
|
||||||
|
@ -130,7 +129,7 @@ public final class DataMatrixReader implements Reader {
|
||||||
|
|
||||||
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
|
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
|
||||||
if (sampleDimension >= width || sampleDimension >= height) {
|
if (sampleDimension >= width || sampleDimension >= height) {
|
||||||
throw new ReaderException("Estimated pure image size is beyond image boundaries");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now just read off the bits
|
// Now just read off the bits
|
||||||
|
|
|
@ -35,7 +35,7 @@ final class BitMatrixParser {
|
||||||
BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {
|
BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {
|
||||||
int dimension = bitMatrix.getDimension();
|
int dimension = bitMatrix.getDimension();
|
||||||
if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) {
|
if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) {
|
||||||
throw new ReaderException("Invalid dimension (" + dimension + ") Must be 0 mod 2 and >= 10 and <= 144");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
version = readVersion(bitMatrix);
|
version = readVersion(bitMatrix);
|
||||||
|
@ -141,7 +141,7 @@ final class BitMatrixParser {
|
||||||
} while ((row < numRows) || (column < numColumns));
|
} while ((row < numRows) || (column < numColumns));
|
||||||
|
|
||||||
if (resultOffset != version.getTotalCodewords()) {
|
if (resultOffset != version.getTotalCodewords()) {
|
||||||
throw new ReaderException("Did not read all codewords");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ final class DecodedBitStreamParser {
|
||||||
decodeBase256Segment(bits, result, byteSegments);
|
decodeBase256Segment(bits, result, byteSegments);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ReaderException("Unsupported mode indicator");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
mode = ASCII_ENCODE;
|
mode = ASCII_ENCODE;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ final class DecodedBitStreamParser {
|
||||||
do {
|
do {
|
||||||
int oneByte = bits.readBits(8);
|
int oneByte = bits.readBits(8);
|
||||||
if (oneByte == 0) {
|
if (oneByte == 0) {
|
||||||
throw new ReaderException("0 is an invalid ASCII codeword");
|
throw ReaderException.getInstance();
|
||||||
} else if (oneByte <= 128) { // ASCII data (ASCII value + 1)
|
} else if (oneByte <= 128) { // ASCII data (ASCII value + 1)
|
||||||
oneByte = upperShift ? (oneByte + 128) : oneByte;
|
oneByte = upperShift ? (oneByte + 128) : oneByte;
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
|
@ -141,11 +141,11 @@ final class DecodedBitStreamParser {
|
||||||
} else if (oneByte == 231) { // Latch to Base 256 encodation
|
} else if (oneByte == 231) { // Latch to Base 256 encodation
|
||||||
return BASE256_ENCODE;
|
return BASE256_ENCODE;
|
||||||
} else if (oneByte == 232) { // FNC1
|
} else if (oneByte == 232) { // FNC1
|
||||||
throw new ReaderException("Currently not supporting FNC1");
|
throw ReaderException.getInstance();
|
||||||
} else if (oneByte == 233) { // Structured Append
|
} else if (oneByte == 233) { // Structured Append
|
||||||
throw new ReaderException("Currently not supporting Structured Append");
|
throw ReaderException.getInstance();
|
||||||
} else if (oneByte == 234) { // Reader Programming
|
} else if (oneByte == 234) { // Reader Programming
|
||||||
throw new ReaderException("Currently not supporting Reader Programming");
|
throw ReaderException.getInstance();
|
||||||
} else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII)
|
} else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII)
|
||||||
upperShift = true;
|
upperShift = true;
|
||||||
} else if (oneByte == 236) { // 05 Macro
|
} else if (oneByte == 236) { // 05 Macro
|
||||||
|
@ -162,9 +162,9 @@ final class DecodedBitStreamParser {
|
||||||
return EDIFACT_ENCODE;
|
return EDIFACT_ENCODE;
|
||||||
} else if (oneByte == 241) { // ECI Character
|
} else if (oneByte == 241) { // ECI Character
|
||||||
// TODO(bbrown): I think we need to support ECI
|
// TODO(bbrown): I think we need to support ECI
|
||||||
throw new ReaderException("Currently not supporting ECI Character");
|
throw ReaderException.getInstance();
|
||||||
} else if (oneByte >= 242) { // Not to be used in ASCII encodation
|
} else if (oneByte >= 242) { // Not to be used in ASCII encodation
|
||||||
throw new ReaderException(oneByte + " should not be used in ASCII encodation");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
} while (bits.available() > 0);
|
} while (bits.available() > 0);
|
||||||
return ASCII_ENCODE;
|
return ASCII_ENCODE;
|
||||||
|
@ -226,11 +226,11 @@ final class DecodedBitStreamParser {
|
||||||
result.append(C40_SHIFT2_SET_CHARS[cValue]);
|
result.append(C40_SHIFT2_SET_CHARS[cValue]);
|
||||||
}
|
}
|
||||||
} else if (cValue == 27) { // FNC1
|
} else if (cValue == 27) { // FNC1
|
||||||
throw new ReaderException("Currently not supporting FNC1");
|
throw ReaderException.getInstance();
|
||||||
} else if (cValue == 30) { // Upper Shift
|
} else if (cValue == 30) { // Upper Shift
|
||||||
upperShift = true;
|
upperShift = true;
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException(cValue + " is not valid in the C40 Shift 2 set");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -244,7 +244,7 @@ final class DecodedBitStreamParser {
|
||||||
shift = 0;
|
shift = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ReaderException("Invalid shift value");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bits.available() > 0);
|
} while (bits.available() > 0);
|
||||||
|
@ -307,11 +307,11 @@ final class DecodedBitStreamParser {
|
||||||
result.append(C40_SHIFT2_SET_CHARS[cValue]);
|
result.append(C40_SHIFT2_SET_CHARS[cValue]);
|
||||||
}
|
}
|
||||||
} else if (cValue == 27) { // FNC1
|
} else if (cValue == 27) { // FNC1
|
||||||
throw new ReaderException("Currently not supporting FNC1");
|
throw ReaderException.getInstance();
|
||||||
} else if (cValue == 30) { // Upper Shift
|
} else if (cValue == 30) { // Upper Shift
|
||||||
upperShift = true;
|
upperShift = true;
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException(cValue + " is not valid in the C40 Shift 2 set");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -325,7 +325,7 @@ final class DecodedBitStreamParser {
|
||||||
shift = 0;
|
shift = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ReaderException("Invalid shift value");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bits.available() > 0);
|
} while (bits.available() > 0);
|
||||||
|
@ -366,7 +366,7 @@ final class DecodedBitStreamParser {
|
||||||
} else if (cValue < 40) { // A - Z
|
} else if (cValue < 40) { // A - Z
|
||||||
result.append((char) (cValue + 51));
|
result.append((char) (cValue + 51));
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException(cValue + " is not valid in the ANSI X12 set");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bits.available() > 0);
|
} while (bits.available() > 0);
|
||||||
|
|
|
@ -119,7 +119,7 @@ public final class Decoder {
|
||||||
try {
|
try {
|
||||||
rsDecoder.decode(codewordsInts, numECCodewords);
|
rsDecoder.decode(codewordsInts, numECCodewords);
|
||||||
} catch (ReedSolomonException rse) {
|
} catch (ReedSolomonException rse) {
|
||||||
throw new ReaderException(rse.toString());
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
||||||
// We don't care about errors in the error-correction codewords
|
// We don't care about errors in the error-correction codewords
|
||||||
|
|
|
@ -98,7 +98,7 @@ public final class Version {
|
||||||
*/
|
*/
|
||||||
public static Version getVersionForDimensions(int numRows, int numColumns) throws ReaderException {
|
public static Version getVersionForDimensions(int numRows, int numColumns) throws ReaderException {
|
||||||
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
|
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
|
||||||
throw new ReaderException("Dimension must be 0 mod 2");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bbrown): This is doing a linear search through the array of versions.
|
// TODO(bbrown): This is doing a linear search through the array of versions.
|
||||||
|
@ -112,7 +112,7 @@ public final class Version {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ReaderException("Dimensions do not correspond to a valid Data Matrix Version.");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -130,7 +130,7 @@ public final class Detector {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maybeTopLeft == null || bottomLeft == null || maybeBottomRight == null) {
|
if (maybeTopLeft == null || bottomLeft == null || maybeBottomRight == null) {
|
||||||
throw new ReaderException("Could not find three corners");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom left is correct but top left and bottom right might be switched
|
// Bottom left is correct but top left and bottom right might be switched
|
||||||
|
@ -212,7 +212,7 @@ public final class Detector {
|
||||||
}
|
}
|
||||||
if (range == null) {
|
if (range == null) {
|
||||||
if (lastRange == null) {
|
if (lastRange == null) {
|
||||||
throw new ReaderException("Center of image not within barcode");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
// lastRange was found
|
// lastRange was found
|
||||||
if (dj == 0) {
|
if (dj == 0) {
|
||||||
|
@ -240,7 +240,7 @@ public final class Detector {
|
||||||
}
|
}
|
||||||
lastRange = range;
|
lastRange = range;
|
||||||
}
|
}
|
||||||
throw new ReaderException("Couldn't find an end to barcode");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -140,7 +140,7 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ReaderException("No barcode found");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,7 +162,7 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
}
|
}
|
||||||
int end = row.getSize();
|
int end = row.getSize();
|
||||||
if (start >= end) {
|
if (start >= end) {
|
||||||
throw new ReaderException("Couldn't fully read a pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
boolean isWhite = !row.get(start);
|
boolean isWhite = !row.get(start);
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
|
@ -185,7 +185,7 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
// If we read fully the last section of pixels and filled up our counters -- or filled
|
// If we read fully the last section of pixels and filled up our counters -- or filled
|
||||||
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
||||||
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
|
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
|
||||||
throw new ReaderException("Couldn't fully read a pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,12 +124,12 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
int end = endRange[1];
|
int end = endRange[1];
|
||||||
int quietEnd = end + (end - endRange[0]);
|
int quietEnd = end + (end - endRange[0]);
|
||||||
if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
|
if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
|
||||||
throw new ReaderException("Pattern not followed by whitespace");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
String resultString = result.toString();
|
String resultString = result.toString();
|
||||||
if (!checkChecksum(resultString)) {
|
if (!checkChecksum(resultString)) {
|
||||||
throw new ReaderException("Checksum failed");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
|
float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
|
||||||
|
@ -162,7 +162,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
for (int i = length - 2; i >= 0; i -= 2) {
|
for (int i = length - 2; i >= 0; i -= 2) {
|
||||||
int digit = (int) s.charAt(i) - (int) '0';
|
int digit = (int) s.charAt(i) - (int) '0';
|
||||||
if (digit < 0 || digit > 9) {
|
if (digit < 0 || digit > 9) {
|
||||||
throw new ReaderException("Illegal character during checksum");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
sum += digit;
|
sum += digit;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
for (int i = length - 1; i >= 0; i -= 2) {
|
for (int i = length - 1; i >= 0; i -= 2) {
|
||||||
int digit = (int) s.charAt(i) - (int) '0';
|
int digit = (int) s.charAt(i) - (int) '0';
|
||||||
if (digit < 0 || digit > 9) {
|
if (digit < 0 || digit > 9) {
|
||||||
throw new ReaderException("Illegal character during checksum");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
sum += digit;
|
sum += digit;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ReaderException("Can't find pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -274,7 +274,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
if (bestMatch >= 0) {
|
if (bestMatch >= 0) {
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Could not match any digit in pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ public final class Code128Reader extends AbstractOneDReader {
|
||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ReaderException("Can't find pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws ReaderException {
|
private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws ReaderException {
|
||||||
|
@ -232,7 +232,7 @@ public final class Code128Reader extends AbstractOneDReader {
|
||||||
if (bestMatch >= 0) {
|
if (bestMatch >= 0) {
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Could not match any code pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ public final class Code128Reader extends AbstractOneDReader {
|
||||||
codeSet = CODE_CODE_C;
|
codeSet = CODE_CODE_C;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ReaderException("Illegal start code");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
@ -302,7 +302,7 @@ public final class Code128Reader extends AbstractOneDReader {
|
||||||
case CODE_START_A:
|
case CODE_START_A:
|
||||||
case CODE_START_B:
|
case CODE_START_B:
|
||||||
case CODE_START_C:
|
case CODE_START_C:
|
||||||
throw new ReaderException("Unexpected start code");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (codeSet) {
|
switch (codeSet) {
|
||||||
|
@ -423,14 +423,14 @@ public final class Code128Reader extends AbstractOneDReader {
|
||||||
nextStart++;
|
nextStart++;
|
||||||
}
|
}
|
||||||
if (!row.isRange(nextStart, Math.min(row.getSize(), nextStart + (nextStart - lastStart) / 2), false)) {
|
if (!row.isRange(nextStart, Math.min(row.getSize(), nextStart + (nextStart - lastStart) / 2), false)) {
|
||||||
throw new ReaderException("Pattern not followed by whitespace");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull out from sum the value of the penultimate check code
|
// Pull out from sum the value of the penultimate check code
|
||||||
checksumTotal -= multiplier * lastCode;
|
checksumTotal -= multiplier * lastCode;
|
||||||
// lastCode is the checksum then:
|
// lastCode is the checksum then:
|
||||||
if (checksumTotal % 103 != lastCode) {
|
if (checksumTotal % 103 != lastCode) {
|
||||||
throw new ReaderException("Checksum failed");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to pull out the check digits from string
|
// Need to pull out the check digits from string
|
||||||
|
@ -449,7 +449,7 @@ public final class Code128Reader extends AbstractOneDReader {
|
||||||
|
|
||||||
if (resultString.length() == 0) {
|
if (resultString.length() == 0) {
|
||||||
// Almost surely a false positive
|
// Almost surely a false positive
|
||||||
throw new ReaderException("Empty barcode found; assuming a false positive");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
|
float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
|
||||||
|
|
|
@ -129,7 +129,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
// If 50% of last pattern size, following last pattern, is not whitespace, fail
|
// If 50% of last pattern size, following last pattern, is not whitespace, fail
|
||||||
// (but if it's whitespace to the very end of the image, that's OK)
|
// (but if it's whitespace to the very end of the image, that's OK)
|
||||||
if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
|
if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
|
||||||
throw new ReaderException("Pattern not followed by whitespace");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usingCheckDigit) {
|
if (usingCheckDigit) {
|
||||||
|
@ -139,7 +139,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
total += ALPHABET_STRING.indexOf(result.charAt(i));
|
total += ALPHABET_STRING.indexOf(result.charAt(i));
|
||||||
}
|
}
|
||||||
if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) {
|
if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) {
|
||||||
throw new ReaderException("Checksum failed");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
result.deleteCharAt(max);
|
result.deleteCharAt(max);
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
|
|
||||||
if (resultString.length() == 0) {
|
if (resultString.length() == 0) {
|
||||||
// Almost surely a false positive
|
// Almost surely a false positive
|
||||||
throw new ReaderException("Empty barcode found; assuming a false positive");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
float left = (float) (start[1] + start[0]) / 2.0f;
|
float left = (float) (start[1] + start[0]) / 2.0f;
|
||||||
|
@ -212,7 +212,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ReaderException("Can't find pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int toNarrowWidePattern(int[] counters) throws ReaderException {
|
private static int toNarrowWidePattern(int[] counters) throws ReaderException {
|
||||||
|
@ -249,14 +249,14 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
wideCounters--;
|
wideCounters--;
|
||||||
// totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
|
// totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
|
||||||
if ((counter << 1) >= totalWideCountersWidth) {
|
if ((counter << 1) >= totalWideCountersWidth) {
|
||||||
throw new ReaderException("Wide bars vary too much in width, rejecting");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
} while (wideCounters > 3);
|
} while (wideCounters > 3);
|
||||||
throw new ReaderException("Can't find 3 wide bars/spaces out of 9");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char patternToChar(int pattern) throws ReaderException {
|
private static char patternToChar(int pattern) throws ReaderException {
|
||||||
|
@ -265,7 +265,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
return ALPHABET[i];
|
return ALPHABET[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ReaderException("Pattern did not match character encoding");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String decodeExtended(String encoded) throws ReaderException {
|
private static String decodeExtended(String encoded) throws ReaderException {
|
||||||
|
@ -282,7 +282,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
if (next >= 'A' && next <= 'Z') {
|
if (next >= 'A' && next <= 'Z') {
|
||||||
decodedChar = (char) (next + 32);
|
decodedChar = (char) (next + 32);
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
|
@ -290,7 +290,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
if (next >= 'A' && next <= 'Z') {
|
if (next >= 'A' && next <= 'Z') {
|
||||||
decodedChar = (char) (next - 64);
|
decodedChar = (char) (next - 64);
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
|
@ -300,7 +300,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
} else if (next >= 'F' && next <= 'W') {
|
} else if (next >= 'F' && next <= 'W') {
|
||||||
decodedChar = (char) (next - 11);
|
decodedChar = (char) (next - 11);
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
|
@ -310,7 +310,7 @@ public final class Code39Reader extends AbstractOneDReader {
|
||||||
} else if (next == 'Z') {
|
} else if (next == 'Z') {
|
||||||
decodedChar = ':';
|
decodedChar = ':';
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Invalid extended sequence: " + c + next);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ public final class EAN13Reader extends AbstractUPCEANReader {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ReaderException("Unable to determine first digit");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -68,7 +68,7 @@ public final class MultiFormatOneDReader extends AbstractOneDReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ReaderException("No barcode was detected in this image.");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ReaderException("No barcode was detected in this image.");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public final class UPCAReader implements UPCEANReader {
|
||||||
if (text.charAt(0) == '0') {
|
if (text.charAt(0) == '0') {
|
||||||
return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
|
return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Found EAN-13 code but was not a UPC-A code");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ public final class UPCEReader extends AbstractUPCEANReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ReaderException("Unable to determine number system and check digit");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
BarcodeFormat getBarcodeFormat() {
|
BarcodeFormat getBarcodeFormat() {
|
||||||
|
|
|
@ -93,7 +93,7 @@ public final class QRCodeReader implements Reader {
|
||||||
borderWidth++;
|
borderWidth++;
|
||||||
}
|
}
|
||||||
if (borderWidth == minDimension) {
|
if (borderWidth == minDimension) {
|
||||||
throw new ReaderException("No black pixels found along diagonal");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// And then keep tracking across the top-left black module to determine module size
|
// And then keep tracking across the top-left black module to determine module size
|
||||||
|
@ -102,7 +102,7 @@ public final class QRCodeReader implements Reader {
|
||||||
moduleEnd++;
|
moduleEnd++;
|
||||||
}
|
}
|
||||||
if (moduleEnd == minDimension) {
|
if (moduleEnd == minDimension) {
|
||||||
throw new ReaderException("No end to black pixels found along diagonal");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
int moduleSize = moduleEnd - borderWidth;
|
int moduleSize = moduleEnd - borderWidth;
|
||||||
|
@ -113,14 +113,13 @@ public final class QRCodeReader implements Reader {
|
||||||
rowEndOfSymbol--;
|
rowEndOfSymbol--;
|
||||||
}
|
}
|
||||||
if (rowEndOfSymbol < 0) {
|
if (rowEndOfSymbol < 0) {
|
||||||
throw new ReaderException("Can't find end of rightmost black module");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
rowEndOfSymbol++;
|
rowEndOfSymbol++;
|
||||||
|
|
||||||
// Make sure width of barcode is a multiple of module size
|
// Make sure width of barcode is a multiple of module size
|
||||||
if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) {
|
if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) {
|
||||||
throw new ReaderException("Bad module size / width: " + moduleSize +
|
throw ReaderException.getInstance();
|
||||||
" / " + (rowEndOfSymbol - borderWidth));
|
|
||||||
}
|
}
|
||||||
int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;
|
int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;
|
||||||
|
|
||||||
|
@ -131,7 +130,7 @@ public final class QRCodeReader implements Reader {
|
||||||
|
|
||||||
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
|
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
|
||||||
if (sampleDimension >= width || sampleDimension >= height) {
|
if (sampleDimension >= width || sampleDimension >= height) {
|
||||||
throw new ReaderException("Estimated pure image size is beyond image boundaries");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now just read off the bits
|
// Now just read off the bits
|
||||||
|
|
|
@ -35,7 +35,7 @@ final class BitMatrixParser {
|
||||||
BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {
|
BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {
|
||||||
int dimension = bitMatrix.getDimension();
|
int dimension = bitMatrix.getDimension();
|
||||||
if (dimension < 21 || (dimension & 0x03) != 1) {
|
if (dimension < 21 || (dimension & 0x03) != 1) {
|
||||||
throw new ReaderException("Dimension must be 1 mod 4 and >= 21");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
this.bitMatrix = bitMatrix;
|
this.bitMatrix = bitMatrix;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ final class BitMatrixParser {
|
||||||
if (parsedFormatInfo != null) {
|
if (parsedFormatInfo != null) {
|
||||||
return parsedFormatInfo;
|
return parsedFormatInfo;
|
||||||
}
|
}
|
||||||
throw new ReaderException("Could not decode format information");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +137,7 @@ final class BitMatrixParser {
|
||||||
if (parsedVersion != null) {
|
if (parsedVersion != null) {
|
||||||
return parsedVersion;
|
return parsedVersion;
|
||||||
}
|
}
|
||||||
throw new ReaderException("Could not decode version");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int copyBit(int i, int j, int versionBits) {
|
private int copyBit(int i, int j, int versionBits) {
|
||||||
|
@ -201,7 +201,7 @@ final class BitMatrixParser {
|
||||||
readingUp = !readingUp; // switch directions
|
readingUp = !readingUp; // switch directions
|
||||||
}
|
}
|
||||||
if (resultOffset != version.getTotalCodewords()) {
|
if (resultOffset != version.getTotalCodewords()) {
|
||||||
throw new ReaderException("Did not read all codewords");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ final class DecodedBitStreamParser {
|
||||||
} else if (mode.equals(Mode.KANJI)) {
|
} else if (mode.equals(Mode.KANJI)) {
|
||||||
decodeKanjiSegment(bits, result, count);
|
decodeKanjiSegment(bits, result, count);
|
||||||
} else {
|
} else {
|
||||||
throw new ReaderException("Unsupported mode indicator");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ final class DecodedBitStreamParser {
|
||||||
try {
|
try {
|
||||||
result.append(new String(buffer, SHIFT_JIS));
|
result.append(new String(buffer, SHIFT_JIS));
|
||||||
} catch (UnsupportedEncodingException uee) {
|
} catch (UnsupportedEncodingException uee) {
|
||||||
throw new ReaderException(SHIFT_JIS + " encoding is not supported on this device");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ final class DecodedBitStreamParser {
|
||||||
Vector byteSegments) throws ReaderException {
|
Vector byteSegments) throws ReaderException {
|
||||||
byte[] readBytes = new byte[count];
|
byte[] readBytes = new byte[count];
|
||||||
if (count << 3 > bits.available()) {
|
if (count << 3 > bits.available()) {
|
||||||
throw new ReaderException("Count too large: " + count);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
readBytes[i] = (byte) bits.readBits(8);
|
readBytes[i] = (byte) bits.readBits(8);
|
||||||
|
@ -162,7 +162,7 @@ final class DecodedBitStreamParser {
|
||||||
try {
|
try {
|
||||||
result.append(new String(readBytes, encoding));
|
result.append(new String(readBytes, encoding));
|
||||||
} catch (UnsupportedEncodingException uce) {
|
} catch (UnsupportedEncodingException uce) {
|
||||||
throw new ReaderException(uce.toString());
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
byteSegments.addElement(readBytes);
|
byteSegments.addElement(readBytes);
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ final class DecodedBitStreamParser {
|
||||||
// Each 10 bits encodes three digits
|
// Each 10 bits encodes three digits
|
||||||
int threeDigitsBits = bits.readBits(10);
|
int threeDigitsBits = bits.readBits(10);
|
||||||
if (threeDigitsBits >= 1000) {
|
if (threeDigitsBits >= 1000) {
|
||||||
throw new ReaderException("Illegal value for 3-digit unit: " + threeDigitsBits);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
result.append(ALPHANUMERIC_CHARS[threeDigitsBits / 100]);
|
result.append(ALPHANUMERIC_CHARS[threeDigitsBits / 100]);
|
||||||
result.append(ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]);
|
result.append(ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]);
|
||||||
|
@ -219,7 +219,7 @@ final class DecodedBitStreamParser {
|
||||||
// Two digits left over to read, encoded in 7 bits
|
// Two digits left over to read, encoded in 7 bits
|
||||||
int twoDigitsBits = bits.readBits(7);
|
int twoDigitsBits = bits.readBits(7);
|
||||||
if (twoDigitsBits >= 100) {
|
if (twoDigitsBits >= 100) {
|
||||||
throw new ReaderException("Illegal value for 2-digit unit: " + twoDigitsBits);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
result.append(ALPHANUMERIC_CHARS[twoDigitsBits / 10]);
|
result.append(ALPHANUMERIC_CHARS[twoDigitsBits / 10]);
|
||||||
result.append(ALPHANUMERIC_CHARS[twoDigitsBits % 10]);
|
result.append(ALPHANUMERIC_CHARS[twoDigitsBits % 10]);
|
||||||
|
@ -227,7 +227,7 @@ final class DecodedBitStreamParser {
|
||||||
// One digit left over to read
|
// One digit left over to read
|
||||||
int digitBits = bits.readBits(4);
|
int digitBits = bits.readBits(4);
|
||||||
if (digitBits >= 10) {
|
if (digitBits >= 10) {
|
||||||
throw new ReaderException("Illegal value for digit unit: " + digitBits);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
result.append(ALPHANUMERIC_CHARS[digitBits]);
|
result.append(ALPHANUMERIC_CHARS[digitBits]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ public final class Decoder {
|
||||||
try {
|
try {
|
||||||
rsDecoder.decode(codewordsInts, numECCodewords);
|
rsDecoder.decode(codewordsInts, numECCodewords);
|
||||||
} catch (ReedSolomonException rse) {
|
} catch (ReedSolomonException rse) {
|
||||||
throw new ReaderException(rse.toString());
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
||||||
// We don't care about errors in the error-correction codewords
|
// We don't care about errors in the error-correction codewords
|
||||||
|
|
|
@ -63,7 +63,7 @@ final class ErrorCorrectionLevel {
|
||||||
*/
|
*/
|
||||||
static ErrorCorrectionLevel forBits(int bits) throws ReaderException {
|
static ErrorCorrectionLevel forBits(int bits) throws ReaderException {
|
||||||
if (bits < 0 || bits >= FOR_BITS.length) {
|
if (bits < 0 || bits >= FOR_BITS.length) {
|
||||||
throw new ReaderException("Illegal error correction level bits" + bits);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
return FOR_BITS[bits];
|
return FOR_BITS[bits];
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ final class Mode {
|
||||||
case 0x9:
|
case 0x9:
|
||||||
return FNC1_SECOND_POSITION;
|
return FNC1_SECOND_POSITION;
|
||||||
default:
|
default:
|
||||||
throw new ReaderException("Unsupported mode bits: " + bits);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,14 +95,14 @@ public final class Version {
|
||||||
*/
|
*/
|
||||||
public static Version getProvisionalVersionForDimension(int dimension) throws ReaderException {
|
public static Version getProvisionalVersionForDimension(int dimension) throws ReaderException {
|
||||||
if (dimension % 4 != 1) {
|
if (dimension % 4 != 1) {
|
||||||
throw new ReaderException("Dimension must be 1 mod 4");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
return getVersionForNumber((dimension - 17) >> 2);
|
return getVersionForNumber((dimension - 17) >> 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Version getVersionForNumber(int versionNumber) throws ReaderException {
|
public static Version getVersionForNumber(int versionNumber) throws ReaderException {
|
||||||
if (versionNumber < 1 || versionNumber > 40) {
|
if (versionNumber < 1 || versionNumber > 40) {
|
||||||
throw new ReaderException("versionNumber must be between 1 and 40");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
return VERSIONS[versionNumber - 1];
|
return VERSIONS[versionNumber - 1];
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ final class AlignmentPatternFinder {
|
||||||
return (AlignmentPattern) possibleCenters.elementAt(0);
|
return (AlignmentPattern) possibleCenters.elementAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ReaderException("Could not find alignment pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,7 +75,7 @@ public final class Detector {
|
||||||
|
|
||||||
float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
|
float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
|
||||||
if (moduleSize < 1.0f) {
|
if (moduleSize < 1.0f) {
|
||||||
throw new ReaderException("Module size too small");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
|
int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
|
||||||
Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
|
Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
|
||||||
|
@ -108,7 +108,7 @@ public final class Detector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (alignmentPattern == null) {
|
if (alignmentPattern == null) {
|
||||||
throw new ReaderException("Could not find alignment pattern");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ public final class Detector {
|
||||||
dimension--;
|
dimension--;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
throw new ReaderException("Bad dimension: " + dimension);
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ public final class Detector {
|
||||||
int alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);
|
int alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);
|
||||||
int alignmentAreaRightX = Math.min(image.getWidth() - 1, estAlignmentX + allowance);
|
int alignmentAreaRightX = Math.min(image.getWidth() - 1, estAlignmentX + allowance);
|
||||||
if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {
|
if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {
|
||||||
throw new ReaderException("Alignment pattern is too small to search");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
int alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);
|
int alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);
|
||||||
|
|
|
@ -484,7 +484,7 @@ final class FinderPatternFinder {
|
||||||
|
|
||||||
if (size < 3) {
|
if (size < 3) {
|
||||||
// Couldn't find enough finder patterns
|
// Couldn't find enough finder patterns
|
||||||
throw new ReaderException("Could not find three finder patterns");
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > 3) {
|
if (size > 3) {
|
||||||
|
|
Loading…
Reference in a new issue