[PyQt] Re: QImage constructors

Phil Thompson phil at riverbankcomputing.co.uk
Sun Jul 12 18:38:29 BST 2009


On Thu, 09 Jul 2009 14:47:25 +0200, Giovanni Bajo <rasky at develer.com>
wrote:
> Hi Phil,
> 
> QImage has four different constructors that use existing pixel data:
> 
>      QImage(uchar *data, int width, int height, Format format);
>      QImage(const uchar *data, int width, int height, Format format);
>      QImage(uchar *data, int width, int height, int bytesPerLine, Format 
> format);
>      QImage(const uchar *data, int width, int height, int bytesPerLine, 
> Format format);
> 
> The "const uchar *" are semantically different from the "uchar *" ones; 
> quoting the Assistant of the const version:
> 
> =====================================================================
> Unlike the similar QImage constructor that takes a non-const data 
> buffer, this version [the const one] will never alter the contents of 
> the buffer. For example, calling QImage::bits() will return a deep copy 
> of the image, rather than the buffer passed to the constructor. This 
> allows for the efficiency of constructing a QImage from raw data, 
> without the possibility of the raw data being changed.
> =====================================================================
> 
> Unfortunately it looks like PyQt does not wrap the non-const version. 
> This is specifically useful because I'm trying to construct QImage over 
> a shared memory area and I would like to be able to modify it in-place.
> 
> Since QSharedMemory.data() returns a sip.voidptr, I suggest declaring 
> the missing constructors as taking a "void*" as first argument for now; 
> this would be backward compatible and make my own use case work. For 
> Python 3.0, you might want to explore the usage of bytes() vs
bytearray().
> 
> Let me know if it makes sense. Thanks!

In tonight's snapshot - I'll leave the testing to you...

Phil


More information about the PyQt mailing list