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

Unified Diff: third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.mm

Issue 2507283002: Add warmup and sandbox file-read permission for testing
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.mm
diff --git a/third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.mm b/third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3226adb8701369b538bee48adc768fbaed2b60e1
--- /dev/null
+++ b/third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.mm
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/scoped_nsobject.h"
+#include "modules/shapedetection/FaceDetectorImplMac.h"
+
+// kCIFormatRGBA8 is not exposed to public until Mac 10.11. So we define this
+// same constant to support RGBA8 format in earlier versions.
+#if !defined(MAC_OS_X_VERSION_10_11)
+namespace {
+
+const int kCIFormatRGBA8 = 24;
+
+} // anonymous namespace
+#endif
+
+namespace blink {
+
+FaceDetectorImpl* FaceDetectorImpl::Create() {
+ return new FaceDetectorImplMac();
+}
+
+FaceDetectorImplMac::FaceDetectorImplMac() : FaceDetectorImpl() {
+ NSLog(@"FaceDetectorImplMac cstr.");
+ DPLOG(ERROR) << "Before creating context_";
+ errno = 0;
+ context_.reset([[CIContext alloc] init]);
+ DPLOG(ERROR) << "Address of context_:" << context_;
+ errno = 0;
+ NSDictionary* const opts = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
+ DPLOG(ERROR) << "Address of opts:" << opts;
+ errno = 0;
+ detector_.reset([[CIDetector detectorOfType:CIDetectorTypeFace
+ context:context_
+ options:opts] retain]);
+ DPLOG(ERROR) << "Address of detector_:" << detector_;
+ NSFileManager* filemgr;
+ NSString* currentpath;
+
+ filemgr = [[NSFileManager alloc] init];
+
+ currentpath = [filemgr currentDirectoryPath];
+ NSLog(@"currentpath:%@", currentpath);
+ NSLog(@"context_ and detector_ initialized.");
+ errno = 0;
+}
+
+HeapVector<Member<DOMRect>> FaceDetectorImplMac::detectFace(void* frame_addr,
+ int width,
+ int height) {
+ DPLOG(ERROR) << "FaceDetectorImplMac::detectFace";
+ HeapVector<Member<DOMRect>> detectedFaces;
+ errno = 0;
+ NSData* byte_data = [NSData dataWithBytesNoCopy:frame_addr
+ length:width * height * 4
+ freeWhenDone:NO];
+ DPLOG(ERROR) << "Address of byte_data:" << byte_data;
+ errno = 0;
+ base::ScopedCFTypeRef<CGColorSpaceRef> colorspace(
+ CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
+ DPLOG(ERROR) << "Address of colorspace:" << colorspace;
+
+ // CIImage will return nil when RGBA8 is not supported in a certain version.
+ errno = 0;
+ base::scoped_nsobject<CIImage> ciimage([[CIImage alloc]
+ initWithBitmapData:byte_data
+ bytesPerRow:width * 4
+ size:CGSizeMake(width, height)
+ format:kCIFormatRGBA8
+ colorSpace:colorspace]);
+ DPLOG(ERROR) << "Address of ciimage:" << ciimage;
+ errno = 0;
+ if (!ciimage) {
+ DLOG(ERROR) << "Failed to create CIImage";
+ return detectedFaces;
+ }
+
+ // base::scoped_nsobject<CIContext> context([[CIContext alloc] init]);
+ // NSDictionary* const opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh
+ // };
+ // base::scoped_nsobject<CIDetector> detector([[CIDetector
+ // detectorOfType:CIDetectorTypeFace
+ // context:context
+ // options:opts] retain]);
+ DPLOG(ERROR) << "Before getting features";
+ errno = 0;
+ NSArray* const features = [detector_ featuresInImage:ciimage];
+ DPLOG(ERROR) << "After getting features";
+ NSLog(@"features.size: %lu", [features count]);
+
+ for (CIFaceFeature* const f in features) {
+ // In the default Core Graphics coordinate space, the origin is located
+ // in the lower-left corner, and thus |ciimage| is flipped vertically.
+ // We need to adjust |y| coordinate of bounding box before sending it back.
+ detectedFaces.append(DOMRect::create(
+ f.bounds.origin.x, height - f.bounds.origin.y - f.bounds.size.height,
+ f.bounds.size.width, f.bounds.size.height));
+ }
+ return detectedFaces;
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698