projects
/
zxing.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
For better handling of some formats, perform rotation with help of Graphics2D
[zxing.git]
/
javase
/
src
/
com
/
google
/
zxing
/
client
/
j2se
/
BufferedImageLuminanceSource.java
diff --git
a/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java
b/javase/src/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java
index
b251eb7
..
2d613cc
100644
(file)
--- 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 com.google.zxing.LuminanceSource;
+import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
-import java.awt.image.AffineTransformOp;
import java.awt.geom.AffineTransform;
/**
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:
// <code>Y = 0.299R + 0.587G + 0.114B</code>
// 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);
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];
}
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) +
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;
}
return row;
}
+ @Override
public byte[] getMatrix() {
int width = getWidth();
int height = getHeight();
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];
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++) {
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;
}
return matrix;
}
+ @Override
public boolean isCropSupported() {
return true;
}
public boolean isCropSupported() {
return true;
}
+ @Override
public LuminanceSource crop(int left, int top, int width, int height) {
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.
}
// Can't run AffineTransforms on images of unknown format.
+ @Override
public boolean isRotateSupported() {
return image.getType() != BufferedImage.TYPE_CUSTOM;
}
public boolean isRotateSupported() {
return image.getType() != BufferedImage.TYPE_CUSTOM;
}
+ @Override
public LuminanceSource rotateCounterClockwise() {
if (!isRotateSupported()) {
throw new IllegalStateException("Rotate not supported");
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);
// 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());
// 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();
// Maintain the cropped region, but rotate it too.
int width = getWidth();