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

Unified Diff: services/shape_detection/detection_utils_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
« no previous file with comments | « services/shape_detection/detection_utils_mac.h ('k') | services/shape_detection/face_detection_impl_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/shape_detection/detection_utils_mac.mm
diff --git a/services/shape_detection/face_detection_impl_mac.mm b/services/shape_detection/detection_utils_mac.mm
similarity index 41%
copy from services/shape_detection/face_detection_impl_mac.mm
copy to services/shape_detection/detection_utils_mac.mm
index ab40e708f12d2d04ec579b9be1ef508cb2fda3e3..4e87812e99854b24dd7251094ea93cb405a134ac 100644
--- a/services/shape_detection/face_detection_impl_mac.mm
+++ b/services/shape_detection/detection_utils_mac.mm
@@ -2,73 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "services/shape_detection/face_detection_impl_mac.h"
+#include "services/shape_detection/detection_utils_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/face_detection_provider_impl.h"
+#include "services/shape_detection/barcode_detection_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.
+// These formats are available but not public until Mac 10.11.
#if !defined(MAC_OS_X_VERSION_10_11) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
const int kCIFormatRGBA8 = 24;
+#else
+//static_assert(kCIFormatRGBA8 == 24, "RGBA8 format enum index.");
#endif
-void RunCallbackWithFaces(
- const shape_detection::mojom::FaceDetection::DetectCallback& callback,
- shape_detection::mojom::FaceDetectionResultPtr faces) {
- callback.Run(std::move(faces));
-}
-
-void RunCallbackWithNoFaces(
- const shape_detection::mojom::FaceDetection::DetectCallback& callback) {
- callback.Run(shape_detection::mojom::FaceDetectionResult::New());
-}
-
-} // anonymous namespace
-
-void FaceDetectionProviderImpl::CreateFaceDetection(
- shape_detection::mojom::FaceDetectionRequest request,
- shape_detection::mojom::FaceDetectorOptionsPtr options) {
- mojo::MakeStrongBinding(
- base::MakeUnique<FaceDetectionImplMac>(std::move(options)),
- std::move(request));
-}
-
-FaceDetectionImplMac::FaceDetectionImplMac(
- shape_detection::mojom::FaceDetectorOptionsPtr options) {
- context_.reset([[CIContext alloc] init]);
- NSDictionary* const opts = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
- detector_.reset([[CIDetector detectorOfType:CIDetectorTypeFace
- context:context_
- options:opts] retain]);
-}
-
-FaceDetectionImplMac::~FaceDetectionImplMac() {}
-
-void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data,
- uint32_t width,
- uint32_t height,
- const DetectCallback& callback) {
- media::ScopedResultCallback<DetectCallback> scoped_callback(
- base::Bind(&RunCallbackWithFaces, callback),
- base::Bind(&RunCallbackWithNoFaces));
-
+base::scoped_nsobject<CIImage> CreateCIImageFromSharedMemory(
+ mojo::ScopedSharedBufferHandle frame_data,
+ uint32_t width,
+ uint32_t height) {
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;
+ return base::scoped_nsobject<CIImage>();
}
base::SharedMemoryHandle memory_handle;
@@ -79,14 +40,14 @@ void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data,
DCHECK_EQ(MOJO_RESULT_OK, result) << "Failed to unwrap SharedBufferHandle";
if (!memory_size || memory_size != num_bytes.ValueOrDie()) {
DLOG(ERROR) << "Invalid image size";
- return;
+ return base::scoped_nsobject<CIImage>();
}
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";
- return;
+ return base::scoped_nsobject<CIImage>();
}
NSData* byte_data = [NSData dataWithBytesNoCopy:shared_memory->memory()
@@ -96,7 +57,7 @@ void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data,
base::ScopedCFTypeRef<CGColorSpaceRef> colorspace(
CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
- // CIImage will return nil when RGBA8 is not supported in a certain version.
+ // CIImage will return nil if RGBA8 is not supported in a certain version.
base::scoped_nsobject<CIImage> ci_image([[CIImage alloc]
initWithBitmapData:byte_data
bytesPerRow:width * 4
@@ -105,23 +66,9 @@ void FaceDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data,
colorSpace:colorspace]);
if (!ci_image) {
DLOG(ERROR) << "Failed to create CIImage";
- return;
- }
-
- NSArray* const features = [detector_ featuresInImage:ci_image];
-
- shape_detection::mojom::FaceDetectionResultPtr faces =
- shape_detection::mojom::FaceDetectionResult::New();
- for (CIFaceFeature* const f in features) {
- // In the default Core Graphics coordinate space, the origin is located
- // in the lower-left corner, and thus |ci_image| is flipped vertically.
- // We need to adjust |y| coordinate of bounding box before sending it.
- gfx::RectF boundingbox(f.bounds.origin.x,
- height - f.bounds.origin.y - f.bounds.size.height,
- f.bounds.size.width, f.bounds.size.height);
- faces->bounding_boxes.push_back(boundingbox);
+ return base::scoped_nsobject<CIImage>();
}
- scoped_callback.Run(std::move(faces));
+ return ci_image;
}
} // namespace shape_detection
« no previous file with comments | « services/shape_detection/detection_utils_mac.h ('k') | services/shape_detection/face_detection_impl_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698