[Qt-interest] how to speed up code?

Peter.Walton at pace.com Peter.Walton at pace.com
Thu Jul 9 13:32:29 CEST 2009


Something like :-

   unsigned int *p;
   int i,k;

   p = (unsigned int *) &bits[ 0 ];
   k = 0;
   for ( i = 0; i < len; i++ )
   {
#if 0
      bits[ i * 4 ] = dst_buf[ i * 3 ];
      bits[ (i * 4) + 1 ] = dst_buf[ (i * 3) + 1 ];
      bits[ (i * 4) + 2 ] = dst_buf[ (i * 3) + 2 ];
#else
      *p = dst_buf[ k ] | (((unsigned int) dst_buf[ k + 1 ]) << 8) |  (((unsigned int) dst_buf[ k + 2 ]) << 16);
      p++;
      k += 3;
#endif
   }

This shows a speed up of about x 2.5, but depends on compiler etc (make sure its optimising as this will have greatest effect).  Also above code makes some assumptions about size of unsigned int's and endian of your system that may not be true :)



-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com]On Behalf Of Srdjan Todorovic
Sent: 09 July 2009 10:19
To: qt-interest
Subject: Re: [Qt-interest] how to speed up code?


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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


 Click https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==  to report this email as spam.

This E-mail and any attachments hereto are strictly confidential and intended solely for the addressee. If you are not the intended addressee please notify the sender by return and delete the message. You must not disclose, forward or copy this E-mail or attachments to any third party without the prior consent of the sender. Pace plc is registered in England and Wales (Company no. 1672847) and our Registered Office is at Victoria Road, Saltaire, West Yorkshire, BD18 3LF, UK. Tel +44 (0) 1274 532000 Fax +44 (0) 1274 532010. <http://www.pace.com>
Save where otherwise agreed in writing between you and Pace (i) all orders for goods and/or services placed by you are made pursuant to Pace's standard terms and conditions of sale which may have been provided to you, or in any event are available at http://www.pace.com/uktcsale.pdf (ii) all orders for goods and/or services placed by Pace are subject to Pace's standard terms and conditions of purchase which may have been provided to you, or in any event are available at http://www.pace.com/uktcpurch.pdf. All other inconsistent terms in any other documentation including without limitation any purchase order, reschedule instruction, order acknowledgement, delivery note or invoice are hereby excluded.



This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com




More information about the Qt-interest-old mailing list