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;
/**
// These methods use an integer calculation for luminance derived from:
// <code>Y = 0.299R + 0.587G + 0.114B</code>
+ @Override
public byte[] getRow(int y, byte[] row) {
if (y < 0 || y >= getHeight()) {
throw new IllegalArgumentException("Requested row is outside the image: " + y);
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) +
return row;
}
+ @Override
public byte[] getMatrix() {
int width = getWidth();
int height = getHeight();
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++) {
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");
// 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();