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 );
}
}
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 );
}
}
To copy to clipboard, switch view to plain text mode
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!
Bookmarks