Tyler Denniston | 187d811 | 2021-01-12 09:34:23 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | bool 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 | |
| 21 | sk_sp<SkImageFilter> SkSVGFeGaussianBlur::onMakeImageFilter(const SkSVGRenderContext& ctx, |
| 22 | const SkSVGFilterContext& fctx) const { |
Florin Malita | 3010f3d | 2021-04-30 10:48:42 -0400 | [diff] [blame] | 23 | const auto sigma = SkV2{fStdDeviation.fX, fStdDeviation.fY} |
| 24 | * ctx.transformForCurrentOBB(fctx.primitiveUnits()).scale; |
Tyler Denniston | 187d811 | 2021-01-12 09:34:23 -0500 | [diff] [blame] | 25 | |
Tyler Denniston | c7e4824 | 2021-01-20 17:31:36 -0500 | [diff] [blame] | 26 | return SkImageFilters::Blur( |
Florin Malita | 3010f3d | 2021-04-30 10:48:42 -0400 | [diff] [blame] | 27 | sigma.x, sigma.y, |
Tyler Denniston | c7e4824 | 2021-01-20 17:31:36 -0500 | [diff] [blame] | 28 | fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)), |
| 29 | this->resolveFilterSubregion(ctx, fctx)); |
Tyler Denniston | 187d811 | 2021-01-12 09:34:23 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | template <> |
| 33 | bool SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>( |
| 34 | SkSVGFeGaussianBlur::StdDeviation* stdDeviation) { |
| 35 | std::vector<SkSVGNumberType> values; |
| 36 | if (!this->parse(&values)) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | stdDeviation->fX = values[0]; |
| 41 | stdDeviation->fY = values.size() > 1 ? values[1] : values[0]; |
| 42 | return true; |
| 43 | } |