[Qt-interest] Memory mapping QImage
Kustaa Nyholm
Kustaa.Nyholm at planmeca.com
Tue Apr 13 08:59:08 CEST 2010
Hi,
currently I'm copying the contents of a QImage to a memory mapped file
with something like this:
char* mmap = (char*) mmap(0, .....
for (int i=0; i<mImage.height(); ++i) {
uchar* p=;
memcpy(
mmap +i*mImage.bytesPerLine(),
mImage.scanLine(i) ,
mImage.bytesPerLine());
}
this works and is reasonably fast for my purpose.
However it seems slightly sub-optimal because of the
copying. Ideally I could just pass the memory mapped
file pointer to QImage to use as the pixel store
and no copying would be involved.
But I can't find a public method for that.
Is there some way to accomplish this?
I'm using the QImage as a paint device in a lighthouse
QPaintDevice *JEmbedWindowSurface::paintDevice()
{
return &mImage;
}
so it does not 'have to' be a QImage, but that
was the best I could find.
I could probably eliminate the for loop and
get away with a slightly faster:
memcpy(
mmap,
mImage.scanLine(0) ,
mImage.bytesPerLine()*mImage.height());
but that would violate the scanLine() contract, what?
br Kusti
More information about the Qt-interest-old
mailing list