Results 1 to 4 of 4

Thread: QImage pixel manipulation access time/performance question

  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QImage pixel manipulation access time/performance question

    Hello,
    I have a small problem with the performance of my pixel manipulation approach.
    Currently I use something like this:
    Qt Code:
    1. QImage img;
    2. int valR = 0, value = 0;
    3. for( int i = 0; i < img.height(); ++i)
    4. {
    5. QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( i ) );
    6.  
    7. for( int j = 0; j < img.width(); ++j)
    8. {
    9. valR = qRed(scL[j]) + value;
    10.  
    11. scL[j] = qRgb( valR, valG, valB );
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    to access pixel data to manipulate.
    I use this code to show "preview" and I can see, while changing slider (connected to the value), that image changes not as fast as i.e. Photoshop (practically real time preview) or Gimp (little slower then PH but much faster then this). (I know that Ph probably use threads to utilize full cpu power, but even with my old cpu with only 1 core speed is much faster).

    Basically what I do is:
    1. load the data
    2. cpy data to QImage tmp
    3. manipulate
    4. change to QPixmap
    5. setPixmap on the QLabel

    Test shows me that execution is around 15-30ms for these 5 steps above so in theory I should have a smooth colour change while moving slider. (qDebug of time.elapsed). But that's don't happens (even with signal blocking for slider while this code execute).

    The question is what can cause such lag?
    Any suggestion are more then welcome.

    Best regards
    PS. sorry if this is wrong forum to post such a question.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  2. #2
    Join Date
    Mar 2006
    Posts
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage pixel manipulation access time/performance question

    Try "repaint" the QLabel right after setting the pixmap. "update" (imo called internally in "setPixmap" function) is not applied immediately.
    QWidget update
    repaint

  3. The following user says thank you to Rembobo for this useful post:

    Talei (12th November 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QImage pixel manipulation access time/performance question

    I use this code to show "preview" and I can see, while changing slider (connected to the value)
    It also can be that you are running the slot for each value change which will restart your loop again and again.
    Try to build in some logic either time based on mouse release, to only run the preview loop when its more or less certain that the current slider value is the value that needs to be previewed.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. The following user says thank you to high_flyer for this useful post:

    Talei (12th November 2010)

  6. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QImage pixel manipulation access time/performance question

    Thanks for reply. I will try to mess around with repaint in widget.

    @high_flyer
    (even with signal blocking for slider while this code execute).
    I already did that, and it's not working.
    Last edited by Talei; 12th November 2010 at 17:31.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. QImage.pixel and Format_Indexed8
    By chef_seppel in forum Newbie
    Replies: 2
    Last Post: 29th September 2010, 22:17
  2. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 10:25
  3. QImage direct pixel access.
    By hickscorp in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2010, 10:23
  4. QImage Pixel Coordinations
    By strateng in forum Newbie
    Replies: 2
    Last Post: 6th May 2010, 10:00
  5. QImage-Greyscale-8-bits-pixel
    By Ivan Labrador in forum Newbie
    Replies: 5
    Last Post: 3rd August 2008, 00: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.