2010/1/4 Christopher Barker <chris.bar...@noaa.gov> wrote:
>
> Mauricio Muñoz Lucero wrote:
>>
>> 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.
>
> ...
>>
>> Is it really a bug or am i using incorrectly the ImageQt module?
>
> That would be a question for a QT list.

Perhaps i did not explain well the other day, but i think that the
problem appears in the ImageQT module of PIL, the piece of code that
take charge to convert an image in palette mode to QImage in PIL is:

        elif im.mode == "P":
            format = QImage.Format_Indexed8
            colortable = []
            palette = im.getpalette()
            for i in range(0, len(palette), 3):
                colortable.append(rgb(*palette[i:i+3]))

But if i change the "palette = im.getpalette()" by:

            palette = im.palette.getdata()
            palette = palette[1]

Then i don't get the OverflowError that i commented on my first
message, because of that i wrote over a "possible bug" in PIL, with
the hope that a developer of PIL could clarify this subject.

> But another option is to convert the image form palette to RGB (or RGBA0 with 
> PIL instead. Something like:
>
> im = PIL.Image(the_image_file)
> im = im.convert('RGB')

Yes, of course, it's a perfect and elegant solution (if you don't need
to manipulate the image in palette mode with QT), only fix the bug
could be better.

Thanks, Chris!

Maurice.
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to