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
This commit is contained in:
srowen 2012-06-26 10:23:54 +00:00
parent f0fb20f055
commit 7bc138ed7a
2 changed files with 26 additions and 22 deletions

View file

@ -49,6 +49,7 @@ 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:
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);
@ -63,6 +64,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
image.setRGB(left, y, width, 1, buffer, 0, sourceWidth);
}
}
}
// Create a grayscale copy, no need to calculate the luminance manually
this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);

View file

@ -51,6 +51,7 @@ 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:
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);
@ -65,6 +66,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
image.setRGB(left, y, width, 1, buffer, 0, sourceWidth);
}
}
}
// Create a grayscale copy, no need to calculate the luminance manually
this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);