[Qt-interest] how to speed up code?
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Thu Jul 9 10:52:48 CEST 2009
Igor Sobinov wrote on Thursday, July 09, 2009 9:48 AM:
> ...
> else//no conversion is needed
> memcpy(dst_buf, (uchar*)m_buffers[buf.index].m_address,
> m_buffers[buf.index].m_len); //creating QImage QImage
> img(m_destFmt.fmt.pix.width, m_destFmt.fmt.pix.height, 32); //Convert
> from 24 to 32 bbp uchar* bits = img.bits();
> const uint len = img.width()*img.height(); bzero(bits, len); //very
> slow loop for (int i = 0; i < len; i++) { bits[4*i ] = dst_buf[3*i];
> bits[4*i+1] = dst_buf[3*i+1]; bits[4*i+2] = dst_buf[3*i+12; }
Sorry, your code is a bit hard to read, because it does not seem to be (ASCII) formatted at all, but anyway, you are doing a lot of index arithmetic here (array[index + 1] etc.) which is sloooooow. You should really be using something like "memcpy", that is copy the entire image data *at once* into the buffer of the QImage (making sure that the format matches and the byte-alignment is the same as being used by QImage.
That loop above I assume is responsible for most of the performance loss (your 1-2 FPS vs the desired 24 FPS).
As I understand your code you are trying to copy the image pixel by pixel into a QImage, and then...
> QPixmap pix;
> //very slow convertion
> if(!pix.convertFromImage(img))
... convert that QImage into a QPixmap for display.
The optimal solution (for the simple case, that is 32 bpp display, 32bpp video data) would be to somehow transfer the decoded video frame directly into a QPixmap.
You seem to be on Linux/Unix (with Qt 3 btw?), you might try to play around with
http://doc.qtsoftware.com/4.5/qpixmap.html#fromX11Pixmap
assuming that you are somehow able to get an X11 "pixmap handle" from video4linux (that's what you are using, right?). Also note that the above method was only introduced in Qt 4.5.
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list