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

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

Issue 11017046: Use LANCZOS3 resize algorithm to generate missing image reps for extension action icons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 337 }
338 338
339 private: 339 private:
340 const ImageSkia source_; 340 const ImageSkia source_;
341 skia::ImageOperations::ResizeMethod resize_method_; 341 skia::ImageOperations::ResizeMethod resize_method_;
342 const Size target_dip_size_; 342 const Size target_dip_size_;
343 343
344 DISALLOW_COPY_AND_ASSIGN(ResizeSource); 344 DISALLOW_COPY_AND_ASSIGN(ResizeSource);
345 }; 345 };
346 346
347 // Image source that uses |resize_method| to generate missing image
348 // representations.
349 class FallbackResizeSource : public ImageSkiaSource {
pkotwicz 2012/10/16 22:13:27 Can you use ResizeSource here? Also can you fix th
tbarzic 2012/10/16 23:19:33 Done.
350 public:
351 FallbackResizeSource(const ImageSkia& source,
352 skia::ImageOperations::ResizeMethod resize_method)
353 : source_(source),
354 resize_method_(resize_method) {
355 }
356 virtual ~FallbackResizeSource() {}
357
358 // gfx::ImageSkiaSource overrides:
359 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
360 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
361 if (image_rep.scale_factor() == scale_factor)
362 return image_rep;
363
364 const float scale = ui::GetScaleFactorScale(scale_factor);
365 const Size target_pixel_size = gfx::ToFlooredSize(
366 source_.size().Scale(scale));
367
368 const SkBitmap resized = skia::ImageOperations::Resize(
369 image_rep.sk_bitmap(),
370 resize_method_,
371 target_pixel_size.width(),
372 target_pixel_size.height());
373 return ImageSkiaRep(resized, scale_factor);
374 }
375
376 private:
377 ImageSkia source_;
378 skia::ImageOperations::ResizeMethod resize_method_;
379 };
380
347 // DropShadowSource generates image reps with drop shadow for image reps in 381 // DropShadowSource generates image reps with drop shadow for image reps in
348 // |source| that represent requested scale factors. 382 // |source| that represent requested scale factors.
349 class DropShadowSource : public ImageSkiaSource { 383 class DropShadowSource : public ImageSkiaSource {
350 public: 384 public:
351 DropShadowSource(const ImageSkia& source, 385 DropShadowSource(const ImageSkia& source,
352 const ShadowValues& shadows_in_dip) 386 const ShadowValues& shadows_in_dip)
353 : source_(source), 387 : source_(source),
354 shaodws_in_dip_(shadows_in_dip) { 388 shaodws_in_dip_(shadows_in_dip) {
355 } 389 }
356 virtual ~DropShadowSource() {} 390 virtual ~DropShadowSource() {}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // static 476 // static
443 ImageSkia ImageSkiaOperations::CreateResizedImage( 477 ImageSkia ImageSkiaOperations::CreateResizedImage(
444 const ImageSkia& source, 478 const ImageSkia& source,
445 skia::ImageOperations::ResizeMethod method, 479 skia::ImageOperations::ResizeMethod method,
446 const Size& target_dip_size) { 480 const Size& target_dip_size) {
447 return ImageSkia(new ResizeSource(source, method, target_dip_size), 481 return ImageSkia(new ResizeSource(source, method, target_dip_size),
448 target_dip_size); 482 target_dip_size);
449 } 483 }
450 484
451 // static 485 // static
486 ImageSkia ImageSkiaOperations::CreateImageWithFallbackResizeMethod(
487 const ImageSkia& source,
488 skia::ImageOperations::ResizeMethod resize_method) {
489 return ImageSkia(new FallbackResizeSource(source, resize_method),
490 source.size());
491 }
492
493 // static
452 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( 494 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
453 const ImageSkia& source, 495 const ImageSkia& source,
454 const ShadowValues& shadows) { 496 const ShadowValues& shadows) {
455 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 497 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
456 gfx::Size shadow_image_size = source.size(); 498 gfx::Size shadow_image_size = source.size();
457 shadow_image_size.Enlarge(shadow_padding.width(), 499 shadow_image_size.Enlarge(shadow_padding.width(),
458 shadow_padding.height()); 500 shadow_padding.height());
459 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 501 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
460 } 502 }
461 503
462 } // namespace gfx 504 } // namespace gfx
OLDNEW
« ui/gfx/image/image_skia_operations.h ('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