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/mac/scoped_cftyperef.h" |
| 8 |
| 9 namespace ui { |
| 10 namespace test { |
| 11 namespace uiimage_utils { |
| 12 |
| 13 UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color) { |
| 14 UIGraphicsBeginImageContext(size); |
| 15 CGContextRef context = UIGraphicsGetCurrentContext(); |
| 16 CGContextSetFillColorWithColor(context, [color CGColor]); |
| 17 CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height)); |
| 18 UIImage* image_with_solid_color = UIGraphicsGetImageFromCurrentImageContext(); |
| 19 UIGraphicsEndImageContext(); |
| 20 return image_with_solid_color; |
| 21 } |
| 22 |
| 23 bool UIImagesAreEqual(UIImage* image_1, UIImage* image_2) { |
| 24 if (image_1 == image_2) |
| 25 return true; |
| 26 |
| 27 if (!CGSizeEqualToSize(image_1.size, image_2.size)) |
| 28 return false; |
| 29 |
| 30 base::ScopedCFTypeRef<CFDataRef> data_ref_1( |
| 31 CGDataProviderCopyData(CGImageGetDataProvider(image_1.CGImage))); |
| 32 base::ScopedCFTypeRef<CFDataRef> data_ref_2( |
| 33 CGDataProviderCopyData(CGImageGetDataProvider(image_2.CGImage))); |
| 34 CFIndex length_1 = CFDataGetLength(data_ref_1); |
| 35 CFIndex length_2 = CFDataGetLength(data_ref_2); |
| 36 if (length_1 != length_2) { |
| 37 return false; |
| 38 } |
| 39 const UInt8* ptr_1 = CFDataGetBytePtr(data_ref_1); |
| 40 const UInt8* ptr_2 = CFDataGetBytePtr(data_ref_2); |
| 41 |
| 42 // memcmp returns 0 if length is 0. |
| 43 return memcmp(ptr_1, ptr_2, length_1) == 0; |
| 44 } |
| 45 |
| 46 } // namespace uiimage_utils |
| 47 } // namespace test |
| 48 } // namespace ui |
OLD | NEW |