bitmap_statistics.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. function string.startsWith(String,Start)
  2. return string.sub(String,1,string.len(Start))==Start
  3. end
  4. function string.endsWith(String,End)
  5. return End=='' or string.sub(String,-string.len(End))==End
  6. end
  7. local canvas = nil
  8. local num_perspective_bitmaps = 0
  9. local num_affine_bitmaps = 0
  10. local num_scaled_bitmaps = 0
  11. local num_translated_bitmaps = 0
  12. local num_identity_bitmaps = 0
  13. local num_scaled_up = 0
  14. local num_scaled_down = 0
  15. function sk_scrape_startcanvas(c, fileName)
  16. canvas = c
  17. end
  18. function sk_scrape_endcanvas(c, fileName)
  19. canvas = nil
  20. end
  21. function sk_scrape_accumulate(t)
  22. -- dump the params in t, specifically showing the verb first, which we
  23. -- then nil out so it doesn't appear in tostr()
  24. if (string.startsWith(t.verb,"drawBitmap")) then
  25. matrix = canvas:getTotalMatrix()
  26. matrixType = matrix:getType()
  27. if matrixType.perspective then
  28. num_perspective_bitmaps = num_perspective_bitmaps + 1
  29. elseif matrixType.affine then
  30. num_affine_bitmaps = num_affine_bitmaps + 1
  31. elseif matrixType.scale then
  32. num_scaled_bitmaps = num_scaled_bitmaps + 1
  33. if matrix:getScaleX() > 1 or matrix:getScaleY() > 1 then
  34. num_scaled_up = num_scaled_up + 1
  35. else
  36. num_scaled_down = num_scaled_down + 1
  37. end
  38. elseif matrixType.translate then
  39. num_translated_bitmaps = num_translated_bitmaps + 1
  40. else
  41. num_identity_bitmaps = num_identity_bitmaps + 1
  42. end
  43. end
  44. end
  45. function sk_scrape_summarize()
  46. io.write( "identity = ", num_identity_bitmaps,
  47. ", translated = ", num_translated_bitmaps,
  48. ", scaled = ", num_scaled_bitmaps, " (up = ", num_scaled_up, "; down = ", num_scaled_down, ")",
  49. ", affine = ", num_affine_bitmaps,
  50. ", perspective = ", num_perspective_bitmaps,
  51. "\n")
  52. end