[PyQt] QImage in BI24 format

Matt Newell newellm at blur.com
Wed Sep 19 17:31:55 BST 2012


On Wednesday, September 19, 2012 12:19:31 AM Gelonida N wrote:
> On 09/18/2012 08:13 PM, Gelonida N wrote:
> > Hi,
> > 
> > I have a C-library creating an image supposedly in in BI24 format (video
> > application)
> > 
> > Now I'd like to display the image.
> > 
> > I tried to set the pixel format to QImage.Format_RGB888
> > 
> > and I can see the image.
> > However the red and blue colors are inversed.
> > 
> > Is there another format, that can directly display the image?
> 
> I managed to convice the other application to create the images in RGB32
> So for the time being my problem is solved.
> 
> However I would still be interested to know, whether Qt can support the
> fourc 'BI24' format and if not, how one could convert most efficiently.
> 

Any conversion is going to need to be implemented in C++ for best speed.

If you are looking for very high performance then you can use an opengl view 
to display the image and use one of the various shader languages to do 
anything you want with the texture(image) data, swapping two color components 
is especially easy once the plumbing is done to get a working view with 
shaders. That way no conversion is necessary on the main CPU.  If you do it 
this way you can upload the image data to an opengl texture without ever 
copying it into a QImage.  This is most likely going to require C++, though it 
may be possible from pure python with some combination of non-PyQt bindings 
and/or ctypes.

If you need the data in a QImage or an OpenGL view is not out of the question 
for whatever reason you can write your own QImageIO plugin that does the 
conversion while copying the data into the QImage, this avoids iterating 
through the image data more than once. This will have to be done in C++.

The next best way is to simply use a loop to iterate through the pixels and 
use qRgb/qRgba to get and set the values.  This is by far the easiest and is 
most likely plenty fast for most applications on modern computers.  Of course 
it will be quite a bit slower if implemented in python compared to C++.

Matt


More information about the PyQt mailing list