Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
SkEmbossMask Class Reference

#include <SkEmbossMask.h>

Static Public Member Functions

static void Emboss (SkMaskBuilder *mask, const SkEmbossMaskFilter::Light &)
 

Detailed Description

Definition at line 16 of file SkEmbossMask.h.

Member Function Documentation

◆ Emboss()

void SkEmbossMask::Emboss ( SkMaskBuilder mask,
const SkEmbossMaskFilter::Light light 
)
static

Definition at line 55 of file SkEmbossMask.cpp.

55 {
57
58 int specular = light.fSpecular;
59 int ambient = light.fAmbient;
60 SkFixed lx = SkScalarToFixed(light.fDirection[0]);
61 SkFixed ly = SkScalarToFixed(light.fDirection[1]);
62 SkFixed lz = SkScalarToFixed(light.fDirection[2]);
63 SkFixed lz_dot_nz = lz * kDelta;
64 int lz_dot8 = lz >> 8;
65
66 size_t planeSize = mask->computeImageSize();
67 uint8_t* alpha = mask->image();
68 uint8_t* multiply = (uint8_t*)alpha + planeSize;
69 uint8_t* additive = multiply + planeSize;
70
71 int rowBytes = mask->fRowBytes;
72 int maxy = mask->fBounds.height() - 1;
73 int maxx = mask->fBounds.width() - 1;
74
75 int prev_row = 0;
76 for (int y = 0; y <= maxy; y++) {
77 int next_row = neq_to_mask(y, maxy) & rowBytes;
78
79 for (int x = 0; x <= maxx; x++) {
80 int nx = alpha[x + neq_to_one(x, maxx)] - alpha[x - nonzero_to_one(x)];
81 int ny = alpha[x + next_row] - alpha[x - prev_row];
82
83 SkFixed numer = lx * nx + ly * ny + lz_dot_nz;
84 int mul = ambient;
85 int add = 0;
86
87 if (numer > 0) { // preflight when numer/denom will be <= 0
88 int denom = SkSqrt32(nx * nx + ny * ny + kDelta*kDelta);
89 SkFixed dot = numer / denom;
90 dot >>= 8; // now dot is 2^8 instead of 2^16
91 mul = std::min(mul + dot, 255);
92
93 // now for the reflection
94
95 // R = 2 (Light * Normal) Normal - Light
96 // hilite = R * Eye(0, 0, 1)
97
98 int hilite = (2 * dot - lz_dot8) * lz_dot8 >> 8;
99 if (hilite > 0) {
100 // pin hilite to 255, since our fast math is also a little sloppy
101 hilite = std::min(hilite, 255);
102
103 // specular is 4.4
104 // would really like to compute the fractional part of this
105 // and then possibly cache a 256 table for a given specular
106 // value in the light, and just pass that in to this function.
107 add = hilite;
108 for (int i = specular >> 4; i > 0; --i) {
109 add = div255(add * hilite);
110 }
111 }
112 }
113 multiply[x] = SkToU8(mul);
114 additive[x] = SkToU8(add);
115 }
116 alpha += rowBytes;
117 multiply += rowBytes;
118 additive += rowBytes;
119 prev_row = rowBytes;
120 }
121}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int neq_to_one(int x, int max)
static int nonzero_to_one(int x)
static int neq_to_mask(int x, int max)
static unsigned div255(unsigned x)
#define kDelta
int32_t SkFixed
Definition: SkFixed.h:25
#define SkScalarToFixed(x)
Definition: SkFixed.h:125
static int32_t SkSqrt32(int32_t n)
Definition: SkMathPriv.h:25
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
Int96 multiply(int64_t a, int32_t b)
Definition: Int96.cpp:41
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
Definition: SkVx.h:964
static void next_row(SkCanvas *canvas)
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
uint8_t *& image()
Definition: SkMask.h:236
const uint32_t fRowBytes
Definition: SkMask.h:43
@ k3D_Format
3 8bit per pixl planes: alpha, mul, add
Definition: SkMask.h:29
const SkIRect fBounds
Definition: SkMask.h:42
size_t computeImageSize() const
Definition: SkMask.cpp:30
const Format fFormat
Definition: SkMask.h:44

The documentation for this class was generated from the following files: