mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Don't crop camera preview before decoding.
This commit is contained in:
@@ -73,8 +73,7 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
if (data.length == size.width * size.height * 3 / 2) {
|
if (data.length == size.width * size.height * 3 / 2) {
|
||||||
CameraInfo info = new CameraInfo();
|
CameraInfo info = new CameraInfo();
|
||||||
Camera.getCameraInfo(cameraIndex, info);
|
Camera.getCameraInfo(cameraIndex, info);
|
||||||
new DecoderTask(data, size.width, size.height,
|
new DecoderTask(data, size.width, size.height).execute();
|
||||||
info.orientation).execute();
|
|
||||||
} else {
|
} else {
|
||||||
// Camera parameters have changed - ask for a new preview
|
// Camera parameters have changed - ask for a new preview
|
||||||
LOG.info("Preview size does not match camera parameters");
|
LOG.info("Preview size does not match camera parameters");
|
||||||
@@ -91,19 +90,18 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
private class DecoderTask extends AsyncTask<Void, Void, Void> {
|
private class DecoderTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private final byte[] data;
|
private final byte[] data;
|
||||||
private final int width, height, orientation;
|
private final int width;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
private DecoderTask(byte[] data, int width, int height,
|
private DecoderTask(byte[] data, int width, int height) {
|
||||||
int orientation) {
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.orientation = orientation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
BinaryBitmap bitmap = binarize(data, width, height, orientation);
|
BinaryBitmap bitmap = binarize(data, width, height);
|
||||||
Result result;
|
Result result;
|
||||||
try {
|
try {
|
||||||
result = reader.decode(bitmap,
|
result = reader.decode(bitmap,
|
||||||
@@ -127,16 +125,9 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BinaryBitmap binarize(byte[] data, int width, int height,
|
private static BinaryBitmap binarize(byte[] data, int width, int height) {
|
||||||
int orientation) {
|
|
||||||
// Crop to a square at the top (portrait) or left (landscape) of the
|
|
||||||
// screen - this will be faster to decode and should include
|
|
||||||
// everything visible in the viewfinder
|
|
||||||
int crop = Math.min(width, height);
|
|
||||||
int left = orientation >= 180 ? width - crop : 0;
|
|
||||||
int top = orientation >= 180 ? height - crop : 0;
|
|
||||||
LuminanceSource src = new PlanarYUVLuminanceSource(data, width,
|
LuminanceSource src = new PlanarYUVLuminanceSource(data, width,
|
||||||
height, left, top, crop, crop, false);
|
height, 0, 0, width, height, false);
|
||||||
return new BinaryBitmap(new HybridBinarizer(src));
|
return new BinaryBitmap(new HybridBinarizer(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user