Image * CPIImageReader::read(std::string filename) { ifstream input(filename.c_str(), ios::binary); try{ if (!input) throw("The file you try to open cannot open or does not exist! Please try again"); addLogEntry("Successfully opened "+filename+" for reading."); char cpi[3]; input.read(cpi, sizeof(char) * 3); if ((cpi[0] != 'C') || (cpi[1] != 'P') || (cpi[2] != 'I')) throw("The image you tried to open is not CPI type. Please try again with another image"); __int8 edition; input.read(&edition, sizeof(edition)); if (edition != 1) throw("The image you tried to open is not of the proper CPI edition (1st). Please try again with another image"); unsigned short BE_LE; input.read((char *)&BE_LE, sizeof(BE_LE)); if (BE_LE != 258) throw("The image you tried to open cannot be read. Please try again with another image"); unsigned short width, height; input.read((char *)&width, sizeof(width)); input.read((char*)&height, sizeof(height)); Component * buff = new Component[width*height * 3]; input.read((char*)buff, sizeof(Component)*width*height * 3); Image * returnedImage = new Image(width, height, buff, false); delete[] buff; input.close(); addLogEntry("The image was successfully read."); return returnedImage; } catch (char * err){ fprintf(stderr, "%s\n", err); addLogEntry(err); input.close(); destroyLogger(); return NULL; } }
void handle(int x) { x=x; destroyLogger(llg); exit(0); }