[Qt-embedded-interest] QImage Format and YCbCr Conversion

Tom Cooksey thomas.cooksey at nokia.com
Fri Jul 17 08:47:03 CEST 2009


> Qt List,
>     So I finally managed to get some sort of data to the screen! 
> Thank you for all the help and suggestions.  If it is of any
> significance (probably not) most of the screen is green.  Anyway,
> my screen wants to see YCbCr pixels so I must convert, and I do
> have a conversion from a previous project that used C but not Qt. 
> So my questions are:
>
>
>  *   How to I know what image format is passed to the blit
> function? 

QScreen::blit() passes you a QImage. You can find out the pixel format 
using QImage::format().


> *   Can I simply use the QImage::Format_ARGB32; or
> similar in the connect member to specify? 

The format Qt chooses for window surfaces depends on weather the 
surface needs an alpha channel or not. If an alpha channel isn't 
needed, it will simply use the same format as the screen is in, as 
returned by QScreen::pixelFormat(). If an alpha channel is needed, the 
format is based on QScreen::depth() and you can see the selection 
algorithm in QWSMemorySurface::preferredImageFormat() in 
qwindowsurface_qws.cpp. Although I guess you probably don't want top-
level window transparency?


> *   What is the best way
> to go about ripping the R,G,and B values from the data.

You can thus get a pointer to the raw data using const version of 
QImage::bits() (make you you use the const version, otherwise it will 
do a copy!). You can then access the pixel data directly. 
Alternetively, you could also use QImage::pixel() which will return a 
QRgb which allow accessing Red, Green & Blue channels seperately - 
although doing that will be significantly slower.


Cheers,

Tom





More information about the Qt-embedded-interest mailing list