155ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org#include "Test.h"
255ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
355ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org#include "SkColorPriv.h"
455ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
555ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org#define ASSERT(expr) REPORTER_ASSERT(r, expr)
655ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
755ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.orgDEF_TEST(Splay, r) {
855ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    const SkPMColor color = 0xA1B2C3D4;
955ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
1055ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    uint32_t ag, rb;
1155ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    SkSplay(color, &ag, &rb);
1255ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    ASSERT(ag == 0x00A100C3);
1355ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    ASSERT(rb == 0x00B200D4);
1455ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    ASSERT(SkUnsplay(ag << 8, rb << 8) == color);
1555ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
1655ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    const uint64_t agrb = SkSplay(color);
17cb08f986938eeeeb57f950c94fee120aca965787mtklein@google.com    ASSERT(agrb == 0x00A100C300B200D4ULL);
1855ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    ASSERT(SkUnsplay(agrb<<8) == color);
1955ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org}
2055ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
2155ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.orgDEF_TEST(FourByteInterp, r) {
2255ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    const SkPMColor src = 0xAB998877, dst = 0x66334455;
2355ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    for (unsigned scale = 0; scale <= 256; scale++) {
2455ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        ASSERT(SkFourByteInterp256(src, dst, scale) == SkFastFourByteInterp256(src, dst, scale));
2555ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    }
2655ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
2755ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    for (unsigned scale = 0; scale < 256; scale++) {
2855ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        // SkFourByteInterp and SkFastFourByteInterp convert from [0, 255] to [0, 256] differently.
2955ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        // In particular, slow may end up a little too high (weirdly, fast is more accurate).
3055ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        const SkPMColor slow = SkFourByteInterp(src, dst, scale);
3155ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        const SkPMColor fast = SkFastFourByteInterp(src, dst, scale);
3255ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
3355ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        const int deltaA = SkGetPackedA32(slow) - SkGetPackedA32(fast);
3455ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        const int deltaR = SkGetPackedR32(slow) - SkGetPackedR32(fast);
3555ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        const int deltaG = SkGetPackedG32(slow) - SkGetPackedG32(fast);
3655ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        const int deltaB = SkGetPackedB32(slow) - SkGetPackedB32(fast);
3755ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org
3855ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        ASSERT(deltaA == 0 || deltaA == 1);
3955ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        ASSERT(deltaR == 0 || deltaR == 1);
4055ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        ASSERT(deltaG == 0 || deltaG == 1);
4155ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org        ASSERT(deltaB == 0 || deltaB == 1);
4255ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org    }
4355ca8244cc19c3067defa64f139521264d777eb0commit-bot@chromium.org}
44