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

Side by Side Diff: services/shape_detection/face_detection_impl_mac.mm

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 #include "services/shape_detection/face_detection_impl_mac.h" 5 #include "services/shape_detection/face_detection_impl_mac.h"
6 6
7 #include "base/mac/scoped_cftyperef.h" 7 #include "base/mac/scoped_cftyperef.h"
8 #include "media/capture/video/scoped_result_callback.h" 8 #include "media/capture/video/scoped_result_callback.h"
9 #include "mojo/public/cpp/bindings/strong_binding.h" 9 #include "mojo/public/cpp/bindings/strong_binding.h"
10 #include "services/shape_detection/detection_utils_mac.h" 10 #include "services/shape_detection/detection_utils_mac.h"
(...skipping 29 matching lines...) Expand all
40 NSString* const accuracy = 40 NSString* const accuracy =
41 options->fast_mode ? CIDetectorAccuracyHigh : CIDetectorAccuracyLow; 41 options->fast_mode ? CIDetectorAccuracyHigh : CIDetectorAccuracyLow;
42 NSDictionary* const detector_options = @{CIDetectorAccuracy : accuracy}; 42 NSDictionary* const detector_options = @{CIDetectorAccuracy : accuracy};
43 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeFace 43 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeFace
44 context:nil 44 context:nil
45 options:detector_options] retain]); 45 options:detector_options] retain]);
46 } 46 }
47 47
48 FaceDetectionImplMac::~FaceDetectionImplMac() {} 48 FaceDetectionImplMac::~FaceDetectionImplMac() {}
49 49
50 void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data, 50 void FaceDetectionImplMac::Detect(const SkBitmap& bitmap,
51 uint32_t width,
52 uint32_t height,
53 const DetectCallback& callback) { 51 const DetectCallback& callback) {
54 media::ScopedResultCallback<DetectCallback> scoped_callback( 52 media::ScopedResultCallback<DetectCallback> scoped_callback(
55 base::Bind(&RunCallbackWithFaces, callback), 53 base::Bind(&RunCallbackWithFaces, callback),
56 base::Bind(&RunCallbackWithNoFaces)); 54 base::Bind(&RunCallbackWithNoFaces));
57 55
58 base::scoped_nsobject<CIImage> ci_image = 56 base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap);
59 CreateCIImageFromSharedMemory(std::move(frame_data), width, height);
60 if (!ci_image) 57 if (!ci_image)
61 return; 58 return;
62 59
63 NSArray* const features = [detector_ featuresInImage:ci_image]; 60 NSArray* const features = [detector_ featuresInImage:ci_image];
61 const int height = bitmap.height();
64 62
65 std::vector<mojom::FaceDetectionResultPtr> results; 63 std::vector<mojom::FaceDetectionResultPtr> results;
66 for (CIFaceFeature* const f in features) { 64 for (CIFaceFeature* const f in features) {
67 // In the default Core Graphics coordinate space, the origin is located 65 // In the default Core Graphics coordinate space, the origin is located
68 // in the lower-left corner, and thus |ci_image| is flipped vertically. 66 // in the lower-left corner, and thus |ci_image| is flipped vertically.
69 // We need to adjust |y| coordinate of bounding box before sending it. 67 // We need to adjust |y| coordinate of bounding box before sending it.
70 gfx::RectF boundingbox(f.bounds.origin.x, 68 gfx::RectF boundingbox(f.bounds.origin.x,
71 height - f.bounds.origin.y - f.bounds.size.height, 69 height - f.bounds.origin.y - f.bounds.size.height,
72 f.bounds.size.width, f.bounds.size.height); 70 f.bounds.size.width, f.bounds.size.height);
73 71
(...skipping 21 matching lines...) Expand all
95 gfx::PointF(f.mouthPosition.x, height - f.mouthPosition.y); 93 gfx::PointF(f.mouthPosition.x, height - f.mouthPosition.y);
96 face->landmarks.push_back(std::move(landmark)); 94 face->landmarks.push_back(std::move(landmark));
97 } 95 }
98 96
99 results.push_back(std::move(face)); 97 results.push_back(std::move(face));
100 } 98 }
101 scoped_callback.Run(std::move(results)); 99 scoped_callback.Run(std::move(results));
102 } 100 }
103 101
104 } // namespace shape_detection 102 } // namespace shape_detection
OLDNEW
« no previous file with comments | « services/shape_detection/face_detection_impl_mac.h ('k') | services/shape_detection/face_detection_impl_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698