[Interest] Fastest Way to convert a QVideoFrame to an QImage?

Thiago Macieira thiago.macieira at intel.com
Wed Feb 12 03:00:51 CET 2014


Em ter 11 fev 2014, às 14:32:10, Jason H escreveu:
> constuchar*bits=frame.bits();
> for(inty=0;y<frame.height();y++)
> {
> QRgb*scanLine=(QRgb*)converted.scanLine(y);
> for(intx=0;x<frame.width();x++)
> {
> intc=bits[y*frame.width()+x];
> scanLine[x]=qRgba(c,c,c,255);
> }
> }

You should add spaces, otherwise your code won't compile.

You can also try this as the inner loop (assumes the width is a multiple of 
4). It requires SSSE3:

	_m128i control = _mm_set_epi32(0xff030303, 0xff020202, 
		0xff010101, 0xff000000);
	for (int x = 0; x < frame.width(); x += 4) {
		// load 4 Y bytes
		uint yyyy = *(uint *)&bits[y*frame.width() + x];

		// transfer to SSE register
		__m128i data = _mm_cvtsi32_si128(yyyy);

		// spread it out to the right lanes and fill in the alpha channel
		__m128i rgba = _mm_shuffle_epi8(data, control);

		// store
		_mm_storeu_si128((__m128i*)&scanLine[x], rgba);
	}

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center



More information about the Interest mailing list