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 "skia/ext/skia_utils_ios.h" | 5 #include "skia/ext/skia_utils_ios.h" |
6 | 6 |
7 #import <ImageIO/ImageIO.h> | 7 #import <ImageIO/ImageIO.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
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/macros.h" | 13 #include "base/macros.h" |
14 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 14 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const uint8 kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00}; | 18 const uint8 kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00}; |
19 | 19 |
20 // Returns whether the data encodes an ico image. | 20 // Returns whether the data encodes an ico image. |
21 bool EncodesIcoImage(NSData* image_data) { | 21 bool EncodesIcoImage(NSData* image_data) { |
22 if (image_data.length < arraysize(kICOHeaderMagic)) | 22 if (image_data.length < arraysize(kICOHeaderMagic)) |
23 return false; | 23 return false; |
24 return memcmp(kICOHeaderMagic, image_data.bytes, | 24 return memcmp(kICOHeaderMagic, image_data.bytes, |
25 arraysize(kICOHeaderMagic)) == 0; | 25 arraysize(kICOHeaderMagic)) == 0; |
26 } | 26 } |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 namespace gfx { | 30 namespace skia { |
31 | 31 |
32 SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { | 32 SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { |
33 SkBitmap bitmap; | 33 SkBitmap bitmap; |
34 if (!image) | 34 if (!image) |
35 return bitmap; | 35 return bitmap; |
36 | 36 |
37 if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque)) | 37 if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque)) |
38 return bitmap; | 38 return bitmap; |
39 | 39 |
40 void* data = bitmap.getPixels(); | 40 void* data = bitmap.getPixels(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return frames; | 123 return frames; |
124 } | 124 } |
125 | 125 |
126 UIColor* UIColorFromSkColor(SkColor color) { | 126 UIColor* UIColorFromSkColor(SkColor color) { |
127 return [UIColor colorWithRed:SkColorGetR(color) / 255.0f | 127 return [UIColor colorWithRed:SkColorGetR(color) / 255.0f |
128 green:SkColorGetG(color) / 255.0f | 128 green:SkColorGetG(color) / 255.0f |
129 blue:SkColorGetB(color) / 255.0f | 129 blue:SkColorGetB(color) / 255.0f |
130 alpha:SkColorGetA(color) / 255.0f]; | 130 alpha:SkColorGetA(color) / 255.0f]; |
131 } | 131 } |
132 | 132 |
133 } // namespace gfx | 133 } // namespace skia |
OLD | NEW |