public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource {
- private int mWidth;
- private int mHeight;
- private byte[] mLuminances;
+ private final byte[] mLuminances;
public RGBMonochromeBitmapSource(String path) throws FileNotFoundException {
+ this(loadBitmap(path));
+ }
+
+ private static Bitmap loadBitmap(String path) throws FileNotFoundException {
Bitmap bitmap = BitmapFactory.decodeFile(path);
if (bitmap == null) {
throw new FileNotFoundException("Couldn't open " + path);
}
+ return bitmap;
+ }
+ public RGBMonochromeBitmapSource(Bitmap bitmap) {
+ super(bitmap.getHeight(), bitmap.getWidth());
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
// In order to measure pure decoding speed, we convert the entire image to a greyscale array up
// front, which is the same as the Y channel of the YUVMonochromeBitmapSource in the real app.
mLuminances = new byte[width * height];
- mWidth = width;
- mHeight = height;
for (int y = 0; y < height; y++) {
int offset = y * height;
for (int x = 0; x < width; x++) {
}
}
- public int getHeight() {
- return mHeight;
- }
-
- public int getWidth() {
- return mWidth;
- }
-
+ @Override
protected int getLuminance(int x, int y) {
- return mLuminances[y * mWidth + x] & 0xff;
+ return mLuminances[y * getWidth() + x] & 0xff;
}
+ @Override
protected int[] getLuminanceRow(int y, int[] row) {
- int width = mWidth;
+ int width = getWidth();
if (row == null || row.length < width) {
row = new int[width];
}
return row;
}
+ @Override
protected int[] getLuminanceColumn(int x, int[] column) {
- int width = mWidth;
- int height = mHeight;
+ int width = getWidth();
+ int height = getHeight();
if (column == null || column.length < height) {
column = new int[height];
}