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