Refactor gfx.py to use bytearrays. Fix some graphics dumping functions.