OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/base/test/ios/ui_image_test_utils.h" | |
6 | |
7 #include "base/logging.h" | |
marq (ping after 24h)
2017/01/27 12:52:56
I don't see where this is used.
jif
2017/01/27 13:51:54
Good catch. Done.
| |
8 #include "base/mac/scoped_cftyperef.h" | |
9 | |
10 namespace ui { | |
11 namespace test { | |
12 namespace uiimage_utils { | |
13 | |
14 UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color) { | |
15 UIGraphicsBeginImageContext(size); | |
16 CGContextRef context = UIGraphicsGetCurrentContext(); | |
17 CGContextSetFillColorWithColor(context, [color CGColor]); | |
18 CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height)); | |
19 UIImage* image_with_solid_color = UIGraphicsGetImageFromCurrentImageContext(); | |
20 UIGraphicsEndImageContext(); | |
21 return image_with_solid_color; | |
22 } | |
23 | |
24 bool UIImagesAreEqual(UIImage* image_1, UIImage* image_2) { | |
25 if (image_1 == image_2) | |
26 return true; | |
27 | |
28 if (!CGSizeEqualToSize(image_1.size, image_2.size)) | |
29 return false; | |
30 | |
31 bool images_are_equal = false; | |
32 | |
33 base::ScopedCFTypeRef<CFDataRef> data_ref_1( | |
34 CGDataProviderCopyData(CGImageGetDataProvider(image_1.CGImage))); | |
35 base::ScopedCFTypeRef<CFDataRef> data_ref_2( | |
36 CGDataProviderCopyData(CGImageGetDataProvider(image_2.CGImage))); | |
37 CFIndex length_1 = CFDataGetLength(data_ref_1); | |
38 CFIndex length_2 = CFDataGetLength(data_ref_2); | |
39 if (length_1 == length_2) { | |
40 const UInt8* ptr_1 = CFDataGetBytePtr(data_ref_1); | |
41 const UInt8* ptr_2 = CFDataGetBytePtr(data_ref_2); | |
42 | |
43 // memcmp returns 0 if length is 0. | |
44 if (memcmp(ptr_1, ptr_2, length_1) == 0) | |
45 images_are_equal = true; | |
46 } | |
47 | |
48 return images_are_equal; | |
49 } | |
50 | |
51 } // namespace uiimage_utils | |
52 } // namespace test | |
53 } // namespace ui | |
OLD | NEW |