X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fqrcode%2Fdecoder%2FDecoder.java;h=520e076f9e4d43c39b9dd560329864ef5ae17ec7;hp=0ee7954b14f8c474ee2c7e65ff7a06f357370fa7;hb=d0920ceb07da310eb8e10f6a11d5590bcb3184ea;hpb=d420554bc509d08feb59ac81cd48a10d3b5e6042 diff --git a/core/src/com/google/zxing/qrcode/decoder/Decoder.java b/core/src/com/google/zxing/qrcode/decoder/Decoder.java index 0ee7954b..520e076f 100644 --- a/core/src/com/google/zxing/qrcode/decoder/Decoder.java +++ b/core/src/com/google/zxing/qrcode/decoder/Decoder.java @@ -16,18 +16,22 @@ package com.google.zxing.qrcode.decoder; -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.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.reedsolomon.GF256; import com.google.zxing.common.reedsolomon.ReedSolomonDecoder; import com.google.zxing.common.reedsolomon.ReedSolomonException; +import java.util.Hashtable; + /** *

The main class which implements QR Code decoding -- as opposed to locating and extracting * the QR Code from an image.

* - * @author srowen@google.com (Sean Owen) + * @author Sean Owen */ public final class Decoder { @@ -37,25 +41,35 @@ public final class Decoder { rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD); } + public DecoderResult decode(boolean[][] image) + throws ChecksumException, FormatException, NotFoundException { + return decode(image, null); + } + /** *

Convenience method that can decode a QR Code represented as a 2D array of booleans. * "true" is taken to mean a black module.

* * @param image booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code - * @throws ReaderException if the QR Code cannot be decoded + * @throws FormatException if the QR Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(boolean[][] image) throws ReaderException { + public DecoderResult decode(boolean[][] image, Hashtable hints) throws ChecksumException, FormatException { int dimension = image.length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { if (image[i][j]) { - bits.set(i, j); + bits.set(j, i); } } } - return decode(bits); + return decode(bits, hints); + } + + public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException { + return decode(bits, null); } /** @@ -63,9 +77,10 @@ public final class Decoder { * * @param bits booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code - * @throws ReaderException if the QR Code cannot be decoded + * @throws FormatException if the QR Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(BitMatrix bits) throws ReaderException { + public DecoderResult decode(BitMatrix bits, Hashtable hints) throws FormatException, ChecksumException { // Construct a parser and read version, error-correction level BitMatrixParser parser = new BitMatrixParser(bits); @@ -97,8 +112,7 @@ public final class Decoder { } // Decode the contents of that stream of bytes - String text = DecodedBitStreamParser.decode(resultBytes, version); - return new DecoderResult(resultBytes, text); + return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints); } /** @@ -107,9 +121,9 @@ public final class Decoder { * * @param codewordBytes data and error correction codewords * @param numDataCodewords number of codewords that are data bytes - * @throws ReaderException if error correction fails + * @throws ChecksumException if error correction fails */ - private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException { + private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException { int numCodewords = codewordBytes.length; // First read into an array of ints int[] codewordsInts = new int[numCodewords]; @@ -120,7 +134,7 @@ public final class Decoder { try { rsDecoder.decode(codewordsInts, numECCodewords); } catch (ReedSolomonException rse) { - throw new ReaderException(rse.toString()); + throw ChecksumException.getChecksumInstance(); } // Copy back into array of bytes -- only need to worry about the bytes that were data // We don't care about errors in the error-correction codewords