-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap.h
48 lines (35 loc) · 985 Bytes
/
bitmap.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
41
42
43
44
45
46
47
48
#ifndef BITMAP_H_
#define BITMAP_H_
#pragma once
#include <string>
#include <vector>
#include "color.h"
namespace raytracer {
// TODO: Make an Image abstract class/interface
class BitmapFile {
public:
BitmapFile(int width, int height);
~BitmapFile();
void SetPixel(int w, int h, const Color& c);
Color GetPixel(int w, int h) const;
bool WriteToFile(const std::string& filename) const;
private:
// TODO: swap width and height.
int width_;
int height_;
std::vector<Color> contents_;
// TODO: DISALLOW_COPY_AND_ASSIGN(PpmFile);
};
inline BitmapFile::BitmapFile(int width, int height)
: width_(width),
height_(height),
contents_(width * height) { }
inline BitmapFile::~BitmapFile() { }
inline void BitmapFile::SetPixel(int x, int y, const Color& c) {
contents_.at(x * width_ + y) = c;
}
inline Color BitmapFile::GetPixel(int x, int y) const {
return contents_.at(x * width_ + y);
}
} // namespace raytracer
#endif // BITMAP_H_