| 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/barcode_detection_impl_mac.h" | 5 #include "services/shape_detection/barcode_detection_impl_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
| 9 #include "base/mac/sdk_forward_declarations.h" | 9 #include "base/mac/sdk_forward_declarations.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 BarcodeDetectionImplMac::BarcodeDetectionImplMac() { | 44 BarcodeDetectionImplMac::BarcodeDetectionImplMac() { |
| 45 NSDictionary* const options = @{CIDetectorAccuracy : CIDetectorAccuracyHigh}; | 45 NSDictionary* const options = @{CIDetectorAccuracy : CIDetectorAccuracyHigh}; |
| 46 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeQRCode | 46 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeQRCode |
| 47 context:nil | 47 context:nil |
| 48 options:options] retain]); | 48 options:options] retain]); |
| 49 } | 49 } |
| 50 | 50 |
| 51 BarcodeDetectionImplMac::~BarcodeDetectionImplMac() {} | 51 BarcodeDetectionImplMac::~BarcodeDetectionImplMac() {} |
| 52 | 52 |
| 53 void BarcodeDetectionImplMac::Detect(const SkBitmap& bitmap, | 53 void BarcodeDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data, |
| 54 uint32_t width, |
| 55 uint32_t height, |
| 54 const DetectCallback& callback) { | 56 const DetectCallback& callback) { |
| 55 media::ScopedResultCallback<DetectCallback> scoped_callback( | 57 media::ScopedResultCallback<DetectCallback> scoped_callback( |
| 56 base::Bind(&RunCallbackWithBarcodes, callback), | 58 base::Bind(&RunCallbackWithBarcodes, callback), |
| 57 base::Bind(&RunCallbackWithNoBarcodes)); | 59 base::Bind(&RunCallbackWithNoBarcodes)); |
| 58 | 60 |
| 59 base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap); | 61 base::scoped_nsobject<CIImage> ci_image = |
| 62 CreateCIImageFromSharedMemory(std::move(frame_data), width, height); |
| 60 if (!ci_image) | 63 if (!ci_image) |
| 61 return; | 64 return; |
| 62 | 65 |
| 63 NSArray* const features = [detector_ featuresInImage:ci_image]; | 66 NSArray* const features = [detector_ featuresInImage:ci_image]; |
| 64 | 67 |
| 65 std::vector<mojom::BarcodeDetectionResultPtr> results; | 68 std::vector<mojom::BarcodeDetectionResultPtr> results; |
| 66 const int height = bitmap.height(); | |
| 67 for (CIQRCodeFeature* const f in features) { | 69 for (CIQRCodeFeature* const f in features) { |
| 68 shape_detection::mojom::BarcodeDetectionResultPtr result = | 70 shape_detection::mojom::BarcodeDetectionResultPtr result = |
| 69 shape_detection::mojom::BarcodeDetectionResult::New(); | 71 shape_detection::mojom::BarcodeDetectionResult::New(); |
| 70 // In the default Core Graphics coordinate space, the origin is located | 72 // In the default Core Graphics coordinate space, the origin is located |
| 71 // in the lower-left corner, and thus |ci_image| is flipped vertically. | 73 // in the lower-left corner, and thus |ci_image| is flipped vertically. |
| 72 // We need to adjust |y| coordinate of bounding box before sending it. | 74 // We need to adjust |y| coordinate of bounding box before sending it. |
| 73 gfx::RectF boundingbox(f.bounds.origin.x, | 75 gfx::RectF boundingbox(f.bounds.origin.x, |
| 74 height - f.bounds.origin.y - f.bounds.size.height, | 76 height - f.bounds.origin.y - f.bounds.size.height, |
| 75 f.bounds.size.width, f.bounds.size.height); | 77 f.bounds.size.width, f.bounds.size.height); |
| 76 result->bounding_box = std::move(boundingbox); | 78 result->bounding_box = std::move(boundingbox); |
| 77 | 79 |
| 78 // Enumerate corner points starting from top-left in clockwise fashion: | 80 // Enumerate corner points starting from top-left in clockwise fashion: |
| 79 // https://wicg.github.io/shape-detection-api/#dom-detectedbarcode-cornerpoi
nts | 81 // https://wicg.github.io/shape-detection-api/#dom-detectedbarcode-cornerpoi
nts |
| 80 result->corner_points.emplace_back(f.topLeft.x, height - f.topLeft.y); | 82 result->corner_points.emplace_back(f.topLeft.x, height - f.topLeft.y); |
| 81 result->corner_points.emplace_back(f.topRight.x, height - f.topRight.y); | 83 result->corner_points.emplace_back(f.topRight.x, height - f.topRight.y); |
| 82 result->corner_points.emplace_back(f.bottomRight.x, | 84 result->corner_points.emplace_back(f.bottomRight.x, |
| 83 height - f.bottomRight.y); | 85 height - f.bottomRight.y); |
| 84 result->corner_points.emplace_back(f.bottomLeft.x, height - f.bottomLeft.y); | 86 result->corner_points.emplace_back(f.bottomLeft.x, height - f.bottomLeft.y); |
| 85 | 87 |
| 86 result->raw_value = base::SysNSStringToUTF8(f.messageString); | 88 result->raw_value = base::SysNSStringToUTF8(f.messageString); |
| 87 results.push_back(std::move(result)); | 89 results.push_back(std::move(result)); |
| 88 } | 90 } |
| 89 scoped_callback.Run(std::move(results)); | 91 scoped_callback.Run(std::move(results)); |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace shape_detection | 94 } // namespace shape_detection |
| OLD | NEW |