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. 158 * @param cropRect Optional rectangle that crops the color input and output. 159 */ 160 static sk_sp<SkImageFilter> DisplacementMap(SkColorChannel xChannelSelector, 161 SkColorChannel yChannelSelector, 162 SkScalar scale, sk_sp<SkImageFilter> displacement, 163 sk_sp<SkImageFilter> color, 164 const CropRect& cropRect = {}); 165 166 /** 167 * Create a filter that draws a drop shadow under the input content. This filter produces an 168 * image that includes the inputs' content. 169 * @param dx The X offset of the shadow. 170 * @param dy The Y offset of the shadow. 171 * @param sigmaX The blur radius for the shadow, along the X axis. 172 * @param sigmaY The blur radius for the shadow, along the Y axis. 173 * @param color The color of the drop shadow. 174 * @param input The input filter, or will use the source bitmap if this is null. 175 * @param cropRect Optional rectangle that crops the input and output. 176 */ 177 static sk_sp<SkImageFilter> DropShadow(SkScalar dx, SkScalar dy, 178 SkScalar sigmaX, SkScalar sigmaY, 179 SkColor color, sk_sp<SkImageFilter> input, 180 const CropRect& cropRect = {}); 181 /** 182 * Create a filter that renders a drop shadow, in exactly the same manner as ::DropShadow, 183 * except that the resulting image does not include the input content. This allows the shadow 184 * and input to be composed by a filter DAG in a more flexible manner. 185 * @param dx The X offset of the shadow. 186 * @param dy The Y offset of the shadow. 187 * @param sigmaX The blur radius for the shadow, along the X axis. 188 * @param sigmaY The blur radius for the shadow, along the Y axis. 189 * @param color The color of the drop shadow. 190 * @param input The input filter, or will use the source bitmap if this is null. 191 * @param cropRect Optional rectangle that crops the input and output. 192 */ 193 static sk_sp<SkImageFilter> DropShadowOnly(SkScalar dx, SkScalar dy, 194 SkScalar sigmaX, SkScalar sigmaY, 195 SkColor color, sk_sp<SkImageFilter> input, 196 const CropRect& cropRect = {}); 197 198 /** 199 * Create a filter that draws the 'srcRect' portion of image into 'dstRect' using the given 200 * filter quality. Similar to SkCanvas::drawImageRect. Returns null if 'image' is null. 201 * @param image The image that is output by the filter, subset by 'srcRect'. 202 * @param srcRect The source pixels sampled into 'dstRect' 203 * @param dstRect The local rectangle to draw the image into. 204 * @param sampling The sampling to use when drawing the image. 205 */ 206 static sk_sp<SkImageFilter> Image(sk_sp<SkImage> image, const SkRect& srcRect, 207 const SkRect& dstRect, const SkSamplingOptions& sampling); 208 209 /** 210 * Create a filter that draws the image using the given sampling. 211 * Similar to SkCanvas::drawImage. Returns null if 'image' is null. 212 * @param image The image that is output by the filter. 213 * @param sampling The sampling to use when drawing the image. 214 */ Image(sk_sp<SkImage> image,const SkSamplingOptions & sampling)215 static sk_sp<SkImageFilter> Image(sk_sp<SkImage> image, const SkSamplingOptions& sampling) { 216 if (image) { 217 SkRect r = SkRect::Make(image->bounds()); 218 return Image(std::move(image), r, r, sampling); 219 } else { 220 return nullptr; 221 } 222 } 223 224 /** 225 * Create a filter that draws the image using Mitchel cubic resampling. 226 * @param image The image that is output by the filter. 227 */ Image(sk_sp<SkImage> image)228 static sk_sp<SkImageFilter> Image(sk_sp<SkImage> image) { 229 return Image(std::move(image), SkSamplingOptions({1/3.0f, 1/3.0f})); 230 } 231 232 /** 233 * Create a filter that mimics a zoom/magnifying lens effect. 234 * @param srcRect 235 * @param inset 236 * @param input The input filter that is magnified, if null the source bitmap is used. 237 * @param cropRect Optional rectangle that crops the input and output. 238 */ 239 static sk_sp<SkImageFilter> Magnifier(const SkRect& srcRect, SkScalar inset, 240 sk_sp<SkImageFilter> input, 241 const CropRect& cropRect = {}); 242 243 /** 244 * Create a filter that applies an NxM image processing kernel to the input image. This can be 245 * used to produce effects such as sharpening, blurring, edge detection, etc. 246 * @param kernelSize The kernel size in pixels, in each dimension (N by M). 247 * @param kernel The image processing kernel. Must contain N * M elements, in row order. 248 * @param gain A scale factor applied to each pixel after convolution. This can be 249 * used to normalize the kernel, if it does not already sum to 1. 250 * @param bias A bias factor added to each pixel after convolution. 251 * @param kernelOffset An offset applied to each pixel coordinate before convolution. 252 * This can be used to center the kernel over the image 253 * (e.g., a 3x3 kernel should have an offset of {1, 1}). 254 * @param tileMode How accesses outside the image are treated. 255 * TODO (michaelludwig) - kMirror is not supported yet 256 * @param convolveAlpha If true, all channels are convolved. If false, only the RGB channels 257 * are convolved, and alpha is copied from the source image. 258 * @param input The input image filter, if null the source bitmap is used instead. 259 * @param cropRect Optional rectangle to which the output processing will be limited. 260 */ 261 static sk_sp<SkImageFilter> MatrixConvolution(const SkISize& kernelSize, 262 const SkScalar kernel[], SkScalar gain, 263 SkScalar bias, const SkIPoint& kernelOffset, 264 SkTileMode tileMode, bool convolveAlpha, 265 sk_sp<SkImageFilter> input, 266 const CropRect& cropRect = {}); 267 268 /** 269 * Create a filter that transforms the input image by 'matrix'. This matrix transforms the 270 * local space, which means it effectively happens prior to any transformation coming from the 271 * SkCanvas initiating the filtering. 272 * @param matrix The matrix to apply to the original content. 273 * @param sampling How the image will be sampled when it is transformed 274 * @param input The image filter to transform, or null to use the source image. 275 */ 276 static sk_sp<SkImageFilter> MatrixTransform(const SkMatrix& matrix, 277 const SkSamplingOptions& sampling, 278 sk_sp<SkImageFilter> input); 279 280 /** 281 * Create a filter that merges the 'count' filters together by drawing their results in order 282 * with src-over blending. 283 * @param filters The input filter array to merge, which must have 'count' elements. Any null 284 * filter pointers will use the source bitmap instead. 285 * @param count The number of input filters to be merged. 286 * @param cropRect Optional rectangle that crops all input filters and the output. 287 */ 288 static sk_sp<SkImageFilter> Merge(sk_sp<SkImageFilter>* const filters, int count, 289 const CropRect& cropRect = {}); 290 /** 291 * Create a filter that merges the results of the two filters together with src-over blending. 292 * @param first The first input filter, or the source bitmap if this is null. 293 * @param second The second input filter, or the source bitmap if this null. 294 * @param cropRect Optional rectangle that crops the inputs and output. 295 */ 296 static sk_sp<SkImageFilter> Merge(sk_sp<SkImageFilter> first, sk_sp<SkImageFilter> second, 297 const CropRect& cropRect = {}) { 298 sk_sp<SkImageFilter> array[] = { std::move(first), std::move(second) }; 299 return Merge(array, 2, cropRect); 300 } 301 302 /** 303 * Create a filter that offsets the input filter by the given vector. 304 * @param dx The x offset in local space that the image is shifted. 305 * @param dy The y offset in local space that the image is shifted. 306 * @param input The input that will be moved, if null the source bitmap is used instead. 307 * @param cropRect Optional rectangle to crop the input and output. 308 */ 309 static sk_sp<SkImageFilter> Offset(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input, 310 const CropRect& cropRect = {}); 311 312 /** 313 * Create a filter that fills the output with the given paint. 314 * @param paint The paint to fill 315 * @param cropRect Optional rectangle that will be filled. If null, the source bitmap's bounds 316 * are filled even though the source bitmap itself is not used. 317 * 318 * DEPRECATED: Use Shader() instead, since many features of SkPaint are ignored when filling 319 * the target output, and paint color/alpha can be emulated with SkShaders::Color(). 320 */ 321 static sk_sp<SkImageFilter> Paint(const SkPaint& paint, const CropRect& cropRect = {}); 322 323 /** 324 * Create a filter that produces the SkPicture as its output, drawn into targetRect. Note that 325 * the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns 326 * null if 'pic' is null. 327 * @param pic The picture that is drawn for the filter output. 328 * @param targetRect The drawing region for the picture. 329 */ 330 static sk_sp<SkImageFilter> Picture(sk_sp<SkPicture> pic, const SkRect& targetRect); 331 // As above, but uses SkPicture::cullRect for the drawing region. Picture(sk_sp<SkPicture> pic)332 static sk_sp<SkImageFilter> Picture(sk_sp<SkPicture> pic) { 333 SkRect target = pic ? pic->cullRect() : SkRect::MakeEmpty(); 334 return Picture(std::move(pic), target); 335 } 336 337 #ifdef SK_ENABLE_SKSL 338 /** 339 * Create a filter that fills the output with the per-pixel evaluation of the SkShader produced 340 * by the SkRuntimeShaderBuilder. The shader is defined in the image filter's local coordinate 341 * system, so it will automatically be affected by SkCanvas' transform. 342 * 343 * @param builder The builder used to produce the runtime shader, that will in turn 344 * fill the result image 345 * @param childShaderName The name of the child shader defined in the builder that will be 346 * bound to the input param (or the source image if the input param 347 * is null). If null the builder can have exactly one child shader, 348 * which automatically binds the input param. 349 * @param input The image filter that will be provided as input to the runtime 350 * shader. If null the implicit source image is used instead 351 */ 352 static sk_sp<SkImageFilter> RuntimeShader(const SkRuntimeShaderBuilder& builder, 353 const char* childShaderName, 354 sk_sp<SkImageFilter> input); 355 356 /** 357 * Create a filter that fills the output with the per-pixel evaluation of the SkShader produced 358 * by the SkRuntimeShaderBuilder. The shader is defined in the image filter's local coordinate 359 * system, so it will automatically be affected by SkCanvas' transform. 360 * 361 * @param builder The builder used to produce the runtime shader, that will in turn 362 * fill the result image 363 * @param childShaderNames The names of the child shaders defined in the builder that will be 364 * bound to the input params (or the source image if the input param 365 * is null). If any name is null, or appears more than once, factory 366 * fails and returns nullptr. 367 * @param inputs The image filters that will be provided as input to the runtime 368 * shader. If any are null, the implicit source image is used instead. 369 * @param inputCount How many entries are present in 'childShaderNames' and 'inputs'. 370 */ 371 static sk_sp<SkImageFilter> RuntimeShader(const SkRuntimeShaderBuilder& builder, 372 const char* childShaderNames[], 373 const sk_sp<SkImageFilter> inputs[], 374 int inputCount); 375 #endif // SK_ENABLE_SKSL 376 377 enum class Dither : bool { 378 kNo = false, 379 kYes = true 380 }; 381 382 /** 383 * Create a filter that fills the output with the per-pixel evaluation of the SkShader. The 384 * shader is defined in the image filter's local coordinate system, so will automatically 385 * be affected by SkCanvas' transform. 386 * 387 * Like Image() and Picture(), this is a leaf filter that can be used to introduce inputs to 388 * a complex filter graph, but should generally be combined with a filter that as at least 389 * one null input to use the implicit source image. 390 * @param shader The shader that fills the result image 391 */ 392 static sk_sp<SkImageFilter> Shader(sk_sp<SkShader> shader, const CropRect& cropRect = {}) { 393 return Shader(std::move(shader), Dither::kNo, cropRect); 394 } 395 static sk_sp<SkImageFilter> Shader(sk_sp<SkShader> shader, Dither dither, 396 const CropRect& cropRect = {}); 397 398 /** 399 * Create a tile image filter. 400 * @param src Defines the pixels to tile 401 * @param dst Defines the pixel region that the tiles will be drawn to 402 * @param input The input that will be tiled, if null the source bitmap is used instead. 403 */ 404 static sk_sp<SkImageFilter> Tile(const SkRect& src, const SkRect& dst, 405 sk_sp<SkImageFilter> input); 406 407 // Morphology filter effects 408 409 /** 410 * Create a filter that dilates each input pixel's channel values to the max value within the 411 * given radii along the x and y axes. 412 * @param radiusX The distance to dilate along the x axis to either side of each pixel. 413 * @param radiusY The distance to dilate along the y axis to either side of each pixel. 414 * @param input The image filter that is dilated, using source bitmap if this is null. 415 * @param cropRect Optional rectangle that crops the input and output. 416 */ 417 static sk_sp<SkImageFilter> Dilate(SkScalar radiusX, SkScalar radiusY, 418 sk_sp<SkImageFilter> input, 419 const CropRect& cropRect = {}); 420 421 /** 422 * Create a filter that erodes each input pixel's channel values to the minimum channel value 423 * within the given radii along the x and y axes. 424 * @param radiusX The distance to erode along the x axis to either side of each pixel. 425 * @param radiusY The distance to erode along the y axis to either side of each pixel. 426 * @param input The image filter that is eroded, using source bitmap if this is null. 427 * @param cropRect Optional rectangle that crops the input and output. 428 */ 429 static sk_sp<SkImageFilter> Erode(SkScalar radiusX, SkScalar radiusY, 430 sk_sp<SkImageFilter> input, 431 const CropRect& cropRect = {}); 432 433 // Lighting filter effects 434 435 /** 436 * Create a filter that calculates the diffuse illumination from a distant light source, 437 * interpreting the alpha channel of the input as the height profile of the surface (to 438 * approximate normal vectors). 439 * @param direction The direction to the distance light. 440 * @param lightColor The color of the diffuse light source. 441 * @param surfaceScale Scale factor to transform from alpha values to physical height. 442 * @param kd Diffuse reflectance coefficient. 443 * @param input The input filter that defines surface normals (as alpha), or uses the 444 * source bitmap when null. 445 * @param cropRect Optional rectangle that crops the input and output. 446 */ 447 static sk_sp<SkImageFilter> DistantLitDiffuse(const SkPoint3& direction, SkColor lightColor, 448 SkScalar surfaceScale, SkScalar kd, 449 sk_sp<SkImageFilter> input, 450 const CropRect& cropRect = {}); 451 /** 452 * Create a filter that calculates the diffuse illumination from a point light source, using 453 * alpha channel of the input as the height profile of the surface (to approximate normal 454 * vectors). 455 * @param location The location of the point light. 456 * @param lightColor The color of the diffuse light source. 457 * @param surfaceScale Scale factor to transform from alpha values to physical height. 458 * @param kd Diffuse reflectance coefficient. 459 * @param input The input filter that defines surface normals (as alpha), or uses the 460 * source bitmap when null. 461 * @param cropRect Optional rectangle that crops the input and output. 462 */ 463 static sk_sp<SkImageFilter> PointLitDiffuse(const SkPoint3& location, SkColor lightColor, 464 SkScalar surfaceScale, SkScalar kd, 465 sk_sp<SkImageFilter> input, 466 const CropRect& cropRect = {}); 467 /** 468 * Create a filter that calculates the diffuse illumination from a spot light source, using 469 * alpha channel of the input as the height profile of the surface (to approximate normal 470 * vectors). The spot light is restricted to be within 'cutoffAngle' of the vector between 471 * the location and target. 472 * @param location The location of the spot light. 473 * @param target The location that the spot light is point towards 474 * @param falloffExponent Exponential falloff parameter for illumination outside of cutoffAngle 475 * @param cutoffAngle Maximum angle from lighting direction that receives full light 476 * @param lightColor The color of the diffuse light source. 477 * @param surfaceScale Scale factor to transform from alpha values to physical height. 478 * @param kd Diffuse reflectance coefficient. 479 * @param input The input filter that defines surface normals (as alpha), or uses the 480 * source bitmap when null. 481 * @param cropRect Optional rectangle that crops the input and output. 482 */ 483 static sk_sp<SkImageFilter> SpotLitDiffuse(const SkPoint3& location, const SkPoint3& target, 484 SkScalar falloffExponent, SkScalar cutoffAngle, 485 SkColor lightColor, SkScalar surfaceScale, 486 SkScalar kd, sk_sp<SkImageFilter> input, 487 const CropRect& cropRect = {}); 488 489 /** 490 * Create a filter that calculates the specular illumination from a distant light source, 491 * interpreting the alpha channel of the input as the height profile of the surface (to 492 * approximate normal vectors). 493 * @param direction The direction to the distance light. 494 * @param lightColor The color of the specular light source. 495 * @param surfaceScale Scale factor to transform from alpha values to physical height. 496 * @param ks Specular reflectance coefficient. 497 * @param shininess The specular exponent determining how shiny the surface is. 498 * @param input The input filter that defines surface normals (as alpha), or uses the 499 * source bitmap when null. 500 * @param cropRect Optional rectangle that crops the input and output. 501 */ 502 static sk_sp<SkImageFilter> DistantLitSpecular(const SkPoint3& direction, SkColor lightColor, 503 SkScalar surfaceScale, SkScalar ks, 504 SkScalar shininess, sk_sp<SkImageFilter> input, 505 const CropRect& cropRect = {}); 506 /** 507 * Create a filter that calculates the specular illumination from a point light source, using 508 * alpha channel of the input as the height profile of the surface (to approximate normal 509 * vectors). 510 * @param location The location of the point light. 511 * @param lightColor The color of the specular light source. 512 * @param surfaceScale Scale factor to transform from alpha values to physical height. 513 * @param ks Specular reflectance coefficient. 514 * @param shininess The specular exponent determining how shiny the surface is. 515 * @param input The input filter that defines surface normals (as alpha), or uses the 516 * source bitmap when null. 517 * @param cropRect Optional rectangle that crops the input and output. 518 */ 519 static sk_sp<SkImageFilter> PointLitSpecular(const SkPoint3& location, SkColor lightColor, 520 SkScalar surfaceScale, SkScalar ks, 521 SkScalar shininess, sk_sp<SkImageFilter> input, 522 const CropRect& cropRect = {}); 523 /** 524 * Create a filter that calculates the specular illumination from a spot light source, using 525 * alpha channel of the input as the height profile of the surface (to approximate normal 526 * vectors). The spot light is restricted to be within 'cutoffAngle' of the vector between 527 * the location and target. 528 * @param location The location of the spot light. 529 * @param target The location that the spot light is point towards 530 * @param falloffExponent Exponential falloff parameter for illumination outside of cutoffAngle 531 * @param cutoffAngle Maximum angle from lighting direction that receives full light 532 * @param lightColor The color of the specular light source. 533 * @param surfaceScale Scale factor to transform from alpha values to physical height. 534 * @param ks Specular reflectance coefficient. 535 * @param shininess The specular exponent determining how shiny the surface is. 536 * @param input The input filter that defines surface normals (as alpha), or uses the 537 * source bitmap when null. 538 * @param cropRect Optional rectangle that crops the input and output. 539 */ 540 static sk_sp<SkImageFilter> SpotLitSpecular(const SkPoint3& location, const SkPoint3& target, 541 SkScalar falloffExponent, SkScalar cutoffAngle, 542 SkColor lightColor, SkScalar surfaceScale, 543 SkScalar ks, SkScalar shininess, 544 sk_sp<SkImageFilter> input, 545 const CropRect& cropRect = {}); 546 547 private: 548 SkImageFilters() = delete; 549 }; 550 551 #endif // SkImageFilters_DEFINED 552