[Image-SIG] Re: Saving 12-bit grayscale from PIL

Jonathan M. Gilligan jonathan.gilligan@vanderbilt.edu
Mon, 17 Sep 2001 18:07:46 -0500


Here is a minimal script to reproduce the problem:

import Numeric, Image, PngImagePlugin
na = Numeric.cumsum(Numeric.cumsum(Numeric.ones((128,256),Numeric.Int32)),1)
print na.shape
print na[0,255]
print na[1,255]
print na[127,0]
print na[127,1]
print na[127,255]
s = na.tostring()
img = Image.fromstring('I', (256,128), s)
print img.size
print img.getpixel((255,0))
print img.getpixel((255,1))
print img.getpixel((0,127))
print img.getpixel((1,127))
print img.getpixel((255,127))

img.save('foo.png')



This produces output:
 >pythonw -u foo.py
(128, 256)
256
512
128
256
32768
(256, 128)
256
512
128
256
32768
 >Exit code: -1073741819

The crash occurs on line 355 of ImageFile.py: "l, s, d = e.encode(bufsize)".

I would note, incidentally, that the PIL 1.1.1 source 
(http://www.pythonware.com/downloads/Imaging-1.1.1.tar.gz) mixes whitespace 
and tabs in many of the Imaging-1.1.1\PIL\*.py files. I don't think this 
would be the source of the problems, but one never knows.

Jonathan
===========================================================================
Jonathan M. Gilligan                     <jonathan.gilligan@vanderbilt.edu>

He was allying himself to science, for what was science but the absence of
prejudice backed by the presence of money? --- Henry James, The Golden Bowl