Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Unified Diff: src/core/SkXfermode4f.cpp

Issue 1707883002: lcd blits for sRGB (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more clarity on names/docs for new flags Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkXfermode.h ('K') | « src/core/SkBlitter_PM4f.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkXfermode4f.cpp
diff --git a/src/core/SkXfermode4f.cpp b/src/core/SkXfermode4f.cpp
index 9aba0da04f3d63f341df5a6740f5d7c7a5f364fc..bf30e92ae7dda664b7a88f8aa3565f3c41bdae51 100644
--- a/src/core/SkXfermode4f.cpp
+++ b/src/core/SkXfermode4f.cpp
@@ -422,3 +422,98 @@ SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const {
Mode mode;
return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n;
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkColorPriv.h"
+
+static Sk4f lcd16_to_unit_4f(uint16_t rgb) {
+ Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb), SkGetPackedB16(rgb), 0);
+ return SkNx_cast<float>(rgbi) * Sk4f(1.0f/31, 1.0f/63, 1.0f/31, 0);
+}
+
+template <DstType D>
+void src_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[]) {
+ const Sk4f s4 = Sk4f::Load(src->fVec);
+
+ if (D == kLinear_Dst) {
+ // operate in bias-255 space for src and dst
+ const Sk4f s4bias = s4 * Sk4f(255);
+ for (int i = 0; i < count; ++i) {
+ uint16_t rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f d4bias = to_4f(dst[i]);
+ dst[i] = to_4b(lerp(s4bias, d4bias, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ } else { // kSRGB
+ for (int i = 0; i < count; ++i) {
+ uint16_t rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f d4 = load_dst<D>(dst[i]);
+ dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ }
+}
+
+template <DstType D>
+void src_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t lcd[]) {
+ for (int i = 0; i < count; ++i) {
+ uint16_t rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f s4 = Sk4f::Load(src[i].fVec);
+ Sk4f d4 = load_dst<D>(dst[i]);
+ dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+}
+
+template <DstType D>
+void srcover_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[]) {
+ const Sk4f s4 = Sk4f::Load(src->fVec);
+ Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
+
+ for (int i = 0; i < count; ++i) {
+ uint16_t rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f d4 = load_dst<D>(dst[i]);
+ Sk4f r4 = s4 + d4 * dst_scale;
+ r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb));
+ dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+}
+
+template <DstType D>
+void srcover_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t lcd[]) {
+ for (int i = 0; i < count; ++i) {
+ uint16_t rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f s4 = Sk4f::Load(src[i].fVec);
+ Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
+ Sk4f d4 = load_dst<D>(dst[i]);
+ Sk4f r4 = s4 + d4 * dst_scale;
+ r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb));
+ dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+}
+
+SkXfermode::LCD32Proc SkXfermode::GetLCD32Proc(uint32_t flags) {
+ SkASSERT((flags & ~7) == 0);
+ flags &= 7;
+
+ const LCD32Proc procs[] = {
+ srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>,
+ srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>,
+
+ srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>,
+ srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>,
+ };
+ return procs[flags];
+}
« include/core/SkXfermode.h ('K') | « src/core/SkBlitter_PM4f.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698