CodaBarReader.java (zxing-zxing-3.4.1) | : | CodaBarReader.java (zxing-zxing-3.5.0) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | |||
* limitations under the License. | * limitations under the License. | |||
*/ | */ | |||
package com.google.zxing.oned; | package com.google.zxing.oned; | |||
import com.google.zxing.BarcodeFormat; | import com.google.zxing.BarcodeFormat; | |||
import com.google.zxing.DecodeHintType; | import com.google.zxing.DecodeHintType; | |||
import com.google.zxing.NotFoundException; | import com.google.zxing.NotFoundException; | |||
import com.google.zxing.Result; | import com.google.zxing.Result; | |||
import com.google.zxing.ResultMetadataType; | ||||
import com.google.zxing.ResultPoint; | import com.google.zxing.ResultPoint; | |||
import com.google.zxing.common.BitArray; | import com.google.zxing.common.BitArray; | |||
import java.util.Arrays; | import java.util.Arrays; | |||
import java.util.Map; | import java.util.Map; | |||
/** | /** | |||
* <p>Decodes Codabar barcodes.</p> | * <p>Decodes Codabar barcodes.</p> | |||
* | * | |||
* @author Bas Vijfwinkel | * @author Bas Vijfwinkel | |||
skipping to change at line 155 | skipping to change at line 156 | |||
int runningCount = 0; | int runningCount = 0; | |||
for (int i = 0; i < startOffset; i++) { | for (int i = 0; i < startOffset; i++) { | |||
runningCount += counters[i]; | runningCount += counters[i]; | |||
} | } | |||
float left = runningCount; | float left = runningCount; | |||
for (int i = startOffset; i < nextStart - 1; i++) { | for (int i = startOffset; i < nextStart - 1; i++) { | |||
runningCount += counters[i]; | runningCount += counters[i]; | |||
} | } | |||
float right = runningCount; | float right = runningCount; | |||
return new Result( | ||||
Result result = new Result( | ||||
decodeRowResult.toString(), | decodeRowResult.toString(), | |||
null, | null, | |||
new ResultPoint[]{ | new ResultPoint[]{ | |||
new ResultPoint(left, rowNumber), | new ResultPoint(left, rowNumber), | |||
new ResultPoint(right, rowNumber)}, | new ResultPoint(right, rowNumber)}, | |||
BarcodeFormat.CODABAR); | BarcodeFormat.CODABAR); | |||
result.putMetadata(ResultMetadataType.SYMBOLOGY_IDENTIFIER, "]F0"); | ||||
return result; | ||||
} | } | |||
private void validatePattern(int start) throws NotFoundException { | private void validatePattern(int start) throws NotFoundException { | |||
// First, sum up the total size of our four categories of stripe sizes; | // First, sum up the total size of our four categories of stripe sizes; | |||
int[] sizes = {0, 0, 0, 0}; | int[] sizes = {0, 0, 0, 0}; | |||
int[] counts = {0, 0, 0, 0}; | int[] counts = {0, 0, 0, 0}; | |||
int end = decodeRowResult.length() - 1; | int end = decodeRowResult.length() - 1; | |||
// We break out of this loop in the middle, in order to handle | // We break out of this loop in the middle, in order to handle | |||
// inter-character spaces properly. | // inter-character spaces properly. | |||
int pos = start; | int pos = start; | |||
for (int i = 0; true; i++) { | for (int i = 0; i <= end; i++) { | |||
int pattern = CHARACTER_ENCODINGS[decodeRowResult.charAt(i)]; | int pattern = CHARACTER_ENCODINGS[decodeRowResult.charAt(i)]; | |||
for (int j = 6; j >= 0; j--) { | for (int j = 6; j >= 0; j--) { | |||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for | // Even j = bars, while odd j = spaces. Categories 2 and 3 are for | |||
// long stripes, while 0 and 1 are for short stripes. | // long stripes, while 0 and 1 are for short stripes. | |||
int category = (j & 1) + (pattern & 1) * 2; | int category = (j & 1) + (pattern & 1) * 2; | |||
sizes[category] += counters[pos + j]; | sizes[category] += counters[pos + j]; | |||
counts[category]++; | counts[category]++; | |||
pattern >>= 1; | pattern >>= 1; | |||
} | } | |||
if (i >= end) { | ||||
break; | ||||
} | ||||
// We ignore the inter-character space - it could be of any size. | // We ignore the inter-character space - it could be of any size. | |||
pos += 8; | pos += 8; | |||
} | } | |||
// Calculate our allowable size thresholds using fixed-point math. | // Calculate our allowable size thresholds using fixed-point math. | |||
float[] maxes = new float[4]; | float[] maxes = new float[4]; | |||
float[] mins = new float[4]; | float[] mins = new float[4]; | |||
// Define the threshold of acceptability to be the midpoint between the | // Define the threshold of acceptability to be the midpoint between the | |||
// average small stripe and the average large stripe. No stripe lengths | // average small stripe and the average large stripe. No stripe lengths | |||
// should be on the "wrong" side of that line. | // should be on the "wrong" side of that line. | |||
for (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | |||
mins[i] = 0.0f; // Accept arbitrarily small "short" stripes. | mins[i] = 0.0f; // Accept arbitrarily small "short" stripes. | |||
mins[i + 2] = ((float) sizes[i] / counts[i] + (float) sizes[i + 2] / count s[i + 2]) / 2.0f; | mins[i + 2] = ((float) sizes[i] / counts[i] + (float) sizes[i + 2] / count s[i + 2]) / 2.0f; | |||
maxes[i] = mins[i + 2]; | maxes[i] = mins[i + 2]; | |||
maxes[i + 2] = (sizes[i + 2] * MAX_ACCEPTABLE + PADDING) / counts[i + 2]; | maxes[i + 2] = (sizes[i + 2] * MAX_ACCEPTABLE + PADDING) / counts[i + 2]; | |||
} | } | |||
// Now verify that all of the stripes are within the thresholds. | // Now verify that all of the stripes are within the thresholds. | |||
pos = start; | pos = start; | |||
for (int i = 0; true; i++) { | for (int i = 0; i <= end; i++) { | |||
int pattern = CHARACTER_ENCODINGS[decodeRowResult.charAt(i)]; | int pattern = CHARACTER_ENCODINGS[decodeRowResult.charAt(i)]; | |||
for (int j = 6; j >= 0; j--) { | for (int j = 6; j >= 0; j--) { | |||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for | // Even j = bars, while odd j = spaces. Categories 2 and 3 are for | |||
// long stripes, while 0 and 1 are for short stripes. | // long stripes, while 0 and 1 are for short stripes. | |||
int category = (j & 1) + (pattern & 1) * 2; | int category = (j & 1) + (pattern & 1) * 2; | |||
int size = counters[pos + j]; | int size = counters[pos + j]; | |||
if (size < mins[category] || size > maxes[category]) { | if (size < mins[category] || size > maxes[category]) { | |||
throw NotFoundException.getNotFoundInstance(); | throw NotFoundException.getNotFoundInstance(); | |||
} | } | |||
pattern >>= 1; | pattern >>= 1; | |||
} | } | |||
if (i >= end) { | ||||
break; | ||||
} | ||||
pos += 8; | pos += 8; | |||
} | } | |||
} | } | |||
/** | /** | |||
* Records the size of all runs of white and black pixels, starting with white . | * Records the size of all runs of white and black pixels, starting with white . | |||
* This is just like recordPattern, except it records all the counters, and | * This is just like recordPattern, except it records all the counters, and | |||
* uses our builtin "counters" member for storage. | * uses our builtin "counters" member for storage. | |||
* @param row row to count from | * @param row row to count from | |||
*/ | */ | |||
End of changes. 7 change blocks. | ||||
9 lines changed or deleted | 7 lines changed or added |