a binary image packing algorithm written in python