[Qt-interest] Quicktime C -> QImage
Stephen Chu
stephen at ju-ju.com
Mon Apr 19 23:35:55 CEST 2010
In article <20100419211825.217320 at gmx.net>,
"Alexander Carôt" <alexander_carot at gmx.net> wrote:
> Hi Stephen,
>
> yes, it worked out bypassing the CGImage. Furthermore, it was indeed an
> endinaness problem, however, I couldn't fix it as you proposed (changing the
> mode) such as
>
> **************
> createDecompressionSession(imageDesc,videoData->width,videoData->height,k32BGR
> APixelFormat,displayAndCompressFrame,videoData,&videoData->decompressionSessio
> n);
> *************
>
> Not sure why this didn't work out but recoding the byteswap loop fixed it:
>
> ***************
> size_t width, height, rowBytes, bitsPerComponent;
> void *baseAddr = NULL;
> CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
> baseAddr = CVPixelBufferGetBaseAddress( pixelBuffer );
> width = CVPixelBufferGetWidth( pixelBuffer );
> height = CVPixelBufferGetHeight( pixelBuffer );
> unsigned char *rawData = new unsigned char[1000000];
> rawData = (unsigned char*) baseAddr;
>
> unsigned char theRed,theGreen,theBlue,theAlpha;
>
> int i = 0;
> do{
> theAlpha = rawData[i];
> theRed = rawData[i+1];
> theGreen = rawData[i+2];
> theBlue = rawData[i+3];
> rawData[i] = theBlue;
> rawData[i+1] = theGreen;
> rawData[i+2] = theRed;
> rawData[i+3] = theAlpha;
> i = i + 4;
> }
> while(i < 400000);
>
> currentObject->displayImage = new
> QImage(rawData,320,240,QImage::Format_ARGB32);
>
> currentObject->update();
> *******************
>
> So all fine for now,
> thanks again,
> best
>
I am not familiar with either QuickTime or CoreVideo so I can't say how
to get it to flip the bytes for you.
Now for the endian swapping, this should work better:
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
quint32 * p = (quint32*) baseAddr;
for(int i=0;i<numPixels;++i) {
p[i] = qToBigEndian(p[i]);
}
#endif
You don't need to do this on a big endian machine since the byte order
is already what Qt wants.
Happy coding.
--
Stephen Chu
More information about the Qt-interest-old
mailing list