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

Unified Diff: src/core/SkSRGB.h

Issue 2173803002: Add clamp to sk_linear_to_srgb, reorder instructions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add a very important set of parentheses 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 | « no previous file | src/opts/SkColorXform_opts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkSRGB.h
diff --git a/src/core/SkSRGB.h b/src/core/SkSRGB.h
index d3baa7463198ee28611b93906c72d8d276ba1471..08ba860e4a5df9aeb545d95165a62b37dc969728 100644
--- a/src/core/SkSRGB.h
+++ b/src/core/SkSRGB.h
@@ -22,6 +22,12 @@
extern const float sk_linear_from_srgb[256];
+static inline Sk4f sk_clamp_0_255(const Sk4f& x) {
+ // The order of the arguments is important here. We want to make sure that NaN
+ // clamps to zero. Note that max(NaN, 0) = 0, while max(0, NaN) = NaN.
+ return Sk4f::Min(Sk4f::Max(x, 0.0f), 255.0f);
+}
+
static inline Sk4i sk_linear_to_srgb(const Sk4f& x) {
// Approximation of the sRGB gamma curve (within 1 when scaled to 8-bit pixels).
//
@@ -40,7 +46,7 @@ static inline Sk4i sk_linear_to_srgb(const Sk4f& x) {
+ (+0.687999f * 255.0f) * sqrt
+ (+0.412999f * 255.0f) * ftrt;
- return SkNx_cast<int>( (x < 0.0048f).thenElse(lo, hi) );
+ return SkNx_cast<int>(sk_clamp_0_255((x < 0.0048f).thenElse(lo, hi)));
}
#endif//SkSRGB_DEFINED
« no previous file with comments | « no previous file | src/opts/SkColorXform_opts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698