Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Unified Diff: services/shape_detection/android/java/src/org/chromium/shape_detection/TextDetectionImpl.java

Issue 2868883003: Shape Detection: use Google Play services Face detection where available (Closed)
Patch Set: reillyg@ nit and filling faceArray[i].landmarks in FaceDetectionImpl.java Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/shape_detection/android/java/src/org/chromium/shape_detection/TextDetectionImpl.java
diff --git a/services/shape_detection/android/java/src/org/chromium/shape_detection/TextDetectionImpl.java b/services/shape_detection/android/java/src/org/chromium/shape_detection/TextDetectionImpl.java
index d5fd2c5ce8e16bd2b9669e94077297143c473dde..3636c1baf495f9808ba640515677a4a93b210e2f 100644
--- a/services/shape_detection/android/java/src/org/chromium/shape_detection/TextDetectionImpl.java
+++ b/services/shape_detection/android/java/src/org/chromium/shape_detection/TextDetectionImpl.java
@@ -5,7 +5,6 @@
package org.chromium.shape_detection;
import android.content.Context;
-import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.SparseArray;
@@ -19,12 +18,10 @@ import org.chromium.base.Log;
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.TextDetection;
import org.chromium.shape_detection.mojom.TextDetectionResult;
-import java.nio.ByteBuffer;
/**
* Implementation of mojo TextDetection, using Google Play Services vision package.
@@ -59,31 +56,9 @@ public class TextDetectionImpl implements TextDetection {
return;
}
- 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)) {
- callback.call(new TextDetectionResult[0]);
- return;
- }
-
- // 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());
- if (imageBuffer.capacity() <= 0) {
- callback.call(new TextDetectionResult[0]);
- return;
- }
-
- Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- bitmap.copyPixelsFromBuffer(imageBuffer);
-
- Frame frame = null;
- try {
- // This constructor implies a pixel format conversion to YUV.
- frame = new Frame.Builder().setBitmap(bitmap).build();
- } catch (IllegalArgumentException | IllegalStateException ex) {
- Log.e(TAG, "Frame.Builder().setBitmap() or build(): " + ex);
+ Frame frame = SharedBufferUtils.convertToFrame(frameData, width, height);
+ if (frame == null) {
+ Log.e(TAG, "Error converting SharedMemory to Frame");
callback.call(new TextDetectionResult[0]);
return;
}

Powered by Google App Engine
This is Rietveld 408576698