Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <stdlib.h>
- using namespace std;
- class PGM{
- private:
- int width;
- int** data;
- int height;
- int baseline;
- bool binopen(ifstream& file_h,string filename){
- int pos =file_h.tellg();
- ifstream file;
- file.open(filename.c_str(),ios::binary);
- file.seekg(pos);
- data = new int*[height];
- for(int y = 0; y< height;y++){
- data[y] = new int[width];
- for(int x = 0; x< width; x++){
- char buff[2];
- file.read(buff,1);
- if((int)buff[0]<0)
- data[y][x]=(int)buff[0]+baseline+1;
- }
- }
- file.close();
- }
- bool asciiopen(ifstream & file,string filename){
- }
- bool startfile(string filename){
- bool bin;
- int dim[2];
- int x=0;
- string tmp;
- string temp = "";
- ifstream file_h;
- file_h.open(filename.c_str());
- getline(file_h,tmp);
- bin = tmp=="P5";
- getline(file_h,tmp);
- getline(file_h,tmp);
- for(int i = 0; i< tmp.length();i++){
- if(tmp[i]==' ') {
- i++;
- dim[x]=atoi(temp.c_str());
- x++;
- temp="";
- }
- temp+=tmp[i];
- }
- dim[x]=atoi(temp.c_str());
- width = dim[0];
- height = dim[1];
- getline(file_h,tmp);
- baseline=atoi(tmp.c_str());
- if(bin){
- binopen(file_h,filename);
- }else{
- asciiopen(file_h,filename);
- }
- file_h.close();
- }
- public:
- PGM(string filename){
- startfile(filename);
- }
- ~PGM(){
- for(int y = 0;y<height;y++){
- delete [] data[y];
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement