diff options
| author | dswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2008-10-30 21:44:10 +0300 |
|---|---|---|
| committer | dswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2008-10-30 21:44:10 +0300 |
| commit | eb2b98b51464bc8c12fe002df2edd83ab1338ebf (patch) | |
| tree | c38df0f06e380664b392edb8727f0b20b6e6a125 | |
| parent | 0c6e76ad4427ea705dd7e1fdd43418d55fcb5748 (diff) | |
| download | zxing-android-embedded-eb2b98b51464bc8c12fe002df2edd83ab1338ebf.tar.xz | |
Did a big refactoring on the MonochromeBitmapSource. I removed all the caching luminance calls and converted them to getting luminance data on demand. This saved another 33,000 function calls per rejected scan, good for another 15 ms savings. I also moved the luminance calls to BaseMonochromeBitmapSource and made them protected, to indicate that the decoders shouldn't use them.
Overall the recent optimizations took one rejected scan from 307 to 135 ms, which is definitely noticeable.
WARNING: I am not able to build the Bug or J2ME clients, but I believe they are correct.
git-svn-id: http://zxing.googlecode.com/svn/trunk/android@656 59b500cc-1b3d-0410-9834-0bbf25fbcc57
| -rwxr-xr-x | src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java b/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java index 15021b81..d3e97820 100755 --- a/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java +++ b/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java @@ -63,17 +63,33 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource { * @param y The y coordinate to fetch within crop * @return The luminance as an int, from 0-255 */ - public int getLuminance(int x, int y) { + protected int getLuminance(int x, int y) { return mYUVData[(y + mCrop.top) * mDataWidth + x + mCrop.left] & 0xff; } - // Nothing to do, since we have direct access to the mYUVData array. - public void cacheRowForLuminance(int y) { - + protected int[] getLuminanceRow(int y, int[] row) { + int width = getWidth(); + if (row == null || row.length < width) { + row = new int[width]; + } + int offset = (y + mCrop.top) * mDataWidth + mCrop.left; + for (int x = 0; x < width; x++) { + row[x] = mYUVData[offset + x] & 0xff; + } + return row; } - public void cacheColumnForLuminance(int x) { - + protected int[] getLuminanceColumn(int x, int[] column) { + int height = getHeight(); + if (column == null || column.length < height) { + column = new int[height]; + } + int offset = mCrop.top * mDataWidth + mCrop.left + x; + for (int y = 0; y < height; y++) { + column[y] = mYUVData[offset] & 0xff; + offset += mDataWidth; + } + return column; } /** |
