Changes to Lua gradient scraping
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2103973002 Review-Url: https://codereview.chromium.org/2103973002
This commit is contained in:
parent
d66110f597
commit
b4f254e051
@ -1268,25 +1268,38 @@ static int lshader_asAGradient(lua_State* L) {
|
||||
SkShader::GradientInfo info;
|
||||
sk_bzero(&info, sizeof(info));
|
||||
|
||||
SkColor colors[3]; // hacked in for extracting info on 3 color case.
|
||||
SkScalar pos[3];
|
||||
|
||||
info.fColorCount = 3;
|
||||
info.fColors = &colors[0];
|
||||
info.fColorOffsets = &pos[0];
|
||||
|
||||
SkShader::GradientType t = shader->asAGradient(&info);
|
||||
|
||||
if (SkShader::kNone_GradientType != t) {
|
||||
lua_newtable(L);
|
||||
setfield_string(L, "type", gradtype2string(t));
|
||||
setfield_number(L, "colorCount", info.fColorCount);
|
||||
setfield_string(L, "tile", mode2string(info.fTileMode));
|
||||
SkAutoTArray<SkScalar> pos(info.fColorCount);
|
||||
info.fColorOffsets = pos.get();
|
||||
shader->asAGradient(&info);
|
||||
|
||||
if (info.fColorCount == 3){
|
||||
setfield_number(L, "midPos", pos[1]);
|
||||
bool containsHardStops = false;
|
||||
bool isEvenlySpaced = true;
|
||||
for (int i = 1; i < info.fColorCount; i++) {
|
||||
if (SkScalarNearlyEqual(info.fColorOffsets[i], info.fColorOffsets[i-1])) {
|
||||
containsHardStops = true;
|
||||
}
|
||||
if (!SkScalarNearlyEqual(info.fColorOffsets[i], i/(info.fColorCount - 1.0f))) {
|
||||
isEvenlySpaced = false;
|
||||
}
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
setfield_string(L, "type", gradtype2string(t));
|
||||
setfield_string(L, "tile", mode2string(info.fTileMode));
|
||||
setfield_number(L, "colorCount", info.fColorCount);
|
||||
setfield_boolean(L, "containsHardStops", containsHardStops);
|
||||
setfield_boolean(L, "isEvenlySpaced", isEvenlySpaced);
|
||||
|
||||
lua_newtable(L);
|
||||
for (int i = 0; i < info.fColorCount; i++) {
|
||||
// Lua uses 1-based indexing
|
||||
setarray_scalar(L, i+1, pos[i]);
|
||||
}
|
||||
lua_setfield(L, -2, "positions");
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
|
||||
function sk_scrape_startcanvas(c, fileName) end
|
||||
|
||||
function sk_scrape_endcanvas(c, fileName) end
|
||||
|
||||
count3 = 0
|
||||
count3sym = 0
|
||||
gradients = {}
|
||||
|
||||
i = 1
|
||||
|
||||
function sk_scrape_accumulate(t)
|
||||
local p = t.paint
|
||||
@ -13,22 +12,41 @@ function sk_scrape_accumulate(t)
|
||||
if s then
|
||||
local g = s:asAGradient()
|
||||
if g then
|
||||
--io.write(g.type, " gradient with ", g.colorCount, " colors\n")
|
||||
|
||||
if g.colorCount == 3 then
|
||||
count3 = count3 + 1
|
||||
gradients[i] = {}
|
||||
gradients[i].colorCount = g.colorCount
|
||||
gradients[i].type = g.type
|
||||
gradients[i].tile = g.tile
|
||||
gradients[i].isEvenlySpaced = g.isEvenlySpaced
|
||||
gradients[i].containsHardStops = g.containsHardStops
|
||||
|
||||
if (g.midPos >= 0.499 and g.midPos <= 0.501) then
|
||||
count3sym = count3sym + 1
|
||||
end
|
||||
end
|
||||
gradients[i].positions = {}
|
||||
for j = 1, g.colorCount, 1 do
|
||||
gradients[i].positions[j] = g.positions[j]
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function sk_scrape_summarize()
|
||||
io.write("Number of 3 color gradients: ", count3, "\n");
|
||||
io.write("Number of 3 color symmetric gradients: ", count3sym, "\n");
|
||||
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
|
||||
|
||||
io.write(string.format("%d %s %s %d %d %s\n",
|
||||
v.colorCount,
|
||||
v.type,
|
||||
v.tile,
|
||||
tonumber(v.isEvenlySpaced and 1 or 0),
|
||||
tonumber(v.containsHardStops and 1 or 0),
|
||||
pos))
|
||||
end
|
||||
end
|
||||
|
||||
|
42
tools/lua/gradients.py
Executable file
42
tools/lua/gradients.py
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2015 Google Inc.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import argparse
|
||||
import sqlite3
|
||||
|
||||
def create_database(inpath, outpath):
|
||||
with sqlite3.connect(outpath) as conn:
|
||||
c = conn.cursor();
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS gradients (
|
||||
ColorCount INTEGER,
|
||||
GradientType TEXT,
|
||||
TileMode TEXT,
|
||||
EvenlySpaced INTEGER,
|
||||
HardStops INTEGER,
|
||||
Positions TEXT
|
||||
)''');
|
||||
c.execute("DELETE FROM gradients");
|
||||
|
||||
with open(inpath, "r") as results:
|
||||
gradients = []
|
||||
for line in [line.strip() for line in results]:
|
||||
gradients.append(line.split());
|
||||
|
||||
c.executemany("INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?)",
|
||||
gradients);
|
||||
|
||||
conn.commit();
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description = "Transform Lua script output to a SQL DB");
|
||||
parser.add_argument("inpath", help="Path to Lua script output file");
|
||||
parser.add_argument("outpath", help="Path to SQL DB");
|
||||
args = parser.parse_args();
|
||||
|
||||
create_database(args.inpath, args.outpath);
|
Loading…
Reference in New Issue
Block a user