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

Side by Side Diff: services/shape_detection/android/java/src/org/chromium/shape_detection/BitmapUtils.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, 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.shape_detection;
6
7 import android.graphics.Bitmap;
8
9 import com.google.android.gms.vision.Frame;
10
11 import org.chromium.skia.mojom.ColorType;
12
13 import java.nio.ByteBuffer;
14
15 /**
16 * Utility class to convert a Bitmap to a GMS core YUV Frame.
17 */
18 public class BitmapUtils {
19 public static Bitmap createBitmap(org.chromium.skia.mojom.Bitmap bitmapData) {
20 int width = bitmapData.width;
21 int height = bitmapData.height;
22 final long numPixels = (long) width * height;
23 // TODO(mcasas): https://crbug.com/670028 homogeneize overflow checking.
24 if (bitmapData.pixelData == null || width <= 0 || height <= 0
25 || numPixels > (Long.MAX_VALUE / 4)) {
26 return null;
27 }
28
29 // TODO(junwei.fu): https://crbug.com/684921 support other bitmap pixel formats.
30 if (bitmapData.colorType != ColorType.RGBA_8888
31 && bitmapData.colorType != ColorType.BGRA_8888) {
32 return null;
33 }
34
35 ByteBuffer imageBuffer = ByteBuffer.wrap(bitmapData.pixelData);
36 if (imageBuffer.capacity() <= 0) {
37 return null;
38 }
39
40 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_88 88);
41 bitmap.copyPixelsFromBuffer(imageBuffer);
42
43 return bitmap;
44 }
45
46 public static Frame convertToFrame(org.chromium.skia.mojom.Bitmap bitmapData ) {
mcasas 2017/05/19 17:20:22 This method is called convertToX() whereas the pre
47 try {
48 // This constructor implies a pixel format conversion to YUV.
49 return new Frame.Builder().setBitmap(createBitmap(bitmapData)).build ();
50 } catch (IllegalArgumentException | IllegalStateException ex) {
51 return null;
52 }
53 }
54 }
mcasas 2017/05/19 17:20:22 We landed recently a Junit test for the predecesso
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698