blob: bf3ba67ecb1be428b316abd017c7b2ea192ff2fa [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
reed@google.comf4888c42011-02-25 19:50:19 +00008#include "SkBitmap.h"
reed@google.com60d32352013-06-28 19:40:50 +00009#include "SkRandom.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000010#include "SkRect.h"
11#include "Test.h"
reed@google.com60d32352013-06-28 19:40:50 +000012
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000013DEF_TEST(GetColor, reporter) {
reed@google.comf4888c42011-02-25 19:50:19 +000014 static const struct Rec {
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000015 SkColorType fColorType;
16 SkColor fInColor;
17 SkColor fOutColor;
reed@google.comf4888c42011-02-25 19:50:19 +000018 } gRec[] = {
19 // todo: add some tests that involve alpha, so we exercise the
20 // unpremultiply aspect of getColor()
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000021 { 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.org28fcae22014-04-11 17:15:40 +000025 { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
26 { kN32_SkColorType, 0, 0 },
27 { kN32_SkColorType, 0xFF224466, 0xFF224466 },
reed@google.comf4888c42011-02-25 19:50:19 +000028 };
29
reed@google.com60d32352013-06-28 19:40:50 +000030 // 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.comf4888c42011-02-25 19:50:19 +000035 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000036 SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
37 kPremul_SkAlphaType);
reed@google.comf4888c42011-02-25 19:50:19 +000038 SkBitmap bm;
reed@google.com60d32352013-06-28 19:40:50 +000039 uint32_t storage[4];
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +000040 bm.installPixels(info, storage, info.minRowBytes());
reed@google.comf4888c42011-02-25 19:50:19 +000041
reed@google.com60d32352013-06-28 19:40:50 +000042 bm.eraseColor(initColor);
43 bm.eraseArea(area, gRec[i].fInColor);
44
45 SkColor c = bm.getColor(1, 1);
reed@google.comf4888c42011-02-25 19:50:19 +000046 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
47 }
reed@google.comf4888c42011-02-25 19:50:19 +000048}