2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-06-28 19:40:50 +00:00
|
|
|
|
2011-02-25 19:50:19 +00:00
|
|
|
#include "SkBitmap.h"
|
2013-06-28 19:40:50 +00:00
|
|
|
#include "SkRandom.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkRect.h"
|
|
|
|
#include "Test.h"
|
2013-06-28 19:40:50 +00:00
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(GetColor, reporter) {
|
2011-02-25 19:50:19 +00:00
|
|
|
static const struct Rec {
|
2014-03-05 13:43:15 +00:00
|
|
|
SkColorType fColorType;
|
|
|
|
SkColor fInColor;
|
|
|
|
SkColor fOutColor;
|
2011-02-25 19:50:19 +00:00
|
|
|
} gRec[] = {
|
|
|
|
// todo: add some tests that involve alpha, so we exercise the
|
|
|
|
// unpremultiply aspect of getColor()
|
2014-03-05 13:43:15 +00:00
|
|
|
{ kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 },
|
|
|
|
{ kAlpha_8_SkColorType, 0, 0 },
|
|
|
|
{ kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 },
|
|
|
|
{ kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF },
|
2014-04-09 20:45:29 +00:00
|
|
|
{ kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
|
|
|
|
{ kN32_SkColorType, 0, 0 },
|
|
|
|
{ kN32_SkColorType, 0xFF224466, 0xFF224466 },
|
2011-02-25 19:50:19 +00:00
|
|
|
};
|
|
|
|
|
2013-06-28 19:40:50 +00:00
|
|
|
// 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 };
|
|
|
|
|
2011-02-25 19:50:19 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
|
2014-03-05 13:43:15 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2011-02-25 19:50:19 +00:00
|
|
|
SkBitmap bm;
|
2013-06-28 19:40:50 +00:00
|
|
|
uint32_t storage[4];
|
2014-03-05 13:43:15 +00:00
|
|
|
bm.installPixels(info, storage, info.minRowBytes(), NULL, NULL);
|
2011-02-25 19:50:19 +00:00
|
|
|
|
2013-06-28 19:40:50 +00:00
|
|
|
bm.eraseColor(initColor);
|
|
|
|
bm.eraseArea(area, gRec[i].fInColor);
|
|
|
|
|
|
|
|
SkColor c = bm.getColor(1, 1);
|
2011-02-25 19:50:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
|
|
|
|
}
|
|
|
|
}
|