1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkBlurMask_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkBlurMask_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11e396455d2d60ddf8e625b5037254f3c09fbcdcf5commit-bot@chromium.org#include "SkBlurTypes.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h" 137c5d7b781385c47e5be9a343d60c5b7d33b5b8cdhumper@google.com#include "SkMask.h" 14a477154cfce6276277f4eacc20908a6c986c112ccommit-bot@chromium.org#include "SkRRect.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkBlurMask { 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 18e396455d2d60ddf8e625b5037254f3c09fbcdcf5commit-bot@chromium.org static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, SkBlurStyle, 197ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com SkIPoint *margin = NULL, 207ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com SkMask::CreateMode createMode = 217ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com SkMask::kComputeBoundsAndRenderImage_CreateMode); 22e396455d2d60ddf8e625b5037254f3c09fbcdcf5commit-bot@chromium.org static bool BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src, SkBlurStyle, 23a477154cfce6276277f4eacc20908a6c986c112ccommit-bot@chromium.org SkIPoint *margin = NULL, 24a477154cfce6276277f4eacc20908a6c986c112ccommit-bot@chromium.org SkMask::CreateMode createMode = 25a477154cfce6276277f4eacc20908a6c986c112ccommit-bot@chromium.org SkMask::kComputeBoundsAndRenderImage_CreateMode); 263d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org 273d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org // forceQuality will prevent BoxBlur from falling back to the low quality approach when sigma 283d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org // is very small -- this can be used predict the margin bump ahead of time without completely 293d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org // replicating the internal logic. This permits not only simpler caching of blurred results, 303d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org // but also being able to predict precisely at what pixels the blurred profile of e.g. a 313d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org // rectangle will lie. 323d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org 337ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com static bool BoxBlur(SkMask* dst, const SkMask& src, 34e396455d2d60ddf8e625b5037254f3c09fbcdcf5commit-bot@chromium.org SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 353d8bf232bd2e4903d2ee2bb575637e7555361604commit-bot@chromium.org SkIPoint* margin = NULL, bool force_quality=false); 367ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com 377ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com // the "ground truth" blur does a gaussian convolution; it's slow 387ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com // but useful for comparison purposes. 39e396455d2d60ddf8e625b5037254f3c09fbcdcf5commit-bot@chromium.org static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, SkBlurStyle, 407ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com SkIPoint* margin = NULL); 417ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com 42daaafa6e81860e3dc52660ba019c336f0a43f1e7reed@google.com // If radius > 0, return the corresponding sigma, else return 0 437ce661d19c5cf4484305a1b20c44bd111f129847robertphillips@google.com static SkScalar ConvertRadiusToSigma(SkScalar radius); 44daaafa6e81860e3dc52660ba019c336f0a43f1e7reed@google.com // If sigma > 0.5, return the corresponding radius, else return 0 45daaafa6e81860e3dc52660ba019c336f0a43f1e7reed@google.com static SkScalar ConvertSigmaToRadius(SkScalar sigma); 464c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 47cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org /* Helper functions for analytic rectangle blurs */ 484c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 49cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org /** Look up the intensity of the (one dimnensional) blurred half-plane. 50cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param profile The precomputed 1D blur profile; memory allocated by and managed by 51cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org ComputeBlurProfile below. 524c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com @param loc the location to look up; The lookup will clamp invalid inputs, but 53cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org meaningful data are available between 0 and blurred_width 54cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param blurred_width The width of the final, blurred rectangle 55cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param sharp_width The width of the original, unblurred rectangle. 564c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com */ 57cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurred_width, int sharp_width); 584c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 59cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org /** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller 60cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org must free the memory. The amount of memory allocated will be exactly 6*sigma bytes. 61cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param sigma The standard deviation of the gaussian blur kernel 62cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param profile_out The location to store the allocated profile curve 63cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org */ 644c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 65cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out); 664c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 67cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org /** Compute an entire scanline of a blurred step function. This is a 1D helper that 68cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org will produce both the horizontal and vertical profiles of the blurry rectangle. 69cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param pixels Location to store the resulting pixel data; allocated and managed by caller 70cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param profile Precomputed blur profile computed by ComputeBlurProfile above. 71cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param width Size of the pixels array. 72cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org @param sigma Standard deviation of the gaussian blur kernel used to compute the profile; 73cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org this implicitly gives the size of the pixels array. 74cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org */ 754c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 76cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile, 77cf34bc06347dd2734a7fdaef5cf8853e92979d5ecommit-bot@chromium.org unsigned int width, SkScalar sigma); 784c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 794c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 804c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 84