mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
add config variable to disable zbar scanning
This commit is contained in:
parent
96fd824a3e
commit
30a9c1208a
2 changed files with 38 additions and 21 deletions
|
@ -58,6 +58,7 @@ public class Config {
|
||||||
private int enumerateHwPeriod = ENUMERATE_HW_PERIOD_SECS;
|
private int enumerateHwPeriod = ENUMERATE_HW_PERIOD_SECS;
|
||||||
private QRDensity qrDensity;
|
private QRDensity qrDensity;
|
||||||
private Boolean hdCapture;
|
private Boolean hdCapture;
|
||||||
|
private Boolean zbarScan;
|
||||||
private String webcamDevice;
|
private String webcamDevice;
|
||||||
private ServerType serverType;
|
private ServerType serverType;
|
||||||
private Server publicElectrumServer;
|
private Server publicElectrumServer;
|
||||||
|
@ -404,6 +405,14 @@ public class Config {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isZbarScan() {
|
||||||
|
return zbarScan == null || zbarScan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZbarScan(Boolean zbarScan) {
|
||||||
|
this.zbarScan = zbarScan;
|
||||||
|
}
|
||||||
|
|
||||||
public String getWebcamDevice() {
|
public String getWebcamDevice() {
|
||||||
return webcamDevice;
|
return webcamDevice;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,11 @@ public class ZBar {
|
||||||
private final static boolean enabled;
|
private final static boolean enabled;
|
||||||
|
|
||||||
static { // static initializer
|
static { // static initializer
|
||||||
enabled = loadLibrary();
|
if(com.sparrowwallet.sparrow.io.Config.get().isZbarScan()) {
|
||||||
|
enabled = loadLibrary();
|
||||||
|
} else {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public static boolean isEnabled() {
|
||||||
|
@ -23,34 +27,38 @@ public class ZBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scan scan(BufferedImage bufferedImage) {
|
public static Scan scan(BufferedImage bufferedImage) {
|
||||||
BufferedImage grayscale = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
|
try {
|
||||||
Graphics2D g2d = (Graphics2D)grayscale.getGraphics();
|
BufferedImage grayscale = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
|
||||||
g2d.drawImage(bufferedImage, 0, 0, null);
|
Graphics2D g2d = (Graphics2D)grayscale.getGraphics();
|
||||||
g2d.dispose();
|
g2d.drawImage(bufferedImage, 0, 0, null);
|
||||||
|
g2d.dispose();
|
||||||
|
|
||||||
byte[] data = convertToY800(grayscale);
|
byte[] data = convertToY800(grayscale);
|
||||||
|
|
||||||
try(Image image = new Image()) {
|
try(Image image = new Image()) {
|
||||||
image.setSize(grayscale.getWidth(), grayscale.getHeight());
|
image.setSize(grayscale.getWidth(), grayscale.getHeight());
|
||||||
image.setFormat("Y800");
|
image.setFormat("Y800");
|
||||||
image.setData(data);
|
image.setData(data);
|
||||||
|
|
||||||
try(ImageScanner scanner = new ImageScanner()) {
|
try(ImageScanner scanner = new ImageScanner()) {
|
||||||
scanner.setConfig(Symbol.NONE, Config.ENABLE, 0);
|
scanner.setConfig(Symbol.NONE, Config.ENABLE, 0);
|
||||||
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
|
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
|
||||||
int result = scanner.scanImage(image);
|
int result = scanner.scanImage(image);
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
try(SymbolSet results = scanner.getResults()) {
|
try(SymbolSet results = scanner.getResults()) {
|
||||||
Scan scan = null;
|
Scan scan = null;
|
||||||
for(Iterator<Symbol> iter = results.iterator(); iter.hasNext(); ) {
|
for(Iterator<Symbol> iter = results.iterator(); iter.hasNext(); ) {
|
||||||
try(Symbol symbol = iter.next()) {
|
try(Symbol symbol = iter.next()) {
|
||||||
scan = new Scan(symbol.getDataBytes(), symbol.getData());
|
scan = new Scan(symbol.getDataBytes(), symbol.getData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return scan;
|
||||||
}
|
}
|
||||||
return scan;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
log.debug("Error scanning with ZBar", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue