[Qt-interest] Quicktime C -> QImage

"Alexander Carôt" alexander_carot at gmx.net
Mon Apr 19 23:18:25 CEST 2010


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,k32BGRAPixelFormat,displayAndCompressFrame,videoData,&videoData->decompressionSession);
*************

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

-- A l e x




-------- Original-Nachricht --------
> Datum: Mon, 19 Apr 2010 12:57:40 -0400
> Von: Stephen Chu <stephen at ju-ju.com>
> An: qt-interest at trolltech.com
> Betreff: Re: [Qt-interest] Quicktime C -> QImage

> 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

-- 
http://www.carot.de
http://www.triologue.de
Email : Alexander at Carot.de
Tel.: +49 (0)177 5719797



GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



More information about the Qt-interest-old mailing list