[Image-SIG] PIL: FAST images from C-Extension?
Sven Havemann
s.havemann@tu-bs.de
Fri, 19 Mar 1999 21:58:38 +0100
This is a multi-part message in MIME format.
--------------4548306A96FD939BFBC93FC5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
fredrik_lundh@ivab.se is invalid??
--------------4548306A96FD939BFBC93FC5
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Return-Path: <s.havemann@tu-bs.de>
Received: from rzcomm1.rz.tu-bs.de (rzcomm1.rz.tu-bs.de [134.169.9.107])
by europa.cg.cs.tu-bs.de (8.8.7/8.8.7) with ESMTP id VAA27071;
Fri, 19 Mar 1999 21:52:46 +0100
Received: from europa.cg.cs.tu-bs.de (root@europa.cg.cs.tu-bs.de [134.169.83.129])
by rzcomm1.rz.tu-bs.de (8.8.6/8.8.6) with ESMTP id VAA11508;
Fri, 19 Mar 1999 21:53:58 +0100 (MET)
Received: from tu-bs.de (nurbs.cg.cs.tu-bs.de [134.169.83.189])
by europa.cg.cs.tu-bs.de (8.8.7/8.8.7) with ESMTP id VAA27064;
Fri, 19 Mar 1999 21:52:42 +0100
Sender: havemann@europa.cg.cs.tu-bs.de
Message-ID: <36F2B9BE.10D5EF74@tu-bs.de>
Date: Fri, 19 Mar 1999 21:55:26 +0100
From: Sven Havemann <s.havemann@tu-bs.de>
Organization: Institut fuer Computergrafik
X-Mailer: Mozilla 4.07C-SGI [en] (X11; I; IRIX 6.5 IP32)
MIME-Version: 1.0
Newsgroups: comp.lang.python
To: Fredrik Lundh <fredrik_lundh@ivab.se>, n.schenk@tu-bs.de
Subject: PIL: FAST images from C-Extension?
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi!
===
We're producing animated bitmaps in a C-extension module to Python and
would like to display them FAST using Python/Tkinter/PIL. How can I
transfer images from C to Python? I've written a demo extension doing
so, you can find THE SOURCE (just 10 kB) in
ftp://ftp.cg.cs.tu-bs.de/pub/cg/people/havemann/pildirect/pildirect.zip
The problem is: IT IS TOO SLOW!
My idea was to have an update function for a Tk Canvas doing the
following (in Python):
=============================================
im=Image.new("RGB",(800,800))
canvas=Canvas(root,width=802,height=802)
imtk = ImageTk.PhotoImage(im)
canvas.create_image(0,0,image=imtk,anchor=NW)
canvas.pack()
def update():
global im,imtk
test(im) # updating the image from our extension module
imtk.paste(im) # updating the PhotoImage
tkroot.after(5,update) # loop
=============================================
test(im) extracts the bitmap info from the Image.Image data structure
and works quite nicely and fast. But the imtk.paste(im) obviously
performs a FLOYD-STEINBERG DITHERING IN EVERY STEP resulting in an
unacceptable O(m*n) complexity for bitmap size (m x n).
Questions: Why is there dithering at all? Isn't the Tk PhotoImage a
Truecolor image? How can I tell Tk to allocate a truecolor visual (by
default)?
The next idea was to use indexed color PhotoImages. But then I didn't
manage to set the image palette and found some inconsistencies in
ImagePalette.py from PIL ('raw' attribute not found in image.load()) and
fixed it in a copied version...
I've discovered that there's a new version of PIL, so I will retry using
Imaging-1.0b1.tar.gz instead of Imaging-0.3b2.tgz monday... But maybe
someone can tell me whether I run in the WRONG DIRECTION AT ALL and
maybe there's obviously a BETTER SOLUTION!!!
TIA for any hint,
regards, Sven.
--
__________________________________________________________________
dipl-inform. Sven Havemann Institut fuer ComputerGraphik
Odastrasse 6 Rebenring 18
38122 Braunschweig - Germany 38106 Braunschweig - Germany
Tel. 0531/2808955 Tel. 0531/391-2108, Fax: -2103
s.havemann@tu-bs.de http://www.cg.cs.tu-bs.de
--------------4548306A96FD939BFBC93FC5--