mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
More stuff in response to static inspection
This commit is contained in:
parent
ccb8293a04
commit
4d39673d67
|
@ -122,7 +122,8 @@ public abstract class GridSampler {
|
|||
int height = image.getHeight();
|
||||
// Check and nudge points from start until we see some that are OK:
|
||||
boolean nudged = true;
|
||||
for (int offset = 0; offset < points.length && nudged; offset += 2) {
|
||||
int maxOffset = points.length - 1; // points.length must be even
|
||||
for (int offset = 0; offset < maxOffset && nudged; offset += 2) {
|
||||
int x = (int) points[offset];
|
||||
int y = (int) points[offset + 1];
|
||||
if (x < -1 || x > width || y < -1 || y > height) {
|
||||
|
|
|
@ -64,7 +64,6 @@ public final class PerspectiveTransform {
|
|||
}
|
||||
|
||||
public void transformPoints(float[] points) {
|
||||
int max = points.length;
|
||||
float a11 = this.a11;
|
||||
float a12 = this.a12;
|
||||
float a13 = this.a13;
|
||||
|
@ -74,7 +73,8 @@ public final class PerspectiveTransform {
|
|||
float a31 = this.a31;
|
||||
float a32 = this.a32;
|
||||
float a33 = this.a33;
|
||||
for (int i = 0; i < max; i += 2) {
|
||||
int maxI = points.length - 1; // points.length must be even
|
||||
for (int i = 0; i < maxI; i += 2) {
|
||||
float x = points[i];
|
||||
float y = points[i + 1];
|
||||
float denominator = a13 * x + a23 * y + a33;
|
||||
|
|
|
@ -45,8 +45,8 @@ public final class MathUtils {
|
|||
* @return Euclidean distance between points A and B
|
||||
*/
|
||||
public static float distance(float aX, float aY, float bX, float bY) {
|
||||
float xDiff = aX - bX;
|
||||
float yDiff = aY - bY;
|
||||
double xDiff = aX - bX;
|
||||
double yDiff = aY - bY;
|
||||
return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ public final class MathUtils {
|
|||
* @return Euclidean distance between points A and B
|
||||
*/
|
||||
public static float distance(int aX, int aY, int bX, int bY) {
|
||||
int xDiff = aX - bX;
|
||||
int yDiff = aY - bY;
|
||||
double xDiff = aX - bX;
|
||||
double yDiff = aY - bY;
|
||||
return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
|||
}
|
||||
|
||||
// Calculate the diagonal length by assuming a 90° angle at topleft
|
||||
float dCpy = (float) Math.sqrt(dA * dA + dB * dB);
|
||||
float dCpy = (float) Math.sqrt((double) dA * dA + (double) dB * dB);
|
||||
// Compare to the real distance in %
|
||||
float vPyC = Math.abs((dC - dCpy) / Math.min(dC, dCpy));
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ public final class PDF417ScanningDecoder {
|
|||
BoundingBox boundingBox = new BoundingBox(image, imageTopLeft, imageBottomLeft, imageTopRight, imageBottomRight);
|
||||
DetectionResultRowIndicatorColumn leftRowIndicatorColumn = null;
|
||||
DetectionResultRowIndicatorColumn rightRowIndicatorColumn = null;
|
||||
DetectionResult detectionResult = null;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
DetectionResult detectionResult;
|
||||
for (boolean firstPass = true; ; firstPass = false) {
|
||||
if (imageTopLeft != null) {
|
||||
leftRowIndicatorColumn = getRowIndicatorColumn(image, boundingBox, imageTopLeft, true, minCodewordWidth,
|
||||
maxCodewordWidth);
|
||||
|
@ -73,15 +73,15 @@ public final class PDF417ScanningDecoder {
|
|||
if (detectionResult == null) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
if (i == 0 && detectionResult.getBoundingBox() != null &&
|
||||
(detectionResult.getBoundingBox().getMinY() < boundingBox.getMinY() || detectionResult.getBoundingBox()
|
||||
.getMaxY() > boundingBox.getMaxY())) {
|
||||
boundingBox = detectionResult.getBoundingBox();
|
||||
BoundingBox resultBox = detectionResult.getBoundingBox();
|
||||
if (firstPass && resultBox != null &&
|
||||
(resultBox.getMinY() < boundingBox.getMinY() || resultBox.getMaxY() > boundingBox.getMaxY())) {
|
||||
boundingBox = resultBox;
|
||||
} else {
|
||||
detectionResult.setBoundingBox(boundingBox);
|
||||
break;
|
||||
}
|
||||
}
|
||||
detectionResult.setBoundingBox(boundingBox);
|
||||
int maxBarcodeColumn = detectionResult.getBarcodeColumnCount() + 1;
|
||||
detectionResult.setDetectionResultColumn(0, leftRowIndicatorColumn);
|
||||
detectionResult.setDetectionResultColumn(maxBarcodeColumn, rightRowIndicatorColumn);
|
||||
|
|
|
@ -702,7 +702,7 @@ public final class PDF417 {
|
|||
continue;
|
||||
}
|
||||
|
||||
float newRatio = ((17 * cols + 69) * DEFAULT_MODULE_WIDTH) / (rows * HEIGHT);
|
||||
float newRatio = ((float) (17 * cols + 69) * DEFAULT_MODULE_WIDTH) / (rows * HEIGHT);
|
||||
|
||||
// ignore if previous ratio is closer to preferred ratio
|
||||
if (dimension != null && Math.abs(newRatio - PREFERRED_RATIO) > Math.abs(ratio - PREFERRED_RATIO)) {
|
||||
|
|
|
@ -607,19 +607,19 @@ public class FinderPatternFinder {
|
|||
// Filter outlier possibilities whose module size is too different
|
||||
if (startSize > 3) {
|
||||
// But we can only afford to do so if we have at least 4 possibilities to choose from
|
||||
float totalModuleSize = 0.0f;
|
||||
float square = 0.0f;
|
||||
double totalModuleSize = 0.0;
|
||||
double square = 0.0;
|
||||
for (FinderPattern center : possibleCenters) {
|
||||
float size = center.getEstimatedModuleSize();
|
||||
totalModuleSize += size;
|
||||
square += size * size;
|
||||
}
|
||||
float average = totalModuleSize / startSize;
|
||||
double average = totalModuleSize / startSize;
|
||||
float stdDev = (float) Math.sqrt(square / startSize - average * average);
|
||||
|
||||
Collections.sort(possibleCenters, new FurthestFromAverageComparator(average));
|
||||
Collections.sort(possibleCenters, new FurthestFromAverageComparator((float) average));
|
||||
|
||||
float limit = Math.max(0.2f * average, stdDev);
|
||||
float limit = Math.max(0.2f * (float) average, stdDev);
|
||||
|
||||
for (int i = 0; i < possibleCenters.size() && possibleCenters.size() > 3; i++) {
|
||||
FinderPattern pattern = possibleCenters.get(i);
|
||||
|
|
|
@ -589,8 +589,11 @@ public final class Encoder {
|
|||
} catch (UnsupportedEncodingException uee) {
|
||||
throw new WriterException(uee);
|
||||
}
|
||||
int length = bytes.length;
|
||||
for (int i = 0; i < length; i += 2) {
|
||||
if (bytes.length % 2 != 0) {
|
||||
throw new WriterException("Kanji byte size not even");
|
||||
}
|
||||
int maxI = bytes.length - 1; // bytes.length must be even
|
||||
for (int i = 0; i < maxI; i += 2) {
|
||||
int byte1 = bytes[i] & 0xFF;
|
||||
int byte2 = bytes[i + 1] & 0xFF;
|
||||
int code = (byte1 << 8) | byte2;
|
||||
|
|
Loading…
Reference in a new issue