Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for inverted and normal scans at the same time #326

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion sample/src/main/java/example/zxing/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ public void scanBarcode(View view) {

public void scanBarcodeInverted(View view){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.addExtra(Intents.Scan.INVERTED_SCAN, true);
integrator.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN);
integrator.initiateScan();
}

<<<<<<< HEAD
public void scanMixedBarcodes(View view){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN);
integrator.initiateScan();
}

=======
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes
public void scanBarcodeCustomLayout(View view) {
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setCaptureActivity(AnyOrientationCaptureActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,29 @@ public static final class Scan {
*/
public static final String RESULT_BARCODE_IMAGE_PATH = "SCAN_RESULT_IMAGE_PATH";

/***
* Define the scan type.
*/
public static final String SCAN_TYPE = "SCAN_TYPE";

/***
* Scan normal barcodes white on black
*/
public static final int NORMAL_SCAN = 0;

/***
* The scan should be inverted. White becomes black, black becomes white.
*/
public static final String INVERTED_SCAN = "INVERTED_SCAN";
public static final int INVERTED_SCAN = 1;

<<<<<<< HEAD
/***
* Scan for inverted and normal badcodes at the same time.
*/
public static final int MIXED_SCAN = 2;

=======
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes
private Scan() {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,25 @@ public void initializeFromIntent(Intent intent) {
setStatusText(customPromptMessage);
}

<<<<<<< HEAD
// Check what type of scan. Default: normal scan
int scanType = intent.getIntExtra(Intents.Scan.SCAN_TYPE, 0);
=======
// Check to see if the scan should be inverted.
boolean inverted = intent.getBooleanExtra(Intents.Scan.INVERTED_SCAN, false);
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes

String characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

MultiFormatReader reader = new MultiFormatReader();
reader.setHints(decodeHints);

barcodeView.setCameraSettings(settings);
<<<<<<< HEAD
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, scanType));
=======
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, inverted));
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes
}

public void setStatusText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@ public class DefaultDecoderFactory implements DecoderFactory {
private Collection<BarcodeFormat> decodeFormats;
private Map<DecodeHintType, ?> hints;
private String characterSet;
<<<<<<< HEAD
private int scanType;
=======
private boolean inverted;
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes

public DefaultDecoderFactory() {
}

<<<<<<< HEAD
public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> hints, String characterSet, int scanType) {
this.decodeFormats = decodeFormats;
this.hints = hints;
this.characterSet = characterSet;
this.scanType = scanType;
=======
public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> hints, String characterSet, boolean inverted) {
this.decodeFormats = decodeFormats;
this.hints = hints;
this.characterSet = characterSet;
this.inverted = inverted;
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes
}

@Override
Expand All @@ -48,7 +60,23 @@ public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
MultiFormatReader reader = new MultiFormatReader();
reader.setHints(hints);

<<<<<<< HEAD
switch (scanType){
case 0:
return new Decoder(reader);
case 1:
return new InvertedDecoder(reader);
case 2:
return new MixedDecoder(reader);
default:
return new Decoder(reader);


}

=======
return inverted ? new InvertedDecoder(reader) : new Decoder(reader);
>>>>>>> parent of cf4c0dc... Added a mixed scan mode to enable scanning inverted and normal barcodes

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.journeyapps.barcodescanner;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.Reader;
import com.google.zxing.common.HybridBinarizer;

/**
* Created by alpaslanbak on 14/09/2017.
*/

public class MixedDecoder extends Decoder{
private boolean isInverted = true;

/**
* Create a new Decoder with the specified Reader.
* <p/>
* It is recommended to use an instance of MultiFormatReader in most cases.
*
* @param reader the reader
*/
public MixedDecoder(Reader reader) {
super(reader);
}

/**
* Given an image source, convert to a binary bitmap.
*
* Override this to use a custom binarizer.
*
* @param source the image source
* @return a BinaryBitmap
*/
protected BinaryBitmap toBitmap(LuminanceSource source) {

if (isInverted){
isInverted = false;
return new BinaryBitmap(new HybridBinarizer(source.invert()));
}
else{
isInverted = true;
return new BinaryBitmap(new HybridBinarizer(source));
}
}

}