Index: chrome/android/java/src/org/chromium/chrome/browser/shapedetection/BarcodeDetectionImpl.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/BarcodeDetectionImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/BarcodeDetectionImpl.java |
index 2035620acc09e46e70692baf37bfbe6cbac930e5..ca84cc152efff443ad1b4671b1dff64d25ef5412 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/BarcodeDetectionImpl.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/BarcodeDetectionImpl.java |
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.shapedetection; |
import android.content.Context; |
import android.graphics.Bitmap; |
+import android.graphics.Bitmap.Config; |
import android.graphics.Point; |
import android.graphics.Rect; |
import android.util.SparseArray; |
@@ -20,10 +21,9 @@ import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; |
import org.chromium.gfx.mojom.PointF; |
import org.chromium.gfx.mojom.RectF; |
import org.chromium.mojo.system.MojoException; |
-import org.chromium.mojo.system.SharedBufferHandle; |
-import org.chromium.mojo.system.SharedBufferHandle.MapFlags; |
import org.chromium.shape_detection.mojom.BarcodeDetection; |
import org.chromium.shape_detection.mojom.BarcodeDetectionResult; |
+import org.chromium.skia.mojom.ColorType; |
import java.nio.ByteBuffer; |
@@ -35,15 +35,33 @@ public class BarcodeDetectionImpl implements BarcodeDetection { |
private final Context mContext; |
private BarcodeDetector mBarcodeDetector; |
+ private Config mBitmapConfig; |
public BarcodeDetectionImpl(Context context) { |
mContext = context; |
mBarcodeDetector = new BarcodeDetector.Builder(mContext).build(); |
} |
+ private boolean validConfig(int colorType) { |
+ switch (colorType) { |
+ case ColorType.ALPHA_8: |
+ mBitmapConfig = Config.ALPHA_8; |
+ return true; |
+ case ColorType.RGB_565: |
+ mBitmapConfig = Config.RGB_565; |
+ return true; |
+ case ColorType.ARGB_4444: |
+ mBitmapConfig = Config.ARGB_4444; |
+ return true; |
+ case ColorType.RGBA_8888: |
+ mBitmapConfig = Config.ARGB_8888; |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
@Override |
- public void detect( |
- SharedBufferHandle frameData, int width, int height, DetectResponse callback) { |
+ public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse callback) { |
if (!ExternalAuthUtils.getInstance().canUseGooglePlayServices( |
mContext, new UserRecoverableErrorHandler.Silent())) { |
Log.e(TAG, "Google Play Services not available"); |
@@ -60,9 +78,12 @@ public class BarcodeDetectionImpl implements BarcodeDetection { |
return; |
} |
+ int width = bitmapData.width; |
+ int height = bitmapData.height; |
final long numPixels = (long) width * height; |
// TODO(mcasas): https://crbug.com/670028 homogeneize overflow checking. |
- if (!frameData.isValid() || width <= 0 || height <= 0 || numPixels > (Long.MAX_VALUE / 4)) { |
+ if (bitmapData.pixelData == null || width <= 0 || height <= 0 |
+ || numPixels > (Long.MAX_VALUE / 4) || !validConfig(bitmapData.colorType)) { |
mcasas
2017/01/24 00:52:05
I doubt that any detector (this or TextDetectionIm
junwei
2017/01/25 06:14:50
I updated l.57 to handle BGRA_8888 the same as RGB
|
callback.call(new BarcodeDetectionResult[0]); |
return; |
} |
@@ -70,13 +91,13 @@ public class BarcodeDetectionImpl implements BarcodeDetection { |
// Mapping |frameData| will fail if the intended mapped size is larger |
// than its actual capacity, which is limited by the appropriate |
// mojo::edk::Configuration entry. |
- ByteBuffer imageBuffer = frameData.map(0, numPixels * 4, MapFlags.none()); |
+ ByteBuffer imageBuffer = ByteBuffer.wrap(bitmapData.pixelData); |
if (imageBuffer.capacity() <= 0) { |
callback.call(new BarcodeDetectionResult[0]); |
return; |
} |
- Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
+ Bitmap bitmap = Bitmap.createBitmap(width, height, mBitmapConfig); |
bitmap.copyPixelsFromBuffer(imageBuffer); |
Frame frame = null; |