Chromium Code Reviews| Index: ui/gfx/image/image_skia_sources.cc |
| diff --git a/ui/gfx/image/image_skia_sources.cc b/ui/gfx/image/image_skia_sources.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d55f41f02710978d120ed06270f8bb64faed7863 |
| --- /dev/null |
| +++ b/ui/gfx/image/image_skia_sources.cc |
| @@ -0,0 +1,98 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/image/image_skia_sources.h" |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "skia/ext/image_operations.h" |
| +#include "ui/gfx/image/image_skia.h" |
| +#include "ui/gfx/image/image_skia_rep.h" |
| +#include "ui/gfx/image/image_skia_source.h" |
| +#include "ui/gfx/size.h" |
| +#include "ui/gfx/skbitmap_operations.h" |
| + |
| +namespace gfx { |
| +namespace image_skia_sources { |
| + |
| +namespace { |
| + |
| +class ResizeSource : public ImageSkiaSource { |
| + public: |
| + ResizeSource(const ImageSkia& source, |
| + const Size& target_dip_size) |
| + : source_(source), |
| + target_dip_size_(target_dip_size) { |
| + } |
| + ~ResizeSource() {} |
|
oshima
2012/07/03 23:00:06
virtual
xiyuan
2012/07/10 20:02:13
Done.
|
| + |
| + private: |
| + // gfx::ImageSkiaSource overrides: |
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| + const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); |
|
pkotwicz
2012/07/04 00:19:50
I will punt reviewing this file to Oshima.
Here is
xiyuan
2012/07/10 20:02:13
Any update?
pkotwicz
2012/07/10 22:59:56
My thought is that we should cap the maximimum siz
|
| + if (image_rep.GetWidth() == target_dip_size_.width() && |
| + image_rep.GetHeight() == target_dip_size_.height()) |
| + return image_rep; |
| + |
| + const float scale = image_rep.GetScale();; |
| + const Size target_pixel_size(target_dip_size_.Scale(scale)); |
| + const SkBitmap resized = skia::ImageOperations::Resize( |
| + image_rep.sk_bitmap(), |
| + skia::ImageOperations::RESIZE_BEST, |
| + target_pixel_size.width(), |
| + target_pixel_size.height()); |
| + return ImageSkiaRep(resized, image_rep.scale_factor()); |
| + } |
| + |
| + const ImageSkia source_; |
| + const Size target_dip_size_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ResizeSource); |
| +}; |
| + |
| +class DropShadowSource : public ImageSkiaSource { |
| + public: |
| + DropShadowSource(const ImageSkia& source, |
| + const ShadowValues& dip_shadows) |
| + : source_(source), |
| + dip_shadows_(dip_shadows) { |
| + } |
| + virtual ~DropShadowSource() {} |
| + |
| + private: |
| + // gfx::ImageSkiaSource overrides: |
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| + const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); |
| + |
| + const float scale = image_rep.GetScale(); |
| + ShadowValues pixel_shadows; |
| + for (size_t i = 0; i < dip_shadows_.size(); ++i) |
| + pixel_shadows.push_back(dip_shadows_[i].Scale(scale)); |
| + |
| + const SkBitmap shadow_image = SkBitmapOperations::CreateDropShadow( |
| + image_rep.sk_bitmap(), |
| + pixel_shadows); |
| + return ImageSkiaRep(shadow_image, image_rep.scale_factor()); |
| + } |
| + |
| + const ImageSkia source_; |
| + const ShadowValues dip_shadows_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DropShadowSource); |
| +}; |
| + |
| +} // namespace |
| + |
| +ImageSkiaSource* CreateResizeSource(const ImageSkia& source, |
| + const Size& target_dip_size) { |
| + return new ResizeSource(source, target_dip_size); |
| +} |
| + |
| +ImageSkiaSource* CreateDropShadowSource(const ImageSkia& source, |
| + const ShadowValues& shadows) { |
| + return new DropShadowSource(source, shadows); |
| +} |
| + |
| +} // namespace image_skia_sources |
| +} // namesoace gfx |