[IMAGE-SIG] [Q] PIL problems: install, palette

Harald Singer singer@itl.atr.co.jp
Tue, 02 Dec 1997 23:04:39 +0900


we just tried to install PIL on Linux, HP-UX, OSF1 and SunOS and we
ran into several interesting (boring?) problems. Our final goal is to
display some nice colourful spectrograms (like in matlab).

1] basic install problems
1a] python: can't resolve symbol 'ImagingCrack'
    solution: commented out _crack in _imagingmodule.c
1b] the configure script is seriously broken when trying to use libz and
    and libjpeg that are not in /usr/local/lib and /usr/local/include
    solution: patched the Makefile by hand
1c] the makefiles are not setup for dealing with libjpeg.so and libz.so
    solution: patched Setup.in
              JPEGLIB = -L$(MYSHLIB) -ljpeg

2] on HP-UX9.05, the 'make test' gives completely different results when 
compiling with gcc and cc. Lena appears but is heavily discoloured when
using gcc. With cc, it looks more like a 'photoshop' job.
I have the suspicion that the cc version is correct. How can I find out?

3] some examples simply don't run.
   >>> im = Image.open('/home/singer/data/gaijin.ppm')
   >>> box = (100, 100, 200, 200)
   >>> region = im.crop(box)
   >>> region = region.transpose(Image.ROTATE_180)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/home/singer/lib/python/Imaging/Image.py", line 591, in transpose
    return self._makeself(im)
  File "/home/singer/lib/python/Imaging/Image.py", line 219, in _makeself
    new.palette = self.palette
AttributeError: palette
I can hack this and then it seems to work.
    region.palette=None; region.info={}

[4] I am reading a .jpg and trying to save as .gif
and get this error:
	IOError: cannot save mode RGB as GIF
What am I doing wrong?

[5] in Lib/ImageTk.py
the line 
	mode = image.palette.mode
fails for mode == "P".
If I hardcode it to
	mode = "RGB"
it seemed to work (for my special case).

class PhotoImage:

    def __init__(self, mode, size = None, **kw):
	if hasattr(mode, "mode") and hasattr(mode, "size"):
	    # got an image instead of a mode
	    image = mode
	    mode = image.mode
            if mode == "P":
                # palette mapped data
                mode = image.palette.mode
	    size = image.size
	    kw["width"], kw["height"] = size
	    image = None
	if mode not in ["1", "L", "RGB", "RGBA"]:
            if mode == "F":
                mode = "L"
                mode = "RGB"
	self.__mode = mode
	self.__size = size
	self.__photo = apply(Tkinter.PhotoImage, (), kw)
	self.image = self.__photo # compatibility
	if image:

[6] will this still be freeware? I find it slightly disconcerting that
the binary version for Windows is more advanced than the source code.

Last not least, I was pretty impressed by this software (that's why
I spent some time to oompile it on all our architectures). BTW, I found
some contributed palette code (around December 96) but it looks like it
would seriously break some other code.
Harald Singer, ATR ITL, tel +81-7749-5-1389    singer@itl.atr.co.jp

IMAGE-SIG - SIG on Image Processing with Python

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