代码备份
void read_ppm_file(const char* file_name) {
ifstream fin(file_name, std::ifstream::binary);
if (fin.fail())
cout<<"Could not open the file!"<<endl;
string ss;
strcpy(img_name, file_name);
if (getline(fin, ss, '\n'))
{
// PPM header
if ( ss != "P6" )
cout<<"Invalid PPM header or signature"<<endl;
}else
cout<<"Cannot read the PPM type!"<<endl;
// skip comments
while ( getline(fin, ss) )
{
if ( ss[0] == '#' )
continue;
else
break;
}
// read image size
istringstream iss;
iss.str(ss);
iss>>hres;
iss>>vres;
pixels.reserve(hres * vres);
if ( hres<=0 || vres<=0 )
cout<<"Invalid image size!"<<endl;
// maximum value to be found in the PPM file (usually 255)
unsigned int max_value;