Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/shapedetection/TextDetectionImpl.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/TextDetectionImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/TextDetectionImpl.java |
| index b6f541c20a974b2b71230a9ed8905ddfc0f98b7a..608f8f6ff2d8b0f7899a61b0c62913dc4cd65c57 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/TextDetectionImpl.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/shapedetection/TextDetectionImpl.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.Rect; |
| import android.util.SparseArray; |
| @@ -18,10 +19,9 @@ import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
| import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; |
| 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.TextDetection; |
| import org.chromium.shape_detection.mojom.TextDetectionResult; |
| +import org.chromium.skia.mojom.ColorType; |
| import java.nio.ByteBuffer; |
| @@ -33,15 +33,33 @@ public class TextDetectionImpl implements TextDetection { |
| private final Context mContext; |
| private TextRecognizer mTextRecognizer; |
| + private Config mBitmapConfig; |
| public TextDetectionImpl(Context context) { |
| mContext = context; |
| mTextRecognizer = new TextRecognizer.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"); |
| @@ -58,9 +76,12 @@ public class TextDetectionImpl implements TextDetection { |
| return; |
| } |
| + int width = bitmapData.width; |
| + int height = bitmapData.height; |
| final long numPixels = (long) width * height; |
| // TODO(xianglu): 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
Same comments here as in BarcodeDetectionImpl.
|
| callback.call(new TextDetectionResult[0]); |
| return; |
| } |
| @@ -68,13 +89,13 @@ public class TextDetectionImpl implements TextDetection { |
| // 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 TextDetectionResult[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; |