Add result points for UPC EAN metadata extension

git-svn-id: https://zxing.googlecode.com/svn/trunk@1519 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-08-11 13:59:48 +00:00
parent 6f3d6a0eff
commit 09b0039530
4 changed files with 44 additions and 13 deletions

View file

@ -506,8 +506,13 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
paint.setColor(getResources().getColor(R.color.result_points));
if (points.length == 2) {
paint.setStrokeWidth(4.0f);
canvas.drawLine(points[0].getX(), points[0].getY(), points[1].getX(),
points[1].getY(), paint);
drawLine(canvas, paint, points[0], points[1]);
} else if (points.length == 4 &&
(rawResult.getBarcodeFormat().equals(BarcodeFormat.UPC_A)) ||
(rawResult.getBarcodeFormat().equals(BarcodeFormat.EAN_13))) {
// Hacky special case -- draw two lines, for the barcode and metadata
drawLine(canvas, paint, points[0], points[1]);
drawLine(canvas, paint, points[2], points[3]);
} else {
paint.setStrokeWidth(10.0f);
for (ResultPoint point : points) {
@ -517,6 +522,10 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
}
}
private static void drawLine(Canvas canvas, Paint paint, ResultPoint a, ResultPoint b) {
canvas.drawLine(a.getX(), a.getY(), b.getX(), b.getY(), paint);
}
// Put up our own UI for how to handle the decoded contents.
private void handleDecodeInternally(Result rawResult, Bitmap barcode) {
statusView.setVisibility(View.GONE);

View file

@ -28,7 +28,7 @@ public final class Result {
private final String text;
private final byte[] rawBytes;
private final ResultPoint[] resultPoints;
private ResultPoint[] resultPoints;
private final BarcodeFormat format;
private Hashtable resultMetadata;
private final long timestamp;
@ -117,6 +117,17 @@ public final class Result {
}
}
public void addResultPoints(ResultPoint[] newPoints) {
if (resultPoints == null) {
resultPoints = newPoints;
} else if (newPoints != null && newPoints.length > 0) {
ResultPoint[] allPoints = new ResultPoint[resultPoints.length + newPoints.length];
System.arraycopy(resultPoints, 0, allPoints, 0, resultPoints.length);
System.arraycopy(newPoints, 0, allPoints, resultPoints.length, newPoints.length);
resultPoints = allPoints;
}
}
public long getTimestamp() {
return timestamp;
}

View file

@ -22,6 +22,7 @@ import com.google.zxing.BarcodeFormat;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitArray;
final class UPCEANExtensionSupport {
@ -34,18 +35,25 @@ final class UPCEANExtensionSupport {
private final int[] decodeMiddleCounters = new int[4];
private final StringBuffer decodeRowStringBuffer = new StringBuffer();
Result decodeRow(BitArray row, int rowOffset) throws NotFoundException {
Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException {
int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN);
StringBuffer result = decodeRowStringBuffer;
result.setLength(0);
decodeMiddle(row, extensionStartRange, result);
int end = decodeMiddle(row, extensionStartRange, result);
String resultString = result.toString();
Hashtable extensionData = parseExtensionString(resultString);
Result extensionResult = new Result(resultString, null, null, BarcodeFormat.UPC_EAN_EXTENSION);
Result extensionResult =
new Result(resultString,
null,
new ResultPoint[] {
new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
new ResultPoint((float) end, (float) rowNumber),
},
BarcodeFormat.UPC_EAN_EXTENSION);
if (extensionData != null) {
extensionResult.putAllMetadata(extensionData);
}
@ -72,12 +80,14 @@ final class UPCEANExtensionSupport {
if (bestMatch >= 10) {
lgPatternFound |= 1 << (4 - x);
}
// Read off separator
while (rowOffset < end && !row.get(rowOffset)) {
rowOffset++;
}
while (rowOffset < end && row.get(rowOffset)) {
rowOffset++;
if (x != 4) {
// Read off separator if not last
while (rowOffset < end && !row.get(rowOffset)) {
rowOffset++;
}
while (rowOffset < end && row.get(rowOffset)) {
rowOffset++;
}
}
}

View file

@ -186,8 +186,9 @@ public abstract class UPCEANReader extends OneDReader {
format);
try {
Result extensionResult = extensionReader.decodeRow(row, endRange[1]);
Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
decodeResult.putAllMetadata(extensionResult.getResultMetadata());
decodeResult.addResultPoints(extensionResult.getResultPoints());
} catch (ReaderException re) {
// continue
}