Issue 875 user supplied compile fix

git-svn-id: https://zxing.googlecode.com/svn/trunk@1827 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-06-19 15:22:38 +00:00
parent 0297363cfc
commit cf0b37c045
2 changed files with 154 additions and 164 deletions

View file

@ -1,4 +1,4 @@
/* /*
* Copyright 2009 ZXing authors * Copyright 2009 ZXing authors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -14,136 +14,124 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.multi package com.google.zxing.multi {
{ import com.google.zxing.BinaryBitmap;
import com.google.zxing.common.flexdatatypes.ArrayList; import com.google.zxing.Reader;
import com.google.zxing.common.flexdatatypes.HashTable; import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.flexdatatypes.ArrayList;
import com.google.zxing.common.flexdatatypes.HashTable;
/** /**
* <p>Attempts to locate multiple barcodes in an image by repeatedly decoding portion of the image. * <p>Attempts to locate multiple barcodes in an image by repeatedly decoding portion of the image.
* After one barcode is found, the areas left, above, right and below the barcode's * After one barcode is found, the areas left, above, right and below the barcode's
* {@link com.google.zxing.ResultPoint}s are scanned, recursively.</p> * {@link com.google.zxing.ResultPoint}s are scanned, recursively.</p>
* *
* <p>A caller may want to also employ {@link ByQuadrantReader} when attempting to find multiple * <p>A caller may want to also employ {@link ByQuadrantReader} when attempting to find multiple
* 2D barcodes, like QR Codes, in an image, where the presence of multiple barcodes might prevent * 2D barcodes, like QR Codes, in an image, where the presence of multiple barcodes might prevent
* detecting any one of them.</p> * detecting any one of them.</p>
* *
* <p>That is, instead of passing a {@link Reader} a caller might pass * <p>That is, instead of passing a {@link Reader} a caller might pass
* <code>new ByQuadrantReader(reader)</code>.</p> * <code>new ByQuadrantReader(reader)</code>.</p>
* *
* @author Sean Owen * @author Sean Owen
*/ */
public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader { public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader {
import Reader; private static var MIN_DIMENSION_TO_RECUR:int = 30;
import Result;
import BinaryBitmap;
import ReaderException;
import ResultPoint;
import common.flexdatatypes.HashTable;
import common.flexdatatypes.ArrayList;
private var delegate:Reader;
public function GenericMultipleBarcodeReader(delegate:Reader) {
private static var MIN_DIMENSION_TO_RECUR:int = 30; this.delegate = delegate;
private var delegate:Reader;
public function GenericMultipleBarcodeReader(delegate:Reader ) {
this.delegate = delegate;
}
public function decodeMultiple(image:BinaryBitmap , hints:HashTable=null):Array
{
var results:ArrayList = new ArrayList();
doDecodeMultiple(image, hints, results, 0, 0);
if (results.isEmpty()) {
throw new ReaderException("multi : GenericMultipleBarcodeReader : decodeMultiple");
} }
var numResults:int = results.size();
var resultArray:Array = new Array(numResults);
for (var i:int = 0; i < numResults; i++) {
resultArray[i] = (results.elementAt(i) as Result);
}
return resultArray;
}
private function doDecodeMultiple(image:BinaryBitmap, public function decodeMultiple(image:BinaryBitmap, hints:HashTable = null):Array {
hints:HashTable , var results:ArrayList = new ArrayList();
results:ArrayList, doDecodeMultiple(image, hints, results, 0, 0);
xOffset:int, if (results.isEmpty()) {
yOffset:int ):void { throw new ReaderException("multi : GenericMultipleBarcodeReader : decodeMultiple");
var result:Result;
try {
result = delegate.decode(image, hints);
} catch (re:ReaderException) {
return;
}
var alreadyFound:Boolean = false;
for (var i:int = 0; i < results.size(); i++) {
var existingResult:Result = (results.elementAt(i) as Result);
if (existingResult.getText() == result.getText()) {
alreadyFound = true;
break;
} }
} var numResults:int = results.size();
if (alreadyFound) { var resultArray:Array = new Array(numResults);
return; for (var i:int = 0; i < numResults; i++) {
} resultArray[i] = (results.elementAt(i) as Result);
results.addElement(translateResultPoints(result, xOffset, yOffset));
var resultPoints:Array = result.getResultPoints();
if (resultPoints == null || resultPoints.length == 0) {
return;
}
var width:int = image.getWidth();
var height:int = image.getHeight();
var minX:Number = width;
var minY:Number = height;
var maxX:Number = 0.0;
var maxY:Number = 0.0;
for (var i2:int = 0; i2 < resultPoints.length; i2++) {
var point:ResultPoint = resultPoints[i2];
var x:Number = point.getX();
var y:Number = point.getY();
if (x < minX) {
minX = x;
} }
if (y < minY) { return resultArray;
minY = y; }
private function doDecodeMultiple(image:BinaryBitmap, hints:HashTable, results:ArrayList,
xOffset:int, yOffset:int):void {
var result:Result;
try {
result = delegate.decode(image, hints);
} catch (re:ReaderException) {
return;
} }
if (x > maxX) { var alreadyFound:Boolean = false;
maxX = x; for (var i:int = 0; i < results.size(); i++) {
var existingResult:Result = (results.elementAt(i) as Result);
if (existingResult.getText() == result.getText()) {
alreadyFound = true;
break;
}
} }
if (y > maxY) { if (alreadyFound) {
maxY = y; return;
}
results.addElement(translateResultPoints(result, xOffset, yOffset));
var resultPoints:Array = result.getResultPoints();
if (resultPoints == null || resultPoints.length == 0) {
return;
}
var width:int = image.getWidth();
var height:int = image.getHeight();
var minX:Number = width;
var minY:Number = height;
var maxX:Number = 0.0;
var maxY:Number = 0.0;
for (var i2:int = 0; i2 < resultPoints.length; i2++) {
var point:ResultPoint = resultPoints[i2];
var x:Number = point.getX();
var y:Number = point.getY();
if (x < minX) {
minX = x;
}
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (y > maxY) {
maxY = y;
}
}
if (minX > MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image.crop(0, 0, int(minX), height), hints, results, 0, 0);
}
if (minY > MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image.crop(0, 0, width, int(minY)), hints, results, 0, 0);
}
if (maxX < width - MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image.crop(int(maxX), 0, width, height), hints, results, int(maxX), 0);
}
if (maxY < height - MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image.crop(0, int(maxY), width, height), hints, results, 0, int(maxY));
} }
} }
if (minX > MIN_DIMENSION_TO_RECUR) { private static function translateResultPoints(result:Result, xOffset:int, yOffset:int):Result {
doDecodeMultiple(image.crop(0, 0, int(minX), height), hints, results, 0, 0); var oldResultPoints:Array = result.getResultPoints();
} var newResultPoints:Array = new Array(oldResultPoints.length);
if (minY > MIN_DIMENSION_TO_RECUR) { for (var i:int = 0; i < oldResultPoints.length; i++) {
doDecodeMultiple(image.crop(0, 0, width, int(minY)), hints, results, 0, 0); var oldPoint:ResultPoint = oldResultPoints[i];
} newResultPoints[i] = new ResultPoint(oldPoint.getX() + xOffset, oldPoint.getY() + yOffset);
if (maxX < width - MIN_DIMENSION_TO_RECUR) { }
doDecodeMultiple(image.crop(int(maxX), 0, width, height), hints, results, int(maxX), 0); return new Result(result.getText(), result.getRawBytes(), newResultPoints,
} result.getBarcodeFormat());
if (maxY < height - MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image.crop(0, int(maxY), width, height), hints, results, 0, int(maxY));
} }
} }
private static function translateResultPoints(result:Result , xOffset:int , yOffset:int ):Result {
var oldResultPoints:Array = result.getResultPoints();
var newResultPoints:Array = new Array(oldResultPoints.length);
for (var i:int = 0; i < oldResultPoints.length; i++) {
var oldPoint:ResultPoint = oldResultPoints[i];
newResultPoints[i] = new ResultPoint(oldPoint.getX() + xOffset, oldPoint.getY() + yOffset);
}
return new Result(result.getText(), result.getRawBytes(), newResultPoints,
result.getBarcodeFormat());
}
}
} }

