OLD | NEW |
1 function sk_scrape_startcanvas(c, fileName) end | 1 function sk_scrape_startcanvas(c, fileName) end |
2 function sk_scrape_endcanvas(c, fileName) end | 2 function sk_scrape_endcanvas(c, fileName) end |
3 | 3 |
4 SkScalarNearlyZero = 1.0 / bit32.lshift(1.0, 12) | 4 LuaDoubleNearlyZero = 1.0 / bit32.lshift(1.0, 12) |
5 | 5 |
6 function SkScalarNearlyEqual(a, b) | 6 function LuaDoubleNearlyEqual(a, b) |
7 return math.abs(a,b) <= SkScalarNearlyZero | 7 return math.abs(a-b) <= LuaDoubleNearlyZero |
8 end | 8 end |
9 | 9 |
10 gradients = {} | 10 gradients = {} |
11 | 11 |
12 i = 1 | 12 i = 1 |
13 | 13 |
14 function sk_scrape_accumulate(t) | 14 function sk_scrape_accumulate(t) |
15 local p = t.paint | 15 local p = t.paint |
16 if p then | 16 if p then |
17 local s = p:getShader() | 17 local s = p:getShader() |
18 if s then | 18 if s then |
19 local g = s:asAGradient() | 19 local g = s:asAGradient() |
20 if g then | 20 if g then |
21 gradients[i] = {} | 21 gradients[i] = {} |
22 | 22 |
23 gradients[i].colorCount = g.colorCount | 23 gradients[i].colorCount = g.colorCount |
24 gradients[i].type = g.type | 24 gradients[i].type = g.type |
25 gradients[i].tile = g.tile | 25 gradients[i].tile = g.tile |
26 | 26 |
27 numHardStops = 0 | |
28 isEvenlySpaced = true | 27 isEvenlySpaced = true |
29 for j = 2, g.colorCount, 1 do | 28 for j = 1, g.colorCount, 1 do |
30 if not SkScalarNearlyEqual(g.positions[j], j/(g.colorCount-1
)) then | 29 if not LuaDoubleNearlyEqual(g.positions[j], (j-1)/(g.colorCo
unt-1)) then |
31 isEvenlySpaced = false | 30 isEvenlySpaced = false |
32 end | 31 end |
| 32 end |
| 33 gradients[i].isEvenlySpaced = isEvenlySpaced |
33 | 34 |
34 if SkScalarNearlyEqual(g.positions[j], g.positions[j-1]) the
n | 35 numHardStops = 0 |
| 36 for j = 2, g.colorCount, 1 do |
| 37 if LuaDoubleNearlyEqual(g.positions[j], g.positions[j-1]) th
en |
35 numHardStops = numHardStops + 1 | 38 numHardStops = numHardStops + 1 |
36 end | 39 end |
37 end | 40 end |
38 | 41 gradients[i].numHardStops = numHardStops; |
39 gradients[i].isEvenlySpaced = isEvenlySpaced | |
40 gradients[i].numHardStops = numHardStops; | |
41 | 42 |
42 gradients[i].positions = {} | 43 gradients[i].positions = {} |
43 for j = 1, g.colorCount, 1 do | 44 for j = 1, g.colorCount, 1 do |
44 gradients[i].positions[j] = g.positions[j] | 45 gradients[i].positions[j] = g.positions[j] |
45 end | 46 end |
46 | 47 |
47 i = i + 1 | 48 i = i + 1 |
48 end | 49 end |
49 end | 50 end |
50 end | 51 end |
(...skipping 12 matching lines...) Expand all Loading... |
63 io.write(string.format("%d %s %s %d %d %s\n", | 64 io.write(string.format("%d %s %s %d %d %s\n", |
64 v.colorCount, | 65 v.colorCount, |
65 v.type, | 66 v.type, |
66 v.tile, | 67 v.tile, |
67 tonumber(v.isEvenlySpaced and 1 or 0), | 68 tonumber(v.isEvenlySpaced and 1 or 0), |
68 v.numHardStops, | 69 v.numHardStops, |
69 pos)) | 70 pos)) |
70 end | 71 end |
71 end | 72 end |
72 | 73 |
OLD | NEW |