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

Unified Diff: src/core/SkColor.cpp

Issue 1622483002: Revert[2] of float color components (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix inversion of unpremul check Created 4 years, 11 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 | « include/effects/SkColorMatrixFilter.h ('k') | src/core/SkColorFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColor.cpp
diff --git a/src/core/SkColor.cpp b/src/core/SkColor.cpp
index a21f0192398f95ba3c4256a41c0d2ff47da4ed64..c9f4a1433dfd9a856c5d7f6bed4725147e0bde89 100644
--- a/src/core/SkColor.cpp
+++ b/src/core/SkColor.cpp
@@ -100,3 +100,37 @@ SkColor SkHSVToColor(U8CPU a, const SkScalar hsv[3]) {
}
return SkColorSetARGB(a, r, g, b);
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkNx.h"
+
+SkColor4f SkColor4f::Pin(float a, float r, float g, float b) {
+ SkColor4f c4;
+ Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec());
+ return c4;
+}
+
+SkColor4f SkColor4f::FromColor(SkColor c) {
+ Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load((const uint8_t*)&c)));
+ SkColor4f c4;
+ (value * Sk4f(1.0f / 255)).store(c4.vec());
+ return c4;
+}
+
+SkPM4f SkColor4f::premul() const {
+ auto src = Sk4f::Load(this->pin().vec());
+ float srcAlpha = src.kth<0>(); // need the pinned version of our alpha
+ src = src * Sk4f(1, srcAlpha, srcAlpha, srcAlpha);
+
+#ifdef SK_PMCOLOR_IS_BGRA
+ // ARGB -> BGRA
+ Sk4f dst = SkNx_shuffle<3,2,1,0>(src);
+#else
+ // ARGB -> RGBA
+ Sk4f dst = SkNx_shuffle<1,2,3,0>(src);
+#endif
+
+ SkPM4f pm4;
+ dst.store(pm4.fVec);
+ return pm4;
+}
« no previous file with comments | « include/effects/SkColorMatrixFilter.h ('k') | src/core/SkColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698