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