2016-07-18 15:20:06 +00:00
|
|
|
filename = ""
|
|
|
|
|
|
|
|
function sk_scrape_startcanvas(c, fileName)
|
|
|
|
filename = fileName
|
|
|
|
end
|
|
|
|
|
|
|
|
function sk_scrape_endcanvas(c, fileName)
|
|
|
|
|
|
|
|
end
|
2013-07-24 15:47:52 +00:00
|
|
|
|
2016-07-12 21:55:39 +00:00
|
|
|
LuaDoubleNearlyZero = 1.0 / bit32.lshift(1.0, 12)
|
2016-07-12 16:17:39 +00:00
|
|
|
|
2016-07-12 21:55:39 +00:00
|
|
|
function LuaDoubleNearlyEqual(a, b)
|
|
|
|
return math.abs(a-b) <= LuaDoubleNearlyZero
|
2016-07-12 16:17:39 +00:00
|
|
|
end
|
|
|
|
|
2016-07-18 20:33:37 +00:00
|
|
|
function bounds(rect)
|
|
|
|
local width = rect.right - rect.left
|
|
|
|
local height = rect.bottom - rect.top
|
|
|
|
|
|
|
|
return width, height
|
|
|
|
end
|
|
|
|
|
2016-06-28 21:03:03 +00:00
|
|
|
gradients = {}
|
|
|
|
|
|
|
|
i = 1
|
2013-08-01 17:32:56 +00:00
|
|
|
|
2013-07-24 15:47:52 +00:00
|
|
|
function sk_scrape_accumulate(t)
|
|
|
|
local p = t.paint
|
|
|
|
if p then
|
|
|
|
local s = p:getShader()
|
|
|
|
if s then
|
|
|
|
local g = s:asAGradient()
|
|
|
|
if g then
|
2016-06-28 21:03:03 +00:00
|
|
|
gradients[i] = {}
|
2016-07-12 16:17:39 +00:00
|
|
|
|
2016-07-18 15:20:06 +00:00
|
|
|
gradients[i].filename = filename
|
|
|
|
|
2016-07-18 20:33:37 +00:00
|
|
|
local width, height = -1, -1
|
|
|
|
if t.rect then
|
|
|
|
width, height = bounds(t.rect)
|
|
|
|
elseif t.rrect then
|
|
|
|
width, height = bounds(t.rrect:rect())
|
|
|
|
elseif t.path then
|
|
|
|
width, height = bounds(t.path:getBounds())
|
|
|
|
end
|
|
|
|
gradients[i].boundsWidth = width
|
|
|
|
gradients[i].boundsHeight = height
|
|
|
|
|
2016-07-12 16:17:39 +00:00
|
|
|
gradients[i].colorCount = g.colorCount
|
|
|
|
gradients[i].type = g.type
|
|
|
|
gradients[i].tile = g.tile
|
|
|
|
|
|
|
|
isEvenlySpaced = true
|
2016-07-12 21:55:39 +00:00
|
|
|
for j = 1, g.colorCount, 1 do
|
|
|
|
if not LuaDoubleNearlyEqual(g.positions[j], (j-1)/(g.colorCount-1)) then
|
2016-07-12 16:17:39 +00:00
|
|
|
isEvenlySpaced = false
|
|
|
|
end
|
2016-07-12 21:55:39 +00:00
|
|
|
end
|
|
|
|
gradients[i].isEvenlySpaced = isEvenlySpaced
|
2016-07-12 16:17:39 +00:00
|
|
|
|
2016-07-12 21:55:39 +00:00
|
|
|
numHardStops = 0
|
|
|
|
for j = 2, g.colorCount, 1 do
|
|
|
|
if LuaDoubleNearlyEqual(g.positions[j], g.positions[j-1]) then
|
2016-07-12 16:17:39 +00:00
|
|
|
numHardStops = numHardStops + 1
|
|
|
|
end
|
|
|
|
end
|
2016-07-14 14:44:50 +00:00
|
|
|
gradients[i].numHardStops = numHardStops
|
2016-06-28 21:03:03 +00:00
|
|
|
|
2016-07-14 14:44:50 +00:00
|
|
|
gradients[i].verb = t.verb
|
|
|
|
|
2016-06-28 21:03:03 +00:00
|
|
|
gradients[i].positions = {}
|
|
|
|
for j = 1, g.colorCount, 1 do
|
|
|
|
gradients[i].positions[j] = g.positions[j]
|
|
|
|
end
|
|
|
|
|
|
|
|
i = i + 1
|
2013-07-24 15:47:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-28 21:03:03 +00:00
|
|
|
function sk_scrape_summarize()
|
|
|
|
for k, v in pairs(gradients) do
|
|
|
|
local pos = ""
|
|
|
|
for j = 1, v.colorCount , 1 do
|
|
|
|
pos = pos .. v.positions[j]
|
|
|
|
if j ~= v.colorCount then
|
|
|
|
pos = pos .. ","
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-18 20:33:37 +00:00
|
|
|
io.write(string.format("%s %d %s %s %d %d %s %d %d %s\n",
|
2016-07-18 15:20:06 +00:00
|
|
|
v.filename,
|
2016-06-28 21:03:03 +00:00
|
|
|
v.colorCount,
|
|
|
|
v.type,
|
|
|
|
v.tile,
|
|
|
|
tonumber(v.isEvenlySpaced and 1 or 0),
|
2016-07-12 16:17:39 +00:00
|
|
|
v.numHardStops,
|
2016-07-14 14:44:50 +00:00
|
|
|
v.verb,
|
2016-07-18 20:33:37 +00:00
|
|
|
v.boundsWidth,
|
|
|
|
v.boundsHeight,
|
2016-06-28 21:03:03 +00:00
|
|
|
pos))
|
|
|
|
end
|
2013-08-01 17:32:56 +00:00
|
|
|
end
|
2013-07-24 15:47:52 +00:00
|
|
|
|