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

Side by Side Diff: ui/gfx/image/image_skia_operations.cc

Issue 10783015: Add ability to store hidpi theme images in data pack (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_skia_operations.h" 5 #include "ui/gfx/image/image_skia_operations.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "skia/ext/image_operations.h" 9 #include "skia/ext/image_operations.h"
10 #include "skia/ext/platform_canvas.h" 10 #include "skia/ext/platform_canvas.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 ImageSkiaRep* target = NULL; 51 ImageSkiaRep* target = NULL;
52 if (first->scale_factor() == ui::SCALE_FACTOR_100P) { 52 if (first->scale_factor() == ui::SCALE_FACTOR_100P) {
53 target = first; 53 target = first;
54 } else { 54 } else {
55 target = second; 55 target = second;
56 } 56 }
57 *target = Create2XImageSkiaRep(*target); 57 *target = Create2XImageSkiaRep(*target);
58 } 58 }
59 } 59 }
60 60
61 class ResizingImageSource : public ImageSkiaSource {
62 public:
63 ResizingImageSource(const ImageSkia& source,
64 const Size& target_size_in_dip)
65 : source_(source),
66 target_size_in_dip_(target_size_in_dip) {
67 DCHECK(source.width() <= 64);
68 DCHECK(source.height() <= 64);
69 DCHECK(target_size_in_dip.width() <= 64);
70 DCHECK(target_size_in_dip.height() <= 64);
71 }
72 virtual ~ResizingImageSource() {}
73
74 // gfx::ImageSkiaSource overrides:
75 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
76 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
77 if (image_rep.GetWidth() == target_size_in_dip_.width() &&
78 image_rep.GetHeight() == target_size_in_dip_.height()) {
79 return image_rep;
80 }
81
82 const float scale = image_rep.GetScale();;
83 const Size target_pixel_size(target_size_in_dip_.Scale(scale));
84 const SkBitmap resized = skia::ImageOperations::Resize(
85 image_rep.sk_bitmap(),
86 skia::ImageOperations::RESIZE_BEST,
87 target_pixel_size.width(),
88 target_pixel_size.height());
89 return ImageSkiaRep(resized, image_rep.scale_factor());
90 }
91
92 private:
93 const ImageSkia source_;
94 const Size target_size_in_dip_;
95
96 DISALLOW_COPY_AND_ASSIGN(ResizingImageSource);
97 };
98
61 class BlendingImageSource : public gfx::ImageSkiaSource { 99 class BlendingImageSource : public gfx::ImageSkiaSource {
62 public: 100 public:
63 BlendingImageSource(const ImageSkia& first, 101 BlendingImageSource(const ImageSkia& first,
64 const ImageSkia& second, 102 const ImageSkia& second,
65 double alpha) 103 double alpha)
66 : first_(first), 104 : first_(first),
67 second_(second), 105 second_(second),
68 alpha_(alpha) { 106 alpha_(alpha) {
69 } 107 }
70 108
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor); 165 ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor);
128 float scale = ui::GetScaleFactorScale(source_rep.scale_factor()); 166 float scale = ui::GetScaleFactorScale(source_rep.scale_factor());
129 return ImageSkiaRep( 167 return ImageSkiaRep(
130 SkBitmapOperations::CreateTiledBitmap( 168 SkBitmapOperations::CreateTiledBitmap(
131 source_rep.sk_bitmap(), 169 source_rep.sk_bitmap(),
132 src_x_ * scale, src_y_ * scale, dst_w_ * scale, dst_h_ * scale), 170 src_x_ * scale, src_y_ * scale, dst_w_ * scale, dst_h_ * scale),
133 source_rep.scale_factor()); 171 source_rep.scale_factor());
134 } 172 }
135 173
136 private: 174 private:
137 const ImageSkia& source_; 175 const ImageSkia source_;
138 const int src_x_; 176 const int src_x_;
139 const int src_y_; 177 const int src_y_;
140 const int dst_w_; 178 const int dst_w_;
141 const int dst_h_; 179 const int dst_h_;
142 180
143 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); 181 DISALLOW_COPY_AND_ASSIGN(TiledImageSource);
144 }; 182 };
145 183
184 class HSLImageSource: public gfx::ImageSkiaSource {
185 public:
186 HSLImageSource(const ImageSkia& image,
187 const color_utils::HSL& hsl_shift)
188 : image_(image),
189 hsl_shift_(hsl_shift) {
190 }
191
192 // gfx::ImageSkiaSource overrides:
193 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
194 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
195 return gfx::ImageSkiaRep(
196 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(),
197 hsl_shift_), image_rep.scale_factor());
198 }
199
200 private:
201 const gfx::ImageSkia image_;
202 const color_utils::HSL hsl_shift_;
203
204 DISALLOW_COPY_AND_ASSIGN(HSLImageSource);
205 };
206
146 // ResizeSource resizes relevant image reps in |source| to |target_dip_size| 207 // ResizeSource resizes relevant image reps in |source| to |target_dip_size|
147 // for requested scale factors. 208 // for requested scale factors.
148 class ResizeSource : public ImageSkiaSource { 209 class ResizeSource : public ImageSkiaSource {
149 public: 210 public:
150 ResizeSource(const ImageSkia& source, 211 ResizeSource(const ImageSkia& source,
151 const Size& target_dip_size) 212 const Size& target_dip_size)
152 : source_(source), 213 : source_(source),
153 target_dip_size_(target_dip_size) { 214 target_dip_size_(target_dip_size) {
154 } 215 }
155 virtual ~ResizeSource() {} 216 virtual ~ResizeSource() {}
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 289
229 // static 290 // static
230 ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source, 291 ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source,
231 int src_x, int src_y, 292 int src_x, int src_y,
232 int dst_w, int dst_h) { 293 int dst_w, int dst_h) {
233 return ImageSkia(new TiledImageSource(source, src_x, src_y, dst_w, dst_h), 294 return ImageSkia(new TiledImageSource(source, src_x, src_y, dst_w, dst_h),
234 gfx::Size(dst_w, dst_h)); 295 gfx::Size(dst_w, dst_h));
235 } 296 }
236 297
237 // static 298 // static
299 ImageSkia ImageSkiaOperations::CreateHSLShiftedImage(
300 const ImageSkia& image,
301 const color_utils::HSL& hsl_shift) {
302 return ImageSkia(new HSLImageSource(image, hsl_shift), image.size());
303 }
304
305 // static
238 ImageSkia ImageSkiaOperations::CreateResizedImage(const ImageSkia& source, 306 ImageSkia ImageSkiaOperations::CreateResizedImage(const ImageSkia& source,
239 const Size& target_dip_size) { 307 const Size& target_dip_size) {
240 return ImageSkia(new ResizeSource(source, target_dip_size), target_dip_size); 308 return ImageSkia(new ResizeSource(source, target_dip_size), target_dip_size);
241 } 309 }
242 310
243 // static 311 // static
244 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( 312 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
245 const ImageSkia& source, 313 const ImageSkia& source,
246 const ShadowValues& shadows) { 314 const ShadowValues& shadows) {
247 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 315 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
248 gfx::Size shadow_image_size = source.size(); 316 gfx::Size shadow_image_size = source.size();
249 shadow_image_size.Enlarge(shadow_padding.width(), 317 shadow_image_size.Enlarge(shadow_padding.width(),
250 shadow_padding.height()); 318 shadow_padding.height());
251 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 319 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
252 } 320 }
253 321
254 } // namespace gfx 322 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698