PDA

View Full Version : [PyQt4]C array to QImage



vasko_v_v
8th July 2009, 20:07
Hi,
I am writing an application in PyQt which draws the MandlebrotSet fractal. If i use pure python the rendering of a 500x500 matrix takes approximately 20 sec :) So i wrote a C DLL which does the computations for 1 sec at most and saves the data in an array(char / int / void *, whatever you like). My question is how can i transfer the data from the array to a QImage object without iterating over each pixel i.e. how can i copy the whole block of data from the array to the QImage object.
Also, if you have better ideas for faster computation, I'll be very thankful :)

remi
19th July 2009, 17:43
Have you tried the QImage(sip.voidptr data, int width, int height, Format format) (http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qimage.html#QImage-5) constructor? The first argument, data, should be just what you're looking for: it's a void * pointing to the beginning of your data array. Be sure to set Format correctly, so that QImage knows how to interpret your data array.

As for faster image computations: check out the Python Image Library (PIL) (http://www.pythonware.com/products/pil/). It's a powerful (and fast) module for image creation / manipulation. You should get a nice performance boost if you can use PIL for some of your work.