| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 #define _USE_MATH_DEFINES | 5 #define _USE_MATH_DEFINES |
| 6 #include <cmath> | 6 #include <cmath> |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "skia/ext/image_operations.h" | 10 #include "skia/ext/image_operations.h" |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 dst_row[x] = SkColorSetARGB(alpha, | 400 dst_row[x] = SkColorSetARGB(alpha, |
| 401 SkAlphaMul(SkColorGetR(rgb_pixel), alpha), | 401 SkAlphaMul(SkColorGetR(rgb_pixel), alpha), |
| 402 SkAlphaMul(SkColorGetG(rgb_pixel), alpha), | 402 SkAlphaMul(SkColorGetG(rgb_pixel), alpha), |
| 403 SkAlphaMul(SkColorGetB(rgb_pixel), alpha)); | 403 SkAlphaMul(SkColorGetB(rgb_pixel), alpha)); |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 return masked; | 407 return masked; |
| 408 } | 408 } |
| 409 | 409 |
| 410 // static |
| 411 SkBitmap ImageOperations::CreateButtonBackground(SkColor color, |
| 412 const SkBitmap& image, |
| 413 const SkBitmap& mask) { |
| 414 DCHECK(image.config() == SkBitmap::kARGB_8888_Config); |
| 415 DCHECK(mask.config() == SkBitmap::kARGB_8888_Config); |
| 416 |
| 417 SkBitmap background; |
| 418 background.setConfig(SkBitmap::kARGB_8888_Config, |
| 419 mask.width(), |
| 420 mask.height(), 0); |
| 421 background.allocPixels(); |
| 422 |
| 423 int bg_a = SkColorGetA(color); |
| 424 int bg_r = SkColorGetR(color); |
| 425 int bg_g = SkColorGetG(color); |
| 426 int bg_b = SkColorGetB(color); |
| 427 |
| 428 SkAutoLockPixels lock_mask(mask); |
| 429 SkAutoLockPixels lock_image(image); |
| 430 SkAutoLockPixels lock_background(background); |
| 431 |
| 432 for (int y = 0; y < mask.height(); y++) { |
| 433 uint32* dst_row = background.getAddr32(0, y); |
| 434 uint32* image_row = image.getAddr32(0, y % image.height()); |
| 435 uint32* mask_row = mask.getAddr32(0, y); |
| 436 |
| 437 for (int x = 0; x < mask.width(); x++) { |
| 438 uint32 mask_pixel = mask_row[x]; |
| 439 uint32 image_pixel = image_row[x % image.width()]; |
| 440 |
| 441 int img_a = SkColorGetA(image_pixel); |
| 442 int img_r = SkColorGetR(image_pixel); |
| 443 int img_g = SkColorGetG(image_pixel); |
| 444 int img_b = SkColorGetB(image_pixel); |
| 445 |
| 446 double img_alpha = static_cast<double>(img_a) / 255.0; |
| 447 double img_inv = 1 - img_alpha; |
| 448 |
| 449 double mask_a = static_cast<double>(SkColorGetA(mask_pixel)) / 255.0; |
| 450 |
| 451 dst_row[x] = SkColorSetARGB( |
| 452 static_cast<int>(std::min(255, bg_a + img_a) * mask_a), |
| 453 static_cast<int>((bg_r * img_inv + img_r * img_alpha) * mask_a), |
| 454 static_cast<int>((bg_g * img_inv + img_g * img_alpha) * mask_a), |
| 455 static_cast<int>((bg_b * img_inv + img_b * img_alpha) * mask_a)); |
| 456 } |
| 457 } |
| 458 |
| 459 return background; |
| 460 } |
| 461 |
| 462 |
| 410 SkBitmap ImageOperations::CreateBlurredBitmap(const SkBitmap& bitmap, | 463 SkBitmap ImageOperations::CreateBlurredBitmap(const SkBitmap& bitmap, |
| 411 int blur_amount ) { | 464 int blur_amount ) { |
| 412 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); | 465 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); |
| 413 | 466 |
| 414 // Blur factor (1 divided by how many pixels the blur takes place over). | 467 // Blur factor (1 divided by how many pixels the blur takes place over). |
| 415 double v = 1.0 / pow(static_cast<double>(blur_amount * 2 + 1), 2); | 468 double v = 1.0 / pow(static_cast<double>(blur_amount * 2 + 1), 2); |
| 416 | 469 |
| 417 SkBitmap blurred; | 470 SkBitmap blurred; |
| 418 blurred.setConfig(SkBitmap::kARGB_8888_Config, bitmap.width(), | 471 blurred.setConfig(SkBitmap::kARGB_8888_Config, bitmap.width(), |
| 419 bitmap.height(), 0); | 472 bitmap.height(), 0); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 619 |
| 567 dst_row[x] = source_row[x_pix]; | 620 dst_row[x] = source_row[x_pix]; |
| 568 } | 621 } |
| 569 } | 622 } |
| 570 | 623 |
| 571 return cropped; | 624 return cropped; |
| 572 } | 625 } |
| 573 | 626 |
| 574 } // namespace skia | 627 } // namespace skia |
| 575 | 628 |
| OLD | NEW |