skia2/tests/BitmapGetColorTest.cpp
Ben Wagner e6b04a1407 IWYU for test files starting with 'B'.
Found reproduction of iwyu issue #486, fixed at
https://github.com/include-what-you-use/include-what-you-use/pull/522

Change-Id: Ic77a1a0c3b02b7853517c7fc4d98d92b29c2b0eb
Reviewed-on: https://skia-review.googlesource.com/113214
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
2018-03-09 20:19:02 +00:00

51 lines
1.7 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmap.h"
#include "SkColor.h"
#include "SkImageInfo.h"
#include "SkRect.h"
#include "SkTypes.h"
#include "Test.h"
DEF_TEST(GetColor, reporter) {
static const struct Rec {
SkColorType fColorType;
SkColor fInColor;
SkColor fOutColor;
} gRec[] = {
// todo: add some tests that involve alpha, so we exercise the
// unpremultiply aspect of getColor()
{ kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 },
{ kAlpha_8_SkColorType, 0, 0 },
{ kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 },
{ kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF },
{ kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
{ kN32_SkColorType, 0, 0 },
{ kN32_SkColorType, 0xFF224466, 0xFF224466 },
};
// specify an area that doesn't touch (0,0) and may extend beyond the
// bitmap bounds (to test that we catch that in eraseArea
const SkColor initColor = 0xFF0000FF;
const SkIRect area = { 1, 1, 3, 3 };
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
kPremul_SkAlphaType);
SkBitmap bm;
uint32_t storage[4];
bm.installPixels(info, storage, info.minRowBytes());
bm.eraseColor(initColor);
bm.eraseArea(area, gRec[i].fInColor);
SkColor c = bm.getColor(1, 1);
REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
}
}