diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 21:03:33 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 21:03:33 +0000 |
commit | 0fb499a5b8b8d2979e7dafe93e8e6689fdedabd8 (patch) | |
tree | 688dadc8de73b7f0eb4d9211a249f537ec366e3d /app | |
parent | 4057c5d217e93a6f05ade5801f45196f3ff738cb (diff) | |
download | chromium_src-0fb499a5b8b8d2979e7dafe93e8e6689fdedabd8.zip chromium_src-0fb499a5b8b8d2979e7dafe93e8e6689fdedabd8.tar.gz chromium_src-0fb499a5b8b8d2979e7dafe93e8e6689fdedabd8.tar.bz2 |
Unrevert 31478 Add UI for turning on/off network devices.
BUG=26636
TEST=run skbitmap_operations_unittest
Review URL: http://codereview.chromium.org/353028
TBR=chocobo@google.com
Review URL: http://codereview.chromium.org/384017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31598 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/gfx/skbitmap_operations.cc | 60 | ||||
-rw-r--r-- | app/gfx/skbitmap_operations.h | 11 | ||||
-rw-r--r-- | app/gfx/skbitmap_operations_unittest.cc | 35 |
3 files changed, 106 insertions, 0 deletions
diff --git a/app/gfx/skbitmap_operations.cc b/app/gfx/skbitmap_operations.cc index 174df68..7108597 100644 --- a/app/gfx/skbitmap_operations.cc +++ b/app/gfx/skbitmap_operations.cc @@ -4,12 +4,72 @@ #include "app/gfx/skbitmap_operations.h" +#include <algorithm> + #include "base/logging.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkUnPreMultiply.h" // static +SkBitmap SkBitmapOperations::CreateInvertedBitmap(const SkBitmap& image) { + DCHECK(image.config() == SkBitmap::kARGB_8888_Config); + + SkAutoLockPixels lock_image(image); + + SkBitmap inverted; + inverted.setConfig(SkBitmap::kARGB_8888_Config, image.width(), image.height(), + 0); + inverted.allocPixels(); + inverted.eraseARGB(0, 0, 0, 0); + + for (int y = 0; y < image.height(); ++y) { + uint32* image_row = image.getAddr32(0, y); + uint32* dst_row = inverted.getAddr32(0, y); + + for (int x = 0; x < image.width(); ++x) { + uint32 image_pixel = image_row[x]; + dst_row[x] = (image_pixel & 0xFF000000) | + (0x00FFFFFF - (image_pixel & 0x00FFFFFF)); + } + } + + return inverted; +} + +// static +SkBitmap SkBitmapOperations::CreateSuperimposedBitmap(const SkBitmap& first, + const SkBitmap& second) { + DCHECK(first.width() == second.width()); + DCHECK(first.height() == second.height()); + DCHECK(first.bytesPerPixel() == second.bytesPerPixel()); + DCHECK(first.config() == SkBitmap::kARGB_8888_Config); + + SkAutoLockPixels lock_first(first); + SkAutoLockPixels lock_second(second); + + SkBitmap superimposed; + superimposed.setConfig(SkBitmap::kARGB_8888_Config, + first.width(), first.height()); + superimposed.allocPixels(); + superimposed.eraseARGB(0, 0, 0, 0); + + SkCanvas canvas(superimposed); + + SkRect rect; + rect.fLeft = 0; + rect.fTop = 0; + rect.fRight = SkIntToScalar(first.width()); + rect.fBottom = SkIntToScalar(first.height()); + + canvas.drawBitmapRect(first, NULL, rect); + canvas.drawBitmapRect(second, NULL, rect); + + return superimposed; +} + +// static SkBitmap SkBitmapOperations::CreateBlendedBitmap(const SkBitmap& first, const SkBitmap& second, double alpha) { diff --git a/app/gfx/skbitmap_operations.h b/app/gfx/skbitmap_operations.h index d6bb5d3..57a2301 100644 --- a/app/gfx/skbitmap_operations.h +++ b/app/gfx/skbitmap_operations.h @@ -12,6 +12,17 @@ class SkBitmap; class SkBitmapOperations { public: + // Create a bitmap that is an inverted image of the passed in image. + // Each color becomes its inverse in the color wheel. So (255, 15, 0) becomes + // (0, 240, 255). The alpha value is not inverted. + static SkBitmap CreateInvertedBitmap(const SkBitmap& image); + + // Create a bitmap that is a superimposition of the second bitmap on top of + // the first. The provided bitmaps must use have the kARGB_8888_Config config + // and be of equal dimensions. + static SkBitmap CreateSuperimposedBitmap(const SkBitmap& first, + const SkBitmap& second); + // Create a bitmap that is a blend of two others. The alpha argument // specifies the opacity of the second bitmap. The provided bitmaps must // use have the kARGB_8888_Config config and be of equal dimensions. diff --git a/app/gfx/skbitmap_operations_unittest.cc b/app/gfx/skbitmap_operations_unittest.cc index feb288c..7a68fe3 100644 --- a/app/gfx/skbitmap_operations_unittest.cc +++ b/app/gfx/skbitmap_operations_unittest.cc @@ -36,6 +36,41 @@ void FillDataToBitmap(int w, int h, SkBitmap* bmp) { } // namespace +// Invert bitmap and verify the each pixel is inverted and the alpha value is +// not changed. +TEST(SkBitmapOperationsTest, CreateInvertedBitmap) { + int src_w = 16, src_h = 16; + SkBitmap src; + src.setConfig(SkBitmap::kARGB_8888_Config, src_w, src_h); + src.allocPixels(); + + for (int y = 0; y < src_h; y++) { + for (int x = 0; x < src_w; x++) { + int i = y * src_w + x; + *src.getAddr32(x, y) = + SkColorSetARGB((255 - i) % 255, i % 255, i * 4 % 255, 0); + } + } + + SkBitmap inverted = SkBitmapOperations::CreateInvertedBitmap(src); + SkAutoLockPixels src_lock(src); + SkAutoLockPixels inverted_lock(inverted); + + for (int y = 0; y < src_h; y++) { + for (int x = 0; x < src_w; x++) { + int i = y * src_w + x; + EXPECT_EQ(static_cast<unsigned int>((255 - i) % 255), + SkColorGetA(*inverted.getAddr32(x, y))); + EXPECT_EQ(static_cast<unsigned int>(255 - (i % 255)), + SkColorGetR(*inverted.getAddr32(x, y))); + EXPECT_EQ(static_cast<unsigned int>(255 - (i * 4 % 255)), + SkColorGetG(*inverted.getAddr32(x, y))); + EXPECT_EQ(static_cast<unsigned int>(255), + SkColorGetB(*inverted.getAddr32(x, y))); + } + } +} + // Blend two bitmaps together at 50% alpha and verify that the result // is the middle-blend of the two. TEST(SkBitmapOperationsTest, CreateBlendedBitmap) { |