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

Unified Diff: experimental/svg/model/SkSVGRenderContext.cpp

Issue 2284123003: [SVGDom] Don't truncate opacity scalars (Closed)
Patch Set: use explicit rounding Created 4 years, 4 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/svg/model/SkSVGRenderContext.cpp
diff --git a/experimental/svg/model/SkSVGRenderContext.cpp b/experimental/svg/model/SkSVGRenderContext.cpp
index 4a1d77d6e450ea463cdd9210ac64a30041c36ceb..d8f762142f6350849c49ae5435857aa84330504e 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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698