blob: c27cb2fed7a104c130559b3b6ee1dd2b3bec6c38 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.com60d32352013-06-28 19:40:50 +00007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#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.com60d32352013-06-28 19:40:50 +000014
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000015DEF_TEST(GetColor, reporter) {
reed@google.comf4888c42011-02-25 19:50:19 +000016 static const struct Rec {
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000017 SkColorType fColorType;
18 SkColor fInColor;
19 SkColor fOutColor;
reed@google.comf4888c42011-02-25 19:50:19 +000020 } gRec[] = {
21 // todo: add some tests that involve alpha, so we exercise the
22 // unpremultiply aspect of getColor()
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000023 { 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.org28fcae22014-04-11 17:15:40 +000027 { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
28 { kN32_SkColorType, 0, 0 },
29 { kN32_SkColorType, 0xFF224466, 0xFF224466 },
reed@google.comf4888c42011-02-25 19:50:19 +000030 };
31
reed@google.com60d32352013-06-28 19:40:50 +000032 // 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.comf4888c42011-02-25 19:50:19 +000037 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000038 SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
39 kPremul_SkAlphaType);
reed@google.comf4888c42011-02-25 19:50:19 +000040 SkBitmap bm;
reed@google.com60d32352013-06-28 19:40:50 +000041 uint32_t storage[4];
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +000042 bm.installPixels(info, storage, info.minRowBytes());
reed@google.comf4888c42011-02-25 19:50:19 +000043
reed@google.com60d32352013-06-28 19:40:50 +000044 bm.eraseColor(initColor);
45 bm.eraseArea(area, gRec[i].fInColor);
46
47 SkColor c = bm.getColor(1, 1);
reed@google.comf4888c42011-02-25 19:50:19 +000048 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
49 }
reed@google.comf4888c42011-02-25 19:50:19 +000050}