mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 1296 Faster check for transparent pixels
git-svn-id: https://zxing.googlecode.com/svn/trunk@2324 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
5e9f84dea2
commit
845b3d81e1
|
@ -49,12 +49,19 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
||||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||||
// barcode image. Force any such pixel to be white:
|
// barcode image. Force any such pixel to be white:
|
||||||
|
int[] buffer = new int[width];
|
||||||
for (int y = top; y < top + height; y++) {
|
for (int y = top; y < top + height; y++) {
|
||||||
for (int x = left; x < left + width; x++) {
|
image.getRGB(left, y, width, 1, buffer, 0, sourceWidth);
|
||||||
if ((image.getRGB(x, y) & 0xFF000000) == 0) {
|
boolean rowChanged = false;
|
||||||
image.setRGB(x, y, 0xFFFFFFFF); // = white
|
for (int x = 0; x < width; x++) {
|
||||||
|
if ((buffer[x] & 0xFF000000) == 0) {
|
||||||
|
buffer[x] = 0xFFFFFFFF; // = white
|
||||||
|
rowChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rowChanged) {
|
||||||
|
image.setRGB(left, y, width, 1, buffer, 0, sourceWidth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a grayscale copy, no need to calculate the luminance manually
|
// Create a grayscale copy, no need to calculate the luminance manually
|
||||||
|
|
|
@ -51,12 +51,19 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
||||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||||
// barcode image. Force any such pixel to be white:
|
// barcode image. Force any such pixel to be white:
|
||||||
|
int[] buffer = new int[width];
|
||||||
for (int y = top; y < top + height; y++) {
|
for (int y = top; y < top + height; y++) {
|
||||||
for (int x = left; x < left + width; x++) {
|
image.getRGB(left, y, width, 1, buffer, 0, sourceWidth);
|
||||||
if ((image.getRGB(x, y) & 0xFF000000) == 0) {
|
boolean rowChanged = false;
|
||||||
image.setRGB(x, y, 0xFFFFFFFF); // = white
|
for (int x = 0; x < width; x++) {
|
||||||
|
if ((buffer[x] & 0xFF000000) == 0) {
|
||||||
|
buffer[x] = 0xFFFFFFFF; // = white
|
||||||
|
rowChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rowChanged) {
|
||||||
|
image.setRGB(left, y, width, 1, buffer, 0, sourceWidth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a grayscale copy, no need to calculate the luminance manually
|
// Create a grayscale copy, no need to calculate the luminance manually
|
||||||
|
|
Loading…
Reference in a new issue