A possible bug in converting palletized images to QImage

Mauricio Muñoz Lucero <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
Hi!

I am making an image converter using PIL 1.1.7 and PyQt 4.6 for the gui.

Everything goes perfect, except when i try to convert an image in "P"
mode (8 bit pixels and using a colour palette) to QImage, using the
ImageQt module.

self.img = ImageQt.ImageQt(self.raw_image)

In this case, always i get a white image, it doesn't appear any error messages.

But if i copy the code of the conversion from the ImageQt module, i
get the next error:

  File "cpcview.py", line 482, in initialize_image_to_convert
    palette_image = self.raw_image.getpalette()
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 932, in
getpalette
    self.load()
  File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 127,
in load
    pixel = Image.Image.load(self)
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 608, in
load
    if self.im and self.palette and self.palette.dirty:
OverflowError: can't convert negative value to unsigned long

The possible bug appears in the getpalette() function, i am using now
a workaround to fix it, using "palette.getdata()" instead of
"getpalette()". This is the workaround in my program:

self.img = ImageQt.ImageQt(self.raw_image)

# Workaround to "OverflowError: can't convert negative value to unsigned long"
if self.imagen_cruda.mode == "P":
    palette_image = self.imagen_cruda.palette.getdata()
    palette_image = palette_image[1]
    colorlist = []
    for i in range(len(palette_image) // 3):
          colorlist.append(QtGui.qRgba(ord(palette_image[i * 3]),
                                  ord(palette_image[i * 3 + 1]),
                                  ord(palette_image[i * 3 + 2]), 0xFF))
    self.img.setColorTable(colorlist)

Is it really a bug or am i using incorrectly the ImageQt module?
Is there a better or more "pythonic" fix to this problem?

Thanks for this wonderful library,
Maurice.
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.