Results 1 to 8 of 8

Thread: waterfall display

  1. #1
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default waterfall display

    Hello,

    Sorry I needed help in creating a "waterfall display" which basically takes in a 2 dimensional array of 8bit pixels and displays it streaming down the screen. This data is just 8bit pixel data and keeps streaming into my display.

    Currently I just copy the data into a QImage with width and height equal to the size of the screen:

    screenImage = new QImage(desktop.width(),desktop.height(),QImage::Fo rmat_Indexed8);

    and print it to screen. Each time I have more pixel data coming in, I memmove the data in the qimage down and repaint the qimage using paintEvent.

    Obviously this is kind of slow because I have to repaint the qimage each time. Can somebody please please help me optimize by explaining a better method or pointing me in the right direction?

    Thank you,
    James
    Last edited by jmsbc; 14th November 2008 at 03:08.

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

    Default Re: waterfall display

    Could we see the exact code? I mean the one used for filling the image with data and the one for rendering it to the widget.

  3. #3
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: waterfall display

    Hi Wysota,

    Thanks for replying. Sure, here is the general idea:

    Qt Code:
    1. GLWidget::GLWidget(QGLWidget *parent)
    2. :QGLWidget(parent)
    3. {
    4.  
    5. // Initialize new QImage to 8bit format
    6. screenImage = new QImage(desktop.width(),desktop.height(),QImage::Format_Indexed8);
    7.  
    8. /* Initialize image array */
    9. for (int i=0; i<BUFFERSIZE; i++) {
    10. imageBuffer[i] = (unsigned char)(i % 256);
    11. }
    12.  
    13. /* Start timer to repaintevent */
    14. QTimer *timer = new QTimer(this);
    15. connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
    16. timer->start(10);
    17. }
    18.  
    19. void GLWidget::animate()
    20. {
    21. update();
    22. }
    23.  
    24. void GLWidget::paintEvent(QPaintEvent *)
    25. {
    26. QPainter painter(this);
    27.  
    28. /* Memcopy pixel data into my QImage FRAMESIZE lines at a time */
    29. for (int i=FRAMESIZE-1; i>=0; i--) {
    30. memcpy(screenImage->scanLine(i),&imageBuffer[(imageLine*imageWidth)%BUFFERSIZE],imageWidth);
    31. imageLine++;
    32. }
    33.  
    34. // Draw the QImage to screen
    35. painter.drawImage(0,0,*screenImage);
    36.  
    37. // Shift qimage down to look like it is streaming down the screen
    38. memmove(screenImage->scanLine(FRAMESIZE),screenImage->scanLine(0),linesFilled*screenImage->bytesPerLine());
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

    Basically I'm calling paintEvent() as often as possible using the timer set on a small time interval. Please help as I've already been searching many hours on a good solution.

    Thanks a lot!
    -James
    Last edited by jmsbc; 14th November 2008 at 19:44.

  4. #4
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: waterfall display

    Qwt has a spectrogram plot that you could animate? Could be ideal if you need more flexibility.
    Best Regards,
    Phil Winder
    www.philwinder.com

  5. #5
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: waterfall display

    Hi Phil,

    Sorry I should clarify, my Qimage has dimensions of my monitor, basically 1600X1200. So it is actually an image that's streaming down my display. I'm not sure if that spectrogram plot would work, but I'll take a look. Thanks.

    In the meantime, Wysota do you have any hints? Thanks.
    Last edited by jmsbc; 14th November 2008 at 23:14.

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

    Default Re: waterfall display

    First thing to do is to change
    Qt Code:
    1. timer->start(10);
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. timer->start(50);
    To copy to clipboard, switch view to plain text mode 
    . You won't be able to see 100 frames per second so you can safely limit it to 20 frames per second. You should immediately get a five times increase in speed

    Second of all you are murdering your processor data cache by processing data from the last line to the first one. Try reversing the order and you should get significant speedup there. It would also be a good idea to process data in larger chunks instead of single lines. Using a chunk of size equivalent to memory page size in your platform (like 1kB or 4kB) should result in a better speed as well.

    All this should already give you much. If that's not enough, we can go further.

    One more thing - don't expect miracles when scrolling such a large image. Currently used graphics architectures are not prepared for good scrolling performance (contrary to times where most games involved scrolling the "game board").

  7. #7
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: waterfall display

    Wysota!

    Thanks for your suggestions. However, the problem exists in the paintEvent not being able to draw a big QImage fast enough. Addressing your suggestions:

    1. The timer is just set to be as fast as possible, so paintEvent gets called as often as possible. I changed it up to 50 but there's no difference because drawImage is the limiting factor.

    2. Even if I change the memcopy/memmove functions around, they're not the limiting factor, drawImage() is. I tried changing my memcopy to copy bigger chunks of data but I still get the same performance.

    I'm wondering if there some hardware acceleration that can be done to paint the images faster. Also are there other possibilites with openGL? I don't know much about graphics so if somebody could give me some guidance that would be great.

    Thanks!

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

    Default Re: waterfall display

    Quote Originally Posted by jmsbc View Post
    1. The timer is just set to be as fast as possible, so paintEvent gets called as often as possible. I changed it up to 50 but there's no difference because drawImage is the limiting factor.
    Good.

    2. Even if I change the memcopy/memmove functions around, they're not the limiting factor, drawImage() is. I tried changing my memcopy to copy bigger chunks of data but I still get the same performance.
    If you still build the image from end to the beginning, you waste cycles which could be spent on rendering.

    I'm wondering if there some hardware acceleration that can be done to paint the images faster. Also are there other possibilites with openGL?
    Use your image as a texture for an OpenGL rectangle that you put orthogonally on your screen. Using some OpenGL extensions you'll gain additional speedup while building the texture if you don't build it from scratch at each frame but instead reuse what you already have.

Similar Threads

  1. Replies: 8
    Last Post: 18th March 2011, 12:27
  2. OS/X how to get physical display handle
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2009, 20:51
  3. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 16:36
  4. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 22:55
  5. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 08:08

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.