From pykde Sun Jul 12 17:38:29 2009 From: Phil Thompson Date: Sun, 12 Jul 2009 17:38:29 +0000 To: pykde Subject: [PyQt] Re: QImage constructors Message-Id: <8c602056e1769a458fddcec42b0e92ad () localhost> X-MARC-Message: https://marc.info/?l=pykde&m=124742069404647 On Thu, 09 Jul 2009 14:47:25 +0200, Giovanni Bajo 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 _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt