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" |
| 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* imageWithSolidColor = UIGraphicsGetImageFromCurrentImageContext(); |
| 19 UIGraphicsEndImageContext(); |
| 20 return imageWithSolidColor; |
| 21 } |
| 22 |
| 23 bool UIImagesAreEqual(UIImage* image1, UIImage* image2) { |
| 24 if (image1 == image2) |
| 25 return true; |
| 26 DCHECK(image1.CGImage); |
| 27 DCHECK(image2.CGImage); |
| 28 |
| 29 bool imagesAreEqual = false; |
| 30 |
| 31 CFDataRef dataRef1 = |
| 32 CGDataProviderCopyData(CGImageGetDataProvider(image1.CGImage)); |
| 33 CFDataRef dataRef2 = |
| 34 CGDataProviderCopyData(CGImageGetDataProvider(image2.CGImage)); |
| 35 CFIndex length1 = CFDataGetLength(dataRef1); |
| 36 CFIndex length2 = CFDataGetLength(dataRef2); |
| 37 if (length1 == length2) { |
| 38 const UInt8* ptr1 = CFDataGetBytePtr(dataRef1); |
| 39 const UInt8* ptr2 = CFDataGetBytePtr(dataRef2); |
| 40 // memcmp returns 0 if length is 0. |
| 41 if (memcmp(ptr1, ptr2, length1) == 0) |
| 42 imagesAreEqual = true; |
| 43 } |
| 44 CFRelease(dataRef1); |
| 45 CFRelease(dataRef2); |
| 46 |
| 47 return imagesAreEqual; |
| 48 } |
| 49 |
| 50 } // namespace uiimage_utils |
| 51 } // namespace test |
| 52 } // namespace ui |
OLD | NEW |