View file

@ -14,61 +14,63 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.multi.qrcode package com.google.zxing.multi.qrcode {
{
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.flexdatatypes.ArrayList;
import com.google.zxing.common.flexdatatypes.HashTable;
import com.google.zxing.common.DecoderResult; import com.google.zxing.multi.MultipleBarcodeReader;
import com.google.zxing.common.flexdatatypes.ArrayList; import com.google.zxing.multi.qrcode.detector.MultiDetector;
import com.google.zxing.common.flexdatatypes.HashTable;
import com.google.zxing.multi.MultipleBarcodeReader; import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.multi.qrcode.detector.MultiDetector;
import com.google.zxing.qrcode.QRCodeReader; /**
* This implementation can detect and decode multiple QR Codes in an image.
*
* @author Sean Owen
* @author Hannes Erven
*/
public final class QRCodeMultiReader extends QRCodeReader implements MultipleBarcodeReader {
/** private static var EMPTY_RESULT_ARRAY:Array = new Array(0);
* This implementation can detect and decode multiple QR Codes in an image.
*
* @author Sean Owen
* @author Hannes Erven
*/
public final class QRCodeMultiReader extends QRCodeReader implements MultipleBarcodeReader {
private static var EMPTY_RESULT_ARRAY:Array = new Array(0); public function decodeMultiple(image:BinaryBitmap, hints:HashTable = null):Array {
var results:ArrayList = new ArrayList();
var detectorResult:Array = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
public function decodeMultiple(image:BinaryBitmap , hints:HashTable=null):Array { for (var i:int = 0; i < detectorResult.length; i++) {
var results:ArrayList = new ArrayList(); try {
var detectorResult:Array = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); var decoderResult:DecoderResult = getDecoder().decode(detectorResult[i].getBits());
for (var i:int = 0; i < detectorResult.length; i++) { var points:Array = detectorResult[i].getPoints();
try { var result:Result = new Result(decoderResult.getText(), decoderResult.getRawBytes(),
var decoderResult:DecoderResult = getDecoder().decode(detectorResult[i].getBits()); points,
var points:Array = detectorResult[i].getPoints(); BarcodeFormat.QR_CODE);
var result:Result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, if (decoderResult.getByteSegments() != null) {
BarcodeFormat.QR_CODE); result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
if (decoderResult.getByteSegments() != null) { }
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments()); if (decoderResult.getECLevel() != null) {
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL,
decoderResult.getECLevel().toString());
}
results.addElement(result);
} catch (re:ReaderException) {
// ignore and continue
} }
if (decoderResult.getECLevel() != null) { }
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString()); if (results.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
var resultArray:Array = new Array(results.size());
for (var i2:int = 0; i2 < results.size(); i2++) {
resultArray[i2] = (results.elementAt(i2) as Result);
} }
results.addElement(result); return resultArray;
} catch (re:ReaderException) {
// ignore and continue
} }
} }
if (results.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
var resultArray:Array = new Array(results.size());
for (var i2:int = 0; i2 < results.size(); i2++) {
resultArray[i2] = (results.elementAt(i2) as Result);
}
return resultArray;
}
} }
}
} }