| OLD | NEW |
| 1 filename = "" | 1 filename = "" |
| 2 | 2 |
| 3 function sk_scrape_startcanvas(c, fileName) | 3 function sk_scrape_startcanvas(c, fileName) |
| 4 filename = fileName | 4 filename = fileName |
| 5 end | 5 end |
| 6 | 6 |
| 7 function sk_scrape_endcanvas(c, fileName) | 7 function sk_scrape_endcanvas(c, fileName) |
| 8 | 8 |
| 9 end | 9 end |
| 10 | 10 |
| 11 LuaDoubleNearlyZero = 1.0 / bit32.lshift(1.0, 12) | 11 LuaDoubleNearlyZero = 1.0 / bit32.lshift(1.0, 12) |
| 12 | 12 |
| 13 function LuaDoubleNearlyEqual(a, b) | 13 function LuaDoubleNearlyEqual(a, b) |
| 14 return math.abs(a-b) <= LuaDoubleNearlyZero | 14 return math.abs(a-b) <= LuaDoubleNearlyZero |
| 15 end | 15 end |
| 16 | 16 |
| 17 verbs = {} | 17 function bounds(rect) |
| 18 local width = rect.right - rect.left |
| 19 local height = rect.bottom - rect.top |
| 20 |
| 21 return width, height |
| 22 end |
| 23 |
| 18 gradients = {} | 24 gradients = {} |
| 19 | 25 |
| 20 i = 1 | 26 i = 1 |
| 21 | 27 |
| 22 function sk_scrape_accumulate(t) | 28 function sk_scrape_accumulate(t) |
| 23 local p = t.paint | 29 local p = t.paint |
| 24 if p then | 30 if p then |
| 25 local s = p:getShader() | 31 local s = p:getShader() |
| 26 if s then | 32 if s then |
| 27 local g = s:asAGradient() | 33 local g = s:asAGradient() |
| 28 if g then | 34 if g then |
| 29 if verbs[t.verb] then | |
| 30 verbs[t.verb] = verbs[t.verb] + 1 | |
| 31 else | |
| 32 verbs[t.verb] = 1 | |
| 33 end | |
| 34 | |
| 35 gradients[i] = {} | 35 gradients[i] = {} |
| 36 | 36 |
| 37 gradients[i].filename = filename | 37 gradients[i].filename = filename |
| 38 | 38 |
| 39 local width, height = -1, -1 |
| 40 if t.rect then |
| 41 width, height = bounds(t.rect) |
| 42 elseif t.rrect then |
| 43 width, height = bounds(t.rrect:rect()) |
| 44 elseif t.path then |
| 45 width, height = bounds(t.path:getBounds()) |
| 46 end |
| 47 gradients[i].boundsWidth = width |
| 48 gradients[i].boundsHeight = height |
| 49 |
| 39 gradients[i].colorCount = g.colorCount | 50 gradients[i].colorCount = g.colorCount |
| 40 gradients[i].type = g.type | 51 gradients[i].type = g.type |
| 41 gradients[i].tile = g.tile | 52 gradients[i].tile = g.tile |
| 42 | 53 |
| 43 isEvenlySpaced = true | 54 isEvenlySpaced = true |
| 44 for j = 1, g.colorCount, 1 do | 55 for j = 1, g.colorCount, 1 do |
| 45 if not LuaDoubleNearlyEqual(g.positions[j], (j-1)/(g.colorCo
unt-1)) then | 56 if not LuaDoubleNearlyEqual(g.positions[j], (j-1)/(g.colorCo
unt-1)) then |
| 46 isEvenlySpaced = false | 57 isEvenlySpaced = false |
| 47 end | 58 end |
| 48 end | 59 end |
| (...skipping 23 matching lines...) Expand all Loading... |
| 72 function sk_scrape_summarize() | 83 function sk_scrape_summarize() |
| 73 for k, v in pairs(gradients) do | 84 for k, v in pairs(gradients) do |
| 74 local pos = "" | 85 local pos = "" |
| 75 for j = 1, v.colorCount , 1 do | 86 for j = 1, v.colorCount , 1 do |
| 76 pos = pos .. v.positions[j] | 87 pos = pos .. v.positions[j] |
| 77 if j ~= v.colorCount then | 88 if j ~= v.colorCount then |
| 78 pos = pos .. "," | 89 pos = pos .. "," |
| 79 end | 90 end |
| 80 end | 91 end |
| 81 | 92 |
| 82 io.write(string.format("%s %d %s %s %d %d %s %s\n", | 93 io.write(string.format("%s %d %s %s %d %d %s %d %d %s\n", |
| 83 v.filename, | 94 v.filename, |
| 84 v.colorCount, | 95 v.colorCount, |
| 85 v.type, | 96 v.type, |
| 86 v.tile, | 97 v.tile, |
| 87 tonumber(v.isEvenlySpaced and 1 or 0), | 98 tonumber(v.isEvenlySpaced and 1 or 0), |
| 88 v.numHardStops, | 99 v.numHardStops, |
| 89 v.verb, | 100 v.verb, |
| 101 v.boundsWidth, |
| 102 v.boundsHeight, |
| 90 pos)) | 103 pos)) |
| 91 end | 104 end |
| 92 end | 105 end |
| 93 | 106 |
| OLD | NEW |