[Qt-interest] Quicktime C -> QImage

Stephen Chu stephen at ju-ju.com
Mon Apr 19 18:57:40 CEST 2010


I don't see how you get pixelBuffer. But if you can, use 
k32BGRAPixelFormat to create it on Intel and k32ARGBPixelFormat on PPC. 
Or if you want to skip the endian issue altogether, use 
k24RGBPixelFormat which is equivalent to QImage::Format_RGB888.

And again, there's no need to go to a CGImage then to a QImage:

CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
int rowBytes = CVPixelBufferGetBytesPerRow( pixelBuffer );
uchar * baseAddr = CVPixelBufferGetBaseAddress( pixelBuffer );
int width = CVPixelBufferGetWidth( pixelBuffer );
int height = CVPixelBufferGetHeight( pixelBuffer );

QImage   image(baseAddr,width,height,rowBytes,QImage::Format_ARGB32) 
should get you the right image to display.


In article <20100419153529.223700 at gmx.net>,
 "Alexander Carôt" <alexander_carot at gmx.net> wrote:

> Hello again (forgot the attachement),
> 
> regarding my color problem I attached a screenshot of the actual image I get 
> when mapping the pixels of a CGImage onto a QImage: The image is kind of 
> blue/white (pillow should be red, pullover shuld be green and skin white).
> 
> The full mapping sequence looks like this:
> 
> *****************************
> CGImageRef image = NULL;
> 
> size_t width, height, rowBytes, bitsPerComponent;
> CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
> rowBytes = CVPixelBufferGetBytesPerRow( pixelBuffer );
> baseAddr = CVPixelBufferGetBaseAddress( pixelBuffer );
> width = CVPixelBufferGetWidth( pixelBuffer );
> height = CVPixelBufferGetHeight( pixelBuffer );
> colorspace = CGColorSpaceCreateDeviceRGB();
> CVBufferRetain( pixelBuffer );
> provider = CGDataProviderCreateWithData( pixelBuffer, baseAddr, rowBytes 
> *height, releaseAndUnlockThis );
> image = CGImageCreate( width, height, 8, 32, rowBytes, colorspace, 
> kCGImageAlphaNoneSkipFirst, provider, NULL, true, kCGRenderingIntentDefault 
> );
> 
> unsigned char *rawData = new unsigned char[1000000];
> unsigned char backup;
> 
> CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(image));
> rawData = (unsigned char*) CFDataGetBytePtr(data);
>  
> if (data != NULL){
>   currentObject->displayImage = new 
>   QImage(rawData,320,240,QImage::Format_RGB32);   
>   currentObject->update();
> }   
> *****************************
>  
> I already changed the formats but this made it even worse. Furthermore I did 
> a manua byte swap of the raw data buffer:
> 
>   for (int i=0;i<100000;i=i+2){
>     backup = rawData[i];
>     rawData[i]=rawData[i+1];
>     rawData[i+1] = backup;
>   } 
>  
> but this painted swapped range in green.
> 
> I anyone might know what the problem might be I'd appreciate any hint.
> 
> Thanks a lot in advance
> 
> -- A l e x

-- 
Stephen Chu



More information about the Qt-interest-old mailing list