Dither.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const uint16_t gDitherMatrix_3Bit_16[4] = {
  2. 0x5140, 0x3726, 0x4051, 0x2637
  3. };
  4. static inline uint16_t SkPackRGB16(unsigned r, unsigned g, unsigned b) {
  5. return ((uint16_t)((r << (5 + 6)) | (g << (5)) | (b << 0)));
  6. }
  7. static inline uint16_t SkDitherRGB32To565(SkPMColor c, unsigned dither)
  8. {
  9. unsigned sr = ((uint32_t)((c) << (24 - 0)) >> 24);
  10. unsigned sg = ((uint32_t)((c) << (24 - 8)) >> 24);
  11. unsigned sb = ((uint32_t)((c) << (24 - 16)) >> 24);
  12. sr = ((unsigned)((sr + dither - (sr >> 5))) >> (8 - 5));
  13. sg = ((unsigned)((sg + (dither >> 1) - (sg >> 6))) >> (8 - 6));
  14. sb = ((unsigned)((sb + dither - (sb >> 5))) >> (8 - 5));
  15. return SkPackRGB16(sr, sg, sb);
  16. }
  17. static void S32_D565_Opaque_Dither(uint16_t* __restrict__ dst,
  18. const SkPMColor* __restrict__ src,
  19. int count, U8CPU alpha, int x, int y) {
  20. if (count > 0) {
  21. const uint16_t dither_scan = gDitherMatrix_3Bit_16[(y) & 3];
  22. do {
  23. SkPMColor c = *src++;
  24. unsigned dither = ((dither_scan >> (((x) & 3) << 2)) & 0xF);
  25. *dst++ = SkDitherRGB32To565(c, dither);
  26. ++(x);
  27. } while (--count != 0);
  28. }
  29. }