Chromium Code Reviews| 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) | |
|
reed1
2016/07/12 15:44:46
since lua just has doubles, I don't think it helps
| |
| 5 | |
| 6 function SkScalarNearlyEqual(a, b) | |
| 7 return math.abs(a,b) <= SkScalarNearlyZero | |
| 8 end | |
| 9 | |
| 4 gradients = {} | 10 gradients = {} |
| 5 | 11 |
| 6 i = 1 | 12 i = 1 |
| 7 | 13 |
| 8 function sk_scrape_accumulate(t) | 14 function sk_scrape_accumulate(t) |
| 9 local p = t.paint | 15 local p = t.paint |
| 10 if p then | 16 if p then |
| 11 local s = p:getShader() | 17 local s = p:getShader() |
| 12 if s then | 18 if s then |
| 13 local g = s:asAGradient() | 19 local g = s:asAGradient() |
| 14 if g then | 20 if g then |
| 15 gradients[i] = {} | 21 gradients[i] = {} |
| 16 gradients[i].colorCount = g.colorCount | 22 |
| 17 gradients[i].type = g.type | 23 gradients[i].colorCount = g.colorCount |
| 18 gradients[i].tile = g.tile | 24 gradients[i].type = g.type |
| 19 gradients[i].isEvenlySpaced = g.isEvenlySpaced | 25 gradients[i].tile = g.tile |
| 20 gradients[i].containsHardStops = g.containsHardStops | 26 |
| 27 numHardStops = 0 | |
| 28 isEvenlySpaced = true | |
| 29 for j = 2, g.colorCount, 1 do | |
| 30 if not SkScalarNearlyEqual(g.positions[j], j/(g.colorCount-1 )) then | |
| 31 isEvenlySpaced = false | |
| 32 end | |
| 33 | |
| 34 if SkScalarNearlyEqual(g.positions[j], g.positions[j-1]) the n | |
| 35 numHardStops = numHardStops + 1 | |
| 36 end | |
| 37 end | |
| 38 | |
| 39 gradients[i].isEvenlySpaced = isEvenlySpaced | |
| 40 gradients[i].numHardStops = numHardStops; | |
| 21 | 41 |
| 22 gradients[i].positions = {} | 42 gradients[i].positions = {} |
| 23 for j = 1, g.colorCount, 1 do | 43 for j = 1, g.colorCount, 1 do |
| 24 gradients[i].positions[j] = g.positions[j] | 44 gradients[i].positions[j] = g.positions[j] |
| 25 end | 45 end |
| 26 | 46 |
| 27 i = i + 1 | 47 i = i + 1 |
| 28 end | 48 end |
| 29 end | 49 end |
| 30 end | 50 end |
| 31 end | 51 end |
| 32 | 52 |
| 33 function sk_scrape_summarize() | 53 function sk_scrape_summarize() |
| 34 for k, v in pairs(gradients) do | 54 for k, v in pairs(gradients) do |
| 35 local pos = "" | 55 local pos = "" |
| 36 for j = 1, v.colorCount , 1 do | 56 for j = 1, v.colorCount , 1 do |
| 37 pos = pos .. v.positions[j] | 57 pos = pos .. v.positions[j] |
| 38 if j ~= v.colorCount then | 58 if j ~= v.colorCount then |
| 39 pos = pos .. "," | 59 pos = pos .. "," |
| 40 end | 60 end |
| 41 end | 61 end |
| 42 | 62 |
| 43 io.write(string.format("%d %s %s %d %d %s\n", | 63 io.write(string.format("%d %s %s %d %d %s\n", |
| 44 v.colorCount, | 64 v.colorCount, |
| 45 v.type, | 65 v.type, |
| 46 v.tile, | 66 v.tile, |
| 47 tonumber(v.isEvenlySpaced and 1 or 0), | 67 tonumber(v.isEvenlySpaced and 1 or 0), |
| 48 tonumber(v.containsHardStops and 1 or 0), | 68 v.numHardStops, |
| 49 pos)) | 69 pos)) |
| 50 end | 70 end |
| 51 end | 71 end |
| 52 | 72 |
| OLD | NEW |