Directory Listing | |
---|---|
ppm_write.cpp
|
|
test.ppm
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
struct RGB {
int r, g, b;
};
struct PPM {
vector< vector<RGB> > pixels;
};
int main() {
PPM img;
img.pixels.resize(1);
for (int i = 0; i < img.pixels.size(); i++) {
img.pixels[i].resize(1);
}
img.pixels[0][0].r = 0;
img.pixels[0][0].g = 0;
img.pixels[0][0].b = 0;
ofstream fout;
fout.open("test.ppm");
fout << "P3" << endl;
fout << 1 << " " << 1 << endl;
fout << 255 << endl;
for (int a = 0; a < img.pixels.size(); a++) {
for (int b = 0; b < img.pixels[a].size(); b++) {
fout << img.pixels[a][b].r << " " << img.pixels[a][b].g << " " << img.pixels[a][b].b << endl;
}
}
}