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

Unified Diff: ui/gfx/image/image_skia_operations.cc

Issue 10704199: Implement remaining SkBitmapOperations as ImageSkiaOperations (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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/image/image_skia_operations.cc
diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc
index a474f6ef6f6d04022b71d1859c82a051a188bdec..62b1053735bc9754f65041a9120bb6113a3159aa 100644
--- a/ui/gfx/image/image_skia_operations.cc
+++ b/ui/gfx/image/image_skia_operations.cc
@@ -180,6 +180,106 @@ class TiledImageSource : public gfx::ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(TiledImageSource);
};
+class ButtonImageSource: public gfx::ImageSkiaSource {
+ public:
+ ButtonImageSource(SkColor color,
+ const ImageSkia& image,
+ const ImageSkia& mask)
+ : color_(color),
+ image_(image),
+ mask_(mask) {
+ }
oshima 2012/07/13 16:54:55 destructor
pkotwicz 2012/07/15 03:36:48 Done.
+
+ // gfx::ImageSkiaSource overrides:
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ ImageSkiaRep mask_rep = mask_.GetRepresentation(scale_factor);
+ MatchScale(&image_rep, &mask_rep);
+ return ImageSkiaRep(
+ SkBitmapOperations::CreateButtonBackground(color_,
+ image_rep.sk_bitmap(), mask_rep.sk_bitmap()),
+ image_rep.scale_factor());
+ }
+
+ private:
+ const SkColor color_;
+ const ImageSkia image_;
+ const ImageSkia mask_;
+
+ DISALLOW_COPY_AND_ASSIGN(ButtonImageSource);
+};
+
+class HSLImageSource: public gfx::ImageSkiaSource {
+ public:
+ HSLImageSource(const ImageSkia& image,
+ const color_utils::HSL& hsl_shift)
+ : image_(image),
+ hsl_shift_(hsl_shift) {
+ }
oshima 2012/07/13 16:54:55 ditto
+
+ // gfx::ImageSkiaSource overrides:
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ return gfx::ImageSkiaRep(
+ SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(),
+ hsl_shift_), image_rep.scale_factor());
+ }
+
+ private:
+ const gfx::ImageSkia image_;
+ const color_utils::HSL hsl_shift_;
+
+ DISALLOW_COPY_AND_ASSIGN(HSLImageSource);
+};
+
+class ColorMaskImageSource: public gfx::ImageSkiaSource {
+ public:
+ ColorMaskImageSource(const gfx::ImageSkia& image,
+ SkColor color)
+ : image_(image),
+ color_(color) {
+ }
oshima 2012/07/13 16:54:55 ditto
+
+ // gfx::ImageSkiaSource overrides:
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ return gfx::ImageSkiaRep(
+ SkBitmapOperations::CreateColorMask(image_rep.sk_bitmap(), color_),
+ image_rep.scale_factor());
+ }
+
+ private:
+ const gfx::ImageSkia image_;
+ const SkColor color_;
+
+ DISALLOW_COPY_AND_ASSIGN(ColorMaskImageSource);
+};
+
+class ExtractSubsetImageSource: public gfx::ImageSkiaSource {
+ public:
+ ExtractSubsetImageSource(const gfx::ImageSkia& image,
+ const gfx::Rect& subset_bounds)
+ : image_(image),
+ subset_bounds_(subset_bounds) {
+ }
oshima 2012/07/13 16:54:55 ditto
+
+ // gfx::ImageSkiaSource overrides:
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ SkIRect subset_bounds_in_pixel = RectToSkIRect(
+ subset_bounds_.Scale(ui::GetScaleFactorScale(scale_factor)));
+ SkBitmap dst;
+ image_rep.sk_bitmap().extractSubset(&dst, subset_bounds_in_pixel);
+ return gfx::ImageSkiaRep(dst, image_rep.scale_factor());
+ }
+
+ private:
+ const gfx::ImageSkia image_;
+ const gfx::Rect subset_bounds_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource);
+};
+
} // namespace;
// static
@@ -211,4 +311,37 @@ ImageSkia ImageSkiaOperations::CreateResizedImage(
target_size_in_dip);
}
+// static
+ImageSkia ImageSkiaOperations::CreateButtonBackground(
+ SkColor color,
+ const ImageSkia& image,
+ const ImageSkia& mask) {
+ return ImageSkia(new ButtonImageSource(color, image, mask), image.size());
+}
+
+// static
+ImageSkia ImageSkiaOperations::CreateHSLShiftedImage(
+ const ImageSkia& image,
+ const color_utils::HSL& hsl_shift) {
+ return ImageSkia(new HSLImageSource(image, hsl_shift), image.size());
+}
+
+// static
+ImageSkia ImageSkiaOperations::CreateColorMask(
+ const ImageSkia& image,
+ SkColor color) {
oshima 2012/07/13 16:54:55 can these be alined to at (?
+ return ImageSkia(new ColorMaskImageSource(image, color), image.size());
+}
+
+// static
+ImageSkia ImageSkiaOperations::ExtractSubset(
+ const ImageSkia& image,
+ const Rect& subset_bounds) {
oshima 2012/07/13 16:54:55 can these be alined to at (?
pkotwicz 2012/07/15 03:36:48 Done.
+ if (image.isNull())
+ return ImageSkia();
oshima 2012/07/13 16:54:55 i wonder "return image" is better. you may keep it
pkotwicz 2012/07/15 03:36:48 I prefer it this way. SkBitmap::extractSubset retu
+
+ return ImageSkia(new ExtractSubsetImageSource(image, subset_bounds),
+ subset_bounds.size());
+}
+
} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698