Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions zxing/src/main/java/cn/bingoogolapple/qrcode/zxing/ZXingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.PlanarYUVLuminanceSource;
import com.google.zxing.Result;
Expand All @@ -27,6 +28,8 @@
public class ZXingView extends QRCodeView {
private MultiFormatReader mMultiFormatReader;
private Map<DecodeHintType, Object> mHintMap;
private boolean isInvertSupported = false;
private long counter = 0;

public ZXingView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
Expand Down Expand Up @@ -75,6 +78,16 @@ public void setType(BarcodeType barcodeType, Map<DecodeHintType, Object> hintMap
setupReader();
}

public void enableInvertCode() {
isInvertSupported = true;
}

@Override
public void startSpot() {
counter = 0;
super.startSpot();
}

@Override
protected ScanResult processBitmapData(Bitmap bitmap) {
return new ScanResult(QRCodeDecoder.syncDecodeQRCode(bitmap));
Expand All @@ -85,8 +98,9 @@ protected ScanResult processData(byte[] data, int width, int height, boolean isR
Result rawResult = null;
Rect scanBoxAreaRect = null;

counter++;
try {
PlanarYUVLuminanceSource source;
LuminanceSource source;
scanBoxAreaRect = mScanBoxView.getScanBoxAreaRect(height);
if (scanBoxAreaRect != null) {
source = new PlanarYUVLuminanceSource(data, width, height, scanBoxAreaRect.left, scanBoxAreaRect.top, scanBoxAreaRect.width(),
Expand All @@ -95,6 +109,10 @@ protected ScanResult processData(byte[] data, int width, int height, boolean isR
source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
}

if (counter % 2 == 0 && isInvertSupported) {
source = source.invert();
}

rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source)));
if (rawResult == null) {
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
Expand Down Expand Up @@ -141,4 +159,4 @@ protected ScanResult processData(byte[] data, int width, int height, boolean isR
private boolean isNeedAutoZoom(BarcodeFormat barcodeFormat) {
return isAutoZoom() && barcodeFormat == BarcodeFormat.QR_CODE;
}
}
}