[PYTHON IMAGE-SIG] The PIL library -- specification for release 0.1

Fredrik Lundh fredrik_lundh@ivab.se
Thu, 21 Mar 1996 09:06:19 +0100

Guido writes:

> Interesting.  Will this interact with Tk?  I'd love to be able to
> stuff images in a Tk "photo image" object without having to write it
> to a file in GIF or PPM format first...

Of course.  I had Grail in mind when I designed some of the PIL
features (more on this below).  I mean, imagine what you can do if you
stuff image processing support into a web-browser!

 Anyway, I have a Tk photo image interface that seems to be working,
but I haven't had the time to figure out how add it to Tk in a clean
way (the current version is boldly patched into Tk.  Are there any Tk
experts out there that have done similar things, drop me a line!).
Anyway, this interface allows you to create a photo image out of a PIL
Image object.

 Even more interesting for Grail, PIL allows you to decode data
incrementally (including TIFF).  Each raster data decoders has an
"expose" method that takes a string of bytes, and returning the amount
of data it was able to use.

 If we boldly ignore the code required to identify and read the file
header (some clever use of StringIO is required here), and bind the
decoder to the image memory, you can do something like:

	buf = sio.getvalue()[headersize:]
	while 1:
	    s, e = decoder.expose(buf)
	    if s < 0:
		break # e is error code, 0 if completed
	    buf = buf[s:]
	    s = io.read(bufsize)
	    if not s:
	        break # file is truncated
	    buf = buf + s
	    if time_to_update():

 Just add some code to set the bufsize based on the connection speed,
and to determine when its appropriate to update the screen, and you
have a nice, progressive image display...

 Maybe in Grail 0.4?


IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org