- public int getWidth() {
- return width;
- }
-
- public void estimateBlackPoint(BlackPointEstimationMethod method, int argument) {
- if (!method.equals(lastMethod) || argument != lastArgument) {
- for (int i = 0; i < blackWhitePixels.length; i++) {
- blackWhitePixels[i] = null;
- }
- int[] histogram = new int[LUMINANCE_BUCKETS];
- if (method.equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
- int minDimension = width < height ? width : height;
- int startI = height == minDimension ? 0 : (height - width) >> 1;
- int startJ = width == minDimension ? 0 : (width - height) >> 1;
- for (int n = 0; n < minDimension; n++) {
- int pixel = image.getPixel(startJ + n, startI + n);
- // Computation of luminance is inlined here for speed:
- histogram[((pixel >> 16) & 0xFF) >> LUMINANCE_SHIFT]++;
- }
- } else if (method.equals(BlackPointEstimationMethod.ROW_SAMPLING)) {
- if (argument < 0 || argument >= height) {
- throw new IllegalArgumentException("Row is not within the image: " + argument);
- }
- int[] yuvArray = new int[width];
- image.getPixels(yuvArray, 0, width, 0, argument, width, 1);
- for (int x = 0; x < width; x++) {
- histogram[((yuvArray[x] >> 16) & 0xFF) >> LUMINANCE_SHIFT]++;
- }
- } else {
- throw new IllegalArgumentException("Unknown method: " + method);
+ /**
+ * Create a greyscale Android Bitmap from the YUV data based on the crop rectangle.
+ *
+ * @return An 8888 bitmap.
+ */
+ public Bitmap renderToBitmap() {
+ int width = getWidth();
+ int height = getHeight();
+ int[] pixels = new int[width * height];
+ byte[] yuvData = mYUVData;
+ for (int y = 0, base = mCropTop * mDataWidth + mCropLeft; y < height; y++, base += mDataWidth) {
+ for (int x = 0; x < width; x++) {
+ int grey = yuvData[base + x] & 0xff;
+ pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey;