PDA

View Full Version : painting raw u16 memory



stinos
5th September 2006, 18:54
Hi all!

Is there a way to have QPainter paint a raw memory buffer, in the same way a framebuffer paints a screen?
What I'm trying to achieve is a simple framebuffer "emulation" using Qt: I have a FrameBuffer class which is implemented on different embedded platforms, and basically just opens a /dev/fbxx device and returns the frame buffer pointer from it.
All classes rendering to the screen just fill the buffer pointed to with the stuff they want to render.
Rendering on these devies is with 16 bit unsigned short pixels, I use a 565 conversion from rgb to pixel values.
Since the developping process for the devices is quite slow, much slower compared to what I can do on a pc, I just wanted to have something that behaves like the FrameBuffer, but prints on a QApplication window on the desktop.
Currently I just use a u16 buffer, pass it to the render classes, and when it returns I paint all the pixels one by one with a QPainter, something like this:



for( unsigned i = 0 ; i < nHeight ; ++i )
{
for( unsigned j = 0 ; j < nWidth ; ++j )
{
//covert from 565 to rgb
tRgb col( tRgb::sf_ColorConvert( m_pFrameBuffer[ nWidth * i + j ] ) );
//set pen color
pen.setColor( QColor( col.r, col.g, col.b ) );
painterken.setPen( pen );
//paint the pixel
painterken.drawPoint( j, i );
}
}


Needless to say, this is *terribly* slow; it doesn't really matter since I just use it for debugging the code, but still, it takes like 1 second to draw a 720*480 screen. Aargh.
Speed could be improved a little bit by having the color conversion method return a Qt RGB val, but that's not the real problem here.
I'd guess my best bet would be to pass the whole memory block to a QImage, but I can't figure out which flags I'd have to use, I don't get anything usable back from it.
Any help is highly appreciated!

wysota
5th September 2006, 20:40
I'd guess my best bet would be to pass the whole memory block to a QImage, but I can't figure out which flags I'd have to use, I don't get anything usable back from it.

Try QImage::loadFromData(). If you're using Qt4 (or its embedded equivalent) you might want to implement your own paint engine.

stinos
6th September 2006, 10:45
Using Qt4 I can get close indeed: if I fill an unsigned int buffer with all pixels converted to QRGB format, and use the QImage( uchar* data, int w, int h, Format format ) constructor with format = Format_RGB32 it works quite ok (I'm loosing color info due to conversion from 565 - > QRGB)
Appearantly I should have Qtopia Core: that has a QImage::Format_RGB16 flag that uses the 565 scheme, so there it would just be a matter of constructing the QImage and painting it, without any conversions needed..