michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkBlurMask_DEFINED michael@0: #define SkBlurMask_DEFINED michael@0: michael@0: #include "SkShader.h" michael@0: #include "SkMask.h" michael@0: #include "SkRRect.h" michael@0: michael@0: class SkBlurMask { michael@0: public: michael@0: enum Style { michael@0: kNormal_Style, //!< fuzzy inside and outside michael@0: kSolid_Style, //!< solid inside, fuzzy outside michael@0: kOuter_Style, //!< nothing inside, fuzzy outside michael@0: kInner_Style, //!< fuzzy inside, nothing outside michael@0: michael@0: kStyleCount michael@0: }; michael@0: michael@0: enum Quality { michael@0: kLow_Quality, //!< box blur michael@0: kHigh_Quality //!< three pass box blur (similar to gaussian) michael@0: }; michael@0: michael@0: static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, michael@0: Style style, michael@0: SkIPoint *margin = NULL, michael@0: SkMask::CreateMode createMode = michael@0: SkMask::kComputeBoundsAndRenderImage_CreateMode); michael@0: static bool BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src, michael@0: Style style, michael@0: SkIPoint *margin = NULL, michael@0: SkMask::CreateMode createMode = michael@0: SkMask::kComputeBoundsAndRenderImage_CreateMode); michael@0: static bool BoxBlur(SkMask* dst, const SkMask& src, michael@0: SkScalar sigma, Style style, Quality quality, michael@0: SkIPoint* margin = NULL); michael@0: michael@0: // the "ground truth" blur does a gaussian convolution; it's slow michael@0: // but useful for comparison purposes. michael@0: static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, michael@0: Style style, michael@0: SkIPoint* margin = NULL); michael@0: michael@0: static SkScalar ConvertRadiusToSigma(SkScalar radius); michael@0: michael@0: /* Helper functions for analytic rectangle blurs */ michael@0: michael@0: /** Look up the intensity of the (one dimnensional) blurred half-plane. michael@0: @param profile The precomputed 1D blur profile; memory allocated by and managed by michael@0: ComputeBlurProfile below. michael@0: @param loc the location to look up; The lookup will clamp invalid inputs, but michael@0: meaningful data are available between 0 and blurred_width michael@0: @param blurred_width The width of the final, blurred rectangle michael@0: @param sharp_width The width of the original, unblurred rectangle. michael@0: */ michael@0: static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurred_width, int sharp_width); michael@0: michael@0: /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller michael@0: must free the memory. The amount of memory allocated will be exactly 6*sigma bytes. michael@0: @param sigma The standard deviation of the gaussian blur kernel michael@0: @param profile_out The location to store the allocated profile curve michael@0: */ michael@0: michael@0: static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out); michael@0: michael@0: /** Compute an entire scanline of a blurred step function. This is a 1D helper that michael@0: will produce both the horizontal and vertical profiles of the blurry rectangle. michael@0: @param pixels Location to store the resulting pixel data; allocated and managed by caller michael@0: @param profile Precomputed blur profile computed by ComputeBlurProfile above. michael@0: @param width Size of the pixels array. michael@0: @param sigma Standard deviation of the gaussian blur kernel used to compute the profile; michael@0: this implicitly gives the size of the pixels array. michael@0: */ michael@0: michael@0: static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile, michael@0: unsigned int width, SkScalar sigma); michael@0: michael@0: michael@0: michael@0: }; michael@0: michael@0: #endif