com.google.zxing.common
Class CroppedMonochromeBitmapSource

java.lang.Object
  extended by com.google.zxing.common.CroppedMonochromeBitmapSource
All Implemented Interfaces:
MonochromeBitmapSource

public final class CroppedMonochromeBitmapSource
extends java.lang.Object
implements MonochromeBitmapSource

Encapulates a cropped region of another MonochromeBitmapSource.

Author:
Sean Owen

Constructor Summary
CroppedMonochromeBitmapSource(MonochromeBitmapSource delegate, int left, int top, int right, int bottom)
          Creates an instance that uses only a region of the given image as a source of pixels to decode.
 
Method Summary
 void estimateBlackPoint(BlackPointEstimationMethod method, int argument)
          Estimates black point according to the given method, which is optionally parameterized by a single int argument.
 BitArray getBlackColumn(int x, BitArray column, int startY, int getHeight)
          Entirely analogous to MonochromeBitmapSource.getBlackRow(int, BitArray, int, int) but gets a column.
 BitArray getBlackDiagonal(int x, int y, int dx, int dy, BitArray diagonal, int size)
           
 BitArray getBlackRow(int y, BitArray row, int startX, int getWidth)
          Returns an entire row of black/white pixels as an array of bits, where "true" means "black".
 int getHeight()
           
 BlackPointEstimationMethod getLastEstimationMethod()
           
 int getLuminance(int x, int y)
          Retrieves the luminance at the pixel x,y in the bitmap.
 int[] getLuminanceColumn(int x, int[] column)
          The same as getLuminanceRow(), but for columns.
 int[] getLuminanceRow(int y, int[] row)
          This is the main mechanism for retrieving luminance data.
 int getWidth()
           
 boolean isBlack(int x, int y)
           
 boolean isRotateSupported()
           
 MonochromeBitmapSource rotateCounterClockwise()
          Optional operation which returns an implementation based on the same underlying image, but which behaves as if the underlying image had been rotated 90 degrees counterclockwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CroppedMonochromeBitmapSource

public CroppedMonochromeBitmapSource(MonochromeBitmapSource delegate,
                                     int left,
                                     int top,
                                     int right,
                                     int bottom)
Creates an instance that uses only a region of the given image as a source of pixels to decode.

Parameters:
delegate - image to decode a region of
left - x coordinate of leftmost pixels to decode
top - y coordinate of topmost pixels to decode
right - one more than the x coordinate of rightmost pixels to decode, i.e. we will decode pixels whose x coordinate is in [left,right)
bottom - likewise, one more than the y coordinate of the bottommost pixels to decode
Method Detail

isBlack

public boolean isBlack(int x,
                       int y)
Specified by:
isBlack in interface MonochromeBitmapSource
Parameters:
x - horizontal offset, from left, of the pixel
y - vertical offset, from top, of the pixel
Returns:
true iff the pixel at (x,y) is black

getBlackRow

public BitArray getBlackRow(int y,
                            BitArray row,
                            int startX,
                            int getWidth)
Description copied from interface: MonochromeBitmapSource

Returns an entire row of black/white pixels as an array of bits, where "true" means "black". This is a sort of "bulk get" operation intended to enable efficient access in certain situations.

Specified by:
getBlackRow in interface MonochromeBitmapSource
Parameters:
y - vertical offset, from top, of the row of pixels
row - if not null, BitArray to write pixels into. If null, a new BitArray is allocated and returned.
startX - horizontal offset, from left, from which to start getting pixels
getWidth - number of pixels to get from the row
Returns:
BitArray representing the (subset of the) row of pixels. If row parameter was not null, it is returned.

getBlackColumn

public BitArray getBlackColumn(int x,
                               BitArray column,
                               int startY,
                               int getHeight)
Description copied from interface: MonochromeBitmapSource
Entirely analogous to MonochromeBitmapSource.getBlackRow(int, BitArray, int, int) but gets a column.

Specified by:
getBlackColumn in interface MonochromeBitmapSource

getHeight

public int getHeight()
Specified by:
getHeight in interface MonochromeBitmapSource
Returns:
height of underlying image

getWidth

public int getWidth()
Specified by:
getWidth in interface MonochromeBitmapSource
Returns:
width of underlying image

getBlackDiagonal

public BitArray getBlackDiagonal(int x,
                                 int y,
                                 int dx,
                                 int dy,
                                 BitArray diagonal,
                                 int size)
Specified by:
getBlackDiagonal in interface MonochromeBitmapSource

estimateBlackPoint

public void estimateBlackPoint(BlackPointEstimationMethod method,
                               int argument)
                        throws ReaderException
Description copied from interface: MonochromeBitmapSource

Estimates black point according to the given method, which is optionally parameterized by a single int argument. For BlackPointEstimationMethod.ROW_SAMPLING, this specifies the row to sample.

The estimated value will be used in subsequent computations that rely on an estimated black point.

Specified by:
estimateBlackPoint in interface MonochromeBitmapSource
Parameters:
method - black point estimation method
argument - method-specific argument
Throws:
ReaderException

getLastEstimationMethod

public BlackPointEstimationMethod getLastEstimationMethod()
Specified by:
getLastEstimationMethod in interface MonochromeBitmapSource
Returns:
BlackPointEstimationMethod representing last sampling method used

rotateCounterClockwise

public MonochromeBitmapSource rotateCounterClockwise()
Description copied from interface: MonochromeBitmapSource

Optional operation which returns an implementation based on the same underlying image, but which behaves as if the underlying image had been rotated 90 degrees counterclockwise. This is useful in the context of 1D barcodes and the DecodeHintType.TRY_HARDER decode hint, and is only intended to be used in non-resource-constrained environments. Hence, implementations of this class which are only used in resource-constrained mobile environments don't have a need to implement this.

Specified by:
rotateCounterClockwise in interface MonochromeBitmapSource

isRotateSupported

public boolean isRotateSupported()
Specified by:
isRotateSupported in interface MonochromeBitmapSource
Returns:
true iff rotation is supported
See Also:
MonochromeBitmapSource.rotateCounterClockwise()

getLuminance

public int getLuminance(int x,
                        int y)
Description copied from interface: MonochromeBitmapSource
Retrieves the luminance at the pixel x,y in the bitmap. This method is only used for estimating the black point and implementing getBlackRow() - it is not meant for decoding, hence it is not part of MonochromeBitmapSource itself, and is protected.

Specified by:
getLuminance in interface MonochromeBitmapSource
Parameters:
x - The x coordinate in the image.
y - The y coordinate in the image.
Returns:
The luminance value between 0 and 255.

getLuminanceRow

public int[] getLuminanceRow(int y,
                             int[] row)
Description copied from interface: MonochromeBitmapSource
This is the main mechanism for retrieving luminance data. It is dramatically more efficient than repeatedly calling getLuminance(). As above, this is not meant for decoders.

Specified by:
getLuminanceRow in interface MonochromeBitmapSource
Parameters:
y - The row to fetch
row - The array to write luminance values into. It is strongly suggested that you allocate this yourself, making sure row.length >= getWidth(), and reuse the same array on subsequent calls for performance. If you pass null, you will be flogged, but then I will take pity on you and allocate a sufficient array internally.
Returns:
The array containing the luminance data. This is the same as row if it was usable.

getLuminanceColumn

public int[] getLuminanceColumn(int x,
                                int[] column)
Description copied from interface: MonochromeBitmapSource
The same as getLuminanceRow(), but for columns.

Specified by:
getLuminanceColumn in interface MonochromeBitmapSource
Parameters:
x - The column to fetch
column - The array to write luminance values into. See above.
Returns:
The array containing the luminance data.