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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
| 9 | #include "include/core/SkColor.h" |
| 10 | #include "include/core/SkImageInfo.h" |
| 11 | #include "include/core/SkRect.h" |
| 12 | #include "include/core/SkTypes.h" |
| 13 | #include "tests/Test.h" |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 14 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 15 | DEF_TEST(GetColor, reporter) { |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 16 | static const struct Rec { |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 17 | SkColorType fColorType; |
| 18 | SkColor fInColor; |
| 19 | SkColor fOutColor; |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 20 | } gRec[] = { |
| 21 | // todo: add some tests that involve alpha, so we exercise the |
| 22 | // unpremultiply aspect of getColor() |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 23 | { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 }, |
| 24 | { kAlpha_8_SkColorType, 0, 0 }, |
| 25 | { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 }, |
| 26 | { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF }, |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 27 | { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 28 | { kN32_SkColorType, 0, 0 }, |
| 29 | { kN32_SkColorType, 0xFF224466, 0xFF224466 }, |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 32 | // specify an area that doesn't touch (0,0) and may extend beyond the |
| 33 | // bitmap bounds (to test that we catch that in eraseArea |
| 34 | const SkColor initColor = 0xFF0000FF; |
| 35 | const SkIRect area = { 1, 1, 3, 3 }; |
| 36 | |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 37 | 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] | 38 | SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType, |
| 39 | kPremul_SkAlphaType); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 40 | SkBitmap bm; |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 41 | uint32_t storage[4]; |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 42 | bm.installPixels(info, storage, info.minRowBytes()); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 43 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 44 | bm.eraseColor(initColor); |
| 45 | bm.eraseArea(area, gRec[i].fInColor); |
| 46 | |
| 47 | SkColor c = bm.getColor(1, 1); |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 48 | REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); |
| 49 | } |
reed@google.com | f4888c4 | 2011-02-25 19:50:19 +0000 | [diff] [blame] | 50 | } |