diff options
author | Mike Klein <mtklein@chromium.org> | 2016-12-13 15:44:23 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-13 22:09:57 +0000 |
commit | 04e10da8362a0dcabd795a4ad53f617719ca0d20 (patch) | |
tree | 203575b49fb941990f0a19b288b6c6cc1eef9388 /src/core/SkRasterPipeline.cpp | |
parent | 21f783829619186442041de6008f7f58f4f6250d (diff) |
clamp to premul when reading premul sRGB
It's pretty easy to start with sound premultiplied linear floats, pack those to sRGB encoded bytes, then read them back to linear floats and find them not quite premultiplied, with a color channel just a smidge greater than the alpha channel. This can happen basically any time we have different transfer functions for alpha and colors... sRGB being the only one we draw into.
This is an annoying problem with no known good solution. So apply the clamp hammer.
These new calls on SkRasterPipeline should make it impossible to get wrong.
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD
Change-Id: I4c974f4a7b151f3f684946f1e83d06b1b288fd01
Reviewed-on: https://skia-review.googlesource.com/5945
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkRasterPipeline.cpp')
-rw-r--r-- | src/core/SkRasterPipeline.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/core/SkRasterPipeline.cpp b/src/core/SkRasterPipeline.cpp index 4c1dbc762e..00ba81e6f3 100644 --- a/src/core/SkRasterPipeline.cpp +++ b/src/core/SkRasterPipeline.cpp @@ -11,6 +11,14 @@ SkRasterPipeline::SkRasterPipeline() {} void SkRasterPipeline::append(StockStage stage, void* ctx) { +#ifdef SK_DEBUG + switch (stage) { + case from_srgb: + case from_srgb_d: + SkDEBUGFAIL("Please use append_srgb[_d]() instead."); + default: break; + } +#endif fStages.push_back({stage, ctx}); } @@ -42,3 +50,29 @@ void SkRasterPipeline::dump() const { } SkDebugf("\n"); } + +// It's pretty easy to start with sound premultiplied linear floats, pack those +// to sRGB encoded bytes, then read them back to linear floats and find them not +// quite premultiplied, with a color channel just a smidge greater than the alpha +// channel. This can happen basically any time we have different transfer +// functions for alpha and colors... sRGB being the only one we draw into. + +// This is an annoying problem with no known good solution. So apply the clamp hammer. + +void SkRasterPipeline::append_from_srgb(SkAlphaType at) { + //this->append(from_srgb); + fStages.push_back({from_srgb, nullptr}); + + if (at == kPremul_SkAlphaType) { + this->append(SkRasterPipeline::clamp_a); + } +} + +void SkRasterPipeline::append_from_srgb_d(SkAlphaType at) { + //this->append(from_srgb_d); + fStages.push_back({from_srgb_d, nullptr}); + + if (at == kPremul_SkAlphaType) { + this->append(SkRasterPipeline::clamp_a_d); + } +} |