epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef SkBlurMask_DEFINED |
| 11 | #define SkBlurMask_DEFINED |
| 12 | |
| 13 | #include "SkShader.h" |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 14 | #include "SkMask.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | |
| 16 | class SkBlurMask { |
| 17 | public: |
| 18 | enum Style { |
| 19 | kNormal_Style, //!< fuzzy inside and outside |
| 20 | kSolid_Style, //!< solid inside, fuzzy outside |
| 21 | kOuter_Style, //!< nothing inside, fuzzy outside |
| 22 | kInner_Style, //!< fuzzy inside, nothing outside |
| 23 | |
| 24 | kStyleCount |
| 25 | }; |
| 26 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 27 | enum Quality { |
| 28 | kLow_Quality, //!< box blur |
| 29 | kHigh_Quality //!< three pass box blur (similar to gaussian) |
| 30 | }; |
| 31 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 32 | static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, |
| 33 | Style style, |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 34 | SkIPoint *margin = NULL, |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 35 | SkMask::CreateMode createMode = |
| 36 | SkMask::kComputeBoundsAndRenderImage_CreateMode); |
| 37 | static bool BoxBlur(SkMask* dst, const SkMask& src, |
| 38 | SkScalar sigma, Style style, Quality quality, |
| 39 | SkIPoint* margin = NULL); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 40 | |
| 41 | // the "ground truth" blur does a gaussian convolution; it's slow |
| 42 | // but useful for comparison purposes. |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 43 | static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, |
| 44 | Style style, |
| 45 | SkIPoint* margin = NULL); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 46 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 47 | SK_ATTR_DEPRECATED("use sigma version") |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 48 | static bool BlurRect(SkMask *dst, const SkRect &src, |
| 49 | SkScalar radius, Style style, |
| 50 | SkIPoint *margin = NULL, |
skia.committer@gmail.com | 7bd141d | 2013-08-28 07:01:18 +0000 | [diff] [blame] | 51 | SkMask::CreateMode createMode = |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 52 | SkMask::kComputeBoundsAndRenderImage_CreateMode); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 53 | |
| 54 | SK_ATTR_DEPRECATED("use sigma version") |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 55 | static bool Blur(SkMask* dst, const SkMask& src, |
| 56 | SkScalar radius, Style style, Quality quality, |
| 57 | SkIPoint* margin = NULL); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 58 | |
| 59 | SK_ATTR_DEPRECATED("use sigma version") |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 60 | static bool BlurGroundTruth(SkMask* dst, const SkMask& src, |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 61 | SkScalar radius, Style style, |
| 62 | SkIPoint* margin = NULL); |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 63 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 64 | static SkScalar ConvertRadiusToSigma(SkScalar radius); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 65 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 66 | /* Helper functions for analytic rectangle blurs */ |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 67 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 68 | /** Look up the intensity of the (one dimnensional) blurred half-plane. |
| 69 | @param profile The precomputed 1D blur profile; memory allocated by and managed by |
| 70 | ComputeBlurProfile below. |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 71 | @param loc the location to look up; The lookup will clamp invalid inputs, but |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 72 | meaningful data are available between 0 and blurred_width |
| 73 | @param blurred_width The width of the final, blurred rectangle |
| 74 | @param sharp_width The width of the original, unblurred rectangle. |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 75 | */ |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 76 | static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurred_width, int sharp_width); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 77 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 78 | /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller |
| 79 | must free the memory. The amount of memory allocated will be exactly 6*sigma bytes. |
| 80 | @param sigma The standard deviation of the gaussian blur kernel |
| 81 | @param profile_out The location to store the allocated profile curve |
| 82 | */ |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 83 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 84 | static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 85 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 86 | /** Compute an entire scanline of a blurred step function. This is a 1D helper that |
| 87 | will produce both the horizontal and vertical profiles of the blurry rectangle. |
| 88 | @param pixels Location to store the resulting pixel data; allocated and managed by caller |
| 89 | @param profile Precomputed blur profile computed by ComputeBlurProfile above. |
| 90 | @param width Size of the pixels array. |
| 91 | @param sigma Standard deviation of the gaussian blur kernel used to compute the profile; |
| 92 | this implicitly gives the size of the pixels array. |
| 93 | */ |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 94 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 95 | static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile, |
| 96 | unsigned int width, SkScalar sigma); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame^] | 97 | |
| 98 | |
| 99 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | #endif |