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.