#include #include #include #include using namespace std; class PPMImage { int width, height, colordepth; int **raster; public: 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()); cin >> str; green = (unsigned char) atoi(str.c_str()); cin >> 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() { for(int row=0; rowgetRaster() != nullptr) { cerr << "imgptr->getRaster() != nullptr\n"; delete imgptr->getRaster(); } else { cerr << "imgptr->getRaster() == nullptr\n"; } delete imgptr; } else { cerr << "imgptr == nullptr\n"; } } delete imgptr; return 0; }