| OLD | NEW |
| 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 Loading... |
| 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(const SkBitmap& bitmap, | 50 void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data, |
| 51 uint32_t width, |
| 52 uint32_t height, |
| 51 const DetectCallback& callback) { | 53 const DetectCallback& callback) { |
| 52 media::ScopedResultCallback<DetectCallback> scoped_callback( | 54 media::ScopedResultCallback<DetectCallback> scoped_callback( |
| 53 base::Bind(&RunCallbackWithFaces, callback), | 55 base::Bind(&RunCallbackWithFaces, callback), |
| 54 base::Bind(&RunCallbackWithNoFaces)); | 56 base::Bind(&RunCallbackWithNoFaces)); |
| 55 | 57 |
| 56 base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap); | 58 base::scoped_nsobject<CIImage> ci_image = |
| 59 CreateCIImageFromSharedMemory(std::move(frame_data), width, height); |
| 57 if (!ci_image) | 60 if (!ci_image) |
| 58 return; | 61 return; |
| 59 | 62 |
| 60 NSArray* const features = [detector_ featuresInImage:ci_image]; | 63 NSArray* const features = [detector_ featuresInImage:ci_image]; |
| 61 | 64 |
| 62 const int height = bitmap.height(); | |
| 63 shape_detection::mojom::FaceDetectionResultPtr faces = | 65 shape_detection::mojom::FaceDetectionResultPtr faces = |
| 64 shape_detection::mojom::FaceDetectionResult::New(); | 66 shape_detection::mojom::FaceDetectionResult::New(); |
| 65 for (CIFaceFeature* const f in features) { | 67 for (CIFaceFeature* const f in features) { |
| 66 // In the default Core Graphics coordinate space, the origin is located | 68 // In the default Core Graphics coordinate space, the origin is located |
| 67 // in the lower-left corner, and thus |ci_image| is flipped vertically. | 69 // in the lower-left corner, and thus |ci_image| is flipped vertically. |
| 68 // We need to adjust |y| coordinate of bounding box before sending it. | 70 // We need to adjust |y| coordinate of bounding box before sending it. |
| 69 gfx::RectF boundingbox(f.bounds.origin.x, | 71 gfx::RectF boundingbox(f.bounds.origin.x, |
| 70 height - f.bounds.origin.y - f.bounds.size.height, | 72 height - f.bounds.origin.y - f.bounds.size.height, |
| 71 f.bounds.size.width, f.bounds.size.height); | 73 f.bounds.size.width, f.bounds.size.height); |
| 72 faces->bounding_boxes.push_back(boundingbox); | 74 faces->bounding_boxes.push_back(boundingbox); |
| 73 } | 75 } |
| 74 scoped_callback.Run(std::move(faces)); | 76 scoped_callback.Run(std::move(faces)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 } // namespace shape_detection | 79 } // namespace shape_detection |
| OLD | NEW |