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

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

Issue 2755393002: Revert of RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: 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(const SkBitmap& bitmap, 51 void TextDetectionImplMac::Detect(mojo::ScopedSharedBufferHandle frame_data,
52 uint32_t width,
53 uint32_t height,
52 const DetectCallback& callback) { 54 const DetectCallback& callback) {
53 DCHECK(base::mac::IsAtLeastOS10_11()); 55 DCHECK(base::mac::IsAtLeastOS10_11());
54 media::ScopedResultCallback<DetectCallback> scoped_callback( 56 media::ScopedResultCallback<DetectCallback> scoped_callback(
55 base::Bind(&RunCallbackWithResults, callback), 57 base::Bind(&RunCallbackWithResults, callback),
56 base::Bind(&RunCallbackWithNoResults)); 58 base::Bind(&RunCallbackWithNoResults));
57 59
58 base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap); 60 base::scoped_nsobject<CIImage> ci_image =
61 CreateCIImageFromSharedMemory(std::move(frame_data), width, height);
59 if (!ci_image) 62 if (!ci_image)
60 return; 63 return;
61 64
62 NSArray* const features = [detector_ featuresInImage:ci_image]; 65 NSArray* const features = [detector_ featuresInImage:ci_image];
63 66
64 const int height = bitmap.height();
65 std::vector<mojom::TextDetectionResultPtr> results; 67 std::vector<mojom::TextDetectionResultPtr> results;
66 for (CIRectangleFeature* const f in features) { 68 for (CIRectangleFeature* const f in features) {
67 // CIRectangleFeature only has bounding box information. 69 // CIRectangleFeature only has bounding box information.
68 auto result = mojom::TextDetectionResult::New(); 70 auto result = mojom::TextDetectionResult::New();
69 // In the default Core Graphics coordinate space, the origin is located 71 // In the default Core Graphics coordinate space, the origin is located
70 // 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.
71 // 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.
72 gfx::RectF boundingbox(f.bounds.origin.x, 74 gfx::RectF boundingbox(f.bounds.origin.x,
73 height - f.bounds.origin.y - f.bounds.size.height, 75 height - f.bounds.origin.y - f.bounds.size.height,
74 f.bounds.size.width, f.bounds.size.height); 76 f.bounds.size.width, f.bounds.size.height);
75 result->bounding_box = std::move(boundingbox); 77 result->bounding_box = std::move(boundingbox);
76 results.push_back(std::move(result)); 78 results.push_back(std::move(result));
77 } 79 }
78 scoped_callback.Run(std::move(results)); 80 scoped_callback.Run(std::move(results));
79 } 81 }
80 82
81 } // 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