Speedup Bitmap Parser

Terry Reedy tjreedy at udel.edu
Mon Feb 16 16:15:42 EST 2009


Jayson Santos wrote:
> Hello people, I'm writing a Bitmap parser for study purposes, however
> when I parse a bitmap file and when I paint that file in a window, the
> script take to much time.

1. You turned constants into static methods called for every line, 
adding attribute lookup and function call time.
2. You read the image a line at a time and break each line into separate 
pixel objects.
3. You paint each pixel by drawing and filling a 1-pixel rectangle.

> How can I optimize my script loops to be faster ?

Don't do any of the above.  Look at how other programs such as PIL or 
pygame read, store, and paint images.

> Here is the script
> http://pastebin.com/m652b8d65

tjr




More information about the Python-list mailing list