Flutter Engine
The Flutter Engine
SharpenEffect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
11#include "include/core/SkSize.h"
21
22#include <cstddef>
23#include <utility>
24
25namespace skjson {
26class ArrayValue;
27}
28
29namespace skottie::internal {
30
31namespace {
32
33class SharpenAdapter final : public DiscardableAdapterBase<SharpenAdapter,
34 sksg::ExternalImageFilter> {
35 public:
36 SharpenAdapter(const skjson::ArrayValue& jprops,
37 const AnimationBuilder& abuilder)
38 : INHERITED(sksg::ExternalImageFilter::Make())
39 {
40 enum : size_t {
41 kSharpenAmount_Index = 0,
42 };
43
44 EffectBinder(jprops, abuilder, this).bind(kSharpenAmount_Index, fAmount);
45 }
46 private:
47 void onSync() override {
48 SkScalar intensity = 1 + (fAmount * 0.01);
49 SkScalar discount = (1 - intensity) / 8.0;
50 SkScalar kernel[9] = {
51 discount, discount, discount,
52 discount, intensity, discount,
53 discount, discount, discount,
54 };
55 auto filter = SkImageFilters::MatrixConvolution(SkISize::Make(3,3), kernel, 1, 0,
57 true, nullptr);
58 this->node()->setImageFilter(std::move(filter));
59 }
60
61 ScalarValue fAmount = 0;
62
63 using INHERITED = DiscardableAdapterBase<SharpenAdapter, sksg::ExternalImageFilter>;
64};
65
66} // namespace
67
68sk_sp<sksg::RenderNode> EffectBuilder::attachSharpenEffect(const skjson::ArrayValue& jprops,
69 sk_sp<sksg::RenderNode> layer) const {
70 auto imageFilterNode = fBuilder->attachDiscardableAdapter<SharpenAdapter>(jprops,
71 *fBuilder);
72 return sksg::ImageFilterEffect::Make(std::move(layer), std::move(imageFilterNode));
73}
74
75} // namespace skottie::internal
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
static sk_sp< SkImageFilter > MatrixConvolution(const SkISize &kernelSize, const SkScalar kernel[], SkScalar gain, SkScalar bias, const SkIPoint &kernelOffset, SkTileMode tileMode, bool convolveAlpha, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
static sk_sp< RenderNode > Make(sk_sp< RenderNode > child, sk_sp< ImageFilter > filter)
float SkScalar
Definition: extension.cpp:12
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
SkScalar ScalarValue
Definition: SkottieValue.h:22
Definition: Skottie.h:32
static constexpr SkIPoint Make(int32_t x, int32_t y)
Definition: SkPoint_impl.h:38
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20