|
1 |
|
2 /* |
|
3 * Copyright 2006 The Android Open Source Project |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 |
|
10 #ifndef SkBlurMask_DEFINED |
|
11 #define SkBlurMask_DEFINED |
|
12 |
|
13 #include "SkShader.h" |
|
14 #include "SkMask.h" |
|
15 #include "SkRRect.h" |
|
16 |
|
17 class SkBlurMask { |
|
18 public: |
|
19 enum Style { |
|
20 kNormal_Style, //!< fuzzy inside and outside |
|
21 kSolid_Style, //!< solid inside, fuzzy outside |
|
22 kOuter_Style, //!< nothing inside, fuzzy outside |
|
23 kInner_Style, //!< fuzzy inside, nothing outside |
|
24 |
|
25 kStyleCount |
|
26 }; |
|
27 |
|
28 enum Quality { |
|
29 kLow_Quality, //!< box blur |
|
30 kHigh_Quality //!< three pass box blur (similar to gaussian) |
|
31 }; |
|
32 |
|
33 static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, |
|
34 Style style, |
|
35 SkIPoint *margin = NULL, |
|
36 SkMask::CreateMode createMode = |
|
37 SkMask::kComputeBoundsAndRenderImage_CreateMode); |
|
38 static bool BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src, |
|
39 Style style, |
|
40 SkIPoint *margin = NULL, |
|
41 SkMask::CreateMode createMode = |
|
42 SkMask::kComputeBoundsAndRenderImage_CreateMode); |
|
43 static bool BoxBlur(SkMask* dst, const SkMask& src, |
|
44 SkScalar sigma, Style style, Quality quality, |
|
45 SkIPoint* margin = NULL); |
|
46 |
|
47 // the "ground truth" blur does a gaussian convolution; it's slow |
|
48 // but useful for comparison purposes. |
|
49 static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, |
|
50 Style style, |
|
51 SkIPoint* margin = NULL); |
|
52 |
|
53 static SkScalar ConvertRadiusToSigma(SkScalar radius); |
|
54 |
|
55 /* Helper functions for analytic rectangle blurs */ |
|
56 |
|
57 /** Look up the intensity of the (one dimnensional) blurred half-plane. |
|
58 @param profile The precomputed 1D blur profile; memory allocated by and managed by |
|
59 ComputeBlurProfile below. |
|
60 @param loc the location to look up; The lookup will clamp invalid inputs, but |
|
61 meaningful data are available between 0 and blurred_width |
|
62 @param blurred_width The width of the final, blurred rectangle |
|
63 @param sharp_width The width of the original, unblurred rectangle. |
|
64 */ |
|
65 static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurred_width, int sharp_width); |
|
66 |
|
67 /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller |
|
68 must free the memory. The amount of memory allocated will be exactly 6*sigma bytes. |
|
69 @param sigma The standard deviation of the gaussian blur kernel |
|
70 @param profile_out The location to store the allocated profile curve |
|
71 */ |
|
72 |
|
73 static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out); |
|
74 |
|
75 /** Compute an entire scanline of a blurred step function. This is a 1D helper that |
|
76 will produce both the horizontal and vertical profiles of the blurry rectangle. |
|
77 @param pixels Location to store the resulting pixel data; allocated and managed by caller |
|
78 @param profile Precomputed blur profile computed by ComputeBlurProfile above. |
|
79 @param width Size of the pixels array. |
|
80 @param sigma Standard deviation of the gaussian blur kernel used to compute the profile; |
|
81 this implicitly gives the size of the pixels array. |
|
82 */ |
|
83 |
|
84 static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile, |
|
85 unsigned int width, SkScalar sigma); |
|
86 |
|
87 |
|
88 |
|
89 }; |
|
90 |
|
91 #endif |