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 "SkBitmap.h" |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 9 | #include "SkRandom.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 10 | #include "SkRect.h" |
| 11 | #include "Test.h" |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 12 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 13 | DEF_TEST(GetColor, reporter) { |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 14 | static const struct Rec { |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 15 | SkColorType fColorType; |
| 16 | SkColor fInColor; |
| 17 | SkColor fOutColor; |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 18 | } gRec[] = { |
| 19 | // todo: add some tests that involve alpha, so we exercise the |
| 20 | // unpremultiply aspect of getColor() |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 21 | { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 }, |
| 22 | { kAlpha_8_SkColorType, 0, 0 }, |
| 23 | { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 }, |
| 24 | { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF }, |
commit-bot@chromium.org | 149e9a1 | 2014-04-09 20:45:29 +0000 | [diff] [blame] | 25 | { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 26 | { kN32_SkColorType, 0, 0 }, |
| 27 | { kN32_SkColorType, 0xFF224466, 0xFF224466 }, |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 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++) { |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 36 | SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType, |
| 37 | kPremul_SkAlphaType); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 38 | SkBitmap bm; |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 39 | uint32_t storage[4]; |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 40 | bm.installPixels(info, storage, info.minRowBytes(), NULL, NULL); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 41 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 42 | bm.eraseColor(initColor); |
| 43 | bm.eraseArea(area, gRec[i].fInColor); |
| 44 | |
| 45 | SkColor c = bm.getColor(1, 1); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); |
| 47 | } |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 48 | } |