| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import <CoreGraphics/CoreGraphics.h> | 5 #import <CoreGraphics/CoreGraphics.h> |
| 6 #import <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 | 7 |
| 8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
| 9 #include "skia/ext/skia_utils_ios.h" | 9 #include "skia/ext/skia_utils_ios.h" |
| 10 #include "ui/gfx/image/image_unittest_util.h" | 10 #include "ui/gfx/image/image_unittest_util.h" |
| 11 | 11 |
| 12 namespace gfx { | 12 namespace gfx { |
| 13 namespace test { | 13 namespace test { |
| 14 | 14 |
| 15 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) { | 15 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) { |
| 16 // Start by extracting the target pixel into a 1x1 CGImage. | 16 // Start by extracting the target pixel into a 1x1 CGImage. |
| 17 base::mac::ScopedCFTypeRef<CGImageRef> pixel_image( | 17 base::ScopedCFTypeRef<CGImageRef> pixel_image( |
| 18 CGImageCreateWithImageInRect(image.CGImage, CGRectMake(x, y, 1, 1))); | 18 CGImageCreateWithImageInRect(image.CGImage, CGRectMake(x, y, 1, 1))); |
| 19 | 19 |
| 20 // Draw that pixel into a 1x1 bitmap context. | 20 // Draw that pixel into a 1x1 bitmap context. |
| 21 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 21 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
| 22 CGColorSpaceCreateDeviceRGB()); | 22 CGColorSpaceCreateDeviceRGB()); |
| 23 base::mac::ScopedCFTypeRef<CGContextRef> bitmap_context( | 23 base::ScopedCFTypeRef<CGContextRef> bitmap_context(CGBitmapContextCreate( |
| 24 CGBitmapContextCreate(/*data=*/ NULL, | 24 /*data=*/ NULL, |
| 25 /*width=*/ 1, /*height=*/ 1, | 25 /*width=*/ 1, |
| 26 /*bitsPerComponent=*/ 8, /*bytesPerRow=*/ 4, | 26 /*height=*/ 1, |
| 27 color_space, | 27 /*bitsPerComponent=*/ 8, |
| 28 kCGImageAlphaPremultipliedFirst | | 28 /*bytesPerRow=*/ 4, |
| 29 kCGBitmapByteOrder32Host)); | 29 color_space, |
| 30 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); |
| 30 CGContextDrawImage(bitmap_context, CGRectMake(0, 0, 1, 1), pixel_image); | 31 CGContextDrawImage(bitmap_context, CGRectMake(0, 0, 1, 1), pixel_image); |
| 31 | 32 |
| 32 // The CGBitmapContext has the same memory layout as SkColor, so we can just | 33 // The CGBitmapContext has the same memory layout as SkColor, so we can just |
| 33 // read an SkColor straight out of the context. | 34 // read an SkColor straight out of the context. |
| 34 SkColor* data = | 35 SkColor* data = |
| 35 reinterpret_cast<SkColor*>(CGBitmapContextGetData(bitmap_context)); | 36 reinterpret_cast<SkColor*>(CGBitmapContextGetData(bitmap_context)); |
| 36 return *data; | 37 return *data; |
| 37 } | 38 } |
| 38 | 39 |
| 39 } // namespace test | 40 } // namespace test |
| 40 } // namespace gfx | 41 } // namespace gfx |
| OLD | NEW |