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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/FaceDetectorImplMac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 #include "base/mac/scoped_cftyperef.h"
6 #include "base/mac/scoped_nsobject.h"
7 #include "modules/shapedetection/FaceDetectorImplMac.h"
8
9 // kCIFormatRGBA8 is not exposed to public until Mac 10.11. So we define this
10 // same constant to support RGBA8 format in earlier versions.
11 #if !defined(MAC_OS_X_VERSION_10_11)
12 namespace {
13
14 const int kCIFormatRGBA8 = 24;
15
16 } // anonymous namespace
17 #endif
18
19 namespace blink {
20
21 FaceDetectorImpl* FaceDetectorImpl::Create() {
22 return new FaceDetectorImplMac();
23 }
24
25 FaceDetectorImplMac::FaceDetectorImplMac() : FaceDetectorImpl() {
26 NSLog(@"FaceDetectorImplMac cstr.");
27 DPLOG(ERROR) << "Before creating context_";
28 errno = 0;
29 context_.reset([[CIContext alloc] init]);
30 DPLOG(ERROR) << "Address of context_:" << context_;
31 errno = 0;
32 NSDictionary* const opts = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
33 DPLOG(ERROR) << "Address of opts:" << opts;
34 errno = 0;
35 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeFace
36 context:context_
37 options:opts] retain]);
38 DPLOG(ERROR) << "Address of detector_:" << detector_;
39 NSFileManager* filemgr;
40 NSString* currentpath;
41
42 filemgr = [[NSFileManager alloc] init];
43
44 currentpath = [filemgr currentDirectoryPath];
45 NSLog(@"currentpath:%@", currentpath);
46 NSLog(@"context_ and detector_ initialized.");
47 errno = 0;
48 }
49
50 HeapVector<Member<DOMRect>> FaceDetectorImplMac::detectFace(void* frame_addr,
51 int width,
52 int height) {
53 DPLOG(ERROR) << "FaceDetectorImplMac::detectFace";
54 HeapVector<Member<DOMRect>> detectedFaces;
55 errno = 0;
56 NSData* byte_data = [NSData dataWithBytesNoCopy:frame_addr
57 length:width * height * 4
58 freeWhenDone:NO];
59 DPLOG(ERROR) << "Address of byte_data:" << byte_data;
60 errno = 0;
61 base::ScopedCFTypeRef<CGColorSpaceRef> colorspace(
62 CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
63 DPLOG(ERROR) << "Address of colorspace:" << colorspace;
64
65 // CIImage will return nil when RGBA8 is not supported in a certain version.
66 errno = 0;
67 base::scoped_nsobject<CIImage> ciimage([[CIImage alloc]
68 initWithBitmapData:byte_data
69 bytesPerRow:width * 4
70 size:CGSizeMake(width, height)
71 format:kCIFormatRGBA8
72 colorSpace:colorspace]);
73 DPLOG(ERROR) << "Address of ciimage:" << ciimage;
74 errno = 0;
75 if (!ciimage) {
76 DLOG(ERROR) << "Failed to create CIImage";
77 return detectedFaces;
78 }
79
80 // base::scoped_nsobject<CIContext> context([[CIContext alloc] init]);
81 // NSDictionary* const opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh
82 // };
83 // base::scoped_nsobject<CIDetector> detector([[CIDetector
84 // detectorOfType:CIDetectorTypeFace
85 // context:context
86 // options:opts] retain]);
87 DPLOG(ERROR) << "Before getting features";
88 errno = 0;
89 NSArray* const features = [detector_ featuresInImage:ciimage];
90 DPLOG(ERROR) << "After getting features";
91 NSLog(@"features.size: %lu", [features count]);
92
93 for (CIFaceFeature* const f in features) {
94 // In the default Core Graphics coordinate space, the origin is located
95 // in the lower-left corner, and thus |ciimage| is flipped vertically.
96 // We need to adjust |y| coordinate of bounding box before sending it back.
97 detectedFaces.append(DOMRect::create(
98 f.bounds.origin.x, height - f.bounds.origin.y - f.bounds.size.height,
99 f.bounds.size.width, f.bounds.size.height));
100 }
101 return detectedFaces;
102 }
103
104 } // namespace blink
OLDNEW
« 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