filter-counter.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function tostr(t)
  2. local str = ""
  3. for k, v in next, t do
  4. if #str > 0 then
  5. str = str .. ", "
  6. end
  7. if type(k) == "number" then
  8. str = str .. "[" .. k .. "] = "
  9. else
  10. str = str .. tostring(k) .. " = "
  11. end
  12. if type(v) == "table" then
  13. str = str .. "{ " .. tostr(v) .. " }"
  14. else
  15. str = str .. tostring(v)
  16. end
  17. end
  18. return str
  19. end
  20. local canvas -- holds the current canvas (from startcanvas())
  21. --[[
  22. startcanvas() is called at the start of each picture file, passing the
  23. canvas that we will be drawing into, and the name of the file.
  24. Following this call, there will be some number of calls to accumulate(t)
  25. where t is a table of parameters that were passed to that draw-op.
  26. t.verb is a string holding the name of the draw-op (e.g. "drawRect")
  27. when a given picture is done, we call endcanvas(canvas, fileName)
  28. ]]
  29. function sk_scrape_startcanvas(c, fileName)
  30. canvas = c
  31. end
  32. --[[
  33. Called when the current canvas is done drawing.
  34. ]]
  35. function sk_scrape_endcanvas(c, fileName)
  36. canvas = nil
  37. end
  38. --[[
  39. Called with the parameters to each canvas.draw call, where canvas is the
  40. current canvas as set by startcanvas()
  41. ]]
  42. local gCF_Count = 0
  43. local gIF_Count = 0
  44. local gBOTH_Count = 0
  45. function sk_scrape_accumulate(t)
  46. if not t.paint then
  47. return
  48. end
  49. local colorFilter = t.paint:getColorFilter()
  50. local imageFilter = t.paint:getImageFilter()
  51. if colorFilter then
  52. gCF_Count = gCF_Count + 1
  53. end
  54. if imageFilter then
  55. gIF_Count = gIF_Count + 1
  56. end
  57. if colorFilter and imageFilter then
  58. gBOTH_Count = gBOTH_Count + 1
  59. end
  60. end
  61. --[[
  62. lua_pictures will call this function after all of the pictures have been
  63. "accumulated".
  64. ]]
  65. function sk_scrape_summarize()
  66. io.write("colorfilters ", gCF_Count, ", imagefilters ", gIF_Count, ", both_filters ", gBOTH_Count, "\n")
  67. --[[
  68. io.write("\n\nFirst glyph spread\n\n")
  69. for k, v in next, gFirstGlyphs do
  70. io.write("glyph, ", k, ",count, ", v, "\n")
  71. end
  72. ]]
  73. end
  74. function test_summary()
  75. io.write("just testing test_summary\n")
  76. end