aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/svg/model/SkSVGRenderContext.cpp
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-08-29 05:54:42 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-29 05:54:42 -0700
commita26cab0c5375070fce4ed61ab282342cae171cdc (patch)
treefaadd01a8d44bba1b8afbdc3c50235bc40e2d816 /experimental/svg/model/SkSVGRenderContext.cpp
parent839d3ad854c015662301e1f36ce3845cbee730ea (diff)
[SVGDom] Don't truncate opacity scalars
Round instead, for more accurate values. R=robertphillips@google.com,stephana@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2284123003 Review-Url: https://codereview.chromium.org/2284123003
Diffstat (limited to 'experimental/svg/model/SkSVGRenderContext.cpp')
-rw-r--r--experimental/svg/model/SkSVGRenderContext.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/experimental/svg/model/SkSVGRenderContext.cpp b/experimental/svg/model/SkSVGRenderContext.cpp
index 4a1d77d6e4..d8f762142f 100644
--- a/experimental/svg/model/SkSVGRenderContext.cpp
+++ b/experimental/svg/model/SkSVGRenderContext.cpp
@@ -113,6 +113,10 @@ void applySvgPaint(const SkSVGPaint& svgPaint, SkPaint* p) {
}
}
+inline uint8_t opacity_to_alpha(SkScalar o) {
+ return SkTo<uint8_t>(SkScalarRoundToInt(o * 255));
+}
+
// Commit the selected attribute to the paint cache.
template <SkSVGAttribute>
void commitToPaint(const SkSVGPresentationAttributes&,
@@ -137,7 +141,7 @@ template <>
void commitToPaint<SkSVGAttribute::kFillOpacity>(const SkSVGPresentationAttributes& attrs,
const SkSVGLengthContext&,
SkSVGPresentationContext* pctx) {
- pctx->fFillPaint.setAlpha(static_cast<uint8_t>(*attrs.fFillOpacity.get() * 255));
+ pctx->fFillPaint.setAlpha(opacity_to_alpha(*attrs.fFillOpacity.get()));
}
template <>
@@ -164,7 +168,7 @@ template <>
void commitToPaint<SkSVGAttribute::kStrokeOpacity>(const SkSVGPresentationAttributes& attrs,
const SkSVGLengthContext&,
SkSVGPresentationContext* pctx) {
- pctx->fStrokePaint.setAlpha(static_cast<uint8_t>(*attrs.fStrokeOpacity.get() * 255));
+ pctx->fStrokePaint.setAlpha(opacity_to_alpha(*attrs.fStrokeOpacity.get()));
}
template <>
@@ -246,7 +250,7 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr
if (auto* opacity = attrs.fOpacity.getMaybeNull()) {
SkPaint opacityPaint;
- opacityPaint.setAlpha(static_cast<uint8_t>(opacity->value() * 255));
+ opacityPaint.setAlpha(opacity_to_alpha(opacity->value()));
// Balanced in the destructor, via restoreToCount().
fCanvas->saveLayer(nullptr, &opacityPaint);
}