Results 1 to 3 of 3

Thread: painting raw u16 memory

  1. #1
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default painting raw u16 memory

    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:

    Qt Code:
    1. for( unsigned i = 0 ; i < nHeight ; ++i )
    2. {
    3. for( unsigned j = 0 ; j < nWidth ; ++j )
    4. {
    5. //covert from 565 to rgb
    6. tRgb col( tRgb::sf_ColorConvert( m_pFrameBuffer[ nWidth * i + j ] ) );
    7. //set pen color
    8. pen.setColor( QColor( col.r, col.g, col.b ) );
    9. painterken.setPen( pen );
    10. //paint the pixel
    11. painterken.drawPoint( j, i );
    12. }
    13. }
    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: painting raw u16 memory

    Quote Originally Posted by stinos
    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.

  3. #3
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: painting raw u16 memory

    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..

Similar Threads

  1. vector memory allocation
    By TheKedge in forum General Programming
    Replies: 1
    Last Post: 23rd March 2006, 17:27
  2. why there are memory leaks in Qt?
    By cocalele in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2006, 09:55
  3. Replies: 2
    Last Post: 13th February 2006, 15:42
  4. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 12:47
  5. Trouble with image painting (QPainter + QImage)
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 20:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.