use a buffer instead of writing to stdout for every pixel