aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-31 19:46:02 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-31 19:46:02 +0000
commite2aad27c5f02e375077ed605738c65009ba0644c (patch)
treed4361b1b24262c188acae352a0ad0943cd62dfe9 /tools/lua
parenta20e42c08b6b92c1022e5b27da3f92a429d0c815 (diff)
sort the glyphID arrays
add head/tail code git-svn-id: http://skia.googlecode.com/svn/trunk@9376 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/lua')
-rw-r--r--tools/lua/glyph-usage.lua46
-rw-r--r--tools/lua/lua_pictures.cpp15
2 files changed, 57 insertions, 4 deletions
diff --git a/tools/lua/glyph-usage.lua b/tools/lua/glyph-usage.lua
index 2b0c0e12a0..8715f726fe 100644
--- a/tools/lua/glyph-usage.lua
+++ b/tools/lua/glyph-usage.lua
@@ -52,6 +52,15 @@ function round(x, mul)
return math.floor(x * mul + 0.5) / mul
end
+dump_glyph_array_p = false
+
+function dump_array_as_C(array)
+ for k, v in next, array do
+ io.write(tostring(v), ", ");
+ end
+ io.write("-1,\n")
+end
+
local strikes = {} -- [fontID_pointsize] = [] unique glyphs
function make_strike_key(paint)
@@ -66,6 +75,16 @@ function array_union(array, other)
end
end
+-- take a table of bools, indexed by values, and return a sorted table of values
+function bools_to_values(t)
+ local array = {}
+ for k, v in next, t do
+ array[#array + 1] = k
+ end
+ table.sort(array)
+ return array
+end
+
function array_count(array)
local n = 0
for k in next, array do
@@ -81,6 +100,10 @@ function sk_scrape_accumulate(t)
local key = make_strike_key(t.paint)
strikes[key] = strikes[key] or {}
array_union(strikes[key], t.glyphs)
+
+ if dump_glyph_array_p then
+ dump_array_as_C(t.glyphs)
+ end
end
end
end
@@ -94,20 +117,41 @@ function sk_scrape_summarize()
local strikeCount = 0
local min, max = 0, 0
+ local histogram = {}
+
for k, v in next, strikes do
local fontID = round(k / 1000)
local size = k - fontID * 1000
local count = array_count(v)
- io.write("fontID = ", fontID, ", size = ", size, ", entries = ", count, "\n");
+-- io.write("fontID,", fontID, ", size,", size, ", entries,", count, "\n");
min = math.min(min, count)
max = math.max(max, count)
totalCount = totalCount + count
strikeCount = strikeCount + 1
+
+ histogram[count] = (histogram[count] or 0) + 1
end
local ave = round(totalCount / strikeCount)
io.write("\n", "unique glyphs: min = ", min, ", max = ", max, ", ave = ", ave, "\n");
+
+ for k, v in next, histogram do
+ io.write("glyph_count,", k, ",frequency,", v, "\n")
+ end
+end
+
+function test_summary()
+ io.write("just testing test_summary\n")
+end
+
+function summarize_unique_glyphIDs()
+ io.write("/* runs of unique glyph IDs, with a -1 sentinel between different runs */\n")
+ io.write("static const int gUniqueGlyphIDs[] = {\n");
+ for k, v in next, strikes do
+ dump_array_as_C(bools_to_values(v))
+ end
+ io.write("-1 };\n")
end
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index ae4e1cabda..ca28f24388 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -30,10 +30,10 @@ static const char gSummarizeFunc[] = "sk_scrape_summarize";
// PictureRenderingFlags.cpp
extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap*);
-
-// Flags used by this file, alphabetically:
DEFINE_string2(skpPath, r, "", "Read .skp files from this dir");
DEFINE_string2(luaFile, l, "", "File containing lua script to run");
+DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning");
+DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
static SkPicture* load_picture(const char path[]) {
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
@@ -91,8 +91,13 @@ int tool_main(int argc, char** argv) {
exit(-1);
}
+ const char* summary = gSummarizeFunc;
+ if (!FLAGS_tailFunc.isEmpty()) {
+ summary = FLAGS_tailFunc[0];
+ }
+
SkAutoGraphics ag;
- SkLua L(gSummarizeFunc);
+ SkLua L(summary);
for (int i = 0; i < FLAGS_luaFile.count(); ++i) {
SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i]));
@@ -103,6 +108,10 @@ int tool_main(int argc, char** argv) {
}
}
+ if (!FLAGS_headCode.isEmpty()) {
+ L.runCode(FLAGS_headCode[0]);
+ }
+
for (int i = 0; i < FLAGS_skpPath.count(); i ++) {
SkOSFile::Iter iter(FLAGS_skpPath[i], "skp");
SkString inputFilename;