From 5c17a1ad71f77a28989b2cffb92b9d77de3e8eb6 Mon Sep 17 00:00:00 2001 From: srowen Date: Thu, 11 Jun 2009 13:42:39 +0000 Subject: [PATCH] Added getBlackDiagonal() which I likely want to use later git-svn-id: https://zxing.googlecode.com/svn/trunk@968 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../com/google/zxing/MonochromeBitmapSource.java | 8 +++++--- .../zxing/common/BaseMonochromeBitmapSource.java | 16 ++++++++++++++++ .../common/CroppedMonochromeBitmapSource.java | 6 +++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/src/com/google/zxing/MonochromeBitmapSource.java b/core/src/com/google/zxing/MonochromeBitmapSource.java index c88ac2472..d1931288d 100644 --- a/core/src/com/google/zxing/MonochromeBitmapSource.java +++ b/core/src/com/google/zxing/MonochromeBitmapSource.java @@ -54,6 +54,8 @@ public interface MonochromeBitmapSource { */ BitArray getBlackColumn(int x, BitArray column, int startY, int getHeight); + BitArray getBlackDiagonal(int x, int y, int dx, int dy, BitArray diagonal, int size); + /** * @return height of underlying image */ @@ -110,7 +112,7 @@ public interface MonochromeBitmapSource { * @param y The y coordinate in the image. * @return The luminance value between 0 and 255. */ - public abstract int getLuminance(int x, int y); + int getLuminance(int x, int y); /** * This is the main mechanism for retrieving luminance data. It is dramatically more efficient @@ -123,7 +125,7 @@ public interface MonochromeBitmapSource { * but then I will take pity on you and allocate a sufficient array internally. * @return The array containing the luminance data. This is the same as row if it was usable. */ - public abstract int[] getLuminanceRow(int y, int[] row); + int[] getLuminanceRow(int y, int[] row); /** * The same as getLuminanceRow(), but for columns. @@ -132,6 +134,6 @@ public interface MonochromeBitmapSource { * @param column The array to write luminance values into. See above. * @return The array containing the luminance data. */ - public abstract int[] getLuminanceColumn(int x, int[] column); + int[] getLuminanceColumn(int x, int[] column); } diff --git a/core/src/com/google/zxing/common/BaseMonochromeBitmapSource.java b/core/src/com/google/zxing/common/BaseMonochromeBitmapSource.java index 06f0513e3..603871e80 100644 --- a/core/src/com/google/zxing/common/BaseMonochromeBitmapSource.java +++ b/core/src/com/google/zxing/common/BaseMonochromeBitmapSource.java @@ -106,6 +106,22 @@ public abstract class BaseMonochromeBitmapSource implements MonochromeBitmapSour return column; } + public BitArray getBlackDiagonal(int x, int y, int dx, int dy, BitArray diagonal, int size) { + if (diagonal == null || diagonal.getSize() < size) { + diagonal = new BitArray(size); + } else { + diagonal.clear(); + } + for (int i = 0; i < size; i++) { + if (isBlack(x, y)) { + diagonal.set(i); + } + x += dx; + y += dy; + } + return diagonal; + } + public void estimateBlackPoint(BlackPointEstimationMethod method, int argument) throws ReaderException { if (!method.equals(lastMethod) || argument != lastArgument) { diff --git a/core/src/com/google/zxing/common/CroppedMonochromeBitmapSource.java b/core/src/com/google/zxing/common/CroppedMonochromeBitmapSource.java index f78cc38a4..72c3ec2af 100644 --- a/core/src/com/google/zxing/common/CroppedMonochromeBitmapSource.java +++ b/core/src/com/google/zxing/common/CroppedMonochromeBitmapSource.java @@ -21,7 +21,7 @@ import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.ReaderException; /** - * Encapulates a cropped region of another {@link com.google.zxing.MonochromeBitmapSource}. + * Encapulates a cropped region of another {@link MonochromeBitmapSource}. * * @author Sean Owen */ @@ -72,6 +72,10 @@ public final class CroppedMonochromeBitmapSource implements MonochromeBitmapSour return right - left; } + public BitArray getBlackDiagonal(int x, int y, int dx, int dy, BitArray diagonal, int size) { + return delegate.getBlackDiagonal(left + x, top + y, dx, dy, diagonal, size); + } + public void estimateBlackPoint(BlackPointEstimationMethod method, int argument) throws ReaderException { // Hmm, the delegate will probably base this on the whole image though...