From b61546ae341d108aab710a5de0d648ff4711c7c0 Mon Sep 17 00:00:00 2001 From: srowen Date: Sat, 14 Aug 2010 19:11:49 +0000 Subject: [PATCH] Issue 492 git-svn-id: http://zxing.googlecode.com/svn/trunk@1533 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- AUTHORS | 2 ++ .../common/AbstractBlackBoxTestCase.java | 19 ++++++++++++++++++- .../FalsePositivesBlackBoxTestCase.java | 4 ++-- .../negative/PartialBlackBoxTestCase.java | 2 +- .../negative/UnsupportedBlackBoxTestCase.java | 4 ++-- .../zxing/qrcode/QRCodeBlackBox2TestCase.java | 4 ++-- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2e66aba9..53ff30d7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -48,7 +48,9 @@ Ryan Alford Sanford Squires Sean Owen (Google) Simon Flannery (Ericsson) +Steven Parkes Suraj Supekar Sven Klinkhamer Thomas Gerbet Vince Francis (LifeMarks) +Yakov Okshtein (Google) diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index 50483439..b4dc4266 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -29,6 +29,7 @@ import junit.framework.TestCase; import javax.imageio.ImageIO; import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.awt.image.BufferedImageOp; @@ -310,9 +311,25 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { if (degrees == 0.0f) { return original; } else { + double radians = Math.toRadians(degrees); + + // Transform simply to find out the new bounding box (don't actually run the image through it) AffineTransform at = new AffineTransform(); - at.rotate(Math.toRadians(degrees), original.getWidth() / 2.0, original.getHeight() / 2.0); + at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0); BufferedImageOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC); + + Rectangle2D r = op.getBounds2D(original); + int width = (int) Math.ceil(r.getWidth()); + int height = (int) Math.ceil(r.getHeight()); + + // Real transform, now that we know the size of the new image and how to translate after we rotate + // to keep it centered + at = new AffineTransform(); + at.rotate(radians, width / 2.0, height / 2.0); + at.translate(((width - original.getWidth()) / 2.0), + ((height - original.getHeight()) / 2.0)); + op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC); + return op.filter(original, null); } } diff --git a/core/test/src/com/google/zxing/negative/FalsePositivesBlackBoxTestCase.java b/core/test/src/com/google/zxing/negative/FalsePositivesBlackBoxTestCase.java index 2d8c0b22..97e18a25 100644 --- a/core/test/src/com/google/zxing/negative/FalsePositivesBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/negative/FalsePositivesBlackBoxTestCase.java @@ -28,9 +28,9 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractNegativeBlackB public FalsePositivesBlackBoxTestCase() { super("test/data/blackbox/falsepositives"); addTest(2, 0.0f); - addTest(0, 90.0f); + addTest(1, 90.0f); addTest(1, 180.0f); - addTest(1, 270.0f); + addTest(2, 270.0f); } } diff --git a/core/test/src/com/google/zxing/negative/PartialBlackBoxTestCase.java b/core/test/src/com/google/zxing/negative/PartialBlackBoxTestCase.java index 6a63da85..227d5a48 100644 --- a/core/test/src/com/google/zxing/negative/PartialBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/negative/PartialBlackBoxTestCase.java @@ -30,7 +30,7 @@ public final class PartialBlackBoxTestCase extends AbstractNegativeBlackBoxTestC addTest(1, 0.0f); addTest(1, 90.0f); addTest(1, 180.0f); - addTest(0, 270.0f); + addTest(1, 270.0f); } } diff --git a/core/test/src/com/google/zxing/negative/UnsupportedBlackBoxTestCase.java b/core/test/src/com/google/zxing/negative/UnsupportedBlackBoxTestCase.java index 969a042f..99ebdef5 100644 --- a/core/test/src/com/google/zxing/negative/UnsupportedBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/negative/UnsupportedBlackBoxTestCase.java @@ -28,9 +28,9 @@ public final class UnsupportedBlackBoxTestCase extends AbstractNegativeBlackBoxT public UnsupportedBlackBoxTestCase() { super("test/data/blackbox/unsupported"); addTest(1, 0.0f); - addTest(0, 90.0f); + addTest(1, 90.0f); addTest(1, 180.0f); - addTest(0, 270.0f); + addTest(1, 270.0f); } } diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java index 8bee5cdf..0fc76ebe 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java @@ -28,9 +28,9 @@ public final class QRCodeBlackBox2TestCase extends AbstractBlackBoxTestCase { public QRCodeBlackBox2TestCase() { super("test/data/blackbox/qrcode-2", new MultiFormatReader(), BarcodeFormat.QR_CODE); addTest(26, 26, 0.0f); - addTest(24, 24, 90.0f); + addTest(25, 25, 90.0f); addTest(24, 24, 180.0f); - addTest(22, 23, 270.0f); + addTest(25, 25, 270.0f); } } -- 2.20.1