epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 7 | |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkBitmap.h" |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 10 | #include "SkRect.h" |
| 11 | #include "SkRandom.h" |
| 12 | |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 13 | static void TestGetColor(skiatest::Reporter* reporter) { |
| 14 | static const struct Rec { |
| 15 | SkBitmap::Config fConfig; |
| 16 | SkColor fInColor; |
| 17 | SkColor fOutColor; |
| 18 | } gRec[] = { |
| 19 | // todo: add some tests that involve alpha, so we exercise the |
| 20 | // unpremultiply aspect of getColor() |
| 21 | { SkBitmap::kA8_Config, 0xFF000000, 0xFF000000 }, |
| 22 | { SkBitmap::kA8_Config, 0, 0 }, |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 23 | { SkBitmap::kRGB_565_Config, 0xFF00FF00, 0xFF00FF00 }, |
| 24 | { SkBitmap::kRGB_565_Config, 0xFFFF00FF, 0xFFFF00FF }, |
| 25 | { SkBitmap::kARGB_8888_Config, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 26 | { SkBitmap::kARGB_8888_Config, 0, 0 }, |
| 27 | { SkBitmap::kARGB_8888_Config, 0xFF224466, 0xFF224466 }, |
| 28 | }; |
| 29 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 30 | // specify an area that doesn't touch (0,0) and may extend beyond the |
| 31 | // bitmap bounds (to test that we catch that in eraseArea |
| 32 | const SkColor initColor = 0xFF0000FF; |
| 33 | const SkIRect area = { 1, 1, 3, 3 }; |
| 34 | |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 35 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 36 | SkBitmap bm; |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 37 | uint32_t storage[4]; |
| 38 | bm.setConfig(gRec[i].fConfig, 2, 2); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 39 | bm.setPixels(storage); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 40 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 41 | bm.eraseColor(initColor); |
| 42 | bm.eraseArea(area, gRec[i].fInColor); |
| 43 | |
| 44 | SkColor c = bm.getColor(1, 1); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 45 | REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); |
| 46 | } |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | #include "TestClassDef.h" |
| 50 | DEFINE_TESTCLASS("GetColor", TestGetColorClass, TestGetColor) |