#include #include #include #include using namespace std; class PPMImage { int width, height, colordepth; int **raster; public: PPMImage(char *filename); ~PPMImage(); }; PPMImage::PPMImage(char *filename) { string str; unsigned char red, green, blue; ifstream in(filename); if(!in.is_open()) { std::ios_base::failure fex("File not found!"); throw fex; } try { in >> str; in >> str; width = atoi(str.c_str()); in >> str; height = atoi(str.c_str()); in >> str; colordepth = atoi(str.c_str()); raster = new int*[height]; for(int row=0; row> str; red = (unsigned char) atoi(str.c_str()); in >> str; green = (unsigned char) atoi(str.c_str()); in >> str; blue = (unsigned char) atoi(str.c_str()); raster[row][col] = 0; raster[row][col] = (red << 16) | (green << 8) | blue; } } } catch(std::bad_alloc &ex) { cerr << "std::bad_alloc occured!\n"; in.close(); throw ex; } } PPMImage::~PPMImage() { if(raster == nullptr) return; for(int row=0; row