Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gfx/image/image_skia_sources.h" | |
|
pkotwicz
2012/07/10 22:59:56
Move this file here: https://chromiumcodereview.ap
xiyuan
2012/07/11 17:39:13
Done.
| |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "skia/ext/image_operations.h" | |
| 10 #include "ui/gfx/image/image_skia.h" | |
| 11 #include "ui/gfx/image/image_skia_rep.h" | |
| 12 #include "ui/gfx/image/image_skia_source.h" | |
| 13 #include "ui/gfx/size.h" | |
| 14 #include "ui/gfx/skbitmap_operations.h" | |
| 15 | |
| 16 namespace gfx { | |
| 17 namespace image_skia_sources { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class ResizeSource : public ImageSkiaSource { | |
| 22 public: | |
| 23 ResizeSource(const ImageSkia& source, | |
| 24 const Size& target_dip_size) | |
| 25 : source_(source), | |
| 26 target_dip_size_(target_dip_size) { | |
| 27 } | |
| 28 virtual ~ResizeSource() {} | |
| 29 | |
| 30 private: | |
| 31 // gfx::ImageSkiaSource overrides: | |
| 32 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
| 33 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | |
| 34 if (image_rep.GetWidth() == target_dip_size_.width() && | |
| 35 image_rep.GetHeight() == target_dip_size_.height()) | |
| 36 return image_rep; | |
| 37 | |
| 38 const float scale = image_rep.GetScale();; | |
| 39 const Size target_pixel_size(target_dip_size_.Scale(scale)); | |
| 40 const SkBitmap resized = skia::ImageOperations::Resize( | |
| 41 image_rep.sk_bitmap(), | |
| 42 skia::ImageOperations::RESIZE_BEST, | |
| 43 target_pixel_size.width(), | |
| 44 target_pixel_size.height()); | |
| 45 return ImageSkiaRep(resized, image_rep.scale_factor()); | |
| 46 } | |
| 47 | |
| 48 const ImageSkia source_; | |
| 49 const Size target_dip_size_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(ResizeSource); | |
| 52 }; | |
| 53 | |
| 54 class DropShadowSource : public ImageSkiaSource { | |
| 55 public: | |
| 56 DropShadowSource(const ImageSkia& source, | |
| 57 const ShadowValues& dip_shadows) | |
| 58 : source_(source), | |
| 59 dip_shadows_(dip_shadows) { | |
| 60 } | |
| 61 virtual ~DropShadowSource() {} | |
| 62 | |
| 63 private: | |
| 64 // gfx::ImageSkiaSource overrides: | |
| 65 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
| 66 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | |
| 67 | |
| 68 const float scale = image_rep.GetScale(); | |
| 69 ShadowValues pixel_shadows; | |
|
pkotwicz
2012/07/10 22:59:56
rename to shadows_in_pixel to be consistent with o
xiyuan
2012/07/11 17:39:13
Done.
| |
| 70 for (size_t i = 0; i < dip_shadows_.size(); ++i) | |
| 71 pixel_shadows.push_back(dip_shadows_[i].Scale(scale)); | |
| 72 | |
| 73 const SkBitmap shadow_image = SkBitmapOperations::CreateDropShadow( | |
| 74 image_rep.sk_bitmap(), | |
| 75 pixel_shadows); | |
| 76 return ImageSkiaRep(shadow_image, image_rep.scale_factor()); | |
| 77 } | |
| 78 | |
| 79 const ImageSkia source_; | |
| 80 const ShadowValues dip_shadows_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); | |
| 83 }; | |
| 84 | |
| 85 } // namespace | |
| 86 | |
| 87 ImageSkiaSource* CreateResizeSource(const ImageSkia& source, | |
| 88 const Size& target_dip_size) { | |
| 89 return new ResizeSource(source, target_dip_size); | |
| 90 } | |
| 91 | |
| 92 ImageSkiaSource* CreateDropShadowSource(const ImageSkia& source, | |
| 93 const ShadowValues& shadows) { | |
| 94 return new DropShadowSource(source, shadows); | |
| 95 } | |
| 96 | |
| 97 } // namespace image_skia_sources | |
| 98 } // namesoace gfx | |
| OLD | NEW |