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

Side by Side Diff: services/shape_detection/android/java/src/org/chromium/shape_detection/BarcodeDetectionImpl.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.Point; 7 import android.graphics.Point;
8 import android.graphics.Rect; 8 import android.graphics.Rect;
9 import android.util.SparseArray; 9 import android.util.SparseArray;
10 10
11 import com.google.android.gms.common.ConnectionResult; 11 import com.google.android.gms.common.ConnectionResult;
12 import com.google.android.gms.common.GoogleApiAvailability; 12 import com.google.android.gms.common.GoogleApiAvailability;
13 import com.google.android.gms.vision.Frame; 13 import com.google.android.gms.vision.Frame;
14 import com.google.android.gms.vision.barcode.Barcode; 14 import com.google.android.gms.vision.barcode.Barcode;
15 import com.google.android.gms.vision.barcode.BarcodeDetector; 15 import com.google.android.gms.vision.barcode.BarcodeDetector;
16 16
17 import org.chromium.base.ContextUtils; 17 import org.chromium.base.ContextUtils;
18 import org.chromium.base.Log; 18 import org.chromium.base.Log;
19 import org.chromium.gfx.mojom.PointF; 19 import org.chromium.gfx.mojom.PointF;
20 import org.chromium.gfx.mojom.RectF; 20 import org.chromium.gfx.mojom.RectF;
21 import org.chromium.mojo.system.MojoException; 21 import org.chromium.mojo.system.MojoException;
22 import org.chromium.mojo.system.SharedBufferHandle;
23 import org.chromium.services.service_manager.InterfaceFactory; 22 import org.chromium.services.service_manager.InterfaceFactory;
24 import org.chromium.shape_detection.mojom.BarcodeDetection; 23 import org.chromium.shape_detection.mojom.BarcodeDetection;
25 import org.chromium.shape_detection.mojom.BarcodeDetectionResult; 24 import org.chromium.shape_detection.mojom.BarcodeDetectionResult;
26 25
27 /** 26 /**
28 * Implementation of mojo BarcodeDetection, using Google Play Services vision pa ckage. 27 * Implementation of mojo BarcodeDetection, using Google Play Services vision pa ckage.
29 */ 28 */
30 public class BarcodeDetectionImpl implements BarcodeDetection { 29 public class BarcodeDetectionImpl implements BarcodeDetection {
31 private static final String TAG = "BarcodeDetectionImpl"; 30 private static final String TAG = "BarcodeDetectionImpl";
32 31
33 private BarcodeDetector mBarcodeDetector; 32 private BarcodeDetector mBarcodeDetector;
34 33
35 public BarcodeDetectionImpl() { 34 public BarcodeDetectionImpl() {
36 mBarcodeDetector = 35 mBarcodeDetector =
37 new BarcodeDetector.Builder(ContextUtils.getApplicationContext() ).build(); 36 new BarcodeDetector.Builder(ContextUtils.getApplicationContext() ).build();
38 } 37 }
39 38
40 @Override 39 @Override
41 public void detect( 40 public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse callback) {
42 SharedBufferHandle frameData, int width, int height, DetectResponse callback) {
43 if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable( 41 if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
44 ContextUtils.getApplicationContext()) 42 ContextUtils.getApplicationContext())
45 != ConnectionResult.SUCCESS) { 43 != ConnectionResult.SUCCESS) {
46 Log.e(TAG, "Google Play Services not available"); 44 Log.e(TAG, "Google Play Services not available");
47 callback.call(new BarcodeDetectionResult[0]); 45 callback.call(new BarcodeDetectionResult[0]);
48 return; 46 return;
49 } 47 }
50 // The vision library will be downloaded the first time the API is used 48 // The vision library will be downloaded the first time the API is used
51 // on the device; this happens "fast", but it might have not completed, 49 // on the device; this happens "fast", but it might have not completed,
52 // bail in this case. Also, the API was disabled between and v.9.0 and 50 // bail in this case. Also, the API was disabled between and v.9.0 and
53 // v.9.2, see https://developers.google.com/android/guides/releases. 51 // v.9.2, see https://developers.google.com/android/guides/releases.
54 if (!mBarcodeDetector.isOperational()) { 52 if (!mBarcodeDetector.isOperational()) {
55 Log.e(TAG, "BarcodeDetector is not operational"); 53 Log.e(TAG, "BarcodeDetector is not operational");
56 callback.call(new BarcodeDetectionResult[0]); 54 callback.call(new BarcodeDetectionResult[0]);
57 return; 55 return;
58 } 56 }
59 57
60 Frame frame = SharedBufferUtils.convertToFrame(frameData, width, height) ; 58 Frame frame = BitmapUtils.convertToFrame(bitmapData);
61 if (frame == null) { 59 if (frame == null) {
62 Log.e(TAG, "Error converting SharedMemory to Frame"); 60 Log.e(TAG, "Error converting SharedMemory to Frame");
63 callback.call(new BarcodeDetectionResult[0]); 61 callback.call(new BarcodeDetectionResult[0]);
64 return; 62 return;
65 } 63 }
66 64
67 final SparseArray<Barcode> barcodes = mBarcodeDetector.detect(frame); 65 final SparseArray<Barcode> barcodes = mBarcodeDetector.detect(frame);
68 66
69 BarcodeDetectionResult[] barcodeArray = new BarcodeDetectionResult[barco des.size()]; 67 BarcodeDetectionResult[] barcodeArray = new BarcodeDetectionResult[barco des.size()];
70 for (int i = 0; i < barcodes.size(); i++) { 68 for (int i = 0; i < barcodes.size(); i++) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 */ 101 */
104 public static class Factory implements InterfaceFactory<BarcodeDetection> { 102 public static class Factory implements InterfaceFactory<BarcodeDetection> {
105 public Factory() {} 103 public Factory() {}
106 104
107 @Override 105 @Override
108 public BarcodeDetection createImpl() { 106 public BarcodeDetection createImpl() {
109 return new BarcodeDetectionImpl(); 107 return new BarcodeDetectionImpl();
110 } 108 }
111 } 109 }
112 } 110 }
OLDNEW
« no previous file with comments | « services/shape_detection/DEPS ('k') | services/shape_detection/android/java/src/org/chromium/shape_detection/BitmapUtils.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698