From f5df4e5adcfa2d0bd6561b99661d8222335542d4 Mon Sep 17 00:00:00 2001 From: srowen Date: Sat, 12 Nov 2011 11:05:00 +0000 Subject: [PATCH] Issue 1059 treat transparent areas as white git-svn-id: https://zxing.googlecode.com/svn/trunk@2028 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../client/j2se/BufferedImageLuminanceSource.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java index 2aadb2da4..dce3f02cf 100644 --- a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java +++ b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java @@ -47,6 +47,18 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { if (left + width > sourceWidth || top + height > sourceHeight) { throw new IllegalArgumentException("Crop rectangle does not fit within image data."); } + + // 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: + for (int i = top; i < top + height; i++) { + for (int j = left; j < left + width; j++) { + if ((image.getRGB(i, j) & 0xFF000000) == 0) { + image.setRGB(i, j, 0xFFFFFFFF); // = white + } + } + } + // Create a grayscale copy, no need to calculate the luminance manually this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); this.image.getGraphics().drawImage(image, 0, 0, null);