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