epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkBitmap.h" |
| 10 | |
| 11 | static void TestGetColor(skiatest::Reporter* reporter) { |
| 12 | static const struct Rec { |
| 13 | SkBitmap::Config fConfig; |
| 14 | SkColor fInColor; |
| 15 | SkColor fOutColor; |
| 16 | } gRec[] = { |
| 17 | // todo: add some tests that involve alpha, so we exercise the |
| 18 | // unpremultiply aspect of getColor() |
| 19 | { SkBitmap::kA8_Config, 0xFF000000, 0xFF000000 }, |
| 20 | { SkBitmap::kA8_Config, 0, 0 }, |
| 21 | { SkBitmap::kARGB_4444_Config, 0xFF224466, 0xFF224466 }, |
| 22 | { SkBitmap::kARGB_4444_Config, 0, 0 }, |
| 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 | |
| 30 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 31 | SkBitmap bm; |
| 32 | uint32_t storage[1]; |
| 33 | bm.setConfig(gRec[i].fConfig, 1, 1); |
| 34 | bm.setPixels(storage); |
| 35 | bm.eraseColor(gRec[i].fInColor); |
| 36 | |
| 37 | SkColor c = bm.getColor(0, 0); |
| 38 | REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | #include "TestClassDef.h" |
| 43 | DEFINE_TESTCLASS("GetColor", TestGetColorClass, TestGetColor) |