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

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

Issue 2753413002: RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: include the generated JS bindings for bitmap.mojom in the layout tests archive. 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/text_detection_impl_mac.h" 5 #include "services/shape_detection/text_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 30 matching lines...) Expand all
41 41
42 TextDetectionImplMac::TextDetectionImplMac() { 42 TextDetectionImplMac::TextDetectionImplMac() {
43 NSDictionary* const opts = @{CIDetectorAccuracy : CIDetectorAccuracyHigh}; 43 NSDictionary* const opts = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
44 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeText 44 detector_.reset([[CIDetector detectorOfType:CIDetectorTypeText
45 context:nil 45 context:nil
46 options:opts] retain]); 46 options:opts] retain]);
47 } 47 }
48 48
49 TextDetectionImplMac::~TextDetectionImplMac() {} 49 TextDetectionImplMac::~TextDetectionImplMac() {}
50 50
51 void TextDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data, 51 void TextDetectionImplMac::Detect(const SkBitmap& bitmap,
52 uint32_t width,
53 uint32_t height,
54 const DetectCallback& callback) { 52 const DetectCallback& callback) {
55 DCHECK(base::mac::IsAtLeastOS10_11()); 53 DCHECK(base::mac::IsAtLeastOS10_11());
56 media::ScopedResultCallback<DetectCallback> scoped_callback( 54 media::ScopedResultCallback<DetectCallback> scoped_callback(
57 base::Bind(&RunCallbackWithResults, callback), 55 base::Bind(&RunCallbackWithResults, callback),
58 base::Bind(&RunCallbackWithNoResults)); 56 base::Bind(&RunCallbackWithNoResults));
59 57
60 base::scoped_nsobject<CIImage> ci_image = 58 base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap);
61 CreateCIImageFromSharedMemory(std::move(frame_data), width, height);
62 if (!ci_image) 59 if (!ci_image)
63 return; 60 return;
64 61
65 NSArray* const features = [detector_ featuresInImage:ci_image]; 62 NSArray* const features = [detector_ featuresInImage:ci_image];
66 63
64 const int height = bitmap.height();
67 std::vector<mojom::TextDetectionResultPtr> results; 65 std::vector<mojom::TextDetectionResultPtr> results;
68 for (CIRectangleFeature* const f in features) { 66 for (CIRectangleFeature* const f in features) {
69 // CIRectangleFeature only has bounding box information. 67 // CIRectangleFeature only has bounding box information.
70 auto result = mojom::TextDetectionResult::New(); 68 auto result = mojom::TextDetectionResult::New();
71 // In the default Core Graphics coordinate space, the origin is located 69 // In the default Core Graphics coordinate space, the origin is located
72 // in the lower-left corner, and thus |ci_image| is flipped vertically. 70 // in the lower-left corner, and thus |ci_image| is flipped vertically.
73 // We need to adjust |y| coordinate of bounding box before sending it. 71 // We need to adjust |y| coordinate of bounding box before sending it.
74 gfx::RectF boundingbox(f.bounds.origin.x, 72 gfx::RectF boundingbox(f.bounds.origin.x,
75 height - f.bounds.origin.y - f.bounds.size.height, 73 height - f.bounds.origin.y - f.bounds.size.height,
76 f.bounds.size.width, f.bounds.size.height); 74 f.bounds.size.width, f.bounds.size.height);
77 result->bounding_box = std::move(boundingbox); 75 result->bounding_box = std::move(boundingbox);
78 results.push_back(std::move(result)); 76 results.push_back(std::move(result));
79 } 77 }
80 scoped_callback.Run(std::move(results)); 78 scoped_callback.Run(std::move(results));
81 } 79 }
82 80
83 } // namespace shape_detection 81 } // namespace shape_detection
OLDNEW
« no previous file with comments | « services/shape_detection/text_detection_impl_mac.h ('k') | services/shape_detection/text_detection_impl_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698