Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ui/gfx/image/image_ios.mm

Issue 11293147: Always add 100P scale format in the supported format list. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding TODO. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/resource/resource_bundle_ios.mm ('k') | ui/gfx/image/image_skia_util_ios.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_nsobject.h" 10 #include "base/memory/scoped_nsobject.h"
11 #include "ui/base/layout.h" 11 #include "ui/base/layout.h"
12 #include "ui/gfx/image/image_skia.h" 12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/image/image_skia_util_ios.h" 13 #include "ui/gfx/image/image_skia_util_ios.h"
14 14
15 namespace gfx { 15 namespace gfx {
16 namespace internal { 16 namespace internal {
17 17
18 void PNGFromUIImage(UIImage* uiimage, std::vector<unsigned char>* png) { 18 void PNGFromUIImage(UIImage* uiimage, std::vector<unsigned char>* png) {
19 NSData* data = UIImagePNGRepresentation(uiimage); 19 NSData* data = UIImagePNGRepresentation(uiimage);
20 20
21 if ([data length] == 0) 21 if ([data length] == 0)
22 return; 22 return;
23 23
24 png->resize([data length]); 24 png->resize([data length]);
25 [data getBytes:&png->at(0) length:[data length]]; 25 [data getBytes:&png->at(0) length:[data length]];
26 } 26 }
27 27
28 UIImage* CreateUIImageFromPNG(const std::vector<unsigned char>& png) { 28 UIImage* CreateUIImageFromPNG(const std::vector<unsigned char>& png) {
29 // iOS only supports one scale factor. 29 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
30 std::vector<ui::ScaleFactor> supported_scale_factors =
31 ui::GetSupportedScaleFactors();
32 DCHECK_EQ(1U, supported_scale_factors.size());
33 if (supported_scale_factors.size() < 1)
34 return nil;
35
36 ui::ScaleFactor scale_factor = supported_scale_factors[0];
37 float scale = ui::GetScaleFactorScale(scale_factor); 30 float scale = ui::GetScaleFactorScale(scale_factor);
38 31
39 NSData* data = [NSData dataWithBytes:&png.front() length:png.size()]; 32 NSData* data = [NSData dataWithBytes:&png.front() length:png.size()];
40 scoped_nsobject<UIImage> image ( 33 scoped_nsobject<UIImage> image (
41 [[UIImage alloc] initWithData:data scale:scale]); 34 [[UIImage alloc] initWithData:data scale:scale]);
42 if (!image) { 35 if (!image) {
43 LOG(WARNING) << "Unable to decode PNG into UIImage."; 36 LOG(WARNING) << "Unable to decode PNG into UIImage.";
44 // Return a 16x16 red image to visually show error. 37 // Return a 16x16 red image to visually show error.
45 BOOL opaque = YES; 38 BOOL opaque = YES;
46 UIGraphicsBeginImageContextWithOptions(CGSizeMake(16, 16), opaque, scale); 39 UIGraphicsBeginImageContextWithOptions(CGSizeMake(16, 16), opaque, scale);
(...skipping 28 matching lines...) Expand all
75 bitmap.allocPixels(); 68 bitmap.allocPixels();
76 bitmap.eraseRGB(0xff, 0, 0); 69 bitmap.eraseRGB(0xff, 0, 0);
77 return new ImageSkia(bitmap); 70 return new ImageSkia(bitmap);
78 } 71 }
79 72
80 return new ImageSkia(ImageSkiaFromUIImage(uiimage)); 73 return new ImageSkia(ImageSkiaFromUIImage(uiimage));
81 } 74 }
82 75
83 } // namespace internal 76 } // namespace internal
84 } // namespace gfx 77 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_ios.mm ('k') | ui/gfx/image/image_skia_util_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698