| fmenozzi | f023e68 | 2016-07-18 08:20:06 -0700 | [diff] [blame] | 1 | filename = "" | 
 | 2 |  | 
 | 3 | function sk_scrape_startcanvas(c, fileName) | 
 | 4 |     filename = fileName | 
 | 5 | end | 
 | 6 |  | 
 | 7 | function sk_scrape_endcanvas(c, fileName) | 
 | 8 |  | 
 | 9 | end | 
| reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 10 |  | 
| fmenozzi | 90ccfba | 2016-07-12 14:55:39 -0700 | [diff] [blame] | 11 | LuaDoubleNearlyZero = 1.0 / bit32.lshift(1.0, 12) | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 12 |  | 
| fmenozzi | 90ccfba | 2016-07-12 14:55:39 -0700 | [diff] [blame] | 13 | function LuaDoubleNearlyEqual(a, b) | 
 | 14 |     return math.abs(a-b) <= LuaDoubleNearlyZero | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 15 | end | 
 | 16 |  | 
| fmenozzi | d876a4b | 2016-07-18 13:33:37 -0700 | [diff] [blame] | 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 |  | 
| fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 24 | gradients = {} | 
 | 25 |  | 
 | 26 | i = 1 | 
| commit-bot@chromium.org | 74f96b9 | 2013-08-01 17:32:56 +0000 | [diff] [blame] | 27 |  | 
| reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 28 | function sk_scrape_accumulate(t) | 
 | 29 |     local p = t.paint | 
 | 30 |     if p then | 
 | 31 |         local s = p:getShader() | 
 | 32 |         if s then | 
 | 33 |             local g = s:asAGradient() | 
 | 34 |             if g then | 
| fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 35 |                 gradients[i] = {} | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 36 |  | 
| fmenozzi | f023e68 | 2016-07-18 08:20:06 -0700 | [diff] [blame] | 37 |                 gradients[i].filename = filename | 
 | 38 |  | 
| fmenozzi | d876a4b | 2016-07-18 13:33:37 -0700 | [diff] [blame] | 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 |  | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 50 |                 gradients[i].colorCount = g.colorCount | 
 | 51 |                 gradients[i].type       = g.type | 
 | 52 |                 gradients[i].tile       = g.tile | 
 | 53 |  | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 54 |                 isEvenlySpaced = true | 
| fmenozzi | 90ccfba | 2016-07-12 14:55:39 -0700 | [diff] [blame] | 55 |                 for j = 1, g.colorCount, 1 do | 
 | 56 |                     if not LuaDoubleNearlyEqual(g.positions[j], (j-1)/(g.colorCount-1)) then | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 57 |                         isEvenlySpaced = false | 
 | 58 |                     end | 
| fmenozzi | 90ccfba | 2016-07-12 14:55:39 -0700 | [diff] [blame] | 59 |                 end | 
 | 60 |                 gradients[i].isEvenlySpaced = isEvenlySpaced | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 61 |  | 
| fmenozzi | 90ccfba | 2016-07-12 14:55:39 -0700 | [diff] [blame] | 62 |                 numHardStops = 0 | 
 | 63 |                 for j = 2, g.colorCount, 1 do | 
 | 64 |                     if LuaDoubleNearlyEqual(g.positions[j], g.positions[j-1]) then | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 65 |                         numHardStops = numHardStops + 1 | 
 | 66 |                     end | 
 | 67 |                 end | 
| fmenozzi | 016e51f | 2016-07-14 07:44:50 -0700 | [diff] [blame] | 68 |                 gradients[i].numHardStops = numHardStops | 
| commit-bot@chromium.org | 74f96b9 | 2013-08-01 17:32:56 +0000 | [diff] [blame] | 69 |  | 
| fmenozzi | 016e51f | 2016-07-14 07:44:50 -0700 | [diff] [blame] | 70 |                 gradients[i].verb = t.verb | 
 | 71 |                  | 
| fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 72 |                 gradients[i].positions = {} | 
 | 73 |                 for j = 1, g.colorCount, 1 do | 
 | 74 |                     gradients[i].positions[j] = g.positions[j] | 
 | 75 |                 end | 
 | 76 |  | 
 | 77 |                 i = i + 1 | 
| reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 78 |             end | 
 | 79 |         end | 
 | 80 |     end | 
 | 81 | end | 
 | 82 |  | 
| fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 83 | function sk_scrape_summarize() | 
 | 84 |     for k, v in pairs(gradients) do | 
 | 85 |         local pos = "" | 
 | 86 |         for j = 1, v.colorCount , 1 do | 
 | 87 |             pos = pos .. v.positions[j] | 
 | 88 |             if j ~= v.colorCount then | 
 | 89 |                 pos = pos .. "," | 
 | 90 |             end | 
 | 91 |         end | 
 | 92 |  | 
| fmenozzi | d876a4b | 2016-07-18 13:33:37 -0700 | [diff] [blame] | 93 |         io.write(string.format("%s %d %s %s %d %d %s %d %d %s\n", | 
| fmenozzi | f023e68 | 2016-07-18 08:20:06 -0700 | [diff] [blame] | 94 |                                 v.filename, | 
| fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 95 |                                 v.colorCount, | 
 | 96 |                                 v.type, | 
 | 97 |                                 v.tile, | 
 | 98 |                                 tonumber(v.isEvenlySpaced and 1 or 0), | 
| fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 99 |                                 v.numHardStops, | 
| fmenozzi | 016e51f | 2016-07-14 07:44:50 -0700 | [diff] [blame] | 100 |                                 v.verb, | 
| fmenozzi | d876a4b | 2016-07-18 13:33:37 -0700 | [diff] [blame] | 101 |                                 v.boundsWidth, | 
 | 102 |                                 v.boundsHeight, | 
| fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 103 |                                 pos)) | 
 | 104 |     end | 
| commit-bot@chromium.org | 74f96b9 | 2013-08-01 17:32:56 +0000 | [diff] [blame] | 105 | end | 
| reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 106 |  |