1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
void get_filenames(string &infname, string &outfname);
//...............put your prototypes here...................
//..........................................................
int main (void)
{
string infilename, outfilename;
// for image:
string type;
int ncols=0, nrows=0, maxval=0;
static int pixels[1024 * 1024] = {0}; // large array needs to be static!
get_filenames(infilename, outfilename);
cout << "reading "<<infilename<<", displaying, and copying to "<<outfilename<<endl;
// Read the PGM file
readPGM(infilename, type, ncols, nrows, maxval, pixels);
if (ncols*nrows == 0) // if image array is size 0, problem!
{
cout << "error reading file "<<infilename<<endl;
return 0;
}
// Display the PGM header info and the pixel array
//...........add your function call to printPGM here!
// Save PGM file
//...........add your function call to savePGM here!
return 0;
}
// get input & output filenames, verify input file can be read
// outputs: infname and outfname, both strings.
void get_filenames(string &infname, string &outfname)
{
cout << "Enter the name of the PGM file: ";
cin >> infname;
ifstream ifs(infname.c_str()); // verify file is readable
if (!ifs)
{
cout << "Error: can't open "<<infname<< " for reading "<<endl;
exit(1); // bail out of program altogether.
}
ifs.close();
cout << "enter the outputname to copy the PGM to: ";
cin >> outfname;
ofstream ofs(outfname.c_str()); // verify we can write to the output file
if (!ofs)
{
cout << "Error: can't open "<<outfname<< " for writing "<<endl;
exit(1); // bail out of program altogether.
}
ofs.close(); // close it. you'll open it later in savePGM
}
//...............put your prototypes here...................
|