mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
move all Result to RXingResult
This commit is contained in:
@@ -23,12 +23,12 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DetectorResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.DetectorRXingResult;
|
||||
import com.google.zxing.qrcode.decoder.Decoder;
|
||||
import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData;
|
||||
import com.google.zxing.qrcode.detector.Detector;
|
||||
@@ -43,7 +43,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class QRCodeReader implements Reader {
|
||||
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
|
||||
|
||||
private final Decoder decoder = new Decoder();
|
||||
|
||||
@@ -60,46 +60,46 @@ public class QRCodeReader implements Reader {
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
|
||||
public RXingResult decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
|
||||
return decode(image, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
public final RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
throws NotFoundException, ChecksumException, FormatException {
|
||||
DecoderResult decoderResult;
|
||||
ResultPoint[] points;
|
||||
DecoderRXingResult decoderRXingResult;
|
||||
RXingResultPoint[] points;
|
||||
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
|
||||
BitMatrix bits = extractPureBits(image.getBlackMatrix());
|
||||
decoderResult = decoder.decode(bits, hints);
|
||||
decoderRXingResult = decoder.decode(bits, hints);
|
||||
points = NO_POINTS;
|
||||
} else {
|
||||
DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
|
||||
decoderResult = decoder.decode(detectorResult.getBits(), hints);
|
||||
points = detectorResult.getPoints();
|
||||
DetectorRXingResult detectorRXingResult = new Detector(image.getBlackMatrix()).detect(hints);
|
||||
decoderRXingResult = decoder.decode(detectorRXingResult.getBits(), hints);
|
||||
points = detectorRXingResult.getPoints();
|
||||
}
|
||||
|
||||
// If the code was mirrored: swap the bottom-left and the top-right points.
|
||||
if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
|
||||
((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
|
||||
if (decoderRXingResult.getOther() instanceof QRCodeDecoderMetaData) {
|
||||
((QRCodeDecoderMetaData) decoderRXingResult.getOther()).applyMirroredCorrection(points);
|
||||
}
|
||||
|
||||
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
|
||||
List<byte[]> byteSegments = decoderResult.getByteSegments();
|
||||
RXingResult result = new RXingResult(decoderRXingResult.getText(), decoderRXingResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
|
||||
List<byte[]> byteSegments = decoderRXingResult.getByteSegments();
|
||||
if (byteSegments != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
|
||||
result.putMetadata(RXingResultMetadataType.BYTE_SEGMENTS, byteSegments);
|
||||
}
|
||||
String ecLevel = decoderResult.getECLevel();
|
||||
String ecLevel = decoderRXingResult.getECLevel();
|
||||
if (ecLevel != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
result.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
}
|
||||
if (decoderResult.hasStructuredAppend()) {
|
||||
result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
|
||||
decoderResult.getStructuredAppendSequenceNumber());
|
||||
result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
|
||||
decoderResult.getStructuredAppendParity());
|
||||
if (decoderRXingResult.hasStructuredAppend()) {
|
||||
result.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
|
||||
decoderRXingResult.getStructuredAppendSequenceNumber());
|
||||
result.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_PARITY,
|
||||
decoderRXingResult.getStructuredAppendParity());
|
||||
}
|
||||
result.putMetadata(ResultMetadataType.SYMBOLOGY_IDENTIFIER, "]Q" + decoderResult.getSymbologyModifier());
|
||||
result.putMetadata(RXingResultMetadataType.SYMBOLOGY_IDENTIFIER, "]Q" + decoderRXingResult.getSymbologyModifier());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ public final class QRCodeWriter implements Writer {
|
||||
}
|
||||
|
||||
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
|
||||
return renderResult(code, width, height, quietZone);
|
||||
return renderRXingResult(code, width, height, quietZone);
|
||||
}
|
||||
|
||||
// Note that the input matrix uses 0 == white, 1 == black, while the output matrix uses
|
||||
// 0 == black, 255 == white (i.e. an 8 bit greyscale bitmap).
|
||||
private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone) {
|
||||
private static BitMatrix renderRXingResult(QRCode code, int width, int height, int quietZone) {
|
||||
ByteMatrix input = code.getMatrix();
|
||||
if (input == null) {
|
||||
throw new IllegalStateException();
|
||||
|
||||
@@ -65,12 +65,12 @@ final class DataBlock {
|
||||
|
||||
// Now establish DataBlocks of the appropriate size and number of data codewords
|
||||
DataBlock[] result = new DataBlock[totalBlocks];
|
||||
int numResultBlocks = 0;
|
||||
int numRXingResultBlocks = 0;
|
||||
for (Version.ECB ecBlock : ecBlockArray) {
|
||||
for (int i = 0; i < ecBlock.getCount(); i++) {
|
||||
int numDataCodewords = ecBlock.getDataCodewords();
|
||||
int numBlockCodewords = ecBlocks.getECCodewordsPerBlock() + numDataCodewords;
|
||||
result[numResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
|
||||
result[numRXingResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,18 +92,18 @@ final class DataBlock {
|
||||
// first fill out as many elements as all of them have
|
||||
int rawCodewordsOffset = 0;
|
||||
for (int i = 0; i < shorterBlocksNumDataCodewords; i++) {
|
||||
for (int j = 0; j < numResultBlocks; j++) {
|
||||
for (int j = 0; j < numRXingResultBlocks; j++) {
|
||||
result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
|
||||
}
|
||||
}
|
||||
// Fill out the last data block in the longer ones
|
||||
for (int j = longerBlocksStartAt; j < numResultBlocks; j++) {
|
||||
for (int j = longerBlocksStartAt; j < numRXingResultBlocks; j++) {
|
||||
result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];
|
||||
}
|
||||
// Now add in error correction blocks
|
||||
int max = result[0].codewords.length;
|
||||
for (int i = shorterBlocksNumDataCodewords; i < max; i++) {
|
||||
for (int j = 0; j < numResultBlocks; j++) {
|
||||
for (int j = 0; j < numRXingResultBlocks; j++) {
|
||||
int iOffset = j < longerBlocksStartAt ? i : i + 1;
|
||||
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.common.BitSource;
|
||||
import com.google.zxing.common.CharacterSetECI;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.StringUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
@@ -49,7 +49,7 @@ final class DecodedBitStreamParser {
|
||||
private DecodedBitStreamParser() {
|
||||
}
|
||||
|
||||
static DecoderResult decode(byte[] bytes,
|
||||
static DecoderRXingResult decode(byte[] bytes,
|
||||
Version version,
|
||||
ErrorCorrectionLevel ecLevel,
|
||||
Map<DecodeHintType,?> hints) throws FormatException {
|
||||
@@ -160,7 +160,7 @@ final class DecodedBitStreamParser {
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
|
||||
return new DecoderResult(bytes,
|
||||
return new DecoderRXingResult(bytes,
|
||||
result.toString(),
|
||||
byteSegments.isEmpty() ? null : byteSegments,
|
||||
ecLevel == null ? null : ecLevel.toString(),
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.reedsolomon.GenericGF;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonException;
|
||||
@@ -41,7 +41,7 @@ public final class Decoder {
|
||||
rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);
|
||||
}
|
||||
|
||||
public DecoderResult decode(boolean[][] image) throws ChecksumException, FormatException {
|
||||
public DecoderRXingResult decode(boolean[][] image) throws ChecksumException, FormatException {
|
||||
return decode(image, null);
|
||||
}
|
||||
|
||||
@@ -55,12 +55,12 @@ public final class Decoder {
|
||||
* @throws FormatException if the QR Code cannot be decoded
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
public DecoderResult decode(boolean[][] image, Map<DecodeHintType,?> hints)
|
||||
public DecoderRXingResult decode(boolean[][] image, Map<DecodeHintType,?> hints)
|
||||
throws ChecksumException, FormatException {
|
||||
return decode(BitMatrix.parse(image), hints);
|
||||
}
|
||||
|
||||
public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException {
|
||||
public DecoderRXingResult decode(BitMatrix bits) throws ChecksumException, FormatException {
|
||||
return decode(bits, null);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public final class Decoder {
|
||||
* @throws FormatException if the QR Code cannot be decoded
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
public DecoderResult decode(BitMatrix bits, Map<DecodeHintType,?> hints)
|
||||
public DecoderRXingResult decode(BitMatrix bits, Map<DecodeHintType,?> hints)
|
||||
throws FormatException, ChecksumException {
|
||||
|
||||
// Construct a parser and read version, error-correction level
|
||||
@@ -111,7 +111,7 @@ public final class Decoder {
|
||||
// Prepare for a mirrored reading.
|
||||
parser.mirror();
|
||||
|
||||
DecoderResult result = decode(parser, hints);
|
||||
DecoderRXingResult result = decode(parser, hints);
|
||||
|
||||
// Success! Notify the caller that the code was mirrored.
|
||||
result.setOther(new QRCodeDecoderMetaData(true));
|
||||
@@ -127,7 +127,7 @@ public final class Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
private DecoderResult decode(BitMatrixParser parser, Map<DecodeHintType,?> hints)
|
||||
private DecoderRXingResult decode(BitMatrixParser parser, Map<DecodeHintType,?> hints)
|
||||
throws FormatException, ChecksumException {
|
||||
Version version = parser.readVersion();
|
||||
ErrorCorrectionLevel ecLevel = parser.readFormatInformation().getErrorCorrectionLevel();
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.google.zxing.qrcode.decoder;
|
||||
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
|
||||
/**
|
||||
* Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the
|
||||
* decoding caller. Callers are expected to process this.
|
||||
*
|
||||
* @see com.google.zxing.common.DecoderResult#getOther()
|
||||
* @see com.google.zxing.common.DecoderRXingResult#getOther()
|
||||
*/
|
||||
public final class QRCodeDecoderMetaData {
|
||||
|
||||
@@ -44,11 +44,11 @@ public final class QRCodeDecoderMetaData {
|
||||
*
|
||||
* @param points Array of points to apply mirror correction to.
|
||||
*/
|
||||
public void applyMirroredCorrection(ResultPoint[] points) {
|
||||
public void applyMirroredCorrection(RXingResultPoint[] points) {
|
||||
if (!mirrored || points == null || points.length < 3) {
|
||||
return;
|
||||
}
|
||||
ResultPoint bottomLeft = points[0];
|
||||
RXingResultPoint bottomLeft = points[0];
|
||||
points[0] = points[2];
|
||||
points[2] = bottomLeft;
|
||||
// No need to 'fix' top-left and alignment pattern.
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.qrcode.detector;
|
||||
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
|
||||
/**
|
||||
* <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
|
||||
@@ -24,7 +24,7 @@ import com.google.zxing.ResultPoint;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AlignmentPattern extends ResultPoint {
|
||||
public final class AlignmentPattern extends RXingResultPoint {
|
||||
|
||||
private final float estimatedModuleSize;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.qrcode.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPointCallback;
|
||||
import com.google.zxing.RXingResultPointCallback;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -47,7 +47,7 @@ final class AlignmentPatternFinder {
|
||||
private final int height;
|
||||
private final float moduleSize;
|
||||
private final int[] crossCheckStateCount;
|
||||
private final ResultPointCallback resultPointCallback;
|
||||
private final RXingResultPointCallback resultPointCallback;
|
||||
|
||||
/**
|
||||
* <p>Creates a finder that will look in a portion of the whole image.</p>
|
||||
@@ -65,7 +65,7 @@ final class AlignmentPatternFinder {
|
||||
int width,
|
||||
int height,
|
||||
float moduleSize,
|
||||
ResultPointCallback resultPointCallback) {
|
||||
RXingResultPointCallback resultPointCallback) {
|
||||
this.image = image;
|
||||
this.possibleCenters = new ArrayList<>(5);
|
||||
this.startX = startX;
|
||||
@@ -268,7 +268,7 @@ final class AlignmentPatternFinder {
|
||||
AlignmentPattern point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
|
||||
possibleCenters.add(point);
|
||||
if (resultPointCallback != null) {
|
||||
resultPointCallback.foundPossibleResultPoint(point);
|
||||
resultPointCallback.foundPossibleRXingResultPoint(point);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -19,10 +19,10 @@ package com.google.zxing.qrcode.detector;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.ResultPointCallback;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.RXingResultPointCallback;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DetectorResult;
|
||||
import com.google.zxing.common.DetectorRXingResult;
|
||||
import com.google.zxing.common.GridSampler;
|
||||
import com.google.zxing.common.PerspectiveTransform;
|
||||
import com.google.zxing.common.detector.MathUtils;
|
||||
@@ -39,7 +39,7 @@ import java.util.Map;
|
||||
public class Detector {
|
||||
|
||||
private final BitMatrix image;
|
||||
private ResultPointCallback resultPointCallback;
|
||||
private RXingResultPointCallback resultPointCallback;
|
||||
|
||||
public Detector(BitMatrix image) {
|
||||
this.image = image;
|
||||
@@ -49,18 +49,18 @@ public class Detector {
|
||||
return image;
|
||||
}
|
||||
|
||||
protected final ResultPointCallback getResultPointCallback() {
|
||||
protected final RXingResultPointCallback getRXingResultPointCallback() {
|
||||
return resultPointCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Detects a QR Code in an image.</p>
|
||||
*
|
||||
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
|
||||
* @return {@link DetectorRXingResult} 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() throws NotFoundException, FormatException {
|
||||
public DetectorRXingResult detect() throws NotFoundException, FormatException {
|
||||
return detect(null);
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ public class Detector {
|
||||
* <p>Detects a QR Code in an image.</p>
|
||||
*
|
||||
* @param hints optional hints to detector
|
||||
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
|
||||
* @return {@link DetectorRXingResult} 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 final DetectorResult detect(Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
|
||||
public final DetectorRXingResult detect(Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
|
||||
|
||||
resultPointCallback = hints == null ? null :
|
||||
(ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
|
||||
(RXingResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
|
||||
|
||||
FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback);
|
||||
FinderPatternInfo info = finder.find(hints);
|
||||
@@ -83,7 +83,7 @@ public class Detector {
|
||||
return processFinderPatternInfo(info);
|
||||
}
|
||||
|
||||
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
|
||||
protected final DetectorRXingResult processFinderPatternInfo(FinderPatternInfo info)
|
||||
throws NotFoundException, FormatException {
|
||||
|
||||
FinderPattern topLeft = info.getTopLeft();
|
||||
@@ -132,19 +132,19 @@ public class Detector {
|
||||
|
||||
BitMatrix bits = sampleGrid(image, transform, dimension);
|
||||
|
||||
ResultPoint[] points;
|
||||
RXingResultPoint[] points;
|
||||
if (alignmentPattern == null) {
|
||||
points = new ResultPoint[]{bottomLeft, topLeft, topRight};
|
||||
points = new RXingResultPoint[]{bottomLeft, topLeft, topRight};
|
||||
} else {
|
||||
points = new ResultPoint[]{bottomLeft, topLeft, topRight, alignmentPattern};
|
||||
points = new RXingResultPoint[]{bottomLeft, topLeft, topRight, alignmentPattern};
|
||||
}
|
||||
return new DetectorResult(bits, points);
|
||||
return new DetectorRXingResult(bits, points);
|
||||
}
|
||||
|
||||
private static PerspectiveTransform createTransform(ResultPoint topLeft,
|
||||
ResultPoint topRight,
|
||||
ResultPoint bottomLeft,
|
||||
ResultPoint alignmentPattern,
|
||||
private static PerspectiveTransform createTransform(RXingResultPoint topLeft,
|
||||
RXingResultPoint topRight,
|
||||
RXingResultPoint bottomLeft,
|
||||
RXingResultPoint alignmentPattern,
|
||||
int dimension) {
|
||||
float dimMinusThree = dimension - 3.5f;
|
||||
float bottomRightX;
|
||||
@@ -195,12 +195,12 @@ public class Detector {
|
||||
* <p>Computes the dimension (number of modules on a size) of the QR Code based on the position
|
||||
* of the finder patterns and estimated module size.</p>
|
||||
*/
|
||||
private static int computeDimension(ResultPoint topLeft,
|
||||
ResultPoint topRight,
|
||||
ResultPoint bottomLeft,
|
||||
private static int computeDimension(RXingResultPoint topLeft,
|
||||
RXingResultPoint topRight,
|
||||
RXingResultPoint bottomLeft,
|
||||
float moduleSize) throws NotFoundException {
|
||||
int tltrCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, topRight) / moduleSize);
|
||||
int tlblCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize);
|
||||
int tltrCentersDimension = MathUtils.round(RXingResultPoint.distance(topLeft, topRight) / moduleSize);
|
||||
int tlblCentersDimension = MathUtils.round(RXingResultPoint.distance(topLeft, bottomLeft) / moduleSize);
|
||||
int dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7;
|
||||
switch (dimension & 0x03) { // mod 4
|
||||
case 0:
|
||||
@@ -225,9 +225,9 @@ public class Detector {
|
||||
* @param bottomLeft detected bottom-left finder pattern center
|
||||
* @return estimated module size
|
||||
*/
|
||||
protected final float calculateModuleSize(ResultPoint topLeft,
|
||||
ResultPoint topRight,
|
||||
ResultPoint bottomLeft) {
|
||||
protected final float calculateModuleSize(RXingResultPoint topLeft,
|
||||
RXingResultPoint topRight,
|
||||
RXingResultPoint bottomLeft) {
|
||||
// Take the average
|
||||
return (calculateModuleSizeOneWay(topLeft, topRight) +
|
||||
calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f;
|
||||
@@ -238,7 +238,7 @@ public class Detector {
|
||||
* {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
|
||||
* width of each, measuring along the axis between their centers.</p>
|
||||
*/
|
||||
private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
|
||||
private float calculateModuleSizeOneWay(RXingResultPoint pattern, RXingResultPoint otherPattern) {
|
||||
float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
|
||||
(int) pattern.getY(),
|
||||
(int) otherPattern.getX(),
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.qrcode.detector;
|
||||
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
|
||||
/**
|
||||
* <p>Encapsulates a finder pattern, which are the three square patterns found in
|
||||
@@ -25,7 +25,7 @@ import com.google.zxing.ResultPoint;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class FinderPattern extends ResultPoint {
|
||||
public final class FinderPattern extends RXingResultPoint {
|
||||
|
||||
private final float estimatedModuleSize;
|
||||
private final int count;
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.google.zxing.qrcode.detector;
|
||||
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.ResultPointCallback;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.RXingResultPointCallback;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -48,7 +48,7 @@ public class FinderPatternFinder {
|
||||
private final List<FinderPattern> possibleCenters;
|
||||
private boolean hasSkipped;
|
||||
private final int[] crossCheckStateCount;
|
||||
private final ResultPointCallback resultPointCallback;
|
||||
private final RXingResultPointCallback resultPointCallback;
|
||||
|
||||
/**
|
||||
* <p>Creates a finder that will search the image for three finder patterns.</p>
|
||||
@@ -59,7 +59,7 @@ public class FinderPatternFinder {
|
||||
this(image, null);
|
||||
}
|
||||
|
||||
public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback) {
|
||||
public FinderPatternFinder(BitMatrix image, RXingResultPointCallback resultPointCallback) {
|
||||
this.image = image;
|
||||
this.possibleCenters = new ArrayList<>();
|
||||
this.crossCheckStateCount = new int[5];
|
||||
@@ -162,7 +162,7 @@ public class FinderPatternFinder {
|
||||
}
|
||||
|
||||
FinderPattern[] patternInfo = selectBestPatterns();
|
||||
ResultPoint.orderBestPatterns(patternInfo);
|
||||
RXingResultPoint.orderBestPatterns(patternInfo);
|
||||
|
||||
return new FinderPatternInfo(patternInfo);
|
||||
}
|
||||
@@ -529,7 +529,7 @@ public class FinderPatternFinder {
|
||||
FinderPattern point = new FinderPattern(centerJ, centerI, estimatedModuleSize);
|
||||
possibleCenters.add(point);
|
||||
if (resultPointCallback != null) {
|
||||
resultPointCallback.foundPossibleResultPoint(point);
|
||||
resultPointCallback.foundPossibleRXingResultPoint(point);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -549,7 +549,7 @@ public class FinderPatternFinder {
|
||||
if (max <= 1) {
|
||||
return 0;
|
||||
}
|
||||
ResultPoint firstConfirmedCenter = null;
|
||||
RXingResultPoint firstConfirmedCenter = null;
|
||||
for (FinderPattern center : possibleCenters) {
|
||||
if (center.getCount() >= CENTER_QUORUM) {
|
||||
if (firstConfirmedCenter == null) {
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class Encoder {
|
||||
mode = Mode.BYTE;
|
||||
|
||||
Charset priorityEncoding = encoding.equals(DEFAULT_BYTE_MODE_ENCODING) ? null : encoding;
|
||||
MinimalEncoder.ResultList rn = MinimalEncoder.encode(content, null, priorityEncoding, hasGS1FormatHint, ecLevel);
|
||||
MinimalEncoder.RXingResultList rn = MinimalEncoder.encode(content, null, priorityEncoding, hasGS1FormatHint, ecLevel);
|
||||
|
||||
headerAndDataBits = new BitArray();
|
||||
rn.getBits(headerAndDataBits);
|
||||
|
||||
@@ -88,7 +88,7 @@ final class MinimalEncoder {
|
||||
* supported charsets.
|
||||
* @param isGS1 {@code true} if a FNC1 is to be prepended; {@code false} otherwise
|
||||
* @param ecLevel The error correction level.
|
||||
* @see ResultList#getVersion
|
||||
* @see RXingResultList#getVersion
|
||||
*/
|
||||
MinimalEncoder(String stringToEncode, Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel) {
|
||||
this.stringToEncode = stringToEncode;
|
||||
@@ -102,46 +102,46 @@ final class MinimalEncoder {
|
||||
*
|
||||
* @param stringToEncode The string to encode
|
||||
* @param version The preferred {@link Version}. A minimal version is computed (see
|
||||
* {@link ResultList#getVersion method} when the value of the argument is null
|
||||
* {@link RXingResultList#getVersion method} when the value of the argument is null
|
||||
* @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm
|
||||
* chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority
|
||||
* charset to encode any character in the input that can be encoded by it if the charset is among the
|
||||
* supported charsets.
|
||||
* @param isGS1 {@code true} if a FNC1 is to be prepended; {@code false} otherwise
|
||||
* @param ecLevel The error correction level.
|
||||
* @return An instance of {@code ResultList} representing the minimal solution.
|
||||
* @see ResultList#getBits
|
||||
* @see ResultList#getVersion
|
||||
* @see ResultList#getSize
|
||||
* @return An instance of {@code RXingResultList} representing the minimal solution.
|
||||
* @see RXingResultList#getBits
|
||||
* @see RXingResultList#getVersion
|
||||
* @see RXingResultList#getSize
|
||||
*/
|
||||
static ResultList encode(String stringToEncode, Version version, Charset priorityCharset, boolean isGS1,
|
||||
static RXingResultList encode(String stringToEncode, Version version, Charset priorityCharset, boolean isGS1,
|
||||
ErrorCorrectionLevel ecLevel) throws WriterException {
|
||||
return new MinimalEncoder(stringToEncode, priorityCharset, isGS1, ecLevel).encode(version);
|
||||
}
|
||||
|
||||
ResultList encode(Version version) throws WriterException {
|
||||
RXingResultList encode(Version version) throws WriterException {
|
||||
if (version == null) { // compute minimal encoding trying the three version sizes.
|
||||
Version[] versions = { getVersion(VersionSize.SMALL),
|
||||
getVersion(VersionSize.MEDIUM),
|
||||
getVersion(VersionSize.LARGE) };
|
||||
ResultList[] results = { encodeSpecificVersion(versions[0]),
|
||||
RXingResultList[] results = { encodeSpecificVersion(versions[0]),
|
||||
encodeSpecificVersion(versions[1]),
|
||||
encodeSpecificVersion(versions[2]) };
|
||||
int smallestSize = Integer.MAX_VALUE;
|
||||
int smallestResult = -1;
|
||||
int smallestRXingResult = -1;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int size = results[i].getSize();
|
||||
if (Encoder.willFit(size, versions[i], ecLevel) && size < smallestSize) {
|
||||
smallestSize = size;
|
||||
smallestResult = i;
|
||||
smallestRXingResult = i;
|
||||
}
|
||||
}
|
||||
if (smallestResult < 0) {
|
||||
if (smallestRXingResult < 0) {
|
||||
throw new WriterException("Data too big for any version");
|
||||
}
|
||||
return results[smallestResult];
|
||||
return results[smallestRXingResult];
|
||||
} else { // compute minimal encoding for a given version
|
||||
ResultList result = encodeSpecificVersion(version);
|
||||
RXingResultList result = encodeSpecificVersion(version);
|
||||
if (!Encoder.willFit(result.getSize(), getVersion(getVersionSize(result.getVersion())), ecLevel)) {
|
||||
throw new WriterException("Data too big for version" + version);
|
||||
}
|
||||
@@ -248,7 +248,7 @@ final class MinimalEncoder {
|
||||
!canEncode(Mode.NUMERIC, stringToEncode.charAt(from + 2)) ? 2 : 3, previous, version));
|
||||
}
|
||||
}
|
||||
ResultList encodeSpecificVersion(Version version) throws WriterException {
|
||||
RXingResultList encodeSpecificVersion(Version version) throws WriterException {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
/* A vertex represents a tuple of a position in the input, a mode and a character encoding where position 0
|
||||
@@ -399,7 +399,7 @@ final class MinimalEncoder {
|
||||
if (minimalJ < 0) {
|
||||
throw new WriterException("Internal error: failed to encode \"" + stringToEncode + "\"");
|
||||
}
|
||||
return new ResultList(version, edges[inputLength][minimalJ][minimalK]);
|
||||
return new RXingResultList(version, edges[inputLength][minimalJ][minimalK]);
|
||||
}
|
||||
|
||||
private final class Edge {
|
||||
@@ -450,12 +450,12 @@ final class MinimalEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
final class ResultList {
|
||||
final class RXingResultList {
|
||||
|
||||
private final List<ResultList.ResultNode> list = new ArrayList<>();
|
||||
private final List<RXingResultList.RXingResultNode> list = new ArrayList<>();
|
||||
private final Version version;
|
||||
|
||||
ResultList(Version version, Edge solution) {
|
||||
RXingResultList(Version version, Edge solution) {
|
||||
int length = 0;
|
||||
Edge current = solution;
|
||||
boolean containsECI = false;
|
||||
@@ -473,12 +473,12 @@ final class MinimalEncoder {
|
||||
}
|
||||
|
||||
if (previous == null || previous.mode != current.mode || needECI) {
|
||||
list.add(0, new ResultNode(current.mode, current.fromPosition, current.charsetEncoderIndex, length));
|
||||
list.add(0, new RXingResultNode(current.mode, current.fromPosition, current.charsetEncoderIndex, length));
|
||||
length = 0;
|
||||
}
|
||||
|
||||
if (needECI) {
|
||||
list.add(0, new ResultNode(Mode.ECI, current.fromPosition, current.charsetEncoderIndex, 0));
|
||||
list.add(0, new RXingResultNode(Mode.ECI, current.fromPosition, current.charsetEncoderIndex, 0));
|
||||
}
|
||||
current = previous;
|
||||
}
|
||||
@@ -486,14 +486,14 @@ final class MinimalEncoder {
|
||||
// prepend FNC1 if needed. If the bits contain an ECI then the FNC1 must be preceeded by an ECI.
|
||||
// If there is no ECI at the beginning then we put an ECI to the default charset (ISO-8859-1)
|
||||
if (isGS1) {
|
||||
ResultNode first = list.get(0);
|
||||
RXingResultNode first = list.get(0);
|
||||
if (first != null && first.mode != Mode.ECI && containsECI) {
|
||||
// prepend a default character set ECI
|
||||
list.add(0, new ResultNode(Mode.ECI, 0, 0, 0));
|
||||
list.add(0, new RXingResultNode(Mode.ECI, 0, 0, 0));
|
||||
}
|
||||
first = list.get(0);
|
||||
// prepend or insert a FNC1_FIRST_POSITION after the ECI (if any)
|
||||
list.add(first.mode != Mode.ECI ? 0 : 1, new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
|
||||
list.add(first.mode != Mode.ECI ? 0 : 1, new RXingResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
|
||||
}
|
||||
|
||||
// set version to smallest version into which the bits fit.
|
||||
@@ -538,7 +538,7 @@ final class MinimalEncoder {
|
||||
|
||||
private int getSize(Version version) {
|
||||
int result = 0;
|
||||
for (ResultNode resultNode : list) {
|
||||
for (RXingResultNode resultNode : list) {
|
||||
result += resultNode.getSize(version);
|
||||
}
|
||||
return result;
|
||||
@@ -548,7 +548,7 @@ final class MinimalEncoder {
|
||||
* appends the bits
|
||||
*/
|
||||
void getBits(BitArray bits) throws WriterException {
|
||||
for (ResultNode resultNode : list) {
|
||||
for (RXingResultNode resultNode : list) {
|
||||
resultNode.getBits(bits);
|
||||
}
|
||||
}
|
||||
@@ -559,8 +559,8 @@ final class MinimalEncoder {
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
ResultNode previous = null;
|
||||
for (ResultNode current : list) {
|
||||
RXingResultNode previous = null;
|
||||
for (RXingResultNode current : list) {
|
||||
if (previous != null) {
|
||||
result.append(",");
|
||||
}
|
||||
@@ -570,14 +570,14 @@ final class MinimalEncoder {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
final class ResultNode {
|
||||
final class RXingResultNode {
|
||||
|
||||
private final Mode mode;
|
||||
private final int fromPosition;
|
||||
private final int charsetEncoderIndex;
|
||||
private final int characterLength;
|
||||
|
||||
ResultNode(Mode mode, int fromPosition, int charsetEncoderIndex, int characterLength) {
|
||||
RXingResultNode(Mode mode, int fromPosition, int charsetEncoderIndex, int characterLength) {
|
||||
this.mode = mode;
|
||||
this.fromPosition = fromPosition;
|
||||
this.charsetEncoderIndex = charsetEncoderIndex;
|
||||
|
||||
Reference in New Issue
Block a user