blob: 25f890e2636a1275aeaea9f97647847a451b6522 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkBlurMask_DEFINED
9#define SkBlurMask_DEFINED
10
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000011#include "SkBlurTypes.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkShader.h"
humper@google.com7c5d7b72013-03-11 20:16:28 +000013#include "SkMask.h"
commit-bot@chromium.orga4771542014-03-10 21:42:06 +000014#include "SkRRect.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015
16class SkBlurMask {
17public:
robertphillipse80eb922015-12-17 11:33:12 -080018 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);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +000026
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
robertphillipse80eb922015-12-17 11:33:12 -080033 static bool SK_WARN_UNUSED_RESULT BoxBlur(SkMask* dst, const SkMask& src,
34 SkScalar sigma, SkBlurStyle style, SkBlurQuality,
35 SkIPoint* margin = nullptr,
36 bool forceQuality = false);
humper@google.coma99a92c2013-02-20 16:42:06 +000037
38 // the "ground truth" blur does a gaussian convolution; it's slow
39 // but useful for comparison purposes.
robertphillipse80eb922015-12-17 11:33:12 -080040 static bool SK_WARN_UNUSED_RESULT BlurGroundTruth(SkScalar sigma, SkMask* dst,
41 const SkMask& src,
42 SkBlurStyle, SkIPoint* margin = nullptr);
humper@google.coma99a92c2013-02-20 16:42:06 +000043
reed@google.comdaaafa62014-04-29 15:20:16 +000044 // If radius > 0, return the corresponding sigma, else return 0
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000045 static SkScalar ConvertRadiusToSigma(SkScalar radius);
reed@google.comdaaafa62014-04-29 15:20:16 +000046 // If sigma > 0.5, return the corresponding radius, else return 0
47 static SkScalar ConvertSigmaToRadius(SkScalar sigma);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000048
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000049 /* Helper functions for analytic rectangle blurs */
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000050
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000051 /** Look up the intensity of the (one dimnensional) blurred half-plane.
52 @param profile The precomputed 1D blur profile; memory allocated by and managed by
53 ComputeBlurProfile below.
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000054 @param loc the location to look up; The lookup will clamp invalid inputs, but
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000055 meaningful data are available between 0 and blurred_width
56 @param blurred_width The width of the final, blurred rectangle
57 @param sharp_width The width of the original, unblurred rectangle.
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000058 */
robertphillips30c4cae2015-09-15 10:20:55 -070059 static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurredWidth, int sharpWidth);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000060
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000061 /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller
62 must free the memory. The amount of memory allocated will be exactly 6*sigma bytes.
63 @param sigma The standard deviation of the gaussian blur kernel
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000064 */
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000065
robertphillips30c4cae2015-09-15 10:20:55 -070066 static uint8_t* ComputeBlurProfile(SkScalar sigma);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000067
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000068 /** Compute an entire scanline of a blurred step function. This is a 1D helper that
69 will produce both the horizontal and vertical profiles of the blurry rectangle.
70 @param pixels Location to store the resulting pixel data; allocated and managed by caller
71 @param profile Precomputed blur profile computed by ComputeBlurProfile above.
72 @param width Size of the pixels array.
73 @param sigma Standard deviation of the gaussian blur kernel used to compute the profile;
74 this implicitly gives the size of the pixels array.
75 */
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000076
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000077 static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile,
78 unsigned int width, SkScalar sigma);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000079
80
81
reed@android.com8a1c16f2008-12-17 15:59:43 +000082};
83
84#endif