This commit is contained in:
Shuo Feng 2024-01-28 20:14:37 -05:00
commit de866d23bf
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
28 changed files with 46878 additions and 0 deletions

25
external/simpleppm.cpp vendored Normal file
View file

@ -0,0 +1,25 @@
#include "simpleppm.h"
/*
This code was adapted from here:
https://rosettacode.org/wiki/Bitmap/Write_a_PPM_file#C.2B.2B
*/
using namespace std;
int save_ppm(std::string file_name, const std::vector<double>& buffer, int dimx, int dimy) {
ofstream ofs(file_name, ios_base::out | ios_base::binary);
ofs << "P6" << endl << dimx << ' ' << dimy << endl << "255" << endl;
for (unsigned int j = 0; j < dimy; ++j)
for (unsigned int i = 0; i < dimx; ++i)
ofs << (char) (255.0 * buffer[3*j*dimx+3*i+0]) << (char) (255.0 * buffer[3*j*dimx+3*i+1]) << (char) (255.0 * buffer[3*j*dimx+3*i+2]);
ofs.close();
return 0;
}