* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
* @return The array of bits for this row (true means black).
*/
- public abstract BitArray getBlackRow(int y, BitArray row) throws ReaderException;
+ public abstract BitArray getBlackRow(int y, BitArray row) throws NotFoundException;
/**
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
*
* @return The 2D array of bits for the image (true means black).
*/
- public abstract BitMatrix getBlackMatrix() throws ReaderException;
+ public abstract BitMatrix getBlackMatrix() throws NotFoundException;
/**
* Creates a new object with the same type as this Binarizer implementation, but with pristine
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
* @return The array of bits for this row (true means black).
*/
- public BitArray getBlackRow(int y, BitArray row) throws ReaderException {
+ public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
return binarizer.getBlackRow(y, row);
}
*
* @return The 2D array of bits for the image (true means black).
*/
- public BitMatrix getBlackMatrix() throws ReaderException {
+ public BitMatrix getBlackMatrix() throws NotFoundException {
// The matrix is created on demand the first time it is requested, then cached. There are two
// reasons for this:
// 1. This work will never be done if the caller only installs 1D Reader objects, or if a
--- /dev/null
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package com.google.zxing;
+
+/**
+ * Thrown when a barcode was successfully detected and decoded, but
+ * was not returned because its checksum feature failed.
+ *
+ * @author Sean Owen
+ */
+public final class ChecksumException extends ReaderException {
+
+ private static final ChecksumException instance = new ChecksumException();
+
+ private ChecksumException() {
+ // do nothing
+ }
+
+ public static ChecksumException getChecksumInstance() {
+ return instance;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package com.google.zxing;
+
+/**
+ * Thrown when a barcode was successfully detected, but some aspect of
+ * the content did not conform to the barcode's format rules. This could have
+ * been due to a mis-detection.
+ *
+ * @author Sean Owen
+ */
+public final class FormatException extends ReaderException {
+
+ private static final FormatException instance = new FormatException();
+
+ private FormatException() {
+ // do nothing
+ }
+
+ public static FormatException getFormatInstance() {
+ return instance;
+ }
+
+}
\ No newline at end of file
package com.google.zxing;
+import com.google.zxing.datamatrix.DataMatrixReader;
import com.google.zxing.oned.MultiFormatOneDReader;
import com.google.zxing.pdf417.PDF417Reader;
import com.google.zxing.qrcode.QRCodeReader;
-import com.google.zxing.datamatrix.DataMatrixReader;
import java.util.Hashtable;
import java.util.Vector;
*
* @param image The pixel data to decode
* @return The contents of the image
- * @throws ReaderException Any errors which occurred
+ * @throws NotFoundException Any errors which occurred
*/
- public Result decode(BinaryBitmap image) throws ReaderException {
+ public Result decode(BinaryBitmap image) throws NotFoundException {
setHints(null);
return decodeInternal(image);
}
* @param image The pixel data to decode
* @param hints The hints to use, clearing the previous state.
* @return The contents of the image
- * @throws ReaderException Any errors which occurred
+ * @throws NotFoundException Any errors which occurred
*/
- public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
+ public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException {
setHints(hints);
return decodeInternal(image);
}
*
* @param image The pixel data to decode
* @return The contents of the image
- * @throws ReaderException Any errors which occurred
+ * @throws NotFoundException Any errors which occurred
*/
- public Result decodeWithState(BinaryBitmap image) throws ReaderException {
+ public Result decodeWithState(BinaryBitmap image) throws NotFoundException {
// Make sure to set up the default state so we don't crash
if (readers == null) {
setHints(null);
}
}
- private Result decodeInternal(BinaryBitmap image) throws ReaderException {
+ private Result decodeInternal(BinaryBitmap image) throws NotFoundException {
int size = readers.size();
for (int i = 0; i < size; i++) {
Reader reader = (Reader) readers.elementAt(i);
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
}
--- /dev/null
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package com.google.zxing;
+
+/**
+ * Thrown when a barcode was not found in the image. It might have been
+ * partially detected but could not be confirmed.
+ *
+ * @author Sean Owen
+ */
+public final class NotFoundException extends ReaderException {
+
+ private static final NotFoundException instance = new NotFoundException();
+
+ private NotFoundException() {
+ // do nothing
+ }
+
+ public static NotFoundException getNotFoundInstance() {
+ return instance;
+ }
+
+}
\ No newline at end of file
*
* @param image image of barcode to decode
* @return String which the barcode encodes
- * @throws ReaderException if the barcode cannot be located or decoded for any reason
+ * @throws NotFoundException if the barcode cannot be located or decoded for any reason
*/
- Result decode(BinaryBitmap image) throws ReaderException;
+ Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException;
/**
* Locates and decodes a barcode in some format within an image. This method also accepts
* meaning of the data depends upon the hint type. The implementation may or may not do
* anything with these hints.
* @return String which the barcode encodes
- * @throws ReaderException if the barcode cannot be located or decoded for any reason
+ * @throws NotFoundException if the barcode cannot be located or decoded for any reason
*/
- Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException;
+ Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, ChecksumException, FormatException;
/**
* Resets any internal state the implementation has after a decode, to prepare it
*
* @author Sean Owen
*/
-public final class ReaderException extends Exception {
+public abstract class ReaderException extends Exception {
// 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
// by disabling the generation of stack traces, which is especially time consuming. These are just
// temporary measures, pending the big cleanup.
- private static final ReaderException instance = new ReaderException();
+ //private static final ReaderException instance = new ReaderException();
// EXCEPTION TRACKING SUPPORT
// Identifies who is throwing exceptions and how often. To use:
// private static int exceptionCount = 0;
// private static Map<String,Integer> throwers = new HashMap<String,Integer>(32);
- private ReaderException() {
+ ReaderException() {
// do nothing
}
- public static ReaderException getInstance() {
+ //public static ReaderException getInstance() {
// Exception e = new Exception();
// // Take the stack frame before this one.
// StackTraceElement stack = e.getStackTrace()[1];
// }
// exceptionCount++;
- return instance;
- }
+ //return instance;
+ //}
// public static int getExceptionCountAndReset() {
// int temp = exceptionCount;
// Prevent stack traces from being taken
// srowen says: huh, my IDE is saying this is not an override. native methods can't be overridden?
// This, at least, does not hurt. Because we use a singleton pattern here, it doesn't matter anyhow.
- public Throwable fillInStackTrace() {
+ public final Throwable fillInStackTrace() {
return null;
}
package com.google.zxing.common;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
/**
* @author Sean Owen
float p1FromX, float p1FromY,
float p2FromX, float p2FromY,
float p3FromX, float p3FromY,
- float p4FromX, float p4FromY) throws ReaderException {
+ float p4FromX, float p4FromY) throws NotFoundException {
PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral(
p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY,
public BitMatrix sampleGrid(BitMatrix image,
int dimension,
- PerspectiveTransform transform) throws ReaderException {
+ PerspectiveTransform transform) throws NotFoundException {
BitMatrix bits = new BitMatrix(dimension);
float[] points = new float[dimension << 1];
for (int y = 0; y < dimension; y++) {
// 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
// catching and wrapping ArrayIndexOutOfBoundsException.
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
}
return bits;
import com.google.zxing.Binarizer;
import com.google.zxing.LuminanceSource;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
/**
* This Binarizer implementation uses the old ZXing global histogram approach. It is suitable
}
// Applies simple sharpening to the row data to improve performance of the 1D Readers.
- public BitArray getBlackRow(int y, BitArray row) throws ReaderException {
+ public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
LuminanceSource source = getLuminanceSource();
int width = source.getWidth();
if (row == null || row.getSize() < width) {
}
// Does not sharpen the data, as this call is intended to only be used by 2D Readers.
- public BitMatrix getBlackMatrix() throws ReaderException {
+ public BitMatrix getBlackMatrix() throws NotFoundException {
LuminanceSource source = getLuminanceSource();
int width = source.getWidth();
int height = source.getHeight();
}
}
- private static int estimateBlackPoint(int[] buckets) throws ReaderException {
+ private static int estimateBlackPoint(int[] buckets) throws NotFoundException {
// Find the tallest peak in the histogram.
int numBuckets = buckets.length;
int maxBucketCount = 0;
// TODO: It might be worth comparing the brightest and darkest pixels seen, rather than the
// two peaks, to determine the contrast.
if (secondPeak - firstPeak <= numBuckets >> 4) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// Find a valley between them that is low and closer to the white peak.
package com.google.zxing.common;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
/**
* Implementations of this class can, given locations of finder patterns for a QR code in an
* @param dimension width/height of {@link BitMatrix} to sample from image
* @return {@link BitMatrix} representing a grid of points sampled from the image within a region
* defined by the "from" parameters
- * @throws ReaderException if image can't be sampled, for example, if the transformation defined
+ * @throws NotFoundException if image can't be sampled, for example, if the transformation defined
* by the given points is invalid or results in sampling outside the image boundaries
*/
public abstract BitMatrix sampleGrid(BitMatrix image,
float p1FromX, float p1FromY,
float p2FromX, float p2FromY,
float p3FromX, float p3FromY,
- float p4FromX, float p4FromY) throws ReaderException;
+ float p4FromX, float p4FromY) throws NotFoundException;
public BitMatrix sampleGrid(BitMatrix image,
int dimension,
- PerspectiveTransform transform) throws ReaderException {
+ PerspectiveTransform transform) throws NotFoundException {
throw new UnsupportedOperationException();
}
*
* @param image image into which the points should map
* @param points actual points in x1,y1,...,xn,yn form
- * @throws ReaderException if an endpoint is lies outside the image boundaries
+ * @throws NotFoundException if an endpoint is lies outside the image boundaries
*/
protected static void checkAndNudgePoints(BitMatrix image, float[] points)
- throws ReaderException {
+ throws NotFoundException {
int width = image.getWidth();
int height = image.getHeight();
// Check and nudge points from start until we see some that are OK:
int x = (int) points[offset];
int y = (int) points[offset + 1];
if (x < -1 || x > width || y < -1 || y > height) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
nudged = false;
if (x == -1) {
int x = (int) points[offset];
int y = (int) points[offset + 1];
if (x < -1 || x > width || y < -1 || y > height) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
nudged = false;
if (x == -1) {
import com.google.zxing.Binarizer;
import com.google.zxing.LuminanceSource;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
/**
* This class implements a local thresholding algorithm, which while slower than the
super(source);
}
- public BitMatrix getBlackMatrix() throws ReaderException {
+ public BitMatrix getBlackMatrix() throws NotFoundException {
binarizeEntireImage();
return matrix;
}
// Calculates the final BitMatrix once for all requests. This could be called once from the
// constructor instead, but there are some advantages to doing it lazily, such as making
// profiling easier, and not doing heavy lifting when callers don't expect it.
- private void binarizeEntireImage() throws ReaderException {
+ private void binarizeEntireImage() throws NotFoundException {
if (matrix == null) {
LuminanceSource source = getLuminanceSource();
if (source.getWidth() >= MINIMUM_DIMENSION && source.getHeight() >= MINIMUM_DIMENSION) {
package com.google.zxing.common.detector;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
* last points are opposed on the diagonal, as are the second and third. The first point will be
* the topmost point and the last, the bottommost. The second point will be leftmost and the
* third, the rightmost
- * @throws ReaderException if no Data Matrix Code can be found
+ * @throws NotFoundException if no Data Matrix Code can be found
*/
- public ResultPoint[] detect() throws ReaderException {
+ public ResultPoint[] detect() throws NotFoundException {
int height = image.getHeight();
int width = image.getWidth();
int halfHeight = height >> 1;
* @param maxWhiteRun maximum run of white pixels that can still be considered to be within
* the barcode
* @return a {@link com.google.zxing.ResultPoint} encapsulating the corner that was found
- * @throws com.google.zxing.ReaderException if such a point cannot be found
+ * @throws NotFoundException if such a point cannot be found
*/
private ResultPoint findCornerFromCenter(int centerX, int deltaX, int left, int right,
- int centerY, int deltaY, int top, int bottom, int maxWhiteRun) throws ReaderException {
+ int centerY, int deltaY, int top, int bottom, int maxWhiteRun) throws NotFoundException {
int[] lastRange = null;
for (int y = centerY, x = centerX;
y < bottom && y >= top && x < right && x >= left;
}
if (range == null) {
if (lastRange == null) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// lastRange was found
if (deltaX == 0) {
}
lastRange = range;
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
/**
package com.google.zxing.datamatrix;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.DecodeHintType;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.DecodeHintType;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
-import com.google.zxing.ReaderException;
import com.google.zxing.Result;
-import com.google.zxing.ResultPoint;
import com.google.zxing.ResultMetadataType;
+import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
* Locates and decodes a Data Matrix code in an image.
*
* @return a String representing the content encoded by the Data Matrix code
- * @throws ReaderException if a Data Matrix code cannot be found, or cannot be decoded
+ * @throws NotFoundException if a Data Matrix code cannot be found
+ * @throws FormatException if a Data Matrix code cannot be decoded
+ * @throws ChecksumException if error correction fails
*/
- public Result decode(BinaryBitmap image) throws ReaderException {
+ public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
return decode(image, null);
}
public Result decode(BinaryBitmap image, Hashtable hints)
- throws ReaderException {
+ throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
ResultPoint[] points;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
* around it. This is a specialized method that works exceptionally fast in this special
* case.
*/
- private static BitMatrix extractPureBits(BitMatrix image) throws ReaderException {
+ private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
// Now need to determine module size in pixels
int height = image.getHeight();
borderWidth++;
}
if (borderWidth == minDimension) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// And then keep tracking across the top-left black module to determine module size
moduleEnd++;
}
if (moduleEnd == width) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int moduleSize = moduleEnd - borderWidth;
columnEndOfSymbol--;
}
if (columnEndOfSymbol < 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
columnEndOfSymbol++;
// Make sure width of barcode is a multiple of module size
if ((columnEndOfSymbol - borderWidth) % moduleSize != 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int dimension = (columnEndOfSymbol - borderWidth) / moduleSize;
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
if (sampleDimension >= width || sampleDimension >= height) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// Now just read off the bits
\r
package com.google.zxing.datamatrix.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.common.BitMatrix;\r
\r
/**\r
\r
/**\r
* @param bitMatrix {@link BitMatrix} to parse\r
- * @throws ReaderException if dimension is < 10 or > 144 or not 0 mod 2\r
+ * @throws FormatException if dimension is < 10 or > 144 or not 0 mod 2\r
*/\r
- BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {\r
+ BitMatrixParser(BitMatrix bitMatrix) throws FormatException {\r
int dimension = bitMatrix.getDimension();\r
if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
version = readVersion(bitMatrix);\r
* \r
* @param bitMatrix Original {@link BitMatrix} including alignment patterns\r
* @return {@link Version} encapsulating the Data Matrix Code's "version"\r
- * @throws ReaderException if the dimensions of the mapping matrix are not valid\r
+ * @throws FormatException if the dimensions of the mapping matrix are not valid\r
* Data Matrix dimensions.\r
*/\r
- Version readVersion(BitMatrix bitMatrix) throws ReaderException {\r
+ Version readVersion(BitMatrix bitMatrix) throws FormatException {\r
\r
if (version != null) {\r
return version;\r
* Data Matrix Code.</p>\r
*\r
* @return bytes encoded within the Data Matrix Code\r
- * @throws ReaderException if the exact number of bytes expected is not read\r
+ * @throws FormatException if the exact number of bytes expected is not read\r
*/\r
- byte[] readCodewords() throws ReaderException {\r
+ byte[] readCodewords() throws FormatException {\r
\r
byte[] result = new byte[version.getTotalCodewords()];\r
int resultOffset = 0;\r
} while ((row < numRows) || (column < numColumns));\r
\r
if (resultOffset != version.getTotalCodewords()) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
return result;\r
}\r
package com.google.zxing.datamatrix.decoder;
-import com.google.zxing.ReaderException;
+import com.google.zxing.FormatException;
import com.google.zxing.common.BitSource;
import com.google.zxing.common.DecoderResult;
-import java.util.Vector;
import java.io.UnsupportedEncodingException;
+import java.util.Vector;
/**
* <p>Data Matrix Codes can encode text as bits in one of several modes, and can use multiple modes
private DecodedBitStreamParser() {
}
- static DecoderResult decode(byte[] bytes) throws ReaderException {
+ static DecoderResult decode(byte[] bytes) throws FormatException {
BitSource bits = new BitSource(bytes);
StringBuffer result = new StringBuffer(100);
StringBuffer resultTrailer = new StringBuffer(0);
decodeBase256Segment(bits, result, byteSegments);
break;
default:
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
mode = ASCII_ENCODE;
}
* See ISO 16022:2006, 5.2.3 and Annex C, Table C.2
*/
private static int decodeAsciiSegment(BitSource bits, StringBuffer result, StringBuffer resultTrailer)
- throws ReaderException {
+ throws FormatException {
boolean upperShift = false;
do {
int oneByte = bits.readBits(8);
if (oneByte == 0) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
} else if (oneByte <= 128) { // ASCII data (ASCII value + 1)
oneByte = upperShift ? (oneByte + 128) : oneByte;
upperShift = false;
//throw ReaderException.getInstance();
// Ignore this symbol for now
} else if (oneByte >= 242) { // Not to be used in ASCII encodation
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
} while (bits.available() > 0);
return ASCII_ENCODE;
/**
* See ISO 16022:2006, 5.2.5 and Annex C, Table C.1
*/
- private static void decodeC40Segment(BitSource bits, StringBuffer result) throws ReaderException {
+ private static void decodeC40Segment(BitSource bits, StringBuffer result) throws FormatException {
// Three C40 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
// TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time
result.append(C40_SHIFT2_SET_CHARS[cValue]);
}
} else if (cValue == 27) { // FNC1
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
} else if (cValue == 30) { // Upper Shift
upperShift = true;
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
shift = 0;
break;
shift = 0;
break;
default:
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
} while (bits.available() > 0);
/**
* See ISO 16022:2006, 5.2.6 and Annex C, Table C.2
*/
- private static void decodeTextSegment(BitSource bits, StringBuffer result) throws ReaderException {
+ private static void decodeTextSegment(BitSource bits, StringBuffer result) throws FormatException {
// Three Text values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
// TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time
result.append(C40_SHIFT2_SET_CHARS[cValue]);
}
} else if (cValue == 27) { // FNC1
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
} else if (cValue == 30) { // Upper Shift
upperShift = true;
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
shift = 0;
break;
shift = 0;
break;
default:
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
} while (bits.available() > 0);
/**
* See ISO 16022:2006, 5.2.7
*/
- private static void decodeAnsiX12Segment(BitSource bits, StringBuffer result) throws ReaderException {
+ private static void decodeAnsiX12Segment(BitSource bits, StringBuffer result) throws FormatException {
// Three ANSI X12 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
} else if (cValue < 40) { // A - Z
result.append((char) (cValue + 51));
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
} while (bits.available() > 0);
\r
package com.google.zxing.datamatrix.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.common.BitMatrix;\r
import com.google.zxing.common.DecoderResult;\r
import com.google.zxing.common.reedsolomon.GF256;\r
*\r
* @param image booleans representing white/black Data Matrix Code modules\r
* @return text and bytes encoded within the Data Matrix Code\r
- * @throws ReaderException if the Data Matrix Code cannot be decoded\r
+ * @throws FormatException if the Data Matrix Code cannot be decoded\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+ public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException {\r
int dimension = image.length;\r
BitMatrix bits = new BitMatrix(dimension);\r
for (int i = 0; i < dimension; i++) {\r
*\r
* @param bits booleans representing white/black Data Matrix Code modules\r
* @return text and bytes encoded within the Data Matrix Code\r
- * @throws ReaderException if the Data Matrix Code cannot be decoded\r
+ * @throws FormatException if the Data Matrix Code cannot be decoded\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+ public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException {\r
\r
// Construct a parser and read version, error-correction level\r
BitMatrixParser parser = new BitMatrixParser(bits);\r
*\r
* @param codewordBytes data and error correction codewords\r
* @param numDataCodewords number of codewords that are data bytes\r
- * @throws ReaderException if error correction fails\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException {\r
+ private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {\r
int numCodewords = codewordBytes.length;\r
// First read into an array of ints\r
int[] codewordsInts = new int[numCodewords];\r
try {\r
rsDecoder.decode(codewordsInts, numECCodewords);\r
} catch (ReedSolomonException rse) {\r
- throw ReaderException.getInstance();\r
+ throw ChecksumException.getChecksumInstance();\r
}\r
// Copy back into array of bytes -- only need to worry about the bytes that were data\r
// We don't care about errors in the error-correction codewords\r
\r
package com.google.zxing.datamatrix.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
\r
/**\r
* The Version object encapsulates attributes about a particular\r
* @param numRows Number of rows in modules\r
* @param numColumns Number of columns in modules\r
* @return {@link Version} for a Data Matrix Code of those dimensions\r
- * @throws ReaderException if dimensions do correspond to a valid Data Matrix size\r
+ * @throws FormatException if dimensions do correspond to a valid Data Matrix size\r
*/\r
- public static Version getVersionForDimensions(int numRows, int numColumns) throws ReaderException {\r
+ public static Version getVersionForDimensions(int numRows, int numColumns) throws FormatException {\r
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
// TODO(bbrown): This is doing a linear search through the array of versions.\r
}\r
}\r
\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
/**\r
package com.google.zxing.datamatrix.detector;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.Collections;
* <p>Detects a Data Matrix Code in an image.</p>
*
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
- * @throws ReaderException if no Data Matrix Code can be found
+ * @throws NotFoundException if no Data Matrix Code can be found
*/
- public DetectorResult detect() throws ReaderException {
+ public DetectorResult detect() throws NotFoundException {
ResultPoint[] cornerPoints = rectangleDetector.detect();
ResultPoint pointA = cornerPoints[0];
}
if (maybeTopLeft == null || bottomLeft == null || maybeBottomRight == null) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// Bottom left is correct but top left and bottom right might be switched
ResultPoint topLeft,
ResultPoint bottomLeft,
ResultPoint bottomRight,
- int dimension) throws ReaderException {
+ int dimension) throws NotFoundException {
// We make up the top right point for now, based on the others.
// TODO: we actually found a fourth corner above and figured out which of two modules
package com.google.zxing.multi;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
-import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import java.util.Hashtable;
this.delegate = delegate;
}
- public Result decode(BinaryBitmap image) throws ReaderException {
+ public Result decode(BinaryBitmap image)
+ throws NotFoundException, ChecksumException, FormatException {
return decode(image, null);
}
- public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
+ public Result decode(BinaryBitmap image, Hashtable hints)
+ throws NotFoundException, ChecksumException, FormatException {
int width = image.getWidth();
int height = image.getHeight();
BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight);
try {
return delegate.decode(topLeft, hints);
- } catch (ReaderException re) {
+ } catch (NotFoundException re) {
// continue
}
BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight);
try {
return delegate.decode(topRight, hints);
- } catch (ReaderException re) {
+ } catch (NotFoundException re) {
// continue
}
BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight);
try {
return delegate.decode(bottomLeft, hints);
- } catch (ReaderException re) {
+ } catch (NotFoundException re) {
// continue
}
BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight);
try {
return delegate.decode(bottomRight, hints);
- } catch (ReaderException re) {
+ } catch (NotFoundException re) {
// continue
}
package com.google.zxing.multi;
-import com.google.zxing.Reader;
-import com.google.zxing.Result;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.NotFoundException;
+import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
+import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import java.util.Hashtable;
this.delegate = delegate;
}
- public Result[] decodeMultiple(BinaryBitmap image) throws ReaderException {
+ public Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException {
return decodeMultiple(image, null);
}
public Result[] decodeMultiple(BinaryBitmap image, Hashtable hints)
- throws ReaderException {
+ throws NotFoundException {
Vector results = new Vector();
doDecodeMultiple(image, hints, results, 0, 0);
if (results.isEmpty()) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int numResults = results.size();
Result[] resultArray = new Result[numResults];
package com.google.zxing.multi;
-import com.google.zxing.Result;
import com.google.zxing.BinaryBitmap;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
+import com.google.zxing.Result;
import java.util.Hashtable;
*/
public interface MultipleBarcodeReader {
- Result[] decodeMultiple(BinaryBitmap image) throws ReaderException;
+ Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException;
- Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws ReaderException;
+ Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws NotFoundException;
}
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
private static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
- public Result[] decodeMultiple(BinaryBitmap image) throws ReaderException {
+ public Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException {
return decodeMultiple(image, null);
}
- public Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws ReaderException {
+ public Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws NotFoundException {
Vector results = new Vector();
DetectorResult[] detectorResult = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
for (int i = 0; i < detectorResult.length; i++) {
package com.google.zxing.multi.qrcode.detector;
-import com.google.zxing.ReaderException;
-import com.google.zxing.common.DetectorResult;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.DetectorResult;
import com.google.zxing.qrcode.detector.Detector;
import com.google.zxing.qrcode.detector.FinderPatternInfo;
super(image);
}
- public DetectorResult[] detectMulti(Hashtable hints) throws ReaderException {
+ public DetectorResult[] detectMulti(Hashtable hints) throws NotFoundException {
BitMatrix image = getImage();
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image);
FinderPatternInfo[] info = finder.findMulti(hints);
if (info == null || info.length == 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
Vector result = new Vector();
for (int i = 0; i < info.length; i++) {
try {
result.addElement(processFinderPatternInfo(info[i]));
- } catch (ReaderException e) {
+ } catch (FormatException e) {
// ignore
}
}
package com.google.zxing.multi.qrcode.detector;\r
\r
import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.ResultPoint;\r
import com.google.zxing.ResultPointCallback;\r
+import com.google.zxing.common.BitMatrix;\r
import com.google.zxing.common.Collections;\r
import com.google.zxing.common.Comparator;\r
-import com.google.zxing.common.BitMatrix;\r
import com.google.zxing.qrcode.detector.FinderPattern;\r
import com.google.zxing.qrcode.detector.FinderPatternFinder;\r
import com.google.zxing.qrcode.detector.FinderPatternInfo;\r
* @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are\r
* those that have been detected at least {@link #CENTER_QUORUM} times, and whose module\r
* size differs from the average among those patterns the least\r
- * @throws ReaderException if 3 such finder patterns do not exist\r
+ * @throws NotFoundException if 3 such finder patterns do not exist\r
*/\r
- private FinderPattern[][] selectBestPatterns() throws ReaderException {\r
+ private FinderPattern[][] selectBestPatterns() throws NotFoundException {\r
Vector possibleCenters = getPossibleCenters();\r
int size = possibleCenters.size();\r
\r
if (size < 3) {\r
// Couldn't find enough finder patterns\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
/*\r
}\r
\r
// Nothing found!\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
- public FinderPatternInfo[] findMulti(Hashtable hints) throws ReaderException {\r
+ public FinderPatternInfo[] findMulti(Hashtable hints) throws NotFoundException {\r
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);\r
BitMatrix image = getImage();\r
int maxI = image.getHeight();\r
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.ReaderException;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitArray;
private static final int CODE_START_C = 105;
private static final int CODE_STOP = 106;
- private static int[] findStartPattern(BitArray row) throws ReaderException {
+ private static int[] findStartPattern(BitArray row) throws NotFoundException {
int width = row.getSize();
int rowOffset = 0;
while (rowOffset < width) {
isWhite = !isWhite;
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
- private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws ReaderException {
+ private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws NotFoundException {
recordPattern(row, rowOffset, counters);
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
int bestMatch = -1;
if (bestMatch >= 0) {
return bestMatch;
} else {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
}
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints)
+ throws NotFoundException, FormatException, ChecksumException {
int[] startPatternInfo = findStartPattern(row);
int startCode = startPatternInfo[2];
codeSet = CODE_CODE_C;
break;
default:
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
boolean done = false;
case CODE_START_A:
case CODE_START_B:
case CODE_START_C:
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
switch (codeSet) {
}
if (!row.isRange(nextStart, Math.min(width, nextStart + (nextStart - lastStart) / 2),
false)) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// Pull out from sum the value of the penultimate check code
checksumTotal -= multiplier * lastCode;
// lastCode is the checksum then:
if (checksumTotal % 103 != lastCode) {
- throw ReaderException.getInstance();
+ throw ChecksumException.getChecksumInstance();
}
// Need to pull out the check digits from string
if (resultString.length() == 0) {
// Almost surely a false positive
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.ReaderException;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitArray;
this.extendedMode = extendedMode;
}
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints)
+ throws NotFoundException, ChecksumException, FormatException {
int[] start = findAsteriskPattern(row);
int nextStart = start[1];
recordPattern(row, nextStart, counters);
int pattern = toNarrowWidePattern(counters);
if (pattern < 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
decodedChar = patternToChar(pattern);
result.append(decodedChar);
// 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)
if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
if (usingCheckDigit) {
total += ALPHABET_STRING.indexOf(result.charAt(i));
}
if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) {
- throw ReaderException.getInstance();
+ throw ChecksumException.getChecksumInstance();
}
result.deleteCharAt(max);
}
if (resultString.length() == 0) {
// Almost surely a false positive
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
float left = (float) (start[1] + start[0]) / 2.0f;
}
- private static int[] findAsteriskPattern(BitArray row) throws ReaderException {
+ private static int[] findAsteriskPattern(BitArray row) throws NotFoundException {
int width = row.getSize();
int rowOffset = 0;
while (rowOffset < width) {
isWhite = !isWhite;
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// For efficiency, returns -1 on failure. Not throwing here saved as many as 700 exceptions
return -1;
}
- private static char patternToChar(int pattern) throws ReaderException {
+ private static char patternToChar(int pattern) throws NotFoundException {
for (int i = 0; i < CHARACTER_ENCODINGS.length; i++) {
if (CHARACTER_ENCODINGS[i] == pattern) {
return ALPHABET[i];
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
- private static String decodeExtended(String encoded) throws ReaderException {
+ private static String decodeExtended(String encoded) throws FormatException {
int length = encoded.length();
StringBuffer decoded = new StringBuffer(length);
for (int i = 0; i < length; i++) {
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next + 32);
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
break;
case '$':
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next - 64);
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
break;
case '%':
} else if (next >= 'F' && next <= 'W') {
decodedChar = (char) (next - 11);
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
break;
case '/':
} else if (next == 'Z') {
decodedChar = ':';
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
break;
}
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.common.BitArray;
/**
}
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString)
- throws ReaderException {
+ throws NotFoundException {
int[] counters = decodeMiddleCounters;
counters[0] = 0;
counters[1] = 0;
* @param resultString string to insert decoded first digit into
* @param lgPatternFound int whose bits indicates the pattern of odd/even L/G patterns used to
* encode digits
- * @throws ReaderException if first digit cannot be determined
+ * @throws NotFoundException if first digit cannot be determined
*/
private static void determineFirstDigit(StringBuffer resultString, int lgPatternFound)
- throws ReaderException {
+ throws NotFoundException {
for (int d = 0; d < 10; d++) {
if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
resultString.insert(0, (char) ('0' + d));
return;
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
}
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.common.BitArray;
/**
}
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result)
- throws ReaderException {
+ throws NotFoundException {
int[] counters = decodeMiddleCounters;
counters[0] = 0;
counters[1] = 0;
\r
import com.google.zxing.BarcodeFormat;\r
import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.Result;\r
import com.google.zxing.ResultPoint;\r
import com.google.zxing.common.BitArray;\r
{N, W, N, W, N} // 9\r
};\r
\r
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {\r
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws FormatException, NotFoundException {\r
\r
// Find out where the Middle section (payload) starts & ends\r
int[] startRange = decodeStart(row);\r
\r
}\r
if (!lengthOK) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
return new Result(\r
* @param row row of black/white values to search\r
* @param payloadStart offset of start pattern\r
* @param resultString {@link StringBuffer} to append decoded chars to\r
- * @throws ReaderException if decoding could not complete successfully\r
+ * @throws NotFoundException if decoding could not complete successfully\r
*/\r
private static void decodeMiddle(BitArray row, int payloadStart, int payloadEnd,\r
- StringBuffer resultString) throws ReaderException {\r
+ StringBuffer resultString) throws NotFoundException {\r
\r
// Digits are interleaved in pairs - 5 black lines for one digit, and the\r
// 5\r
* @param row row of black/white values to search\r
* @return Array, containing index of start of 'start block' and end of\r
* 'start block'\r
- * @throws ReaderException\r
+ * @throws NotFoundException\r
*/\r
- int[] decodeStart(BitArray row) throws ReaderException {\r
+ int[] decodeStart(BitArray row) throws NotFoundException {\r
int endStart = skipWhiteSpace(row);\r
int[] startPattern = findGuardPattern(row, endStart, START_PATTERN);\r
\r
*\r
* @param row bit array representing the scanned barcode.\r
* @param startPattern index into row of the start or end pattern.\r
- * @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown.\r
+ * @throws NotFoundException if the quiet zone cannot be found, a ReaderException is thrown.\r
*/\r
- private void validateQuietZone(BitArray row, int startPattern) throws ReaderException {\r
+ private void validateQuietZone(BitArray row, int startPattern) throws NotFoundException {\r
\r
int quietCount = this.narrowLineWidth * 10; // expect to find this many pixels of quiet zone\r
\r
}\r
if (quietCount != 0) {\r
// Unable to find the necessary number of quiet zone pixels.\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
}\r
\r
*\r
* @param row row of black/white values to search\r
* @return index of the first black line.\r
- * @throws ReaderException Throws exception if no black lines are found in the row\r
+ * @throws NotFoundException Throws exception if no black lines are found in the row\r
*/\r
- private static int skipWhiteSpace(BitArray row) throws ReaderException {\r
+ private static int skipWhiteSpace(BitArray row) throws NotFoundException {\r
int width = row.getSize();\r
int endStart = 0;\r
while (endStart < width) {\r
endStart++;\r
}\r
if (endStart == width) {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
return endStart;\r
* @param row row of black/white values to search\r
* @return Array, containing index of start of 'end block' and end of 'end\r
* block'\r
- * @throws ReaderException\r
+ * @throws NotFoundException\r
*/\r
\r
- int[] decodeEnd(BitArray row) throws ReaderException {\r
+ int[] decodeEnd(BitArray row) throws NotFoundException {\r
\r
// For convenience, reverse the row and then\r
// search from 'the start' for the end block\r
* being searched for as a pattern\r
* @return start/end horizontal offset of guard pattern, as an array of two\r
* ints\r
- * @throws ReaderException if pattern is not found\r
+ * @throws NotFoundException if pattern is not found\r
*/\r
- private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException {\r
+ private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws NotFoundException {\r
\r
// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be\r
// merged to a single method.\r
isWhite = !isWhite;\r
}\r
}\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
/**\r
*\r
* @param counters the counts of runs of observed black/white/black/... values\r
* @return The decoded digit\r
- * @throws ReaderException if digit cannot be decoded\r
+ * @throws NotFoundException if digit cannot be decoded\r
*/\r
- private static int decodeDigit(int[] counters) throws ReaderException {\r
+ private static int decodeDigit(int[] counters) throws NotFoundException {\r
\r
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept\r
int bestMatch = -1;\r
if (bestMatch >= 0) {\r
return bestMatch;\r
} else {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
}\r
\r
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.common.BitArray;
-import com.google.zxing.oned.rss.RSS14Reader;
import java.util.Hashtable;
import java.util.Vector;
}
}
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException {
int size = readers.size();
for (int i = 0; i < size; i++) {
OneDReader reader = (OneDReader) readers.elementAt(i);
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
public void reset() {
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
}
}
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException {
// Compute this location once and reuse it on multiple implementations
int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row);
int size = readers.size();
return result;
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
public void reset() {
package com.google.zxing.oned;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
private static final int INTEGER_MATH_SHIFT = 8;
protected static final int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT;
- public Result decode(BinaryBitmap image) throws ReaderException {
+ public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {
return decode(image, null);
}
// Note that we don't try rotation without the try harder flag, even if rotation was supported.
- public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
+ public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, FormatException {
try {
return doDecode(image, hints);
- } catch (ReaderException re) {
+ } catch (NotFoundException nfe) {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
if (tryHarder && image.isRotateSupported()) {
BinaryBitmap rotatedImage = image.rotateCounterClockwise();
}
return result;
} else {
- throw re;
+ throw nfe;
}
}
}
* @param image The image to decode
* @param hints Any hints that were requested
* @return The contents of the decoded barcode
- * @throws ReaderException Any spontaneous errors which occur
+ * @throws NotFoundException Any spontaneous errors which occur
*/
- private Result doDecode(BinaryBitmap image, Hashtable hints) throws ReaderException {
+ private Result doDecode(BinaryBitmap image, Hashtable hints) throws NotFoundException {
int width = image.getWidth();
int height = image.getHeight();
BitArray row = new BitArray(width);
// Estimate black point for this row and load it:
try {
row = image.getBlackRow(rowNumber, row);
- } catch (ReaderException re) {
+ } catch (NotFoundException nfe) {
continue;
}
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
/**
* @param row row to count from
* @param start offset into row to start at
* @param counters array into which to record counts
- * @throws ReaderException if counters cannot be filled entirely from row before running out
+ * @throws NotFoundException if counters cannot be filled entirely from row before running out
* of pixels
*/
- protected static void recordPattern(BitArray row, int start, int[] counters) throws ReaderException {
+ protected static void recordPattern(BitArray row, int start, int[] counters) throws NotFoundException {
int numCounters = counters.length;
for (int i = 0; i < numCounters; i++) {
counters[i] = 0;
}
int end = row.getSize();
if (start >= end) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
boolean isWhite = !row.get(start);
int counterPosition = 0;
// 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.
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
}
protected static void recordPatternInReverse(BitArray row, int start, int[] counters)
- throws ReaderException {
+ throws NotFoundException {
// This could be more efficient I guess
int numTransitionsLeft = counters.length;
boolean last = row.get(start);
}
}
if (numTransitionsLeft >= 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
recordPattern(row, start + 1, counters);
}
* @param row the black/white pixel data of the row
* @param hints decode hints
* @return {@link Result} containing encoded string and start/end of barcode
- * @throws ReaderException if an error occurs or barcode cannot be found
+ * @throws NotFoundException if an error occurs or barcode cannot be found
*/
public abstract Result decodeRow(int rowNumber, BitArray row, Hashtable hints)
- throws ReaderException;
+ throws NotFoundException, ChecksumException, FormatException;
}
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.ReaderException;
-import com.google.zxing.Result;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
+import com.google.zxing.Result;
import com.google.zxing.common.BitArray;
import java.util.Hashtable;
private final UPCEANReader ean13Reader = new EAN13Reader();
public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Hashtable hints)
- throws ReaderException {
+ throws NotFoundException, FormatException, ChecksumException {
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
}
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints)
+ throws NotFoundException, FormatException, ChecksumException {
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, hints));
}
- public Result decode(BinaryBitmap image) throws ReaderException {
+ public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {
return maybeReturnResult(ean13Reader.decode(image));
}
- public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
+ public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, FormatException {
return maybeReturnResult(ean13Reader.decode(image, hints));
}
}
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString)
- throws ReaderException {
+ throws NotFoundException {
return ean13Reader.decodeMiddle(row, startRange, resultString);
}
- private static Result maybeReturnResult(Result result) throws ReaderException {
+ private static Result maybeReturnResult(Result result) throws FormatException {
String text = result.getText();
if (text.charAt(0) == '0') {
return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
package com.google.zxing.oned;
-import com.google.zxing.ReaderException;
-import com.google.zxing.Result;
-import com.google.zxing.ResultPointCallback;
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
+import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
-import com.google.zxing.BarcodeFormat;
+import com.google.zxing.ResultPointCallback;
import com.google.zxing.common.BitArray;
import java.util.Hashtable;
decodeRowStringBuffer = new StringBuffer(20);
}
- static int[] findStartGuardPattern(BitArray row) throws ReaderException {
+ static int[] findStartGuardPattern(BitArray row) throws NotFoundException {
boolean foundStart = false;
int[] startRange = null;
int nextStart = 0;
return startRange;
}
- public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+ public Result decodeRow(int rowNumber, BitArray row, Hashtable hints)
+ throws NotFoundException, ChecksumException, FormatException {
return decodeRow(rowNumber, row, findStartGuardPattern(row), hints);
}
* found. This allows this to be computed once and reused across many implementations.</p>
*/
public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Hashtable hints)
- throws ReaderException {
+ throws NotFoundException, ChecksumException, FormatException {
ResultPointCallback resultPointCallback = hints == null ? null :
(ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
int end = endRange[1];
int quietEnd = end + (end - endRange[0]);
if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
String resultString = result.toString();
if (!checkChecksum(resultString)) {
- throw ReaderException.getInstance();
+ throw ChecksumException.getChecksumInstance();
}
float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
/**
* @return {@link #checkStandardUPCEANChecksum(String)}
*/
- boolean checkChecksum(String s) throws ReaderException {
+ boolean checkChecksum(String s) throws ChecksumException, FormatException {
return checkStandardUPCEANChecksum(s);
}
*
* @param s string of digits to check
* @return true iff string of digits passes the UPC/EAN checksum algorithm
- * @throws ReaderException if the string does not contain only digits
+ * @throws FormatException if the string does not contain only digits
+ * @throws ChecksumException if checksum mismatches
*/
- private static boolean checkStandardUPCEANChecksum(String s) throws ReaderException {
+ private static boolean checkStandardUPCEANChecksum(String s) throws ChecksumException, FormatException {
int length = s.length();
if (length == 0) {
return false;
for (int i = length - 2; i >= 0; i -= 2) {
int digit = (int) s.charAt(i) - (int) '0';
if (digit < 0 || digit > 9) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
sum += digit;
}
for (int i = length - 1; i >= 0; i -= 2) {
int digit = (int) s.charAt(i) - (int) '0';
if (digit < 0 || digit > 9) {
- throw ReaderException.getInstance();
+ throw ChecksumException.getChecksumInstance();
}
sum += digit;
}
return sum % 10 == 0;
}
- int[] decodeEnd(BitArray row, int endStart) throws ReaderException {
+ int[] decodeEnd(BitArray row, int endStart) throws NotFoundException {
return findGuardPattern(row, endStart, false, START_END_PATTERN);
}
* @param pattern pattern of counts of number of black and white pixels that are being
* searched for as a pattern
* @return start/end horizontal offset of guard pattern, as an array of two ints
- * @throws ReaderException if pattern is not found
+ * @throws NotFoundException if pattern is not found
*/
static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern)
- throws ReaderException {
+ throws NotFoundException {
int patternLength = pattern.length;
int[] counters = new int[patternLength];
int width = row.getSize();
isWhite = !isWhite;
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
/**
* for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should
* be used
* @return horizontal offset of first pixel beyond the decoded digit
- * @throws ReaderException if digit cannot be decoded
+ * @throws NotFoundException if digit cannot be decoded
*/
static int decodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns)
- throws ReaderException {
+ throws NotFoundException {
recordPattern(row, rowOffset, counters);
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
int bestMatch = -1;
if (bestMatch >= 0) {
return bestMatch;
} else {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
}
* @param startRange start/end offset of start guard pattern
* @param resultString {@link StringBuffer} to append decoded chars to
* @return horizontal offset of first pixel after the "middle" that was decoded
- * @throws ReaderException if decoding could not complete successfully
+ * @throws NotFoundException if decoding could not complete successfully
*/
protected abstract int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString)
- throws ReaderException;
+ throws NotFoundException;
}
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
-import com.google.zxing.ReaderException;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.common.BitArray;
/**
}
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result)
- throws ReaderException {
+ throws NotFoundException {
int[] counters = decodeMiddleCounters;
counters[0] = 0;
counters[1] = 0;
return rowOffset;
}
- protected int[] decodeEnd(BitArray row, int endStart) throws ReaderException {
+ protected int[] decodeEnd(BitArray row, int endStart) throws NotFoundException {
return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN);
}
- protected boolean checkChecksum(String s) throws ReaderException {
+ protected boolean checkChecksum(String s) throws FormatException, ChecksumException {
return super.checkChecksum(convertUPCEtoUPCA(s));
}
private static void determineNumSysAndCheckDigit(StringBuffer resultString, int lgPatternFound)
- throws ReaderException {
+ throws NotFoundException {
for (int numSys = 0; numSys <= 1; numSys++) {
for (int d = 0; d < 10; d++) {
}
}
}
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
BarcodeFormat getBarcodeFormat() {
import com.google.zxing.BarcodeFormat;\r
import com.google.zxing.BinaryBitmap;\r
import com.google.zxing.DecodeHintType;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.Reader;\r
-import com.google.zxing.ReaderException;\r
import com.google.zxing.Result;\r
import com.google.zxing.ResultPoint;\r
import com.google.zxing.common.BitMatrix;\r
* Locates and decodes a PDF417 code in an image.\r
*\r
* @return a String representing the content encoded by the PDF417 code\r
- * @throws ReaderException if a PDF417 code cannot be found, or cannot be decoded\r
+ * @throws NotFoundException if a PDF417 code cannot be found,\r
+ * @throws FormatException if a PDF417 cannot be decoded\r
*/\r
- public Result decode(BinaryBitmap image) throws ReaderException {\r
+ public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {\r
return decode(image, null);\r
}\r
\r
public Result decode(BinaryBitmap image, Hashtable hints)\r
- throws ReaderException {\r
+ throws NotFoundException, FormatException {\r
DecoderResult decoderResult;\r
ResultPoint[] points;\r
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {\r
* around it. This is a specialized method that works exceptionally fast in this special\r
* case.\r
*/\r
- private static BitMatrix extractPureBits(BinaryBitmap image) throws ReaderException {\r
+ private static BitMatrix extractPureBits(BinaryBitmap image) throws NotFoundException {\r
// Now need to determine module size in pixels\r
BitMatrix matrix = image.getBlackMatrix();\r
int height = matrix.getHeight();\r
borderWidth++;\r
}\r
if (borderWidth == minDimension) {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
// And then keep tracking across the top-left black module to determine module size\r
moduleEnd++;\r
}\r
if (moduleEnd == minDimension) {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
int moduleSize = moduleEnd - borderWidth;\r
rowEndOfSymbol--;\r
}\r
if (rowEndOfSymbol < 0) {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
rowEndOfSymbol++;\r
\r
// Make sure width of barcode is a multiple of module size\r
if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;\r
\r
\r
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;\r
if (sampleDimension >= width || sampleDimension >= height) {\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
// Now just read off the bits\r
\r
package com.google.zxing.pdf417.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.common.BitMatrix;\r
\r
/**\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
+ * @throws NotFoundException\r
*/\r
/*\r
int processRow1(int[] rowCounters, int rowNumber, int rowHeight,\r
\r
package com.google.zxing.pdf417.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.common.DecoderResult;\r
\r
/**\r
private DecodedBitStreamParser() {\r
}\r
\r
- static DecoderResult decode(int[] codewords) throws ReaderException {\r
+ static DecoderResult decode(int[] codewords) throws FormatException {\r
StringBuffer result = new StringBuffer(100);\r
// Get compaction mode\r
int codeIndex = 1;\r
if (codeIndex < codewords.length) {\r
code = codewords[codeIndex++];\r
} else {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
}\r
return new DecoderResult(null, result.toString(), null, null);\r
\r
package com.google.zxing.pdf417.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.common.BitMatrix;\r
import com.google.zxing.common.DecoderResult;\r
//import com.google.zxing.pdf417.reedsolomon.ReedSolomonDecoder;\r
*\r
* @param image booleans representing white/black PDF417 modules\r
* @return text and bytes encoded within the PDF417 Code\r
- * @throws ReaderException if the PDF417 Code cannot be decoded\r
+ * @throws NotFoundException if the PDF417 Code cannot be decoded\r
*/\r
- public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+ public DecoderResult decode(boolean[][] image) throws FormatException {\r
int dimension = image.length;\r
BitMatrix bits = new BitMatrix(dimension);\r
for (int i = 0; i < dimension; i++) {\r
*\r
* @param bits booleans representing white/black PDF417 Code modules\r
* @return text and bytes encoded within the PDF417 Code\r
- * @throws ReaderException if the PDF417 Code cannot be decoded\r
+ * @throws FormatException if the PDF417 Code cannot be decoded\r
*/\r
- public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+ public DecoderResult decode(BitMatrix bits) throws FormatException {\r
// Construct a parser to read the data codewords and error-correction level\r
BitMatrixParser parser = new BitMatrixParser(bits);\r
int[] codewords = parser.readCodewords();\r
if (codewords == null || codewords.length == 0) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
int ecLevel = parser.getECLevel();\r
*\r
* @param codewords\r
* @return an index to the first data codeword.\r
- * @throws ReaderException\r
+ * @throws FormatException\r
*/\r
- private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws ReaderException {\r
+ private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws FormatException {\r
if (codewords.length < 4) {\r
// Codeword array size should be at least 4 allowing for\r
// Count CW, At least one Data CW, Error Correction CW, Error Correction CW\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
// The first codeword, the Symbol Length Descriptor, shall always encode the total number of data\r
// codewords in the symbol, including the Symbol Length Descriptor itself, data codewords and pad\r
// codewords, but excluding the number of error correction codewords.\r
int numberOfCodewords = codewords[0];\r
if (numberOfCodewords > codewords.length) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
if (numberOfCodewords == 0) {\r
// Reset to the length of the array - 8 (Allow for at least level 3 Error Correction (8 Error Codewords)\r
if (numECCodewords < codewords.length) {\r
codewords[0] = codewords.length - numECCodewords;\r
} else {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
}\r
}\r
* correct the errors in-place using Reed-Solomon error correction.</p>\r
*\r
* @param codewords data and error correction codewords\r
- * @throws ReaderException if error correction fails\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws ReaderException {\r
+ private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws FormatException {\r
if ((erasures != null && erasures.length > numECCodewords / 2 + MAX_ERRORS) ||\r
(numECCodewords < 0 || numECCodewords > MAX_EC_CODEWORDS)) {\r
// Too many errors or EC Codewords is corrupted\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
// Try to correct the errors\r
+ // TODO enable error correction\r
int result = 0; // rsDecoder.correctErrors(codewords, numECCodewords);\r
if (erasures != null) {\r
int numErasures = erasures.length;\r
}\r
if (numErasures > MAX_ERRORS) {\r
// Still too many errors\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
}\r
return result;\r
package com.google.zxing.pdf417.detector;
import com.google.zxing.BinaryBitmap;
-import com.google.zxing.ReaderException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
* <p>Detects a PDF417 Code in an image, simply.</p>
*
* @return {@link DetectorResult} encapsulating results of detecting a PDF417 Code
- * @throws ReaderException if no QR Code can be found
+ * @throws NotFoundException if no QR Code can be found
*/
- public DetectorResult detect() throws ReaderException {
+ public DetectorResult detect() throws NotFoundException {
return detect(null);
}
*
* @param hints optional hints to detector
* @return {@link DetectorResult} encapsulating results of detecting a PDF417 Code
- * @throws ReaderException if no PDF417 Code can be found
+ * @throws NotFoundException if no PDF417 Code can be found
*/
- public DetectorResult detect(Hashtable hints) throws ReaderException {
+ public DetectorResult detect(Hashtable hints) throws NotFoundException {
// Fetch the 1 bit matrix once up front.
BitMatrix matrix = image.getBlackMatrix();
correctCodeWordVertices(vertices, false);
}
- if (vertices != null) {
- float moduleWidth = computeModuleWidth(vertices);
- if (moduleWidth < 1.0f) {
- throw ReaderException.getInstance();
- }
+ if (vertices == null) {
+ throw NotFoundException.getNotFoundInstance();
+ }
- int dimension = computeDimension(vertices[4], vertices[6],
- vertices[5], vertices[7], moduleWidth);
- if (dimension < 1) {
- throw ReaderException.getInstance();
- }
+ float moduleWidth = computeModuleWidth(vertices);
+ if (moduleWidth < 1.0f) {
+ throw NotFoundException.getNotFoundInstance();
+ }
- // Deskew and sample image.
- BitMatrix bits = sampleGrid(matrix, vertices[4], vertices[5],
- vertices[6], vertices[7], dimension);
- return new DetectorResult(bits, new ResultPoint[]{vertices[4],
- vertices[5], vertices[6], vertices[7]});
- } else {
- throw ReaderException.getInstance();
+ int dimension = computeDimension(vertices[4], vertices[6],
+ vertices[5], vertices[7], moduleWidth);
+ if (dimension < 1) {
+ throw NotFoundException.getNotFoundInstance();
}
+
+ // Deskew and sample image.
+ BitMatrix bits = sampleGrid(matrix, vertices[4], vertices[5],
+ vertices[6], vertices[7], dimension);
+ return new DetectorResult(bits, new ResultPoint[]{vertices[4],
+ vertices[5], vertices[6], vertices[7]});
}
/**
private static BitMatrix sampleGrid(BitMatrix matrix, ResultPoint topLeft,
ResultPoint bottomLeft, ResultPoint topRight, ResultPoint bottomRight, int dimension)
- throws ReaderException {
+ throws NotFoundException {
// Note that unlike the QR Code sampler, we didn't find the center of modules, but the
// very corners. So there is no 0.5f here; 0.0f is right.
package com.google.zxing.qrcode;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
-import com.google.zxing.ReaderException;
import com.google.zxing.Result;
-import com.google.zxing.ResultPoint;
import com.google.zxing.ResultMetadataType;
-import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
* Locates and decodes a QR code in an image.
*
* @return a String representing the content encoded by the QR code
- * @throws ReaderException if a QR code cannot be found, or cannot be decoded
+ * @throws NotFoundException if a QR code cannot be found
+ * @throws FormatException if a QR code cannot be decoded
+ * @throws ChecksumException if error correction fails
*/
- public Result decode(BinaryBitmap image) throws ReaderException {
+ public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
return decode(image, null);
}
public Result decode(BinaryBitmap image, Hashtable hints)
- throws ReaderException {
+ throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
ResultPoint[] points;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
* around it. This is a specialized method that works exceptionally fast in this special
* case.
*/
- private static BitMatrix extractPureBits(BitMatrix image) throws ReaderException {
+ private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
// Now need to determine module size in pixels
int height = image.getHeight();
borderWidth++;
}
if (borderWidth == minDimension) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// And then keep tracking across the top-left black module to determine module size
moduleEnd++;
}
if (moduleEnd == minDimension) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int moduleSize = moduleEnd - borderWidth;
rowEndOfSymbol--;
}
if (rowEndOfSymbol < 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
rowEndOfSymbol++;
// Make sure width of barcode is a multiple of module size
if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
if (sampleDimension >= width || sampleDimension >= height) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
// Now just read off the bits
import com.google.zxing.Writer;
import com.google.zxing.WriterException;
import com.google.zxing.common.ByteMatrix;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.encoder.Encoder;
import com.google.zxing.qrcode.encoder.QRCode;
-import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.util.Hashtable;
\r
package com.google.zxing.qrcode.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.common.BitMatrix;\r
\r
/**\r
\r
/**\r
* @param bitMatrix {@link BitMatrix} to parse\r
- * @throws ReaderException if dimension is not >= 21 and 1 mod 4\r
+ * @throws FormatException if dimension is not >= 21 and 1 mod 4\r
*/\r
- BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {\r
+ BitMatrixParser(BitMatrix bitMatrix) throws FormatException {\r
int dimension = bitMatrix.getDimension();\r
if (dimension < 21 || (dimension & 0x03) != 1) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
this.bitMatrix = bitMatrix;\r
}\r
* <p>Reads format information from one of its two locations within the QR Code.</p>\r
*\r
* @return {@link FormatInformation} encapsulating the QR Code's format info\r
- * @throws ReaderException if both format information locations cannot be parsed as\r
+ * @throws FormatException if both format information locations cannot be parsed as\r
* the valid encoding of format information\r
*/\r
- FormatInformation readFormatInformation() throws ReaderException {\r
+ FormatInformation readFormatInformation() throws FormatException {\r
\r
if (parsedFormatInfo != null) {\r
return parsedFormatInfo;\r
if (parsedFormatInfo != null) {\r
return parsedFormatInfo;\r
}\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
/**\r
* <p>Reads version information from one of its two locations within the QR Code.</p>\r
*\r
* @return {@link Version} encapsulating the QR Code's version\r
- * @throws ReaderException if both version information locations cannot be parsed as\r
+ * @throws FormatException if both version information locations cannot be parsed as\r
* the valid encoding of version information\r
*/\r
- Version readVersion() throws ReaderException {\r
+ Version readVersion() throws FormatException {\r
\r
if (parsedVersion != null) {\r
return parsedVersion;\r
if (parsedVersion != null && parsedVersion.getDimensionForVersion() == dimension) {\r
return parsedVersion;\r
}\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
private int copyBit(int i, int j, int versionBits) {\r
* QR Code.</p>\r
*\r
* @return bytes encoded within the QR Code\r
- * @throws ReaderException if the exact number of bytes expected is not read\r
+ * @throws FormatException if the exact number of bytes expected is not read\r
*/\r
- byte[] readCodewords() throws ReaderException {\r
+ byte[] readCodewords() throws FormatException {\r
\r
FormatInformation formatInfo = readFormatInformation();\r
Version version = readVersion();\r
readingUp ^= true; // readingUp = !readingUp; // switch directions\r
}\r
if (resultOffset != version.getTotalCodewords()) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
return result;\r
}\r
package com.google.zxing.qrcode.decoder;
import com.google.zxing.DecodeHintType;
-import com.google.zxing.ReaderException;
+import com.google.zxing.FormatException;
import com.google.zxing.common.BitSource;
import com.google.zxing.common.CharacterSetECI;
import com.google.zxing.common.DecoderResult;
}
static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Hashtable hints)
- throws ReaderException {
+ throws FormatException {
BitSource bits = new BitSource(bytes);
StringBuffer result = new StringBuffer(50);
CharacterSetECI currentCharacterSetECI = null;
try {
mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
} catch (IllegalArgumentException iae) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
if (!mode.equals(Mode.TERMINATOR)) {
int value = parseECIValue(bits);
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
if (currentCharacterSetECI == null) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
} else {
// How many characters will follow, encoded in this mode?
} else if (mode.equals(Mode.KANJI)) {
decodeKanjiSegment(bits, result, count);
} else {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
}
private static void decodeKanjiSegment(BitSource bits,
StringBuffer result,
- int count) throws ReaderException {
+ int count) throws FormatException {
// Each character will require 2 bytes. Read the characters as 2-byte pairs
// and decode as Shift_JIS afterwards
byte[] buffer = new byte[2 * count];
try {
result.append(new String(buffer, SHIFT_JIS));
} catch (UnsupportedEncodingException uee) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
}
int count,
CharacterSetECI currentCharacterSetECI,
Vector byteSegments,
- Hashtable hints) throws ReaderException {
+ Hashtable hints) throws FormatException {
byte[] readBytes = new byte[count];
if (count << 3 > bits.available()) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
for (int i = 0; i < count; i++) {
readBytes[i] = (byte) bits.readBits(8);
try {
result.append(new String(readBytes, encoding));
} catch (UnsupportedEncodingException uce) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
byteSegments.addElement(readBytes);
}
private static void decodeNumericSegment(BitSource bits,
StringBuffer result,
- int count) throws ReaderException {
+ int count) throws FormatException {
// Read three digits at a time
while (count >= 3) {
// Each 10 bits encodes three digits
int threeDigitsBits = bits.readBits(10);
if (threeDigitsBits >= 1000) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
result.append(ALPHANUMERIC_CHARS[threeDigitsBits / 100]);
result.append(ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]);
// Two digits left over to read, encoded in 7 bits
int twoDigitsBits = bits.readBits(7);
if (twoDigitsBits >= 100) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
result.append(ALPHANUMERIC_CHARS[twoDigitsBits / 10]);
result.append(ALPHANUMERIC_CHARS[twoDigitsBits % 10]);
// One digit left over to read
int digitBits = bits.readBits(4);
if (digitBits >= 10) {
- throw ReaderException.getInstance();
+ throw FormatException.getFormatInstance();
}
result.append(ALPHANUMERIC_CHARS[digitBits]);
}
\r
package com.google.zxing.qrcode.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.common.BitMatrix;\r
import com.google.zxing.common.DecoderResult;\r
import com.google.zxing.common.reedsolomon.GF256;\r
rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r
}\r
\r
- public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+ public DecoderResult decode(boolean[][] image)\r
+ throws ChecksumException, FormatException, NotFoundException {\r
return decode(image, null);\r
}\r
\r
*\r
* @param image booleans representing white/black QR Code modules\r
* @return text and bytes encoded within the QR Code\r
- * @throws ReaderException if the QR Code cannot be decoded\r
+ * @throws NotFoundException if the QR Code cannot be found\r
+ * @throws FormatException if the QR Code cannot be decoded\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- public DecoderResult decode(boolean[][] image, Hashtable hints) throws ReaderException {\r
+ public DecoderResult decode(boolean[][] image, Hashtable hints)\r
+ throws ChecksumException, FormatException, NotFoundException {\r
int dimension = image.length;\r
BitMatrix bits = new BitMatrix(dimension);\r
for (int i = 0; i < dimension; i++) {\r
return decode(bits, hints);\r
}\r
\r
- public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+ public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException, NotFoundException {\r
return decode(bits, null);\r
}\r
\r
*\r
* @param bits booleans representing white/black QR Code modules\r
* @return text and bytes encoded within the QR Code\r
- * @throws ReaderException if the QR Code cannot be decoded\r
+ * @throws NotFoundException if the QR Code cannot be found\r
+ * @throws FormatException if the QR Code cannot be decoded\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- public DecoderResult decode(BitMatrix bits, Hashtable hints) throws ReaderException {\r
+ public DecoderResult decode(BitMatrix bits, Hashtable hints)\r
+ throws NotFoundException, FormatException, ChecksumException {\r
\r
// Construct a parser and read version, error-correction level\r
BitMatrixParser parser = new BitMatrixParser(bits);\r
*\r
* @param codewordBytes data and error correction codewords\r
* @param numDataCodewords number of codewords that are data bytes\r
- * @throws ReaderException if error correction fails\r
+ * @throws ChecksumException if error correction fails\r
*/\r
- private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException {\r
+ private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {\r
int numCodewords = codewordBytes.length;\r
// First read into an array of ints\r
int[] codewordsInts = new int[numCodewords];\r
try {\r
rsDecoder.decode(codewordsInts, numECCodewords);\r
} catch (ReedSolomonException rse) {\r
- throw ReaderException.getInstance();\r
+ throw ChecksumException.getChecksumInstance();\r
}\r
// Copy back into array of bytes -- only need to worry about the bytes that were data\r
// We don't care about errors in the error-correction codewords\r
\r
package com.google.zxing.qrcode.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.common.BitMatrix;\r
\r
/**\r
*\r
* @param dimension dimension in modules\r
* @return {@link Version} for a QR Code of that dimension\r
- * @throws ReaderException if dimension is not 1 mod 4\r
+ * @throws FormatException if dimension is not 1 mod 4\r
*/\r
- public static Version getProvisionalVersionForDimension(int dimension) throws ReaderException {\r
+ public static Version getProvisionalVersionForDimension(int dimension) throws FormatException {\r
if (dimension % 4 != 1) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
try {\r
return getVersionForNumber((dimension - 17) >> 2);\r
} catch (IllegalArgumentException iae) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
}\r
\r
\r
package com.google.zxing.qrcode.detector;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.ResultPoint;\r
import com.google.zxing.ResultPointCallback;\r
import com.google.zxing.common.BitMatrix;\r
* it's pretty performance-critical and so is written to be fast foremost.</p>\r
*\r
* @return {@link AlignmentPattern} if found\r
- * @throws ReaderException if not found\r
+ * @throws NotFoundException if not found\r
*/\r
- AlignmentPattern find() throws ReaderException {\r
+ AlignmentPattern find() throws NotFoundException {\r
int startX = this.startX;\r
int height = this.height;\r
int maxJ = startX + width;\r
return (AlignmentPattern) possibleCenters.elementAt(0);\r
}\r
\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
/**\r
package com.google.zxing.qrcode.detector;
import com.google.zxing.DecodeHintType;
-import com.google.zxing.ReaderException;
+import com.google.zxing.FormatException;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ResultPoint;
import com.google.zxing.ResultPointCallback;
import com.google.zxing.common.BitMatrix;
* <p>Detects a QR Code in an image, simply.</p>
*
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
- * @throws ReaderException if no QR Code can be found
+ * @throws NotFoundException if no QR Code can be found
*/
- public DetectorResult detect() throws ReaderException {
+ public DetectorResult detect() throws NotFoundException, FormatException {
return detect(null);
}
* <p>Detects a QR Code in an image, simply.</p>
*
* @param hints optional hints to detector
- * @return {@link DetectorResult} encapsulating results of detecting a QR Code
- * @throws ReaderException if no QR Code can be found
+ * @return {@link NotFoundException} encapsulating results of detecting a QR Code
+ * @throws NotFoundException if QR Code cannot be found
+ * @throws FormatException if a QR Code cannot be decoded
*/
- public DetectorResult detect(Hashtable hints) throws ReaderException {
+ public DetectorResult detect(Hashtable hints) throws NotFoundException, FormatException {
resultPointCallback = hints == null ? null :
(ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
return processFinderPatternInfo(info);
}
- protected DetectorResult processFinderPatternInfo(FinderPatternInfo info) throws ReaderException {
+ protected DetectorResult processFinderPatternInfo(FinderPatternInfo info)
+ throws NotFoundException, FormatException {
FinderPattern topLeft = info.getTopLeft();
FinderPattern topRight = info.getTopRight();
float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
if (moduleSize < 1.0f) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
estAlignmentY,
(float) i);
break;
- } catch (ReaderException re) {
+ } catch (NotFoundException re) {
// try next round
}
}
private static BitMatrix sampleGrid(BitMatrix image,
PerspectiveTransform transform,
- int dimension) throws ReaderException {
+ int dimension) throws NotFoundException {
GridSampler sampler = GridSampler.getInstance();
return sampler.sampleGrid(image, dimension, transform);
protected static int computeDimension(ResultPoint topLeft,
ResultPoint topRight,
ResultPoint bottomLeft,
- float moduleSize) throws ReaderException {
+ float moduleSize) throws NotFoundException {
int tltrCentersDimension = round(ResultPoint.distance(topLeft, topRight) / moduleSize);
int tlblCentersDimension = round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize);
int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;
dimension--;
break;
case 3:
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
return dimension;
}
* @param estAlignmentY y coordinate of above
* @param allowanceFactor number of pixels in all directions to search from the center
* @return {@link AlignmentPattern} if found, or null otherwise
- * @throws ReaderException if an unexpected error occurs during detection
+ * @throws NotFoundException if an unexpected error occurs during detection
*/
protected AlignmentPattern findAlignmentInRegion(float overallEstModuleSize,
int estAlignmentX,
int estAlignmentY,
float allowanceFactor)
- throws ReaderException {
+ throws NotFoundException {
// Look for an alignment pattern (3 modules in size) around where it
// should be
int allowance = (int) (allowanceFactor * overallEstModuleSize);
int alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);
int alignmentAreaRightX = Math.min(image.getWidth() - 1, estAlignmentX + allowance);
if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {
- throw ReaderException.getInstance();
+ throw NotFoundException.getNotFoundInstance();
}
int alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);
package com.google.zxing.qrcode.detector;\r
\r
import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
import com.google.zxing.ResultPoint;\r
import com.google.zxing.ResultPointCallback;\r
+import com.google.zxing.common.BitMatrix;\r
import com.google.zxing.common.Collections;\r
import com.google.zxing.common.Comparator;\r
-import com.google.zxing.common.BitMatrix;\r
\r
import java.util.Hashtable;\r
import java.util.Vector;\r
return possibleCenters;\r
}\r
\r
- FinderPatternInfo find(Hashtable hints) throws ReaderException {\r
+ FinderPatternInfo find(Hashtable hints) throws NotFoundException {\r
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);\r
int maxI = image.getHeight();\r
int maxJ = image.getWidth();\r
* @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are\r
* those that have been detected at least {@link #CENTER_QUORUM} times, and whose module\r
* size differs from the average among those patterns the least\r
- * @throws ReaderException if 3 such finder patterns do not exist\r
+ * @throws NotFoundException if 3 such finder patterns do not exist\r
*/\r
- private FinderPattern[] selectBestPatterns() throws ReaderException {\r
+ private FinderPattern[] selectBestPatterns() throws NotFoundException {\r
\r
int startSize = possibleCenters.size();\r
if (startSize < 3) {\r
// Couldn't find enough finder patterns\r
- throw ReaderException.getInstance();\r
+ throw NotFoundException.getNotFoundInstance();\r
}\r
\r
// Filter outlier possibilities whose module size is too different\r
package com.google.zxing.qrcode.encoder;
-import com.google.zxing.WriterException;
import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
import com.google.zxing.common.ByteArray;
import com.google.zxing.common.ByteMatrix;
import com.google.zxing.common.CharacterSetECI;
import com.google.zxing.qrcode.decoder.Mode;
import com.google.zxing.qrcode.decoder.Version;
-import java.util.Vector;
-import java.util.Hashtable;
import java.io.UnsupportedEncodingException;
+import java.util.Hashtable;
+import java.util.Vector;
/**
* @author satorux@google.com (Satoru Takabayashi) - creator
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
import java.util.Arrays;
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link CalendarParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link EmailAddressParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link com.google.zxing.client.result.GeoParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link ISBNParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link ProductParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link SMSParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link TelParsedResult}.
package com.google.zxing.client.result;
-import junit.framework.TestCase;
-import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.Result;
+import junit.framework.TestCase;
/**
* Tests {@link URIParsedResult}.
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
-
import junit.framework.TestCase;
+import javax.imageio.ImageIO;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.util.Hashtable;
import java.util.List;
-import javax.imageio.ImageIO;
-
/**
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
+import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import javax.imageio.ImageIO;
-
/**
* This abstract class looks for negative results, i.e. it only allows a certain number of false
* positives in images which should not decode. This helps ensure that we are not too lenient.
import junit.framework.TestCase;
-import com.google.zxing.ReaderException;
-
/**
* @author bbrown@google.com (Brian Brown)
*/
public final class DecodedBitStreamParserTestCase extends TestCase{
- public void testAsciiStandardDecode() throws ReaderException {
+ public void testAsciiStandardDecode() throws Exception {
// ASCII characters 0-127 are encoded as the value + 1
byte[] bytes = {(byte) ('a' + 1), (byte) ('b' + 1), (byte) ('c' + 1),
(byte) ('A' + 1), (byte) ('B' + 1), (byte) ('C' + 1)};
assertEquals("abcABC", decodedString);
}
- public void testAsciiDoubleDigitDecode() throws ReaderException{
+ public void testAsciiDoubleDigitDecode() throws Exception{
// ASCII double digit (00 - 99) Numeric Value + 130
byte[] bytes = {(byte) 130 , (byte) ( 1 + 130),
(byte) (98 + 130), (byte) (99 + 130)};
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.common.AbstractBlackBoxTestCase;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
* @author Sean Owen
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
-import java.io.File;
-
/**
* @author dswitkin@google.com (Daniel Switkin)
*/
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.oned;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.qrcode;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.qrcode;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.qrcode;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.qrcode;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.qrcode;
-import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
package com.google.zxing.qrcode.decoder;
-import com.google.zxing.ReaderException;
import com.google.zxing.common.BitSourceBuilder;
import junit.framework.TestCase;
*/
public final class DecodedBitStreamParserTestCase extends TestCase {
- public void testSimpleByteMode() throws ReaderException {
+ public void testSimpleByteMode() throws Exception {
BitSourceBuilder builder = new BitSourceBuilder();
builder.write(0x04, 4); // Byte mode
builder.write(0x03, 8); // 3 bytes
assertEquals("\u00f1\u00f2\u00f3", result);
}
- public void testSimpleSJIS() throws ReaderException {
+ public void testSimpleSJIS() throws Exception {
BitSourceBuilder builder = new BitSourceBuilder();
builder.write(0x04, 4); // Byte mode
builder.write(0x03, 8); // 3 bytes
assertEquals("\uff61\uff62\uff63", result);
}
- public void testECI() throws ReaderException {
+ public void testECI() throws Exception {
BitSourceBuilder builder = new BitSourceBuilder();
builder.write(0x07, 4); // ECI mode
builder.write(0x02, 8); // ECI 2 = CP437 encoding
package com.google.zxing.qrcode.decoder;
-import com.google.zxing.ReaderException;
import junit.framework.TestCase;
/**
assertNotNull(version.buildFunctionPattern());
}
- public void testGetProvisionalVersionForDimension() throws ReaderException {
+ public void testGetProvisionalVersionForDimension() throws Exception {
for (int i = 1; i <= 40; i++) {
assertEquals(i, Version.getProvisionalVersionForDimension(4*i + 17).getVersionNumber());
}
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedResult;
", type: " + parsedResult.getType() + "):\nRaw result:\n" + result.getText() +
"\nParsed result:\n" + parsedResult.getDisplayResult());
return result;
- } catch (ReaderException e) {
+ } catch (NotFoundException nfe) {
System.out.println(uri.toString() + ": No barcode found");
return null;
} finally {
for (int y = 0; y < height; y++) {
try {
row = bitmap.getBlackRow(y, row);
- } catch (ReaderException e) {
+ } catch (NotFoundException nfe) {
// If fetching the row failed, draw a red line and keep going.
int offset = y * stride + width;
for (int x = 0; x < width; x++) {
}
}
}
- } catch (ReaderException e) {
+ } catch (NotFoundException nfe) {
}
// Write the result
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
+import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.common.BitArray;
import com.google.zxing.common.BitMatrix;
for (int y = 0; y < height; y++) {
try {
array = bitmap.getBlackRow(y, array);
- } catch (ReaderException e) {
+ } catch (NotFoundException nfe) {
// Draw rows with insufficient dynamic range in red
for (int x = 0; x < width; x++) {
result.setRGB(x, y, RED);
result.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
}
}
- } catch (ReaderException e) {
+ } catch (NotFoundException nfe) {
}
}
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
+import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
+import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
*/
public final class DecodeServlet extends HttpServlet {
- private static final long MAX_IMAGE_SIZE = 500000L;
+ private static final long MAX_IMAGE_SIZE = 2000000L;
private static final Logger log = Logger.getLogger(DecodeServlet.class.getName());
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = reader.decode(bitmap, HINTS);
- } catch (ReaderException re2) {
- log.info("DECODE FAILED: " + re.toString());
+ } catch (NotFoundException nfe) {
+ log.info("Not found: " + re.toString());
response.sendRedirect("notfound.jspx");
return;
+ } catch (FormatException fe) {
+ log.info("Format problem: " + re.toString());
+ response.sendRedirect("format.jspx");
+ return;
+ } catch (ChecksumException ce) {
+ log.info("Checksum problem: " + re.toString());
+ response.sendRedirect("format.jspx");
+ return;
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2008 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
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ 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.
+ -->
+<!-- Author: Sean Owen -->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
+<jsp:directive.page contentType="text/html" session="false"/>
+<jsp:scriptlet>response.setHeader("Cache-Control", "public");</jsp:scriptlet>
+<jsp:text><![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">]]></jsp:text>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+ <title>No Barcode Found</title>
+ <link rel="stylesheet" href="style.css" type="text/css"/>
+ </head>
+ <body>
+ <div id="header"><h1><img src="zxing-icon.png" height="32" width="32" alt=""/> Barcode Format Problem</h1></div>
+ <p>A barcode was possibly found in this image, but a problem occurred while decoding it. The data did not conform
+ to the barcode format. This could be due to a misdetection of the barcode, or could indicate a problem
+ with the barcode contents. Go "Back" in your browser and try another image.
+ </p>
+ <jsp:include page="analytics.jspx"/>
+ </body>
+</html>
+</jsp:root>