diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 02:31:02 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 02:31:02 +0000 |
commit | 6e853c3ad131fe6713ce8efbac2270fee26ab5b2 (patch) | |
tree | d0c9c8a5d1949cbdd108059add44b86b989514f4 /skia | |
parent | 26e99ffd2a4179aefe5dbf8cbd5da74c0bc7a76b (diff) | |
download | chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.zip chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.tar.gz chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.tar.bz2 |
Add ability to theme our buttons.
BUG=12762
TEST=Verify that buttons can be themed.
Review URL: http://codereview.chromium.org/119025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/image_operations.cc | 53 | ||||
-rw-r--r-- | skia/ext/image_operations.h | 9 |
2 files changed, 62 insertions, 0 deletions
diff --git a/skia/ext/image_operations.cc b/skia/ext/image_operations.cc index 561bd4e..c0ee3e0 100644 --- a/skia/ext/image_operations.cc +++ b/skia/ext/image_operations.cc @@ -407,6 +407,59 @@ SkBitmap ImageOperations::CreateMaskedBitmap(const SkBitmap& rgb, return masked; } +// static +SkBitmap ImageOperations::CreateButtonBackground(SkColor color, + const SkBitmap& image, + const SkBitmap& mask) { + DCHECK(image.config() == SkBitmap::kARGB_8888_Config); + DCHECK(mask.config() == SkBitmap::kARGB_8888_Config); + + SkBitmap background; + background.setConfig(SkBitmap::kARGB_8888_Config, + mask.width(), + mask.height(), 0); + background.allocPixels(); + + int bg_a = SkColorGetA(color); + int bg_r = SkColorGetR(color); + int bg_g = SkColorGetG(color); + int bg_b = SkColorGetB(color); + + SkAutoLockPixels lock_mask(mask); + SkAutoLockPixels lock_image(image); + SkAutoLockPixels lock_background(background); + + for (int y = 0; y < mask.height(); y++) { + uint32* dst_row = background.getAddr32(0, y); + uint32* image_row = image.getAddr32(0, y % image.height()); + uint32* mask_row = mask.getAddr32(0, y); + + for (int x = 0; x < mask.width(); x++) { + uint32 mask_pixel = mask_row[x]; + uint32 image_pixel = image_row[x % image.width()]; + + int img_a = SkColorGetA(image_pixel); + int img_r = SkColorGetR(image_pixel); + int img_g = SkColorGetG(image_pixel); + int img_b = SkColorGetB(image_pixel); + + double img_alpha = static_cast<double>(img_a) / 255.0; + double img_inv = 1 - img_alpha; + + double mask_a = static_cast<double>(SkColorGetA(mask_pixel)) / 255.0; + + dst_row[x] = SkColorSetARGB( + static_cast<int>(std::min(255, bg_a + img_a) * mask_a), + static_cast<int>((bg_r * img_inv + img_r * img_alpha) * mask_a), + static_cast<int>((bg_g * img_inv + img_g * img_alpha) * mask_a), + static_cast<int>((bg_b * img_inv + img_b * img_alpha) * mask_a)); + } + } + + return background; +} + + SkBitmap ImageOperations::CreateBlurredBitmap(const SkBitmap& bitmap, int blur_amount ) { DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); diff --git a/skia/ext/image_operations.h b/skia/ext/image_operations.h index 3086fab..4e3c93e 100644 --- a/skia/ext/image_operations.h +++ b/skia/ext/image_operations.h @@ -61,6 +61,15 @@ class ImageOperations { static SkBitmap CreateMaskedBitmap(const SkBitmap& first, const SkBitmap& alpha); + // We create a button background image by compositing the color and image + // together, then applying the mask. This is a highly specialized composite + // operation that is the equivalent of drawing a background in |color|, + // tiling |image| over the top, and then masking the result out with |mask|. + // The images must use kARGB_8888_Config config. + static SkBitmap CreateButtonBackground(SkColor color, + const SkBitmap& image, + const SkBitmap& mask); + // Blur a bitmap using an average-blur algorithm over the rectangle defined // by |blur_amount|. The blur will wrap around image edges. static SkBitmap CreateBlurredBitmap(const SkBitmap& bitmap, int blur_amount); |