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

Unified Diff: services/shape_detection/face_detection_impl_mac.mm

Issue 2655303005: Shape detection service: Add QR detection in Mac (Closed)
Patch Set: Don't init explicitly a vector of vectors Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: services/shape_detection/face_detection_impl_mac.mm
diff --git a/services/shape_detection/face_detection_impl_mac.mm b/services/shape_detection/face_detection_impl_mac.mm
index ab40e708f12d2d04ec579b9be1ef508cb2fda3e3..211ddac2deb98f742a24c68c791a8a02b3712556 100644
--- a/services/shape_detection/face_detection_impl_mac.mm
+++ b/services/shape_detection/face_detection_impl_mac.mm
@@ -5,24 +5,15 @@
#include "services/shape_detection/face_detection_impl_mac.h"
#include "base/mac/scoped_cftyperef.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/memory/shared_memory.h"
#include "media/capture/video/scoped_result_callback.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "mojo/public/cpp/system/platform_handle.h"
+#include "services/shape_detection/detection_utils_mac.h"
#include "services/shape_detection/face_detection_provider_impl.h"
namespace shape_detection {
namespace {
-// kCIFormatRGBA8 is not exposed to public until Mac 10.11. So we define the
-// same constant to support RGBA8 format in earlier versions.
-#if !defined(MAC_OS_X_VERSION_10_11) || \
- MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
-const int kCIFormatRGBA8 = 24;
-#endif
-
void RunCallbackWithFaces(
const shape_detection::mojom::FaceDetection::DetectCallback& callback,
shape_detection::mojom::FaceDetectionResultPtr faces) {
@@ -46,10 +37,9 @@ void FaceDetectionProviderImpl::CreateFaceDetection(
FaceDetectionImplMac::FaceDetectionImplMac(
shape_detection::mojom::FaceDetectorOptionsPtr options) {
- context_.reset([[CIContext alloc] init]);
NSDictionary* const opts = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
detector_.reset([[CIDetector detectorOfType:CIDetectorTypeFace
- context:context_
+ context:nil
options:opts] retain]);
}
@@ -63,50 +53,10 @@ void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data,
base::Bind(&RunCallbackWithFaces, callback),
base::Bind(&RunCallbackWithNoFaces));
- base::CheckedNumeric<uint32_t> num_pixels =
- base::CheckedNumeric<uint32_t>(width) * height;
- base::CheckedNumeric<uint32_t> num_bytes = num_pixels * 4;
- if (!num_bytes.IsValid()) {
- DLOG(ERROR) << "Data overflow";
- return;
- }
-
- base::SharedMemoryHandle memory_handle;
- size_t memory_size = 0;
- bool read_only_flag = false;
- const MojoResult result = mojo::UnwrapSharedMemoryHandle(
- std::move(frame_data), &memory_handle, &memory_size, &read_only_flag);
- DCHECK_EQ(MOJO_RESULT_OK, result) << "Failed to unwrap SharedBufferHandle";
- if (!memory_size || memory_size != num_bytes.ValueOrDie()) {
- DLOG(ERROR) << "Invalid image size";
- return;
- }
-
- auto shared_memory =
- base::MakeUnique<base::SharedMemory>(memory_handle, true /* read_only */);
- if (!shared_memory->Map(memory_size)) {
- DLOG(ERROR) << "Failed to map bytes from shared memory";
+ base::scoped_nsobject<CIImage> ci_image =
+ CreateCIImageFromSharedMemory(std::move(frame_data), width, height);
+ if (!ci_image)
return;
- }
-
- NSData* byte_data = [NSData dataWithBytesNoCopy:shared_memory->memory()
- length:num_bytes.ValueOrDie()
- freeWhenDone:NO];
-
- base::ScopedCFTypeRef<CGColorSpaceRef> colorspace(
- CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
-
- // CIImage will return nil when RGBA8 is not supported in a certain version.
- base::scoped_nsobject<CIImage> ci_image([[CIImage alloc]
- initWithBitmapData:byte_data
- bytesPerRow:width * 4
- size:CGSizeMake(width, height)
- format:kCIFormatRGBA8
- colorSpace:colorspace]);
- if (!ci_image) {
- DLOG(ERROR) << "Failed to create CIImage";
- return;
- }
NSArray* const features = [detector_ featuresInImage:ci_image];
« no previous file with comments | « services/shape_detection/face_detection_impl_mac.h ('k') | services/shape_detection/shape_detection_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698