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

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

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