X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fdatamatrix%2Fdecoder%2FDecoder.java;h=47ecac950d8731488bdb45a8b22d7627e8b6aec6;hp=65311761ace42032f76626b6085436b54b27b56a;hb=d0920ceb07da310eb8e10f6a11d5590bcb3184ea;hpb=6e7e7c61527df949b0d6a1ac1fac2684d474fbb2 diff --git a/core/src/com/google/zxing/datamatrix/decoder/Decoder.java b/core/src/com/google/zxing/datamatrix/decoder/Decoder.java index 65311761..47ecac95 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/Decoder.java +++ b/core/src/com/google/zxing/datamatrix/decoder/Decoder.java @@ -16,7 +16,8 @@ package com.google.zxing.datamatrix.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.reedsolomon.GF256; @@ -43,15 +44,16 @@ public final class Decoder { * * @param image booleans representing white/black Data Matrix Code modules * @return text and bytes encoded within the Data Matrix Code - * @throws ReaderException if the Data Matrix Code cannot be decoded + * @throws FormatException if the Data Matrix Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(boolean[][] image) throws ReaderException { + public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException { 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); } } } @@ -64,13 +66,14 @@ public final class Decoder { * * @param bits booleans representing white/black Data Matrix Code modules * @return text and bytes encoded within the Data Matrix Code - * @throws ReaderException if the Data Matrix Code cannot be decoded + * @throws FormatException if the Data Matrix Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(BitMatrix bits) throws ReaderException { + public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException { // Construct a parser and read version, error-correction level BitMatrixParser parser = new BitMatrixParser(bits); - Version version = parser.readVersion(bits); + Version version = parser.getVersion(); // Read codewords byte[] codewords = parser.readCodewords(); @@ -97,8 +100,7 @@ public final class Decoder { } // Decode the contents of that stream of bytes - String text = DecodedBitStreamParser.decode(resultBytes); - return new DecoderResult(resultBytes, text); + return DecodedBitStreamParser.decode(resultBytes); } /** @@ -107,9 +109,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]; @@ -118,9 +120,9 @@ public final class Decoder { } int numECCodewords = codewordBytes.length - numDataCodewords; try { - rsDecoder.decode(codewordsInts, numECCodewords, true); + 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