Chromium Code Reviews| 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 6d46e5fa3985d7948e29ab92ed28f90c75b43914..bcd54a34f481d9e4137f2864abfd92ce56348dd0 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,11 +21,10 @@ 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.services.service_manager.InterfaceFactory; |
| import org.chromium.shape_detection.mojom.BarcodeDetection; |
| import org.chromium.shape_detection.mojom.BarcodeDetectionResult; |
| +import org.chromium.skia.mojom.ColorType; |
| import java.nio.ByteBuffer; |
| @@ -42,9 +42,23 @@ public class BarcodeDetectionImpl implements BarcodeDetection { |
| mBarcodeDetector = new BarcodeDetector.Builder(mContext).build(); |
| } |
| + private Config validConfig(int colorType) { |
| + switch (colorType) { |
| + case ColorType.ALPHA_8: |
| + return Config.ALPHA_8; |
| + case ColorType.RGB_565: |
| + return Config.RGB_565; |
| + case ColorType.ARGB_4444: |
| + return Config.ARGB_4444; |
| + case ColorType.RGBA_8888: |
| + case ColorType.BGRA_8888: |
| + return Config.ARGB_8888; |
| + } |
| + return null; |
| + } |
| + |
| @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"); |
| @@ -61,9 +75,13 @@ public class BarcodeDetectionImpl implements BarcodeDetection { |
| return; |
| } |
| + int width = bitmapData.width; |
| + int height = bitmapData.height; |
| + Config bitmapConfig = validConfig(bitmapData.colorType); |
|
mcasas
2017/01/24 20:48:31
The problem is that, even though the code reads as
|
| 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) || bitmapConfig == null) { |
| callback.call(new BarcodeDetectionResult[0]); |
| return; |
| } |
| @@ -71,13 +89,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, bitmapConfig); |
| bitmap.copyPixelsFromBuffer(imageBuffer); |
| Frame frame = null; |