blob: 9e4407b845daee723323e294c49aca83c68d9b12 [file] [log] [blame]
Tyler Denniston187d8112021-01-12 09:34:23 -05001/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "include/effects/SkImageFilters.h"
9#include "modules/svg/include/SkSVGAttributeParser.h"
10#include "modules/svg/include/SkSVGFeGaussianBlur.h"
11#include "modules/svg/include/SkSVGFilterContext.h"
12#include "modules/svg/include/SkSVGRenderContext.h"
13#include "modules/svg/include/SkSVGValue.h"
14
15bool SkSVGFeGaussianBlur::parseAndSetAttribute(const char* name, const char* value) {
16 return INHERITED::parseAndSetAttribute(name, value) ||
17 this->setStdDeviation(SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>(
18 "stdDeviation", name, value));
19}
20
21sk_sp<SkImageFilter> SkSVGFeGaussianBlur::onMakeImageFilter(const SkSVGRenderContext& ctx,
22 const SkSVGFilterContext& fctx) const {
23 SkScalar sigmaX = fStdDeviation.fX;
24 SkScalar sigmaY = fStdDeviation.fY;
25 if (fctx.primitiveUnits().type() == SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox) {
26 SkASSERT(ctx.node());
27 const SkRect objBounds = ctx.node()->objectBoundingBox(ctx);
28 sigmaX *= objBounds.width();
29 sigmaY *= objBounds.height();
30 }
31
32 return SkImageFilters::Blur(sigmaX, sigmaY,
John Stiles36acb7b2021-01-13 22:57:06 +000033 fctx.resolveInput(ctx, this->getIn()),
Tyler Denniston187d8112021-01-12 09:34:23 -050034 this->resolveFilterSubregion(ctx, fctx));
35}
36
37template <>
38bool SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>(
39 SkSVGFeGaussianBlur::StdDeviation* stdDeviation) {
40 std::vector<SkSVGNumberType> values;
41 if (!this->parse(&values)) {
42 return false;
43 }
44
45 stdDeviation->fX = values[0];
46 stdDeviation->fY = values.size() > 1 ? values[1] : values[0];
47 return true;
48}