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
3 // found in the LICENSE file.
5 #import <CoreGraphics/CoreGraphics.h>
6 #import <UIKit/UIKit.h>
8 #include "base/mac/scoped_cftyperef.h"
9 #include "skia/ext/skia_utils_ios.h"
10 #include "ui/gfx/image/image_unittest_util.h"
15 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
16 // Start by extracting the target pixel into a 1x1 CGImage.
17 base::ScopedCFTypeRef<CGImageRef> pixel_image(
18 CGImageCreateWithImageInRect(image.CGImage, CGRectMake(x, y, 1, 1)));
20 // Draw that pixel into a 1x1 bitmap context.
21 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
22 CGColorSpaceCreateDeviceRGB());
23 base::ScopedCFTypeRef<CGContextRef> bitmap_context(CGBitmapContextCreate(
27 /*bitsPerComponent=*/ 8,
30 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
31 CGContextDrawImage(bitmap_context, CGRectMake(0, 0, 1, 1), pixel_image);
33 // The CGBitmapContext has the same memory layout as SkColor, so we can just
34 // read an SkColor straight out of the context.
36 reinterpret_cast<SkColor*>(CGBitmapContextGetData(bitmap_context));