1 /* 2 * Copyright 2019 Google LLC 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 8 #ifndef SkImageFilters_DEFINED 9 #define SkImageFilters_DEFINED 10 11 #include "include/core/SkBlendMode.h" 12 #include "include/core/SkColor.h" 13 #include "include/core/SkImage.h" 14 #include "include/core/SkImageFilter.h" 15 #include "include/core/SkPicture.h" 16 #include "include/core/SkRect.h" 17 #include "include/core/SkTileMode.h" 18 #include "include/core/SkTypes.h" 19 #include "include/effects/SkRuntimeEffect.h" 20 21 #include <cstddef> 22 23 class SkBlender; 24 class SkColorFilter; 25 class SkPaint; 26 class SkRegion; 27 28 namespace skif { 29 static constexpr SkRect kNoCropRect = {SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity, 30 SK_ScalarInfinity, SK_ScalarInfinity}; 31 } 32 33 // A set of factory functions providing useful SkImageFilter effects. For image filters that take an 34 // input filter, providing nullptr means it will automatically use the dynamic source image. This 35 // source depends on how the filter is applied, but is either the contents of a saved layer when 36 // drawing with SkCanvas, or an explicit SkImage if using SkImage::makeWithFilter. 37 class SK_API SkImageFilters { 38 public: 39 // This is just a convenience type to allow passing SkIRects, SkRects, and optional pointers 40 // to those types as a crop rect for the image filter factories. It's not intended to be used 41 // directly. 42 struct CropRect { CropRectCropRect43 CropRect() : fCropRect(skif::kNoCropRect) {} 44 // Intentionally not explicit so callers don't have to use this type but can use SkIRect or 45 // SkRect as desired. CropRectCropRect46 CropRect(std::nullptr_t) : fCropRect(skif::kNoCropRect) {} CropRectCropRect47 CropRect(const SkIRect& crop) : fCropRect(SkRect::Make(crop)) {} CropRectCropRect48 CropRect(const SkRect& crop) : fCropRect(crop) {} CropRectCropRect49 CropRect(const SkIRect* optionalCrop) : fCropRect(optionalCrop ? SkRect::Make(*optionalCrop) 50 : skif::kNoCropRect) {} CropRectCropRect51 CropRect(const SkRect* optionalCrop) : fCropRect(optionalCrop ? *optionalCrop 52 : skif::kNoCropRect) {} 53 54 operator const SkRect*() const { return fCropRect == skif::kNoCropRect ? nullptr : &fCropRect; } 55 56 SkRect fCropRect; 57 }; 58 59 /** 60 * Create a filter that updates the alpha of the image based on 'region'. Pixels inside the 61 * region are made more opaque and pixels outside are made more transparent. 62 * 63 * Specifically, if a pixel is inside the region, its alpha will be set to 64 * max(innerMin, pixel's alpha). If a pixel is outside the region, its alpha will be updated to 65 * min(outerMax, pixel's alpha). 66 * @param region The geometric region controlling the inner and outer alpha thresholds. 67 * @param innerMin The minimum alpha value for pixels inside 'region'. 68 * @param outerMax The maximum alpha value for pixels outside of 'region'. 69 * @param input The input filter, or uses the source bitmap if this is null. 70 * @param cropRect Optional rectangle that crops the input and output. 71 */ 72 static sk_sp<SkImageFilter> AlphaThreshold(const SkRegion& region, SkScalar innerMin, 73 SkScalar outerMax, sk_sp<SkImageFilter> input, 74 const CropRect& cropRect = {}); 75 76 /** 77 * Create a filter that implements a custom blend mode. Each output pixel is the result of 78 * combining the corresponding background and foreground pixels using the 4 coefficients: 79 * k1 * foreground * background + k2 * foreground + k3 * background + k4 80 * @param k1, k2, k3, k4 The four coefficients used to combine the foreground and background. 81 * @param enforcePMColor If true, the RGB channels will be clamped to the calculated alpha. 82 * @param background The background content, using the source bitmap when this is null. 83 * @param foreground The foreground content, using the source bitmap when this is null. 84 * @param cropRect Optional rectangle that crops the inputs and output. 85 */ 86 static sk_sp<SkImageFilter> Arithmetic(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4, 87 bool enforcePMColor, sk_sp<SkImageFilter> background, 88 sk_sp<SkImageFilter> foreground, 89 const CropRect& cropRect = {}); 90 91 /** 92 * This filter takes an SkBlendMode and uses it to composite the two filters together. 93 * @param mode The blend mode that defines the compositing operation 94 * @param background The Dst pixels used in blending, if null the source bitmap is used. 95 * @param foreground The Src pixels used in blending, if null the source bitmap is used. 96 * @cropRect Optional rectangle to crop input and output. 97 */ 98 static sk_sp<SkImageFilter> Blend(SkBlendMode mode, sk_sp<SkImageFilter> background, 99 sk_sp<SkImageFilter> foreground = nullptr, 100 const CropRect& cropRect = {}); 101 102 /** 103 * This filter takes an SkBlendMode and uses it to composite the two filters together. 104 * @param blender The blender that defines the compositing operation 105 * @param background The Dst pixels used in blending, if null the source bitmap is used. 106 * @param foreground The Src pixels used in blending, if null the source bitmap is used. 107 * @cropRect Optional rectangle to crop input and output. 108 */ 109 static sk_sp<SkImageFilter> Blend(sk_sp<SkBlender> blender, sk_sp<SkImageFilter> background, 110 sk_sp<SkImageFilter> foreground = nullptr, 111 const CropRect& cropRect = {}); 112 113 /** 114 * Create a filter that blurs its input by the separate X and Y sigmas. The provided tile mode 115 * is used when the blur kernel goes outside the input image. 116 * @param sigmaX The Gaussian sigma value for blurring along the X axis. 117 * @param sigmaY The Gaussian sigma value for blurring along the Y axis. 118 * @param tileMode The tile mode applied at edges . 119 * TODO (michaelludwig) - kMirror is not supported yet 120 * @param input The input filter that is blurred, uses source bitmap if this is null. 121 * @param cropRect Optional rectangle that crops the input and output. 122 */ 123 static sk_sp<SkImageFilter> Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, 124 sk_sp<SkImageFilter> input, const CropRect& cropRect = {}); 125 // As above, but defaults to the decal tile mode. 126 static sk_sp<SkImageFilter> Blur(SkScalar sigmaX, SkScalar sigmaY, sk_sp<SkImageFilter> input, 127 const CropRect& cropRect = {}) { 128 return Blur(sigmaX, sigmaY, SkTileMode::kDecal, std::move(input), cropRect); 129 } 130 131 /** 132 * Create a filter that applies the color filter to the input filter results. 133 * @param cf The color filter that transforms the input image. 134 * @param input The input filter, or uses the source bitmap if this is null. 135 * @param cropRect Optional rectangle that crops the input and output. 136 */ 137 static sk_sp<SkImageFilter> ColorFilter(sk_sp<SkColorFilter> cf, sk_sp<SkImageFilter> input, 138 const CropRect& cropRect = {}); 139 140 /** 141 * Create a filter that composes 'inner' with 'outer', such that the results of 'inner' are 142 * treated as the source bitmap passed to 'outer', i.e. result = outer(inner(source)). 143 * @param outer The outer filter that evaluates the results of inner. 144 * @param inner The inner filter that produces the input to outer. 145 */ 146 static sk_sp<SkImageFilter> Compose(sk_sp<SkImageFilter> outer, sk_sp<SkImageFilter> inner); 147 148 /** 149 * Create a filter that moves each pixel in its color input based on an (x,y) vector encoded 150 * in its displacement input filter. Two color components of the displacement image are 151 * mapped into a vector as scale * (color[xChannel], color[yChannel]), where the channel 152 * selectors are one of R, G, B, or A. 153 * @param xChannelSelector RGBA channel that encodes the x displacement per pixel. 154 * @param yChannelSelector RGBA channel that encodes the y displacement per pixel. 155 * @param scale Scale applied to displacement extracted from image. 156 * @param displacement The filter defining the displacement image, or null to use source. 157 * @param color The filter providing the color pixels to be displaced. If null, 158 * it will use the source. 159 * @param cropRect Optional rectangle that crops the color input and output. 160 */ 161 static sk_sp<SkImageFilter> DisplacementMap(SkColorChannel xChannelSelector, 162 SkColorChannel yChannelSelector, 163 SkScalar scale, sk_sp<SkImageFilter> displacement, 164 sk_sp<SkImageFilter> color, 165 const CropRect& cropRect = {}); 166 167 /** 168 * Create a filter that draws a drop shadow under the input content. This filter produces an 169 * image that includes the inputs' content. 170 * @param dx The X offset of the shadow. 171 * @param dy The Y offset of the shadow. 172 * @param sigmaX The blur radius for the shadow, along the X axis. 173 * @param sigmaY The blur radius for the shadow, along the Y axis. 174 * @param color The color of the drop shadow. 175 * @param input The input filter, or will use the source bitmap if this is null. 176 * @param cropRect Optional rectangle that crops the input and output. 177 */ 178 static sk_sp<SkImageFilter> DropShadow(SkScalar dx, SkScalar dy, 179 SkScalar sigmaX, SkScalar sigmaY, 180 SkColor color, sk_sp<SkImageFilter> input, 181 const CropRect& cropRect = {}); 182 /** 183 * Create a filter that renders a drop shadow, in exactly the same manner as ::DropShadow, 184 * except that the resulting image does not include the input content. This allows the shadow 185 * and input to be composed by a filter DAG in a more flexible manner. 186 * @param dx The X offset of the shadow. 187 * @param dy The Y offset of the shadow. 188 * @param sigmaX The blur radius for the shadow, along the X axis. 189 * @param sigmaY The blur radius for the shadow, along the Y axis. 190 * @param color The color of the drop shadow. 191 * @param input The input filter, or will use the source bitmap if this is null. 192 * @param cropRect Optional rectangle that crops the input and output. 193 */ 194 static sk_sp<SkImageFilter> DropShadowOnly(SkScalar dx, SkScalar dy, 195 SkScalar sigmaX, SkScalar sigmaY, 196 SkColor color, sk_sp<SkImageFilter> input, 197 const CropRect& cropRect = {}); 198 199 /** 200 * Create a filter that draws the 'srcRect' portion of image into 'dstRect' using the given 201 * filter quality. Similar to SkCanvas::drawImageRect. Returns null if 'image' is null. 202 * @param image The image that is output by the filter, subset by 'srcRect'. 203 * @param srcRect The source pixels sampled into 'dstRect' 204 * @param dstRect The local rectangle to draw the image into. 205 * @param sampling The sampling to use when drawing the image. 206 */ 207 static sk_sp<SkImageFilter> Image(sk_sp<SkImage> image, const SkRect& srcRect, 208 const SkRect& dstRect, const SkSamplingOptions& sampling); 209 210 /** 211 * Create a filter that draws the image using the given sampling. 212 * Similar to SkCanvas::drawImage. Returns null if 'image' is null. 213 * @param image The image that is output by the filter. 214 * @param sampling The sampling to use when drawing the image. 215 */ Image(sk_sp<SkImage> image,const SkSamplingOptions & sampling)216 static sk_sp<SkImageFilter> Image(sk_sp<SkImage> image, const SkSamplingOptions& sampling) { 217 if (image) { 218 SkRect r = SkRect::Make(image->bounds()); 219 return Image(std::move(image), r, r, sampling); 220 } else { 221 return nullptr; 222 } 223 } 224 225 /** 226 * Create a filter that draws the image using Mitchel cubic resampling. 227 * @param image The image that is output by the filter. 228 */ Image(sk_sp<SkImage> image)229 static sk_sp<SkImageFilter> Image(sk_sp<SkImage> image) { 230 return Image(std::move(image), SkSamplingOptions({1/3.0f, 1/3.0f})); 231 } 232 233 /** 234 * Create a filter that mimics a zoom/magnifying lens effect. 235 * @param srcRect 236 * @param inset 237 * @param input The input filter that is magnified, if null the source bitmap is used. 238 * @param cropRect Optional rectangle that crops the input and output. 239 */ 240 static sk_sp<SkImageFilter> Magnifier(const SkRect& srcRect, SkScalar inset, 241 sk_sp<SkImageFilter> input, 242 const CropRect& cropRect = {}); 243 244 /** 245 * Create a filter that applies an NxM image processing kernel to the input image. This can be 246 * used to produce effects such as sharpening, blurring, edge detection, etc. 247 * @param kernelSize The kernel size in pixels, in each dimension (N by M). 248 * @param kernel The image processing kernel. Must contain N * M elements, in row order. 249 * @param gain A scale factor applied to each pixel after convolution. This can be 250 * used to normalize the kernel, if it does not already sum to 1. 251 * @param bias A bias factor added to each pixel after convolution. 252 * @param kernelOffset An offset applied to each pixel coordinate before convolution. 253 * This can be used to center the kernel over the image 254 * (e.g., a 3x3 kernel should have an offset of {1, 1}). 255 * @param tileMode How accesses outside the image are treated. 256 * TODO (michaelludwig) - kMirror is not supported yet 257 * @param convolveAlpha If true, all channels are convolved. If false, only the RGB channels 258 * are convolved, and alpha is copied from the source image. 259 * @param input The input image filter, if null the source bitmap is used instead. 260 * @param cropRect Optional rectangle to which the output processing will be limited. 261 */ 262 static sk_sp<SkImageFilter> MatrixConvolution(const SkISize& kernelSize, 263 const SkScalar kernel[], SkScalar gain, 264 SkScalar bias, const SkIPoint& kernelOffset, 265 SkTileMode tileMode, bool convolveAlpha, 266 sk_sp<SkImageFilter> input, 267 const CropRect& cropRect = {}); 268 269 /** 270 * Create a filter that transforms the input image by 'matrix'. This matrix transforms the 271 * local space, which means it effectively happens prior to any transformation coming from the 272 * SkCanvas initiating the filtering. 273 * @param matrix The matrix to apply to the original content. 274 * @param sampling How the image will be sampled when it is transformed 275 * @param input The image filter to transform, or null to use the source image. 276 */ 277 static sk_sp<SkImageFilter> MatrixTransform(const SkMatrix& matrix, 278 const SkSamplingOptions& sampling, 279 sk_sp<SkImageFilter> input); 280 281 /** 282 * Create a filter that merges the 'count' filters together by drawing their results in order 283 * with src-over blending. 284 * @param filters The input filter array to merge, which must have 'count' elements. Any null 285 * filter pointers will use the source bitmap instead. 286 * @param count The number of input filters to be merged. 287 * @param cropRect Optional rectangle that crops all input filters and the output. 288 */ 289 static sk_sp<SkImageFilter> Merge(sk_sp<SkImageFilter>* const filters, int count, 290 const CropRect& cropRect = {}); 291 /** 292 * Create a filter that merges the results of the two filters together with src-over blending. 293 * @param first The first input filter, or the source bitmap if this is null. 294 * @param second The second input filter, or the source bitmap if this null. 295 * @param cropRect Optional rectangle that crops the inputs and output. 296 */ 297 static sk_sp<SkImageFilter> Merge(sk_sp<SkImageFilter> first, sk_sp<SkImageFilter> second, 298 const CropRect& cropRect = {}) { 299 sk_sp<SkImageFilter> array[] = { std::move(first), std::move(second) }; 300 return Merge(array, 2, cropRect); 301 } 302 303 /** 304 * Create a filter that offsets the input filter by the given vector. 305 * @param dx The x offset in local space that the image is shifted. 306 * @param dy The y offset in local space that the image is shifted. 307 * @param input The input that will be moved, if null the source bitmap is used instead. 308 * @param cropRect Optional rectangle to crop the input and output. 309 */ 310 static sk_sp<SkImageFilter> Offset(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input, 311 const CropRect& cropRect = {}); 312 313 /** 314 * Create a filter that produces the SkPicture as its output, drawn into targetRect. Note that 315 * the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns 316 * null if 'pic' is null. 317 * @param pic The picture that is drawn for the filter output. 318 * @param targetRect The drawing region for the picture. 319 */ 320 static sk_sp<SkImageFilter> Picture(sk_sp<SkPicture> pic, const SkRect& targetRect); 321 // As above, but uses SkPicture::cullRect for the drawing region. Picture(sk_sp<SkPicture> pic)322 static sk_sp<SkImageFilter> Picture(sk_sp<SkPicture> pic) { 323 SkRect target = pic ? pic->cullRect() : SkRect::MakeEmpty(); 324 return Picture(std::move(pic), target); 325 } 326 327 #ifdef SK_ENABLE_SKSL 328 /** 329 * Create a filter that fills the output with the per-pixel evaluation of the SkShader produced 330 * by the SkRuntimeShaderBuilder. The shader is defined in the image filter's local coordinate 331 * system, so it will automatically be affected by SkCanvas' transform. 332 * 333 * @param builder The builder used to produce the runtime shader, that will in turn 334 * fill the result image 335 * @param childShaderName The name of the child shader defined in the builder that will be 336 * bound to the input param (or the source image if the input param 337 * is null). If empty, the builder can have exactly one child shader, 338 * which automatically binds the input param. 339 * @param input The image filter that will be provided as input to the runtime 340 * shader. If null the implicit source image is used instead 341 */ 342 static sk_sp<SkImageFilter> RuntimeShader(const SkRuntimeShaderBuilder& builder, 343 std::string_view childShaderName, 344 sk_sp<SkImageFilter> input); 345 346 /** 347 * Create a filter that fills the output with the per-pixel evaluation of the SkShader produced 348 * by the SkRuntimeShaderBuilder. The shader is defined in the image filter's local coordinate 349 * system, so it will automatically be affected by SkCanvas' transform. 350 * 351 * @param builder The builder used to produce the runtime shader, that will in turn 352 * fill the result image 353 * @param childShaderNames The names of the child shaders defined in the builder that will be 354 * bound to the input params (or the source image if the input param 355 * is null). If any name is null, or appears more than once, factory 356 * fails and returns nullptr. 357 * @param inputs The image filters that will be provided as input to the runtime 358 * shader. If any are null, the implicit source image is used instead. 359 * @param inputCount How many entries are present in 'childShaderNames' and 'inputs'. 360 */ 361 static sk_sp<SkImageFilter> RuntimeShader(const SkRuntimeShaderBuilder& builder, 362 std::string_view childShaderNames[], 363 const sk_sp<SkImageFilter> inputs[], 364 int inputCount); 365 #endif // SK_ENABLE_SKSL 366 367 enum class Dither : bool { 368 kNo = false, 369 kYes = true 370 }; 371 372 /** 373 * Create a filter that fills the output with the per-pixel evaluation of the SkShader. The 374 * shader is defined in the image filter's local coordinate system, so will automatically 375 * be affected by SkCanvas' transform. 376 * 377 * Like Image() and Picture(), this is a leaf filter that can be used to introduce inputs to 378 * a complex filter graph, but should generally be combined with a filter that as at least 379 * one null input to use the implicit source image. 380 * @param shader The shader that fills the result image 381 */ 382 static sk_sp<SkImageFilter> Shader(sk_sp<SkShader> shader, const CropRect& cropRect = {}) { 383 return Shader(std::move(shader), Dither::kNo, cropRect); 384 } 385 static sk_sp<SkImageFilter> Shader(sk_sp<SkShader> shader, Dither dither, 386 const CropRect& cropRect = {}); 387 388 /** 389 * Create a tile image filter. 390 * @param src Defines the pixels to tile 391 * @param dst Defines the pixel region that the tiles will be drawn to 392 * @param input The input that will be tiled, if null the source bitmap is used instead. 393 */ 394 static sk_sp<SkImageFilter> Tile(const SkRect& src, const SkRect& dst, 395 sk_sp<SkImageFilter> input); 396 397 // Morphology filter effects 398 399 /** 400 * Create a filter that dilates each input pixel's channel values to the max value within the 401 * given radii along the x and y axes. 402 * @param radiusX The distance to dilate along the x axis to either side of each pixel. 403 * @param radiusY The distance to dilate along the y axis to either side of each pixel. 404 * @param input The image filter that is dilated, using source bitmap if this is null. 405 * @param cropRect Optional rectangle that crops the input and output. 406 */ 407 static sk_sp<SkImageFilter> Dilate(SkScalar radiusX, SkScalar radiusY, 408 sk_sp<SkImageFilter> input, 409 const CropRect& cropRect = {}); 410 411 /** 412 * Create a filter that erodes each input pixel's channel values to the minimum channel value 413 * within the given radii along the x and y axes. 414 * @param radiusX The distance to erode along the x axis to either side of each pixel. 415 * @param radiusY The distance to erode along the y axis to either side of each pixel. 416 * @param input The image filter that is eroded, using source bitmap if this is null. 417 * @param cropRect Optional rectangle that crops the input and output. 418 */ 419 static sk_sp<SkImageFilter> Erode(SkScalar radiusX, SkScalar radiusY, 420 sk_sp<SkImageFilter> input, 421 const CropRect& cropRect = {}); 422 423 // Lighting filter effects 424 425 /** 426 * Create a filter that calculates the diffuse illumination from a distant light source, 427 * interpreting the alpha channel of the input as the height profile of the surface (to 428 * approximate normal vectors). 429 * @param direction The direction to the distance light. 430 * @param lightColor The color of the diffuse light source. 431 * @param surfaceScale Scale factor to transform from alpha values to physical height. 432 * @param kd Diffuse reflectance coefficient. 433 * @param input The input filter that defines surface normals (as alpha), or uses the 434 * source bitmap when null. 435 * @param cropRect Optional rectangle that crops the input and output. 436 */ 437 static sk_sp<SkImageFilter> DistantLitDiffuse(const SkPoint3& direction, SkColor lightColor, 438 SkScalar surfaceScale, SkScalar kd, 439 sk_sp<SkImageFilter> input, 440 const CropRect& cropRect = {}); 441 /** 442 * Create a filter that calculates the diffuse illumination from a point light source, using 443 * alpha channel of the input as the height profile of the surface (to approximate normal 444 * vectors). 445 * @param location The location of the point light. 446 * @param lightColor The color of the diffuse light source. 447 * @param surfaceScale Scale factor to transform from alpha values to physical height. 448 * @param kd Diffuse reflectance coefficient. 449 * @param input The input filter that defines surface normals (as alpha), or uses the 450 * source bitmap when null. 451 * @param cropRect Optional rectangle that crops the input and output. 452 */ 453 static sk_sp<SkImageFilter> PointLitDiffuse(const SkPoint3& location, SkColor lightColor, 454 SkScalar surfaceScale, SkScalar kd, 455 sk_sp<SkImageFilter> input, 456 const CropRect& cropRect = {}); 457 /** 458 * Create a filter that calculates the diffuse illumination from a spot light source, using 459 * alpha channel of the input as the height profile of the surface (to approximate normal 460 * vectors). The spot light is restricted to be within 'cutoffAngle' of the vector between 461 * the location and target. 462 * @param location The location of the spot light. 463 * @param target The location that the spot light is point towards 464 * @param falloffExponent Exponential falloff parameter for illumination outside of cutoffAngle 465 * @param cutoffAngle Maximum angle from lighting direction that receives full light 466 * @param lightColor The color of the diffuse light source. 467 * @param surfaceScale Scale factor to transform from alpha values to physical height. 468 * @param kd Diffuse reflectance coefficient. 469 * @param input The input filter that defines surface normals (as alpha), or uses the 470 * source bitmap when null. 471 * @param cropRect Optional rectangle that crops the input and output. 472 */ 473 static sk_sp<SkImageFilter> SpotLitDiffuse(const SkPoint3& location, const SkPoint3& target, 474 SkScalar falloffExponent, SkScalar cutoffAngle, 475 SkColor lightColor, SkScalar surfaceScale, 476 SkScalar kd, sk_sp<SkImageFilter> input, 477 const CropRect& cropRect = {}); 478 479 /** 480 * Create a filter that calculates the specular illumination from a distant light source, 481 * interpreting the alpha channel of the input as the height profile of the surface (to 482 * approximate normal vectors). 483 * @param direction The direction to the distance light. 484 * @param lightColor The color of the specular light source. 485 * @param surfaceScale Scale factor to transform from alpha values to physical height. 486 * @param ks Specular reflectance coefficient. 487 * @param shininess The specular exponent determining how shiny the surface is. 488 * @param input The input filter that defines surface normals (as alpha), or uses the 489 * source bitmap when null. 490 * @param cropRect Optional rectangle that crops the input and output. 491 */ 492 static sk_sp<SkImageFilter> DistantLitSpecular(const SkPoint3& direction, SkColor lightColor, 493 SkScalar surfaceScale, SkScalar ks, 494 SkScalar shininess, sk_sp<SkImageFilter> input, 495 const CropRect& cropRect = {}); 496 /** 497 * Create a filter that calculates the specular illumination from a point light source, using 498 * alpha channel of the input as the height profile of the surface (to approximate normal 499 * vectors). 500 * @param location The location of the point light. 501 * @param lightColor The color of the specular light source. 502 * @param surfaceScale Scale factor to transform from alpha values to physical height. 503 * @param ks Specular reflectance coefficient. 504 * @param shininess The specular exponent determining how shiny the surface is. 505 * @param input The input filter that defines surface normals (as alpha), or uses the 506 * source bitmap when null. 507 * @param cropRect Optional rectangle that crops the input and output. 508 */ 509 static sk_sp<SkImageFilter> PointLitSpecular(const SkPoint3& location, SkColor lightColor, 510 SkScalar surfaceScale, SkScalar ks, 511 SkScalar shininess, sk_sp<SkImageFilter> input, 512 const CropRect& cropRect = {}); 513 /** 514 * Create a filter that calculates the specular illumination from a spot light source, using 515 * alpha channel of the input as the height profile of the surface (to approximate normal 516 * vectors). The spot light is restricted to be within 'cutoffAngle' of the vector between 517 * the location and target. 518 * @param location The location of the spot light. 519 * @param target The location that the spot light is point towards 520 * @param falloffExponent Exponential falloff parameter for illumination outside of cutoffAngle 521 * @param cutoffAngle Maximum angle from lighting direction that receives full light 522 * @param lightColor The color of the specular light source. 523 * @param surfaceScale Scale factor to transform from alpha values to physical height. 524 * @param ks Specular reflectance coefficient. 525 * @param shininess The specular exponent determining how shiny the surface is. 526 * @param input The input filter that defines surface normals (as alpha), or uses the 527 * source bitmap when null. 528 * @param cropRect Optional rectangle that crops the input and output. 529 */ 530 static sk_sp<SkImageFilter> SpotLitSpecular(const SkPoint3& location, const SkPoint3& target, 531 SkScalar falloffExponent, SkScalar cutoffAngle, 532 SkColor lightColor, SkScalar surfaceScale, 533 SkScalar ks, SkScalar shininess, 534 sk_sp<SkImageFilter> input, 535 const CropRect& cropRect = {}); 536 537 private: 538 SkImageFilters() = delete; 539 }; 540 541 #endif // SkImageFilters_DEFINED 542