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

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

Issue 10823358: image: Specify the resize-method when resizing ImageSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: deep-copy Created 8 years, 4 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 const gfx::Rect subset_bounds_; 301 const gfx::Rect subset_bounds_;
302 302
303 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); 303 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource);
304 }; 304 };
305 305
306 // ResizeSource resizes relevant image reps in |source| to |target_dip_size| 306 // ResizeSource resizes relevant image reps in |source| to |target_dip_size|
307 // for requested scale factors. 307 // for requested scale factors.
308 class ResizeSource : public ImageSkiaSource { 308 class ResizeSource : public ImageSkiaSource {
309 public: 309 public:
310 ResizeSource(const ImageSkia& source, 310 ResizeSource(const ImageSkia& source,
311 skia::ImageOperations::ResizeMethod method,
311 const Size& target_dip_size) 312 const Size& target_dip_size)
312 : source_(source), 313 : source_(source),
314 resize_method_(method),
313 target_dip_size_(target_dip_size) { 315 target_dip_size_(target_dip_size) {
314 } 316 }
315 virtual ~ResizeSource() {} 317 virtual ~ResizeSource() {}
316 318
317 // gfx::ImageSkiaSource overrides: 319 // gfx::ImageSkiaSource overrides:
318 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { 320 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
319 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); 321 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
320 if (image_rep.GetWidth() == target_dip_size_.width() && 322 if (image_rep.GetWidth() == target_dip_size_.width() &&
321 image_rep.GetHeight() == target_dip_size_.height()) 323 image_rep.GetHeight() == target_dip_size_.height())
322 return image_rep; 324 return image_rep;
323 325
324 const float scale = ui::GetScaleFactorScale(scale_factor); 326 const float scale = ui::GetScaleFactorScale(scale_factor);
325 const Size target_pixel_size(target_dip_size_.Scale(scale)); 327 const Size target_pixel_size(target_dip_size_.Scale(scale));
326 const SkBitmap resized = skia::ImageOperations::Resize( 328 const SkBitmap resized = skia::ImageOperations::Resize(
327 image_rep.sk_bitmap(), 329 image_rep.sk_bitmap(),
328 skia::ImageOperations::RESIZE_BEST, 330 resize_method_,
329 target_pixel_size.width(), 331 target_pixel_size.width(),
330 target_pixel_size.height()); 332 target_pixel_size.height());
331 return ImageSkiaRep(resized, scale_factor); 333 return ImageSkiaRep(resized, scale_factor);
332 } 334 }
333 335
334 private: 336 private:
335 const ImageSkia source_; 337 const ImageSkia source_;
338 skia::ImageOperations::ResizeMethod resize_method_;
336 const Size target_dip_size_; 339 const Size target_dip_size_;
337 340
338 DISALLOW_COPY_AND_ASSIGN(ResizeSource); 341 DISALLOW_COPY_AND_ASSIGN(ResizeSource);
339 }; 342 };
340 343
341 // DropShadowSource generates image reps with drop shadow for image reps in 344 // DropShadowSource generates image reps with drop shadow for image reps in
342 // |source| that represent requested scale factors. 345 // |source| that represent requested scale factors.
343 class DropShadowSource : public ImageSkiaSource { 346 class DropShadowSource : public ImageSkiaSource {
344 public: 347 public:
345 DropShadowSource(const ImageSkia& source, 348 DropShadowSource(const ImageSkia& source,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 gfx::Rect clipped_bounds = subset_bounds.Intersect(gfx::Rect(image.size())); 430 gfx::Rect clipped_bounds = subset_bounds.Intersect(gfx::Rect(image.size()));
428 if (image.isNull() || clipped_bounds.IsEmpty()) { 431 if (image.isNull() || clipped_bounds.IsEmpty()) {
429 return ImageSkia(); 432 return ImageSkia();
430 } 433 }
431 434
432 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds), 435 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds),
433 clipped_bounds.size()); 436 clipped_bounds.size());
434 } 437 }
435 438
436 // static 439 // static
437 ImageSkia ImageSkiaOperations::CreateResizedImage(const ImageSkia& source, 440 ImageSkia ImageSkiaOperations::CreateResizedImage(
438 const Size& target_dip_size) { 441 const ImageSkia& source,
439 return ImageSkia(new ResizeSource(source, target_dip_size), target_dip_size); 442 skia::ImageOperations::ResizeMethod method,
443 const Size& target_dip_size) {
444 return ImageSkia(new ResizeSource(source, method, target_dip_size),
445 target_dip_size);
440 } 446 }
441 447
442 // static 448 // static
443 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( 449 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
444 const ImageSkia& source, 450 const ImageSkia& source,
445 const ShadowValues& shadows) { 451 const ShadowValues& shadows) {
446 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 452 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
447 gfx::Size shadow_image_size = source.size(); 453 gfx::Size shadow_image_size = source.size();
448 shadow_image_size.Enlarge(shadow_padding.width(), 454 shadow_image_size.Enlarge(shadow_padding.width(),
449 shadow_padding.height()); 455 shadow_padding.height());
450 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 456 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
451 } 457 }
452 458
453 } // namespace gfx 459 } // namespace gfx
OLDNEW
« chrome/browser/chromeos/login/wallpaper_manager.cc ('K') | « ui/gfx/image/image_skia_operations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698