# include # include using namespace std; int main ( ) // // MONA_REVERSE reads data from a PGM graphics file of the Mona Lisa, // reverses the gray scale colors, and writes out the new data. // // The program should be run with commands like: // // g++ mona_reverse.cpp // mv a.out mona_reverse // ./mona_reverse < mona.pgm > mona_reverse.pgm // { char c1, c2; int cols, g_max, i, j, p_num, rows; int mona[360][250]; // // This part of the code reads some initial data from the graphics file. // cin >> c1; cin >> c2; cin >> cols; cin >> rows; cin >> g_max; // // Read the pixel data into the 2D array. // p_num = 0; for ( i = 0; i < rows; i++ ) { for ( j = 0; j < cols; j++ ) { cin >> mona[i][j]; p_num = p_num + 1; } } // // Reverse the pixel data. // for ( i = 0; i < rows; i++ ) { for ( j = 0; j < cols; j++ ) { mona[i][j] = 255 - mona[i][j]; } } // // Write the data back out. // First we have to write three lines of information about the data. // cout << c1 << c2 << "\n"; cout << cols << " " << rows << "\n"; cout << g_max << "\n"; for ( i = 0; i < rows; i++ ) { for ( j = 0; j < cols; j++ ) { cout << " " << mona[i][j]; } cout << "\n"; } return 0; }