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