mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -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();
|
int height = image.getHeight();
|
||||||
// Check and nudge points from start until we see some that are OK:
|
// Check and nudge points from start until we see some that are OK:
|
||||||
boolean nudged = true;
|
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 x = (int) points[offset];
|
||||||
int y = (int) points[offset + 1];
|
int y = (int) points[offset + 1];
|
||||||
if (x < -1 || x > width || y < -1 || y > height) {
|
if (x < -1 || x > width || y < -1 || y > height) {
|
||||||
|
|
|
@ -64,7 +64,6 @@ public final class PerspectiveTransform {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transformPoints(float[] points) {
|
public void transformPoints(float[] points) {
|
||||||
int max = points.length;
|
|
||||||
float a11 = this.a11;
|
float a11 = this.a11;
|
||||||
float a12 = this.a12;
|
float a12 = this.a12;
|
||||||
float a13 = this.a13;
|
float a13 = this.a13;
|
||||||
|
@ -74,7 +73,8 @@ public final class PerspectiveTransform {
|
||||||
float a31 = this.a31;
|
float a31 = this.a31;
|
||||||
float a32 = this.a32;
|
float a32 = this.a32;
|
||||||
float a33 = this.a33;
|
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 x = points[i];
|
||||||
float y = points[i + 1];
|
float y = points[i + 1];
|
||||||
float denominator = a13 * x + a23 * y + a33;
|
float denominator = a13 * x + a23 * y + a33;
|
||||||
|
|
|
@ -45,8 +45,8 @@ public final class MathUtils {
|
||||||
* @return Euclidean distance between points A and B
|
* @return Euclidean distance between points A and B
|
||||||
*/
|
*/
|
||||||
public static float distance(float aX, float aY, float bX, float bY) {
|
public static float distance(float aX, float aY, float bX, float bY) {
|
||||||
float xDiff = aX - bX;
|
double xDiff = aX - bX;
|
||||||
float yDiff = aY - bY;
|
double yDiff = aY - bY;
|
||||||
return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ public final class MathUtils {
|
||||||
* @return Euclidean distance between points A and B
|
* @return Euclidean distance between points A and B
|
||||||
*/
|
*/
|
||||||
public static float distance(int aX, int aY, int bX, int bY) {
|
public static float distance(int aX, int aY, int bX, int bY) {
|
||||||
int xDiff = aX - bX;
|
double xDiff = aX - bX;
|
||||||
int yDiff = aY - bY;
|
double yDiff = aY - bY;
|
||||||
return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
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
|
// 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 %
|
// Compare to the real distance in %
|
||||||
float vPyC = Math.abs((dC - dCpy) / Math.min(dC, dCpy));
|
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);
|
BoundingBox boundingBox = new BoundingBox(image, imageTopLeft, imageBottomLeft, imageTopRight, imageBottomRight);
|
||||||
DetectionResultRowIndicatorColumn leftRowIndicatorColumn = null;
|
DetectionResultRowIndicatorColumn leftRowIndicatorColumn = null;
|
||||||
DetectionResultRowIndicatorColumn rightRowIndicatorColumn = null;
|
DetectionResultRowIndicatorColumn rightRowIndicatorColumn = null;
|
||||||
DetectionResult detectionResult = null;
|
DetectionResult detectionResult;
|
||||||
for (int i = 0; i < 2; i++) {
|
for (boolean firstPass = true; ; firstPass = false) {
|
||||||
if (imageTopLeft != null) {
|
if (imageTopLeft != null) {
|
||||||
leftRowIndicatorColumn = getRowIndicatorColumn(image, boundingBox, imageTopLeft, true, minCodewordWidth,
|
leftRowIndicatorColumn = getRowIndicatorColumn(image, boundingBox, imageTopLeft, true, minCodewordWidth,
|
||||||
maxCodewordWidth);
|
maxCodewordWidth);
|
||||||
|
@ -73,15 +73,15 @@ public final class PDF417ScanningDecoder {
|
||||||
if (detectionResult == null) {
|
if (detectionResult == null) {
|
||||||
throw NotFoundException.getNotFoundInstance();
|
throw NotFoundException.getNotFoundInstance();
|
||||||
}
|
}
|
||||||
if (i == 0 && detectionResult.getBoundingBox() != null &&
|
BoundingBox resultBox = detectionResult.getBoundingBox();
|
||||||
(detectionResult.getBoundingBox().getMinY() < boundingBox.getMinY() || detectionResult.getBoundingBox()
|
if (firstPass && resultBox != null &&
|
||||||
.getMaxY() > boundingBox.getMaxY())) {
|
(resultBox.getMinY() < boundingBox.getMinY() || resultBox.getMaxY() > boundingBox.getMaxY())) {
|
||||||
boundingBox = detectionResult.getBoundingBox();
|
boundingBox = resultBox;
|
||||||
} else {
|
} else {
|
||||||
detectionResult.setBoundingBox(boundingBox);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
detectionResult.setBoundingBox(boundingBox);
|
||||||
int maxBarcodeColumn = detectionResult.getBarcodeColumnCount() + 1;
|
int maxBarcodeColumn = detectionResult.getBarcodeColumnCount() + 1;
|
||||||
detectionResult.setDetectionResultColumn(0, leftRowIndicatorColumn);
|
detectionResult.setDetectionResultColumn(0, leftRowIndicatorColumn);
|
||||||
detectionResult.setDetectionResultColumn(maxBarcodeColumn, rightRowIndicatorColumn);
|
detectionResult.setDetectionResultColumn(maxBarcodeColumn, rightRowIndicatorColumn);
|
||||||
|
|
|
@ -702,7 +702,7 @@ public final class PDF417 {
|
||||||
continue;
|
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
|
// ignore if previous ratio is closer to preferred ratio
|
||||||
if (dimension != null && Math.abs(newRatio - PREFERRED_RATIO) > Math.abs(ratio - 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
|
// Filter outlier possibilities whose module size is too different
|
||||||
if (startSize > 3) {
|
if (startSize > 3) {
|
||||||
// But we can only afford to do so if we have at least 4 possibilities to choose from
|
// But we can only afford to do so if we have at least 4 possibilities to choose from
|
||||||
float totalModuleSize = 0.0f;
|
double totalModuleSize = 0.0;
|
||||||
float square = 0.0f;
|
double square = 0.0;
|
||||||
for (FinderPattern center : possibleCenters) {
|
for (FinderPattern center : possibleCenters) {
|
||||||
float size = center.getEstimatedModuleSize();
|
float size = center.getEstimatedModuleSize();
|
||||||
totalModuleSize += size;
|
totalModuleSize += size;
|
||||||
square += size * size;
|
square += size * size;
|
||||||
}
|
}
|
||||||
float average = totalModuleSize / startSize;
|
double average = totalModuleSize / startSize;
|
||||||
float stdDev = (float) Math.sqrt(square / startSize - average * average);
|
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++) {
|
for (int i = 0; i < possibleCenters.size() && possibleCenters.size() > 3; i++) {
|
||||||
FinderPattern pattern = possibleCenters.get(i);
|
FinderPattern pattern = possibleCenters.get(i);
|
||||||
|
|
|
@ -589,8 +589,11 @@ public final class Encoder {
|
||||||
} catch (UnsupportedEncodingException uee) {
|
} catch (UnsupportedEncodingException uee) {
|
||||||
throw new WriterException(uee);
|
throw new WriterException(uee);
|
||||||
}
|
}
|
||||||
int length = bytes.length;
|
if (bytes.length % 2 != 0) {
|
||||||
for (int i = 0; i < length; i += 2) {
|
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 byte1 = bytes[i] & 0xFF;
|
||||||
int byte2 = bytes[i + 1] & 0xFF;
|
int byte2 = bytes[i + 1] & 0xFF;
|
||||||
int code = (byte1 << 8) | byte2;
|
int code = (byte1 << 8) | byte2;
|
||||||
|
|
Loading…
Reference in a new issue