diff --git a/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java b/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java index f22268674..5c8e40b26 100644 --- a/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java +++ b/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java @@ -49,12 +49,19 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { // 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 // barcode image. Force any such pixel to be white: + int[] buffer = new int[width]; for (int y = top; y < top + height; y++) { - for (int x = left; x < left + width; x++) { - if ((image.getRGB(x, y) & 0xFF000000) == 0) { - image.setRGB(x, y, 0xFFFFFFFF); // = white + image.getRGB(left, y, width, 1, buffer, 0, sourceWidth); + boolean rowChanged = false; + 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 diff --git a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java index 0775703ab..aed8385a9 100644 --- a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java +++ b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java @@ -51,12 +51,19 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { // 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 // barcode image. Force any such pixel to be white: + int[] buffer = new int[width]; for (int y = top; y < top + height; y++) { - for (int x = left; x < left + width; x++) { - if ((image.getRGB(x, y) & 0xFF000000) == 0) { - image.setRGB(x, y, 0xFFFFFFFF); // = white + image.getRGB(left, y, width, 1, buffer, 0, sourceWidth); + boolean rowChanged = false; + 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