Tiny speedups

git-svn-id: https://zxing.googlecode.com/svn/trunk@1111 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2009-11-17 20:32:10 +00:00
parent 58b5bf7b0f
commit 57cebcc697
2 changed files with 11 additions and 11 deletions

View file

@ -165,19 +165,17 @@ final class DecodeThread extends Thread {
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
boolean success;
Result rawResult = null;
BaseLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
success = true;
} catch (ReaderException e) {
success = false;
} catch (ReaderException re) {
// continue
}
long end = System.currentTimeMillis();
if (success) {
if (rawResult != null) {
long end = System.currentTimeMillis();
Log.v(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult);
Bundle bundle = new Bundle();

View file

@ -61,7 +61,7 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
if (row == null || row.length < width) {
row = new byte[width];
}
int offset = (y + top) * dataWidth * 2 + (left * 2);
int offset = ((y + top) * dataWidth << 1) + (left << 1);
byte[] yuv = yuvData;
for (int x = 0; x < width; x++) {
row[x] = yuv[offset + (x << 1)];
@ -75,7 +75,8 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
int height = getHeight();
int area = width * height;
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;
for (int y = 0; y < height; y++) {
@ -83,7 +84,7 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
for (int x = 0; x < width; x++) {
matrix[outputOffset + x] = yuv[inputOffset + (x << 1)];
}
inputOffset += (dataWidth * 2);
inputOffset += (dataWidth << 1);
}
return matrix;
}
@ -115,7 +116,8 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
int height = getHeight();
int[] pixels = new int[width * height];
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++) {
int outputOffset = y * width;
@ -123,7 +125,7 @@ public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource
int grey = yuv[inputOffset + (x << 1)] & 0xff;
pixels[outputOffset + x] = (0xff000000) | (grey * 0x00010101);
}
inputOffset += (dataWidth * 2);
inputOffset += (dataWidth << 1);
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);