mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
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:
parent
0297363cfc
commit
cf0b37c045
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright 2009 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -14,136 +14,124 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.multi
|
||||
{
|
||||
import com.google.zxing.common.flexdatatypes.ArrayList;
|
||||
import com.google.zxing.common.flexdatatypes.HashTable;
|
||||
|
||||
package com.google.zxing.multi {
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.Reader;
|
||||
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.
|
||||
* 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>
|
||||
*
|
||||
* <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
|
||||
* detecting any one of them.</p>
|
||||
*
|
||||
* <p>That is, instead of passing a {@link Reader} a caller might pass
|
||||
* <code>new ByQuadrantReader(reader)</code>.</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader {
|
||||
/**
|
||||
* <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
|
||||
* {@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
|
||||
* 2D barcodes, like QR Codes, in an image, where the presence of multiple barcodes might prevent
|
||||
* detecting any one of them.</p>
|
||||
*
|
||||
* <p>That is, instead of passing a {@link Reader} a caller might pass
|
||||
* <code>new ByQuadrantReader(reader)</code>.</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader {
|
||||
|
||||
import Reader;
|
||||
import Result;
|
||||
import BinaryBitmap;
|
||||
import ReaderException;
|
||||
import ResultPoint;
|
||||
import common.flexdatatypes.HashTable;
|
||||
import common.flexdatatypes.ArrayList;
|
||||
private static var MIN_DIMENSION_TO_RECUR:int = 30;
|
||||
|
||||
private var delegate:Reader;
|
||||
|
||||
|
||||
private static var MIN_DIMENSION_TO_RECUR:int = 30;
|
||||
|
||||
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");
|
||||
public function GenericMultipleBarcodeReader(delegate:Reader) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
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,
|
||||
hints:HashTable ,
|
||||
results:ArrayList,
|
||||
xOffset:int,
|
||||
yOffset:int ):void {
|
||||
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;
|
||||
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");
|
||||
}
|
||||
}
|
||||
if (alreadyFound) {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
if (y < minY) {
|
||||
minY = y;
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
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) {
|
||||
maxX = x;
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (y > maxY) {
|
||||
maxY = y;
|
||||
if (alreadyFound) {
|
||||
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) {
|
||||
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));
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,61 +14,63 @@
|
|||
* 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.common.flexdatatypes.ArrayList;
|
||||
import com.google.zxing.common.flexdatatypes.HashTable;
|
||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||
import com.google.zxing.multi.qrcode.detector.MultiDetector;
|
||||
|
||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||
import com.google.zxing.multi.qrcode.detector.MultiDetector;
|
||||
import com.google.zxing.qrcode.QRCodeReader;
|
||||
|
||||
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 {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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);
|
||||
for (var i:int = 0; i < detectorResult.length; i++) {
|
||||
try {
|
||||
var decoderResult:DecoderResult = getDecoder().decode(detectorResult[i].getBits());
|
||||
var points:Array = detectorResult[i].getPoints();
|
||||
var result:Result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
|
||||
BarcodeFormat.QR_CODE);
|
||||
if (decoderResult.getByteSegments() != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
|
||||
public function decodeMultiple(image:BinaryBitmap, hints:HashTable = null):Array {
|
||||
var results:ArrayList = new ArrayList();
|
||||
var detectorResult:Array = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
|
||||
for (var i:int = 0; i < detectorResult.length; i++) {
|
||||
try {
|
||||
var decoderResult:DecoderResult = getDecoder().decode(detectorResult[i].getBits());
|
||||
var points:Array = detectorResult[i].getPoints();
|
||||
var result:Result = new Result(decoderResult.getText(), decoderResult.getRawBytes(),
|
||||
points,
|
||||
BarcodeFormat.QR_CODE);
|
||||
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);
|
||||
} catch (re:ReaderException) {
|
||||
// ignore and continue
|
||||
return resultArray;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue