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

@@ -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.datamatrix.decoder.Decoder;
import com.google.zxing.datamatrix.detector.Detector;
@@ -42,7 +42,7 @@ import java.util.Map;
*/
public final class DataMatrixReader 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();
@@ -55,35 +55,35 @@ public final class DataMatrixReader 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 Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
public 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);
decoderRXingResult = decoder.decode(bits);
points = NO_POINTS;
} else {
DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
decoderResult = decoder.decode(detectorResult.getBits());
points = detectorResult.getPoints();
DetectorRXingResult detectorRXingResult = new Detector(image.getBlackMatrix()).detect();
decoderRXingResult = decoder.decode(detectorRXingResult.getBits());
points = detectorRXingResult.getPoints();
}
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
RXingResult result = new RXingResult(decoderRXingResult.getText(), decoderRXingResult.getRawBytes(), points,
BarcodeFormat.DATA_MATRIX);
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);
}
result.putMetadata(ResultMetadataType.SYMBOLOGY_IDENTIFIER, "]d" + decoderResult.getSymbologyModifier());
result.putMetadata(RXingResultMetadataType.SYMBOLOGY_IDENTIFIER, "]d" + decoderRXingResult.getSymbologyModifier());
return result;
}

View File

@@ -57,12 +57,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.getECCodewords() + numDataCodewords;
result[numResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
result[numRXingResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
}
}
@@ -78,14 +78,14 @@ final class DataBlock {
// first fill out as many elements as all of them have minus 1
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
boolean specialVersion = version.getVersionNumber() == 24;
int numLongerBlocks = specialVersion ? 8 : numResultBlocks;
int numLongerBlocks = specialVersion ? 8 : numRXingResultBlocks;
for (int j = 0; j < numLongerBlocks; j++) {
result[j].codewords[longerBlocksNumDataCodewords - 1] = rawCodewords[rawCodewordsOffset++];
}
@@ -93,8 +93,8 @@ final class DataBlock {
// Now add in error correction blocks
int max = result[0].codewords.length;
for (int i = longerBlocksNumDataCodewords; i < max; i++) {
for (int j = 0; j < numResultBlocks; j++) {
int jOffset = specialVersion ? (j + 8) % numResultBlocks : j;
for (int j = 0; j < numRXingResultBlocks; j++) {
int jOffset = specialVersion ? (j + 8) % numRXingResultBlocks : j;
int iOffset = specialVersion && jOffset > 7 ? i - 1 : i;
result[jOffset].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
}

View File

@@ -18,7 +18,7 @@ package com.google.zxing.datamatrix.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.common.BitSource;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DecoderRXingResult;
import com.google.zxing.common.ECIStringBuilder;
import java.nio.charset.StandardCharsets;
@@ -86,7 +86,7 @@ final class DecodedBitStreamParser {
private DecodedBitStreamParser() {
}
static DecoderResult decode(byte[] bytes) throws FormatException {
static DecoderRXingResult decode(byte[] bytes) throws FormatException {
BitSource bits = new BitSource(bytes);
ECIStringBuilder result = new ECIStringBuilder(100);
StringBuilder resultTrailer = new StringBuilder(0);
@@ -149,7 +149,7 @@ final class DecodedBitStreamParser {
}
}
return new DecoderResult(bytes,
return new DecoderRXingResult(bytes,
result.toString(),
byteSegments.isEmpty() ? null : byteSegments,
null,

View File

@@ -19,7 +19,7 @@ package com.google.zxing.datamatrix.decoder;
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.DecoderRXingResult;
import com.google.zxing.common.reedsolomon.GenericGF;
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;
import com.google.zxing.common.reedsolomon.ReedSolomonException;
@@ -47,7 +47,7 @@ public final class Decoder {
* @throws FormatException if the Data Matrix Code cannot be decoded
* @throws ChecksumException if error correction fails
*/
public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException {
public DecoderRXingResult decode(boolean[][] image) throws FormatException, ChecksumException {
return decode(BitMatrix.parse(image));
}
@@ -60,7 +60,7 @@ public final class Decoder {
* @throws FormatException if the Data Matrix Code cannot be decoded
* @throws ChecksumException if error correction fails
*/
public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException {
public DecoderRXingResult decode(BitMatrix bits) throws FormatException, ChecksumException {
// Construct a parser and read version, error-correction level
BitMatrixParser parser = new BitMatrixParser(bits);

View File

@@ -17,9 +17,9 @@
package com.google.zxing.datamatrix.detector;
import com.google.zxing.NotFoundException;
import com.google.zxing.ResultPoint;
import com.google.zxing.RXingResultPoint;
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.detector.WhiteRectangleDetector;
@@ -42,14 +42,14 @@ public final class Detector {
/**
* <p>Detects a Data Matrix Code in an image.</p>
*
* @return {@link DetectorResult} encapsulating results of detecting a Data Matrix Code
* @return {@link DetectorRXingResult} encapsulating results of detecting a Data Matrix Code
* @throws NotFoundException if no Data Matrix Code can be found
*/
public DetectorResult detect() throws NotFoundException {
public DetectorRXingResult detect() throws NotFoundException {
ResultPoint[] cornerPoints = rectangleDetector.detect();
RXingResultPoint[] cornerPoints = rectangleDetector.detect();
ResultPoint[] points = detectSolid1(cornerPoints);
RXingResultPoint[] points = detectSolid1(cornerPoints);
points = detectSolid2(points);
points[3] = correctTopRight(points);
if (points[3] == null) {
@@ -57,10 +57,10 @@ public final class Detector {
}
points = shiftToModuleCenter(points);
ResultPoint topLeft = points[0];
ResultPoint bottomLeft = points[1];
ResultPoint bottomRight = points[2];
ResultPoint topRight = points[3];
RXingResultPoint topLeft = points[0];
RXingResultPoint bottomLeft = points[1];
RXingResultPoint bottomRight = points[2];
RXingResultPoint topRight = points[3];
int dimensionTop = transitionsBetween(topLeft, topRight) + 1;
int dimensionRight = transitionsBetween(bottomRight, topRight) + 1;
@@ -84,16 +84,16 @@ public final class Detector {
dimensionTop,
dimensionRight);
return new DetectorResult(bits, new ResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
return new DetectorRXingResult(bits, new RXingResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
}
private static ResultPoint shiftPoint(ResultPoint point, ResultPoint to, int div) {
private static RXingResultPoint shiftPoint(RXingResultPoint point, RXingResultPoint to, int div) {
float x = (to.getX() - point.getX()) / (div + 1);
float y = (to.getY() - point.getY()) / (div + 1);
return new ResultPoint(point.getX() + x, point.getY() + y);
return new RXingResultPoint(point.getX() + x, point.getY() + y);
}
private static ResultPoint moveAway(ResultPoint point, float fromX, float fromY) {
private static RXingResultPoint moveAway(RXingResultPoint point, float fromX, float fromY) {
float x = point.getX();
float y = point.getY();
@@ -109,19 +109,19 @@ public final class Detector {
y += 1;
}
return new ResultPoint(x, y);
return new RXingResultPoint(x, y);
}
/**
* Detect a solid side which has minimum transition.
*/
private ResultPoint[] detectSolid1(ResultPoint[] cornerPoints) {
private RXingResultPoint[] detectSolid1(RXingResultPoint[] cornerPoints) {
// 0 2
// 1 3
ResultPoint pointA = cornerPoints[0];
ResultPoint pointB = cornerPoints[1];
ResultPoint pointC = cornerPoints[3];
ResultPoint pointD = cornerPoints[2];
RXingResultPoint pointA = cornerPoints[0];
RXingResultPoint pointB = cornerPoints[1];
RXingResultPoint pointC = cornerPoints[3];
RXingResultPoint pointD = cornerPoints[2];
int trAB = transitionsBetween(pointA, pointB);
int trBC = transitionsBetween(pointB, pointC);
@@ -132,7 +132,7 @@ public final class Detector {
// : :
// 1--2
int min = trAB;
ResultPoint[] points = {pointD, pointA, pointB, pointC};
RXingResultPoint[] points = {pointD, pointA, pointB, pointC};
if (min > trBC) {
min = trBC;
points[0] = pointA;
@@ -160,20 +160,20 @@ public final class Detector {
/**
* Detect a second solid side next to first solid side.
*/
private ResultPoint[] detectSolid2(ResultPoint[] points) {
private RXingResultPoint[] detectSolid2(RXingResultPoint[] points) {
// A..D
// : :
// B--C
ResultPoint pointA = points[0];
ResultPoint pointB = points[1];
ResultPoint pointC = points[2];
ResultPoint pointD = points[3];
RXingResultPoint pointA = points[0];
RXingResultPoint pointB = points[1];
RXingResultPoint pointC = points[2];
RXingResultPoint pointD = points[3];
// Transition detection on the edge is not stable.
// To safely detect, shift the points to the module center.
int tr = transitionsBetween(pointA, pointD);
ResultPoint pointBs = shiftPoint(pointB, pointC, (tr + 1) * 4);
ResultPoint pointCs = shiftPoint(pointC, pointB, (tr + 1) * 4);
RXingResultPoint pointBs = shiftPoint(pointB, pointC, (tr + 1) * 4);
RXingResultPoint pointCs = shiftPoint(pointC, pointB, (tr + 1) * 4);
int trBA = transitionsBetween(pointBs, pointA);
int trCD = transitionsBetween(pointCs, pointD);
@@ -200,28 +200,28 @@ public final class Detector {
/**
* Calculates the corner position of the white top right module.
*/
private ResultPoint correctTopRight(ResultPoint[] points) {
private RXingResultPoint correctTopRight(RXingResultPoint[] points) {
// A..D
// | :
// B--C
ResultPoint pointA = points[0];
ResultPoint pointB = points[1];
ResultPoint pointC = points[2];
ResultPoint pointD = points[3];
RXingResultPoint pointA = points[0];
RXingResultPoint pointB = points[1];
RXingResultPoint pointC = points[2];
RXingResultPoint pointD = points[3];
// shift points for safe transition detection.
int trTop = transitionsBetween(pointA, pointD);
int trRight = transitionsBetween(pointB, pointD);
ResultPoint pointAs = shiftPoint(pointA, pointB, (trRight + 1) * 4);
ResultPoint pointCs = shiftPoint(pointC, pointB, (trTop + 1) * 4);
RXingResultPoint pointAs = shiftPoint(pointA, pointB, (trRight + 1) * 4);
RXingResultPoint pointCs = shiftPoint(pointC, pointB, (trTop + 1) * 4);
trTop = transitionsBetween(pointAs, pointD);
trRight = transitionsBetween(pointCs, pointD);
ResultPoint candidate1 = new ResultPoint(
RXingResultPoint candidate1 = new RXingResultPoint(
pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop + 1),
pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop + 1));
ResultPoint candidate2 = new ResultPoint(
RXingResultPoint candidate2 = new RXingResultPoint(
pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight + 1),
pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight + 1));
@@ -248,22 +248,22 @@ public final class Detector {
/**
* Shift the edge points to the module center.
*/
private ResultPoint[] shiftToModuleCenter(ResultPoint[] points) {
private RXingResultPoint[] shiftToModuleCenter(RXingResultPoint[] points) {
// A..D
// | :
// B--C
ResultPoint pointA = points[0];
ResultPoint pointB = points[1];
ResultPoint pointC = points[2];
ResultPoint pointD = points[3];
RXingResultPoint pointA = points[0];
RXingResultPoint pointB = points[1];
RXingResultPoint pointC = points[2];
RXingResultPoint pointD = points[3];
// calculate pseudo dimensions
int dimH = transitionsBetween(pointA, pointD) + 1;
int dimV = transitionsBetween(pointC, pointD) + 1;
// shift points for safe dimension detection
ResultPoint pointAs = shiftPoint(pointA, pointB, dimV * 4);
ResultPoint pointCs = shiftPoint(pointC, pointB, dimH * 4);
RXingResultPoint pointAs = shiftPoint(pointA, pointB, dimV * 4);
RXingResultPoint pointCs = shiftPoint(pointC, pointB, dimH * 4);
// calculate more precise dimensions
dimH = transitionsBetween(pointAs, pointD) + 1;
@@ -284,8 +284,8 @@ public final class Detector {
pointC = moveAway(pointC, centerX, centerY);
pointD = moveAway(pointD, centerX, centerY);
ResultPoint pointBs;
ResultPoint pointDs;
RXingResultPoint pointBs;
RXingResultPoint pointDs;
// shift points to the center of each modules
pointAs = shiftPoint(pointA, pointB, dimV * 4);
@@ -297,18 +297,18 @@ public final class Detector {
pointDs = shiftPoint(pointD, pointC, dimV * 4);
pointDs = shiftPoint(pointDs, pointA, dimH * 4);
return new ResultPoint[]{pointAs, pointBs, pointCs, pointDs};
return new RXingResultPoint[]{pointAs, pointBs, pointCs, pointDs};
}
private boolean isValid(ResultPoint p) {
private boolean isValid(RXingResultPoint p) {
return p.getX() >= 0 && p.getX() <= image.getWidth() - 1 && p.getY() > 0 && p.getY() <= image.getHeight() - 1;
}
private static BitMatrix sampleGrid(BitMatrix image,
ResultPoint topLeft,
ResultPoint bottomLeft,
ResultPoint bottomRight,
ResultPoint topRight,
RXingResultPoint topLeft,
RXingResultPoint bottomLeft,
RXingResultPoint bottomRight,
RXingResultPoint topRight,
int dimensionX,
int dimensionY) throws NotFoundException {
@@ -338,7 +338,7 @@ public final class Detector {
/**
* Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
*/
private int transitionsBetween(ResultPoint from, ResultPoint to) {
private int transitionsBetween(RXingResultPoint from, RXingResultPoint to) {
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
int fromX = (int) from.getX();
int fromY = (int) from.getY();

View File

@@ -251,7 +251,7 @@ public final class MinimalEncoder {
addEdge(edges, new Edge(input, Mode.EDF, from, 4, previous));
}
}
static Result encodeMinimally(Input input) {
static RXingResult encodeMinimally(Input input) {
@SuppressWarnings("checkstyle:lineLength")
/* The minimal encoding is computed by Dijkstra. The acyclic graph is modeled as follows:
@@ -474,7 +474,7 @@ public final class MinimalEncoder {
if (minimalJ < 0) {
throw new RuntimeException("Internal error: failed to encode \"" + input + "\"");
}
return new Result(edges[inputLength][minimalJ]);
return new RXingResult(edges[inputLength][minimalJ]);
}
private static final class Edge {
@@ -926,11 +926,11 @@ public final class MinimalEncoder {
}
}
private static final class Result {
private static final class RXingResult {
private final byte[] bytes;
Result(Edge solution) {
RXingResult(Edge solution) {
Input input = solution.input;
int size = 0;
List<Byte> bytesAL = new ArrayList<>();