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

Unified Diff: src/opts/SkBlend_opts.h

Issue 1939783003: Add a hook for CPU-optimized sRGB-sRGB srcover. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits Created 4 years, 8 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
« no previous file with comments | « src/core/SkOpts.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkBlend_opts.h
diff --git a/src/opts/SkBlend_opts.h b/src/opts/SkBlend_opts.h
new file mode 100644
index 0000000000000000000000000000000000000000..a1067407be84a89b74b0b396d9d7a94ab1412973
--- /dev/null
+++ b/src/opts/SkBlend_opts.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBlend_opts_DEFINED
+#define SkBlend_opts_DEFINED
+
+namespace SK_OPTS_NS {
+
+#if 0
+
+#else
+
+ static inline void srcover_srgb_srgb_1(uint32_t* dst, uint32_t src) {
+ switch (src >> 24) {
f(malita) 2016/05/02 18:19:27 Should dst/src be SkPMColor to make the swizzle ex
+ case 0x00: return;
+ case 0xff: *dst = src; return;
+ }
+
+ Sk4f d = SkNx_cast<float>(Sk4b::Load( dst)),
+ s = SkNx_cast<float>(Sk4b::Load(&src));
+
+ // Approximate sRGB gamma as 2.0.
+ Sk4f d_sq = d*d,
+ s_sq = s*s;
+ d = Sk4f{d_sq[0], d_sq[1], d_sq[2], d[3]};
+ s = Sk4f{s_sq[0], s_sq[1], s_sq[2], s[3]};
+
+ // SrcOver.
+ Sk4f invA = 1.0f - s[3]*(1/255.0f);
+ d = s + d * invA;
+
+ // Re-apply approximate sRGB gamma.
+ Sk4f d_sqrt = d.sqrt();
+ d = Sk4f{d_sqrt[0], d_sqrt[1], d_sqrt[2], d[3]};
+
+ SkNx_cast<uint8_t>(d).store(dst);
+ }
+
+ static inline void srcover_srgb_srgb(uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) {
+ while (ndst > 0) {
+ int n = SkTMin(ndst, nsrc);
+
+ for (int i = 0; i < n; i++) {
+ srcover_srgb_srgb_1(dst++, src[i]);
+ }
+ ndst -= n;
+ }
+ }
+
+#endif
+
+} // namespace SK_OPTS_NS
+
+#endif//SkBlend_opts_DEFINED
« no previous file with comments | « src/core/SkOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698