add config variable to disable zbar scanning

This commit is contained in:
Craig Raw 2023-07-17 08:48:34 +02:00
parent 96fd824a3e
commit 30a9c1208a
2 changed files with 38 additions and 21 deletions

View file

@ -58,6 +58,7 @@ public class Config {
private int enumerateHwPeriod = ENUMERATE_HW_PERIOD_SECS;
private QRDensity qrDensity;
private Boolean hdCapture;
private Boolean zbarScan;
private String webcamDevice;
private ServerType serverType;
private Server publicElectrumServer;
@ -404,6 +405,14 @@ public class Config {
flush();
}
public Boolean isZbarScan() {
return zbarScan == null || zbarScan;
}
public void setZbarScan(Boolean zbarScan) {
this.zbarScan = zbarScan;
}
public String getWebcamDevice() {
return webcamDevice;
}

View file

@ -15,7 +15,11 @@ public class ZBar {
private final static boolean enabled;
static { // static initializer
if(com.sparrowwallet.sparrow.io.Config.get().isZbarScan()) {
enabled = loadLibrary();
} else {
enabled = false;
}
}
public static boolean isEnabled() {
@ -23,6 +27,7 @@ public class ZBar {
}
public static Scan scan(BufferedImage bufferedImage) {
try {
BufferedImage grayscale = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2d = (Graphics2D)grayscale.getGraphics();
g2d.drawImage(bufferedImage, 0, 0, null);
@ -52,6 +57,9 @@ public class ZBar {
}
}
}
} catch(Exception e) {
log.debug("Error scanning with ZBar", e);
}
return null;
}