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

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

Issue 2863773005: Shape Detection: Face detection junit tests (Closed)
Patch Set: setFaceDetector() should be a static method (from findBugs) 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/FaceDetectionImpl.java
diff --git a/services/shape_detection/android/java/src/org/chromium/shape_detection/FaceDetectionImpl.java b/services/shape_detection/android/java/src/org/chromium/shape_detection/FaceDetectionImpl.java
index 4d88df132ea630035c9358cb2dcdfaf8b07fd996..158e925553dc0a9a1daa9983cb11795a59b8f79c 100644
--- a/services/shape_detection/android/java/src/org/chromium/shape_detection/FaceDetectionImpl.java
+++ b/services/shape_detection/android/java/src/org/chromium/shape_detection/FaceDetectionImpl.java
@@ -11,6 +11,7 @@ import android.media.FaceDetector.Face;
import android.os.AsyncTask;
import org.chromium.base.Log;
+import org.chromium.base.VisibleForTesting;
import org.chromium.gfx.mojom.RectF;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojo.system.SharedBufferHandle;
@@ -29,6 +30,7 @@ import java.nio.ByteBuffer;
public class FaceDetectionImpl implements FaceDetection {
private static final String TAG = "FaceDetectionImpl";
private static final int MAX_FACES = 32;
+ private static FaceDetector sFaceDetector;
private final boolean mFastMode;
private final int mMaxFaces;
@@ -37,6 +39,11 @@ public class FaceDetectionImpl implements FaceDetection {
mMaxFaces = Math.min(options.maxDetectedFaces, MAX_FACES);
}
+ @VisibleForTesting
+ public static void setFaceDetector(FaceDetector faceDetector) {
+ sFaceDetector = faceDetector;
+ }
+
@Override
public void detect(SharedBufferHandle frameData, final int width, final int height,
final DetectResponse callback) {
@@ -63,7 +70,12 @@ public class FaceDetectionImpl implements FaceDetection {
// to create this intermediate Bitmap.
// TODO(xianglu): Consider worker pool as appropriate threads.
// http://crbug.com/655814
- bitmap.copyPixelsFromBuffer(imageBuffer);
+ try {
+ bitmap.copyPixelsFromBuffer(imageBuffer);
+ } catch (RuntimeException e) {
+ callback.call(new FaceDetectionResult[0]);
+ return;
+ }
// A Bitmap must be in 565 format for findFaces() to work. See
// http://androidxref.com/7.0.0_r1/xref/frameworks/base/media/java/android/media/FaceDetector.java#124
@@ -84,7 +96,9 @@ public class FaceDetectionImpl implements FaceDetection {
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
- final FaceDetector detector = new FaceDetector(width, height, mMaxFaces);
+ final FaceDetector detector = (sFaceDetector != null)
+ ? sFaceDetector
+ : new FaceDetector(width, height, mMaxFaces);
Face[] detectedFaces = new Face[mMaxFaces];
// findFaces() will stop at |mMaxFaces|.
final int numberOfFaces = detector.findFaces(unPremultipliedBitmap, detectedFaces);
« no previous file with comments | « services/BUILD.gn ('k') | services/shape_detection/android/junit/src/org/chromium/shape_detection/FaceDetectionImplTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698