X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=javase%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2se%2FBufferedImageLuminanceSource.java;h=2d613ccf19dcfd0419e1914366872ea9e080b972;hb=9e65454f51088f4ce539cdc445182bd6c060369c;hp=b251eb79c68ece46d18f5a2c1f8101caee4982d0;hpb=afc10a58143505842f5a3433ba5675d45346f0be;p=zxing.git diff --git a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java index b251eb79..2d613ccf 100644 --- a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java +++ b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java @@ -18,9 +18,8 @@ package com.google.zxing.client.j2se; import com.google.zxing.LuminanceSource; +import java.awt.Graphics2D; import java.awt.image.BufferedImage; -import java.awt.image.BufferedImageOp; -import java.awt.image.AffineTransformOp; import java.awt.geom.AffineTransform; /** @@ -57,6 +56,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { // These methods use an integer calculation for luminance derived from: // Y = 0.299R + 0.587G + 0.114B + @Override public byte[] getRow(int y, byte[] row) { if (y < 0 || y >= getHeight()) { throw new IllegalArgumentException("Requested row is outside the image: " + y); @@ -69,7 +69,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { if (rgbData == null || rgbData.length < width) { rgbData = new int[width]; } - image.getRGB(left, top + y, width, 1, rgbData, 0, image.getWidth()); + image.getRGB(left, top + y, width, 1, rgbData, 0, width); for (int x = 0; x < width; x++) { int pixel = rgbData[x]; int luminance = (306 * ((pixel >> 16) & 0xFF) + @@ -80,6 +80,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { return row; } + @Override public byte[] getMatrix() { int width = getWidth(); int height = getHeight(); @@ -87,7 +88,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { byte[] matrix = new byte[area]; int[] rgb = new int[area]; - image.getRGB(left, top, width, height, rgb, 0, image.getWidth()); + image.getRGB(left, top, width, height, rgb, 0, width); for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { @@ -101,19 +102,23 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { return matrix; } + @Override public boolean isCropSupported() { return true; } + @Override public LuminanceSource crop(int left, int top, int width, int height) { - return new BufferedImageLuminanceSource(image, left, top, width, height); + return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height); } // Can't run AffineTransforms on images of unknown format. + @Override public boolean isRotateSupported() { return image.getType() != BufferedImage.TYPE_CUSTOM; } + @Override public LuminanceSource rotateCounterClockwise() { if (!isRotateSupported()) { throw new IllegalStateException("Rotate not supported"); @@ -123,11 +128,14 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { // Rotate 90 degrees counterclockwise. AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); - BufferedImageOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); // Note width/height are flipped since we are rotating 90 degrees. BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, image.getType()); - op.filter(image, rotatedImage); + + // Draw the original image into rotated, via transformation + Graphics2D g = rotatedImage.createGraphics(); + g.drawImage(image, transform, null); + g.dispose(); // Maintain the cropped region, but rotate it too. int width = getWidth();