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

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

Issue 2875243002: RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: RELAND2: ShapeDetection: use mojom::Bitmap for mojo interface. Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.shape_detection; 5 package org.chromium.shape_detection;
6 6
7 import android.graphics.Rect; 7 import android.graphics.Rect;
8 import android.util.SparseArray; 8 import android.util.SparseArray;
9 9
10 import com.google.android.gms.common.ConnectionResult; 10 import com.google.android.gms.common.ConnectionResult;
11 import com.google.android.gms.common.GoogleApiAvailability; 11 import com.google.android.gms.common.GoogleApiAvailability;
12 import com.google.android.gms.vision.Frame; 12 import com.google.android.gms.vision.Frame;
13 import com.google.android.gms.vision.text.TextBlock; 13 import com.google.android.gms.vision.text.TextBlock;
14 import com.google.android.gms.vision.text.TextRecognizer; 14 import com.google.android.gms.vision.text.TextRecognizer;
15 15
16 import org.chromium.base.ContextUtils; 16 import org.chromium.base.ContextUtils;
17 import org.chromium.base.Log; 17 import org.chromium.base.Log;
18 import org.chromium.gfx.mojom.RectF; 18 import org.chromium.gfx.mojom.RectF;
19 import org.chromium.mojo.system.MojoException; 19 import org.chromium.mojo.system.MojoException;
20 import org.chromium.mojo.system.SharedBufferHandle;
21 import org.chromium.services.service_manager.InterfaceFactory; 20 import org.chromium.services.service_manager.InterfaceFactory;
22 import org.chromium.shape_detection.mojom.TextDetection; 21 import org.chromium.shape_detection.mojom.TextDetection;
23 import org.chromium.shape_detection.mojom.TextDetectionResult; 22 import org.chromium.shape_detection.mojom.TextDetectionResult;
24 23
25 24
26 /** 25 /**
27 * Implementation of mojo TextDetection, using Google Play Services vision packa ge. 26 * Implementation of mojo TextDetection, using Google Play Services vision packa ge.
28 */ 27 */
29 public class TextDetectionImpl implements TextDetection { 28 public class TextDetectionImpl implements TextDetection {
30 private static final String TAG = "TextDetectionImpl"; 29 private static final String TAG = "TextDetectionImpl";
31 30
32 private TextRecognizer mTextRecognizer; 31 private TextRecognizer mTextRecognizer;
33 32
34 public TextDetectionImpl() { 33 public TextDetectionImpl() {
35 mTextRecognizer = new TextRecognizer.Builder(ContextUtils.getApplication Context()).build(); 34 mTextRecognizer = new TextRecognizer.Builder(ContextUtils.getApplication Context()).build();
36 } 35 }
37 36
38 @Override 37 @Override
39 public void detect( 38 public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse callback) {
40 SharedBufferHandle frameData, int width, int height, DetectResponse callback) {
41 if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable( 39 if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
42 ContextUtils.getApplicationContext()) 40 ContextUtils.getApplicationContext())
43 != ConnectionResult.SUCCESS) { 41 != ConnectionResult.SUCCESS) {
44 Log.e(TAG, "Google Play Services not available"); 42 Log.e(TAG, "Google Play Services not available");
45 callback.call(new TextDetectionResult[0]); 43 callback.call(new TextDetectionResult[0]);
46 return; 44 return;
47 } 45 }
48 // The vision library will be downloaded the first time the API is used 46 // The vision library will be downloaded the first time the API is used
49 // on the device; this happens "fast", but it might have not completed, 47 // on the device; this happens "fast", but it might have not completed,
50 // bail in this case. Also, the API was disabled between and v.9.0 and 48 // bail in this case. Also, the API was disabled between and v.9.0 and
51 // v.9.2, see https://developers.google.com/android/guides/releases. 49 // v.9.2, see https://developers.google.com/android/guides/releases.
52 if (!mTextRecognizer.isOperational()) { 50 if (!mTextRecognizer.isOperational()) {
53 Log.e(TAG, "TextDetector is not operational"); 51 Log.e(TAG, "TextDetector is not operational");
54 callback.call(new TextDetectionResult[0]); 52 callback.call(new TextDetectionResult[0]);
55 return; 53 return;
56 } 54 }
57 55
58 Frame frame = SharedBufferUtils.convertToFrame(frameData, width, height) ; 56 Frame frame = BitmapUtils.convertToFrame(bitmapData);
59 if (frame == null) { 57 if (frame == null) {
60 Log.e(TAG, "Error converting SharedMemory to Frame"); 58 Log.e(TAG, "Error converting SharedMemory to Frame");
61 callback.call(new TextDetectionResult[0]); 59 callback.call(new TextDetectionResult[0]);
62 return; 60 return;
63 } 61 }
64 62
65 final SparseArray<TextBlock> textBlocks = mTextRecognizer.detect(frame); 63 final SparseArray<TextBlock> textBlocks = mTextRecognizer.detect(frame);
66 64
67 TextDetectionResult[] detectedTextArray = new TextDetectionResult[textBl ocks.size()]; 65 TextDetectionResult[] detectedTextArray = new TextDetectionResult[textBl ocks.size()];
68 for (int i = 0; i < textBlocks.size(); i++) { 66 for (int i = 0; i < textBlocks.size(); i++) {
(...skipping 24 matching lines...) Expand all
93 */ 91 */
94 public static class Factory implements InterfaceFactory<TextDetection> { 92 public static class Factory implements InterfaceFactory<TextDetection> {
95 public Factory() {} 93 public Factory() {}
96 94
97 @Override 95 @Override
98 public TextDetection createImpl() { 96 public TextDetection createImpl() {
99 return new TextDetectionImpl(); 97 return new TextDetectionImpl();
100 } 98 }
101 } 99 }
102 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698