mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-21 22:39:12 +00:00
Remove padding from Y plane data before passing it to ZXing
Fixes #726 Fixes #657
This commit is contained in:
parent
a62e474e33
commit
fb58c877d1
1 changed files with 28 additions and 5 deletions
|
@ -43,11 +43,7 @@ public class QrCodeAnalyzer implements ImageAnalysis.Analyzer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer buf = image.getPlanes()[0].getBuffer();
|
byte[] data = getLuminancePlaneData(image);
|
||||||
byte[] data = new byte[buf.remaining()];
|
|
||||||
buf.get(data);
|
|
||||||
buf.rewind();
|
|
||||||
|
|
||||||
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(
|
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(
|
||||||
data, image.getWidth(), image.getHeight(), 0, 0, image.getWidth(), image.getHeight(), false
|
data, image.getWidth(), image.getHeight(), 0, 0, image.getWidth(), image.getHeight(), false
|
||||||
);
|
);
|
||||||
|
@ -66,6 +62,33 @@ public class QrCodeAnalyzer implements ImageAnalysis.Analyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] getLuminancePlaneData(ImageProxy image) {
|
||||||
|
ImageProxy.PlaneProxy plane = image.getPlanes()[0];
|
||||||
|
ByteBuffer buf = plane.getBuffer();
|
||||||
|
byte[] data = new byte[buf.remaining()];
|
||||||
|
buf.get(data);
|
||||||
|
buf.rewind();
|
||||||
|
|
||||||
|
int width = image.getWidth();
|
||||||
|
int height = image.getHeight();
|
||||||
|
int rowStride = plane.getRowStride();
|
||||||
|
int pixelStride = plane.getPixelStride();
|
||||||
|
|
||||||
|
if (width != rowStride || pixelStride != 1) {
|
||||||
|
// remove padding from the Y plane data
|
||||||
|
byte[] cleanData = new byte[width * height];
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
cleanData[y * width + x] = data[y * rowStride + x * pixelStride];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanData;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
void onQrCodeDetected(Result result);
|
void onQrCodeDetected(Result result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue