From 16e49142c0aff5057cf45abd4cecc60a0afaa76d Mon Sep 17 00:00:00 2001 From: dswitkin Date: Wed, 15 Jul 2009 18:32:01 +0000 Subject: [PATCH] Added an optimization to the Android client's LuminanceSource implementation, and removed manual array copies in favor of System.arraycopy(). git-svn-id: http://zxing.googlecode.com/svn/trunk@1020 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../client/android/YUVLuminanceSource.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/android/src/com/google/zxing/client/android/YUVLuminanceSource.java b/android/src/com/google/zxing/client/android/YUVLuminanceSource.java index b48620ca..36260380 100644 --- a/android/src/com/google/zxing/client/android/YUVLuminanceSource.java +++ b/android/src/com/google/zxing/client/android/YUVLuminanceSource.java @@ -59,10 +59,7 @@ public final class YUVLuminanceSource extends LuminanceSource { row = new byte[width]; } int offset = (y + top) * dataWidth + left; - byte[] yuv = yuvData; - for (int x = 0; x < width; x++) { - row[x] = yuv[offset + x]; - } + System.arraycopy(yuvData, offset, row, 0, width); return row; } @@ -78,14 +75,19 @@ public final class YUVLuminanceSource extends LuminanceSource { int area = width * height; byte[] matrix = new byte[area]; - byte[] yuv = yuvData; int inputOffset = top * dataWidth + left; + + // If the width matches the full width of the underlying data, perform a single copy. + if (width == dataWidth) { + System.arraycopy(yuvData, inputOffset, matrix, 0, area); + return matrix; + } + + // Otherwise copy one cropped row at a time. + byte[] yuv = yuvData; for (int y = 0; y < height; y++) { int outputOffset = y * width; - for (int x = 0; x < width; x++) { - // TODO: Compare performance with using System.arraycopy(). - matrix[outputOffset + x] = yuv[inputOffset + x]; - } + System.arraycopy(yuv, inputOffset, matrix, outputOffset, width); inputOffset += dataWidth; } return matrix; -- 2.20.1