1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2017 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/SkColor.h" 9cb93a386Sopenharmony_ci#include "include/core/SkColorPriv.h" 10cb93a386Sopenharmony_ci#include "include/core/SkTypes.h" 11cb93a386Sopenharmony_ci#include "include/private/SkColorData.h" 12cb93a386Sopenharmony_ci#include "tests/Test.h" 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_ci#define ASSERT(expr) REPORTER_ASSERT(r, expr) 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ciDEF_TEST(Splay, r) { 17cb93a386Sopenharmony_ci const SkPMColor color = 0xA1B2C3D4; 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_ci uint32_t ag, rb; 20cb93a386Sopenharmony_ci SkSplay(color, &ag, &rb); 21cb93a386Sopenharmony_ci ASSERT(ag == 0x00A100C3); 22cb93a386Sopenharmony_ci ASSERT(rb == 0x00B200D4); 23cb93a386Sopenharmony_ci ASSERT(SkUnsplay(ag << 8, rb << 8) == color); 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ci const uint64_t agrb = SkSplay(color); 26cb93a386Sopenharmony_ci ASSERT(agrb == 0x00A100C300B200D4ULL); 27cb93a386Sopenharmony_ci ASSERT(SkUnsplay(agrb<<8) == color); 28cb93a386Sopenharmony_ci} 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ciDEF_TEST(FourByteInterp, r) { 31cb93a386Sopenharmony_ci const SkPMColor src = 0xAB998877, dst = 0x66334455; 32cb93a386Sopenharmony_ci for (unsigned scale = 0; scale <= 256; scale++) { 33cb93a386Sopenharmony_ci ASSERT(SkFourByteInterp256(src, dst, scale) == SkFastFourByteInterp256(src, dst, scale)); 34cb93a386Sopenharmony_ci } 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci for (unsigned scale = 0; scale < 256; scale++) { 37cb93a386Sopenharmony_ci // SkFourByteInterp and SkFastFourByteInterp convert from [0, 255] to [0, 256] differently. 38cb93a386Sopenharmony_ci // In particular, slow may end up a little too high (weirdly, fast is more accurate). 39cb93a386Sopenharmony_ci const SkPMColor slow = SkFourByteInterp(src, dst, scale); 40cb93a386Sopenharmony_ci const SkPMColor fast = SkFastFourByteInterp(src, dst, scale); 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ci const int deltaA = SkGetPackedA32(slow) - SkGetPackedA32(fast); 43cb93a386Sopenharmony_ci const int deltaR = SkGetPackedR32(slow) - SkGetPackedR32(fast); 44cb93a386Sopenharmony_ci const int deltaG = SkGetPackedG32(slow) - SkGetPackedG32(fast); 45cb93a386Sopenharmony_ci const int deltaB = SkGetPackedB32(slow) - SkGetPackedB32(fast); 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci ASSERT(deltaA == 0 || deltaA == 1); 48cb93a386Sopenharmony_ci ASSERT(deltaR == 0 || deltaR == 1); 49cb93a386Sopenharmony_ci ASSERT(deltaG == 0 || deltaG == 1); 50cb93a386Sopenharmony_ci ASSERT(deltaB == 0 || deltaB == 1); 51cb93a386Sopenharmony_ci } 52cb93a386Sopenharmony_ci} 53