Debian Codegraph @

src/effects/SkEmbossMaskFilter.h

raw
1 /*
2 * Copyright 2006 The Android Open Source Project
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 SkEmbossMaskFilter_DEFINED
9 #define SkEmbossMaskFilter_DEFINED
10
11 #include "include/core/SkColor.h"
12 #include "include/core/SkFlattenable.h"
13 #include "include/core/SkMaskFilter.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkScalar.h"
16 #include "src/core/SkMask.h"
17 #include "src/core/SkMaskFilterBase.h"
18
19 #include <cstdint>
20 #include <utility>
21
22 class SkImageFilter;
23 class SkMatrix;
24 class SkPaint;
25 class SkReadBuffer;
26 class SkWriteBuffer;
27 struct SkIPoint;
28 struct SkPoint3;
29
30 /** \class SkEmbossMaskFilter
31
32 This mask filter creates a 3D emboss look, by specifying a light and blur amount.
33 */
34 class SkEmbossMaskFilter : public SkMaskFilterBase {
35 public:
36 struct Light {
37 SkScalar fDirection[3]; // x,y,z
38 uint16_t fPad;
39 uint8_t fAmbient;
40 uint8_t fSpecular; // exponent, 4.4 right now
41 };
42
43 static sk_sp<SkMaskFilter> Make(SkScalar blurSigma, const Light& light);
44
45 // overrides from SkMaskFilter
46 // This method is not exported to java.
47 SkMask::Format getFormat() const override;
48 // This method is not exported to java.
49 bool filterMask(SkMaskBuilder* dst, const SkMask& src, const SkMatrix&,
50 SkIPoint* margin) const override;
51 SkMaskFilterBase::Type type() const override { return SkMaskFilterBase::Type::kEmboss; }
52 std::pair<sk_sp<SkImageFilter>, bool> asImageFilter(const SkMatrix& ctm,
53 const SkPaint& paint) const override;
54
55 protected:
56 SkEmbossMaskFilter(SkScalar blurSigma, const Light& light);
57 void flatten(SkWriteBuffer&) const override;
58
59 private:
60 SK_FLATTENABLE_HOOKS(SkEmbossMaskFilter)
61
62 /**
63 * Create a filter that calculates the specular illumination from a distant light source,
64 * interpreting the alpha channel of the input as the height profile of the surface (to
65 * approximate normal vectors). This is based on the legacy raster implementation of the
66 * emboss mask filter for clients that still use it.
67 * @param direction The direction to the distance light.
68 * @param lightColor The color of the specular light source.
69 * @param surfaceScale Scale factor to transform from alpha values to physical height.
70 * @param ks Specular reflectance coefficient.
71 * @param shininess The specular exponent determining how shiny the surface is.
72 * @param input The input filter that defines surface normals (as alpha), or uses the
73 * source bitmap when null.
74 * @param cropRect Optional rectangle that crops the input and output.
75 *
76 * Defined in SkLightingImageFilter.cpp because it overlaps heavily with
77 * SkImageFilters::DistantLitSpecular and that family of functions.
78 */
79 static sk_sp<SkImageFilter> LegacySpecular(const SkPoint3& direction, SkColor lightColor,
80 SkScalar surfaceScale, SkScalar ks,
81 SkScalar shininess, sk_sp<SkImageFilter> input);
82
83 Light fLight;
84 SkScalar fBlurSigma;
85
86 using INHERITED = SkMaskFilter;
87 };
88
89 #endif