[Qt-interest] how to speed up code?

Srdjan Todorovic todorovic.s at googlemail.com
Thu Jul 9 11:18:43 CEST 2009


Hi,

On 09/07/2009, Oliver.Knoll at comit.ch <Oliver.Knoll at comit.ch> wrote:
> 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

Email seemed fine here ;)

> 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.

No he's not trying to do a stright copy of the pixel data.
I think he's trying to copy a 24bit pixel to a 32bit pixel, so has to
skip one of the bytes out from the destination buffer.

I *think* this is what he wants:

dest[0]  = src[0];
dest[1] = src[1];
dest[2] = src[2];
// skip 3
dest[4] = src[3];
dest[5] = src[4];
dest[6] = src[5];
//skip 7
dest[8] = src[6];
....

> 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.

What if the video data is not 32bpp ?

Srdjan



More information about the Qt-interest-old mailing list