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