Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkBlurMask.h
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
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#ifndef SkBlurMask_DEFINED
9#define SkBlurMask_DEFINED
10
13#include "src/core/SkMask.h"
14
15#include <cstdint>
16
17class SkRRect;
18enum SkBlurStyle : int;
19struct SkIPoint;
20struct SkRect;
21
23public:
24 [[nodiscard]] static bool BlurRect(SkScalar sigma, SkMaskBuilder *dst, const SkRect &src,
25 SkBlurStyle, SkIPoint *margin = nullptr,
26 SkMaskBuilder::CreateMode createMode =
28 [[nodiscard]] static bool BlurRRect(SkScalar sigma, SkMaskBuilder *dst, const SkRRect &src,
29 SkBlurStyle, SkIPoint *margin = nullptr,
30 SkMaskBuilder::CreateMode createMode =
32
33 // forceQuality will prevent BoxBlur from falling back to the low quality approach when sigma
34 // is very small -- this can be used predict the margin bump ahead of time without completely
35 // replicating the internal logic. This permits not only simpler caching of blurred results,
36 // but also being able to predict precisely at what pixels the blurred profile of e.g. a
37 // rectangle will lie.
38 //
39 // Calling details:
40 // * calculate margin - if src.fImage is null, then this call only calculates the border.
41 // * failure - if src.fImage is not null, failure is signal with dst->fImage being
42 // null.
43
44 [[nodiscard]] static bool BoxBlur(SkMaskBuilder* dst, const SkMask& src,
45 SkScalar sigma, SkBlurStyle style,
46 SkIPoint* margin = nullptr);
47
48 // the "ground truth" blur does a gaussian convolution; it's slow
49 // but useful for comparison purposes.
50 [[nodiscard]] static bool BlurGroundTruth(SkScalar sigma, SkMaskBuilder* dst,
51 const SkMask& src,
52 SkBlurStyle, SkIPoint* margin = nullptr);
53
54 // If radius > 0, return the corresponding sigma, else return 0
56 // If sigma > 0.5, return the corresponding radius, else return 0
58
59 /* Helper functions for analytic rectangle blurs */
60
61 /** Look up the intensity of the (one dimnensional) blurred half-plane.
62 @param profile The precomputed 1D blur profile; initialized by ComputeBlurProfile below.
63 @param loc the location to look up; The lookup will clamp invalid inputs, but
64 meaningful data are available between 0 and blurred_width
65 @param blurred_width The width of the final, blurred rectangle
66 @param sharp_width The width of the original, unblurred rectangle.
67 */
68 static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurredWidth, int sharpWidth);
69
70 /** Populate the profile of a 1D blurred halfplane.
71 @param profile The 1D table to fill in
72 @param size Should be 6*sigma bytes
73 @param sigma The standard deviation of the gaussian blur kernel
74 */
75 static void ComputeBlurProfile(uint8_t* profile, int size, SkScalar sigma);
76
77 /** Compute an entire scanline of a blurred step function. This is a 1D helper that
78 will produce both the horizontal and vertical profiles of the blurry rectangle.
79 @param pixels Location to store the resulting pixel data; allocated and managed by caller
80 @param profile Precomputed blur profile computed by ComputeBlurProfile above.
81 @param width Size of the pixels array.
82 @param sigma Standard deviation of the gaussian blur kernel used to compute the profile;
83 this implicitly gives the size of the pixels array.
84 */
85
86 static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile,
87 unsigned int width, SkScalar sigma);
88};
89
90#endif
#define SK_SPI
Definition SkAPI.h:41
SkBlurStyle
Definition SkBlurTypes.h:11
Type::kYUV Type::kRGBA() int(0.7 *637)
static void ComputeBlurProfile(uint8_t *profile, int size, SkScalar sigma)
static void ComputeBlurredScanline(uint8_t *pixels, const uint8_t *profile, unsigned int width, SkScalar sigma)
static bool BlurRect(SkScalar sigma, SkMaskBuilder *dst, const SkRect &src, SkBlurStyle, SkIPoint *margin=nullptr, SkMaskBuilder::CreateMode createMode=SkMaskBuilder::kComputeBoundsAndRenderImage_CreateMode)
static bool BlurRRect(SkScalar sigma, SkMaskBuilder *dst, const SkRRect &src, SkBlurStyle, SkIPoint *margin=nullptr, SkMaskBuilder::CreateMode createMode=SkMaskBuilder::kComputeBoundsAndRenderImage_CreateMode)
static SkScalar SK_SPI ConvertSigmaToRadius(SkScalar sigma)
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
static bool BlurGroundTruth(SkScalar sigma, SkMaskBuilder *dst, const SkMask &src, SkBlurStyle, SkIPoint *margin=nullptr)
static bool BoxBlur(SkMaskBuilder *dst, const SkMask &src, SkScalar sigma, SkBlurStyle style, SkIPoint *margin=nullptr)
static uint8_t ProfileLookup(const uint8_t *profile, int loc, int blurredWidth, int sharpWidth)
float SkScalar
Definition extension.cpp:12
int32_t width
@ kComputeBoundsAndRenderImage_CreateMode
compute bounds, alloc image and render into it
Definition SkMask.h:301