Added an optimization to the Android client's LuminanceSource implementation, and removed manual array copies in favor of System.arraycopy().

git-svn-id: https://zxing.googlecode.com/svn/trunk@1020 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2009-07-15 18:32:01 +00:00
parent c51c5800f6
commit 38f73bca64

View file

@ -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;