[Interest] allocate QImage data in QSharedMemory

Joshua Grauman jnfo-c at grauman.com
Mon Dec 12 22:45:58 CET 2016


Hello all,

I have been able to generate a screen capture of my program by rendering a 
window into a QImage at 30fps (called from QTimer), and then copying the 
QImage to shared memory (QSharedMemory) where another program grabs the 
frames and outputs them to ffmpeg. It all works great.

However, my cpu is barely keeping up if I do much on my app.

One of the ways I thought of to speed it up is to avoid the memcpy from 
the QImage (img) to QSharedMemory (sharedMemory) by deriving from QImage 
to a new class (QSharedMemoryImage) which allocates its image data in 
shared memory to begin with so that the window->render() function renders 
the window right into shared memory so the copy isn't necessary. QImage 
was a bit too complex for me to figure out how to do this.

For you experts, is this possible? How hard would it be?

Here's the relevant code in the QTimer:

   window->render(&img, QPoint(), QRegion(), QWidget::DrawChildren);
   sharedMemory.lock();
   char *to = (char*)sharedMemory.data();
   const unsigned char *from = img.constBits();
   memcpy(to, from, sharedMemory.size());
   sharedMemory.unlock();

Josh



More information about the Interest mailing list