/* Image.cpp * * CSE 326, Spring 2000 * Project 1 * * class image * main */ #include "Image.h" #define MAX_LINE 200 #define NUM_ARGS 3 #define OUTPUT_MAX_VALUE 255 #define USAGE "arguments: [input_file] [output_file]\n" int main(int argc, char **argv) { if(argc != NUM_ARGS) { cerr << USAGE; exit(1); } // add stuff here return 0; } image::image(title tl) { } void image::readImage(string input_file) { int i, j; ifstream input(input_file.c_str()); string buffer; char temp[MAX_LINE]; if(input.is_open() == false){ cerr << "The input file cannot be opened.\n"; exit(1); } input >> buffer; if(buffer != "P2"){ cerr << "The format is incorrect.\n"; exit(1); } input >> buffer; while(buffer[0] == '#'){ //skip comments input.getline(temp, MAX_LINE, '\n'); input >> buffer; } input >> buffer; //skip col input >> buffer; //skip max_value for(i = 0; i < row; i++) for(j = 0; j < col; j++) input >> array[i][j]; input.close(); } void image::convertPGM(int num_components) { int i, j; if(num_components == 0) return; int offset = OUTPUT_MAX_VALUE / num_components; for(i = 0; i < row; i++) for(j = 0; j < col; j++) array[i][j] *= offset; } image::~image() { int i; for(i = 0; i < row; i++) delete [] array[i]; }