| 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 #include "ui/gfx/image/image.h" | 5 #include "ui/gfx/image/image.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #import <UIKit/UIKit.h> | 9 #import <UIKit/UIKit.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/memory/scoped_nsobject.h" | 13 #include "base/memory/scoped_nsobject.h" |
| 14 #include "ui/base/layout.h" | 14 #include "ui/base/layout.h" |
| 15 #include "ui/gfx/image/image_png_rep.h" | 15 #include "ui/gfx/image/image_png_rep.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 17 #include "ui/gfx/image/image_skia_util_ios.h" | 17 #include "ui/gfx/image/image_skia_util_ios.h" |
| 18 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
| 19 | 19 |
| 20 namespace gfx { | 20 namespace gfx { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Returns a 16x16 red UIImage to visually show when a UIImage cannot be | 25 // Returns a 16x16 red UIImage to visually show when a UIImage cannot be |
| 26 // created from PNG data. Logs error as well. | 26 // created from PNG data. Logs error as well. |
| 27 // Caller takes ownership of returned UIImage. | 27 // Caller takes ownership of returned UIImage. |
| 28 UIImage* CreateErrorUIImage(float scale) { | 28 UIImage* CreateErrorUIImage(float scale) { |
| 29 LOG(ERROR) << "Unable to decode PNG into UIImage."; | 29 LOG(ERROR) << "Unable to decode PNG into UIImage."; |
| 30 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 30 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
| 31 CGColorSpaceCreateDeviceRGB()); | 31 CGColorSpaceCreateDeviceRGB()); |
| 32 base::mac::ScopedCFTypeRef<CGContextRef> context( | 32 base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate( |
| 33 CGBitmapContextCreate(NULL, // Allow CG to allocate memory. | 33 NULL, // Allow CG to allocate memory. |
| 34 16, // width | 34 16, // width |
| 35 16, // height | 35 16, // height |
| 36 8, // bitsPerComponent | 36 8, // bitsPerComponent |
| 37 0, // CG will calculate by default. | 37 0, // CG will calculate by default. |
| 38 color_space, | 38 color_space, |
| 39 kCGImageAlphaPremultipliedFirst | | 39 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); |
| 40 kCGBitmapByteOrder32Host)); | |
| 41 CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0); | 40 CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0); |
| 42 CGContextFillRect(context, CGRectMake(0.0, 0.0, 16, 16)); | 41 CGContextFillRect(context, CGRectMake(0.0, 0.0, 16, 16)); |
| 43 base::mac::ScopedCFTypeRef<CGImageRef> cg_image( | 42 base::ScopedCFTypeRef<CGImageRef> cg_image( |
| 44 CGBitmapContextCreateImage(context)); | 43 CGBitmapContextCreateImage(context)); |
| 45 return [[UIImage imageWithCGImage:cg_image.get() | 44 return [[UIImage imageWithCGImage:cg_image.get() |
| 46 scale:scale | 45 scale:scale |
| 47 orientation:UIImageOrientationUp] retain]; | 46 orientation:UIImageOrientationUp] retain]; |
| 48 } | 47 } |
| 49 | 48 |
| 50 // Converts from ImagePNGRep to UIImage. | 49 // Converts from ImagePNGRep to UIImage. |
| 51 UIImage* CreateUIImageFromImagePNGRep(const gfx::ImagePNGRep& image_png_rep) { | 50 UIImage* CreateUIImageFromImagePNGRep(const gfx::ImagePNGRep& image_png_rep) { |
| 52 float scale = ui::GetScaleFactorScale(image_png_rep.scale_factor); | 51 float scale = ui::GetScaleFactorScale(image_png_rep.scale_factor); |
| 53 scoped_refptr<base::RefCountedMemory> png = image_png_rep.raw_data; | 52 scoped_refptr<base::RefCountedMemory> png = image_png_rep.raw_data; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 128 } |
| 130 | 129 |
| 131 gfx::Size UIImageSize(UIImage* image) { | 130 gfx::Size UIImageSize(UIImage* image) { |
| 132 int width = static_cast<int>(image.size.width); | 131 int width = static_cast<int>(image.size.width); |
| 133 int height = static_cast<int>(image.size.height); | 132 int height = static_cast<int>(image.size.height); |
| 134 return gfx::Size(width, height); | 133 return gfx::Size(width, height); |
| 135 } | 134 } |
| 136 | 135 |
| 137 } // namespace internal | 136 } // namespace internal |
| 138 } // namespace gfx | 137 } // namespace gfx |
| OLD | NEW |