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 */
7
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"
14
DEF_TEST(GetColor,reporter)15 DEF_TEST(GetColor, reporter) {
16 static const struct Rec {
17 SkColorType fColorType;
18 SkColor fInColor;
19 SkColor fOutColor;
20 } gRec[] = {
21 // todo: add some tests that involve alpha, so we exercise the
22 // unpremultiply aspect of getColor()
23 { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 },
24 { kAlpha_8_SkColorType, 0, 0 },
25 { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 },
26 { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF },
27 { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
28 { kN32_SkColorType, 0, 0 },
29 { kN32_SkColorType, 0xFF224466, 0xFF224466 },
30 };
31
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
37 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
38 SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
39 kPremul_SkAlphaType);
40 SkBitmap bm;
41 uint32_t storage[4];
42 bm.installPixels(info, storage, info.minRowBytes());
43
44 bm.eraseColor(initColor);
45 bm.eraseArea(area, gRec[i].fInColor);
46
47 SkColor c = bm.getColor(1, 1);
48 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
49 }
50 }
51