mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
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:
parent
c51c5800f6
commit
38f73bca64
|
@ -59,10 +59,7 @@ public final class YUVLuminanceSource extends LuminanceSource {
|
||||||
row = new byte[width];
|
row = new byte[width];
|
||||||
}
|
}
|
||||||
int offset = (y + top) * dataWidth + left;
|
int offset = (y + top) * dataWidth + left;
|
||||||
byte[] yuv = yuvData;
|
System.arraycopy(yuvData, offset, row, 0, width);
|
||||||
for (int x = 0; x < width; x++) {
|
|
||||||
row[x] = yuv[offset + x];
|
|
||||||
}
|
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +75,19 @@ public final class YUVLuminanceSource extends LuminanceSource {
|
||||||
|
|
||||||
int area = width * height;
|
int area = width * height;
|
||||||
byte[] matrix = new byte[area];
|
byte[] matrix = new byte[area];
|
||||||
byte[] yuv = yuvData;
|
|
||||||
int inputOffset = top * dataWidth + left;
|
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++) {
|
for (int y = 0; y < height; y++) {
|
||||||
int outputOffset = y * width;
|
int outputOffset = y * width;
|
||||||
for (int x = 0; x < width; x++) {
|
System.arraycopy(yuv, inputOffset, matrix, outputOffset, width);
|
||||||
// TODO: Compare performance with using System.arraycopy().
|
|
||||||
matrix[outputOffset + x] = yuv[inputOffset + x];
|
|
||||||
}
|
|
||||||
inputOffset += dataWidth;
|
inputOffset += dataWidth;
|
||||||
}
|
}
|
||||||
return matrix;
|
return matrix;
|
||||||
|
|
Loading…
Reference in a new issue