blob: 40aa3e26bff813a53075064fb660cfa2d250d073 [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 "Test.h"
9#include "SkBitmap.h"
reed@google.com60d32352013-06-28 19:40:50 +000010#include "SkRect.h"
11#include "SkRandom.h"
12
reed@google.comf4888c42011-02-25 19:50:19 +000013static void TestGetColor(skiatest::Reporter* reporter) {
14 static const struct Rec {
15 SkBitmap::Config fConfig;
16 SkColor fInColor;
17 SkColor fOutColor;
18 } gRec[] = {
19 // todo: add some tests that involve alpha, so we exercise the
20 // unpremultiply aspect of getColor()
21 { SkBitmap::kA8_Config, 0xFF000000, 0xFF000000 },
22 { SkBitmap::kA8_Config, 0, 0 },
reed@google.comf4888c42011-02-25 19:50:19 +000023 { SkBitmap::kRGB_565_Config, 0xFF00FF00, 0xFF00FF00 },
24 { SkBitmap::kRGB_565_Config, 0xFFFF00FF, 0xFFFF00FF },
25 { SkBitmap::kARGB_8888_Config, 0xFFFFFFFF, 0xFFFFFFFF },
26 { SkBitmap::kARGB_8888_Config, 0, 0 },
27 { SkBitmap::kARGB_8888_Config, 0xFF224466, 0xFF224466 },
28 };
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++) {
36 SkBitmap bm;
reed@google.com60d32352013-06-28 19:40:50 +000037 uint32_t storage[4];
38 bm.setConfig(gRec[i].fConfig, 2, 2);
reed@google.comf4888c42011-02-25 19:50:19 +000039 bm.setPixels(storage);
reed@google.comf4888c42011-02-25 19:50:19 +000040
reed@google.com60d32352013-06-28 19:40:50 +000041 bm.eraseColor(initColor);
42 bm.eraseArea(area, gRec[i].fInColor);
43
44 SkColor c = bm.getColor(1, 1);
reed@google.comf4888c42011-02-25 19:50:19 +000045 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
46 }
reed@google.comf4888c42011-02-25 19:50:19 +000047}
48
49#include "TestClassDef.h"
50DEFINE_TESTCLASS("GetColor", TestGetColorClass, TestGetColor)