Results 1 to 5 of 5

Thread: Vertically flipped QImage.

  1. #1
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Vertically flipped QImage.

    Hello guys, I've a map_server that reads in a PGM file yet prints out a flipped image of it on a QImage. Here is my code.

    Qt Code:
    1. int width = msg->info.width;
    2. int height = msg->info.height;
    3. const std::vector<int8_t>& data (msg->data);
    4. unsigned char *p, *q;
    5.  
    6. if( mapImage == NULL ) {
    7. lineImage = new unsigned char[ width * 3 ];
    8. mapImage = new QImage( width, height, QImage::Format_RGB888 );
    9. }
    10.  
    11. if( mapImage != NULL ) {
    12. for( int i = 0; i < height; i++ ) {
    13. q = lineImage;
    14. p = ( unsigned char * )&data[ i * width ];
    15. for( int j = 0; j < width; j++ ) {
    16. *q++ = *p;
    17. *q++ = *p;
    18. *q++ = *p;
    19. p++;
    20. }
    21. memcpy( mapImage->scanLine( i ), lineImage, width * 3 );
    22. }
    23. }
    24.  
    25. printf( "Map received!\n" );
    To copy to clipboard, switch view to plain text mode 


    The "for loop" for height takes in from "0" till the limit(height) and I can assume that the picture it reads in the limit, till "0".
    But everything seems to be in placed and correct. I'm lost to what I can do to correct this "wrong".

    Would greatly appreciate your help! Thanks.

    JeremyEthanKoh.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertically flipped QImage.

    Hi, it's not directly related to your code, but I think you should be able to flip the image using a QMatrix and QImage::transformed().

    Ginsengelf

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Vertically flipped QImage.

    Maybe your input data is flipped.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Vertically flipped QImage.

    The "for loop" for height takes in from "0" till the limit(height) and I can assume that the picture it reads in the limit, till "0".
    But everything seems to be in placed and correct. I'm lost to what I can do to correct this "wrong".
    QImage (and all other Qt objects with pixel-based coordinates) assign pixel (0, 0) to the upper left corner. Your map server apparently assumes that the (0, 0) map coordinate is in the lower left corner. This would make sense for a geographical map.

    You can fix this by assigning your scan lines from the top down:

    Qt Code:
    1. memcpy( mapImage->scanLine( height - i - 1 ), lineImage, width * 3 );
    To copy to clipboard, switch view to plain text mode 


    ------------------
    If the original designers of the oscilloscope (and its descendent, the television) had designed it to draw the scan lines from the bottom up, instead of from the top down, we wouldn't have this (0,0) at the top left corner problem. (0,0) would be at the bottom right where it makes sense, and we wouldn't be faced with having to flip y coordinates for everything we draw. It wouldn't have been hard - all they would have had to do is change the polarity on the CRT deflection plates. See how decisions made nearly a century ago still haunt us?
    Last edited by d_stranz; 8th August 2014 at 17:28.

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

    xtrememoo (11th August 2014)

  6. #5
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Vertically flipped QImage.

    Yep that's what I needed! Thanks so much.

Similar Threads

  1. QCamera images flipped on Windows platform
    By jas67 in forum Qt Programming
    Replies: 4
    Last Post: 22nd March 2013, 13:21
  2. QScrollArea that only scrolls vertically
    By stephelton in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2013, 12:48
  3. Align vertically QwtPlot
    By Valsylver in forum Qwt
    Replies: 1
    Last Post: 4th August 2012, 13:44
  4. Rezizing the Qlabels vertically
    By anju123 in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2008, 16:35
  5. How can I write vertically in a QPushbutton ?
    By castorvert in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2006, 22:27

Tags for this Thread

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.