Detector.java (zxing-zxing-3.4.1) | : | Detector.java (zxing-zxing-3.5.0) | ||
---|---|---|---|---|
skipping to change at line 74 | skipping to change at line 74 | |||
int dimensionTop = transitionsBetween(topLeft, topRight) + 1; | int dimensionTop = transitionsBetween(topLeft, topRight) + 1; | |||
int dimensionRight = transitionsBetween(bottomRight, topRight) + 1; | int dimensionRight = transitionsBetween(bottomRight, topRight) + 1; | |||
if ((dimensionTop & 0x01) == 1) { | if ((dimensionTop & 0x01) == 1) { | |||
dimensionTop += 1; | dimensionTop += 1; | |||
} | } | |||
if ((dimensionRight & 0x01) == 1) { | if ((dimensionRight & 0x01) == 1) { | |||
dimensionRight += 1; | dimensionRight += 1; | |||
} | } | |||
if (4 * dimensionTop < 7 * dimensionRight && 4 * dimensionRight < 7 * dimens ionTop) { | if (4 * dimensionTop < 6 * dimensionRight && 4 * dimensionRight < 6 * dimens ionTop) { | |||
// The matrix is square | // The matrix is square | |||
dimensionTop = dimensionRight = Math.max(dimensionTop, dimensionRight); | dimensionTop = dimensionRight = Math.max(dimensionTop, dimensionRight); | |||
} | } | |||
BitMatrix bits = sampleGrid(image, | BitMatrix bits = sampleGrid(image, | |||
topLeft, | topLeft, | |||
bottomLeft, | bottomLeft, | |||
bottomRight, | bottomRight, | |||
topRight, | topRight, | |||
dimensionTop, | dimensionTop, | |||
skipping to change at line 222 | skipping to change at line 222 | |||
// shift points for safe transition detection. | // shift points for safe transition detection. | |||
int trTop = transitionsBetween(pointA, pointD); | int trTop = transitionsBetween(pointA, pointD); | |||
int trRight = transitionsBetween(pointB, pointD); | int trRight = transitionsBetween(pointB, pointD); | |||
ResultPoint pointAs = shiftPoint(pointA, pointB, (trRight + 1) * 4); | ResultPoint pointAs = shiftPoint(pointA, pointB, (trRight + 1) * 4); | |||
ResultPoint pointCs = shiftPoint(pointC, pointB, (trTop + 1) * 4); | ResultPoint pointCs = shiftPoint(pointC, pointB, (trTop + 1) * 4); | |||
trTop = transitionsBetween(pointAs, pointD); | trTop = transitionsBetween(pointAs, pointD); | |||
trRight = transitionsBetween(pointCs, pointD); | trRight = transitionsBetween(pointCs, pointD); | |||
ResultPoint candidate1 = new ResultPoint( | ResultPoint candidate1 = new ResultPoint( | |||
pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop + 1), | pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop + 1), | |||
pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop + 1)); | pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop + 1)); | |||
ResultPoint candidate2 = new ResultPoint( | ResultPoint candidate2 = new ResultPoint( | |||
pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight + 1), | pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight + 1), | |||
pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight + 1)); | pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight + 1)); | |||
if (!isValid(candidate1)) { | if (!isValid(candidate1)) { | |||
if (isValid(candidate2)) { | if (isValid(candidate2)) { | |||
return candidate2; | return candidate2; | |||
} | } | |||
return null; | return null; | |||
} | } | |||
if (!isValid(candidate2)) { | if (!isValid(candidate2)) { | |||
return candidate1; | return candidate1; | |||
} | } | |||
skipping to change at line 304 | skipping to change at line 304 | |||
pointBs = shiftPoint(pointBs, pointC, dimH * 4); | pointBs = shiftPoint(pointBs, pointC, dimH * 4); | |||
pointCs = shiftPoint(pointC, pointD, dimV * 4); | pointCs = shiftPoint(pointC, pointD, dimV * 4); | |||
pointCs = shiftPoint(pointCs, pointB, dimH * 4); | pointCs = shiftPoint(pointCs, pointB, dimH * 4); | |||
pointDs = shiftPoint(pointD, pointC, dimV * 4); | pointDs = shiftPoint(pointD, pointC, dimV * 4); | |||
pointDs = shiftPoint(pointDs, pointA, dimH * 4); | pointDs = shiftPoint(pointDs, pointA, dimH * 4); | |||
return new ResultPoint[]{pointAs, pointBs, pointCs, pointDs}; | return new ResultPoint[]{pointAs, pointBs, pointCs, pointDs}; | |||
} | } | |||
private boolean isValid(ResultPoint p) { | private boolean isValid(ResultPoint p) { | |||
return p.getX() >= 0 && p.getX() < image.getWidth() && p.getY() > 0 && p.get Y() < image.getHeight(); | return p.getX() >= 0 && p.getX() <= image.getWidth() - 1 && p.getY() > 0 && p.getY() <= image.getHeight() - 1; | |||
} | } | |||
private static BitMatrix sampleGrid(BitMatrix image, | private static BitMatrix sampleGrid(BitMatrix image, | |||
ResultPoint topLeft, | ResultPoint topLeft, | |||
ResultPoint bottomLeft, | ResultPoint bottomLeft, | |||
ResultPoint bottomRight, | ResultPoint bottomRight, | |||
ResultPoint topRight, | ResultPoint topRight, | |||
int dimensionX, | int dimensionX, | |||
int dimensionY) throws NotFoundException { | int dimensionY) throws NotFoundException { | |||
skipping to change at line 346 | skipping to change at line 346 | |||
} | } | |||
/** | /** | |||
* Counts the number of black/white transitions between two points, using some thing like Bresenham's algorithm. | * Counts the number of black/white transitions between two points, using some thing like Bresenham's algorithm. | |||
*/ | */ | |||
private int transitionsBetween(ResultPoint from, ResultPoint to) { | private int transitionsBetween(ResultPoint from, ResultPoint to) { | |||
// See QR Code Detector, sizeOfBlackWhiteBlackRun() | // See QR Code Detector, sizeOfBlackWhiteBlackRun() | |||
int fromX = (int) from.getX(); | int fromX = (int) from.getX(); | |||
int fromY = (int) from.getY(); | int fromY = (int) from.getY(); | |||
int toX = (int) to.getX(); | int toX = (int) to.getX(); | |||
int toY = (int) to.getY(); | int toY = Math.min(image.getHeight() - 1, (int) to.getY()); | |||
boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX); | boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX); | |||
if (steep) { | if (steep) { | |||
int temp = fromX; | int temp = fromX; | |||
fromX = fromY; | fromX = fromY; | |||
fromY = temp; | fromY = temp; | |||
temp = toX; | temp = toX; | |||
toX = toY; | toX = toY; | |||
toY = temp; | toY = temp; | |||
} | } | |||
End of changes. 5 change blocks. | ||||
7 lines changed or deleted | 8 lines changed or added |