-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppmR.h
42 lines (28 loc) · 819 Bytes
/
ppmR.h
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
39
40
#ifndef PPM_H
#define PPM_H
#include <math.h>
#include "color.h"
using namespace std;
class ppmR {
public:
ppmR(int w, int h) : width(w), height(h) {}
void writePixel(ostream& out, int x, int y, color cOut) const;
void writeHeader(ostream& out) const;
void writeNewLine(ostream& out) const;
public:
int width;
int height;
};
void ppmR::writePixel(ostream& out, int x, int y, color cOut) const {
out << static_cast<int>(clamp(cOut.r(), 0.0, 255)) << " "
<< static_cast<int>(clamp(cOut.g(), 0.0, 255)) << " "
<< static_cast<int>(clamp(cOut.b(), 0.0, 255)) << endl;
}
void ppmR::writeNewLine(ostream& out) const {
out << "\n";
}
void ppmR::writeHeader(ostream& out) const {
//PPM format header
out << "P3\n" << width << " " << height << "\n255\n";
}
#endif