[Image-SIG] Fast updates to PhotoImage

Andrew Kuchling akuchlin@mems-exchange.org
Tue, 06 Nov 2001 15:03:16 -0500


I'm experimenting with a protocol in which an image is diced up into a
number of tiles, and each tile is sent in a separate UDP packet.  A
Tkinter + PIL client then receives packets and reassembles the image.

Performance is turning out to be a problem.  It's acceptable for a
small image that measures only 320x240 or thereabouts, but for an
800x600 image, it's too slow.  The photo_image.paste() call ends up
requiring .18 seconds on my machine, and that's for a single tile;
given that the whole image is around 50 tiles, this makes it
impossible for the client to present a coherent display.

My code creates a PhotoImage and then does photo_image.paste(<updated
image object>).  Is there some faster way of displaying an image that
will be frequently modified?  Possible approaches might be:

1) Update a PIL.Image for every tile; that's fast enough to keep up.
Update the PhotoImage only once per second or so.  (The problem is
then our frame rate will be limited to 1 frame/sec.)

2) PhotoImage.paste() ignores its 'box' argument, as someone recently
pointed out.  Perhaps implementing it would help, so the C
Tk_PhotoPutBlock call wouldn't have to handle the entire image.

3) Manage the Tk photo object myself, and handle pasting into the
image using Tk's functions.  

Any suggestions?

--amk