*/
public static final DecodeHintType TRY_HARDER = new DecodeHintType();
+ /**
+ * Specifies what character encoding to use when decoding, where applicable (type String)
+ */
+ public static final DecodeHintType CHARACTER_SET = new DecodeHintType();
+
/**
* Allowed lengths of encoded data -- reject anything else. Maps to an int[].
*/
ResultPoint[] points;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
BitMatrix bits = extractPureBits(image.getBlackMatrix());
- decoderResult = decoder.decode(bits);
+ decoderResult = decoder.decode(bits, hints);
points = NO_POINTS;
} else {
DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
- decoderResult = decoder.decode(detectorResult.getBits());
+ decoderResult = decoder.decode(detectorResult.getBits(), hints);
points = detectorResult.getPoints();
}
return result;
}
+ public void reset() {
+ // do nothing
+ }
+
/**
* This method detects a barcode in a "pure" image -- that is, pure monochrome image
* which contains only an unrotated, unskewed, image of a barcode, with some white border
package com.google.zxing.qrcode.decoder;
+import com.google.zxing.DecodeHintType;
import com.google.zxing.ReaderException;
import com.google.zxing.common.BitSource;
import com.google.zxing.common.CharacterSetECI;
import com.google.zxing.common.DecoderResult;
import java.io.UnsupportedEncodingException;
+import java.util.Hashtable;
import java.util.Vector;
/**
private DecodedBitStreamParser() {
}
- static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel) throws ReaderException {
+ static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Hashtable hints)
+ throws ReaderException {
BitSource bits = new BitSource(bytes);
StringBuffer result = new StringBuffer(50);
CharacterSetECI currentCharacterSetECI = null;
} else if (mode.equals(Mode.ALPHANUMERIC)) {
decodeAlphanumericSegment(bits, result, count, fc1InEffect);
} else if (mode.equals(Mode.BYTE)) {
- decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments);
+ decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
} else if (mode.equals(Mode.KANJI)) {
decodeKanjiSegment(bits, result, count);
} else {
StringBuffer result,
int count,
CharacterSetECI currentCharacterSetECI,
- Vector byteSegments) throws ReaderException {
+ Vector byteSegments,
+ Hashtable hints) throws ReaderException {
byte[] readBytes = new byte[count];
if (count << 3 > bits.available()) {
throw ReaderException.getInstance();
// upon decoding. I have seen ISO-8859-1 used as well as
// Shift_JIS -- without anything like an ECI designator to
// give a hint.
- encoding = guessEncoding(readBytes);
+ encoding = guessEncoding(readBytes, hints);
} else {
encoding = currentCharacterSetECI.getEncodingName();
}
}
}
- private static String guessEncoding(byte[] bytes) {
+ private static String guessEncoding(byte[] bytes, Hashtable hints) {
+ if (hints != null) {
+ String characterSet = (String) hints.get(DecodeHintType.CHARACTER_SET);
+ if (characterSet != null) {
+ return characterSet;
+ }
+ }
if (ASSUME_SHIFT_JIS) {
return SHIFT_JIS;
}
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;\r
import com.google.zxing.common.reedsolomon.ReedSolomonException;\r
\r
+import java.util.Hashtable;\r
+\r
/**\r
* <p>The main class which implements QR Code decoding -- as opposed to locating and extracting\r
* the QR Code from an image.</p>\r
rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r
}\r
\r
+ public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+ return decode(image, null);\r
+ }\r
+\r
/**\r
* <p>Convenience method that can decode a QR Code represented as a 2D array of booleans.\r
* "true" is taken to mean a black module.</p>\r
* @return text and bytes encoded within the QR Code\r
* @throws ReaderException if the QR Code cannot be decoded\r
*/\r
- public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+ public DecoderResult decode(boolean[][] image, Hashtable hints) throws ReaderException {\r
int dimension = image.length;\r
BitMatrix bits = new BitMatrix(dimension);\r
for (int i = 0; i < dimension; i++) {\r
}\r
}\r
}\r
- return decode(bits);\r
+ return decode(bits, hints);\r
+ }\r
+\r
+ public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+ return decode(bits, null);\r
}\r
\r
/**\r
* @return text and bytes encoded within the QR Code\r
* @throws ReaderException if the QR Code cannot be decoded\r
*/\r
- public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+ public DecoderResult decode(BitMatrix bits, Hashtable hints) throws ReaderException {\r
\r
// Construct a parser and read version, error-correction level\r
BitMatrixParser parser = new BitMatrixParser(bits);\r
}\r
\r
// Decode the contents of that stream of bytes\r
- return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);\r
+ return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints);\r
}\r
\r
/**\r