Results 1 to 4 of 4

Thread: QImage vs QPixmap the eternal dilemma of good drawing performance on linux

  1. #1

    Default QImage vs QPixmap the eternal dilemma of good drawing performance on linux

    So some background information about my problem. I have a program which displays images coming from webcam. The program works just fine, but the frame rate never reaches anywhere near the 30 which is coming from the camera. I have pinpointed the issue and it is with converting QVideoFrame to QImage and then drawing the image. On windows this code works fine and the whole drawing process takes about 2ms. On linux it's completely different story, drawing the QImage takes more than 20ms which may not sound like much but when it's added for every frame the framerate drops to half of what it should be.

    Now i know drawing QImages is slow on linux environments from doing some research but i have no clue how to convert the QVideoFrame straight to QPixmap which is faster to draw. Using QPixmap::fromImage() is not viable solution because that is slow as well.

    Current implementation for drawing the image coming from the webcam.

    Qt Code:
    1. if(mVFcurrentFrame.map(QAbstractVideoBuffer::ReadOnly))
    2. {
    3. QImage image(mVFcurrentFrame.bits(), mVFcurrentFrame.width(), mVFcurrentFrame.height(), mVFcurrentFrame.bytesPerLine(), imageFormat);
    4. painter->drawImage(0,0,image); //Takes about 20ms
    5. mVFcurrentFrame.unmap();
    6. }
    To copy to clipboard, switch view to plain text mode 

    So my questions are:

    Is it possible to convert QVideoFrame straight to QPixmap and would it be a viable solution?

    Is there some other way i could speed up the drawing process?
    Last edited by MidWay; 13th May 2014 at 10:54.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage vs QPixmap the eternal dilemma of good drawing performance on linux

    Traditionally a QPixmap refers to an image in the memory of the graphics system, on X11 in the memory managed by the XServer.
    A QImage on the other hand is data in the program's memory.

    So converting an QImage to a QPixmap meant transferring data and/or using something like shared memory.

    However, nowadays that is not necessarily true, as there are various ways of how Qt abstracts the platform's graphics system.

    Which Qt version are you using?

    Cheers,
    _

  3. #3

    Default Re: QImage vs QPixmap the eternal dilemma of good drawing performance on linux

    Quote Originally Posted by anda_skoa View Post
    Traditionally a QPixmap refers to an image in the memory of the graphics system, on X11 in the memory managed by the XServer.
    A QImage on the other hand is data in the program's memory.

    So converting an QImage to a QPixmap meant transferring data and/or using something like shared memory.

    However, nowadays that is not necessarily true, as there are various ways of how Qt abstracts the platform's graphics system.

    Which Qt version are you using?

    Cheers,
    _
    I'm using Qt 4.74. If there is any additional information you need i'm happy to provide it.

    The current flow is

    When new QVideoFrame is available it's brought to subclassed QVideoWidgetSurface via VideoWidgetSurface:resent(const QVideoFrame &frame) method which calls repaint() and generates the QImage from the QVideoFrame data and draws it.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage vs QPixmap the eternal dilemma of good drawing performance on linux

    You could try experiementing with the -graphicssystem commandline switch (or QApplication::setGraphicsSystem), e.g. checking if there is a difference between "native" and "raster".

    If your source can deliver multiple formats, you can also check if you might currently be using one that requires lots of conversions, e.g. different color depth, etc.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 8th May 2009, 13:37
  2. Replies: 4
    Last Post: 8th May 2009, 13:04
  3. drawing on a QPixmap or QImage
    By gren15 in forum Newbie
    Replies: 15
    Last Post: 3rd March 2009, 18:48
  4. Replies: 4
    Last Post: 28th August 2008, 14:13
  5. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 18:11

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.