From 7bc138ed7a558b38963336fba0f91bb03e97f7e2 Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 26 Jun 2012 10:23:54 +0000 Subject: [PATCH] Avoid check for transparency when there is no alpha channel git-svn-id: https://zxing.googlecode.com/svn/trunk@2327 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/BufferedImageLuminanceSource.java | 24 ++++++++++--------- .../j2se/BufferedImageLuminanceSource.java | 24 ++++++++++--------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java b/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java index 5c8e40b26..28a3c34c1 100644 --- a/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java +++ b/core/test/src/com/google/zxing/BufferedImageLuminanceSource.java @@ -49,18 +49,20 @@ 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++) { - 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 (image.getAlphaRaster() != null) { + int[] buffer = new int[width]; + for (int y = top; y < top + height; y++) { + 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); } - } - if (rowChanged) { - image.setRGB(left, y, width, 1, buffer, 0, sourceWidth); } } diff --git a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java index aed8385a9..a08f27598 100644 --- a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java +++ b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java @@ -51,18 +51,20 @@ 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++) { - 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 (image.getAlphaRaster() != null) { + int[] buffer = new int[width]; + for (int y = top; y < top + height; y++) { + 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); } - } - if (rowChanged) { - image.setRGB(left, y, width, 1, buffer, 0, sourceWidth); } }