image lib & Qt4
K.S.Sreeram
sreeram at tachyontech.net
Sat Jun 3 10:21:35 EDT 2006
thanks!
so does that mean the BGRA raw mode is supported in PIL 1.1.6?
Regards
Sreeram
Fredrik Lundh wrote:
> K.S.Sreeram wrote:
>
>> I was hacking the code trying to support RGBA mode images, and
>> inadvertently i tried im.tostring("raw","BGRX") on the RGBA mode image.
>>
>> So BGRX does indeed work for RGB mode images.
>>
>> While trying to support RGBA mode images, i realized that a BGRA raw
>> mode is needed for working with QImage. It doesn't seem to be supported
>> by PIL. Any workarounds?
>
> sure! here's a patch:
>
> Index: ImageQt.py
> ===================================================================
> --- ImageQt.py (revision 342)
> +++ ImageQt.py (working copy)
> @@ -58,6 +61,14 @@
> elif im.mode == "RGB":
> data = im.tostring("raw", "BGRX")
> format = QImage.Format_RGB32
> + elif im.mode == "RGBA":
> + try:
> + data = im.tostring("raw", "BGRA")
> + except SystemError:
> + # workaround for earlier versions
> + r, g, b, a = im.split()
> + im = Image.merge("RGBA", (b, g, r, a))
> + format = QImage.Format_ARGB32
> else:
> raise ValueError("unsupported image mode %r" % im.mode)
>
> </F>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20060603/6827b8b8/attachment.sig>
More information about the Python-list
mailing list