diff --git a/src/libppm.cpp b/src/libppm.cpp index 32c1702..9268f79 100644 --- a/src/libppm.cpp +++ b/src/libppm.cpp @@ -81,7 +81,7 @@ struct image_t* read_ppm_file(char* path_to_input_file) // get pixel values val = skip_blanks_comments_while_reading(&read_stream); - /*for(int i = 0; i < image->height; i++) + for(int i = 0; i < image->height; i++) { for(int j = 0; j < image->width; j++) { @@ -91,9 +91,9 @@ struct image_t* read_ppm_file(char* path_to_input_file) val = read_stream.get(); //assuming maxval of <=255 } } - }*/ - read_stream.seekg(-1, ios_base::cur); - read_stream.read(((char*)image->image_pixels), image->height * image->width * 3); //assuming maxval of <=255 + } + //read_stream.seekg(-1, ios_base::cur); + //read_stream.read(((char*)image->image_pixels), image->height * image->width * 3); //assuming maxval of <=255 read_stream.close(); @@ -123,7 +123,17 @@ void write_ppm_file(char * path_to_output_file, struct image_t* image) //cout << "height = " << height_string << "\n"; write_stream.write(height_string.c_str(), height_string.length()); write_stream.write("\n255\n", 5); - write_stream.write(((char*)image->image_pixels), image->height * image->width * 3); + for(int i = 0; i < image->height; i++) + { + for(int j = 0; j < image->width; j++) + { + for(int k = 0; k < 3; k++) + { + write_stream.put(image->image_pixels[i][j][k]); //assuming maxval of <=255 + } + } + } + //write_stream.write(((char*)image->image_pixels), image->height * image->width * 3); write_stream.close(); } else