[Qt-interest] how to speed up code?

Igor Sobinov sluge at mail.ru
Thu Jul 9 09:48:29 CEST 2009


hello all

I develop application that get images from web camera and show it in Qt widget. 

My code is:

//if we need to convert image formatsd, let's convert it
if(m_destFmt != m_srcFmt)
{
const int ret = v4lconvert_convert(m_convertData, &m_srcFmt, 
&m_destFmt, (uchar*)m_buffers[buf.index].m_address, 
m_buffers[buf.index].m_len, 
dst_buf, m_destFmt.fmt.pix.sizeimage);

if(ERR_RET == ret)
{
qDebug("Error conversion libv4l");
return;
}
}
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;
}

QPixmap pix;
//very slow convertion
if(!pix.convertFromImage(img))
qDebug("Error convertiong pixmap");
//send image to display in widget
emit setImage(pix);
//fps calculation
m_fpsCount++;


actually camera sends 25 frames per second, but because of very slow image converion operation real FPS is 1-2  ;(

Is any way to improve perfomance of this code? 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/c83c228d/attachment.html 


More information about the Qt-interest-old mailing list