move all Result to RXingResult

This commit is contained in:
Henry Schimke
2022-08-20 12:12:30 -05:00
parent 9f72478dc8
commit 90ace738b7
149 changed files with 1658 additions and 1658 deletions

View File

@@ -22,8 +22,8 @@ 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.ResultPoint;
import com.google.zxing.RXingResult;
import com.google.zxing.RXingResultPoint;
import java.util.Map;
@@ -45,13 +45,13 @@ public final class ByQuadrantReader implements Reader {
}
@Override
public Result decode(BinaryBitmap image)
public RXingResult decode(BinaryBitmap image)
throws NotFoundException, ChecksumException, FormatException {
return decode(image, null);
}
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
public RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, ChecksumException, FormatException {
int width = image.getWidth();
@@ -67,24 +67,24 @@ public final class ByQuadrantReader implements Reader {
}
try {
Result result = delegate.decode(image.crop(halfWidth, 0, halfWidth, halfHeight), hints);
makeAbsolute(result.getResultPoints(), halfWidth, 0);
RXingResult result = delegate.decode(image.crop(halfWidth, 0, halfWidth, halfHeight), hints);
makeAbsolute(result.getRXingResultPoints(), halfWidth, 0);
return result;
} catch (NotFoundException re) {
// continue
}
try {
Result result = delegate.decode(image.crop(0, halfHeight, halfWidth, halfHeight), hints);
makeAbsolute(result.getResultPoints(), 0, halfHeight);
RXingResult result = delegate.decode(image.crop(0, halfHeight, halfWidth, halfHeight), hints);
makeAbsolute(result.getRXingResultPoints(), 0, halfHeight);
return result;
} catch (NotFoundException re) {
// continue
}
try {
Result result = delegate.decode(image.crop(halfWidth, halfHeight, halfWidth, halfHeight), hints);
makeAbsolute(result.getResultPoints(), halfWidth, halfHeight);
RXingResult result = delegate.decode(image.crop(halfWidth, halfHeight, halfWidth, halfHeight), hints);
makeAbsolute(result.getRXingResultPoints(), halfWidth, halfHeight);
return result;
} catch (NotFoundException re) {
// continue
@@ -93,8 +93,8 @@ public final class ByQuadrantReader implements Reader {
int quarterWidth = halfWidth / 2;
int quarterHeight = halfHeight / 2;
BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight);
Result result = delegate.decode(center, hints);
makeAbsolute(result.getResultPoints(), quarterWidth, quarterHeight);
RXingResult result = delegate.decode(center, hints);
makeAbsolute(result.getRXingResultPoints(), quarterWidth, quarterHeight);
return result;
}
@@ -103,12 +103,12 @@ public final class ByQuadrantReader implements Reader {
delegate.reset();
}
private static void makeAbsolute(ResultPoint[] points, int leftOffset, int topOffset) {
private static void makeAbsolute(RXingResultPoint[] points, int leftOffset, int topOffset) {
if (points != null) {
for (int i = 0; i < points.length; i++) {
ResultPoint relative = points[i];
RXingResultPoint relative = points[i];
if (relative != null) {
points[i] = new ResultPoint(relative.getX() + leftOffset, relative.getY() + topOffset);
points[i] = new RXingResultPoint(relative.getX() + leftOffset, relative.getY() + topOffset);
}
}
}

View File

@@ -21,8 +21,8 @@ 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.ResultPoint;
import com.google.zxing.RXingResult;
import com.google.zxing.RXingResultPoint;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +31,7 @@ import java.util.Map;
/**
* <p>Attempts to locate multiple barcodes in an image by repeatedly decoding portion of the image.
* After one barcode is found, the areas left, above, right and below the barcode's
* {@link ResultPoint}s are scanned, recursively.</p>
* {@link RXingResultPoint}s are scanned, recursively.</p>
*
* <p>A caller may want to also employ {@link ByQuadrantReader} when attempting to find multiple
* 2D barcodes, like QR Codes, in an image, where the presence of multiple barcodes might prevent
@@ -47,7 +47,7 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
private static final int MIN_DIMENSION_TO_RECUR = 100;
private static final int MAX_DEPTH = 4;
static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
static final RXingResult[] EMPTY_RESULT_ARRAY = new RXingResult[0];
private final Reader delegate;
@@ -56,14 +56,14 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
}
@Override
public Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException {
public RXingResult[] decodeMultiple(BinaryBitmap image) throws NotFoundException {
return decodeMultiple(image, null);
}
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints)
public RXingResult[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException {
List<Result> results = new ArrayList<>();
List<RXingResult> results = new ArrayList<>();
doDecodeMultiple(image, hints, results, 0, 0, 0);
if (results.isEmpty()) {
throw NotFoundException.getNotFoundInstance();
@@ -73,7 +73,7 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
private void doDecodeMultiple(BinaryBitmap image,
Map<DecodeHintType,?> hints,
List<Result> results,
List<RXingResult> results,
int xOffset,
int yOffset,
int currentDepth) {
@@ -81,23 +81,23 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
return;
}
Result result;
RXingResult result;
try {
result = delegate.decode(image, hints);
} catch (ReaderException ignored) {
return;
}
boolean alreadyFound = false;
for (Result existingResult : results) {
if (existingResult.getText().equals(result.getText())) {
for (RXingResult existingRXingResult : results) {
if (existingRXingResult.getText().equals(result.getText())) {
alreadyFound = true;
break;
}
}
if (!alreadyFound) {
results.add(translateResultPoints(result, xOffset, yOffset));
results.add(translateRXingResultPoints(result, xOffset, yOffset));
}
ResultPoint[] resultPoints = result.getResultPoints();
RXingResultPoint[] resultPoints = result.getRXingResultPoints();
if (resultPoints == null || resultPoints.length == 0) {
return;
}
@@ -107,7 +107,7 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
float minY = height;
float maxX = 0.0f;
float maxY = 0.0f;
for (ResultPoint point : resultPoints) {
for (RXingResultPoint point : resultPoints) {
if (point == null) {
continue;
}
@@ -157,26 +157,26 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
}
}
private static Result translateResultPoints(Result result, int xOffset, int yOffset) {
ResultPoint[] oldResultPoints = result.getResultPoints();
if (oldResultPoints == null) {
private static RXingResult translateRXingResultPoints(RXingResult result, int xOffset, int yOffset) {
RXingResultPoint[] oldRXingResultPoints = result.getRXingResultPoints();
if (oldRXingResultPoints == null) {
return result;
}
ResultPoint[] newResultPoints = new ResultPoint[oldResultPoints.length];
for (int i = 0; i < oldResultPoints.length; i++) {
ResultPoint oldPoint = oldResultPoints[i];
RXingResultPoint[] newRXingResultPoints = new RXingResultPoint[oldRXingResultPoints.length];
for (int i = 0; i < oldRXingResultPoints.length; i++) {
RXingResultPoint oldPoint = oldRXingResultPoints[i];
if (oldPoint != null) {
newResultPoints[i] = new ResultPoint(oldPoint.getX() + xOffset, oldPoint.getY() + yOffset);
newRXingResultPoints[i] = new RXingResultPoint(oldPoint.getX() + xOffset, oldPoint.getY() + yOffset);
}
}
Result newResult = new Result(result.getText(),
RXingResult newRXingResult = new RXingResult(result.getText(),
result.getRawBytes(),
result.getNumBits(),
newResultPoints,
newRXingResultPoints,
result.getBarcodeFormat(),
result.getTimestamp());
newResult.putAllMetadata(result.getResultMetadata());
return newResult;
newRXingResult.putAllMetadata(result.getRXingResultMetadata());
return newRXingResult;
}
}

View File

@@ -19,7 +19,7 @@ package com.google.zxing.multi;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.RXingResult;
import java.util.Map;
@@ -31,9 +31,9 @@ import java.util.Map;
*/
public interface MultipleBarcodeReader {
Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException;
RXingResult[] decodeMultiple(BinaryBitmap image) throws NotFoundException;
Result[] decodeMultiple(BinaryBitmap image,
RXingResult[] decodeMultiple(BinaryBitmap image,
Map<DecodeHintType,?> hints) throws NotFoundException;
}

View File

@@ -21,11 +21,11 @@ import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.RXingResult;
import com.google.zxing.RXingResultMetadataType;
import com.google.zxing.RXingResultPoint;
import com.google.zxing.common.DecoderRXingResult;
import com.google.zxing.common.DetectorRXingResult;
import com.google.zxing.multi.MultipleBarcodeReader;
import com.google.zxing.multi.qrcode.detector.MultiDetector;
import com.google.zxing.qrcode.QRCodeReader;
@@ -47,41 +47,41 @@ import java.util.Comparator;
*/
public final class QRCodeMultiReader extends QRCodeReader implements MultipleBarcodeReader {
private static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
private static final RXingResult[] EMPTY_RESULT_ARRAY = new RXingResult[0];
private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
@Override
public Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException {
public RXingResult[] decodeMultiple(BinaryBitmap image) throws NotFoundException {
return decodeMultiple(image, null);
}
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
List<Result> results = new ArrayList<>();
DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
for (DetectorResult detectorResult : detectorResults) {
public RXingResult[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
List<RXingResult> results = new ArrayList<>();
DetectorRXingResult[] detectorRXingResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
for (DetectorRXingResult detectorRXingResult : detectorRXingResults) {
try {
DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints);
ResultPoint[] points = detectorResult.getPoints();
DecoderRXingResult decoderRXingResult = getDecoder().decode(detectorRXingResult.getBits(), hints);
RXingResultPoint[] 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,
RXingResult result = new RXingResult(decoderRXingResult.getText(), decoderRXingResult.getRawBytes(), points,
BarcodeFormat.QR_CODE);
List<byte[]> byteSegments = decoderResult.getByteSegments();
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());
}
results.add(result);
} catch (ReaderException re) {
@@ -96,32 +96,32 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
}
}
static List<Result> processStructuredAppend(List<Result> results) {
List<Result> newResults = new ArrayList<>();
List<Result> saResults = new ArrayList<>();
for (Result result : results) {
if (result.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) {
saResults.add(result);
static List<RXingResult> processStructuredAppend(List<RXingResult> results) {
List<RXingResult> newRXingResults = new ArrayList<>();
List<RXingResult> saRXingResults = new ArrayList<>();
for (RXingResult result : results) {
if (result.getRXingResultMetadata().containsKey(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) {
saRXingResults.add(result);
} else {
newResults.add(result);
newRXingResults.add(result);
}
}
if (saResults.isEmpty()) {
if (saRXingResults.isEmpty()) {
return results;
}
// sort and concatenate the SA list items
Collections.sort(saResults, new SAComparator());
Collections.sort(saRXingResults, new SAComparator());
StringBuilder newText = new StringBuilder();
ByteArrayOutputStream newRawBytes = new ByteArrayOutputStream();
ByteArrayOutputStream newByteSegment = new ByteArrayOutputStream();
for (Result saResult : saResults) {
newText.append(saResult.getText());
byte[] saBytes = saResult.getRawBytes();
for (RXingResult saRXingResult : saRXingResults) {
newText.append(saRXingResult.getText());
byte[] saBytes = saRXingResult.getRawBytes();
newRawBytes.write(saBytes, 0, saBytes.length);
@SuppressWarnings("unchecked")
Iterable<byte[]> byteSegments =
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
(Iterable<byte[]>) saRXingResult.getRXingResultMetadata().get(RXingResultMetadataType.BYTE_SEGMENTS);
if (byteSegments != null) {
for (byte[] segment : byteSegments) {
newByteSegment.write(segment, 0, segment.length);
@@ -129,19 +129,19 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
}
}
Result newResult = new Result(newText.toString(), newRawBytes.toByteArray(), NO_POINTS, BarcodeFormat.QR_CODE);
RXingResult newRXingResult = new RXingResult(newText.toString(), newRawBytes.toByteArray(), NO_POINTS, BarcodeFormat.QR_CODE);
if (newByteSegment.size() > 0) {
newResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, Collections.singletonList(newByteSegment.toByteArray()));
newRXingResult.putMetadata(RXingResultMetadataType.BYTE_SEGMENTS, Collections.singletonList(newByteSegment.toByteArray()));
}
newResults.add(newResult);
return newResults;
newRXingResults.add(newRXingResult);
return newRXingResults;
}
private static final class SAComparator implements Comparator<Result>, Serializable {
private static final class SAComparator implements Comparator<RXingResult>, Serializable {
@Override
public int compare(Result a, Result b) {
int aNumber = (int) a.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE);
int bNumber = (int) b.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE);
public int compare(RXingResult a, RXingResult b) {
int aNumber = (int) a.getRXingResultMetadata().get(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE);
int bNumber = (int) b.getRXingResultMetadata().get(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE);
return Integer.compare(aNumber, bNumber);
}
}

View File

@@ -19,9 +19,9 @@ package com.google.zxing.multi.qrcode.detector;
import com.google.zxing.DecodeHintType;
import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.ResultPointCallback;
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.qrcode.detector.Detector;
import com.google.zxing.qrcode.detector.FinderPatternInfo;
@@ -38,16 +38,16 @@ import java.util.Map;
*/
public final class MultiDetector extends Detector {
private static final DetectorResult[] EMPTY_DETECTOR_RESULTS = new DetectorResult[0];
private static final DetectorRXingResult[] EMPTY_DETECTOR_RESULTS = new DetectorRXingResult[0];
public MultiDetector(BitMatrix image) {
super(image);
}
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException {
public DetectorRXingResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback =
hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
RXingResultPointCallback resultPointCallback =
hints == null ? null : (RXingResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
@@ -55,7 +55,7 @@ public final class MultiDetector extends Detector {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<>();
List<DetectorRXingResult> result = new ArrayList<>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));

View File

@@ -18,8 +18,8 @@ package com.google.zxing.multi.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 com.google.zxing.qrcode.detector.FinderPattern;
import com.google.zxing.qrcode.detector.FinderPatternFinder;
@@ -86,7 +86,7 @@ public final class MultiFinderPatternFinder extends FinderPatternFinder {
}
}
public MultiFinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback) {
public MultiFinderPatternFinder(BitMatrix image, RXingResultPointCallback resultPointCallback) {
super(image, resultPointCallback);
}
@@ -176,13 +176,13 @@ public final class MultiFinderPatternFinder extends FinderPatternFinder {
}
FinderPattern[] test = {p1, p2, p3};
ResultPoint.orderBestPatterns(test);
RXingResultPoint.orderBestPatterns(test);
// Calculate the distances: a = topleft-bottomleft, b=topleft-topright, c = diagonal
FinderPatternInfo info = new FinderPatternInfo(test);
float dA = ResultPoint.distance(info.getTopLeft(), info.getBottomLeft());
float dC = ResultPoint.distance(info.getTopRight(), info.getBottomLeft());
float dB = ResultPoint.distance(info.getTopLeft(), info.getTopRight());
float dA = RXingResultPoint.distance(info.getTopLeft(), info.getBottomLeft());
float dC = RXingResultPoint.distance(info.getTopRight(), info.getBottomLeft());
float dB = RXingResultPoint.distance(info.getTopLeft(), info.getTopRight());
// Check the sizes
float estimatedModuleCount = (dA + dB) / (p1.getEstimatedModuleSize() * 2.0f);
@@ -276,7 +276,7 @@ public final class MultiFinderPatternFinder extends FinderPatternFinder {
FinderPattern[][] patternInfo = selectMultipleBestPatterns();
List<FinderPatternInfo> result = new ArrayList<>();
for (FinderPattern[] pattern : patternInfo) {
ResultPoint.orderBestPatterns(pattern);
RXingResultPoint.orderBestPatterns(pattern);
result.add(new FinderPatternInfo(pattern));
}