[Image-SIG] PIL as loadable Tcl module (0.3b2)

Matthias Klose doko@cs.tu-berlin.de
Tue, 11 Aug 1998 14:52:06 +0200 (MET DST)


Attached is a patch to build a dynamically loadable Pil Tcl module,
such that no recompilation of the Tkinter module is needed. This is
tested on Linux glibc2 and Solaris2.6. In the Makefile INCLUDES,
LIBDIRS and LIBS need to edited by hand ... The two file PIL.so and
pkgIndex.tcl need to be installed in a subdirectory of $tcl_pkgPath

--- pil-0.3b2.orig/PIL/ImageTk.py
+++ pil-0.3b2/PIL/ImageTk.py
@@ -110,6 +110,7 @@
             block = image.new_block(self.__mode, im.size)
             image.convert2(block, image) # convert directly between buffers
 
+        self.__photo.tk.call("package", "require", "Pil")
         self.__photo.tk.call("PyImagingPhoto", self.__photo, block.id)
 
 
--- pil-0.3b2.orig/Tk/tkImaging.c
+++ pil-0.3b2/Tk/tkImaging.c
@@ -183,9 +183,22 @@
 }
 
 
+#ifdef PIL_MODULE
+int
+Pil_Init(Tcl_Interp* interp)
+{                                                                               
+    Tcl_CreateCommand(interp, "PyImagingPhoto", PyImagingPhoto,                 
+                      (ClientData) 0, (Tcl_CmdDeleteProc*) NULL);               
+    if (Tcl_PkgProvide(interp, "Pil", "0.3") != TCL_OK) {
+         return TCL_ERROR;
+    }
+    return TCL_OK;
+}                                                                               
+#else
 void
 TkImaging_Init(Tcl_Interp* interp)
 {
     Tcl_CreateCommand(interp, "PyImagingPhoto", PyImagingPhoto,
                       (ClientData) 0, (Tcl_CmdDeleteProc*) NULL);
 }
+#endif
--- pil-0.3b2.orig/Tk/Makefile
+++ pil-0.3b2/Tk/Makefile
@@ -0,0 +1,50 @@
+# The C compiler:
+CC = cc
+
+# Compiler options:
+COPTS = -O2 -fpic -DPIL_MODULE
+
+# Name for the shared lib:
+SH_LIB = PIL.so
+
+# Shared library linker command:
+SHLINK = cc -shared
+
+# Where to find tcl.h, tk.h
+INCLUDES =
+
+# Where to find libtcl.a, libtk.a
+LIBDIRS =
+
+# Libraries to link with (-ldl for Linux only?):
+LIBS = -ltk8.0 -ltcl8.0 -lm -lc -ldl
+
+TK_FLAGS =
+
+
+#### Shouldn't have to change anything beyond this point ####
+
+
+CFLAGS = $(COPTS) $(INCLUDES) $(TK_FLAGS)
+
+LFLAGS = $(LIBDIRS)
+
+all: shared pkgIndex.tcl
+
+shared: $(SH_LIB)
+
+tkImaging.o: tkImaging.c
+	$(CC) -c -I../libImaging $(CFLAGS) tkImaging.c
+
+
+$(SH_LIB): tkImaging.o
+	$(SHLINK) $(LFLAGS) $(LIBS) tkImaging.o -o $@
+
+pkgIndex.tcl: $(SH_LIB)
+	echo pkg_mkIndex . $(SH_LIB) | tclsh8.0
+
+clean:
+	-rm -f *.o *~ core pkgIndex.tcl
+
+realclean:
+	-rm -f *.o *~ core *.so pkgIndex.tcl