void SkProcXfermode::xfer16(SK_RESTRICT uint16_t dst[], const SK_RESTRICT SkPMColor src[], int count, const SK_RESTRICT SkAlpha aa[]) { SkASSERT(dst && src && count >= 0); SkXfermodeProc proc = fProc; if (NULL != proc) { if (NULL == aa) { for (int i = count - 1; i >= 0; --i) { SkPMColor dstC = SkPixel16ToPixel32(dst[i]); dst[i] = SkPixel32ToPixel16_ToU16(proc(src[i], dstC)); } } else { for (int i = count - 1; i >= 0; --i) { unsigned a = aa[i]; if (0 != a) { SkPMColor dstC = SkPixel16ToPixel32(dst[i]); SkPMColor C = proc(src[i], dstC); if (0xFF != a) { C = SkFourByteInterp(C, dstC, a); } dst[i] = SkPixel32ToPixel16_ToU16(C); } } } } }
const uint16_t* SkColorTable::read16BitCache() const { return f16BitCache.get([&]{ auto cache = new uint16_t[fCount]; for (int i = 0; i < fCount; i++) { cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); } return cache; }); }
const uint16_t* SkColorTable::read16BitCache() const { f16BitCacheOnce([this] { f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); for (int i = 0; i < fCount; i++) { f16BitCache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); } }); return f16BitCache; }
void SkSSE2ProcCoeffXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count, const SkAlpha aa[]) const { SkASSERT(dst && src && count >= 0); SkXfermodeProc proc = this->getProc(); SkXfermodeProcSIMD procSIMD = reinterpret_cast<SkXfermodeProcSIMD>(fProcSIMD); SkASSERT(procSIMD != NULL); if (NULL == aa) { if (count >= 8) { while (((size_t)dst & 0x0F) != 0) { SkPMColor dstC = SkPixel16ToPixel32(*dst); *dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC)); dst++; src++; count--; } const __m128i* s = reinterpret_cast<const __m128i*>(src); __m128i* d = reinterpret_cast<__m128i*>(dst); while (count >= 8) { __m128i src_pixel1 = _mm_loadu_si128(s++); __m128i src_pixel2 = _mm_loadu_si128(s++); __m128i dst_pixel = _mm_load_si128(d); __m128i dst_pixel1 = _mm_unpacklo_epi16(dst_pixel, _mm_setzero_si128()); __m128i dst_pixel2 = _mm_unpackhi_epi16(dst_pixel, _mm_setzero_si128()); __m128i dstC1 = SkPixel16ToPixel32_SSE2(dst_pixel1); __m128i dstC2 = SkPixel16ToPixel32_SSE2(dst_pixel2); dst_pixel1 = procSIMD(src_pixel1, dstC1); dst_pixel2 = procSIMD(src_pixel2, dstC2); dst_pixel = SkPixel32ToPixel16_ToU16_SSE2(dst_pixel1, dst_pixel2); _mm_store_si128(d++, dst_pixel); count -= 8; } src = reinterpret_cast<const SkPMColor*>(s); dst = reinterpret_cast<uint16_t*>(d); } for (int i = count - 1; i >= 0; --i) { SkPMColor dstC = SkPixel16ToPixel32(*dst); *dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC)); dst++; src++; } } else { for (int i = count - 1; i >= 0; --i) { unsigned a = aa[i]; if (0 != a) { SkPMColor dstC = SkPixel16ToPixel32(dst[i]); SkPMColor C = proc(src[i], dstC); if (0xFF != a) { C = SkFourByteInterp(C, dstC, a); } dst[i] = SkPixel32ToPixel16_ToU16(C); } } } }