epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkBlurMask_DEFINED |
| 9 | #define SkBlurMask_DEFINED |
| 10 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 11 | #include "SkBlurTypes.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkShader.h" |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 13 | #include "SkMask.h" |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 14 | #include "SkRRect.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | |
| 16 | class SkBlurMask { |
| 17 | public: |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 18 | static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, SkBlurStyle, |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 19 | SkIPoint *margin = NULL, |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 20 | SkMask::CreateMode createMode = |
| 21 | SkMask::kComputeBoundsAndRenderImage_CreateMode); |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 22 | static bool BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src, SkBlurStyle, |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 23 | SkIPoint *margin = NULL, |
| 24 | SkMask::CreateMode createMode = |
| 25 | SkMask::kComputeBoundsAndRenderImage_CreateMode); |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 26 | static bool BoxBlur(SkMask* dst, const SkMask& src, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 27 | SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, |
commit-bot@chromium.org | 55aec08 | 2014-04-28 18:21:24 +0000 | [diff] [blame] | 28 | SkIPoint* margin = NULL); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 29 | |
| 30 | // the "ground truth" blur does a gaussian convolution; it's slow |
| 31 | // but useful for comparison purposes. |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 32 | static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, SkBlurStyle, |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 33 | SkIPoint* margin = NULL); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 34 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 35 | static SkScalar ConvertRadiusToSigma(SkScalar radius); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 36 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 37 | /* Helper functions for analytic rectangle blurs */ |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 39 | /** Look up the intensity of the (one dimnensional) blurred half-plane. |
| 40 | @param profile The precomputed 1D blur profile; memory allocated by and managed by |
| 41 | ComputeBlurProfile below. |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 42 | @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] | 43 | meaningful data are available between 0 and blurred_width |
| 44 | @param blurred_width The width of the final, blurred rectangle |
| 45 | @param sharp_width The width of the original, unblurred rectangle. |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 46 | */ |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 47 | 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] | 48 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 49 | /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller |
| 50 | must free the memory. The amount of memory allocated will be exactly 6*sigma bytes. |
| 51 | @param sigma The standard deviation of the gaussian blur kernel |
| 52 | @param profile_out The location to store the allocated profile curve |
| 53 | */ |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 54 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 55 | static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 56 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 57 | /** Compute an entire scanline of a blurred step function. This is a 1D helper that |
| 58 | will produce both the horizontal and vertical profiles of the blurry rectangle. |
| 59 | @param pixels Location to store the resulting pixel data; allocated and managed by caller |
| 60 | @param profile Precomputed blur profile computed by ComputeBlurProfile above. |
| 61 | @param width Size of the pixels array. |
| 62 | @param sigma Standard deviation of the gaussian blur kernel used to compute the profile; |
| 63 | this implicitly gives the size of the pixels array. |
| 64 | */ |
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 | static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile, |
| 67 | unsigned int width, SkScalar sigma); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 68 | |
| 69 | |
| 70 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #endif |