1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/effects/SkBlurMask.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkBlurMask_DEFINED 1.14 +#define SkBlurMask_DEFINED 1.15 + 1.16 +#include "SkShader.h" 1.17 +#include "SkMask.h" 1.18 +#include "SkRRect.h" 1.19 + 1.20 +class SkBlurMask { 1.21 +public: 1.22 + enum Style { 1.23 + kNormal_Style, //!< fuzzy inside and outside 1.24 + kSolid_Style, //!< solid inside, fuzzy outside 1.25 + kOuter_Style, //!< nothing inside, fuzzy outside 1.26 + kInner_Style, //!< fuzzy inside, nothing outside 1.27 + 1.28 + kStyleCount 1.29 + }; 1.30 + 1.31 + enum Quality { 1.32 + kLow_Quality, //!< box blur 1.33 + kHigh_Quality //!< three pass box blur (similar to gaussian) 1.34 + }; 1.35 + 1.36 + static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, 1.37 + Style style, 1.38 + SkIPoint *margin = NULL, 1.39 + SkMask::CreateMode createMode = 1.40 + SkMask::kComputeBoundsAndRenderImage_CreateMode); 1.41 + static bool BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src, 1.42 + Style style, 1.43 + SkIPoint *margin = NULL, 1.44 + SkMask::CreateMode createMode = 1.45 + SkMask::kComputeBoundsAndRenderImage_CreateMode); 1.46 + static bool BoxBlur(SkMask* dst, const SkMask& src, 1.47 + SkScalar sigma, Style style, Quality quality, 1.48 + SkIPoint* margin = NULL); 1.49 + 1.50 + // the "ground truth" blur does a gaussian convolution; it's slow 1.51 + // but useful for comparison purposes. 1.52 + static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, 1.53 + Style style, 1.54 + SkIPoint* margin = NULL); 1.55 + 1.56 + static SkScalar ConvertRadiusToSigma(SkScalar radius); 1.57 + 1.58 + /* Helper functions for analytic rectangle blurs */ 1.59 + 1.60 + /** Look up the intensity of the (one dimnensional) blurred half-plane. 1.61 + @param profile The precomputed 1D blur profile; memory allocated by and managed by 1.62 + ComputeBlurProfile below. 1.63 + @param loc the location to look up; The lookup will clamp invalid inputs, but 1.64 + meaningful data are available between 0 and blurred_width 1.65 + @param blurred_width The width of the final, blurred rectangle 1.66 + @param sharp_width The width of the original, unblurred rectangle. 1.67 + */ 1.68 + static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurred_width, int sharp_width); 1.69 + 1.70 + /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller 1.71 + must free the memory. The amount of memory allocated will be exactly 6*sigma bytes. 1.72 + @param sigma The standard deviation of the gaussian blur kernel 1.73 + @param profile_out The location to store the allocated profile curve 1.74 + */ 1.75 + 1.76 + static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out); 1.77 + 1.78 + /** Compute an entire scanline of a blurred step function. This is a 1D helper that 1.79 + will produce both the horizontal and vertical profiles of the blurry rectangle. 1.80 + @param pixels Location to store the resulting pixel data; allocated and managed by caller 1.81 + @param profile Precomputed blur profile computed by ComputeBlurProfile above. 1.82 + @param width Size of the pixels array. 1.83 + @param sigma Standard deviation of the gaussian blur kernel used to compute the profile; 1.84 + this implicitly gives the size of the pixels array. 1.85 + */ 1.86 + 1.87 + static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile, 1.88 + unsigned int width, SkScalar sigma); 1.89 + 1.90 + 1.91 + 1.92 +}; 1.93 + 1.94 +#endif