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

Unified Diff: src/core/SkPM4fPriv.h

Issue 2130183003: Remove bloat from SkBlend_opts. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 | « bench/SkBlend_optsBench.cpp ('k') | src/opts/SkBlend_opts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPM4fPriv.h
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h
index fa5498f90ae9a0b9a89e0b944bc2567d29b5ff06..57a44c1cb22ec04e83f25fa299e20701a32991ff 100644
--- a/src/core/SkPM4fPriv.h
+++ b/src/core/SkPM4fPriv.h
@@ -124,4 +124,28 @@ static inline uint32_t exact_Sk4f_toS32(const Sk4f& x4) {
return to_4b(exact_linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f));
}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// An implementation of SrcOver from bytes to bytes in linear space that takes advantage of the
+// observation that the 255's cancel.
+// invA = 1 - (As / 255);
+//
+// R = 255 * sqrt((Rs/255)^2 + (Rd/255)^2 * invA)
+// => R = 255 * sqrt((Rs^2 + Rd^2 * invA)/255^2)
+// => R = sqrt(Rs^2 + Rd^2 * invA)
+// Note: src is assumed to be linear.
+static inline void srcover_blend_srgb8888_srgb_1(uint32_t* dst, const Sk4f& src) {
+ Sk4f d = srgb_to_linear(to_4f(*dst));
+ Sk4f invAlpha = 1.0f - Sk4f{src[SkPM4f::A]} * (1.0f / 255.0f);
+ Sk4f r = linear_to_srgb(src + d * invAlpha) + 0.5f;
+ *dst = to_4b(r);
+}
+
+static inline void srcover_srgb8888_srgb_1(uint32_t* dst, const uint32_t pixel) {
+ if ((~pixel & 0xFF000000) == 0) {
+ *dst = pixel;
+ } else if ((pixel & 0xFF000000) != 0) {
+ srcover_blend_srgb8888_srgb_1(dst, srgb_to_linear(to_4f(pixel)));
+ }
+}
+
#endif
« no previous file with comments | « bench/SkBlend_optsBench.cpp ('k') | src/opts/SkBlend_opts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698