Chromium Code Reviews| Index: ui/gfx/skbitmap_operations.cc |
| diff --git a/ui/gfx/skbitmap_operations.cc b/ui/gfx/skbitmap_operations.cc |
| index 10cce9c45b27aaf3061cafddda74f87b28685de7..d08f0c74be2ca84fdc97fb076cb99d04ef57b227 100644 |
| --- a/ui/gfx/skbitmap_operations.cc |
| +++ b/ui/gfx/skbitmap_operations.cc |
| @@ -81,8 +81,10 @@ SkBitmap SkBitmapOperations::CreateBlendedBitmap(const SkBitmap& first, |
| const SkBitmap& second, |
| double alpha) { |
| DCHECK((alpha >= 0) && (alpha <= 1)); |
| - DCHECK(first.width() == second.width()); |
| - DCHECK(first.height() == second.height()); |
| + // Allow for a 1 pixel mismatch in height or width, which may result from |
|
pkotwicz
2013/03/12 15:54:37
I would rather that you did the clipping before ca
kevers
2013/03/12 22:02:25
Done.
|
| + // rounding errors when working with fractional scale factors. |
| + DCHECK(abs(first.width() - second.width()) <= 1); |
| + DCHECK(abs(first.height() - second.height()) <= 1); |
| DCHECK(first.bytesPerPixel() == second.bytesPerPixel()); |
| DCHECK(first.config() == SkBitmap::kARGB_8888_Config); |
| @@ -97,20 +99,22 @@ SkBitmap SkBitmapOperations::CreateBlendedBitmap(const SkBitmap& first, |
| SkAutoLockPixels lock_first(first); |
| SkAutoLockPixels lock_second(second); |
| + int width = std::min(first.width(), second.width()); |
| + int height = std::min(first.height(), second.height()); |
| + |
| SkBitmap blended; |
| - blended.setConfig(SkBitmap::kARGB_8888_Config, first.width(), first.height(), |
| - 0); |
| + blended.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); |
| blended.allocPixels(); |
| blended.eraseARGB(0, 0, 0, 0); |
| double first_alpha = 1 - alpha; |
| - for (int y = 0; y < first.height(); ++y) { |
| + for (int y = 0; y < height; ++y) { |
| uint32* first_row = first.getAddr32(0, y); |
| uint32* second_row = second.getAddr32(0, y); |
| uint32* dst_row = blended.getAddr32(0, y); |
| - for (int x = 0; x < first.width(); ++x) { |
| + for (int x = 0; x < width; ++x) { |
| uint32 first_pixel = first_row[x]; |
| uint32 second_pixel = second_row[x]; |
| @@ -133,8 +137,10 @@ SkBitmap SkBitmapOperations::CreateBlendedBitmap(const SkBitmap& first, |
| // static |
| SkBitmap SkBitmapOperations::CreateMaskedBitmap(const SkBitmap& rgb, |
| const SkBitmap& alpha) { |
| - DCHECK(rgb.width() == alpha.width()); |
| - DCHECK(rgb.height() == alpha.height()); |
| + // Allow for a 1 pixel mismatch in height or width, which may result from |
| + // rounding errors when working with fractional scale factors. |
| + DCHECK(abs(rgb.width() - alpha.width()) <= 1); |
| + DCHECK(abs(rgb.height() - alpha.height()) <= 1); |
| DCHECK(rgb.bytesPerPixel() == alpha.bytesPerPixel()); |
| DCHECK(rgb.config() == SkBitmap::kARGB_8888_Config); |
| DCHECK(alpha.config() == SkBitmap::kARGB_8888_Config); |
| @@ -148,12 +154,15 @@ SkBitmap SkBitmapOperations::CreateMaskedBitmap(const SkBitmap& rgb, |
| SkAutoLockPixels lock_alpha(alpha); |
| SkAutoLockPixels lock_masked(masked); |
| - for (int y = 0; y < masked.height(); ++y) { |
| + int height = std::min(rgb.height(), masked.height()); |
| + int width = std::min(rgb.width(), masked.width()); |
| + |
| + for (int y = 0; y < height; ++y) { |
| uint32* rgb_row = rgb.getAddr32(0, y); |
| uint32* alpha_row = alpha.getAddr32(0, y); |
| uint32* dst_row = masked.getAddr32(0, y); |
| - for (int x = 0; x < masked.width(); ++x) { |
| + for (int x = 0; x < width; ++x) { |
| SkColor rgb_pixel = SkUnPreMultiply::PMColorToColor(rgb_row[x]); |
| SkColor alpha_pixel = SkUnPreMultiply::PMColorToColor(alpha_row[x]); |
| int alpha = SkAlphaMul(SkColorGetA(rgb_pixel), |