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

Side by Side Diff: services/shape_detection/barcode_detection_impl_mac.mm

Issue 2681913003: RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: Fix the issue of failing to fetch bitmap module Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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
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(mojo::ScopedSharedBufferHandle frame_data, 53 void BarcodeDetectionImplMac::Detect(const SkBitmap& bitmap,
54 uint32_t width,
55 uint32_t height,
56 const DetectCallback& callback) { 54 const DetectCallback& callback) {
57 media::ScopedResultCallback<DetectCallback> scoped_callback( 55 media::ScopedResultCallback<DetectCallback> scoped_callback(
58 base::Bind(&RunCallbackWithBarcodes, callback), 56 base::Bind(&RunCallbackWithBarcodes, callback),
59 base::Bind(&RunCallbackWithNoBarcodes)); 57 base::Bind(&RunCallbackWithNoBarcodes));
60 58
61 base::scoped_nsobject<CIImage> ci_image = 59 base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap);
62 CreateCIImageFromSharedMemory(std::move(frame_data), width, height);
63 if (!ci_image) 60 if (!ci_image)
64 return; 61 return;
65 62
66 NSArray* const features = [detector_ featuresInImage:ci_image]; 63 NSArray* const features = [detector_ featuresInImage:ci_image];
67 64
68 std::vector<mojom::BarcodeDetectionResultPtr> results; 65 std::vector<mojom::BarcodeDetectionResultPtr> results;
66 const int height = bitmap.height();
69 for (CIQRCodeFeature* const f in features) { 67 for (CIQRCodeFeature* const f in features) {
70 shape_detection::mojom::BarcodeDetectionResultPtr result = 68 shape_detection::mojom::BarcodeDetectionResultPtr result =
71 shape_detection::mojom::BarcodeDetectionResult::New(); 69 shape_detection::mojom::BarcodeDetectionResult::New();
72 // In the default Core Graphics coordinate space, the origin is located 70 // In the default Core Graphics coordinate space, the origin is located
73 // in the lower-left corner, and thus |ci_image| is flipped vertically. 71 // in the lower-left corner, and thus |ci_image| is flipped vertically.
74 // We need to adjust |y| coordinate of bounding box before sending it. 72 // We need to adjust |y| coordinate of bounding box before sending it.
75 gfx::RectF boundingbox(f.bounds.origin.x, 73 gfx::RectF boundingbox(f.bounds.origin.x,
76 height - f.bounds.origin.y - f.bounds.size.height, 74 height - f.bounds.origin.y - f.bounds.size.height,
77 f.bounds.size.width, f.bounds.size.height); 75 f.bounds.size.width, f.bounds.size.height);
78 result->bounding_box = std::move(boundingbox); 76 result->bounding_box = std::move(boundingbox);
79 77
80 // Enumerate corner points starting from top-left in clockwise fashion: 78 // Enumerate corner points starting from top-left in clockwise fashion:
81 // https://wicg.github.io/shape-detection-api/#dom-detectedbarcode-cornerpoi nts 79 // https://wicg.github.io/shape-detection-api/#dom-detectedbarcode-cornerpoi nts
82 result->corner_points.emplace_back(f.topLeft.x, height - f.topLeft.y); 80 result->corner_points.emplace_back(f.topLeft.x, height - f.topLeft.y);
83 result->corner_points.emplace_back(f.topRight.x, height - f.topRight.y); 81 result->corner_points.emplace_back(f.topRight.x, height - f.topRight.y);
84 result->corner_points.emplace_back(f.bottomRight.x, 82 result->corner_points.emplace_back(f.bottomRight.x,
85 height - f.bottomRight.y); 83 height - f.bottomRight.y);
86 result->corner_points.emplace_back(f.bottomLeft.x, height - f.bottomLeft.y); 84 result->corner_points.emplace_back(f.bottomLeft.x, height - f.bottomLeft.y);
87 85
88 result->raw_value = base::SysNSStringToUTF8(f.messageString); 86 result->raw_value = base::SysNSStringToUTF8(f.messageString);
89 results.push_back(std::move(result)); 87 results.push_back(std::move(result));
90 } 88 }
91 scoped_callback.Run(std::move(results)); 89 scoped_callback.Run(std::move(results));
92 } 90 }
93 91
94 } // namespace shape_detection 92 } // namespace shape_detection
OLDNEW
« no previous file with comments | « services/shape_detection/barcode_detection_impl_mac.h ('k') | services/shape_detection/barcode_detection_impl_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698