Skip to content

Commit

Permalink
image exporter started
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakapio committed Apr 4, 2023
1 parent ec3b943 commit 983d5f5
Showing 1 changed file with 16 additions and 49 deletions.
65 changes: 16 additions & 49 deletions PPMImageExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,25 @@ class PPMImageExporter {
}

void export(std::string path, int width, int height, int factor, vector<glm::vec3> data) {
string out = "";
std::string out = "";
std::ofstream op;
std::string str;
int i,j;
int r,g,b;
int factor;

fp.open(filename.c_str());

if (!fp.is_open())
throw std::invalid_argument("File not found!");

std::cout << "Image file opened" << std::endl;

//read line by line and ignore comments
std::stringstream input;
std::string line;

while (std::getline(fp,line)) {
if ((line.length()>0) && (line[0]!='#')) {
input << line << std::endl;
}
}
fp.close();


//read in the word P3

input >> str;


//now read in the width and height

input >> width >> height;

//read in the factor
input >> factor;

image = new GLubyte[3*width*height];

for (i=0;i<height;i++)
{
for (j=0;j<width;j++)
{
input >> r >> g >> b;
image[3*((height-1-i)*width+j)] = r;
image[3*((height-1-i)*width+j)+1] = g;
image[3*((height-1-i)*width+j)+2] = b;
// << "r=" << (int)r << ", g=" << (int)g << ",b=" << (int)b << endl;
}
}
//fp.close();
out += "P3" + "\n";
out += width + " " + height + "\n";
out += "255\n";


// for (i=0;i<height;i++)
// {
// for (j=0;j<width;j++)
// {
// input >> r >> g >> b;
// image[3*((height-1-i)*width+j)] = r;
// image[3*((height-1-i)*width+j)+1] = g;
// image[3*((height-1-i)*width+j)+2] = b;
// }
// }
}

};
Expand Down

0 comments on commit 983d5f5

Please sign in to comment.