1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/core/SkBitmap.h" 9cb93a386Sopenharmony_ci#include "include/core/SkColor.h" 10cb93a386Sopenharmony_ci#include "include/core/SkImageInfo.h" 11cb93a386Sopenharmony_ci#include "include/core/SkRect.h" 12cb93a386Sopenharmony_ci#include "include/core/SkTypes.h" 13cb93a386Sopenharmony_ci#include "tests/Test.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ciDEF_TEST(GetColor, reporter) { 16cb93a386Sopenharmony_ci static const struct Rec { 17cb93a386Sopenharmony_ci SkColorType fColorType; 18cb93a386Sopenharmony_ci SkColor fInColor; 19cb93a386Sopenharmony_ci SkColor fOutColor; 20cb93a386Sopenharmony_ci } gRec[] = { 21cb93a386Sopenharmony_ci // todo: add some tests that involve alpha, so we exercise the 22cb93a386Sopenharmony_ci // unpremultiply aspect of getColor() 23cb93a386Sopenharmony_ci { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 }, 24cb93a386Sopenharmony_ci { kAlpha_8_SkColorType, 0, 0 }, 25cb93a386Sopenharmony_ci { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 }, 26cb93a386Sopenharmony_ci { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF }, 27cb93a386Sopenharmony_ci { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF }, 28cb93a386Sopenharmony_ci { kN32_SkColorType, 0, 0 }, 29cb93a386Sopenharmony_ci { kN32_SkColorType, 0xFF224466, 0xFF224466 }, 30cb93a386Sopenharmony_ci }; 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci // specify an area that doesn't touch (0,0) and may extend beyond the 33cb93a386Sopenharmony_ci // bitmap bounds (to test that we catch that in eraseArea 34cb93a386Sopenharmony_ci const SkColor initColor = 0xFF0000FF; 35cb93a386Sopenharmony_ci const SkIRect area = { 1, 1, 3, 3 }; 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { 38cb93a386Sopenharmony_ci SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType, 39cb93a386Sopenharmony_ci kPremul_SkAlphaType); 40cb93a386Sopenharmony_ci SkBitmap bm; 41cb93a386Sopenharmony_ci uint32_t storage[4]; 42cb93a386Sopenharmony_ci bm.installPixels(info, storage, info.minRowBytes()); 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci bm.eraseColor(initColor); 45cb93a386Sopenharmony_ci bm.eraseArea(area, gRec[i].fInColor); 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci SkColor c = bm.getColor(1, 1); 48cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); 49cb93a386Sopenharmony_ci } 50cb93a386Sopenharmony_ci} 51