Results 1 to 3 of 3

Thread: Shifting a QImage up by 1 pixel row

  1. #1
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Shifting a QImage up by 1 pixel row

    I was wondering if someone could suggest an efficient way to do this:

    I have a QImage of an arbitrary size. I want to very quickly transform this to a QImage of the same size with the entire image shifted up by one row of pixels. The bottom row of pixels will be the same color. In other words, I want to shift the top row of pixels out and shift in a new row at the bottom of pixels with the same color.

    I can think of ways to do this, but I need an extremely fast and efficient solution. Thoughts?

    Thanks in advance,
    MSUdom5

  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: Shifting a QImage up by 1 pixel row

    The fastest way would probably be this:

    Qt Code:
    1. QImage shiftUp(const QImage &original) {
    2. QImage shifted(original.size(), original.format());
    3. if(!original.colorTable().isEmpty())
    4. shifted.setColorTable(original.colorTable());
    5. uchar *data = original.bits();
    6. uchar *dest = shifted.bits();
    7. memcpy(dest, data+original.bytesPerLine(), original.numBytes()-original.bytesPerLine());
    8. return shifted;
    9. }
    To copy to clipboard, switch view to plain text mode 

    Then just fill the last row with your colour (you can probably use memset() to do that quickly).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    MSUdom5 (30th November 2009)

  4. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Shifting a QImage up by 1 pixel row

    If you're trying to do it without duplicating your image (e.g. working directly in your original image), you can use a convolution matrix of this vector:
    0 0 0
    0 0 0
    0 1 0
    Or more simply:
    0
    0
    1

    Pierre.

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. Multithreaded per pixel operations on QImage
    By N¤X in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2009, 12:29
  3. Multiple QPainters on QImage
    By fire in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2008, 13:10
  4. QPixmap pixel by pixel ?
    By tommy in forum Qt Programming
    Replies: 19
    Last Post: 3rd December 2007, 22:52
  5. QShared
    By sabeesh in forum Qt Programming
    Replies: 11
    Last Post: 11th October 2007, 12:40

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.