[Image-SIG] raw decoder change 0.3a4 -> 1.0b1

Fredrik Lundh fredrik@pythonware.com
Wed, 10 Feb 1999 15:57:33 +0100


Rob Hooft once wrote:
>With 0.3a4, I could do:
>
>        im=Image.fromstring("P",(self.h.xsize,self.h.ysize),
>                            data.astype(Numeric.Int8).tostring(),"raw","L")
>        im.palette=Palette(self.palette)
>
>This now gives a "ValueError" exception. I currently (1.0b1) have the code:
>
>        im=Image.fromstring("L",(self.h.xsize,self.h.ysize),
>                            data.astype(Numeric.Int8).tostring(),"raw","L")
>        im.mode="P"
>        im.palette=Palette(self.palette)
>
>Just to make sure: is this "proper-PIL" coding? Any cleaner alternatives?

Without testing your code, I think this is the PCX and Sun Raster
buglet once again.  The rawmode (here, the last argument to
fromstring) must be compatible with the mode (the first
argument).  "P" and "L" are two different things,  but earlier
versions didn't really care since the internal layout is the
same.

On the other hand, patching the mode attribute is really
dangerous.  Here's what I would try (untested):

>        im=Image.fromstring("P",(self.h.xsize,self.h.ysize),
>                            data.astype(Numeric.Int8).tostring(),"raw","P")
>        im.palette=Palette(self.palette)

Cheers /F
fredrik@pythonware.com
http://www.pythonware.com