mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Tiny speedups
git-svn-id: https://zxing.googlecode.com/svn/trunk@1111 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
58b5bf7b0f
commit
57cebcc697
|
@ -165,19 +165,17 @@ final class DecodeThread extends Thread {
|
||||||
*/
|
*/
|
||||||
private void decode(byte[] data, int width, int height) {
|
private void decode(byte[] data, int width, int height) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
boolean success;
|
|
||||||
Result rawResult = null;
|
Result rawResult = null;
|
||||||
BaseLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);
|
BaseLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);
|
||||||
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
||||||
try {
|
try {
|
||||||
rawResult = multiFormatReader.decodeWithState(bitmap);
|
rawResult = multiFormatReader.decodeWithState(bitmap);
|
||||||
success = true;
|
} catch (ReaderException re) {
|
||||||
} catch (ReaderException e) {
|
// continue
|
||||||
success = false;
|
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
|
|
||||||
if (success) {
|
if (rawResult != null) {
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
Log.v(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
|
Log.v(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
|
||||||
Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult);
|
Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult);
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
|
@ -61,7 +61,7 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
|
||||||
if (row == null || row.length < width) {
|
if (row == null || row.length < width) {
|
||||||
row = new byte[width];
|
row = new byte[width];
|
||||||
}
|
}
|
||||||
int offset = (y + top) * dataWidth * 2 + (left * 2);
|
int offset = ((y + top) * dataWidth << 1) + (left << 1);
|
||||||
byte[] yuv = yuvData;
|
byte[] yuv = yuvData;
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
row[x] = yuv[offset + (x << 1)];
|
row[x] = yuv[offset + (x << 1)];
|
||||||
|
@ -75,7 +75,8 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
|
||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
int area = width * height;
|
int area = width * height;
|
||||||
byte[] matrix = new byte[area];
|
byte[] matrix = new byte[area];
|
||||||
int inputOffset = top * dataWidth * 2 + (left * 2);
|
int dataWidth = this.dataWidth;
|
||||||
|
int inputOffset = (top * dataWidth << 1) + (left << 1);
|
||||||
byte[] yuv = yuvData;
|
byte[] yuv = yuvData;
|
||||||
|
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
|
@ -83,7 +84,7 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
matrix[outputOffset + x] = yuv[inputOffset + (x << 1)];
|
matrix[outputOffset + x] = yuv[inputOffset + (x << 1)];
|
||||||
}
|
}
|
||||||
inputOffset += (dataWidth * 2);
|
inputOffset += (dataWidth << 1);
|
||||||
}
|
}
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +116,8 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
|
||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
int[] pixels = new int[width * height];
|
int[] pixels = new int[width * height];
|
||||||
byte[] yuv = yuvData;
|
byte[] yuv = yuvData;
|
||||||
int inputOffset = top * dataWidth * 2 + (left * 2);
|
int dataWidth = this.dataWidth;
|
||||||
|
int inputOffset = (top * dataWidth << 1) + (left << 1);
|
||||||
|
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
int outputOffset = y * width;
|
int outputOffset = y * width;
|
||||||
|
@ -123,7 +125,7 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
|
||||||
int grey = yuv[inputOffset + (x << 1)] & 0xff;
|
int grey = yuv[inputOffset + (x << 1)] & 0xff;
|
||||||
pixels[outputOffset + x] = (0xff000000) | (grey * 0x00010101);
|
pixels[outputOffset + x] = (0xff000000) | (grey * 0x00010101);
|
||||||
}
|
}
|
||||||
inputOffset += (dataWidth * 2);
|
inputOffset += (dataWidth << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
|
Loading…
Reference in a new issue