com.google.zxing.client.android
Class YUVMonochromeBitmapSource

java.lang.Object
  extended by com.google.zxing.common.BaseMonochromeBitmapSource
      extended by com.google.zxing.client.android.YUVMonochromeBitmapSource
All Implemented Interfaces:
MonochromeBitmapSource

public final class YUVMonochromeBitmapSource
extends BaseMonochromeBitmapSource

This object implements MonochromeBitmapSource around an array of YUV data, giving you the option to crop to a rectangle within the full data. This can be used to exclude superfluous pixels around the perimeter and speed up decoding.

Author:
Sean Owen, Daniel Switkin

Constructor Summary
YUVMonochromeBitmapSource(byte[] yuvData, int dataWidth, int dataHeight)
          Builds an object around a YUV buffer from the camera.
YUVMonochromeBitmapSource(byte[] yuvData, int dataWidth, int dataHeight, int cropTop, int cropLeft, int cropBottom, int cropRight)
          Builds an object around a YUV buffer from the camera.
YUVMonochromeBitmapSource(byte[] yuvData, int dataWidth, int dataHeight, android.graphics.Rect crop)
          Builds an object around a YUV buffer from the camera.
 
Method Summary
 int getLuminance(int x, int y)
          The Y channel is stored as planar data at the head of the array, so we just ignore the interleaved U and V which follow it.
 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.
 android.graphics.Bitmap renderToBitmap()
          Create a greyscale Android Bitmap from the YUV data based on the crop rectangle.
 
Methods inherited from class com.google.zxing.common.BaseMonochromeBitmapSource
estimateBlackPoint, getBlackColumn, getBlackDiagonal, getBlackRow, getHeight, getLastEstimationMethod, getWidth, isBlack, isRotateSupported, rotateCounterClockwise, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

YUVMonochromeBitmapSource

public YUVMonochromeBitmapSource(byte[] yuvData,
                                 int dataWidth,
                                 int dataHeight)
Builds an object around a YUV buffer from the camera. The image is not cropped.

Parameters:
yuvData - A byte array of planar Y data, followed by interleaved U and V
dataWidth - The width of the Y data
dataHeight - The height of the Y data

YUVMonochromeBitmapSource

public YUVMonochromeBitmapSource(byte[] yuvData,
                                 int dataWidth,
                                 int dataHeight,
                                 android.graphics.Rect crop)
Builds an object around a YUV buffer from the camera. THe image is cropped and only that part of the image is evaluated.

Parameters:
yuvData - A byte array of planar Y data, followed by interleaved U and V
dataWidth - The width of the Y data
dataHeight - The height of the Y data
crop - The rectangle within the yuvData to expose to MonochromeBitmapSource users

YUVMonochromeBitmapSource

public YUVMonochromeBitmapSource(byte[] yuvData,
                                 int dataWidth,
                                 int dataHeight,
                                 int cropTop,
                                 int cropLeft,
                                 int cropBottom,
                                 int cropRight)
Builds an object around a YUV buffer from the camera. The image is cropped and only that part of the image is evaluated.

Parameters:
yuvData - A byte array of planar Y data, followed by interleaved U and V
dataWidth - The width of the Y data
dataHeight - The height of the Y data
cropTop - Top coordinate of rectangle to crop
cropLeft - Left coordinate of rectangle to crop
cropBottom - Bottom coordinate of rectangle to crop
cropRight - Right coordinate of rectangle to crop
Method Detail

getLuminance

public int getLuminance(int x,
                        int y)
The Y channel is stored as planar data at the head of the array, so we just ignore the interleaved U and V which follow it.

Specified by:
getLuminance in interface MonochromeBitmapSource
Specified by:
getLuminance in class BaseMonochromeBitmapSource
Parameters:
x - The x coordinate to fetch within crop
y - The y coordinate to fetch within crop
Returns:
The luminance as an int, from 0-255

getLuminanceRow

public int[] getLuminanceRow(int y,
                             int[] row)
Description copied from class: BaseMonochromeBitmapSource
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
Specified by:
getLuminanceRow in class BaseMonochromeBitmapSource
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 class: BaseMonochromeBitmapSource
The same as getLuminanceRow(), but for columns.

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

renderToBitmap

public android.graphics.Bitmap renderToBitmap()
Create a greyscale Android Bitmap from the YUV data based on the crop rectangle.

Returns:
An 8888 bitmap.